@omen.foundation/node-microservice-runtime 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +13 -0
- package/dist/auth.cjs +97 -0
- package/dist/auth.d.ts +14 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +93 -0
- package/dist/auth.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +588 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/decorators.cjs +181 -0
- package/dist/decorators.d.ts +23 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +155 -0
- package/dist/decorators.js.map +1 -0
- package/dist/dependency.cjs +165 -0
- package/dist/dependency.d.ts +56 -0
- package/dist/dependency.d.ts.map +1 -0
- package/dist/dependency.js +162 -0
- package/dist/dependency.js.map +1 -0
- package/dist/dev.cjs +34 -0
- package/dist/dev.d.ts +9 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +32 -0
- package/dist/dev.js.map +1 -0
- package/dist/discovery.cjs +79 -0
- package/dist/discovery.d.ts +20 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +75 -0
- package/dist/discovery.js.map +1 -0
- package/dist/docs.cjs +206 -0
- package/dist/docs.d.ts +30 -0
- package/dist/docs.d.ts.map +1 -0
- package/dist/docs.js +209 -0
- package/dist/docs.js.map +1 -0
- package/dist/env.cjs +106 -0
- package/dist/env.d.ts +4 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +108 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.cjs +58 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +48 -0
- package/dist/errors.js.map +1 -0
- package/dist/federation.cjs +356 -0
- package/dist/federation.d.ts +108 -0
- package/dist/federation.d.ts.map +1 -0
- package/dist/federation.js +341 -0
- package/dist/federation.js.map +1 -0
- package/dist/index.cjs +42 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory.cjs +361 -0
- package/dist/inventory.d.ts +116 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +351 -0
- package/dist/inventory.js.map +1 -0
- package/dist/logger.cjs +62 -0
- package/dist/logger.d.ts +9 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +29 -0
- package/dist/logger.js.map +1 -0
- package/dist/message.cjs +19 -0
- package/dist/message.d.ts +5 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +15 -0
- package/dist/message.js.map +1 -0
- package/dist/requester.cjs +100 -0
- package/dist/requester.d.ts +20 -0
- package/dist/requester.d.ts.map +1 -0
- package/dist/requester.js +99 -0
- package/dist/requester.js.map +1 -0
- package/dist/routing.cjs +39 -0
- package/dist/routing.d.ts +2 -0
- package/dist/routing.d.ts.map +1 -0
- package/dist/routing.js +36 -0
- package/dist/routing.js.map +1 -0
- package/dist/runtime.cjs +735 -0
- package/dist/runtime.d.ts +40 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +825 -0
- package/dist/runtime.js.map +1 -0
- package/dist/services.cjs +346 -0
- package/dist/services.d.ts +46 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +343 -0
- package/dist/services.js.map +1 -0
- package/dist/storage.cjs +147 -0
- package/dist/storage.d.ts +46 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +144 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/urls.cjs +55 -0
- package/dist/utils/urls.d.ts +5 -0
- package/dist/utils/urls.d.ts.map +1 -0
- package/dist/utils/urls.js +50 -0
- package/dist/utils/urls.js.map +1 -0
- package/dist/websocket.cjs +142 -0
- package/dist/websocket.d.ts +33 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +139 -0
- package/dist/websocket.js.map +1 -0
- package/env.sample +13 -0
- package/package.json +49 -0
- package/scripts/generate-openapi.mjs +114 -0
- package/scripts/lib/cli-utils.mjs +58 -0
- package/scripts/prepare-cjs.mjs +44 -0
- package/scripts/publish-service.mjs +1126 -0
- package/scripts/validate-service.mjs +103 -0
- package/scripts/ws-test.mjs +25 -0
- package/src/auth.ts +117 -0
- package/src/cli/index.ts +699 -0
- package/src/decorators.ts +207 -0
- package/src/dependency.ts +211 -0
- package/src/dev.ts +17 -0
- package/src/discovery.ts +88 -0
- package/src/docs.ts +262 -0
- package/src/env.ts +125 -0
- package/src/errors.ts +55 -0
- package/src/federation.ts +559 -0
- package/src/index.ts +51 -0
- package/src/inventory.ts +491 -0
- package/src/logger.ts +38 -0
- package/src/message.ts +19 -0
- package/src/requester.ts +126 -0
- package/src/routing.ts +42 -0
- package/src/runtime.ts +967 -0
- package/src/services.ts +459 -0
- package/src/storage.ts +206 -0
- package/src/types/beamable-sdk-api.d.ts +5 -0
- package/src/types.ts +117 -0
- package/src/utils/urls.ts +53 -0
- package/src/websocket.ts +170 -0
- package/tsconfig.base.json +31 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.cjs.json +16 -0
- package/tsconfig.dev.json +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACnD,OA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;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC9D,IAAI,CAAC,CAAC,CAAC,CAAC;AACV,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,eAAe;IAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,GAAG,IAAI,SAAS,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,GAAG,IAAI,SAAS,CAAC;QAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,IAAI,SAAS,CAAC;QAC9D,OAAO;YACL,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,SAAS;YAC7B,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,SAAS;YAC7B,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAS;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\r\n\r\nimport fs from 'node:fs/promises';\r\nimport path from 'node:path';\r\nimport os from 'node:os';\r\nimport { spawn } from 'node:child_process';\r\nimport readline from 'node:readline';\r\nimport { stdin, stdout, exit } from 'node:process';\r\nimport { fileURLToPath } from 'node:url';\r\nimport dotenv from 'dotenv';\r\n\r\ntype KeytarModule = typeof import('keytar');\r\n\r\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\r\n\r\ninterface TokenRecord {\r\n accessToken: string;\r\n refreshToken: string;\r\n expiresAt?: number;\r\n}\r\n\r\ninterface ProfileConfig {\r\n id: string;\r\n cid: string;\r\n pid: string;\r\n host: string;\r\n apiHost: string;\r\n email: string;\r\n lastUsed?: number;\r\n}\r\n\r\ninterface ConfigFile {\r\n profiles: Record<string, ProfileConfig>;\r\n lastUsed?: string;\r\n}\r\n\r\ninterface LoginOptions {\r\n cid: string;\r\n pid: string;\r\n host: string;\r\n email: string;\r\n password: string;\r\n}\r\n\r\ninterface ProfileSelectionOptions {\r\n cid?: string;\r\n pid?: string;\r\n host?: string;\r\n profileId?: string;\r\n}\r\n\r\nconst SERVICE_NAME = 'beamo-node';\r\nconst CONFIG_DIR = path.join(os.homedir(), '.beamo-node');\r\nconst CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');\r\nconst TOKEN_FALLBACK_DIR = path.join(CONFIG_DIR, 'tokens');\r\nconst DEFAULT_SOCKET_HOST = 'wss://api.beamable.com/socket';\r\nconst MIN_TOKEN_BUFFER_MS = 60_000;\r\n\r\nclass CredentialStore {\r\n private keytar?: KeytarModule;\r\n\r\n private constructor(keytar?: KeytarModule) {\r\n this.keytar = keytar;\r\n }\r\n\r\n static async create(): Promise<CredentialStore> {\r\n try {\r\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\r\n const keytarModule: KeytarModule = (await import('keytar')).default;\r\n return new CredentialStore(keytarModule);\r\n } catch (error) {\r\n console.warn('[beamo-node] keytar not available, falling back to file-based credential storage.');\r\n return new CredentialStore();\r\n }\r\n }\r\n\r\n async get(account: string): Promise<TokenRecord | undefined> {\r\n if (this.keytar) {\r\n const payload = await this.keytar.getPassword(SERVICE_NAME, account);\r\n if (!payload) {\r\n return undefined;\r\n }\r\n return this.parseTokenPayload(payload);\r\n }\r\n\r\n const filePath = this.fallbackPath(account);\r\n try {\r\n const payload = await fs.readFile(filePath, 'utf8');\r\n return this.parseTokenPayload(payload);\r\n } catch (error) {\r\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\r\n return undefined;\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n async set(account: string, record: TokenRecord): Promise<void> {\r\n const payload = JSON.stringify(record);\r\n if (this.keytar) {\r\n await this.keytar.setPassword(SERVICE_NAME, account, payload);\r\n return;\r\n }\r\n\r\n await fs.mkdir(TOKEN_FALLBACK_DIR, { recursive: true });\r\n const filePath = this.fallbackPath(account);\r\n await fs.writeFile(filePath, payload, { mode: 0o600, encoding: 'utf8' });\r\n }\r\n\r\n async clear(account: string): Promise<void> {\r\n if (this.keytar) {\r\n await this.keytar.deletePassword(SERVICE_NAME, account);\r\n return;\r\n }\r\n try {\r\n await fs.unlink(this.fallbackPath(account));\r\n } catch (error) {\r\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {\r\n throw error;\r\n }\r\n }\r\n }\r\n\r\n private parseTokenPayload(payload: string): TokenRecord {\r\n const parsed = JSON.parse(payload) as Partial<TokenRecord>;\r\n if (!parsed || typeof parsed !== 'object') {\r\n throw new Error('Stored credentials are malformed.');\r\n }\r\n if (typeof parsed.accessToken !== 'string' || typeof parsed.refreshToken !== 'string') {\r\n throw new Error('Stored credentials missing access or refresh token.');\r\n }\r\n return {\r\n accessToken: parsed.accessToken,\r\n refreshToken: parsed.refreshToken,\r\n expiresAt: typeof parsed.expiresAt === 'number' ? parsed.expiresAt : undefined,\r\n };\r\n }\r\n\r\n private fallbackPath(account: string): string {\r\n const safe = Buffer.from(account).toString('base64url');\r\n return path.join(TOKEN_FALLBACK_DIR, `${safe}.json`);\r\n }\r\n}\r\n\r\nclass ConfigStore {\r\n async load(): Promise<ConfigFile> {\r\n try {\r\n const payload = await fs.readFile(CONFIG_FILE, 'utf8');\r\n const data = JSON.parse(payload) as ConfigFile;\r\n return {\r\n profiles: data?.profiles ?? {},\r\n lastUsed: data?.lastUsed,\r\n };\r\n } catch (error) {\r\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\r\n return { profiles: {} };\r\n }\r\n throw error;\r\n }\r\n }\r\n\r\n async save(config: ConfigFile): Promise<void> {\r\n await fs.mkdir(CONFIG_DIR, { recursive: true });\r\n const payload = JSON.stringify(config, null, 2);\r\n await fs.writeFile(CONFIG_FILE, `${payload}\\n`, { encoding: 'utf8', mode: 0o600 });\r\n }\r\n}\r\n\r\nclass TokenManager {\r\n constructor(private readonly store: CredentialStore) {}\r\n\r\n async login(options: LoginOptions): Promise<TokenRecord> {\r\n const apiHost = normalizeApiHost(options.host);\r\n // Scope should be cid.pid if both are provided (matches official CLI behavior)\r\n const scope = options.pid ? `${options.cid}.${options.pid}` : options.cid;\r\n // Admin accounts require customerScoped: true (matches C# CLI behavior)\r\n // The registry will accept customer-scoped tokens when proper headers are used\r\n const customerScoped = true;\r\n const response = await fetch(new URL('/basic/auth/token', apiHost), {\r\n method: 'POST',\r\n headers: {\r\n Accept: 'application/json',\r\n 'Content-Type': 'application/json',\r\n ...(scope ? { 'X-BEAM-SCOPE': scope } : {}),\r\n },\r\n body: JSON.stringify({\r\n grant_type: 'password',\r\n username: options.email,\r\n password: options.password,\r\n customerScoped,\r\n }),\r\n });\r\n\r\n if (!response.ok) {\r\n const message = await safeReadError(response);\r\n throw new Error(`Login failed (${response.status}): ${message}`);\r\n }\r\n\r\n const body = (await response.json()) as Record<string, unknown>;\r\n const accessToken = typeof body.access_token === 'string' ? body.access_token : undefined;\r\n const refreshToken = typeof body.refresh_token === 'string' ? body.refresh_token : undefined;\r\n const expiresIn = typeof body.expires_in === 'number' ? body.expires_in : Number(body.expires_in ?? 0);\r\n\r\n if (!accessToken || !refreshToken) {\r\n throw new Error('Login response did not contain access and refresh tokens.');\r\n }\r\n\r\n const expiresAt = Number.isFinite(expiresIn) && expiresIn > 0 ? Date.now() + expiresIn * 1000 : undefined;\r\n const record: TokenRecord = { accessToken, refreshToken, expiresAt };\r\n const account = profileKey({ cid: options.cid, pid: options.pid, apiHost });\r\n\r\n await this.store.set(account, record);\r\n return record;\r\n }\r\n\r\n async getValidTokens(cid: string, pid: string, host: string, forceRealmScoped = false): Promise<TokenRecord> {\r\n const apiHost = normalizeApiHost(host);\r\n const account = profileKey({ cid, pid, apiHost });\r\n\r\n const existing = await this.store.get(account);\r\n if (!existing) {\r\n throw new Error(`No stored credentials for ${cid}.${pid} (${apiHost}). Run \"beamo-node login\" first.`);\r\n }\r\n\r\n // Refresh token if expired or if explicitly requested\r\n // Note: If login was done with PID, tokens are already realm-scoped\r\n if (forceRealmScoped || isTokenExpired(existing.expiresAt)) {\r\n if (process.env.BEAMO_DEBUG === '1' || process.env.BEAMO_NODE_DEBUG === '1') {\r\n console.log(`[beamo-node] Refreshing token (forceRealmScoped=${forceRealmScoped}, expired=${isTokenExpired(existing.expiresAt)})`);\r\n }\r\n const refreshed = await this.refreshToken(existing.refreshToken, cid, pid, apiHost);\r\n await this.store.set(account, refreshed);\r\n return refreshed;\r\n }\r\n\r\n return existing;\r\n }\r\n\r\n private async refreshToken(refreshToken: string, cid: string, pid: string, apiHost: string): Promise<TokenRecord> {\r\n const scope = pid ? `${cid}.${pid}` : cid;\r\n const response = await fetch(new URL('/basic/auth/token', apiHost), {\r\n method: 'POST',\r\n headers: {\r\n Accept: 'application/json',\r\n 'Content-Type': 'application/json',\r\n ...(scope ? { 'X-BEAM-SCOPE': scope } : {}),\r\n },\r\n body: JSON.stringify({\r\n grant_type: 'refresh_token',\r\n refresh_token: refreshToken,\r\n // Don't include customerScoped - refresh tokens inherit scope from the refresh token itself\r\n // Setting X-BEAM-SCOPE header should be enough to get a realm-scoped token\r\n }),\r\n });\r\n\r\n if (!response.ok) {\r\n const message = await safeReadError(response);\r\n throw new Error(`Failed to refresh token (${response.status}): ${message}`);\r\n }\r\n\r\n const body = (await response.json()) as Record<string, unknown>;\r\n const accessToken = typeof body.access_token === 'string' ? body.access_token : undefined;\r\n const newRefreshToken = typeof body.refresh_token === 'string' ? body.refresh_token : refreshToken;\r\n const expiresIn = typeof body.expires_in === 'number' ? body.expires_in : Number(body.expires_in ?? 0);\r\n\r\n if (!accessToken) {\r\n throw new Error('Refresh token response missing access token.');\r\n }\r\n\r\n const expiresAt = Number.isFinite(expiresIn) && expiresIn > 0 ? Date.now() + expiresIn * 1000 : undefined;\r\n \r\n // Verify the refreshed token works with realm scope\r\n if (pid && process.env.BEAMO_DEBUG === '1') {\r\n try {\r\n const testUrl = new URL('/basic/accounts/me', apiHost);\r\n const testResponse = await fetch(testUrl, {\r\n headers: {\r\n Authorization: `Bearer ${accessToken}`,\r\n Accept: 'application/json',\r\n 'X-BEAM-SCOPE': scope,\r\n },\r\n });\r\n if (!testResponse.ok) {\r\n console.warn(`[beamo-node] Warning: Refreshed token validation failed (${testResponse.status}). Token may still be customer-scoped.`);\r\n }\r\n } catch {\r\n // Ignore validation errors in debug mode\r\n }\r\n }\r\n \r\n return { accessToken, refreshToken: newRefreshToken, expiresAt };\r\n }\r\n}\r\n\r\nfunction parseCommandLine(argv: string[]): { command?: string; args: string[] } {\r\n const [command, ...rest] = argv;\r\n return { command, args: rest };\r\n}\r\n\r\nfunction splitArgs(args: string[], recognizedFlags: Set<string>): { flags: Record<string, string | boolean>; forward: string[] } {\r\n const flags: Record<string, string | boolean> = {};\r\n const forward: string[] = [];\r\n\r\n for (let index = 0; index < args.length; index += 1) {\r\n const token = args[index];\r\n if (!token.startsWith('-')) {\r\n forward.push(token);\r\n continue;\r\n }\r\n\r\n const key = token.replace(/^--/, '');\r\n\r\n if (recognizedFlags.has(key)) {\r\n const next = args[index + 1];\r\n if (next !== undefined && !next.startsWith('-')) {\r\n flags[key] = next;\r\n index += 1;\r\n } else {\r\n flags[key] = true;\r\n }\r\n } else {\r\n forward.push(token);\r\n const next = args[index + 1];\r\n if (next !== undefined && !next.startsWith('-')) {\r\n forward.push(next);\r\n index += 1;\r\n }\r\n }\r\n }\r\n\r\n return { flags, forward };\r\n}\r\n\r\nasync function promptInput(question: string, defaultValue?: string): Promise<string> {\r\n const rl = readline.createInterface({ input: stdin, output: stdout });\r\n return new Promise<string>((resolve) => {\r\n rl.question(defaultValue ? `${question} (${defaultValue}): ` : `${question}: `, (answer) => {\r\n rl.close();\r\n const value = answer.trim();\r\n resolve(value === '' && defaultValue !== undefined ? defaultValue : value);\r\n });\r\n });\r\n}\r\n\r\nasync function promptHidden(question: string): Promise<string> {\r\n const rl = readline.createInterface({ input: stdin, output: stdout } as readline.ReadLineOptions & { stdoutMuted?: boolean });\r\n\r\n return new Promise<string>((resolve) => {\r\n const mutable = rl as readline.Interface & {\r\n stdoutMuted?: boolean;\r\n _writeToOutput?: (stringToWrite: string) => void;\r\n output?: typeof stdout;\r\n };\r\n mutable.stdoutMuted = true;\r\n const originalWrite = mutable._writeToOutput?.bind(mutable);\r\n const outputStream = mutable.output ?? stdout;\r\n mutable._writeToOutput = (stringToWrite: string) => {\r\n if (mutable.stdoutMuted) {\r\n outputStream.write('*');\r\n } else if (originalWrite) {\r\n originalWrite(stringToWrite);\r\n } else {\r\n outputStream.write(stringToWrite);\r\n }\r\n };\r\n\r\n mutable.question(`${question}: `, (answer) => {\r\n mutable.close();\r\n stdout.write(os.EOL);\r\n resolve(answer);\r\n });\r\n });\r\n}\r\n\r\nasync function handleLogin(args: string[], configStore: ConfigStore, tokenManager: TokenManager): Promise<void> {\r\n const { flags } = splitArgs(args, new Set(['cid', 'pid', 'host', 'email']));\r\n const envDefaults = await loadEnvDefaults();\r\n\r\n const cid = typeof flags.cid === 'string' ? flags.cid : await promptInput('CID', envDefaults.cid);\r\n const pid = typeof flags.pid === 'string' ? flags.pid : await promptInput('PID', envDefaults.pid);\r\n const hostDefault = envDefaults.host ?? DEFAULT_SOCKET_HOST;\r\n const host = typeof flags.host === 'string' ? flags.host : await promptInput('Host', hostDefault);\r\n const email = typeof flags.email === 'string' ? flags.email : await promptInput('Email');\r\n const password = await promptHidden('Password');\r\n\r\n if (!cid || !pid || !host || !email || !password) {\r\n throw new Error('CID, PID, host, email, and password are required.');\r\n }\r\n\r\n const record = await tokenManager.login({ cid, pid, host, email, password });\r\n const config = await configStore.load();\r\n const apiHost = normalizeApiHost(host);\r\n const id = profileKey({ cid, pid, apiHost });\r\n\r\n config.profiles[id] = {\r\n id,\r\n cid,\r\n pid,\r\n host,\r\n apiHost,\r\n email,\r\n lastUsed: Date.now(),\r\n };\r\n config.lastUsed = id;\r\n\r\n await configStore.save(config);\r\n\r\n console.log(`Login successful for ${email} (${cid}.${pid}).`);\r\n if (!record.expiresAt) {\r\n console.warn('[beamo-node] Access token does not include an expiration. You may need to re-login if publish fails.');\r\n }\r\n}\r\n\r\nasync function handlePublish(args: string[], configStore: ConfigStore, tokenManager: TokenManager): Promise<void> {\r\n const { flags, forward } = splitArgs(args, new Set(['cid', 'pid', 'host', 'profile']));\r\n const profile = await resolveProfile(flags, configStore);\r\n\r\n // Refresh token if expired (customer-scoped tokens work with registry when proper headers are used)\r\n // The C# CLI uses the same access token for both registry API calls and Docker registry uploads\r\n const tokens = await tokenManager.getValidTokens(profile.cid, profile.pid, profile.host, false);\r\n const env = buildCommandEnv(profile, tokens);\r\n\r\n const scriptArgs = buildScriptArgs(forward, profile, true); // publish needs --api-host\r\n const scriptPath = path.resolve(__dirname, '../../scripts/publish-service.mjs');\r\n await runScript(scriptPath, scriptArgs, env);\r\n}\r\n\r\nasync function handleValidate(args: string[], configStore: ConfigStore, tokenManager: TokenManager): Promise<void> {\r\n const { flags, forward } = splitArgs(args, new Set(['cid', 'pid', 'host', 'profile']));\r\n const profile = await resolveProfile(flags, configStore);\r\n\r\n // Validation does not require tokens, but downstream scripts expect CID/PID/HOST env values.\r\n const tokens = await tokenManager.getValidTokens(profile.cid, profile.pid, profile.host);\r\n const env = buildCommandEnv(profile, tokens);\r\n\r\n const scriptArgs = buildScriptArgs(forward, profile, false); // validate doesn't need --api-host\r\n const scriptPath = path.resolve(__dirname, '../../scripts/validate-service.mjs');\r\n await runScript(scriptPath, scriptArgs, env);\r\n}\r\n\r\nasync function resolveProfile(flags: Record<string, string | boolean>, configStore: ConfigStore): Promise<ProfileConfig> {\r\n const config = await configStore.load();\r\n\r\n if (typeof flags.profile === 'string') {\r\n const explicit = config.profiles[flags.profile];\r\n if (!explicit) {\r\n throw new Error(`Profile \"${flags.profile}\" not found. Run \"beamo-node login\" to create it.`);\r\n }\r\n config.lastUsed = explicit.id;\r\n await configStore.save(config);\r\n return explicit;\r\n }\r\n\r\n const directOptions: ProfileSelectionOptions = {\r\n cid: typeof flags.cid === 'string' ? flags.cid : undefined,\r\n pid: typeof flags.pid === 'string' ? flags.pid : undefined,\r\n host: typeof flags.host === 'string' ? flags.host : undefined,\r\n };\r\n\r\n if (directOptions.cid && directOptions.pid && directOptions.host) {\r\n const apiHost = normalizeApiHost(directOptions.host);\r\n const id = profileKey({ cid: directOptions.cid, pid: directOptions.pid, apiHost });\r\n const profile = config.profiles[id];\r\n if (!profile) {\r\n throw new Error(`No stored credentials for ${directOptions.cid}.${directOptions.pid}. Run \"beamo-node login\" first.`);\r\n }\r\n profile.lastUsed = Date.now();\r\n config.lastUsed = profile.id;\r\n await configStore.save(config);\r\n return profile;\r\n }\r\n\r\n if (!config.lastUsed) {\r\n if (Object.keys(config.profiles).length === 0) {\r\n throw new Error('No stored credentials found. Run \"beamo-node login\" first.');\r\n }\r\n throw new Error('Multiple profiles found. Specify one with \"--profile <id>\" or run \"beamo-node login\" first.');\r\n }\r\n\r\n const profile = config.profiles[config.lastUsed];\r\n if (!profile) {\r\n throw new Error(`Last used profile \"${config.lastUsed}\" is missing. Run \"beamo-node login\" to refresh credentials.`);\r\n }\r\n\r\n profile.lastUsed = Date.now();\r\n config.lastUsed = profile.id;\r\n await configStore.save(config);\r\n return profile;\r\n}\r\n\r\nfunction buildScriptArgs(original: string[], profile: ProfileConfig, includeApiHost = true): string[] {\r\n const hasFlag = (flag: string) => original.some((token) => token === flag);\r\n const args: string[] = [...original];\r\n if (!hasFlag('--cid')) {\r\n args.push('--cid', profile.cid);\r\n }\r\n if (!hasFlag('--pid')) {\r\n args.push('--pid', profile.pid);\r\n }\r\n if (!hasFlag('--host')) {\r\n args.push('--host', profile.host);\r\n }\r\n if (includeApiHost && !hasFlag('--api-host')) {\r\n args.push('--api-host', profile.apiHost);\r\n }\r\n return args;\r\n}\r\n\r\nfunction buildCommandEnv(profile: ProfileConfig, tokens: TokenRecord): NodeJS.ProcessEnv {\r\n return {\r\n ...process.env,\r\n BEAMABLE_TOKEN: tokens.accessToken,\r\n ACCESS_TOKEN: tokens.accessToken,\r\n BEAMABLE_REFRESH_TOKEN: tokens.refreshToken,\r\n REFRESH_TOKEN: tokens.refreshToken,\r\n BEAMABLE_CID: profile.cid,\r\n CID: profile.cid,\r\n BEAMABLE_PID: profile.pid,\r\n PID: profile.pid,\r\n BEAMABLE_HOST: profile.host,\r\n HOST: profile.host,\r\n BEAMABLE_API_HOST: profile.apiHost,\r\n };\r\n}\r\n\r\nasync function runScript(command: string, args: string[], env: NodeJS.ProcessEnv): Promise<void> {\r\n const isNodeScript = /\\.(mjs|cjs|js)$/i.test(command);\r\n const executable = isNodeScript ? process.execPath : command;\r\n const finalArgs = isNodeScript ? [command, ...args] : args;\r\n const shouldUseShell = process.platform === 'win32' && !isNodeScript;\r\n const debug = process.env.BEAMO_DEBUG === '1' || process.env.BEAMO_NODE_DEBUG === '1';\r\n if (debug) {\r\n console.log(\r\n `[beamo-node] command=\"${command}\" exec=\"${executable}\" args=${JSON.stringify(\r\n finalArgs,\r\n )} shell=${shouldUseShell} cwd=${process.cwd()}`,\r\n );\r\n }\r\n\r\n await new Promise<void>((resolve, reject) => {\r\n const child = spawn(executable, finalArgs, {\r\n stdio: 'inherit',\r\n env,\r\n shell: shouldUseShell,\r\n });\r\n\r\n child.on('error', (error) => reject(error));\r\n child.on('exit', (code) => {\r\n if (code === 0) {\r\n resolve();\r\n } else {\r\n reject(new Error(`Command failed with exit code ${code ?? 'unknown'}.`));\r\n }\r\n });\r\n });\r\n}\r\n\r\nfunction normalizeApiHost(host: string): string {\r\n const trimmed = host.trim();\r\n if (trimmed.startsWith('wss://')) {\r\n return `https://${trimmed.substring('wss://'.length).replace(/\\/socket$/, '')}`;\r\n }\r\n if (trimmed.startsWith('ws://')) {\r\n return `http://${trimmed.substring('ws://'.length).replace(/\\/socket$/, '')}`;\r\n }\r\n let normalized = trimmed.replace(/\\/socket$/, '').replace(/\\/$/, '');\r\n if (!/^https?:\\/\\//i.test(normalized)) {\r\n normalized = `https://${normalized}`;\r\n }\r\n return normalized;\r\n}\r\n\r\nfunction profileKey(input: { cid: string; pid: string; apiHost: string }): string {\r\n return `${input.cid}.${input.pid}@${input.apiHost}`;\r\n}\r\n\r\nfunction isTokenExpired(expiresAt?: number): boolean {\r\n if (!expiresAt || !Number.isFinite(expiresAt)) {\r\n return true;\r\n }\r\n return Date.now() + MIN_TOKEN_BUFFER_MS >= expiresAt;\r\n}\r\n\r\nasync function safeReadError(response: Response): Promise<string> {\r\n try {\r\n const body = await response.text();\r\n if (!body) {\r\n return 'No response body';\r\n }\r\n try {\r\n const parsed = JSON.parse(body) as Record<string, unknown>;\r\n return typeof parsed.error === 'string'\r\n ? parsed.error\r\n : typeof parsed.message === 'string'\r\n ? parsed.message\r\n : body;\r\n } catch {\r\n return body;\r\n }\r\n } catch {\r\n return 'No response body';\r\n }\r\n}\r\n\r\nasync function main(): Promise<void> {\r\n const [, , ...argv] = process.argv;\r\n const { command, args } = parseCommandLine(argv);\r\n\r\n if (!command || command === '--help' || command === '-h') {\r\n printHelp();\r\n return;\r\n }\r\n\r\n const credentialStore = await CredentialStore.create();\r\n const tokenManager = new TokenManager(credentialStore);\r\n const configStore = new ConfigStore();\r\n\r\n switch (command) {\r\n case 'login':\r\n await handleLogin(args, configStore, tokenManager);\r\n break;\r\n case 'publish':\r\n await handlePublish(args, configStore, tokenManager);\r\n break;\r\n case 'validate':\r\n await handleValidate(args, configStore, tokenManager);\r\n break;\r\n case 'profiles':\r\n await listProfiles(configStore);\r\n break;\r\n default:\r\n console.error(`Unknown command: ${command}`);\r\n printHelp();\r\n exit(1);\r\n }\r\n}\r\n\r\nasync function listProfiles(configStore: ConfigStore): Promise<void> {\r\n const config = await configStore.load();\r\n const entries = Object.values(config.profiles).sort((a, b) => (b.lastUsed ?? 0) - (a.lastUsed ?? 0));\r\n if (entries.length === 0) {\r\n console.log('No stored profiles. Run \"beamo-node login\" to create one.');\r\n return;\r\n }\r\n console.log('Stored profiles:');\r\n for (const profile of entries) {\r\n const marker = config.lastUsed === profile.id ? '*' : ' ';\r\n console.log(` ${marker} ${profile.id}`);\r\n console.log(` CID: ${profile.cid}`);\r\n console.log(` PID: ${profile.pid}`);\r\n console.log(` Host: ${profile.host}`);\r\n console.log(` Email: ${profile.email}`);\r\n }\r\n}\r\n\r\nfunction printHelp(): void {\r\n console.log(`beamo-node CLI\r\n\r\nUsage:\r\n beamo-node login [--cid CID] [--pid PID] [--host HOST] [--email EMAIL]\r\n beamo-node publish [--profile ID] [--cid CID --pid PID --host HOST] [-- ...publish flags...]\r\n beamo-node validate [--profile ID] [--cid CID --pid PID --host HOST] [-- ...validate flags...]\r\n beamo-node profiles\r\n\r\nCommands:\r\n login Authenticate with Beamable and store credentials securely.\r\n publish Run the publish pipeline using stored credentials (forwards extra flags to the publish script).\r\n validate Generate OpenAPI docs and validate the project (forwards extra flags).\r\n profiles List stored profiles and indicate the default selection.\r\n`);\r\n}\r\n\r\nmain().catch((error) => {\r\n console.error(error instanceof Error ? error.message : error);\r\n exit(1);\r\n});\r\n\r\nasync function loadEnvDefaults(): Promise<ProfileSelectionOptions> {\r\n const envPath = path.resolve('.env');\r\n try {\r\n const content = await fs.readFile(envPath, 'utf8');\r\n const parsed = dotenv.parse(content);\r\n const cid = parsed.BEAMABLE_CID ?? parsed.CID ?? undefined;\r\n const pid = parsed.BEAMABLE_PID ?? parsed.PID ?? undefined;\r\n const host = parsed.BEAMABLE_HOST ?? parsed.HOST ?? undefined;\r\n return {\r\n cid: cid?.trim() || undefined,\r\n pid: pid?.trim() || undefined,\r\n host: host?.trim() || undefined,\r\n };\r\n } catch (error) {\r\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\r\n return {};\r\n }\r\n throw error;\r\n }\r\n}\r\n\r\n\r\n"]}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Microservice = Microservice;
|
|
4
|
+
exports.Callable = Callable;
|
|
5
|
+
exports.listRegisteredServices = listRegisteredServices;
|
|
6
|
+
exports.getServiceOptions = getServiceOptions;
|
|
7
|
+
exports.ClientCallable = ClientCallable;
|
|
8
|
+
exports.ServerCallable = ServerCallable;
|
|
9
|
+
exports.AdminCallable = AdminCallable;
|
|
10
|
+
exports.SwaggerCategory = SwaggerCategory;
|
|
11
|
+
exports.SwaggerTags = SwaggerTags;
|
|
12
|
+
exports.configureServices = configureServices;
|
|
13
|
+
exports.initializeServices = initializeServices;
|
|
14
|
+
exports.ConfigureServices = ConfigureServices;
|
|
15
|
+
exports.InitializeServices = InitializeServices;
|
|
16
|
+
exports.getConfigureServicesHandlers = getConfigureServicesHandlers;
|
|
17
|
+
exports.getInitializeServicesHandlers = getInitializeServicesHandlers;
|
|
18
|
+
require("reflect-metadata");
|
|
19
|
+
const SERVICE_METADATA = new Map();
|
|
20
|
+
const PENDING_REGISTRATIONS = new Map();
|
|
21
|
+
const SWAGGER_TAGS_METADATA_KEY = Symbol('beamable:swaggerTags');
|
|
22
|
+
const CONFIGURE_SERVICES_METADATA = new Map();
|
|
23
|
+
const INITIALIZE_SERVICES_METADATA = new Map();
|
|
24
|
+
function Microservice(name, options = {}) {
|
|
25
|
+
if (!name || !/^[A-Za-z0-9_]+$/.test(name)) {
|
|
26
|
+
throw new Error(`Invalid microservice name "${name}". Only alphanumeric and underscore characters are allowed.`);
|
|
27
|
+
}
|
|
28
|
+
return function decorator(ctor) {
|
|
29
|
+
const qualifiedName = `micro_${name}`;
|
|
30
|
+
const entry = {
|
|
31
|
+
name,
|
|
32
|
+
qualifiedName,
|
|
33
|
+
ctor,
|
|
34
|
+
callables: new Map(),
|
|
35
|
+
options,
|
|
36
|
+
};
|
|
37
|
+
SERVICE_METADATA.set(ctor, entry);
|
|
38
|
+
const pending = PENDING_REGISTRATIONS.get(ctor);
|
|
39
|
+
if (pending) {
|
|
40
|
+
pending.forEach((fn) => fn(entry));
|
|
41
|
+
PENDING_REGISTRATIONS.delete(ctor);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function Callable(options = {}) {
|
|
46
|
+
return function decorator(target, propertyKey, _descriptor) {
|
|
47
|
+
var _a;
|
|
48
|
+
let ctorCandidate;
|
|
49
|
+
if (typeof target === 'function') {
|
|
50
|
+
ctorCandidate = target;
|
|
51
|
+
}
|
|
52
|
+
else if (target !== null && typeof target === 'object') {
|
|
53
|
+
const obj = target;
|
|
54
|
+
ctorCandidate = obj.constructor;
|
|
55
|
+
}
|
|
56
|
+
if (typeof ctorCandidate !== 'function') {
|
|
57
|
+
throw new Error('@Callable can only be applied to methods on a class.');
|
|
58
|
+
}
|
|
59
|
+
const ctor = ctorCandidate;
|
|
60
|
+
const metadataTarget = typeof target === 'function'
|
|
61
|
+
? target
|
|
62
|
+
: target !== null && typeof target === 'object'
|
|
63
|
+
? target
|
|
64
|
+
: undefined;
|
|
65
|
+
if (!metadataTarget) {
|
|
66
|
+
throw new Error('@Callable decorator received an invalid target.');
|
|
67
|
+
}
|
|
68
|
+
const meta = SERVICE_METADATA.get(ctor);
|
|
69
|
+
if (!meta) {
|
|
70
|
+
const queue = (_a = PENDING_REGISTRATIONS.get(ctor)) !== null && _a !== void 0 ? _a : [];
|
|
71
|
+
queue.push((lateMeta) => registerCallable(lateMeta, propertyKey, options, metadataTarget));
|
|
72
|
+
PENDING_REGISTRATIONS.set(ctor, queue);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
registerCallable(meta, propertyKey, options, metadataTarget);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function registerCallable(meta, propertyKey, options, metadataTarget) {
|
|
79
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
80
|
+
const access = (_a = options.access) !== null && _a !== void 0 ? _a : 'public';
|
|
81
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', metadataTarget, propertyKey);
|
|
82
|
+
const route = (_b = options.route) !== null && _b !== void 0 ? _b : propertyKey;
|
|
83
|
+
const decoratorTags = (_c = Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, metadataTarget, propertyKey)) !== null && _c !== void 0 ? _c : [];
|
|
84
|
+
const combinedTags = (_d = options.tags) !== null && _d !== void 0 ? _d : decoratorTags;
|
|
85
|
+
const tags = Array.from(new Set(combinedTags !== null && combinedTags !== void 0 ? combinedTags : []));
|
|
86
|
+
const metadata = {
|
|
87
|
+
route,
|
|
88
|
+
displayName: propertyKey,
|
|
89
|
+
requireAuth: (_e = options.requireAuth) !== null && _e !== void 0 ? _e : access !== 'public',
|
|
90
|
+
requiredScopes: (_f = options.requiredScopes) !== null && _f !== void 0 ? _f : defaultScopesForAccess(access),
|
|
91
|
+
useLegacySerialization: (_h = (_g = options.useLegacySerialization) !== null && _g !== void 0 ? _g : meta.options.useLegacySerialization) !== null && _h !== void 0 ? _h : false,
|
|
92
|
+
parameterTypes: paramTypes !== null && paramTypes !== void 0 ? paramTypes : [],
|
|
93
|
+
access,
|
|
94
|
+
tags,
|
|
95
|
+
};
|
|
96
|
+
const key = route.toLowerCase();
|
|
97
|
+
if (meta.callables.has(key)) {
|
|
98
|
+
throw new Error(`Duplicate callable route "${route}" on ${meta.ctor.name}.`);
|
|
99
|
+
}
|
|
100
|
+
meta.callables.set(key, metadata);
|
|
101
|
+
}
|
|
102
|
+
function defaultScopesForAccess(access) {
|
|
103
|
+
switch (access) {
|
|
104
|
+
case 'admin':
|
|
105
|
+
return ['admin'];
|
|
106
|
+
case 'server':
|
|
107
|
+
return ['server'];
|
|
108
|
+
default:
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function listRegisteredServices() {
|
|
113
|
+
return Array.from(SERVICE_METADATA.values()).map((entry) => ({
|
|
114
|
+
name: entry.name,
|
|
115
|
+
qualifiedName: entry.qualifiedName,
|
|
116
|
+
ctor: entry.ctor,
|
|
117
|
+
callables: new Map(entry.callables),
|
|
118
|
+
options: entry.options,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
function getServiceOptions(ctor) {
|
|
122
|
+
var _a;
|
|
123
|
+
return (_a = SERVICE_METADATA.get(ctor)) === null || _a === void 0 ? void 0 : _a.options;
|
|
124
|
+
}
|
|
125
|
+
function ClientCallable(options = {}) {
|
|
126
|
+
return Callable({ ...options, access: 'client', requireAuth: true });
|
|
127
|
+
}
|
|
128
|
+
function ServerCallable(options = {}) {
|
|
129
|
+
return Callable({ ...options, access: 'server', requireAuth: true });
|
|
130
|
+
}
|
|
131
|
+
function AdminCallable(options = {}) {
|
|
132
|
+
return Callable({ ...options, access: 'admin', requireAuth: true });
|
|
133
|
+
}
|
|
134
|
+
function SwaggerCategory(category) {
|
|
135
|
+
return SwaggerTags(category);
|
|
136
|
+
}
|
|
137
|
+
function SwaggerTags(...tags) {
|
|
138
|
+
return function decorator(target, propertyKey, _descriptor) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (tags.length === 0) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const current = (_a = Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, target, propertyKey)) !== null && _a !== void 0 ? _a : [];
|
|
144
|
+
const merged = Array.from(new Set([...current, ...tags]));
|
|
145
|
+
Reflect.defineMetadata(SWAGGER_TAGS_METADATA_KEY, merged, target, propertyKey);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function configureServices(target) {
|
|
149
|
+
var _a;
|
|
150
|
+
return (_a = CONFIGURE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
151
|
+
}
|
|
152
|
+
function initializeServices(target) {
|
|
153
|
+
var _a;
|
|
154
|
+
return (_a = INITIALIZE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
155
|
+
}
|
|
156
|
+
function ConfigureServices(target, _propertyKey, descriptor) {
|
|
157
|
+
var _a;
|
|
158
|
+
if (typeof descriptor.value !== 'function') {
|
|
159
|
+
throw new Error('@ConfigureServices can only decorate static methods.');
|
|
160
|
+
}
|
|
161
|
+
const handlers = (_a = CONFIGURE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
162
|
+
handlers.push(descriptor.value.bind(target));
|
|
163
|
+
CONFIGURE_SERVICES_METADATA.set(target, handlers);
|
|
164
|
+
}
|
|
165
|
+
function InitializeServices(target, _propertyKey, descriptor) {
|
|
166
|
+
var _a;
|
|
167
|
+
if (typeof descriptor.value !== 'function') {
|
|
168
|
+
throw new Error('@InitializeServices can only decorate static methods.');
|
|
169
|
+
}
|
|
170
|
+
const handlers = (_a = INITIALIZE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
171
|
+
handlers.push(descriptor.value.bind(target));
|
|
172
|
+
INITIALIZE_SERVICES_METADATA.set(target, handlers);
|
|
173
|
+
}
|
|
174
|
+
function getConfigureServicesHandlers(target) {
|
|
175
|
+
var _a;
|
|
176
|
+
return (_a = CONFIGURE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
177
|
+
}
|
|
178
|
+
function getInitializeServicesHandlers(target) {
|
|
179
|
+
var _a;
|
|
180
|
+
return (_a = INITIALIZE_SERVICES_METADATA.get(target)) !== null && _a !== void 0 ? _a : [];
|
|
181
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { ServiceDefinition, MicroserviceOptions, CallableOptions } from './types.js';
|
|
3
|
+
import type { DependencyBuilder, DependencyScope } from './dependency.js';
|
|
4
|
+
type ConfigureServicesHandler = (builder: DependencyBuilder) => void | Promise<void>;
|
|
5
|
+
type InitializeServicesHandler = (provider: DependencyScope) => void | Promise<void>;
|
|
6
|
+
export type { ConfigureServicesHandler, InitializeServicesHandler };
|
|
7
|
+
export declare function Microservice(name: string, options?: MicroserviceOptions): <T extends new (...args: unknown[]) => unknown>(ctor: T) => void;
|
|
8
|
+
export declare function Callable(options?: CallableOptions): (target: unknown, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
9
|
+
export declare function listRegisteredServices(): ServiceDefinition[];
|
|
10
|
+
export declare function getServiceOptions(ctor: Function): MicroserviceOptions | undefined;
|
|
11
|
+
export type { MicroserviceOptions, CallableOptions };
|
|
12
|
+
export declare function ClientCallable(options?: CallableOptions): (target: unknown, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
13
|
+
export declare function ServerCallable(options?: CallableOptions): (target: unknown, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
14
|
+
export declare function AdminCallable(options?: CallableOptions): (target: unknown, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
15
|
+
export declare function SwaggerCategory(category: string): (target: object, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
16
|
+
export declare function SwaggerTags(...tags: string[]): (target: object, propertyKey: string, _descriptor: PropertyDescriptor) => void;
|
|
17
|
+
export declare function configureServices(target: Function): ConfigureServicesHandler[];
|
|
18
|
+
export declare function initializeServices(target: Function): InitializeServicesHandler[];
|
|
19
|
+
export declare function ConfigureServices(target: Function, _propertyKey: string, descriptor: PropertyDescriptor): void;
|
|
20
|
+
export declare function InitializeServices(target: Function, _propertyKey: string, descriptor: PropertyDescriptor): void;
|
|
21
|
+
export declare function getConfigureServicesHandlers(target: Function): ConfigureServicesHandler[];
|
|
22
|
+
export declare function getInitializeServicesHandlers(target: Function): InitializeServicesHandler[];
|
|
23
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAA2B,iBAAiB,EAAE,mBAAmB,EAAE,eAAe,EAAiB,MAAM,YAAY,CAAC;AAClI,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE1E,KAAK,wBAAwB,GAAG,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACrF,KAAK,yBAAyB,GAAG,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAErF,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,CAAC;AAgBpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,IAIhD,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,CAAC,KAAG,IAAI,CAiBxF;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,IAElD,QAAQ,OAAO,EACf,aAAa,MAAM,EACnB,aAAa,kBAAkB,KAC9B,IAAI,CAkCR;AA0CD,wBAAgB,sBAAsB,IAAI,iBAAiB,EAAE,CAQ5D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,mBAAmB,GAAG,SAAS,CAEjF;AAED,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,CAAC;AAErD,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,YA/FhD,OAAO,eACF,MAAM,eACN,kBAAkB,KAC9B,IAAI,CA8FR;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,YAnGhD,OAAO,eACF,MAAM,eACN,kBAAkB,KAC9B,IAAI,CAkGR;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,eAAoB,YAvG/C,OAAO,eACF,MAAM,eACN,kBAAkB,KAC9B,IAAI,CAsGR;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,YAMpC,MAAM,eACD,MAAM,eACN,kBAAkB,KAC9B,IAAI,CAPR;AAED,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,IAEzC,QAAQ,MAAM,EACd,aAAa,MAAM,EACnB,aAAa,kBAAkB,KAC9B,IAAI,CAQR;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,GAAG,wBAAwB,EAAE,CAE9E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,GAAG,yBAAyB,EAAE,CAEhF;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAO9G;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAO/G;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,QAAQ,GAAG,wBAAwB,EAAE,CAEzF;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,QAAQ,GAAG,yBAAyB,EAAE,CAE3F"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
const SERVICE_METADATA = new Map();
|
|
3
|
+
const PENDING_REGISTRATIONS = new Map();
|
|
4
|
+
const SWAGGER_TAGS_METADATA_KEY = Symbol('beamable:swaggerTags');
|
|
5
|
+
const CONFIGURE_SERVICES_METADATA = new Map();
|
|
6
|
+
const INITIALIZE_SERVICES_METADATA = new Map();
|
|
7
|
+
export function Microservice(name, options = {}) {
|
|
8
|
+
if (!name || !/^[A-Za-z0-9_]+$/.test(name)) {
|
|
9
|
+
throw new Error(`Invalid microservice name "${name}". Only alphanumeric and underscore characters are allowed.`);
|
|
10
|
+
}
|
|
11
|
+
return function decorator(ctor) {
|
|
12
|
+
const qualifiedName = `micro_${name}`;
|
|
13
|
+
const entry = {
|
|
14
|
+
name,
|
|
15
|
+
qualifiedName,
|
|
16
|
+
ctor,
|
|
17
|
+
callables: new Map(),
|
|
18
|
+
options,
|
|
19
|
+
};
|
|
20
|
+
SERVICE_METADATA.set(ctor, entry);
|
|
21
|
+
const pending = PENDING_REGISTRATIONS.get(ctor);
|
|
22
|
+
if (pending) {
|
|
23
|
+
pending.forEach((fn) => fn(entry));
|
|
24
|
+
PENDING_REGISTRATIONS.delete(ctor);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function Callable(options = {}) {
|
|
29
|
+
return function decorator(target, propertyKey, _descriptor) {
|
|
30
|
+
let ctorCandidate;
|
|
31
|
+
if (typeof target === 'function') {
|
|
32
|
+
ctorCandidate = target;
|
|
33
|
+
}
|
|
34
|
+
else if (target !== null && typeof target === 'object') {
|
|
35
|
+
const obj = target;
|
|
36
|
+
ctorCandidate = obj.constructor;
|
|
37
|
+
}
|
|
38
|
+
if (typeof ctorCandidate !== 'function') {
|
|
39
|
+
throw new Error('@Callable can only be applied to methods on a class.');
|
|
40
|
+
}
|
|
41
|
+
const ctor = ctorCandidate;
|
|
42
|
+
const metadataTarget = typeof target === 'function'
|
|
43
|
+
? target
|
|
44
|
+
: target !== null && typeof target === 'object'
|
|
45
|
+
? target
|
|
46
|
+
: undefined;
|
|
47
|
+
if (!metadataTarget) {
|
|
48
|
+
throw new Error('@Callable decorator received an invalid target.');
|
|
49
|
+
}
|
|
50
|
+
const meta = SERVICE_METADATA.get(ctor);
|
|
51
|
+
if (!meta) {
|
|
52
|
+
const queue = PENDING_REGISTRATIONS.get(ctor) ?? [];
|
|
53
|
+
queue.push((lateMeta) => registerCallable(lateMeta, propertyKey, options, metadataTarget));
|
|
54
|
+
PENDING_REGISTRATIONS.set(ctor, queue);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
registerCallable(meta, propertyKey, options, metadataTarget);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function registerCallable(meta, propertyKey, options, metadataTarget) {
|
|
61
|
+
const access = options.access ?? 'public';
|
|
62
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', metadataTarget, propertyKey);
|
|
63
|
+
const route = options.route ?? propertyKey;
|
|
64
|
+
const decoratorTags = Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, metadataTarget, propertyKey) ?? [];
|
|
65
|
+
const combinedTags = options.tags ?? decoratorTags;
|
|
66
|
+
const tags = Array.from(new Set(combinedTags ?? []));
|
|
67
|
+
const metadata = {
|
|
68
|
+
route,
|
|
69
|
+
displayName: propertyKey,
|
|
70
|
+
requireAuth: options.requireAuth ?? access !== 'public',
|
|
71
|
+
requiredScopes: options.requiredScopes ?? defaultScopesForAccess(access),
|
|
72
|
+
useLegacySerialization: options.useLegacySerialization ?? meta.options.useLegacySerialization ?? false,
|
|
73
|
+
parameterTypes: paramTypes ?? [],
|
|
74
|
+
access,
|
|
75
|
+
tags,
|
|
76
|
+
};
|
|
77
|
+
const key = route.toLowerCase();
|
|
78
|
+
if (meta.callables.has(key)) {
|
|
79
|
+
throw new Error(`Duplicate callable route "${route}" on ${meta.ctor.name}.`);
|
|
80
|
+
}
|
|
81
|
+
meta.callables.set(key, metadata);
|
|
82
|
+
}
|
|
83
|
+
function defaultScopesForAccess(access) {
|
|
84
|
+
switch (access) {
|
|
85
|
+
case 'admin':
|
|
86
|
+
return ['admin'];
|
|
87
|
+
case 'server':
|
|
88
|
+
return ['server'];
|
|
89
|
+
default:
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function listRegisteredServices() {
|
|
94
|
+
return Array.from(SERVICE_METADATA.values()).map((entry) => ({
|
|
95
|
+
name: entry.name,
|
|
96
|
+
qualifiedName: entry.qualifiedName,
|
|
97
|
+
ctor: entry.ctor,
|
|
98
|
+
callables: new Map(entry.callables),
|
|
99
|
+
options: entry.options,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
export function getServiceOptions(ctor) {
|
|
103
|
+
return SERVICE_METADATA.get(ctor)?.options;
|
|
104
|
+
}
|
|
105
|
+
export function ClientCallable(options = {}) {
|
|
106
|
+
return Callable({ ...options, access: 'client', requireAuth: true });
|
|
107
|
+
}
|
|
108
|
+
export function ServerCallable(options = {}) {
|
|
109
|
+
return Callable({ ...options, access: 'server', requireAuth: true });
|
|
110
|
+
}
|
|
111
|
+
export function AdminCallable(options = {}) {
|
|
112
|
+
return Callable({ ...options, access: 'admin', requireAuth: true });
|
|
113
|
+
}
|
|
114
|
+
export function SwaggerCategory(category) {
|
|
115
|
+
return SwaggerTags(category);
|
|
116
|
+
}
|
|
117
|
+
export function SwaggerTags(...tags) {
|
|
118
|
+
return function decorator(target, propertyKey, _descriptor) {
|
|
119
|
+
if (tags.length === 0) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const current = Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, target, propertyKey) ?? [];
|
|
123
|
+
const merged = Array.from(new Set([...current, ...tags]));
|
|
124
|
+
Reflect.defineMetadata(SWAGGER_TAGS_METADATA_KEY, merged, target, propertyKey);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function configureServices(target) {
|
|
128
|
+
return CONFIGURE_SERVICES_METADATA.get(target) ?? [];
|
|
129
|
+
}
|
|
130
|
+
export function initializeServices(target) {
|
|
131
|
+
return INITIALIZE_SERVICES_METADATA.get(target) ?? [];
|
|
132
|
+
}
|
|
133
|
+
export function ConfigureServices(target, _propertyKey, descriptor) {
|
|
134
|
+
if (typeof descriptor.value !== 'function') {
|
|
135
|
+
throw new Error('@ConfigureServices can only decorate static methods.');
|
|
136
|
+
}
|
|
137
|
+
const handlers = CONFIGURE_SERVICES_METADATA.get(target) ?? [];
|
|
138
|
+
handlers.push(descriptor.value.bind(target));
|
|
139
|
+
CONFIGURE_SERVICES_METADATA.set(target, handlers);
|
|
140
|
+
}
|
|
141
|
+
export function InitializeServices(target, _propertyKey, descriptor) {
|
|
142
|
+
if (typeof descriptor.value !== 'function') {
|
|
143
|
+
throw new Error('@InitializeServices can only decorate static methods.');
|
|
144
|
+
}
|
|
145
|
+
const handlers = INITIALIZE_SERVICES_METADATA.get(target) ?? [];
|
|
146
|
+
handlers.push(descriptor.value.bind(target));
|
|
147
|
+
INITIALIZE_SERVICES_METADATA.set(target, handlers);
|
|
148
|
+
}
|
|
149
|
+
export function getConfigureServicesHandlers(target) {
|
|
150
|
+
return CONFIGURE_SERVICES_METADATA.get(target) ?? [];
|
|
151
|
+
}
|
|
152
|
+
export function getInitializeServicesHandlers(target) {
|
|
153
|
+
return INITIALIZE_SERVICES_METADATA.get(target) ?? [];
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAS1B,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAsC,CAAC;AACvE,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAA6D,CAAC;AACnG,MAAM,yBAAyB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACjE,MAAM,2BAA2B,GAAG,IAAI,GAAG,EAAwC,CAAC;AACpF,MAAM,4BAA4B,GAAG,IAAI,GAAG,EAAyC,CAAC;AAUtF,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,UAA+B,EAAE;IAC1E,IAAI,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,M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C;AACrD,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAAgB;IAC3D,OAAO,2BAA2B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,MAAgB;IAC5D,OAAO,4BAA4B,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import 'reflect-metadata';\r\nimport type { ServiceCallableMetadata, ServiceDefinition, MicroserviceOptions, CallableOptions, ServiceAccess } from './types.js';\r\nimport type { DependencyBuilder, DependencyScope } from './dependency.js';\r\n\r\ntype ConfigureServicesHandler = (builder: DependencyBuilder) => void | Promise<void>;\r\ntype InitializeServicesHandler = (provider: DependencyScope) => void | Promise<void>;\r\n\r\nexport type { ConfigureServicesHandler, InitializeServicesHandler };\r\n\r\nconst SERVICE_METADATA = new Map<Function, MutableServiceDefinition>();\r\nconst PENDING_REGISTRATIONS = new Map<Function, Array<(meta: MutableServiceDefinition) => void>>();\r\nconst SWAGGER_TAGS_METADATA_KEY = Symbol('beamable:swaggerTags');\r\nconst CONFIGURE_SERVICES_METADATA = new Map<Function, ConfigureServicesHandler[]>();\r\nconst INITIALIZE_SERVICES_METADATA = new Map<Function, InitializeServicesHandler[]>();\r\n\r\ninterface MutableServiceDefinition {\r\n name: string;\r\n qualifiedName: string;\r\n ctor: new (...args: unknown[]) => unknown;\r\n callables: Map<string, ServiceCallableMetadata>;\r\n options: MicroserviceOptions;\r\n}\r\n\r\nexport function Microservice(name: string, options: MicroserviceOptions = {}) {\r\n if (!name || !/^[A-Za-z0-9_]+$/.test(name)) {\r\n throw new Error(`Invalid microservice name \"${name}\". Only alphanumeric and underscore characters are allowed.`);\r\n }\r\n return function decorator<T extends new (...args: unknown[]) => unknown>(ctor: T): void {\r\n const qualifiedName = `micro_${name}`;\r\n const entry: MutableServiceDefinition = {\r\n name,\r\n qualifiedName,\r\n ctor,\r\n callables: new Map(),\r\n options,\r\n };\r\n SERVICE_METADATA.set(ctor, entry);\r\n\r\n const pending = PENDING_REGISTRATIONS.get(ctor);\r\n if (pending) {\r\n pending.forEach((fn) => fn(entry));\r\n PENDING_REGISTRATIONS.delete(ctor);\r\n }\r\n };\r\n}\r\n\r\nexport function Callable(options: CallableOptions = {}) {\r\n return function decorator(\r\n target: unknown,\r\n propertyKey: string,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n let ctorCandidate: unknown;\r\n if (typeof target === 'function') {\r\n ctorCandidate = target;\r\n } else if (target !== null && typeof target === 'object') {\r\n const obj = target as { constructor?: Function };\r\n ctorCandidate = obj.constructor;\r\n }\r\n\r\n if (typeof ctorCandidate !== 'function') {\r\n throw new Error('@Callable can only be applied to methods on a class.');\r\n }\r\n const ctor = ctorCandidate as new (...args: unknown[]) => unknown;\r\n const metadataTarget =\r\n typeof target === 'function'\r\n ? (target as object)\r\n : target !== null && typeof target === 'object'\r\n ? (target as object)\r\n : undefined;\r\n\r\n if (!metadataTarget) {\r\n throw new Error('@Callable decorator received an invalid target.');\r\n }\r\n\r\n const meta = SERVICE_METADATA.get(ctor);\r\n if (!meta) {\r\n const queue = PENDING_REGISTRATIONS.get(ctor) ?? [];\r\n queue.push((lateMeta) => registerCallable(lateMeta, propertyKey, options, metadataTarget));\r\n PENDING_REGISTRATIONS.set(ctor, queue);\r\n return;\r\n }\r\n\r\n registerCallable(meta, propertyKey, options, metadataTarget);\r\n };\r\n}\r\n\r\nfunction registerCallable(\r\n meta: MutableServiceDefinition,\r\n propertyKey: string,\r\n options: CallableOptions,\r\n metadataTarget: object,\r\n): void {\r\n const access: ServiceAccess = options.access ?? 'public';\r\n const paramTypes = Reflect.getMetadata('design:paramtypes', metadataTarget, propertyKey) as ReadonlyArray<unknown> | undefined;\r\n const route = options.route ?? propertyKey;\r\n const decoratorTags = (Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, metadataTarget, propertyKey) as string[] | undefined) ?? [];\r\n const combinedTags = options.tags ?? decoratorTags;\r\n const tags = Array.from(new Set(combinedTags ?? []));\r\n const metadata: ServiceCallableMetadata = {\r\n route,\r\n displayName: propertyKey,\r\n requireAuth: options.requireAuth ?? access !== 'public',\r\n requiredScopes: options.requiredScopes ?? defaultScopesForAccess(access),\r\n useLegacySerialization: options.useLegacySerialization ?? meta.options.useLegacySerialization ?? false,\r\n parameterTypes: paramTypes ?? [],\r\n access,\r\n tags,\r\n };\r\n const key = route.toLowerCase();\r\n if (meta.callables.has(key)) {\r\n throw new Error(`Duplicate callable route \"${route}\" on ${meta.ctor.name}.`);\r\n }\r\n meta.callables.set(key, metadata);\r\n}\r\n\r\nfunction defaultScopesForAccess(access: ServiceAccess): string[] {\r\n switch (access) {\r\n case 'admin':\r\n return ['admin'];\r\n case 'server':\r\n return ['server'];\r\n default:\r\n return [];\r\n }\r\n}\r\n\r\nexport function listRegisteredServices(): ServiceDefinition[] {\r\n return Array.from(SERVICE_METADATA.values()).map((entry) => ({\r\n name: entry.name,\r\n qualifiedName: entry.qualifiedName,\r\n ctor: entry.ctor,\r\n callables: new Map(entry.callables),\r\n options: entry.options,\r\n }));\r\n}\r\n\r\nexport function getServiceOptions(ctor: Function): MicroserviceOptions | undefined {\r\n return SERVICE_METADATA.get(ctor)?.options;\r\n}\r\n\r\nexport type { MicroserviceOptions, CallableOptions };\r\n\r\nexport function ClientCallable(options: CallableOptions = {}) {\r\n return Callable({ ...options, access: 'client', requireAuth: true });\r\n}\r\n\r\nexport function ServerCallable(options: CallableOptions = {}) {\r\n return Callable({ ...options, access: 'server', requireAuth: true });\r\n}\r\n\r\nexport function AdminCallable(options: CallableOptions = {}) {\r\n return Callable({ ...options, access: 'admin', requireAuth: true });\r\n}\r\n\r\nexport function SwaggerCategory(category: string) {\r\n return SwaggerTags(category);\r\n}\r\n\r\nexport function SwaggerTags(...tags: string[]) {\r\n return function decorator(\r\n target: object,\r\n propertyKey: string,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n if (tags.length === 0) {\r\n return;\r\n }\r\n const current = (Reflect.getMetadata(SWAGGER_TAGS_METADATA_KEY, target, propertyKey) as string[] | undefined) ?? [];\r\n const merged = Array.from(new Set([...current, ...tags]));\r\n Reflect.defineMetadata(SWAGGER_TAGS_METADATA_KEY, merged, target, propertyKey);\r\n };\r\n}\r\n\r\nexport function configureServices(target: Function): ConfigureServicesHandler[] {\r\n return CONFIGURE_SERVICES_METADATA.get(target) ?? [];\r\n}\r\n\r\nexport function initializeServices(target: Function): InitializeServicesHandler[] {\r\n return INITIALIZE_SERVICES_METADATA.get(target) ?? [];\r\n}\r\n\r\nexport function ConfigureServices(target: Function, _propertyKey: string, descriptor: PropertyDescriptor): void {\r\n if (typeof descriptor.value !== 'function') {\r\n throw new Error('@ConfigureServices can only decorate static methods.');\r\n }\r\n const handlers = CONFIGURE_SERVICES_METADATA.get(target) ?? [];\r\n handlers.push(descriptor.value.bind(target));\r\n CONFIGURE_SERVICES_METADATA.set(target, handlers);\r\n}\r\n\r\nexport function InitializeServices(target: Function, _propertyKey: string, descriptor: PropertyDescriptor): void {\r\n if (typeof descriptor.value !== 'function') {\r\n throw new Error('@InitializeServices can only decorate static methods.');\r\n }\r\n const handlers = INITIALIZE_SERVICES_METADATA.get(target) ?? [];\r\n handlers.push(descriptor.value.bind(target));\r\n INITIALIZE_SERVICES_METADATA.set(target, handlers);\r\n}\r\n\r\nexport function getConfigureServicesHandlers(target: Function): ConfigureServicesHandler[] {\r\n return CONFIGURE_SERVICES_METADATA.get(target) ?? [];\r\n}\r\n\r\nexport function getInitializeServicesHandlers(target: Function): InitializeServicesHandler[] {\r\n return INITIALIZE_SERVICES_METADATA.get(target) ?? [];\r\n}\r\n"]}
|