mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 06:47:28 +00:00
Add communication account plugin scaffolds
This commit is contained in:
parent
5cfeea6b57
commit
c23ce42948
48 changed files with 1949 additions and 13 deletions
28
packages/account-core/src/provider-registry.ts
Normal file
28
packages/account-core/src/provider-registry.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import type { LogicSrcAccountKind, LogicSrcAccountProviderManifest } from "./types.js";
|
||||
|
||||
export function createProviderRegistry(providers: LogicSrcAccountProviderManifest[]) {
|
||||
const byId = new Map<string, LogicSrcAccountProviderManifest>();
|
||||
|
||||
for (const provider of providers) {
|
||||
if (byId.has(provider.id)) {
|
||||
throw new Error(`Duplicate account provider: ${provider.id}`);
|
||||
}
|
||||
byId.set(provider.id, provider);
|
||||
}
|
||||
|
||||
return {
|
||||
list(kind?: LogicSrcAccountKind) {
|
||||
return providers.filter((provider) => !kind || provider.kind === kind);
|
||||
},
|
||||
get(id: string) {
|
||||
return byId.get(id);
|
||||
},
|
||||
require(id: string) {
|
||||
const provider = byId.get(id);
|
||||
if (!provider) {
|
||||
throw new Error(`Unknown account provider: ${id}`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue