@ebay-dt/bonfire-next 0.2.0-alpha.0 → 0.2.0-alpha.10
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/client/lifecycle-provider.d.ts.map +1 -1
- package/dist/client/lifecycle-provider.js.map +1 -1
- package/dist/server/create-bonfire-next.d.ts +4 -0
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +11 -1
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/entry-coordinator.d.ts.map +1 -1
- package/dist/server/entry-coordinator.js.map +1 -1
- package/dist/server/prototype-actions.d.ts +1 -0
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +39 -1
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/prototype-source-link.d.ts +11 -0
- package/dist/server/prototype-source-link.d.ts.map +1 -0
- package/dist/server/prototype-source-link.js +59 -0
- package/dist/server/prototype-source-link.js.map +1 -0
- package/dist/server/repository-actions.d.ts.map +1 -1
- package/dist/server/repository-actions.js +10 -2
- package/dist/server/repository-actions.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle-provider.d.ts","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,uBAAuB,EAG5B,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,4BAA4B,IAAI,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxG,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAEjF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,uBAAuB,CAAC;IACjC,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,OAAc,EACd,IAAW,EACX,aAAa,EACb,mBAAmB,GACpB,EAAE,0BAA0B,+TAa5B","sourcesContent":["\"use client\";\n\nimport {\n createDirtyObservationAdapter,\n createLifecycleController,\n LifecycleProvider,\n RepositoryActionsProvider,\n type LifecycleActionBindings,\n type LifecycleNavigationAdapter,\n type LifecycleRouteAdapter,\n type RepositoryActionBindings,\n} from \"@ebay-dt/bonfire-react/lifecycle\";\nimport type { BonfireIdentity } from \"@ebay-dt/bonfire-core\";\nimport { usePathname, useRouter } from \"next/navigation.js\";\nimport { useEffect, useState, type ReactNode } from \"react\";\n\nexport { useOptionalRepositoryActions as useRepositoryActions } from \"@ebay-dt/bonfire-react/lifecycle\";\nexport type { RepositoryActionBindings } from \"@ebay-dt/bonfire-react/lifecycle\";\n\nexport type NextLifecycleProviderProps = {\n actions: LifecycleActionBindings;\n repositoryActions?: RepositoryActionBindings;\n children: ReactNode;\n enabled?: boolean;\n user?: BonfireIdentity | null;\n dirtyEndpoint?: string;\n deploymentAvailable?: boolean;\n};\n\nexport function NextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n enabled = true,\n user = null,\n dirtyEndpoint,\n deploymentAvailable,\n}: NextLifecycleProviderProps) {\n if (!enabled) return children;\n return (\n <EnabledNextLifecycleProvider\n actions={actions}\n repositoryActions={repositoryActions}\n dirtyEndpoint={dirtyEndpoint}\n deploymentAvailable={deploymentAvailable}\n user={user}\n >\n {children}\n </EnabledNextLifecycleProvider>\n );\n}\n\nfunction EnabledNextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n user,\n dirtyEndpoint,\n deploymentAvailable,\n}: Pick<\n NextLifecycleProviderProps,\n \"actions\"
|
|
1
|
+
{"version":3,"file":"lifecycle-provider.d.ts","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,uBAAuB,EAG5B,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,4BAA4B,IAAI,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxG,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAEjF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,uBAAuB,CAAC;IACjC,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,OAAc,EACd,IAAW,EACX,aAAa,EACb,mBAAmB,GACpB,EAAE,0BAA0B,+TAa5B","sourcesContent":["\"use client\";\n\nimport {\n createDirtyObservationAdapter,\n createLifecycleController,\n LifecycleProvider,\n RepositoryActionsProvider,\n type LifecycleActionBindings,\n type LifecycleNavigationAdapter,\n type LifecycleRouteAdapter,\n type RepositoryActionBindings,\n} from \"@ebay-dt/bonfire-react/lifecycle\";\nimport type { BonfireIdentity } from \"@ebay-dt/bonfire-core\";\nimport { usePathname, useRouter } from \"next/navigation.js\";\nimport { useEffect, useState, type ReactNode } from \"react\";\n\nexport { useOptionalRepositoryActions as useRepositoryActions } from \"@ebay-dt/bonfire-react/lifecycle\";\nexport type { RepositoryActionBindings } from \"@ebay-dt/bonfire-react/lifecycle\";\n\nexport type NextLifecycleProviderProps = {\n actions: LifecycleActionBindings;\n repositoryActions?: RepositoryActionBindings;\n children: ReactNode;\n enabled?: boolean;\n user?: BonfireIdentity | null;\n dirtyEndpoint?: string;\n deploymentAvailable?: boolean;\n};\n\nexport function NextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n enabled = true,\n user = null,\n dirtyEndpoint,\n deploymentAvailable,\n}: NextLifecycleProviderProps) {\n if (!enabled) return children;\n return (\n <EnabledNextLifecycleProvider\n actions={actions}\n repositoryActions={repositoryActions}\n dirtyEndpoint={dirtyEndpoint}\n deploymentAvailable={deploymentAvailable}\n user={user}\n >\n {children}\n </EnabledNextLifecycleProvider>\n );\n}\n\nfunction EnabledNextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n user,\n dirtyEndpoint,\n deploymentAvailable,\n}: Pick<\n NextLifecycleProviderProps,\n | \"actions\"\n | \"repositoryActions\"\n | \"children\"\n | \"user\"\n | \"dirtyEndpoint\"\n | \"deploymentAvailable\"\n>) {\n const pathname = usePathname() ?? \"/\";\n const router = useRouter();\n const [route] = useState(() => {\n let currentPathname = pathname;\n const listeners = new Set<() => void>();\n const adapter: LifecycleRouteAdapter = {\n getPathname: () => currentPathname,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n return {\n adapter,\n setPathname(nextPathname: string) {\n if (nextPathname === currentPathname) return;\n currentPathname = nextPathname;\n for (const listener of listeners) listener();\n },\n };\n });\n const [navigation] = useState<LifecycleNavigationAdapter>(() => ({\n pathname,\n push: (href) => router.push(href),\n replace: (href) => router.replace(href),\n back: () => router.back(),\n refresh: () => router.refresh(),\n }));\n const [dirtyObservation] = useState(() =>\n createDirtyObservationAdapter({ endpoint: dirtyEndpoint }),\n );\n const [controller] = useState(() =>\n createLifecycleController({\n actions,\n navigation,\n route: route.adapter,\n user,\n dirtyObservation,\n deploymentAvailable,\n }),\n );\n\n useEffect(() => {\n route.setPathname(pathname);\n }, [pathname, route]);\n\n return (\n <RepositoryActionsProvider actions={repositoryActions}>\n <LifecycleProvider controller={controller}>{children}</LifecycleProvider>\n </RepositoryActionsProvider>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle-provider.js","sourceRoot":"","sources":["../../src/client/lifecycle-provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,iBAAiB,EACjB,yBAAyB,GAK1B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,4BAA4B,IAAI,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAaxG,MAAM,UAAU,qBAAqB,CAAC,EACpC,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,OAAO,GAAG,IAAI,EACd,IAAI,GAAG,IAAI,EACX,aAAa,EACb,mBAAmB,GACQ;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC;IAC9B,OAAO,CACL,KAAC,4BAA4B,IAC3B,OAAO,EAAE,OAAO,EAChB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,aAAa,EAC5B,mBAAmB,EAAE,mBAAmB,EACxC,IAAI,EAAE,IAAI,YAET,QAAQ,GACoB,CAChC,CAAC;AACJ,CAAC;AAED,SAAS,4BAA4B,CAAC,EACpC,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,mBAAmB,
|
|
1
|
+
{"version":3,"file":"lifecycle-provider.js","s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Q,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,KAAC,yBAAyB,IAAC,OAAO,EAAE,iBAAiB,YACnD,KAAC,iBAAiB,IAAC,UAAU,EAAE,UAAU,YAAG,QAAQ,GAAqB,GAC/C,CAC7B,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport {\n createDirtyObservationAdapter,\n createLifecycleController,\n LifecycleProvider,\n RepositoryActionsProvider,\n type LifecycleActionBindings,\n type LifecycleNavigationAdapter,\n type LifecycleRouteAdapter,\n type RepositoryActionBindings,\n} from \"@ebay-dt/bonfire-react/lifecycle\";\nimport type { BonfireIdentity } from \"@ebay-dt/bonfire-core\";\nimport { usePathname, useRouter } from \"next/navigation.js\";\nimport { useEffect, useState, type ReactNode } from \"react\";\n\nexport { useOptionalRepositoryActions as useRepositoryActions } from \"@ebay-dt/bonfire-react/lifecycle\";\nexport type { RepositoryActionBindings } from \"@ebay-dt/bonfire-react/lifecycle\";\n\nexport type NextLifecycleProviderProps = {\n actions: LifecycleActionBindings;\n repositoryActions?: RepositoryActionBindings;\n children: ReactNode;\n enabled?: boolean;\n user?: BonfireIdentity | null;\n dirtyEndpoint?: string;\n deploymentAvailable?: boolean;\n};\n\nexport function NextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n enabled = true,\n user = null,\n dirtyEndpoint,\n deploymentAvailable,\n}: NextLifecycleProviderProps) {\n if (!enabled) return children;\n return (\n <EnabledNextLifecycleProvider\n actions={actions}\n repositoryActions={repositoryActions}\n dirtyEndpoint={dirtyEndpoint}\n deploymentAvailable={deploymentAvailable}\n user={user}\n >\n {children}\n </EnabledNextLifecycleProvider>\n );\n}\n\nfunction EnabledNextLifecycleProvider({\n actions,\n repositoryActions,\n children,\n user,\n dirtyEndpoint,\n deploymentAvailable,\n}: Pick<\n NextLifecycleProviderProps,\n | \"actions\"\n | \"repositoryActions\"\n | \"children\"\n | \"user\"\n | \"dirtyEndpoint\"\n | \"deploymentAvailable\"\n>) {\n const pathname = usePathname() ?? \"/\";\n const router = useRouter();\n const [route] = useState(() => {\n let currentPathname = pathname;\n const listeners = new Set<() => void>();\n const adapter: LifecycleRouteAdapter = {\n getPathname: () => currentPathname,\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n return {\n adapter,\n setPathname(nextPathname: string) {\n if (nextPathname === currentPathname) return;\n currentPathname = nextPathname;\n for (const listener of listeners) listener();\n },\n };\n });\n const [navigation] = useState<LifecycleNavigationAdapter>(() => ({\n pathname,\n push: (href) => router.push(href),\n replace: (href) => router.replace(href),\n back: () => router.back(),\n refresh: () => router.refresh(),\n }));\n const [dirtyObservation] = useState(() =>\n createDirtyObservationAdapter({ endpoint: dirtyEndpoint }),\n );\n const [controller] = useState(() =>\n createLifecycleController({\n actions,\n navigation,\n route: route.adapter,\n user,\n dirtyObservation,\n deploymentAvailable,\n }),\n );\n\n useEffect(() => {\n route.setPathname(pathname);\n }, [pathname, route]);\n\n return (\n <RepositoryActionsProvider actions={repositoryActions}>\n <LifecycleProvider controller={controller}>{children}</LifecycleProvider>\n </RepositoryActionsProvider>\n );\n}\n"]}
|
|
@@ -29,6 +29,10 @@ type AppLayoutModel = {
|
|
|
29
29
|
headerProps: {
|
|
30
30
|
applicationName: string;
|
|
31
31
|
user: BonfireIdentity | null;
|
|
32
|
+
sourceRepository?: {
|
|
33
|
+
url: string;
|
|
34
|
+
prototypeDirectory: string;
|
|
35
|
+
};
|
|
32
36
|
};
|
|
33
37
|
};
|
|
34
38
|
export declare function createBonfireNext(options: CreateBonfireNextOptions): {
|
|
@@ -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,kB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA2KvB,OAAO,CAAC,cAAc,CAAC;2CAiBhD,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;EA2DhE","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 { createEntrySynchronizationCoordinator } from \"./entry-coordinator.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n prototypeRoot?: 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};\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 };\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 && 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 automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const entrySynchronization = createEntrySynchronizationCoordinator({\n lifecycle,\n onStatus: production\n ? undefined\n : ({ identity, status, result }) => {\n if (status === \"started\") {\n console.info(\n `[bonfire] Preparing repository branch for ${identity.login}…`,\n );\n } else if (status === \"deferred\") {\n console.warn(\n `[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`,\n );\n } else if (result?.status === \"ready\") {\n console.info(\n `[bonfire] Branch preparation completed for ${identity.login}.`,\n );\n } else if (result?.status === \"disabled\") {\n console.info(\n `[bonfire] Branch preparation skipped for ${identity.login}.`,\n );\n } else {\n console.warn(\n `[bonfire] Branch preparation completed with repository attention for ${identity.login}.`,\n );\n }\n },\n });\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 getCurrentUser: getSession,\n lifecycle,\n entrySynchronizationInFlight: entrySynchronization.isInFlight,\n waitForEntrySynchronization: entrySynchronization.waitForCompletion,\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 if (user !== null) await entrySynchronization.synchronize(user);\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 },\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,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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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 { createEntrySynchronizationCoordinator } from \"./entry-coordinator.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 prototypeRoot?: 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};\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?: { url: string; prototypeDirectory: string };\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 automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const entrySynchronization = createEntrySynchronizationCoordinator({\n lifecycle,\n onStatus: production\n ? undefined\n : ({ identity, status, result }) => {\n if (status === \"started\") {\n console.info(\n `[bonfire] Preparing repository branch for ${identity.login}…`,\n );\n } else if (status === \"deferred\") {\n console.warn(\n `[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`,\n );\n } else if (result?.status === \"ready\") {\n console.info(\n `[bonfire] Branch preparation completed for ${identity.login}.`,\n );\n } else if (result?.status === \"disabled\") {\n console.info(\n `[bonfire] Branch preparation skipped for ${identity.login}.`,\n );\n } else {\n console.warn(\n `[bonfire] Branch preparation completed with repository attention for ${identity.login}.`,\n );\n }\n },\n });\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 getCurrentUser: getSession,\n lifecycle,\n entrySynchronizationInFlight: entrySynchronization.isInFlight,\n waitForEntrySynchronization: entrySynchronization.waitForCompletion,\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 if (user !== null) await entrySynchronization.synchronize(user);\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 });\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"]}
|
|
@@ -14,6 +14,7 @@ import { createPrototypeRoutes } from "./prototype-routes.js";
|
|
|
14
14
|
import { createEntrySynchronizationCoordinator } from "./entry-coordinator.js";
|
|
15
15
|
import { createRepositoryActions } from "./repository-actions.js";
|
|
16
16
|
import { createRepositoryRoutes } from "./repository-routes.js";
|
|
17
|
+
import { getPrototypeSourceRepository } from "./prototype-source-link.js";
|
|
17
18
|
const APP_HEADER_BLOCK_SIZE_PROPERTY = "--app-header-block-size";
|
|
18
19
|
const APP_HEADER_PRESENT_BLOCK_SIZE = "2.5rem";
|
|
19
20
|
export function createBonfireNext(options) {
|
|
@@ -35,7 +36,8 @@ export function createBonfireNext(options) {
|
|
|
35
36
|
const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;
|
|
36
37
|
if (options.prototypeLifecycle !== undefined &&
|
|
37
38
|
((gitMode === "manual" && injectedLifecycleMode !== "manual") ||
|
|
38
|
-
(injectedLifecycleMode !== undefined &&
|
|
39
|
+
(injectedLifecycleMode !== undefined &&
|
|
40
|
+
injectedLifecycleMode !== gitMode))) {
|
|
39
41
|
throw new TypeError(gitMode === "manual"
|
|
40
42
|
? "prototypeLifecycle must declare manual mode when gitMode is manual"
|
|
41
43
|
: "prototypeLifecycle gitMode does not match configured gitMode");
|
|
@@ -165,6 +167,13 @@ export function createBonfireNext(options) {
|
|
|
165
167
|
const user = production ? null : await getCurrentUser();
|
|
166
168
|
if (user !== null)
|
|
167
169
|
await entrySynchronization.synchronize(user);
|
|
170
|
+
const sourceRepository = user === null
|
|
171
|
+
? undefined
|
|
172
|
+
: await getPrototypeSourceRepository({
|
|
173
|
+
repositoryRoot: options.repositoryRoot,
|
|
174
|
+
prototypeRoot: options.prototypeRoot,
|
|
175
|
+
hostname: config.auth.github.hostname,
|
|
176
|
+
});
|
|
168
177
|
const style = {
|
|
169
178
|
[APP_HEADER_BLOCK_SIZE_PROPERTY]: user === null ? "0px" : APP_HEADER_PRESENT_BLOCK_SIZE,
|
|
170
179
|
};
|
|
@@ -173,6 +182,7 @@ export function createBonfireNext(options) {
|
|
|
173
182
|
headerProps: {
|
|
174
183
|
applicationName: config.name,
|
|
175
184
|
user,
|
|
185
|
+
...(sourceRepository === undefined ? {} : { sourceRepository }),
|
|
176
186
|
},
|
|
177
187
|
};
|
|
178
188
|
});
|
|
@@ -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,GAKp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AAC,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 { createEntrySynchronizationCoordinator } from \"./entry-coordinator.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n prototypeRoot?: 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};\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 };\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 && 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 automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const entrySynchronization = createEntrySynchronizationCoordinator({\n lifecycle,\n onStatus: production\n ? undefined\n : ({ identity, status, result }) => {\n if (status === \"started\") {\n console.info(\n `[bonfire] Preparing repository branch for ${identity.login}…`,\n );\n } else if (status === \"deferred\") {\n console.warn(\n `[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`,\n );\n } else if (result?.status === \"ready\") {\n console.info(\n `[bonfire] Branch preparation completed for ${identity.login}.`,\n );\n } else if (result?.status === \"disabled\") {\n console.info(\n `[bonfire] Branch preparation skipped for ${identity.login}.`,\n );\n } else {\n console.warn(\n `[bonfire] Branch preparation completed with repository attention for ${identity.login}.`,\n );\n }\n },\n });\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 getCurrentUser: getSession,\n lifecycle,\n entrySynchronizationInFlight: entrySynchronization.isInFlight,\n waitForEntrySynchronization: entrySynchronization.waitForCompletion,\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 if (user !== null) await entrySynchronization.synchronize(user);\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 },\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.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,CAAC;AAC9D,OAAO,EAAE,qCAAqC,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,4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AU,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 { createEntrySynchronizationCoordinator } from \"./entry-coordinator.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 prototypeRoot?: 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};\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?: { url: string; prototypeDirectory: string };\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 automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const entrySynchronization = createEntrySynchronizationCoordinator({\n lifecycle,\n onStatus: production\n ? undefined\n : ({ identity, status, result }) => {\n if (status === \"started\") {\n console.info(\n `[bonfire] Preparing repository branch for ${identity.login}…`,\n );\n } else if (status === \"deferred\") {\n console.warn(\n `[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`,\n );\n } else if (result?.status === \"ready\") {\n console.info(\n `[bonfire] Branch preparation completed for ${identity.login}.`,\n );\n } else if (result?.status === \"disabled\") {\n console.info(\n `[bonfire] Branch preparation skipped for ${identity.login}.`,\n );\n } else {\n console.warn(\n `[bonfire] Branch preparation completed with repository attention for ${identity.login}.`,\n );\n }\n },\n });\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 getCurrentUser: getSession,\n lifecycle,\n entrySynchronizationInFlight: entrySynchronization.isInFlight,\n waitForEntrySynchronization: entrySynchronization.waitForCompletion,\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 if (user !== null) await entrySynchronization.synchronize(user);\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 });\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":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,KAAK,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAOhE,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAE9E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,
|
|
1
|
+
{"version":3,"file":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,KAAK,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAOhE,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,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC1C,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;KACjC,GAAG,IAAI,CAAC;CACV,GAAG,+BAA+B,CAuFlC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<BranchPreparationValue | 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\n * page render to proceed with deferred preparation.\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 }): 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, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\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<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\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) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(() => ({ status: \"unsafe\" }) satisfies BranchPreparationValue);\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAuBA,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,q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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} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<BranchPreparationValue | 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\n * page render to proceed with deferred preparation.\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 }): 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, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\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<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\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) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(() => ({ status: \"unsafe\" }) satisfies BranchPreparationValue);\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\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"]}
|
|
@@ -8,6 +8,7 @@ export type PrototypeActions = {
|
|
|
8
8
|
save(input: PrototypeCommandInput): Promise<LifecycleResult<SavePrototypeValue>>;
|
|
9
9
|
discard(input: PrototypeCommandInput): Promise<LifecycleResult<DiscardPrototypeValue>>;
|
|
10
10
|
deploy(input: PrototypeCommandInput): Promise<LifecycleResult<DeploymentValue>>;
|
|
11
|
+
retryPublish?(input: PrototypeCommandInput): Promise<LifecycleResult<DeploymentValue>>;
|
|
11
12
|
};
|
|
12
13
|
export type PrototypeActionsOptions = {
|
|
13
14
|
production: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-actions.d.ts","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CACJ,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClD,SAAS,CACP,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC9E,MAAM,CACJ,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClD,IAAI,CACF,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAChD,OAAO,CACL,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACnD,MAAM,CACJ,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAeF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAkNlB","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype-actions.d.ts","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CACJ,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClD,SAAS,CACP,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC9E,MAAM,CACJ,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClD,IAAI,CACF,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAChD,OAAO,CACL,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACnD,MAAM,CACJ,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC;IAC7C,YAAY,CAAC,CACX,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAwBF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CA2PlB","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n retryPublish?(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction logUnexpectedFailure(\n operation:\n | \"create\"\n | \"duplicate\"\n | \"edit\"\n | \"delete\"\n | \"save\"\n | \"discard\"\n | \"deploy\"\n | \"retry-publish\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function retryPublish(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.retryPublish === undefined\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n try {\n return await options.lifecycle.retryPublish(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n retryPublish,\n };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { lifecycleFailure, parseCreatePrototypeInput, parseDuplicatePrototypeInput, parseEditPrototypeInput, parsePrototypeCommandInput, LifecycleInputError, } from "@ebay-dt/bonfire-core";
|
|
2
2
|
function isManualLifecycleCompatible(options) {
|
|
3
|
-
return options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual";
|
|
3
|
+
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
4
4
|
}
|
|
5
5
|
function logUnexpectedFailure(operation) {
|
|
6
6
|
console.error(`Bonfire prototype ${operation} failed unexpectedly.`);
|
|
@@ -126,6 +126,43 @@ export function createPrototypeActions(options) {
|
|
|
126
126
|
return lifecycleFailure("unexpected-failure");
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
async function retryPublish(input) {
|
|
130
|
+
if (options.production || options.gitMode === "manual") {
|
|
131
|
+
return lifecycleFailure("forbidden");
|
|
132
|
+
}
|
|
133
|
+
if (options.lifecycle === null ||
|
|
134
|
+
options.lifecycle.retryPublish === undefined) {
|
|
135
|
+
return lifecycleFailure("deployment-unavailable");
|
|
136
|
+
}
|
|
137
|
+
let parsedInput;
|
|
138
|
+
try {
|
|
139
|
+
parsedInput = parsePrototypeCommandInput(input);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (error instanceof LifecycleInputError) {
|
|
143
|
+
return lifecycleFailure("invalid-input");
|
|
144
|
+
}
|
|
145
|
+
logUnexpectedFailure("retry-publish");
|
|
146
|
+
return lifecycleFailure("deployment-failure");
|
|
147
|
+
}
|
|
148
|
+
let identity;
|
|
149
|
+
try {
|
|
150
|
+
identity = await options.getCurrentUser();
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
logUnexpectedFailure("retry-publish");
|
|
154
|
+
return lifecycleFailure("unexpected-failure");
|
|
155
|
+
}
|
|
156
|
+
if (identity === null)
|
|
157
|
+
return lifecycleFailure("unauthenticated");
|
|
158
|
+
try {
|
|
159
|
+
return await options.lifecycle.retryPublish(identity, parsedInput);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
logUnexpectedFailure("retry-publish");
|
|
163
|
+
return lifecycleFailure("deployment-failure");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
129
166
|
async function deploy(input) {
|
|
130
167
|
if (options.production || options.gitMode === "manual") {
|
|
131
168
|
return lifecycleFailure("forbidden");
|
|
@@ -170,6 +207,7 @@ export function createPrototypeActions(options) {
|
|
|
170
207
|
save,
|
|
171
208
|
discard,
|
|
172
209
|
deploy,
|
|
210
|
+
retryPublish,
|
|
173
211
|
};
|
|
174
212
|
}
|
|
175
213
|
//# sourceMappingURL=prototype-actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,u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QAED,IAAI,WAAkC,CAAC;QACvC,IAAI,CAAC;YACH,WAAW,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;gBACzC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAC3C,CAAC;YACD,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC/B,OAAO,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,QAAgC,CAAC;QACrC,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5C,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAElE,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAgBpB,MAAM,uBAAuB,CAAC;AAoC/B,SAAS,2BAA2B,CAClC,OAAgC;IAEhC,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,SAQmB;IAEnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAgC;IAEhC,KAAK,UAAU,MAAM,CACnB,KAA2B;QAE3B,IACE,OAAO,CAAC,UAAU;YAClB,OAAO,CAAC,SAAS,KAAK,IAAI;YAC1B,CAAC,2BAA2B,CAAC,OAAO,CAAC,EACrC,CAAC;YACD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAChD,I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AQ,KAAK,IAAI;YAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAElE,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;QACN,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n retryPublish?(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction logUnexpectedFailure(\n operation:\n | \"create\"\n | \"duplicate\"\n | \"edit\"\n | \"delete\"\n | \"save\"\n | \"discard\"\n | \"deploy\"\n | \"retry-publish\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function retryPublish(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.retryPublish === undefined\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n try {\n return await options.lifecycle.retryPublish(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n retryPublish,\n };\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Only return a canonical HTTPS URL on the configured GitHub host. */
|
|
2
|
+
export declare function gitHubRepositoryUrl(remote: string, hostname: string): string | null;
|
|
3
|
+
export declare function getPrototypeSourceRepository(options: {
|
|
4
|
+
repositoryRoot: string;
|
|
5
|
+
prototypeRoot?: string;
|
|
6
|
+
hostname: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
url: string;
|
|
9
|
+
prototypeDirectory: string;
|
|
10
|
+
} | undefined>;
|
|
11
|
+
//# sourceMappingURL=prototype-source-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype-source-link.d.ts","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAQA,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;CAClB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAqBnE","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\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}): Promise<{ url: string; prototypeDirectory: string } | undefined> {\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 { url, prototypeDirectory };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { relative, sep } from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { resolvePrototypeCatalogPaths } from "@ebay-dt/bonfire-node";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
6
|
+
const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;
|
|
7
|
+
/** Only return a canonical HTTPS URL on the configured GitHub host. */
|
|
8
|
+
export function gitHubRepositoryUrl(remote, hostname) {
|
|
9
|
+
const value = remote.trim();
|
|
10
|
+
let pathname;
|
|
11
|
+
if (value.startsWith(`git@${hostname}:`)) {
|
|
12
|
+
pathname = value.slice(`git@${hostname}:`.length);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = new URL(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (parsed.hostname !== hostname ||
|
|
23
|
+
!["https:", "ssh:"].includes(parsed.protocol) ||
|
|
24
|
+
parsed.port !== "" ||
|
|
25
|
+
parsed.search !== "" ||
|
|
26
|
+
parsed.hash !== "" ||
|
|
27
|
+
parsed.password !== "" ||
|
|
28
|
+
(parsed.protocol === "ssh:"
|
|
29
|
+
? parsed.username !== "git"
|
|
30
|
+
: parsed.username !== "")) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
pathname = parsed.pathname.replace(/^\//u, "");
|
|
34
|
+
}
|
|
35
|
+
const segments = pathname.replace(/\.git$/u, "").split("/");
|
|
36
|
+
if (segments.length !== 2 ||
|
|
37
|
+
segments.some((segment) => !GITHUB_NAME.test(segment))) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return `https://${hostname}/${segments[0]}/${segments[1]}`;
|
|
41
|
+
}
|
|
42
|
+
export async function getPrototypeSourceRepository(options) {
|
|
43
|
+
try {
|
|
44
|
+
const { stdout } = await execFileAsync("git", ["-C", options.repositoryRoot, "config", "--get", "remote.origin.url"], { timeout: 2_000, maxBuffer: 4_096 });
|
|
45
|
+
const url = gitHubRepositoryUrl(stdout, options.hostname);
|
|
46
|
+
if (url === null)
|
|
47
|
+
return undefined;
|
|
48
|
+
const paths = resolvePrototypeCatalogPaths(options);
|
|
49
|
+
const prototypeDirectory = relative(paths.repositoryRoot, paths.prototypeRoot)
|
|
50
|
+
.split(sep)
|
|
51
|
+
.join("/");
|
|
52
|
+
return { url, prototypeDirectory };
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// A missing or unsupported origin should not block the application header.
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=prototype-source-link.js.map
|
|
@@ -0,0 +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;AAEpD,uEAAuE;AACvE,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,QAAgB;IAEhB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,IAAI,QAAgB,CAAC;IACrB,IAAI,KAAK,CAA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,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;AAC7D,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,OAIlD;IACC,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CACpC,KAAK,EACL,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,CAAC,EACtE,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CACrC,CAAC;QACF,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC1D,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QACnC,MAAM,KAAK,GAAG,4BAA4B,CAAC,OAAO,CAAC,CAAC;QACpD,MAAM,kBAAkB,GAAG,QAAQ,CACjC,KAAK,CAAC,cAAc,EACpB,KAAK,CAAC,aAAa,CACpB;aACE,KAAK,CAAC,GAAG,CAAC;aACV,IAAI,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,CAAC;IACrC,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 { 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}): Promise<{ url: string; prototypeDirectory: string } | undefined> {\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 { url, prototypeDirectory };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -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,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAA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AA2B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E,CAAC;AAyBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CA8KnB","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\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<RepositorySummary>>;\n retry(): Promise<LifecycleResult<RepositorySummary>>;\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\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\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 applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\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 return await options.lifecycle.getRepositorySummary(identity);\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 save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getGitManagementCapabilities, lifecycleFailure, lifecycleSuccess, } from "@ebay-dt/bonfire-core";
|
|
2
2
|
const DEFAULT_CHECK_THROTTLE_MS = 30_000;
|
|
3
3
|
function compatible(options) {
|
|
4
|
-
return options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual";
|
|
4
|
+
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
5
5
|
}
|
|
6
6
|
function unavailable() {
|
|
7
7
|
return lifecycleFailure("forbidden");
|
|
@@ -121,9 +121,17 @@ export function createRepositoryActions(options) {
|
|
|
121
121
|
return unavailable();
|
|
122
122
|
invalidateChecks(identity.login);
|
|
123
123
|
try {
|
|
124
|
-
|
|
124
|
+
const result = (await Reflect.apply(mutation, options.lifecycle, [
|
|
125
|
+
identity,
|
|
126
|
+
input,
|
|
127
|
+
]));
|
|
128
|
+
if (!result.ok) {
|
|
129
|
+
console.error(`Bonfire repository ${operation} failed: ${result.error.code}`);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
125
132
|
}
|
|
126
133
|
catch {
|
|
134
|
+
console.error(`Bonfire repository ${operation} failed unexpectedly`);
|
|
127
135
|
return lifecycleFailure("unexpected-failure");
|
|
128
136
|
}
|
|
129
137
|
finally {
|
|
@@ -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,GAMjB,MAAM,uBAAuB,CAAC;AAgC/B,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,SAAS,UAAU,CAAC,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,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\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<RepositorySummary>>;\n retry(): Promise<LifecycleResult<RepositorySummary>>;\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\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\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 options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\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 return await mutation(identity, input);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\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 return await options.lifecycle.getRepositorySummary(identity);\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 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,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,GAMjB,MAAM,uBAAuB,CAAC;AAgC/B,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,SAAS,UAAU,CAAC,O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C;IAED,OAAO;QACL,UAAU;QACV,KAAK;QACL,YAAY;QACZ,KAAK,EAAE,YAAY;QACnB,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 LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\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<RepositorySummary>>;\n retry(): Promise<LifecycleResult<RepositorySummary>>;\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\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\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 applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\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 return await options.lifecycle.getRepositorySummary(identity);\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 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.10",
|
|
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.10",
|
|
35
|
+
"@ebay-dt/bonfire-node": "0.2.0-alpha.10",
|
|
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.10",
|
|
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.10",
|
|
46
46
|
"@repo/eslint-config": "0.0.0",
|
|
47
47
|
"@repo/typescript-config": "0.0.0",
|
|
48
48
|
"@types/node": "20.19.43",
|