@ankhorage/infra 3.1.1 → 3.3.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/CHANGELOG.md +12 -0
- package/README.md +14 -10
- package/dist/adapters/minikube/auth/index.d.ts +2 -1
- package/dist/adapters/minikube/auth/index.d.ts.map +1 -1
- package/dist/adapters/minikube/auth/index.js +6 -3
- package/dist/adapters/minikube/auth/index.js.map +1 -1
- package/dist/adapters/minikube/auth/targetAwareOAuthRuntime.d.ts +7 -0
- package/dist/adapters/minikube/auth/targetAwareOAuthRuntime.d.ts.map +1 -0
- package/dist/adapters/minikube/auth/targetAwareOAuthRuntime.js +104 -0
- package/dist/adapters/minikube/auth/targetAwareOAuthRuntime.js.map +1 -0
- package/dist/adapters/minikube/index.d.ts.map +1 -1
- package/dist/adapters/minikube/index.js +5 -1
- package/dist/adapters/minikube/index.js.map +1 -1
- package/dist/authTargetRedirects.d.ts +12 -0
- package/dist/authTargetRedirects.d.ts.map +1 -0
- package/dist/authTargetRedirects.js +32 -0
- package/dist/authTargetRedirects.js.map +1 -0
- package/dist/project/index.d.ts +3 -1
- package/dist/project/index.d.ts.map +1 -1
- package/dist/project/index.js +3 -1
- package/dist/project/index.js.map +1 -1
- package/dist/projectDatabase.d.ts +5 -0
- package/dist/projectDatabase.d.ts.map +1 -0
- package/dist/projectDatabase.js +22 -0
- package/dist/projectDatabase.js.map +1 -0
- package/dist/projectEnvironment.d.ts +6 -0
- package/dist/projectEnvironment.d.ts.map +1 -0
- package/dist/projectEnvironment.js +45 -0
- package/dist/projectEnvironment.js.map +1 -0
- package/dist/projectInfrastructure.d.ts +16 -0
- package/dist/projectInfrastructure.d.ts.map +1 -1
- package/dist/projectInfrastructure.js +25 -0
- package/dist/projectInfrastructure.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +8 -26
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/minikube/auth/index.ts +8 -4
- package/src/adapters/minikube/auth/targetAwareOAuthRuntime.test.ts +83 -0
- package/src/adapters/minikube/auth/targetAwareOAuthRuntime.ts +136 -0
- package/src/adapters/minikube/index.ts +5 -1
- package/src/authTargetRedirects.test.ts +62 -0
- package/src/authTargetRedirects.ts +46 -0
- package/src/project/index.test.ts +80 -1
- package/src/project/index.ts +4 -0
- package/src/projectDatabase.ts +27 -0
- package/src/projectEnvironment.ts +51 -0
- package/src/projectInfrastructure.ts +44 -0
- package/src/runtime.ts +8 -25
- package/src/types.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectInfrastructure.js","sourceRoot":"","sources":["../src/projectInfrastructure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAC7D,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAmBnC,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAK/C;IACC,MAAM,eAAe,GAAG,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElE,IAAI,IAAI,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;QACzC,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,eAAe;YACzB,OAAO,EAAE;gBACP,MAAM,EAAE,iEAAiE;aAC1E;SACF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/D,MAAM,aAAa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AAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { AppManifest } from '@ankhorage/contracts';\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nimport { generateInfrastructure } from './index.js';\nimport { validateInfraSupport } from './infraValidation.js';\n\nconst INFRA_LEDGER_RELATIVE_PATH = '.ankh/infra-ledger.json';\nconst STUDIO_PROJECT_ID = 'studio';\n\ninterface InfraLedger {\n readonly schemaVersion: 1;\n readonly generatedAt: string;\n readonly target: string;\n readonly files: readonly string[];\n readonly warnings: readonly string[];\n}\n\nexport interface InfraSyncResult {\n readonly generated: number;\n readonly removed: number;\n readonly warnings: readonly string[];\n readonly skipped?: {\n readonly reason: string;\n };\n}\n\nexport async function syncProjectInfrastructure(args: {\n readonly generateInfrastructureImpl?: typeof generateInfrastructure;\n readonly manifest: AppManifest;\n readonly projectId: string;\n readonly projectPath: string;\n}): Promise<InfraSyncResult> {\n const supportWarnings = validateInfraSupport(args.manifest.infra);\n\n if (args.projectId === STUDIO_PROJECT_ID) {\n return {\n generated: 0,\n removed: 0,\n warnings: supportWarnings,\n skipped: {\n reason: 'apps/studio is the dashboard and is not a generated app target.',\n },\n };\n }\n\n const previousLedger = await readInfraLedger(args.projectPath);\n const previousFiles = new Set(previousLedger?.files ?? []);\n\n if (args.manifest.infra.deployment === undefined) {\n const removed = await removeFiles(args.projectPath, previousFiles);\n await removeInfraLedger(args.projectPath);\n return {\n generated: 0,\n removed,\n warnings: supportWarnings,\n };\n }\n\n const generated = (args.generateInfrastructureImpl ?? generateInfrastructure)(\n args.manifest.infra,\n {\n namespaceHint: args.projectId,\n appManifest: args.manifest,\n },\n );\n const combinedWarnings = uniqueStrings([...supportWarnings, ...generated.warnings]);\n const nextFiles = new Set<string>();\n\n for (const file of generated.files) {\n const outputPath = resolveProjectFile(args.projectPath, file.path);\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.writeFile(outputPath, file.content, 'utf8');\n\n if (file.executable === true) {\n await fs.chmod(outputPath, 0o755);\n }\n\n nextFiles.add(file.path);\n }\n\n const staleFiles = new Set([...previousFiles].filter((filePath) => !nextFiles.has(filePath)));\n const removed = await removeFiles(args.projectPath, staleFiles);\n\n await writeInfraLedger(args.projectPath, {\n schemaVersion: 1,\n generatedAt: new Date().toISOString(),\n target: generated.meta.target,\n files: [...nextFiles].sort(),\n warnings: combinedWarnings,\n });\n\n return {\n generated: generated.files.length,\n removed,\n warnings: combinedWarnings,\n };\n}\n\nexport async function resolveProjectInfrastructureTarget(args: {\n readonly manifest: AppManifest;\n readonly projectPath: string;\n}): Promise<string | null> {\n const manifestTarget = args.manifest.infra.deployment?.target;\n if (manifestTarget !== undefined) {\n return manifestTarget;\n }\n\n const ledger = await readInfraLedger(args.projectPath);\n return ledger?.target ?? null;\n}\n\nexport function resolveProjectFile(projectPath: string, filePath: string): string {\n const rootPath = path.resolve(projectPath);\n const resolvedPath = path.resolve(rootPath, filePath);\n const relativePath = path.relative(rootPath, resolvedPath);\n\n if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {\n throw new Error(`Invalid infra output path outside project root: ${filePath}`);\n }\n\n return resolvedPath;\n}\n\nasync function readInfraLedger(projectPath: string): Promise<InfraLedger | null> {\n const ledgerPath = path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH);\n\n try {\n const rawLedger = await fs.readFile(ledgerPath, 'utf8');\n const parsedLedger: unknown = JSON.parse(rawLedger);\n return isInfraLedger(parsedLedger) ? parsedLedger : null;\n } catch {\n return null;\n }\n}\n\nasync function writeInfraLedger(projectPath: string, ledger: InfraLedger): Promise<void> {\n const ledgerPath = path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH);\n await fs.mkdir(path.dirname(ledgerPath), { recursive: true });\n await fs.writeFile(ledgerPath, `${JSON.stringify(ledger, null, 2)}\\n`, 'utf8');\n}\n\nasync function removeInfraLedger(projectPath: string): Promise<void> {\n await fs.rm(path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH), { force: true });\n}\n\nasync function removeFiles(projectPath: string, files: ReadonlySet<string>): Promise<number> {\n let removedFiles = 0;\n\n for (const filePath of files) {\n await fs.rm(resolveProjectFile(projectPath, filePath), { force: true });\n removedFiles += 1;\n }\n\n return removedFiles;\n}\n\nfunction isInfraLedger(value: unknown): value is InfraLedger {\n return (\n isRecord(value) &&\n value.schemaVersion === 1 &&\n typeof value.generatedAt === 'string' &&\n typeof value.target === 'string' &&\n Array.isArray(value.files) &&\n value.files.every((filePath) => typeof filePath === 'string') &&\n Array.isArray(value.warnings) &&\n value.warnings.every((warning) => typeof warning === 'string')\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction uniqueStrings(values: readonly string[]): readonly string[] {\n return [...new Set(values)];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"projectInfrastructure.js","sourceRoot":"","sources":["../src/projectInfrastructure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAC7D,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AA+BnC,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAK/C;IACC,MAAM,eAAe,GAAG,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAElE,IAAI,IAAI,CAAC,SAAS,KAAK,iBAAiB,EAAE,CAAC;QACzC,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,eAAe;YACzB,OAAO,EAAE;gBACP,MAAM,EAAE,iEAAiE;aAC1E;SACF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GA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UAAU,WAAW,CAAC,WAAmB,EAAE,KAA0B;IACxE,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC7B,MAAM,EAAE,CAAC,EAAE,CAAC,kBAAkB,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,YAAY,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,KAAK,CAAC,aAAa,KAAK,CAAC;QACzB,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;QACrC,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,QAAQ,KAAK,QAAQ,CAAC;QAC7D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,aAAa,CAAC,MAAyB;IAC9C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { AppManifest } from '@ankhorage/contracts';\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nimport { generateInfrastructure } from './index.js';\nimport { validateInfraSupport } from './infraValidation.js';\n\nconst INFRA_LEDGER_RELATIVE_PATH = '.ankh/infra-ledger.json';\nconst STUDIO_PROJECT_ID = 'studio';\n\ninterface InfraLedger {\n readonly schemaVersion: 1;\n readonly generatedAt: string;\n readonly target: string;\n readonly files: readonly string[];\n readonly warnings: readonly string[];\n}\n\nexport interface InfraSyncResult {\n readonly generated: number;\n readonly removed: number;\n readonly warnings: readonly string[];\n readonly skipped?: {\n readonly reason: string;\n };\n}\n\nexport interface InfraProjectInspection {\n readonly generated: boolean;\n readonly generatedAt: string | null;\n readonly hasDeployment: boolean;\n readonly target: string | null;\n readonly trackedFiles: number;\n readonly warnings: readonly string[];\n readonly skipped?: {\n readonly reason: string;\n };\n}\n\nexport async function syncProjectInfrastructure(args: {\n readonly generateInfrastructureImpl?: typeof generateInfrastructure;\n readonly manifest: AppManifest;\n readonly projectId: string;\n readonly projectPath: string;\n}): Promise<InfraSyncResult> {\n const supportWarnings = validateInfraSupport(args.manifest.infra);\n\n if (args.projectId === STUDIO_PROJECT_ID) {\n return {\n generated: 0,\n removed: 0,\n warnings: supportWarnings,\n skipped: {\n reason: 'apps/studio is the dashboard and is not a generated app target.',\n },\n };\n }\n\n const previousLedger = await readInfraLedger(args.projectPath);\n const previousFiles = new Set(previousLedger?.files ?? []);\n\n if (args.manifest.infra.deployment === undefined) {\n const removed = await removeFiles(args.projectPath, previousFiles);\n await removeInfraLedger(args.projectPath);\n return {\n generated: 0,\n removed,\n warnings: supportWarnings,\n };\n }\n\n const generated = (args.generateInfrastructureImpl ?? generateInfrastructure)(\n args.manifest.infra,\n {\n namespaceHint: args.projectId,\n appManifest: args.manifest,\n },\n );\n const combinedWarnings = uniqueStrings([...supportWarnings, ...generated.warnings]);\n const nextFiles = new Set<string>();\n\n for (const file of generated.files) {\n const outputPath = resolveProjectFile(args.projectPath, file.path);\n await fs.mkdir(path.dirname(outputPath), { recursive: true });\n await fs.writeFile(outputPath, file.content, 'utf8');\n\n if (file.executable === true) {\n await fs.chmod(outputPath, 0o755);\n }\n\n nextFiles.add(file.path);\n }\n\n const staleFiles = new Set([...previousFiles].filter((filePath) => !nextFiles.has(filePath)));\n const removed = await removeFiles(args.projectPath, staleFiles);\n\n await writeInfraLedger(args.projectPath, {\n schemaVersion: 1,\n generatedAt: new Date().toISOString(),\n target: generated.meta.target,\n files: [...nextFiles].sort(),\n warnings: combinedWarnings,\n });\n\n return {\n generated: generated.files.length,\n removed,\n warnings: combinedWarnings,\n };\n}\n\nexport async function inspectProjectInfrastructure(args: {\n readonly manifest: AppManifest;\n readonly projectId: string;\n readonly projectPath: string;\n}): Promise<InfraProjectInspection> {\n const supportWarnings = validateInfraSupport(args.manifest.infra);\n\n if (args.projectId === STUDIO_PROJECT_ID) {\n return {\n generated: false,\n generatedAt: null,\n hasDeployment: false,\n target: null,\n trackedFiles: 0,\n warnings: supportWarnings,\n skipped: {\n reason: 'apps/studio is the dashboard and is not a generated app target.',\n },\n };\n }\n\n const ledger = await readInfraLedger(args.projectPath);\n return {\n generated: ledger !== null,\n generatedAt: ledger?.generatedAt ?? null,\n hasDeployment: args.manifest.infra.deployment !== undefined,\n target: args.manifest.infra.deployment?.target ?? ledger?.target ?? null,\n trackedFiles: ledger?.files.length ?? 0,\n warnings: uniqueStrings([...supportWarnings, ...(ledger?.warnings ?? [])]),\n };\n}\n\nexport async function resolveProjectInfrastructureTarget(args: {\n readonly manifest: AppManifest;\n readonly projectPath: string;\n}): Promise<string | null> {\n const manifestTarget = args.manifest.infra.deployment?.target;\n if (manifestTarget !== undefined) {\n return manifestTarget;\n }\n\n const ledger = await readInfraLedger(args.projectPath);\n return ledger?.target ?? null;\n}\n\nexport function resolveProjectFile(projectPath: string, filePath: string): string {\n const rootPath = path.resolve(projectPath);\n const resolvedPath = path.resolve(rootPath, filePath);\n const relativePath = path.relative(rootPath, resolvedPath);\n\n if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {\n throw new Error(`Invalid infra output path outside project root: ${filePath}`);\n }\n\n return resolvedPath;\n}\n\nasync function readInfraLedger(projectPath: string): Promise<InfraLedger | null> {\n const ledgerPath = path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH);\n\n try {\n const rawLedger = await fs.readFile(ledgerPath, 'utf8');\n const parsedLedger: unknown = JSON.parse(rawLedger);\n return isInfraLedger(parsedLedger) ? parsedLedger : null;\n } catch {\n return null;\n }\n}\n\nasync function writeInfraLedger(projectPath: string, ledger: InfraLedger): Promise<void> {\n const ledgerPath = path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH);\n await fs.mkdir(path.dirname(ledgerPath), { recursive: true });\n await fs.writeFile(ledgerPath, `${JSON.stringify(ledger, null, 2)}\\n`, 'utf8');\n}\n\nasync function removeInfraLedger(projectPath: string): Promise<void> {\n await fs.rm(path.join(projectPath, INFRA_LEDGER_RELATIVE_PATH), { force: true });\n}\n\nasync function removeFiles(projectPath: string, files: ReadonlySet<string>): Promise<number> {\n let removedFiles = 0;\n\n for (const filePath of files) {\n await fs.rm(resolveProjectFile(projectPath, filePath), { force: true });\n removedFiles += 1;\n }\n\n return removedFiles;\n}\n\nfunction isInfraLedger(value: unknown): value is InfraLedger {\n return (\n isRecord(value) &&\n value.schemaVersion === 1 &&\n typeof value.generatedAt === 'string' &&\n typeof value.target === 'string' &&\n Array.isArray(value.files) &&\n value.files.every((filePath) => typeof filePath === 'string') &&\n Array.isArray(value.warnings) &&\n value.warnings.every((warning) => typeof warning === 'string')\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction uniqueStrings(values: readonly string[]): readonly string[] {\n return [...new Set(values)];\n}\n"]}
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"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AAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAe7B;AAED,wBAAsB,uCAAuC,CAAC,IAAI,EAAE;IAClE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAkBhC;AAED,wBAAsB,qBAAqB,CAAC,IAAI,EAAE;IAChD,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhB;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,MAAM,CAET"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import { promises as fs } from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
+
import { readProjectInfrastructureEnvironment } from './projectEnvironment.js';
|
|
4
5
|
export class InfraScriptExecutionError extends Error {
|
|
5
6
|
exitCode;
|
|
6
7
|
stderr;
|
|
@@ -27,14 +28,14 @@ export async function runProjectInfrastructureLifecycle(args) {
|
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
export async function resolveProjectInfrastructurePortForward(args) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const localPort = parsePositivePort(
|
|
31
|
+
const environment = await readProjectInfrastructureEnvironment({
|
|
32
|
+
keys: ['APP_PORT_FORWARD_LOCAL_PORT'],
|
|
33
|
+
projectPath: args.projectPath,
|
|
34
|
+
target: args.target,
|
|
35
|
+
});
|
|
36
|
+
const localPort = parsePositivePort(environment.APP_PORT_FORWARD_LOCAL_PORT);
|
|
36
37
|
if (localPort === null) {
|
|
37
|
-
throw new Error(
|
|
38
|
+
throw new Error('Generated Infra did not provide a valid APP_PORT_FORWARD_LOCAL_PORT. Regenerate infrastructure first.');
|
|
38
39
|
}
|
|
39
40
|
return {
|
|
40
41
|
localPort,
|
|
@@ -108,25 +109,6 @@ function createExitError(scriptPath, exitCode, stdout, stderr) {
|
|
|
108
109
|
stdout,
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
|
-
async function readSimpleEnvMap(filePath) {
|
|
112
|
-
const out = new Map();
|
|
113
|
-
const content = await fs.readFile(filePath, 'utf8');
|
|
114
|
-
for (const line of content.split(/\r?\n/u)) {
|
|
115
|
-
const trimmed = line.trim();
|
|
116
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
117
|
-
continue;
|
|
118
|
-
const separator = trimmed.indexOf('=');
|
|
119
|
-
if (separator <= 0)
|
|
120
|
-
continue;
|
|
121
|
-
const key = trimmed.slice(0, separator).trim();
|
|
122
|
-
const value = trimmed
|
|
123
|
-
.slice(separator + 1)
|
|
124
|
-
.trim()
|
|
125
|
-
.replace(/^['"]|['"]$/g, '');
|
|
126
|
-
out.set(key, value);
|
|
127
|
-
}
|
|
128
|
-
return out;
|
|
129
|
-
}
|
|
130
112
|
function parsePositivePort(value) {
|
|
131
113
|
if (value === undefined)
|
|
132
114
|
return null;
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","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esContent":["import { spawn } from 'child_process';\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nimport type { InfraCommandContext } from './commandContext.js';\n\nexport type InfraLifecycleScript = 'destroy' | 'down' | 'port-forward' | 'reset' | 'status' | 'up';\n\nexport interface InfraScriptOutput {\n readonly stderr: string;\n readonly stdout: string;\n}\n\nexport interface InfraPortForwardInfo {\n readonly localPort: number;\n readonly url: string;\n}\n\nexport class InfraScriptExecutionError extends Error {\n readonly exitCode: number | null;\n readonly stderr: string;\n readonly stdout: string;\n\n constructor(args: {\n readonly exitCode: number | null;\n readonly message: string;\n readonly stderr: string;\n readonly stdout: string;\n }) {\n super(args.message);\n this.name = 'InfraScriptExecutionError';\n this.exitCode = args.exitCode;\n this.stderr = args.stderr;\n this.stdout = args.stdout;\n }\n}\n\nexport async function runProjectInfrastructureLifecycle(args: {\n readonly args?: readonly string[];\n readonly env?: Readonly<Record<string, string | undefined>>;\n readonly onStderr?: (chunk: string) => void;\n readonly onStdout?: (chunk: string) => void;\n readonly projectId: string;\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): Promise<InfraScriptOutput> {\n const scriptPath = resolveProjectInfraScriptPath(args);\n if (!(await pathExists(scriptPath))) {\n throw new Error(\n `Infra script not found: ${scriptPath}. Run infra generate for project '${args.projectId}' first.`,\n );\n }\n\n return runShellScript({\n args: args.args ?? [],\n env: args.env ?? process.env,\n onStderr: args.onStderr,\n onStdout: args.onStdout,\n scriptPath,\n });\n}\n\nexport async function resolveProjectInfrastructurePortForward(args: {\n readonly projectPath: string;\n readonly target: string;\n}): Promise<InfraPortForwardInfo> {\n const infraRoot = path.join(args.projectPath, 'infra', args.target);\n const envPath = path.join(infraRoot, '.env');\n const fallbackEnvPath = path.join(infraRoot, '.env.example');\n const sourcePath = (await pathExists(envPath)) ? envPath : fallbackEnvPath;\n const env = await readSimpleEnvMap(sourcePath);\n const localPort = parsePositivePort(env.get('APP_PORT_FORWARD_LOCAL_PORT'));\n\n if (localPort === null) {\n throw new Error(\n `Generated Infra did not provide a valid APP_PORT_FORWARD_LOCAL_PORT in ${sourcePath}. Regenerate infrastructure first.`,\n );\n }\n\n return {\n localPort,\n url: `http://127.0.0.1:${localPort}`,\n };\n}\n\nexport async function runProjectInfraScript(args: {\n readonly context: InfraCommandContext;\n readonly projectId: string;\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): Promise<void> {\n await runProjectInfrastructureLifecycle({\n env: args.context.env,\n onStderr: (chunk) => args.context.writeStderr(chunk),\n onStdout: (chunk) => args.context.writeStdout(chunk),\n projectId: args.projectId,\n projectPath: args.projectPath,\n script: args.script,\n target: args.target,\n });\n}\n\nexport function resolveProjectInfraScriptPath(args: {\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): string {\n return path.join(args.projectPath, getInfraScriptsDirectory(args.target), `${args.script}.sh`);\n}\n\nfunction getInfraScriptsDirectory(target: string): string {\n switch (target) {\n case 'minikube':\n return 'infra/minikube/scripts';\n default:\n throw new Error(`Unsupported deployment target for infra scripts: ${target}`);\n }\n}\n\nasync function runShellScript(args: {\n readonly args: readonly string[];\n readonly env: Readonly<Record<string, string | undefined>>;\n readonly onStderr?: (chunk: string) => void;\n readonly onStdout?: (chunk: string) => void;\n readonly scriptPath: string;\n}): Promise<InfraScriptOutput> {\n return new Promise<InfraScriptOutput>((resolve, reject) => {\n const child = spawn('bash', [args.scriptPath, ...args.args], {\n cwd: path.dirname(args.scriptPath),\n env: { ...args.env },\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n\n let stdout = '';\n let stderr = '';\n child.stdout.setEncoding('utf8');\n child.stderr.setEncoding('utf8');\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk;\n args.onStdout?.(chunk);\n });\n child.stderr.on('data', (chunk: string) => {\n stderr += chunk;\n args.onStderr?.(chunk);\n });\n child.once('error', (error) =>\n reject(createStartError(args.scriptPath, error, stdout, stderr)),\n );\n child.once('close', (exitCode) => {\n if (exitCode === 0) {\n resolve({ stderr, stdout });\n return;\n }\n reject(createExitError(args.scriptPath, exitCode, stdout, stderr));\n });\n });\n}\n\nfunction createStartError(\n scriptPath: string,\n error: Error,\n stdout: string,\n stderr: string,\n): InfraScriptExecutionError {\n return new InfraScriptExecutionError({\n exitCode: null,\n message: `Failed to start infra script '${scriptPath}': ${error.message}`,\n stderr,\n stdout,\n });\n}\n\nfunction createExitError(\n scriptPath: string,\n exitCode: number | null,\n stdout: string,\n stderr: string,\n): InfraScriptExecutionError {\n return new InfraScriptExecutionError({\n exitCode,\n message: `Infra script '${scriptPath}' exited with code ${exitCode ?? 'unknown'}.`,\n stderr,\n stdout,\n });\n}\n\nasync function readSimpleEnvMap(filePath: string): Promise<Map<string, string>> {\n const out = new Map<string, string>();\n const content = await fs.readFile(filePath, 'utf8');\n for (const line of content.split(/\\r?\\n/u)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) continue;\n const separator = trimmed.indexOf('=');\n if (separator <= 0) continue;\n const key = trimmed.slice(0, separator).trim();\n const value = trimmed\n .slice(separator + 1)\n .trim()\n .replace(/^['\"]|['\"]$/g, '');\n out.set(key, value);\n }\n return out;\n}\n\nfunction parsePositivePort(value: string | undefined): number | null {\n if (value === undefined) return null;\n const parsed = Number.parseInt(value.trim(), 10);\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 65_535 ? parsed : null;\n}\n\nasync function pathExists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,oCAAoC,EAAE,MAAM,yBAAyB,CAAC;A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AAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CACvB,UAAkB,EAClB,KAAY,EACZ,MAAc,EACd,MAAc;IAEd,OAAO,IAAI,yBAAyB,CAAC;QACnC,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,iCAAiC,UAAU,MAAM,KAAK,CAAC,OAAO,EAAE;QACzE,MAAM;QACN,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CACtB,UAAkB,EAClB,QAAuB,EACvB,MAAc,EACd,MAAc;IAEd,OAAO,IAAI,yBAAyB,CAAC;QACnC,QAAQ;QACR,OAAO,EAAE,iBAAiB,UAAU,sBAAsB,QAAQ,IAAI,SAAS,GAAG;QAClF,MAAM;QACN,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAyB;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACrF,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { spawn } from 'child_process';\nimport { promises as fs } from 'fs';\nimport path from 'path';\n\nimport type { InfraCommandContext } from './commandContext.js';\nimport { readProjectInfrastructureEnvironment } from './projectEnvironment.js';\n\nexport type InfraLifecycleScript = 'destroy' | 'down' | 'port-forward' | 'reset' | 'status' | 'up';\n\nexport interface InfraScriptOutput {\n readonly stderr: string;\n readonly stdout: string;\n}\n\nexport interface InfraPortForwardInfo {\n readonly localPort: number;\n readonly url: string;\n}\n\nexport class InfraScriptExecutionError extends Error {\n readonly exitCode: number | null;\n readonly stderr: string;\n readonly stdout: string;\n\n constructor(args: {\n readonly exitCode: number | null;\n readonly message: string;\n readonly stderr: string;\n readonly stdout: string;\n }) {\n super(args.message);\n this.name = 'InfraScriptExecutionError';\n this.exitCode = args.exitCode;\n this.stderr = args.stderr;\n this.stdout = args.stdout;\n }\n}\n\nexport async function runProjectInfrastructureLifecycle(args: {\n readonly args?: readonly string[];\n readonly env?: Readonly<Record<string, string | undefined>>;\n readonly onStderr?: (chunk: string) => void;\n readonly onStdout?: (chunk: string) => void;\n readonly projectId: string;\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): Promise<InfraScriptOutput> {\n const scriptPath = resolveProjectInfraScriptPath(args);\n if (!(await pathExists(scriptPath))) {\n throw new Error(\n `Infra script not found: ${scriptPath}. Run infra generate for project '${args.projectId}' first.`,\n );\n }\n\n return runShellScript({\n args: args.args ?? [],\n env: args.env ?? process.env,\n onStderr: args.onStderr,\n onStdout: args.onStdout,\n scriptPath,\n });\n}\n\nexport async function resolveProjectInfrastructurePortForward(args: {\n readonly projectPath: string;\n readonly target: string;\n}): Promise<InfraPortForwardInfo> {\n const environment = await readProjectInfrastructureEnvironment({\n keys: ['APP_PORT_FORWARD_LOCAL_PORT'],\n projectPath: args.projectPath,\n target: args.target,\n });\n const localPort = parsePositivePort(environment.APP_PORT_FORWARD_LOCAL_PORT);\n\n if (localPort === null) {\n throw new Error(\n 'Generated Infra did not provide a valid APP_PORT_FORWARD_LOCAL_PORT. Regenerate infrastructure first.',\n );\n }\n\n return {\n localPort,\n url: `http://127.0.0.1:${localPort}`,\n };\n}\n\nexport async function runProjectInfraScript(args: {\n readonly context: InfraCommandContext;\n readonly projectId: string;\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): Promise<void> {\n await runProjectInfrastructureLifecycle({\n env: args.context.env,\n onStderr: (chunk) => args.context.writeStderr(chunk),\n onStdout: (chunk) => args.context.writeStdout(chunk),\n projectId: args.projectId,\n projectPath: args.projectPath,\n script: args.script,\n target: args.target,\n });\n}\n\nexport function resolveProjectInfraScriptPath(args: {\n readonly projectPath: string;\n readonly script: InfraLifecycleScript;\n readonly target: string;\n}): string {\n return path.join(args.projectPath, getInfraScriptsDirectory(args.target), `${args.script}.sh`);\n}\n\nfunction getInfraScriptsDirectory(target: string): string {\n switch (target) {\n case 'minikube':\n return 'infra/minikube/scripts';\n default:\n throw new Error(`Unsupported deployment target for infra scripts: ${target}`);\n }\n}\n\nasync function runShellScript(args: {\n readonly args: readonly string[];\n readonly env: Readonly<Record<string, string | undefined>>;\n readonly onStderr?: (chunk: string) => void;\n readonly onStdout?: (chunk: string) => void;\n readonly scriptPath: string;\n}): Promise<InfraScriptOutput> {\n return new Promise<InfraScriptOutput>((resolve, reject) => {\n const child = spawn('bash', [args.scriptPath, ...args.args], {\n cwd: path.dirname(args.scriptPath),\n env: { ...args.env },\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n\n let stdout = '';\n let stderr = '';\n child.stdout.setEncoding('utf8');\n child.stderr.setEncoding('utf8');\n child.stdout.on('data', (chunk: string) => {\n stdout += chunk;\n args.onStdout?.(chunk);\n });\n child.stderr.on('data', (chunk: string) => {\n stderr += chunk;\n args.onStderr?.(chunk);\n });\n child.once('error', (error) =>\n reject(createStartError(args.scriptPath, error, stdout, stderr)),\n );\n child.once('close', (exitCode) => {\n if (exitCode === 0) {\n resolve({ stderr, stdout });\n return;\n }\n reject(createExitError(args.scriptPath, exitCode, stdout, stderr));\n });\n });\n}\n\nfunction createStartError(\n scriptPath: string,\n error: Error,\n stdout: string,\n stderr: string,\n): InfraScriptExecutionError {\n return new InfraScriptExecutionError({\n exitCode: null,\n message: `Failed to start infra script '${scriptPath}': ${error.message}`,\n stderr,\n stdout,\n });\n}\n\nfunction createExitError(\n scriptPath: string,\n exitCode: number | null,\n stdout: string,\n stderr: string,\n): InfraScriptExecutionError {\n return new InfraScriptExecutionError({\n exitCode,\n message: `Infra script '${scriptPath}' exited with code ${exitCode ?? 'unknown'}.`,\n stderr,\n stdout,\n });\n}\n\nfunction parsePositivePort(value: string | undefined): number | null {\n if (value === undefined) return null;\n const parsed = Number.parseInt(value.trim(), 10);\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 65_535 ? parsed : null;\n}\n\nasync function pathExists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface InfrastructureGenerationOptions {
|
|
|
30
30
|
/**
|
|
31
31
|
* Optional app-level context used by provider/engine-specific generators.
|
|
32
32
|
*/
|
|
33
|
-
readonly appManifest?: Pick<AppManifest, 'generatedApis' | 'infra' | 'metadata' | 'navigator' | 'screens' | 'settings'>;
|
|
33
|
+
readonly appManifest?: Pick<AppManifest, 'deploy' | 'generatedApis' | 'infra' | 'metadata' | 'navigator' | 'screens' | 'settings'>;
|
|
34
34
|
}
|
|
35
35
|
export interface InfraGenerationInput {
|
|
36
36
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,C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EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,KAAK,oBAAoB,GAAG,WAAW,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AAE3F,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAC1C,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppManifest, InfraManifest } from '@ankhorage/contracts';\n\nexport interface GeneratedInfrastructureFile {\n /**\n * Path relative to the target app root.\n */\n readonly path: string;\n readonly content: string;\n readonly executable?: boolean;\n}\n\nexport interface GeneratedPackageDependency {\n readonly name: string;\n readonly version: string;\n readonly reason: string;\n}\n\nexport interface InfrastructureGenerationMeta {\n readonly target: NonNullable<InfraManifest['deployment']>['target'];\n readonly providers: readonly string[];\n}\n\nexport interface InfrastructureGenerationResult {\n readonly files: readonly GeneratedInfrastructureFile[];\n readonly warnings: readonly string[];\n readonly meta: InfrastructureGenerationMeta;\n readonly dependencies: readonly GeneratedPackageDependency[];\n}\n\nexport interface InfrastructureGenerationOptions {\n /**\n * Optional namespace hint from caller context, such as app slug or project id.\n */\n readonly namespaceHint?: string;\n /**\n * Optional app-level context used by provider/engine-specific generators.\n */\n readonly appManifest?: Pick<\n AppManifest,\n 'generatedApis' | 'infra' | 'metadata' | 'navigator' | 'screens' | 'settings'\n >;\n}\n\nexport interface InfraGenerationInput {\n /**\n * Infra manifest section from an app manifest.\n */\n readonly manifest: InfraManifestInput;\n /**\n * Optional root used by callers that want to keep output intent alongside generation.\n * The generator itself still returns relative file paths and does not write to disk.\n */\n readonly outputRoot?: string;\n readonly options?: InfrastructureGenerationOptions;\n}\n\nexport type InfraGenerationOptions = InfrastructureGenerationOptions;\nexport type InfraGenerationResult = InfrastructureGenerationResult;\nexport type GeneratedFile = GeneratedInfrastructureFile;\nexport type PackageDependency = GeneratedPackageDependency;\n\nexport interface InfraDiagnostic {\n readonly severity: 'warning';\n readonly message: string;\n}\n\ntype InfraStorageProvider = NonNullable<InfraManifest['storage']>['provider'] | 'supabase';\n\ninterface InfraStorageSpecInput {\n readonly provider: InfraStorageProvider;\n readonly buckets: readonly string[];\n}\n\n/**\n * Infra-local manifest input type.\n *\n * This is intentionally broader than `@ankhorage/contracts` to allow adapters to support\n * additional providers before the shared contracts package officially includes them.\n */\nexport type InfraManifestInput = Omit<InfraManifest, 'storage'> & {\n readonly storage?: InfraStorageSpecInput;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AppManifest, InfraManifest } from '@ankhorage/contracts';\n\nexport interface GeneratedInfrastructureFile {\n /**\n * Path relative to the target app root.\n */\n readonly path: string;\n readonly content: string;\n readonly executable?: boolean;\n}\n\nexport interface GeneratedPackageDependency {\n readonly name: string;\n readonly version: string;\n readonly reason: string;\n}\n\nexport interface InfrastructureGenerationMeta {\n readonly target: NonNullable<InfraManifest['deployment']>['target'];\n readonly providers: readonly string[];\n}\n\nexport interface InfrastructureGenerationResult {\n readonly files: readonly GeneratedInfrastructureFile[];\n readonly warnings: readonly string[];\n readonly meta: InfrastructureGenerationMeta;\n readonly dependencies: readonly GeneratedPackageDependency[];\n}\n\nexport interface InfrastructureGenerationOptions {\n /**\n * Optional namespace hint from caller context, such as app slug or project id.\n */\n readonly namespaceHint?: string;\n /**\n * Optional app-level context used by provider/engine-specific generators.\n */\n readonly appManifest?: Pick<\n AppManifest,\n 'deploy' | 'generatedApis' | 'infra' | 'metadata' | 'navigator' | 'screens' | 'settings'\n >;\n}\n\nexport interface InfraGenerationInput {\n /**\n * Infra manifest section from an app manifest.\n */\n readonly manifest: InfraManifestInput;\n /**\n * Optional root used by callers that want to keep output intent alongside generation.\n * The generator itself still returns relative file paths and does not write to disk.\n */\n readonly outputRoot?: string;\n readonly options?: InfrastructureGenerationOptions;\n}\n\nexport type InfraGenerationOptions = InfrastructureGenerationOptions;\nexport type InfraGenerationResult = InfrastructureGenerationResult;\nexport type GeneratedFile = GeneratedInfrastructureFile;\nexport type PackageDependency = GeneratedPackageDependency;\n\nexport interface InfraDiagnostic {\n readonly severity: 'warning';\n readonly message: string;\n}\n\ntype InfraStorageProvider = NonNullable<InfraManifest['storage']>['provider'] | 'supabase';\n\ninterface InfraStorageSpecInput {\n readonly provider: InfraStorageProvider;\n readonly buckets: readonly string[];\n}\n\n/**\n * Infra-local manifest input type.\n *\n * This is intentionally broader than `@ankhorage/contracts` to allow adapters to support\n * additional providers before the shared contracts package officially includes them.\n */\nexport type InfraManifestInput = Omit<InfraManifest, 'storage'> & {\n readonly storage?: InfraStorageSpecInput;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/infra",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"description": "Project-aware infrastructure generation library and executable Ankh provider for Ankhorage.",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/infra#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"openapi"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ankhorage/contracts": "^7.
|
|
38
|
+
"@ankhorage/contracts": "^7.7.0",
|
|
39
39
|
"@ankhorage/supabase-vault": "^0.2.4"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type { InfraManifestInput } from '../../../types';
|
|
1
|
+
import type { InfraManifestInput, InfrastructureGenerationOptions } from '../../../types';
|
|
2
2
|
import { emptyMinikubeArtifacts, type MinikubeAdapterArtifacts } from '../contracts';
|
|
3
|
-
import { generateSupabaseOAuthRuntimeArtifacts } from './oauthRuntime';
|
|
4
3
|
import { generateSupabaseAuthArtifacts } from './supabase';
|
|
4
|
+
import { generateTargetAwareSupabaseOAuthRuntimeArtifacts } from './targetAwareOAuthRuntime';
|
|
5
5
|
|
|
6
6
|
export function generateAuthProviderArtifacts(args: {
|
|
7
|
+
appManifest: InfrastructureGenerationOptions['appManifest'];
|
|
7
8
|
manifest: InfraManifestInput;
|
|
8
9
|
namespace: string;
|
|
9
10
|
}): MinikubeAdapterArtifacts {
|
|
10
|
-
const { manifest, namespace } = args;
|
|
11
|
+
const { appManifest, manifest, namespace } = args;
|
|
11
12
|
const { auth } = manifest;
|
|
12
13
|
|
|
13
14
|
if (!auth) {
|
|
@@ -21,7 +22,10 @@ export function generateAuthProviderArtifacts(args: {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const providerArtifacts = generateSupabaseAuthArtifacts({ manifest, namespace });
|
|
24
|
-
const oauthArtifacts =
|
|
25
|
+
const oauthArtifacts = generateTargetAwareSupabaseOAuthRuntimeArtifacts({
|
|
26
|
+
appManifest,
|
|
27
|
+
manifest,
|
|
28
|
+
});
|
|
25
29
|
|
|
26
30
|
return {
|
|
27
31
|
files: [...providerArtifacts.files, ...oauthArtifacts.files],
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { InfraManifest } from '@ankhorage/contracts';
|
|
2
|
+
import { describe, expect, test } from 'bun:test';
|
|
3
|
+
|
|
4
|
+
import { createAppManifest } from '../../../testSupport';
|
|
5
|
+
import { generateTargetAwareSupabaseOAuthRuntimeArtifacts } from './targetAwareOAuthRuntime';
|
|
6
|
+
|
|
7
|
+
describe('target-aware Supabase OAuth runtime', () => {
|
|
8
|
+
test('removes the legacy native redirect environment source', () => {
|
|
9
|
+
const artifacts = generateTargetAwareSupabaseOAuthRuntimeArtifacts({
|
|
10
|
+
appManifest: undefined,
|
|
11
|
+
manifest: createOAuthManifest(),
|
|
12
|
+
});
|
|
13
|
+
const [lifecycle] = artifacts.providerLifecycle;
|
|
14
|
+
const command = lifecycle?.reconciliationCommands[0]?.command ?? '';
|
|
15
|
+
|
|
16
|
+
expect(command).toContain('http://127.0.0.1:*/auth/callback');
|
|
17
|
+
expect(command).toContain('http://localhost:*/auth/callback');
|
|
18
|
+
expect(command).not.toContain('OAUTH_NATIVE_REDIRECT_URLS');
|
|
19
|
+
expect(artifacts.warnings).toEqual([
|
|
20
|
+
'OAuth deploy.targets is missing; Infra keeps Web-local redirects only until canonical targets are persisted.',
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('emits only the enabled native callback for a native-only app', () => {
|
|
25
|
+
const appManifest = {
|
|
26
|
+
...createAppManifest('native-oauth'),
|
|
27
|
+
deploy: {
|
|
28
|
+
targets: {
|
|
29
|
+
web: { enabled: false },
|
|
30
|
+
android: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
package: 'com.ankh.native',
|
|
33
|
+
scheme: 'ankh-native',
|
|
34
|
+
},
|
|
35
|
+
ios: {
|
|
36
|
+
enabled: false,
|
|
37
|
+
bundleIdentifier: 'com.ankh.native',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const artifacts = generateTargetAwareSupabaseOAuthRuntimeArtifacts({
|
|
43
|
+
appManifest,
|
|
44
|
+
manifest: createOAuthManifest(),
|
|
45
|
+
});
|
|
46
|
+
const [lifecycle] = artifacts.providerLifecycle;
|
|
47
|
+
const command = lifecycle?.reconciliationCommands[0]?.command ?? '';
|
|
48
|
+
const status = lifecycle?.statusChecks[0]?.command ?? '';
|
|
49
|
+
|
|
50
|
+
expect(command).toContain("oauth_redirect_allow_list='ankh-native://auth/callback'");
|
|
51
|
+
expect(command).not.toContain('oauth_site_url');
|
|
52
|
+
expect(command).not.toContain('localhost:*');
|
|
53
|
+
expect(command).not.toContain('127.0.0.1:*');
|
|
54
|
+
expect(command).not.toContain('OAUTH_NATIVE_REDIRECT_URLS');
|
|
55
|
+
expect(status).toContain('app-callback: disabled (web target)');
|
|
56
|
+
expect(status).toContain('native-callbacks: ankh-native://auth/callback');
|
|
57
|
+
expect(artifacts.warnings).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function createOAuthManifest(): InfraManifest {
|
|
62
|
+
return {
|
|
63
|
+
deployment: { target: 'minikube', monitoring: false },
|
|
64
|
+
auth: {
|
|
65
|
+
scope: 'global',
|
|
66
|
+
provider: 'supabase',
|
|
67
|
+
oauth: {
|
|
68
|
+
enabled: true,
|
|
69
|
+
callbackRoute: '/auth/callback',
|
|
70
|
+
providers: [
|
|
71
|
+
{
|
|
72
|
+
id: 'google',
|
|
73
|
+
enabled: true,
|
|
74
|
+
credentialsRef: 'auth/oauth/google',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
database: { provider: 'supabase', tier: 'dev' },
|
|
80
|
+
secretStore: { provider: 'supabase-vault' },
|
|
81
|
+
modules: [],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { getLocalAuthRedirectPatterns, normalizeAuthCallbackRoute } from '../../../authRedirects';
|
|
2
|
+
import { resolveAuthTargetRedirectModel } from '../../../authTargetRedirects';
|
|
3
|
+
import type { InfraManifestInput, InfrastructureGenerationOptions } from '../../../types';
|
|
4
|
+
import type { MinikubeAdapterArtifacts, MinikubeProviderLifecycle } from '../contracts';
|
|
5
|
+
import { generateSupabaseOAuthRuntimeArtifacts } from './oauthRuntime';
|
|
6
|
+
|
|
7
|
+
interface RedirectPolicy {
|
|
8
|
+
readonly callbackRoute: string;
|
|
9
|
+
readonly localPatterns: readonly string[];
|
|
10
|
+
readonly nativeRedirectUris: readonly string[];
|
|
11
|
+
readonly webEnabled: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function generateTargetAwareSupabaseOAuthRuntimeArtifacts(args: {
|
|
15
|
+
readonly appManifest: InfrastructureGenerationOptions['appManifest'];
|
|
16
|
+
readonly manifest: InfraManifestInput;
|
|
17
|
+
}): MinikubeAdapterArtifacts {
|
|
18
|
+
const baseArtifacts = generateSupabaseOAuthRuntimeArtifacts(args.manifest);
|
|
19
|
+
if (!baseArtifacts.providerLifecycle.some((lifecycle) => lifecycle.id === 'supabase-auth')) {
|
|
20
|
+
return baseArtifacts;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const callbackRoute = normalizeAuthCallbackRoute(args.manifest.auth?.oauth?.callbackRoute ?? '');
|
|
24
|
+
const targets = resolveAuthTargetRedirectModel({
|
|
25
|
+
callbackRoute,
|
|
26
|
+
targets: args.appManifest?.deploy?.targets,
|
|
27
|
+
});
|
|
28
|
+
const policy: RedirectPolicy = {
|
|
29
|
+
callbackRoute,
|
|
30
|
+
localPatterns: targets.webEnabled ? getLocalAuthRedirectPatterns(callbackRoute) : [],
|
|
31
|
+
nativeRedirectUris: targets.nativeRedirectUris,
|
|
32
|
+
webEnabled: targets.webEnabled,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...baseArtifacts,
|
|
37
|
+
files: baseArtifacts.files.map((file) =>
|
|
38
|
+
file.path === 'infra/minikube/auth/oauth-runtime.md'
|
|
39
|
+
? { ...file, content: getTargetAwareGuide(policy) }
|
|
40
|
+
: file,
|
|
41
|
+
),
|
|
42
|
+
providerLifecycle: baseArtifacts.providerLifecycle.map((lifecycle) =>
|
|
43
|
+
lifecycle.id === 'supabase-auth' ? applyRedirectPolicy(lifecycle, policy) : lifecycle,
|
|
44
|
+
),
|
|
45
|
+
warnings: [...baseArtifacts.warnings, ...targets.warnings],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function applyRedirectPolicy(
|
|
50
|
+
lifecycle: MinikubeProviderLifecycle,
|
|
51
|
+
policy: RedirectPolicy,
|
|
52
|
+
): MinikubeProviderLifecycle {
|
|
53
|
+
return {
|
|
54
|
+
...lifecycle,
|
|
55
|
+
reconciliationCommands: lifecycle.reconciliationCommands.map((entry) => ({
|
|
56
|
+
...entry,
|
|
57
|
+
command: rewriteReconciliationCommand(entry.command, policy),
|
|
58
|
+
})),
|
|
59
|
+
statusChecks: lifecycle.statusChecks.map((entry) => ({
|
|
60
|
+
...entry,
|
|
61
|
+
command: getTargetAwareStatusCommand(policy),
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function rewriteReconciliationCommand(command: string, policy: RedirectPolicy): string {
|
|
67
|
+
const legacyPatterns = getLocalAuthRedirectPatterns(policy.callbackRoute).join(',');
|
|
68
|
+
const legacyPolicy = `oauth_redirect_allow_list="\${oauth_site_url},\${oauth_site_url}/\${oauth_callback_path},${legacyPatterns}"
|
|
69
|
+
if [[ -n "\${OAUTH_NATIVE_REDIRECT_URLS:-}" ]]; then
|
|
70
|
+
oauth_redirect_allow_list="\${oauth_redirect_allow_list},\${OAUTH_NATIVE_REDIRECT_URLS}"
|
|
71
|
+
fi`;
|
|
72
|
+
const staticRedirects = [...policy.localPatterns, ...policy.nativeRedirectUris].join(',');
|
|
73
|
+
const suffix = staticRedirects ? `,${staticRedirects}` : '';
|
|
74
|
+
const canonicalPolicy = policy.webEnabled
|
|
75
|
+
? `oauth_redirect_allow_list="\${oauth_site_url},\${oauth_site_url}/\${oauth_callback_path}${suffix}"`
|
|
76
|
+
: `oauth_redirect_allow_list='${staticRedirects}'`;
|
|
77
|
+
let rewritten = replaceOnce(command, legacyPolicy, canonicalPolicy);
|
|
78
|
+
|
|
79
|
+
if (!policy.webEnabled) {
|
|
80
|
+
rewritten = replaceOnce(rewritten, 'oauth_site_url="${SITE_URL%/}"\n', '');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return rewritten;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getTargetAwareStatusCommand(policy: RedirectPolicy): string {
|
|
87
|
+
const appCallback = policy.webEnabled
|
|
88
|
+
? `if [[ -n "\${SITE_URL:-}" ]]; then
|
|
89
|
+
echo "- provider supabase-auth/app-callback: \${SITE_URL%/}/\${oauth_callback_path}"
|
|
90
|
+
else
|
|
91
|
+
echo "- provider supabase-auth/app-callback: unavailable"
|
|
92
|
+
fi`
|
|
93
|
+
: 'echo "- provider supabase-auth/app-callback: disabled (web target)"';
|
|
94
|
+
const localPatterns = policy.localPatterns.join(',') || 'none';
|
|
95
|
+
const nativeRedirects = policy.nativeRedirectUris.join(',') || 'none';
|
|
96
|
+
|
|
97
|
+
return `oauth_callback_route='${policy.callbackRoute}'
|
|
98
|
+
oauth_callback_path="\${oauth_callback_route#/}"
|
|
99
|
+
if [[ -n "\${API_EXTERNAL_URL:-}" ]]; then
|
|
100
|
+
echo "- provider supabase-auth/provider-callback: \${API_EXTERNAL_URL%/}/callback"
|
|
101
|
+
else
|
|
102
|
+
echo "- provider supabase-auth/provider-callback: unavailable"
|
|
103
|
+
fi
|
|
104
|
+
${appCallback}
|
|
105
|
+
echo "- provider supabase-auth/local-callback-patterns: ${localPatterns}"
|
|
106
|
+
echo "- provider supabase-auth/native-callbacks: ${nativeRedirects}"`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getTargetAwareGuide(policy: RedirectPolicy): string {
|
|
110
|
+
const nativeRedirects = policy.nativeRedirectUris.length
|
|
111
|
+
? policy.nativeRedirectUris.map((uri) => `- \`${uri}\``).join('\n')
|
|
112
|
+
: '- none';
|
|
113
|
+
|
|
114
|
+
return `# Supabase OAuth Runtime Reconciliation
|
|
115
|
+
|
|
116
|
+
The provider callback remains project-owned. GoTrue-to-app redirects use the configured callback
|
|
117
|
+
route \`${policy.callbackRoute}\` and are derived from \`AppManifest.deploy.targets\`.
|
|
118
|
+
|
|
119
|
+
- Web target: ${policy.webEnabled ? 'enabled' : 'disabled'}
|
|
120
|
+
- Native callbacks:
|
|
121
|
+
${nativeRedirects}
|
|
122
|
+
|
|
123
|
+
Local loopback patterns are emitted only for an enabled Web target. Native callbacks come only
|
|
124
|
+
from enabled Android/iOS target schemes; no environment variable or slug-derived identity can add
|
|
125
|
+
a native callback. Provider credential values remain sourced from trusted secret resolution.
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function replaceOnce(value: string, search: string, replacement: string): string {
|
|
130
|
+
if (!value.includes(search)) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
'Supabase OAuth redirect reconciliation template drifted from its canonical form.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return value.replace(search, replacement);
|
|
136
|
+
}
|
|
@@ -33,7 +33,11 @@ export function generateMinikubeInfra(
|
|
|
33
33
|
const appSlug = validateCanonicalAppSlug(options.appManifest?.metadata.slug);
|
|
34
34
|
const namespace = APP_NAMESPACE;
|
|
35
35
|
|
|
36
|
-
const authArtifacts = generateAuthProviderArtifacts({
|
|
36
|
+
const authArtifacts = generateAuthProviderArtifacts({
|
|
37
|
+
appManifest: options.appManifest,
|
|
38
|
+
manifest,
|
|
39
|
+
namespace,
|
|
40
|
+
});
|
|
37
41
|
const authzArtifacts = generateAuthorizationArtifacts({
|
|
38
42
|
manifest,
|
|
39
43
|
namespace,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AppDeployTargets } from '@ankhorage/contracts/deploy';
|
|
2
|
+
import { describe, expect, test } from 'bun:test';
|
|
3
|
+
|
|
4
|
+
import { resolveAuthTargetRedirectModel } from './authTargetRedirects';
|
|
5
|
+
|
|
6
|
+
describe('resolveAuthTargetRedirectModel', () => {
|
|
7
|
+
test('derives enabled native callbacks and deduplicates shared schemes', () => {
|
|
8
|
+
const targets: AppDeployTargets = {
|
|
9
|
+
web: { enabled: true },
|
|
10
|
+
android: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
package: 'com.ankh.demo',
|
|
13
|
+
scheme: 'ankh-demo',
|
|
14
|
+
},
|
|
15
|
+
ios: {
|
|
16
|
+
enabled: true,
|
|
17
|
+
bundleIdentifier: 'com.ankh.demo',
|
|
18
|
+
scheme: 'ankh-demo',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
expect(resolveAuthTargetRedirectModel({ callbackRoute: '/auth/callback', targets })).toEqual({
|
|
23
|
+
nativeRedirectUris: ['ankh-demo://auth/callback'],
|
|
24
|
+
warnings: [],
|
|
25
|
+
webEnabled: true,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('omits disabled targets and warns instead of guessing missing native schemes', () => {
|
|
30
|
+
const targets: AppDeployTargets = {
|
|
31
|
+
web: { enabled: false },
|
|
32
|
+
android: {
|
|
33
|
+
enabled: false,
|
|
34
|
+
package: 'com.ankh.demo',
|
|
35
|
+
},
|
|
36
|
+
ios: {
|
|
37
|
+
enabled: true,
|
|
38
|
+
bundleIdentifier: 'com.ankh.demo',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const result = resolveAuthTargetRedirectModel({ callbackRoute: '/auth/callback', targets });
|
|
43
|
+
|
|
44
|
+
expect(result.nativeRedirectUris).toEqual([]);
|
|
45
|
+
expect(result.webEnabled).toBe(false);
|
|
46
|
+
expect(result.warnings).toEqual([
|
|
47
|
+
'OAuth ios target is enabled but deploy.targets.ios.scheme is missing; native callback omitted.',
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('keeps the pre-target manifest path Web-only and explicit', () => {
|
|
52
|
+
expect(
|
|
53
|
+
resolveAuthTargetRedirectModel({ callbackRoute: '/auth/callback', targets: undefined }),
|
|
54
|
+
).toEqual({
|
|
55
|
+
nativeRedirectUris: [],
|
|
56
|
+
warnings: [
|
|
57
|
+
'OAuth deploy.targets is missing; Infra keeps Web-local redirects only until canonical targets are persisted.',
|
|
58
|
+
],
|
|
59
|
+
webEnabled: true,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AppDeployTargets } from '@ankhorage/contracts/deploy';
|
|
2
|
+
|
|
3
|
+
interface AuthTargetRedirectModel {
|
|
4
|
+
readonly nativeRedirectUris: readonly string[];
|
|
5
|
+
readonly warnings: readonly string[];
|
|
6
|
+
readonly webEnabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function resolveAuthTargetRedirectModel(args: {
|
|
10
|
+
readonly callbackRoute: string;
|
|
11
|
+
readonly targets: AppDeployTargets | undefined;
|
|
12
|
+
}): AuthTargetRedirectModel {
|
|
13
|
+
if (args.targets === undefined) {
|
|
14
|
+
return {
|
|
15
|
+
nativeRedirectUris: [],
|
|
16
|
+
warnings: [
|
|
17
|
+
'OAuth deploy.targets is missing; Infra keeps Web-local redirects only until canonical targets are persisted.',
|
|
18
|
+
],
|
|
19
|
+
webEnabled: true,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const callbackPath = args.callbackRoute.replace(/^\/+/u, '');
|
|
24
|
+
const nativeRedirectUris: string[] = [];
|
|
25
|
+
const warnings: string[] = [];
|
|
26
|
+
|
|
27
|
+
for (const [targetId, target] of [
|
|
28
|
+
['android', args.targets.android],
|
|
29
|
+
['ios', args.targets.ios],
|
|
30
|
+
] as const) {
|
|
31
|
+
if (target?.enabled !== true) continue;
|
|
32
|
+
if (target.scheme === undefined) {
|
|
33
|
+
warnings.push(
|
|
34
|
+
`OAuth ${targetId} target is enabled but deploy.targets.${targetId}.scheme is missing; native callback omitted.`,
|
|
35
|
+
);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
nativeRedirectUris.push(`${target.scheme}://${callbackPath}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
nativeRedirectUris: [...new Set(nativeRedirectUris)],
|
|
43
|
+
warnings,
|
|
44
|
+
webEnabled: args.targets.web?.enabled === true,
|
|
45
|
+
};
|
|
46
|
+
}
|