@ebay-dt/bonfire-next 0.2.0-alpha.10 → 0.2.0-alpha.12
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/README.md +9 -3
- package/dist/client/lifecycle-provider.d.ts.map +1 -1
- package/dist/client/lifecycle-provider.js +1 -1
- package/dist/client/lifecycle-provider.js.map +1 -1
- package/dist/server/create-bonfire-next.d.ts +3 -0
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +3 -27
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/entry-coordinator.d.ts +15 -4
- package/dist/server/entry-coordinator.d.ts.map +1 -1
- package/dist/server/entry-coordinator.js +13 -7
- package/dist/server/entry-coordinator.js.map +1 -1
- package/dist/server/prototype-actions.d.ts +3 -1
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +44 -1
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/repository-actions.d.ts +6 -4
- package/dist/server/repository-actions.d.ts.map +1 -1
- package/dist/server/repository-actions.js +61 -1
- package/dist/server/repository-actions.js.map +1 -1
- package/dist/server/repository-routes.d.ts +1 -0
- package/dist/server/repository-routes.d.ts.map +1 -1
- package/dist/server/repository-routes.js +7 -0
- package/dist/server/repository-routes.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -109,8 +109,12 @@ Run `bonfire prepare` before development so the secret exists in
|
|
|
109
109
|
The explicit repository root enables request-time discovery under
|
|
110
110
|
`src/app/(prototypes)` without relying on package-internal `process.cwd()`.
|
|
111
111
|
`BF_PROTOTYPE_BASE_BRANCH` can override the default `main` branch used as the
|
|
112
|
-
base for identity branches.
|
|
113
|
-
|
|
112
|
+
base for identity branches. A missing base branch reports repository attention
|
|
113
|
+
without silently using the current branch. Set `BF_GIT_MODE=manual` to disable
|
|
114
|
+
all Bonfire Git mutations while retaining filesystem lifecycle actions and
|
|
115
|
+
read-only local Git observation; `managed` is the default. This is distinct
|
|
116
|
+
from `BF_DISABLE_AUTO_BRANCH_SWITCH=true`, which skips automatic branch
|
|
117
|
+
selection but does not disable managed commits and pushes.
|
|
114
118
|
|
|
115
119
|
A development instance can also receive a trusted server-only
|
|
116
120
|
`preparePrototypeFiles` callback. It runs after Bonfire scaffolds or
|
|
@@ -146,7 +150,9 @@ export default async function RootLayout({ children }: LayoutProps<"/">) {
|
|
|
146
150
|
`getAppLayoutModel()` returns a paired set of opaque document props and
|
|
147
151
|
serializable header props. Spread `htmlProps` on `<html>` and `headerProps` on
|
|
148
152
|
`<AppHeader>`; do not omit the document props when rendering the header. Both
|
|
149
|
-
values come from the same `getAppLayoutModel()` result.
|
|
153
|
+
values come from the same `getAppLayoutModel()` result. With repository actions
|
|
154
|
+
configured, the header checks for updates when opened in development and offers
|
|
155
|
+
Get updates/preparation without applying updates on open. Render `AppHeader` in
|
|
150
156
|
the route layout that owns it. Keep the dashboard header in a system layout and
|
|
151
157
|
the prototype header inside the prototype environment, so the header can
|
|
152
158
|
consume the environment context:
|
|
@@ -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\"\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
|
|
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\n controller={controller}\n getPendingRecovery={actions.getPendingRecovery}\n >\n {children}\n </LifecycleProvider>\n </RepositoryActionsProvider>\n );\n}\n"]}
|
|
@@ -52,6 +52,6 @@ function EnabledNextLifecycleProvider({ actions, repositoryActions, children, us
|
|
|
52
52
|
useEffect(() => {
|
|
53
53
|
route.setPathname(pathname);
|
|
54
54
|
}, [pathname, route]);
|
|
55
|
-
return (_jsx(RepositoryActionsProvider, { actions: repositoryActions, children: _jsx(LifecycleProvider, { controller: controller, children: children }) }));
|
|
55
|
+
return (_jsx(RepositoryActionsProvider, { actions: repositoryActions, children: _jsx(LifecycleProvider, { controller: controller, getPendingRecovery: actions.getPendingRecovery, children: children }) }));
|
|
56
56
|
}
|
|
57
57
|
//# sourceMappingURL=lifecycle-provider.js.map
|
|
@@ -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,GASpB;IACC,MAAM,QAAQ,GAAG,WAAW,EAAE,IAAI,GAAG,CAAC;IACtC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC5B,IAAI,eA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EAAE,CAAC,CAC3D,CAAC;IACF,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CACjC,yBAAyB,CAAC;QACxB,OAAO;QACP,UAAU;QACV,KAAK,EAAE,KAAK,CAAC,OAAO;QACpB,IAAI;QACJ,gBAAgB;QAChB,mBAAmB;KACpB,CAAC,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtB,OAAO,CACL,KAAC,yBAAyB,IAAC,OAAO,EAAE,iBAAiB,YACnD,KAAC,iBAAiB,IAChB,UAAU,EAAE,UAAU,EACtB,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,YAE7C,QAAQ,GACS,GACM,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\n controller={controller}\n getPendingRecovery={actions.getPendingRecovery}\n >\n {children}\n </LifecycleProvider>\n </RepositoryActionsProvider>\n );\n}\n"]}
|
|
@@ -5,7 +5,9 @@ import { type CSSProperties } from "react";
|
|
|
5
5
|
import { type LoginSearchParams } from "./login-page-model.js";
|
|
6
6
|
export type CreateBonfireNextOptions = BonfireConfigInput & {
|
|
7
7
|
repositoryRoot: string;
|
|
8
|
+
/** Shared with CLI startup through BF_* environment settings. */
|
|
8
9
|
prototypeRoot?: string;
|
|
10
|
+
remote?: string;
|
|
9
11
|
primaryBranch?: string;
|
|
10
12
|
sessionSecret?: string;
|
|
11
13
|
githubCli?: GitHubCliClientLike;
|
|
@@ -17,6 +19,7 @@ export type CreateBonfireNextOptions = BonfireConfigInput & {
|
|
|
17
19
|
preparePrototypeFiles?: PreparePrototypeFiles;
|
|
18
20
|
disableAutoBranchSwitch?: string;
|
|
19
21
|
gitMode?: GitMode;
|
|
22
|
+
installDependencies?: (root: string) => Promise<void>;
|
|
20
23
|
};
|
|
21
24
|
export type PrototypeCapabilities = {
|
|
22
25
|
deployment: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-bonfire-next.d.ts","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,OAAO,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAY/B,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,eAAe,CAAC,EAAE,yBAAyB,CAAC;IAC5C,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,yBAAyB,CAAC;CAChC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE;QACT,KAAK,EAAE,aAAa,CAAC;KACtB,CAAC;IACF,WAAW,EAAE;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;QAC7B,gBAAgB,CAAC,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,kBAAkB,EAAE,MAAM,CAAA;SAAE,CAAC;KAChE,CAAC;CACH,CAAC;AAQF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCA4KvB,OAAO,CAAC,cAAc,CAAC;2CA0BhD,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;EA2DhE","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n 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
|
+
{"version":3,"file":"create-bonfire-next.d.ts","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,OAAO,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAML,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAW/B,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,GAAG;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,C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ManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: { 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 remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n });\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"]}
|
|
@@ -11,7 +11,6 @@ import { createPrototypeAgentActions } from "./agent-actions.js";
|
|
|
11
11
|
import { createPrototypeDashboardModelLoader } from "./prototype-dashboard.js";
|
|
12
12
|
import { createPrototypeEnvironmentModelLoader } from "./prototype-environment.js";
|
|
13
13
|
import { createPrototypeRoutes } from "./prototype-routes.js";
|
|
14
|
-
import { createEntrySynchronizationCoordinator } from "./entry-coordinator.js";
|
|
15
14
|
import { createRepositoryActions } from "./repository-actions.js";
|
|
16
15
|
import { createRepositoryRoutes } from "./repository-routes.js";
|
|
17
16
|
import { getPrototypeSourceRepository } from "./prototype-source-link.js";
|
|
@@ -63,40 +62,20 @@ export function createBonfireNext(options) {
|
|
|
63
62
|
repositoryRoot: options.repositoryRoot,
|
|
64
63
|
prototypeRoot: options.prototypeRoot,
|
|
65
64
|
primaryBranch: options.primaryBranch,
|
|
65
|
+
remote: options.remote,
|
|
66
66
|
automaticBranchSwitch,
|
|
67
67
|
gitMode,
|
|
68
68
|
applicationId: config.appId,
|
|
69
69
|
catalog: prototypeCatalog,
|
|
70
70
|
deploymentProvider: options.deploymentProvider,
|
|
71
71
|
preparePrototypeFiles: options.preparePrototypeFiles,
|
|
72
|
+
installDependencies: options.installDependencies,
|
|
72
73
|
themeRegistry: config.themes,
|
|
73
74
|
}));
|
|
74
75
|
const deploymentAvailable = !production &&
|
|
75
76
|
gitMode === "managed" &&
|
|
76
77
|
(options.deploymentProvider !== undefined ||
|
|
77
78
|
options.prototypeLifecycle?.deploy !== undefined);
|
|
78
|
-
const entrySynchronization = createEntrySynchronizationCoordinator({
|
|
79
|
-
lifecycle,
|
|
80
|
-
onStatus: production
|
|
81
|
-
? undefined
|
|
82
|
-
: ({ identity, status, result }) => {
|
|
83
|
-
if (status === "started") {
|
|
84
|
-
console.info(`[bonfire] Preparing repository branch for ${identity.login}…`);
|
|
85
|
-
}
|
|
86
|
-
else if (status === "deferred") {
|
|
87
|
-
console.warn(`[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`);
|
|
88
|
-
}
|
|
89
|
-
else if (result?.status === "ready") {
|
|
90
|
-
console.info(`[bonfire] Branch preparation completed for ${identity.login}.`);
|
|
91
|
-
}
|
|
92
|
-
else if (result?.status === "disabled") {
|
|
93
|
-
console.info(`[bonfire] Branch preparation skipped for ${identity.login}.`);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
console.warn(`[bonfire] Branch preparation completed with repository attention for ${identity.login}.`);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
79
|
const getCurrentUser = cache(() => getSession());
|
|
101
80
|
const prototypeActions = createPrototypeActions({
|
|
102
81
|
production,
|
|
@@ -108,10 +87,9 @@ export function createBonfireNext(options) {
|
|
|
108
87
|
const repositoryActions = createRepositoryActions({
|
|
109
88
|
production,
|
|
110
89
|
gitMode,
|
|
90
|
+
automaticBranchSwitch,
|
|
111
91
|
getCurrentUser: getSession,
|
|
112
92
|
lifecycle,
|
|
113
|
-
entrySynchronizationInFlight: entrySynchronization.isInFlight,
|
|
114
|
-
waitForEntrySynchronization: entrySynchronization.waitForCompletion,
|
|
115
93
|
});
|
|
116
94
|
const repositoryRoutes = createRepositoryRoutes({
|
|
117
95
|
production,
|
|
@@ -165,8 +143,6 @@ export function createBonfireNext(options) {
|
|
|
165
143
|
const getCurrentRouteModel = cache(getCurrentRouteModelUncached);
|
|
166
144
|
const getAppLayoutModel = cache(async () => {
|
|
167
145
|
const user = production ? null : await getCurrentUser();
|
|
168
|
-
if (user !== null)
|
|
169
|
-
await entrySynchronization.synchronize(user);
|
|
170
146
|
const sourceRepository = user === null
|
|
171
147
|
? undefined
|
|
172
148
|
: await getPrototypeSourceRepository({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-bonfire-next.js","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,iCAAiC,EACjC,mBAAmB,GAKpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,GAO7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,qCAAqC,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,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,4BAA4B,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E,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
|
+
{"version":3,"file":"create-bonfire-next.js","sourceRoot":"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AAO,EAAE,KAAK;4BACd,UAAU,EAAE,KAAK;4BACjB,MAAM,EAAE,KAAK;yBACd;wBACH,CAAC,CAAC,EAAE,CAAC;iBACR;aAC8B;YACjC,SAAS;YACT,OAAO,EAAE,gBAAgB;YACzB,UAAU,EAAE,iBAAiB;YAC7B,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,EAAE,GAAG,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE;SAC7D;QACD,IAAI,EAAE;YACJ,UAAU;YACV,cAAc;YACd,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\nimport { getPrototypeSourceRepository } from \"./prototype-source-link.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n /** Shared with CLI startup through BF_* environment settings. */\n prototypeRoot?: string;\n remote?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n installDependencies?: (root: string) => Promise<void>;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n sourceRepository?: { 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 remote: options.remote,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n installDependencies: options.installDependencies,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n automaticBranchSwitch,\n getCurrentUser: getSession,\n lifecycle,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n const sourceRepository =\n user === null\n ? undefined\n : await getPrototypeSourceRepository({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n hostname: config.auth.github.hostname,\n });\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,9 +1,19 @@
|
|
|
1
|
-
import type { BonfireIdentity, BranchPreparationValue } from "@ebay-dt/bonfire-core";
|
|
1
|
+
import type { BonfireIdentity, BranchPreparationValue, LifecycleErrorCode } from "@ebay-dt/bonfire-core";
|
|
2
2
|
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
3
|
type EntryLifecycle = Pick<PrototypeLifecycle, "prepareBranch">;
|
|
4
|
+
export type EntrySynchronizationCompletion = {
|
|
5
|
+
status: "completed";
|
|
6
|
+
preparation: BranchPreparationValue;
|
|
7
|
+
} | {
|
|
8
|
+
status: "failed";
|
|
9
|
+
error: LifecycleErrorCode;
|
|
10
|
+
};
|
|
11
|
+
export type EntrySynchronizationResult = EntrySynchronizationCompletion | {
|
|
12
|
+
status: "in-flight";
|
|
13
|
+
};
|
|
4
14
|
export type EntrySynchronizationStatus = "started" | "deferred" | "completed";
|
|
5
15
|
export type EntrySynchronizationCoordinator = {
|
|
6
|
-
synchronize(identity: BonfireIdentity): Promise<
|
|
16
|
+
synchronize(identity: BonfireIdentity): Promise<EntrySynchronizationResult | null>;
|
|
7
17
|
waitForCompletion(identity: BonfireIdentity): Promise<void>;
|
|
8
18
|
isInFlight(identity: BonfireIdentity): boolean;
|
|
9
19
|
};
|
|
@@ -13,8 +23,8 @@ export type EntrySynchronizationCoordinator = {
|
|
|
13
23
|
* not repeated until the process is restarted.
|
|
14
24
|
*
|
|
15
25
|
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
16
|
-
* timed-out request continues the operation in-process while allowing the
|
|
17
|
-
*
|
|
26
|
+
* timed-out request continues the operation in-process while allowing the page
|
|
27
|
+
* render to proceed with an explicitly in-flight result.
|
|
18
28
|
*/
|
|
19
29
|
export declare function createEntrySynchronizationCoordinator(options: {
|
|
20
30
|
lifecycle: EntryLifecycle | null;
|
|
@@ -23,6 +33,7 @@ export declare function createEntrySynchronizationCoordinator(options: {
|
|
|
23
33
|
identity: BonfireIdentity;
|
|
24
34
|
status: EntrySynchronizationStatus;
|
|
25
35
|
result?: BranchPreparationValue;
|
|
36
|
+
error?: LifecycleErrorCode;
|
|
26
37
|
}): void;
|
|
27
38
|
}): EntrySynchronizationCoordinator;
|
|
28
39
|
export {};
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,kBAAkB,EAEnB,MAAM,uBAAuB,CA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from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\nexport type EntrySynchronizationCompletion =\n | { status: \"completed\"; preparation: BranchPreparationValue }\n | { status: \"failed\"; error: LifecycleErrorCode };\n\nexport type EntrySynchronizationResult =\n EntrySynchronizationCompletion | { status: \"in-flight\" };\n\ntype InFlightAttempt = {\n completion: Promise<EntrySynchronizationCompletion>;\n renderWait: Promise<EntrySynchronizationResult>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<EntrySynchronizationResult | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the page\n * render to proceed with an explicitly in-flight result.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, EntrySynchronizationCompletion>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<EntrySynchronizationCompletion>,\n ): Promise<EntrySynchronizationResult> {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<EntrySynchronizationResult>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"in-flight\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result: LifecycleResult<BranchPreparationValue>) =>\n result.ok\n ? ({ status: \"completed\", preparation: result.value } as const)\n : ({ status: \"failed\", error: result.error.code } as const),\n )\n .catch(\n () => ({ status: \"failed\", error: \"unexpected-failure\" }) as const,\n );\n\n let completion!: Promise<EntrySynchronizationCompletion>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({\n identity,\n status: \"completed\",\n ...(result.status === \"completed\"\n ? { result: result.preparation }\n : { error: result.error }),\n });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
|
@@ -5,8 +5,8 @@ const DEFAULT_ENTRY_WAIT_MS = 10_000;
|
|
|
5
5
|
* not repeated until the process is restarted.
|
|
6
6
|
*
|
|
7
7
|
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
8
|
-
* timed-out request continues the operation in-process while allowing the
|
|
9
|
-
*
|
|
8
|
+
* timed-out request continues the operation in-process while allowing the page
|
|
9
|
+
* render to proceed with an explicitly in-flight result.
|
|
10
10
|
*/
|
|
11
11
|
export function createEntrySynchronizationCoordinator(options) {
|
|
12
12
|
const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;
|
|
@@ -31,7 +31,7 @@ export function createEntrySynchronizationCoordinator(options) {
|
|
|
31
31
|
deferredReported.add(identity.login);
|
|
32
32
|
report({ identity, status: "deferred" });
|
|
33
33
|
}
|
|
34
|
-
resolve({ status: "
|
|
34
|
+
resolve({ status: "in-flight" });
|
|
35
35
|
}, waitMs);
|
|
36
36
|
});
|
|
37
37
|
return Promise.race([completion, deferred]).finally(() => {
|
|
@@ -52,14 +52,20 @@ export function createEntrySynchronizationCoordinator(options) {
|
|
|
52
52
|
const attempt = options.lifecycle
|
|
53
53
|
.prepareBranch(identity)
|
|
54
54
|
.then((result) => result.ok
|
|
55
|
-
? result.value
|
|
56
|
-
: { status: "
|
|
57
|
-
.catch(() => ({ status: "
|
|
55
|
+
? { status: "completed", preparation: result.value }
|
|
56
|
+
: { status: "failed", error: result.error.code })
|
|
57
|
+
.catch(() => ({ status: "failed", error: "unexpected-failure" }));
|
|
58
58
|
let completion;
|
|
59
59
|
completion = attempt
|
|
60
60
|
.then((result) => {
|
|
61
61
|
completed.set(identity.login, result);
|
|
62
|
-
report({
|
|
62
|
+
report({
|
|
63
|
+
identity,
|
|
64
|
+
status: "completed",
|
|
65
|
+
...(result.status === "completed"
|
|
66
|
+
? { result: result.preparation }
|
|
67
|
+
: { error: result.error }),
|
|
68
|
+
});
|
|
63
69
|
return result;
|
|
64
70
|
})
|
|
65
71
|
.finally(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"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EAAE,WAAW;gBACnB,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW;oBAC/B,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;oBAChC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;aAC7B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACZ,gBAAgB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACxC,IAAI,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,KAAK,UAAU,EAAE,CAAC;gBAC5D,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC,CAAC,CAAC;QACL,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAEzD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,KAAK,UAAU,iBAAiB,CAAC,QAAyB;QACxD,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACjD,CAAC;IAED,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;KACvD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n LifecycleErrorCode,\n LifecycleResult,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\nexport type EntrySynchronizationCompletion =\n | { status: \"completed\"; preparation: BranchPreparationValue }\n | { status: \"failed\"; error: LifecycleErrorCode };\n\nexport type EntrySynchronizationResult =\n EntrySynchronizationCompletion | { status: \"in-flight\" };\n\ntype InFlightAttempt = {\n completion: Promise<EntrySynchronizationCompletion>;\n renderWait: Promise<EntrySynchronizationResult>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(\n identity: BonfireIdentity,\n ): Promise<EntrySynchronizationResult | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the page\n * render to proceed with an explicitly in-flight result.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, EntrySynchronizationCompletion>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n error?: LifecycleErrorCode;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<EntrySynchronizationCompletion>,\n ): Promise<EntrySynchronizationResult> {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<EntrySynchronizationResult>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"in-flight\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result: LifecycleResult<BranchPreparationValue>) =>\n result.ok\n ? ({ status: \"completed\", preparation: result.value } as const)\n : ({ status: \"failed\", error: result.error.code } as const),\n )\n .catch(\n () => ({ status: \"failed\", error: \"unexpected-failure\" }) as const,\n );\n\n let completion!: Promise<EntrySynchronizationCompletion>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({\n identity,\n status: \"completed\",\n ...(result.status === \"completed\"\n ? { result: result.preparation }\n : { error: result.error }),\n });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CreatePrototypeInput, type CreatePrototypeValue, type DeletePrototypeValue, type DeploymentValue, type DiscardPrototypeValue, type DuplicatePrototypeInput, type DuplicatePrototypeValue, type EditPrototypeInput, type EditPrototypeValue, type GitMode, type LifecycleResult, type PrototypeCommandInput, type SavePrototypeValue, type BonfireIdentity, type ThemeRegistry } from "@ebay-dt/bonfire-core";
|
|
1
|
+
import { type CreatePrototypeInput, type CreatePrototypeValue, type DeletePrototypeValue, type DeploymentValue, type DiscardPrototypeValue, type DuplicatePrototypeInput, type DuplicatePrototypeValue, type EditPrototypeInput, type EditPrototypeValue, type GitMode, type LifecycleResult, type LifecycleRecoveryValue, type PrototypeCommandInput, type SavePrototypeValue, type BonfireIdentity, type ThemeRegistry } from "@ebay-dt/bonfire-core";
|
|
2
2
|
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
3
|
export type PrototypeActions = {
|
|
4
4
|
create(input: CreatePrototypeInput): Promise<LifecycleResult<CreatePrototypeValue>>;
|
|
@@ -9,6 +9,8 @@ export type PrototypeActions = {
|
|
|
9
9
|
discard(input: PrototypeCommandInput): Promise<LifecycleResult<DiscardPrototypeValue>>;
|
|
10
10
|
deploy(input: PrototypeCommandInput): Promise<LifecycleResult<DeploymentValue>>;
|
|
11
11
|
retryPublish?(input: PrototypeCommandInput): Promise<LifecycleResult<DeploymentValue>>;
|
|
12
|
+
getPendingRecovery(): Promise<LifecycleResult<LifecycleRecoveryValue | null>>;
|
|
13
|
+
retryPendingPublication(recoveryId: string): Promise<LifecycleResult<LifecycleRecoveryValue>>;
|
|
12
14
|
};
|
|
13
15
|
export type PrototypeActionsOptions = {
|
|
14
16
|
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,kB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,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
|
+
{"version":3,"file":"prototype-actions.d.ts","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,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,sBAAsB,EAC3B,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;IAC7C,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC,CAAC;IAC9E,uBAAuB,CACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC,CAAC;CACrD,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;AA0BF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CA+SlB","sourcesContent":["import {\n lifecycleFailure,\n lifecycleSuccess,\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 LifecycleRecoveryValue,\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 getPendingRecovery(): Promise<LifecycleResult<LifecycleRecoveryValue | null>>;\n retryPendingPublication(\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>>;\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 | \"retry-pending-publication\"\n | \"get-pending-recovery\",\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 getPendingRecovery(): Promise<\n LifecycleResult<LifecycleRecoveryValue | null>\n > {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.getPendingRecovery === undefined\n ) {\n return lifecycleSuccess(null);\n }\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.getPendingRecovery(identity);\n } catch {\n logUnexpectedFailure(\"get-pending-recovery\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function retryPendingPublication(\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.retryPendingPublication === undefined\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n if (typeof recoveryId !== \"string\" || recoveryId.length === 0) {\n return lifecycleFailure(\"invalid-input\");\n }\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.retryPendingPublication(\n identity,\n recoveryId,\n );\n } catch {\n logUnexpectedFailure(\"retry-pending-publication\");\n return lifecycleFailure(\"deployment-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 getPendingRecovery,\n retryPendingPublication,\n };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lifecycleFailure, parseCreatePrototypeInput, parseDuplicatePrototypeInput, parseEditPrototypeInput, parsePrototypeCommandInput, LifecycleInputError, } from "@ebay-dt/bonfire-core";
|
|
1
|
+
import { lifecycleFailure, lifecycleSuccess, parseCreatePrototypeInput, parseDuplicatePrototypeInput, parseEditPrototypeInput, parsePrototypeCommandInput, LifecycleInputError, } from "@ebay-dt/bonfire-core";
|
|
2
2
|
function isManualLifecycleCompatible(options) {
|
|
3
3
|
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
4
4
|
}
|
|
@@ -126,6 +126,47 @@ export function createPrototypeActions(options) {
|
|
|
126
126
|
return lifecycleFailure("unexpected-failure");
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
async function getPendingRecovery() {
|
|
130
|
+
if (options.production || options.gitMode === "manual") {
|
|
131
|
+
return lifecycleFailure("forbidden");
|
|
132
|
+
}
|
|
133
|
+
if (options.lifecycle === null ||
|
|
134
|
+
options.lifecycle.getPendingRecovery === undefined) {
|
|
135
|
+
return lifecycleSuccess(null);
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const identity = await options.getCurrentUser();
|
|
139
|
+
if (identity === null)
|
|
140
|
+
return lifecycleFailure("unauthenticated");
|
|
141
|
+
return await options.lifecycle.getPendingRecovery(identity);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
logUnexpectedFailure("get-pending-recovery");
|
|
145
|
+
return lifecycleFailure("unexpected-failure");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function retryPendingPublication(recoveryId) {
|
|
149
|
+
if (options.production || options.gitMode === "manual") {
|
|
150
|
+
return lifecycleFailure("forbidden");
|
|
151
|
+
}
|
|
152
|
+
if (options.lifecycle === null ||
|
|
153
|
+
options.lifecycle.retryPendingPublication === undefined) {
|
|
154
|
+
return lifecycleFailure("deployment-unavailable");
|
|
155
|
+
}
|
|
156
|
+
if (typeof recoveryId !== "string" || recoveryId.length === 0) {
|
|
157
|
+
return lifecycleFailure("invalid-input");
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const identity = await options.getCurrentUser();
|
|
161
|
+
if (identity === null)
|
|
162
|
+
return lifecycleFailure("unauthenticated");
|
|
163
|
+
return await options.lifecycle.retryPendingPublication(identity, recoveryId);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
logUnexpectedFailure("retry-pending-publication");
|
|
167
|
+
return lifecycleFailure("deployment-failure");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
129
170
|
async function retryPublish(input) {
|
|
130
171
|
if (options.production || options.gitMode === "manual") {
|
|
131
172
|
return lifecycleFailure("forbidden");
|
|
@@ -208,6 +249,8 @@ export function createPrototypeActions(options) {
|
|
|
208
249
|
discard,
|
|
209
250
|
deploy,
|
|
210
251
|
retryPublish,
|
|
252
|
+
getPendingRecovery,
|
|
253
|
+
retryPendingPublication,
|
|
211
254
|
};
|
|
212
255
|
}
|
|
213
256
|
//# sourceMappingURL=prototype-actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-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ePrototypeInput,\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"]}
|
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AC;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;QACZ,kBAAkB;QAClB,uBAAuB;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n lifecycleSuccess,\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 LifecycleRecoveryValue,\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 getPendingRecovery(): Promise<LifecycleResult<LifecycleRecoveryValue | null>>;\n retryPendingPublication(\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>>;\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 | \"retry-pending-publication\"\n | \"get-pending-recovery\",\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 getPendingRecovery(): Promise<\n LifecycleResult<LifecycleRecoveryValue | null>\n > {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.getPendingRecovery === undefined\n ) {\n return lifecycleSuccess(null);\n }\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.getPendingRecovery(identity);\n } catch {\n logUnexpectedFailure(\"get-pending-recovery\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function retryPendingPublication(\n recoveryId: string,\n ): Promise<LifecycleResult<LifecycleRecoveryValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.retryPendingPublication === undefined\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n if (typeof recoveryId !== \"string\" || recoveryId.length === 0) {\n return lifecycleFailure(\"invalid-input\");\n }\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.retryPendingPublication(\n identity,\n recoveryId,\n );\n } catch {\n logUnexpectedFailure(\"retry-pending-publication\");\n return lifecycleFailure(\"deployment-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 getPendingRecovery,\n retryPendingPublication,\n };\n}\n"]}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { type BonfireIdentity, type GitMode, type LifecycleResult, type PrototypeCommandInput, type RepositorySummary } from "@ebay-dt/bonfire-core";
|
|
1
|
+
import { type BonfireIdentity, type GitMode, type AutomaticBranchSwitchMode, type LifecycleResult, type PrototypeCommandInput, type RepositorySummary, type RepositoryUpdateValue, type DependencyPreparationValue } from "@ebay-dt/bonfire-core";
|
|
2
2
|
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
3
|
export type RepositoryActions = {
|
|
4
4
|
getSummary(): Promise<LifecycleResult<RepositorySummary>>;
|
|
5
5
|
check(): Promise<LifecycleResult<RepositorySummary>>;
|
|
6
|
-
applyUpdates(): Promise<LifecycleResult<
|
|
7
|
-
retry(): Promise<LifecycleResult<
|
|
6
|
+
applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;
|
|
7
|
+
retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;
|
|
8
|
+
retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;
|
|
8
9
|
save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;
|
|
9
10
|
discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;
|
|
10
11
|
};
|
|
11
|
-
type RepositoryLifecycle = Pick<PrototypeLifecycle, "gitMode" | "getRepositorySummary" | "checkRepositorySummary" | "prepareBranch"> & Partial<Pick<PrototypeLifecycle, "save" | "discard">>;
|
|
12
|
+
type RepositoryLifecycle = Pick<PrototypeLifecycle, "gitMode" | "getRepositorySummary" | "checkRepositorySummary" | "prepareBranch"> & Partial<Pick<PrototypeLifecycle, "save" | "discard" | "prepareDependencies">>;
|
|
12
13
|
export type RepositoryActionsOptions = {
|
|
13
14
|
production: boolean;
|
|
14
15
|
gitMode: GitMode;
|
|
16
|
+
automaticBranchSwitch?: AutomaticBranchSwitchMode;
|
|
15
17
|
getCurrentUser: () => Promise<BonfireIdentity | null>;
|
|
16
18
|
lifecycle: RepositoryLifecycle | null;
|
|
17
19
|
now?: () => number;
|
|
@@ -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,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrD,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC5D,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3E,CAAC;AAEF,KAAK,mBAAmB,GAAG,IAAI,CAC7B,kBAAkB,EAChB,SAAS,GACT,sBAAsB,GACtB,wBAAwB,GACxB,eAAe,CAClB,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAExD,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;IACtE,2BAA2B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E,CAAC;AAyBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,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
|
+
{"version":3,"file":"repository-actions.d.ts","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrD,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAChE,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3E,CAAC;AAEF,KAAK,mBAAmB,GAAG,IAAI,CAC7B,kBAAkB,EAChB,SAAS,GACT,sBAAsB,GACtB,wBAAwB,GACxB,eAAe,CAClB,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB,CAAC,EAAE,yBAAyB,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;IACtE,2BAA2B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E,CAAC;AAyBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAqPnB","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
@@ -138,6 +138,27 @@ export function createRepositoryActions(options) {
|
|
|
138
138
|
invalidateChecks(identity.login);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
async function retryPreparation() {
|
|
142
|
+
if (options.production ||
|
|
143
|
+
options.lifecycle === null ||
|
|
144
|
+
options.gitMode === "manual" ||
|
|
145
|
+
options.automaticBranchSwitch === "disabled" ||
|
|
146
|
+
!compatible(options)) {
|
|
147
|
+
return unavailable();
|
|
148
|
+
}
|
|
149
|
+
const identity = await identityOrFailure();
|
|
150
|
+
if (identity === null)
|
|
151
|
+
return lifecycleFailure("unauthenticated");
|
|
152
|
+
if (options.lifecycle.prepareDependencies === undefined) {
|
|
153
|
+
return lifecycleFailure("forbidden");
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return await options.lifecycle.prepareDependencies();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return lifecycleFailure("unexpected-failure");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
141
162
|
async function applyUpdates() {
|
|
142
163
|
if (options.production ||
|
|
143
164
|
options.lifecycle === null ||
|
|
@@ -153,7 +174,45 @@ export function createRepositoryActions(options) {
|
|
|
153
174
|
const preparation = await options.lifecycle.prepareBranch(identity);
|
|
154
175
|
if (!preparation.ok)
|
|
155
176
|
return lifecycleFailure(preparation.error.code);
|
|
156
|
-
|
|
177
|
+
let dependencyPreparation;
|
|
178
|
+
const dependencyPaths = preparation.value.effects.dependencyPaths ?? [];
|
|
179
|
+
const preparationRequired = preparation.value.effects.preparationRequired === true ||
|
|
180
|
+
dependencyPaths.length > 0;
|
|
181
|
+
// Deferred/unsafe Git reconciliation is not an install boundary. In
|
|
182
|
+
// particular, never install against a partially applied baseline.
|
|
183
|
+
if (preparation.value.status === "ready" &&
|
|
184
|
+
preparationRequired &&
|
|
185
|
+
options.lifecycle.prepareDependencies !== undefined) {
|
|
186
|
+
const dependencies = await options.lifecycle.prepareDependencies(dependencyPaths);
|
|
187
|
+
if (!dependencies.ok)
|
|
188
|
+
return lifecycleFailure(dependencies.error.code);
|
|
189
|
+
dependencyPreparation = dependencies.value;
|
|
190
|
+
}
|
|
191
|
+
else if (preparationRequired &&
|
|
192
|
+
preparation.value.status === "ready" &&
|
|
193
|
+
preparationRequired &&
|
|
194
|
+
options.lifecycle.prepareDependencies === undefined) {
|
|
195
|
+
// A lifecycle that cannot perform the shared preparation contract is
|
|
196
|
+
// incompatible with a required update; do not silently claim ready.
|
|
197
|
+
return lifecycleFailure("forbidden");
|
|
198
|
+
}
|
|
199
|
+
let summaryRefresh;
|
|
200
|
+
try {
|
|
201
|
+
const refreshed = await options.lifecycle.getRepositorySummary(identity);
|
|
202
|
+
summaryRefresh = refreshed.ok
|
|
203
|
+
? { status: "refreshed", summary: refreshed.value }
|
|
204
|
+
: { status: "failed", error: refreshed.error.code };
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
summaryRefresh = { status: "failed", error: "unexpected-failure" };
|
|
208
|
+
}
|
|
209
|
+
return lifecycleSuccess({
|
|
210
|
+
preparation: preparation.value,
|
|
211
|
+
summaryRefresh,
|
|
212
|
+
...(dependencyPreparation === undefined
|
|
213
|
+
? {}
|
|
214
|
+
: { dependencyPreparation }),
|
|
215
|
+
});
|
|
157
216
|
}
|
|
158
217
|
catch {
|
|
159
218
|
return lifecycleFailure("unexpected-failure");
|
|
@@ -167,6 +226,7 @@ export function createRepositoryActions(options) {
|
|
|
167
226
|
check,
|
|
168
227
|
applyUpdates,
|
|
169
228
|
retry: applyUpdates,
|
|
229
|
+
retryPreparation,
|
|
170
230
|
save: (input) => scopedMutation("save", input),
|
|
171
231
|
discard: (input) => scopedMutation("discard", input),
|
|
172
232
|
};
|
|
@@ -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,OAAiC;IACnD,OAAO,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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"]}
|
|
1
|
+
{"version":3,"file":"repository-actions.js","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,GASjB,MAAM,uBAAuB,CAAC;AAkC/B,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC,SAAS,UAAU,CAAC,OAAiC;IACnD,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,WAAW;IAClB,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,eAAe,CAAC,IAAa;IACpC,OAAO;QACL,IAAI;QACJ,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,4BAA4B,CAAC,IAAI,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,OAAiC;IAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACpC,MAAM,UAAU,GAAG,OAAO,CAAC,eAAe,IAAI,yBAAyB,CAAC;IACxE,MAAM,QAAQ,GAAG,IAAI,GAAG,EAMrB,CAAC;IACJ,MAAM,cAAc,GAAG,IAAI,GAAG,EAG3B,CAAC;IACJ,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEnD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AE,qBAAqB,EAAE,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;gBAAS,CAAC;YACT,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,KAAK;QACL,YAAY;QACZ,KAAK,EAAE,YAAY;QACnB,gBAAgB;QAChB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;QAC9C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC;KACrD,CAAC;AACJ,CAAC","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-routes.d.ts","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repository-routes.d.ts","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;CACvC,CAAC;AAqBF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,gBAAgB,CAgCnB","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport { lifecycleFailure, type LifecycleResult } from \"@ebay-dt/bonfire-core\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n retryPreparation(): Promise<Response>;\n};\n\nfunction responseFor<Value>(result: LifecycleResult<Value>) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n async retryPreparation() {\n return options.production\n ? unavailable()\n : responseFor(\n await (options.actions.retryPreparation?.() ??\n Promise.resolve(lifecycleFailure(\"forbidden\"))),\n );\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextResponse } from "next/server.js";
|
|
2
|
+
import { lifecycleFailure } from "@ebay-dt/bonfire-core";
|
|
2
3
|
function responseFor(result) {
|
|
3
4
|
if (result.ok) {
|
|
4
5
|
return NextResponse.json(result.value, {
|
|
@@ -38,6 +39,12 @@ export function createRepositoryRoutes(options) {
|
|
|
38
39
|
? unavailable()
|
|
39
40
|
: responseFor(await options.actions.retry());
|
|
40
41
|
},
|
|
42
|
+
async retryPreparation() {
|
|
43
|
+
return options.production
|
|
44
|
+
? unavailable()
|
|
45
|
+
: responseFor(await (options.actions.retryPreparation?.() ??
|
|
46
|
+
Promise.resolve(lifecycleFailure("forbidden"))));
|
|
47
|
+
},
|
|
41
48
|
};
|
|
42
49
|
}
|
|
43
50
|
//# sourceMappingURL=repository-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-routes.js","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"repository-routes.js","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAW/E,SAAS,WAAW,CAAQ,MAA8B;IACxD,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE;SACzC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,MAAM,GACV,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,iBAAiB;QACrC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW;YACjC,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,GAAG,CAAC;IACZ,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE;QAC5B,MAAM;QACN,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE;KACzC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,OAGtC;IACC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9D,OAAO;QACL,KAAK,CAAC,OAAO;YACX,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,KAAK,CAAC,KAAK;YACT,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,CAAC,MAAM;YACV,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,KAAK,CAAC,KAAK;YACT,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,CAAC,gBAAgB;YACpB,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CACT,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE;oBACzC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAClD,CAAC;QACR,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport { lifecycleFailure, type LifecycleResult } from \"@ebay-dt/bonfire-core\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n retryPreparation(): Promise<Response>;\n};\n\nfunction responseFor<Value>(result: LifecycleResult<Value>) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n async retryPreparation() {\n return options.production\n ? unavailable()\n : responseFor(\n await (options.actions.retryPreparation?.() ??\n Promise.resolve(lifecycleFailure(\"forbidden\"))),\n );\n },\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.12",
|
|
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.12",
|
|
35
|
+
"@ebay-dt/bonfire-node": "0.2.0-alpha.12",
|
|
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.12",
|
|
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.12",
|
|
46
46
|
"@repo/eslint-config": "0.0.0",
|
|
47
47
|
"@repo/typescript-config": "0.0.0",
|
|
48
48
|
"@types/node": "20.19.43",
|