@ebay-dt/bonfire-next 0.2.0-alpha.16 → 0.2.0-alpha.18
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/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +4 -3
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/prototype-source-link.d.ts.map +1 -1
- package/dist/server/prototype-source-link.js +3 -2
- package/dist/server/prototype-source-link.js.map +1 -1
- package/dist/server/repository-actions.d.ts +0 -2
- package/dist/server/repository-actions.d.ts.map +1 -1
- package/dist/server/repository-actions.js +1 -23
- package/dist/server/repository-actions.js.map +1 -1
- package/package.json +5 -5
- package/dist/server/entry-coordinator.d.ts +0 -40
- package/dist/server/entry-coordinator.d.ts.map +0 -1
- package/dist/server/entry-coordinator.js +0 -90
- package/dist/server/entry-coordinator.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-bonfire-next.d.ts","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,OAAO,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAW/B,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE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2DhE","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: {\n url: string;\n prototypeDirectory: string;\n primaryBranch: string;\n };\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const gitMode = parseGitModeSetting(\n options.gitMode ?? process.env.BF_GIT_MODE,\n );\n const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;\n if (\n options.prototypeLifecycle !== undefined &&\n ((gitMode === \"manual\" && injectedLifecycleMode !== \"manual\") ||\n (injectedLifecycleMode !== undefined &&\n injectedLifecycleMode !== gitMode))\n ) {\n throw new TypeError(\n gitMode === \"manual\"\n ? \"prototypeLifecycle must declare manual mode when gitMode is manual\"\n : \"prototypeLifecycle gitMode does not match configured gitMode\",\n );\n }\n const session = createSessionAdapter({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const githubCli =\n options.githubCli ??\n new GitHubCliClient({ hostname: config.auth.github.hostname });\n const getSession = session.getSession;\n const prototypeCatalog =\n options.prototypeCatalog ??\n new PrototypeCatalog({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n themeRegistry: config.themes,\n });\n const lifecycle =\n options.prototypeLifecycle ??\n (production\n ? null\n : new LocalPrototypeLifecycle({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n primaryBranch: options.primaryBranch,\n remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n primaryBranch: options.primaryBranch,\n });\n const style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n ...(sourceRepository === undefined ? {} : { sourceRepository }),\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n git: {\n ...getGitManagementCapabilities(gitMode),\n ...(production\n ? {\n filesystemLifecycle: false,\n gitObservation: false,\n save: false,\n discard: false,\n getUpdates: false,\n deploy: false,\n }\n : {}),\n },\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n repository: repositoryActions,\n agents: prototypeAgentActions,\n routes: { ...prototypeRoutes, repository: repositoryRoutes },\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-bonfire-next.d.ts","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,OAAO,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAW/B,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,eAAe,CAAC,EAAE,yBAAyB,CAAC;IAC5C,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,yBAAyB,CAAC;CAChC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE;QACT,KAAK,EAAE,aAAa,CAAC;KACtB,CAAC;IACF,WAAW,EAAE;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;QAC7B,gBAAgB,CAAC,EAAE;YACjB,GAAG,EAAE,MAAM,CAAC;YACZ,kBAAkB,EAAE,MAAM,CAAC;YAC3B,aAAa,EAAE,MAAM,CAAC;SACvB,CAAC;KACH,CAAC;CACH,CAAC;AAQF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAkJvB,OAAO,CAAC,cAAc,CAAC;2CA0BhD,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;EA2DhE","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n resolvePrimaryBranch,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: {\n url: string;\n prototypeDirectory: string;\n primaryBranch: string;\n };\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const primaryBranch = resolvePrimaryBranch(options.primaryBranch);\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const gitMode = parseGitModeSetting(\n options.gitMode ?? process.env.BF_GIT_MODE,\n );\n const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;\n if (\n options.prototypeLifecycle !== undefined &&\n ((gitMode === \"manual\" && injectedLifecycleMode !== \"manual\") ||\n (injectedLifecycleMode !== undefined &&\n injectedLifecycleMode !== gitMode))\n ) {\n throw new TypeError(\n gitMode === \"manual\"\n ? \"prototypeLifecycle must declare manual mode when gitMode is manual\"\n : \"prototypeLifecycle gitMode does not match configured gitMode\",\n );\n }\n const session = createSessionAdapter({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const githubCli =\n options.githubCli ??\n new GitHubCliClient({ hostname: config.auth.github.hostname });\n const getSession = session.getSession;\n const prototypeCatalog =\n options.prototypeCatalog ??\n new PrototypeCatalog({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n themeRegistry: config.themes,\n });\n const lifecycle =\n options.prototypeLifecycle ??\n (production\n ? null\n : new LocalPrototypeLifecycle({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n primaryBranch,\n remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n primaryBranch,\n });\n const style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n ...(sourceRepository === undefined ? {} : { sourceRepository }),\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n git: {\n ...getGitManagementCapabilities(gitMode),\n ...(production\n ? {\n filesystemLifecycle: false,\n gitObservation: false,\n save: false,\n discard: false,\n getUpdates: false,\n deploy: false,\n }\n : {}),\n },\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n repository: repositoryActions,\n agents: prototypeAgentActions,\n routes: { ...prototypeRoutes, repository: repositoryRoutes },\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, resolve } from "node:path";
|
|
2
|
-
import { defineConfig, getGitManagementCapabilities, parseAutomaticBranchSwitchSetting, parseGitModeSetting, } from "@ebay-dt/bonfire-core";
|
|
2
|
+
import { defineConfig, getGitManagementCapabilities, parseAutomaticBranchSwitchSetting, parseGitModeSetting, resolvePrimaryBranch, } from "@ebay-dt/bonfire-core";
|
|
3
3
|
import { GitHubCliClient, LocalPrototypeLifecycle, PrototypeAgentService, PrototypeCatalog, resolvePrototypeCatalogPaths, } from "@ebay-dt/bonfire-node";
|
|
4
4
|
import { cache } from "react";
|
|
5
5
|
import { createAuthProxy } from "./auth-boundary.js";
|
|
@@ -17,6 +17,7 @@ import { getPrototypeSourceRepository } from "./prototype-source-link.js";
|
|
|
17
17
|
const APP_HEADER_BLOCK_SIZE_PROPERTY = "--app-header-block-size";
|
|
18
18
|
const APP_HEADER_PRESENT_BLOCK_SIZE = "2.5rem";
|
|
19
19
|
export function createBonfireNext(options) {
|
|
20
|
+
const primaryBranch = resolvePrimaryBranch(options.primaryBranch);
|
|
20
21
|
const config = defineConfig({
|
|
21
22
|
appId: options.appId,
|
|
22
23
|
name: options.name,
|
|
@@ -61,7 +62,7 @@ export function createBonfireNext(options) {
|
|
|
61
62
|
: new LocalPrototypeLifecycle({
|
|
62
63
|
repositoryRoot: options.repositoryRoot,
|
|
63
64
|
prototypeRoot: options.prototypeRoot,
|
|
64
|
-
primaryBranch
|
|
65
|
+
primaryBranch,
|
|
65
66
|
remote: options.remote,
|
|
66
67
|
automaticBranchSwitch,
|
|
67
68
|
gitMode,
|
|
@@ -149,7 +150,7 @@ export function createBonfireNext(options) {
|
|
|
149
150
|
repositoryRoot: options.repositoryRoot,
|
|
150
151
|
prototypeRoot: options.prototypeRoot,
|
|
151
152
|
hostname: config.auth.github.hostname,
|
|
152
|
-
primaryBranch
|
|
153
|
+
primaryBranch,
|
|
153
154
|
});
|
|
154
155
|
const style = {
|
|
155
156
|
[APP_HEADER_BLOCK_SIZE_PROPERTY]: user === null ? "0px" : APP_HEADER_PRESENT_BLOCK_SIZE,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-bonfire-next.js","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,iCAAiC,EACjC,mBAAmB,GAKpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,GAO7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,qCAAqC,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,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a;QACpC,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC,CAAC;IACH,OAAO;QACL,UAAU,EAAE;YACV,iBAAiB;YACjB,aAAa;YACb,oBAAoB;YACpB,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAC9D,YAAY,EAAE;gBACZ,UAAU,EAAE,mBAAmB;gBAC/B,GAAG,EAAE;oBACH,GAAG,4BAA4B,CAAC,OAAO,CAAC;oBACxC,GAAG,CAAC,UAAU;wBACZ,CAAC,CAAC;4BACE,mBAAmB,EAAE,KAAK;4BAC1B,cAAc,EAAE,KAAK;4BACrB,IAAI,EAAE,KAAK;4BACX,OAAO,EAAE,KAAK;4BACd,UAAU,EAAE,KAAK;4BACjB,MAAM,EAAE,KAAK;yBACd;wBACH,CAAC,CAAC,EAAE,CAAC;iBACR;aAC8B;YACjC,SAAS;YACT,OAAO,EAAE,gBAAgB;YACzB,UAAU,EAAE,iBAAiB;YAC7B,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,EAAE,GAAG,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE;SAC7D;QACD,IAAI,EAAE;YACJ,UAAU;YACV,cAAc;YACd,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: {\n url: string;\n prototypeDirectory: string;\n primaryBranch: string;\n };\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const gitMode = parseGitModeSetting(\n options.gitMode ?? process.env.BF_GIT_MODE,\n );\n const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;\n if (\n options.prototypeLifecycle !== undefined &&\n ((gitMode === \"manual\" && injectedLifecycleMode !== \"manual\") ||\n (injectedLifecycleMode !== undefined &&\n injectedLifecycleMode !== gitMode))\n ) {\n throw new TypeError(\n gitMode === \"manual\"\n ? \"prototypeLifecycle must declare manual mode when gitMode is manual\"\n : \"prototypeLifecycle gitMode does not match configured gitMode\",\n );\n }\n const session = createSessionAdapter({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const githubCli =\n options.githubCli ??\n new GitHubCliClient({ hostname: config.auth.github.hostname });\n const getSession = session.getSession;\n const prototypeCatalog =\n options.prototypeCatalog ??\n new PrototypeCatalog({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n themeRegistry: config.themes,\n });\n const lifecycle =\n options.prototypeLifecycle ??\n (production\n ? null\n : new LocalPrototypeLifecycle({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n primaryBranch: options.primaryBranch,\n remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n primaryBranch: options.primaryBranch,\n });\n const style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n ...(sourceRepository === undefined ? {} : { sourceRepository }),\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n git: {\n ...getGitManagementCapabilities(gitMode),\n ...(production\n ? {\n filesystemLifecycle: false,\n gitObservation: false,\n save: false,\n discard: false,\n getUpdates: false,\n deploy: false,\n }\n : {}),\n },\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n repository: repositoryActions,\n agents: prototypeAgentActions,\n routes: { ...prototypeRoutes, repository: repositoryRoutes },\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
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,UAAU;wBACZ,CAAC,CAAC;4BACE,mBAAmB,EAAE,KAAK;4BAC1B,cAAc,EAAE,KAAK;4BACrB,IAAI,EAAE,KAAK;4BACX,OAAO,EAAE,KAAK;4BACd,UAAU,EAAE,KAAK;4BACjB,MAAM,EAAE,KAAK;yBACd;wBACH,CAAC,CAAC,EAAE,CAAC;iBACR;aAC8B;YACjC,SAAS;YACT,OAAO,EAAE,gBAAgB;YACzB,UAAU,EAAE,iBAAiB;YAC7B,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,EAAE,GAAG,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE;SAC7D;QACD,IAAI,EAAE;YACJ,UAAU;YACV,cAAc;YACd,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n resolvePrimaryBranch,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: {\n url: string;\n prototypeDirectory: string;\n primaryBranch: string;\n };\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const primaryBranch = resolvePrimaryBranch(options.primaryBranch);\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const gitMode = parseGitModeSetting(\n options.gitMode ?? process.env.BF_GIT_MODE,\n );\n const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;\n if (\n options.prototypeLifecycle !== undefined &&\n ((gitMode === \"manual\" && injectedLifecycleMode !== \"manual\") ||\n (injectedLifecycleMode !== undefined &&\n injectedLifecycleMode !== gitMode))\n ) {\n throw new TypeError(\n gitMode === \"manual\"\n ? \"prototypeLifecycle must declare manual mode when gitMode is manual\"\n : \"prototypeLifecycle gitMode does not match configured gitMode\",\n );\n }\n const session = createSessionAdapter({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const githubCli =\n options.githubCli ??\n new GitHubCliClient({ hostname: config.auth.github.hostname });\n const getSession = session.getSession;\n const prototypeCatalog =\n options.prototypeCatalog ??\n new PrototypeCatalog({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n themeRegistry: config.themes,\n });\n const lifecycle =\n options.prototypeLifecycle ??\n (production\n ? null\n : new LocalPrototypeLifecycle({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n primaryBranch,\n remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n primaryBranch,\n });\n const style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n ...(sourceRepository === undefined ? {} : { sourceRepository }),\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n git: {\n ...getGitManagementCapabilities(gitMode),\n ...(production\n ? {\n filesystemLifecycle: false,\n gitObservation: false,\n save: false,\n discard: false,\n getUpdates: false,\n deploy: false,\n }\n : {}),\n },\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n repository: repositoryActions,\n agents: prototypeAgentActions,\n routes: { ...prototypeRoutes, repository: repositoryRoutes },\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-source-link.d.ts","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AASA,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAmCf;AAED,wBAAsB,4BAA4B,CAAC,OAAO,EAAE;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"prototype-source-link.d.ts","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AASA,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAmCf;AAED,wBAAsB,4BAA4B,CAAC,OAAO,EAAE;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CACT;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAC/E,CA0BA","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { resolvePrimaryBranch } from \"@ebay-dt/bonfire-core\";\nimport { resolvePrototypeCatalogPaths } from \"@ebay-dt/bonfire-node\";\n\nconst execFileAsync = promisify(execFile);\nconst GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;\n\n/** Only return a canonical HTTPS URL on the configured GitHub host. */\nexport function gitHubRepositoryUrl(\n remote: string,\n hostname: string,\n): string | null {\n const value = remote.trim();\n let pathname: string;\n if (value.startsWith(`git@${hostname}:`)) {\n pathname = value.slice(`git@${hostname}:`.length);\n } else {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (\n parsed.hostname !== hostname ||\n ![\"https:\", \"ssh:\"].includes(parsed.protocol) ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.password !== \"\" ||\n (parsed.protocol === \"ssh:\"\n ? parsed.username !== \"git\"\n : parsed.username !== \"\")\n ) {\n return null;\n }\n pathname = parsed.pathname.replace(/^\\//u, \"\");\n }\n const segments = pathname.replace(/\\.git$/u, \"\").split(\"/\");\n if (\n segments.length !== 2 ||\n segments.some((segment) => !GITHUB_NAME.test(segment))\n ) {\n return null;\n }\n return `https://${hostname}/${segments[0]}/${segments[1]}`;\n}\n\nexport async function getPrototypeSourceRepository(options: {\n repositoryRoot: string;\n prototypeRoot?: string;\n hostname: string;\n primaryBranch?: string;\n}): Promise<\n { url: string; prototypeDirectory: string; primaryBranch: string } | undefined\n> {\n const primaryBranch = resolvePrimaryBranch(options.primaryBranch);\n try {\n const { stdout } = await execFileAsync(\n \"git\",\n [\"-C\", options.repositoryRoot, \"config\", \"--get\", \"remote.origin.url\"],\n { timeout: 2_000, maxBuffer: 4_096 },\n );\n const url = gitHubRepositoryUrl(stdout, options.hostname);\n if (url === null) return undefined;\n const paths = resolvePrototypeCatalogPaths(options);\n const prototypeDirectory = relative(\n paths.repositoryRoot,\n paths.prototypeRoot,\n )\n .split(sep)\n .join(\"/\");\n return {\n url,\n prototypeDirectory,\n primaryBranch,\n };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { relative, sep } from "node:path";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
|
+
import { resolvePrimaryBranch } from "@ebay-dt/bonfire-core";
|
|
4
5
|
import { resolvePrototypeCatalogPaths } from "@ebay-dt/bonfire-node";
|
|
5
6
|
const execFileAsync = promisify(execFile);
|
|
6
7
|
const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;
|
|
7
|
-
const DEFAULT_PRIMARY_BRANCH = "main";
|
|
8
8
|
/** Only return a canonical HTTPS URL on the configured GitHub host. */
|
|
9
9
|
export function gitHubRepositoryUrl(remote, hostname) {
|
|
10
10
|
const value = remote.trim();
|
|
@@ -41,6 +41,7 @@ export function gitHubRepositoryUrl(remote, hostname) {
|
|
|
41
41
|
return `https://${hostname}/${segments[0]}/${segments[1]}`;
|
|
42
42
|
}
|
|
43
43
|
export async function getPrototypeSourceRepository(options) {
|
|
44
|
+
const primaryBranch = resolvePrimaryBranch(options.primaryBranch);
|
|
44
45
|
try {
|
|
45
46
|
const { stdout } = await execFileAsync("git", ["-C", options.repositoryRoot, "config", "--get", "remote.origin.url"], { timeout: 2_000, maxBuffer: 4_096 });
|
|
46
47
|
const url = gitHubRepositoryUrl(stdout, options.hostname);
|
|
@@ -53,7 +54,7 @@ export async function getPrototypeSourceRepository(options) {
|
|
|
53
54
|
return {
|
|
54
55
|
url,
|
|
55
56
|
prototypeDirectory,
|
|
56
|
-
primaryBranch
|
|
57
|
+
primaryBranch,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-source-link.js","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAC1C,MAAM,WAAW,GAAG,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"prototype-source-link.js","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;A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AkB;YAClB,aAAa;SACd,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { resolvePrimaryBranch } from \"@ebay-dt/bonfire-core\";\nimport { resolvePrototypeCatalogPaths } from \"@ebay-dt/bonfire-node\";\n\nconst execFileAsync = promisify(execFile);\nconst GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;\n\n/** Only return a canonical HTTPS URL on the configured GitHub host. */\nexport function gitHubRepositoryUrl(\n remote: string,\n hostname: string,\n): string | null {\n const value = remote.trim();\n let pathname: string;\n if (value.startsWith(`git@${hostname}:`)) {\n pathname = value.slice(`git@${hostname}:`.length);\n } else {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (\n parsed.hostname !== hostname ||\n ![\"https:\", \"ssh:\"].includes(parsed.protocol) ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.password !== \"\" ||\n (parsed.protocol === \"ssh:\"\n ? parsed.username !== \"git\"\n : parsed.username !== \"\")\n ) {\n return null;\n }\n pathname = parsed.pathname.replace(/^\\//u, \"\");\n }\n const segments = pathname.replace(/\\.git$/u, \"\").split(\"/\");\n if (\n segments.length !== 2 ||\n segments.some((segment) => !GITHUB_NAME.test(segment))\n ) {\n return null;\n }\n return `https://${hostname}/${segments[0]}/${segments[1]}`;\n}\n\nexport async function getPrototypeSourceRepository(options: {\n repositoryRoot: string;\n prototypeRoot?: string;\n hostname: string;\n primaryBranch?: string;\n}): Promise<\n { url: string; prototypeDirectory: string; primaryBranch: string } | undefined\n> {\n const primaryBranch = resolvePrimaryBranch(options.primaryBranch);\n try {\n const { stdout } = await execFileAsync(\n \"git\",\n [\"-C\", options.repositoryRoot, \"config\", \"--get\", \"remote.origin.url\"],\n { timeout: 2_000, maxBuffer: 4_096 },\n );\n const url = gitHubRepositoryUrl(stdout, options.hostname);\n if (url === null) return undefined;\n const paths = resolvePrototypeCatalogPaths(options);\n const prototypeDirectory = relative(\n paths.repositoryRoot,\n paths.prototypeRoot,\n )\n .split(sep)\n .join(\"/\");\n return {\n url,\n prototypeDirectory,\n primaryBranch,\n };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -18,8 +18,6 @@ export type RepositoryActionsOptions = {
|
|
|
18
18
|
lifecycle: RepositoryLifecycle | null;
|
|
19
19
|
now?: () => number;
|
|
20
20
|
checkThrottleMs?: number;
|
|
21
|
-
entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;
|
|
22
|
-
waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;
|
|
23
21
|
};
|
|
24
22
|
export declare function createRepositoryActions(options: RepositoryActionsOptions): RepositoryActions;
|
|
25
23
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-actions.d.ts","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrD,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAChE,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3E,CAAC;AAEF,KAAK,mBAAmB,GAAG,IAAI,CAC7B,kBAAkB,EAChB,SAAS,GACT,sBAAsB,GACtB,wBAAwB,GACxB,eAAe,CAClB,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB,CAAC,EAAE,yBAAyB,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;IACtE,2BAA2B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E,CAAC;AAyBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAqPnB","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repository-act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E,yBAAyB,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAcF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAsOnB","sourcesContent":["import {\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths = preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies =\n await options.lifecycle.prepareDependencies(dependencyPaths);\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lifecycleFailure, lifecycleSuccess, } from "@ebay-dt/bonfire-core";
|
|
2
2
|
const DEFAULT_CHECK_THROTTLE_MS = 30_000;
|
|
3
3
|
function compatible(options) {
|
|
4
4
|
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
@@ -6,16 +6,6 @@ function compatible(options) {
|
|
|
6
6
|
function unavailable() {
|
|
7
7
|
return lifecycleFailure("forbidden");
|
|
8
8
|
}
|
|
9
|
-
function checkingSummary(mode) {
|
|
10
|
-
return {
|
|
11
|
-
mode,
|
|
12
|
-
readiness: "checking",
|
|
13
|
-
updateCheck: "checking",
|
|
14
|
-
changes: [],
|
|
15
|
-
attention: [],
|
|
16
|
-
capabilities: getGitManagementCapabilities(mode),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
9
|
export function createRepositoryActions(options) {
|
|
20
10
|
const now = options.now ?? Date.now;
|
|
21
11
|
const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;
|
|
@@ -44,9 +34,6 @@ export function createRepositoryActions(options) {
|
|
|
44
34
|
const identity = await identityOrFailure();
|
|
45
35
|
if (identity === null)
|
|
46
36
|
return lifecycleFailure("unauthenticated");
|
|
47
|
-
if (options.entrySynchronizationInFlight?.(identity)) {
|
|
48
|
-
return lifecycleSuccess(checkingSummary(options.gitMode));
|
|
49
|
-
}
|
|
50
37
|
try {
|
|
51
38
|
return await options.lifecycle.getRepositorySummary(identity);
|
|
52
39
|
}
|
|
@@ -63,14 +50,6 @@ export function createRepositoryActions(options) {
|
|
|
63
50
|
const identity = await identityOrFailure();
|
|
64
51
|
if (identity === null)
|
|
65
52
|
return lifecycleFailure("unauthenticated");
|
|
66
|
-
if (options.entrySynchronizationInFlight?.(identity)) {
|
|
67
|
-
if (options.waitForEntrySynchronization !== undefined) {
|
|
68
|
-
await options.waitForEntrySynchronization(identity);
|
|
69
|
-
}
|
|
70
|
-
if (options.entrySynchronizationInFlight?.(identity)) {
|
|
71
|
-
return lifecycleSuccess(checkingSummary(options.gitMode));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
53
|
const generation = checkGenerations.get(identity.login) ?? 0;
|
|
75
54
|
const previous = previousChecks.get(identity.login);
|
|
76
55
|
if (previous !== undefined && now() - previous.at < throttleMs) {
|
|
@@ -190,7 +169,6 @@ export function createRepositoryActions(options) {
|
|
|
190
169
|
}
|
|
191
170
|
else if (preparationRequired &&
|
|
192
171
|
preparation.value.status === "ready" &&
|
|
193
|
-
preparationRequired &&
|
|
194
172
|
options.lifecycle.prepareDependencies === undefined) {
|
|
195
173
|
// A lifecycle that cannot perform the shared preparation contract is
|
|
196
174
|
// incompatible with a required update; do not silently claim ready.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-actions.js","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,GASjB,MAAM,uBAAuB,CAAC;AAkC/B,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,SAAS,UAAU,CAAC,OAAiC;IACnD,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW;IAClB,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,eAAe,CAAC,IAAa;IACpC,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,4BAA4B,CAAC,IAAI,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,OAAiC;IAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,eAAe,IAAI,yBAAyB,CAA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D,OAAO,gBAAgB,CAAC;gBACtB,WAAW,EAAE,WAAW,CAAC,KAAK;gBAC9B,cAAc;gBACd,GAAG,CAAC,qBAAqB,KAAK,SAAS;oBACrC,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,qBAAqB,EAAE,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;gBAAS,CAAC;YACT,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,KAAK;QACL,YAAY;QACZ,KAAK,EAAE,YAAY;QACnB,gBAAgB;QAChB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;QAC9C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC;KACrD,CAAC;AACJ,CAAC","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repository-actions.js","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GASjB,MAAM,uBAAuB,CAAC;AAgC/B,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,SAAS,UAAU,CAAC,OAAiC;IACnD,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW;IAClB,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,OAAiC;IAEjC,MAAM,GAAG,GAAG,O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AK,EAAE,YAAY;QACnB,gBAAgB;QAChB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;QAC9C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC;KACrD,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths = preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies =\n await options.lifecycle.prepareDependencies(dependencyPaths);\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay-dt/bonfire-next",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.18",
|
|
4
4
|
"description": "Next.js server integration for Bonfire.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ebay-dt/bonfire-core": "0.2.0-alpha.
|
|
35
|
-
"@ebay-dt/bonfire-node": "0.2.0-alpha.
|
|
34
|
+
"@ebay-dt/bonfire-core": "0.2.0-alpha.18",
|
|
35
|
+
"@ebay-dt/bonfire-node": "0.2.0-alpha.18",
|
|
36
36
|
"jose": "^6.1.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@ebay-dt/bonfire-react": "0.2.0-alpha.
|
|
39
|
+
"@ebay-dt/bonfire-react": "0.2.0-alpha.18",
|
|
40
40
|
"next": ">=16.2 <17",
|
|
41
41
|
"react": ">=19.2 <20",
|
|
42
42
|
"react-dom": ">=19.2 <20"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ebay-dt/bonfire-react": "0.2.0-alpha.
|
|
45
|
+
"@ebay-dt/bonfire-react": "0.2.0-alpha.18",
|
|
46
46
|
"@repo/eslint-config": "0.0.0",
|
|
47
47
|
"@repo/typescript-config": "0.0.0",
|
|
48
48
|
"@types/node": "20.19.43",
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { BonfireIdentity, BranchPreparationValue, LifecycleErrorCode } from "@ebay-dt/bonfire-core";
|
|
2
|
-
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
|
-
type EntryLifecycle = Pick<PrototypeLifecycle, "prepareBranch">;
|
|
4
|
-
export type EntrySynchronizationCompletion = {
|
|
5
|
-
status: "completed";
|
|
6
|
-
preparation: BranchPreparationValue;
|
|
7
|
-
} | {
|
|
8
|
-
status: "failed";
|
|
9
|
-
error: LifecycleErrorCode;
|
|
10
|
-
};
|
|
11
|
-
export type EntrySynchronizationResult = EntrySynchronizationCompletion | {
|
|
12
|
-
status: "in-flight";
|
|
13
|
-
};
|
|
14
|
-
export type EntrySynchronizationStatus = "started" | "deferred" | "completed";
|
|
15
|
-
export type EntrySynchronizationCoordinator = {
|
|
16
|
-
synchronize(identity: BonfireIdentity): Promise<EntrySynchronizationResult | null>;
|
|
17
|
-
waitForCompletion(identity: BonfireIdentity): Promise<void>;
|
|
18
|
-
isInFlight(identity: BonfireIdentity): boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Coordinates the first authenticated repository attempt for each identity in
|
|
22
|
-
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
23
|
-
* not repeated until the process is restarted.
|
|
24
|
-
*
|
|
25
|
-
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
26
|
-
* timed-out request continues the operation in-process while allowing the page
|
|
27
|
-
* render to proceed with an explicitly in-flight result.
|
|
28
|
-
*/
|
|
29
|
-
export declare function createEntrySynchronizationCoordinator(options: {
|
|
30
|
-
lifecycle: EntryLifecycle | null;
|
|
31
|
-
waitMs?: number;
|
|
32
|
-
onStatus?(event: {
|
|
33
|
-
identity: BonfireIdentity;
|
|
34
|
-
status: EntrySynchronizationStatus;
|
|
35
|
-
result?: BranchPreparationValue;
|
|
36
|
-
error?: LifecycleErrorCode;
|
|
37
|
-
}): void;
|
|
38
|
-
}): EntrySynchronizationCoordinator;
|
|
39
|
-
export {};
|
|
40
|
-
//# sourceMappingURL=entry-coordinator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAEnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,KAAK,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAEhE,MAAM,MAAM,8BAA8B,GACtC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,sBAAsB,CAAA;CAAE,GAC5D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAEpD,MAAM,MAAM,0BAA0B,GACpC,8BAA8B,GAAG;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC;AAO3D,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAE9E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,CACT,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAAC;IAC9C,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC;CAChD,CAAC;AAIF;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CAAC,OAAO,EAAE;IAC7D,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,CAAC,KAAK,EAAE;QACf,QAAQ,EAAE,eAAe,CAAC;QAC1B,MAAM,EAAE,0BAA0B,CAAC;QACnC,MAAM,CAAC,EAAE,sBAAsB,CAAC;QAChC,KAAK,CAAC,EAAE,kBAAkB,CAAC;KAC5B,GAAG,IAAI,CAAC;CACV,GAAG,+BAA+B,CAgGlC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n LifecycleErrorCode,\n LifecycleResult,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\nexport type EntrySynchronizationCompletion =\n | { status: \"completed\"; preparation: BranchPreparationValue }\n | { status: \"failed\"; error: LifecycleErrorCode };\n\nexport type EntrySynchronizationResult =\n EntrySynchronizationCompletion | { status: \"in-flight\" };\n\ntype InFlightAttempt = {\n completion: Promise<EntrySynchronizationCompletion>;\n renderWait: Promise<EntrySynchronizationResult>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<EntrySynchronizationResult | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the page\n * render to proceed with an explicitly in-flight result.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, EntrySynchronizationCompletion>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<EntrySynchronizationCompletion>,\n ): Promise<EntrySynchronizationResult> {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<EntrySynchronizationResult>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"in-flight\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result: LifecycleResult<BranchPreparationValue>) =>\n result.ok\n ? ({ status: \"completed\", preparation: result.value } as const)\n : ({ status: \"failed\", error: result.error.code } as const),\n )\n .catch(\n () => ({ status: \"failed\", error: \"unexpected-failure\" }) as const,\n );\n\n let completion!: Promise<EntrySynchronizationCompletion>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({\n identity,\n status: \"completed\",\n ...(result.status === \"completed\"\n ? { result: result.preparation }\n : { error: result.error }),\n });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const DEFAULT_ENTRY_WAIT_MS = 10_000;
|
|
2
|
-
/**
|
|
3
|
-
* Coordinates the first authenticated repository attempt for each identity in
|
|
4
|
-
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
5
|
-
* not repeated until the process is restarted.
|
|
6
|
-
*
|
|
7
|
-
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
8
|
-
* timed-out request continues the operation in-process while allowing the page
|
|
9
|
-
* render to proceed with an explicitly in-flight result.
|
|
10
|
-
*/
|
|
11
|
-
export function createEntrySynchronizationCoordinator(options) {
|
|
12
|
-
const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;
|
|
13
|
-
const inFlight = new Map();
|
|
14
|
-
const completed = new Map();
|
|
15
|
-
const deferredReported = new Set();
|
|
16
|
-
function report(event) {
|
|
17
|
-
try {
|
|
18
|
-
options.onStatus?.(event);
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// Observability must never affect authentication or page rendering.
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function createRenderWait(identity, completion) {
|
|
25
|
-
if (waitMs <= 0)
|
|
26
|
-
return completion;
|
|
27
|
-
let timeout;
|
|
28
|
-
const deferred = new Promise((resolve) => {
|
|
29
|
-
timeout = setTimeout(() => {
|
|
30
|
-
if (!deferredReported.has(identity.login)) {
|
|
31
|
-
deferredReported.add(identity.login);
|
|
32
|
-
report({ identity, status: "deferred" });
|
|
33
|
-
}
|
|
34
|
-
resolve({ status: "in-flight" });
|
|
35
|
-
}, waitMs);
|
|
36
|
-
});
|
|
37
|
-
return Promise.race([completion, deferred]).finally(() => {
|
|
38
|
-
if (timeout !== undefined)
|
|
39
|
-
clearTimeout(timeout);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async function synchronize(identity) {
|
|
43
|
-
if (options.lifecycle === null)
|
|
44
|
-
return null;
|
|
45
|
-
const previous = completed.get(identity.login);
|
|
46
|
-
if (previous !== undefined)
|
|
47
|
-
return previous;
|
|
48
|
-
const active = inFlight.get(identity.login);
|
|
49
|
-
if (active !== undefined)
|
|
50
|
-
return active.renderWait;
|
|
51
|
-
report({ identity, status: "started" });
|
|
52
|
-
const attempt = options.lifecycle
|
|
53
|
-
.prepareBranch(identity)
|
|
54
|
-
.then((result) => result.ok
|
|
55
|
-
? { status: "completed", preparation: result.value }
|
|
56
|
-
: { status: "failed", error: result.error.code })
|
|
57
|
-
.catch(() => ({ status: "failed", error: "unexpected-failure" }));
|
|
58
|
-
let completion;
|
|
59
|
-
completion = attempt
|
|
60
|
-
.then((result) => {
|
|
61
|
-
completed.set(identity.login, result);
|
|
62
|
-
report({
|
|
63
|
-
identity,
|
|
64
|
-
status: "completed",
|
|
65
|
-
...(result.status === "completed"
|
|
66
|
-
? { result: result.preparation }
|
|
67
|
-
: { error: result.error }),
|
|
68
|
-
});
|
|
69
|
-
return result;
|
|
70
|
-
})
|
|
71
|
-
.finally(() => {
|
|
72
|
-
deferredReported.delete(identity.login);
|
|
73
|
-
if (inFlight.get(identity.login)?.completion === completion) {
|
|
74
|
-
inFlight.delete(identity.login);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
const renderWait = createRenderWait(identity, completion);
|
|
78
|
-
inFlight.set(identity.login, { completion, renderWait });
|
|
79
|
-
return renderWait;
|
|
80
|
-
}
|
|
81
|
-
async function waitForCompletion(identity) {
|
|
82
|
-
await inFlight.get(identity.login)?.completion;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
synchronize,
|
|
86
|
-
waitForCompletion,
|
|
87
|
-
isInFlight: (identity) => inFlight.has(identity.login),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=entry-coordinator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAgCA,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,qCAAqC,CAAC,OASrD;IACC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;IACpD,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0C,CAAC;IACpE,MAAM,gBAAgB,GAAG,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C,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;gBAC5D,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC,CAAC,CAAC;QACL,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAEzD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,KAAK,UAAU,iBAAiB,CAAC,QAAyB;QACxD,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACjD,CAAC;IAED,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;KACvD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n LifecycleErrorCode,\n LifecycleResult,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\nexport type EntrySynchronizationCompletion =\n | { status: \"completed\"; preparation: BranchPreparationValue }\n | { status: \"failed\"; error: LifecycleErrorCode };\n\nexport type EntrySynchronizationResult =\n EntrySynchronizationCompletion | { status: \"in-flight\" };\n\ntype InFlightAttempt = {\n completion: Promise<EntrySynchronizationCompletion>;\n renderWait: Promise<EntrySynchronizationResult>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<EntrySynchronizationResult | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the page\n * render to proceed with an explicitly in-flight result.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, EntrySynchronizationCompletion>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<EntrySynchronizationCompletion>,\n ): Promise<EntrySynchronizationResult> {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<EntrySynchronizationResult>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"in-flight\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result: LifecycleResult<BranchPreparationValue>) =>\n result.ok\n ? ({ status: \"completed\", preparation: result.value } as const)\n : ({ status: \"failed\", error: result.error.code } as const),\n )\n .catch(\n () => ({ status: \"failed\", error: \"unexpected-failure\" }) as const,\n );\n\n let completion!: Promise<EntrySynchronizationCompletion>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({\n identity,\n status: \"completed\",\n ...(result.status === \"completed\"\n ? { result: result.preparation }\n : { error: result.error }),\n });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|