@ebay-dt/bonfire-next 0.1.0 → 0.2.0-alpha.3
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 +24 -10
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/lifecycle-provider.d.ts +5 -2
- package/dist/client/lifecycle-provider.d.ts.map +1 -1
- package/dist/client/lifecycle-provider.js +6 -5
- package/dist/client/lifecycle-provider.js.map +1 -1
- package/dist/server/agent-actions.d.ts +2 -1
- package/dist/server/agent-actions.d.ts.map +1 -1
- package/dist/server/agent-actions.js +27 -1
- package/dist/server/agent-actions.js.map +1 -1
- package/dist/server/auth-routes.d.ts +1 -2
- package/dist/server/auth-routes.d.ts.map +1 -1
- package/dist/server/auth-routes.js +0 -28
- package/dist/server/auth-routes.js.map +1 -1
- package/dist/server/create-bonfire-next.d.ts +17 -2
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +67 -10
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/entry-coordinator.d.ts +29 -0
- package/dist/server/entry-coordinator.d.ts.map +1 -0
- package/dist/server/entry-coordinator.js +84 -0
- package/dist/server/entry-coordinator.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/prototype-actions.d.ts +2 -1
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +23 -7
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/repository-actions.d.ts +24 -0
- package/dist/server/repository-actions.d.ts.map +1 -0
- package/dist/server/repository-actions.js +166 -0
- package/dist/server/repository-actions.js.map +1 -0
- package/dist/server/repository-routes.d.ts +12 -0
- package/dist/server/repository-routes.d.ts.map +1 -0
- package/dist/server/repository-routes.js +43 -0
- package/dist/server/repository-routes.js.map +1 -0
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, resolve } from "node:path";
|
|
2
|
-
import { defineConfig,
|
|
2
|
+
import { defineConfig, getGitManagementCapabilities, parseAutomaticBranchSwitchSetting, parseGitModeSetting, } from "@ebay-dt/bonfire-core";
|
|
3
3
|
import { GitHubCliClient, LocalPrototypeLifecycle, PrototypeAgentService, PrototypeCatalog, resolvePrototypeCatalogPaths, } from "@ebay-dt/bonfire-node";
|
|
4
4
|
import { cache } from "react";
|
|
5
5
|
import { createAuthProxy } from "./auth-boundary.js";
|
|
@@ -11,6 +11,9 @@ 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
|
+
import { createRepositoryActions } from "./repository-actions.js";
|
|
16
|
+
import { createRepositoryRoutes } from "./repository-routes.js";
|
|
14
17
|
const APP_HEADER_BLOCK_SIZE_PROPERTY = "--app-header-block-size";
|
|
15
18
|
const APP_HEADER_PRESENT_BLOCK_SIZE = "2.5rem";
|
|
16
19
|
export function createBonfireNext(options) {
|
|
@@ -28,6 +31,15 @@ export function createBonfireNext(options) {
|
|
|
28
31
|
throw new Error("prototypeLifecycle and preparePrototypeFiles cannot be supplied together");
|
|
29
32
|
}
|
|
30
33
|
const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(options.disableAutoBranchSwitch);
|
|
34
|
+
const gitMode = parseGitModeSetting(options.gitMode ?? process.env.BF_GIT_MODE);
|
|
35
|
+
const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;
|
|
36
|
+
if (options.prototypeLifecycle !== undefined &&
|
|
37
|
+
((gitMode === "manual" && injectedLifecycleMode !== "manual") ||
|
|
38
|
+
(injectedLifecycleMode !== undefined && injectedLifecycleMode !== gitMode))) {
|
|
39
|
+
throw new TypeError(gitMode === "manual"
|
|
40
|
+
? "prototypeLifecycle must declare manual mode when gitMode is manual"
|
|
41
|
+
: "prototypeLifecycle gitMode does not match configured gitMode");
|
|
42
|
+
}
|
|
31
43
|
const session = createSessionAdapter({
|
|
32
44
|
appId: config.appId,
|
|
33
45
|
sessionSecret: options.sessionSecret,
|
|
@@ -50,6 +62,7 @@ export function createBonfireNext(options) {
|
|
|
50
62
|
prototypeRoot: options.prototypeRoot,
|
|
51
63
|
primaryBranch: options.primaryBranch,
|
|
52
64
|
automaticBranchSwitch,
|
|
65
|
+
gitMode,
|
|
53
66
|
applicationId: config.appId,
|
|
54
67
|
catalog: prototypeCatalog,
|
|
55
68
|
deploymentProvider: options.deploymentProvider,
|
|
@@ -57,22 +70,51 @@ export function createBonfireNext(options) {
|
|
|
57
70
|
themeRegistry: config.themes,
|
|
58
71
|
}));
|
|
59
72
|
const deploymentAvailable = !production &&
|
|
73
|
+
gitMode === "managed" &&
|
|
60
74
|
(options.deploymentProvider !== undefined ||
|
|
61
75
|
options.prototypeLifecycle?.deploy !== undefined);
|
|
76
|
+
const entrySynchronization = createEntrySynchronizationCoordinator({
|
|
77
|
+
lifecycle,
|
|
78
|
+
onStatus: production
|
|
79
|
+
? undefined
|
|
80
|
+
: ({ identity, status, result }) => {
|
|
81
|
+
if (status === "started") {
|
|
82
|
+
console.info(`[bonfire] Preparing repository branch for ${identity.login}…`);
|
|
83
|
+
}
|
|
84
|
+
else if (status === "deferred") {
|
|
85
|
+
console.warn(`[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`);
|
|
86
|
+
}
|
|
87
|
+
else if (result?.status === "ready") {
|
|
88
|
+
console.info(`[bonfire] Branch preparation completed for ${identity.login}.`);
|
|
89
|
+
}
|
|
90
|
+
else if (result?.status === "disabled") {
|
|
91
|
+
console.info(`[bonfire] Branch preparation skipped for ${identity.login}.`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.warn(`[bonfire] Branch preparation completed with repository attention for ${identity.login}.`);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
62
98
|
const getCurrentUser = cache(() => getSession());
|
|
63
|
-
const prepareIdentity = production
|
|
64
|
-
? undefined
|
|
65
|
-
: automaticBranchSwitch === "enabled" && lifecycle
|
|
66
|
-
? lifecycle.prepareBranch.bind(lifecycle)
|
|
67
|
-
: async () => lifecycleSuccess({
|
|
68
|
-
status: "disabled",
|
|
69
|
-
});
|
|
70
99
|
const prototypeActions = createPrototypeActions({
|
|
71
100
|
production,
|
|
101
|
+
gitMode,
|
|
72
102
|
getCurrentUser: getSession,
|
|
73
103
|
lifecycle,
|
|
74
104
|
themeRegistry: config.themes,
|
|
75
105
|
});
|
|
106
|
+
const repositoryActions = createRepositoryActions({
|
|
107
|
+
production,
|
|
108
|
+
gitMode,
|
|
109
|
+
getCurrentUser: getSession,
|
|
110
|
+
lifecycle,
|
|
111
|
+
entrySynchronizationInFlight: entrySynchronization.isInFlight,
|
|
112
|
+
waitForEntrySynchronization: entrySynchronization.waitForCompletion,
|
|
113
|
+
});
|
|
114
|
+
const repositoryRoutes = createRepositoryRoutes({
|
|
115
|
+
production,
|
|
116
|
+
actions: repositoryActions,
|
|
117
|
+
});
|
|
76
118
|
const prototypeAgents = production
|
|
77
119
|
? null
|
|
78
120
|
: (options.prototypeAgents ??
|
|
@@ -121,6 +163,8 @@ export function createBonfireNext(options) {
|
|
|
121
163
|
const getCurrentRouteModel = cache(getCurrentRouteModelUncached);
|
|
122
164
|
const getAppLayoutModel = cache(async () => {
|
|
123
165
|
const user = production ? null : await getCurrentUser();
|
|
166
|
+
if (user !== null)
|
|
167
|
+
await entrySynchronization.synchronize(user);
|
|
124
168
|
const style = {
|
|
125
169
|
[APP_HEADER_BLOCK_SIZE_PROPERTY]: user === null ? "0px" : APP_HEADER_PRESENT_BLOCK_SIZE,
|
|
126
170
|
};
|
|
@@ -153,7 +197,6 @@ export function createBonfireNext(options) {
|
|
|
153
197
|
githubCli,
|
|
154
198
|
createSession: session.createSession,
|
|
155
199
|
clearSession: session.clearSession,
|
|
156
|
-
prepareIdentity,
|
|
157
200
|
});
|
|
158
201
|
return {
|
|
159
202
|
prototypes: {
|
|
@@ -163,11 +206,25 @@ export function createBonfireNext(options) {
|
|
|
163
206
|
getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),
|
|
164
207
|
capabilities: {
|
|
165
208
|
deployment: deploymentAvailable,
|
|
209
|
+
git: {
|
|
210
|
+
...getGitManagementCapabilities(gitMode),
|
|
211
|
+
...(production
|
|
212
|
+
? {
|
|
213
|
+
filesystemLifecycle: false,
|
|
214
|
+
gitObservation: false,
|
|
215
|
+
save: false,
|
|
216
|
+
discard: false,
|
|
217
|
+
getUpdates: false,
|
|
218
|
+
deploy: false,
|
|
219
|
+
}
|
|
220
|
+
: {}),
|
|
221
|
+
},
|
|
166
222
|
},
|
|
167
223
|
lifecycle,
|
|
168
224
|
actions: prototypeActions,
|
|
225
|
+
repository: repositoryActions,
|
|
169
226
|
agents: prototypeAgentActions,
|
|
170
|
-
routes: prototypeRoutes,
|
|
227
|
+
routes: { ...prototypeRoutes, repository: repositoryRoutes },
|
|
171
228
|
},
|
|
172
229
|
auth: {
|
|
173
230
|
getSession,
|
|
@@ -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,gBAAgB,EAChB,iCAAiC,GAIlC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,GAO7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,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6D;QAE7D,uEAAuE;QACvE,yEAAyE;QACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACxD,IAAI,UAAU;YAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,MAAM,UAAU,EAAE;YAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEtC,MAAM,MAAM,GAAG,MAAM,wBAAwB,CAAC,YAAY,CAAC,CAAC;QAC5D,OAAO,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,KAAK,GAAG,eAAe,CAAC;QAC5B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,UAAU;KACX,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC9B,UAAU;QACV,SAAS;QACT,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,eAAe;KAChB,CAAC,CAAC;IACH,OAAO;QACL,UAAU,EAAE;YACV,iBAAiB;YACjB,aAAa;YACb,oBAAoB;YACpB,UAAU,EAAE,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC;YAC9D,YAAY,EAAE;gBACZ,UAAU,EAAE,mBAAmB;aACA;YACjC,SAAS;YACT,OAAO,EAAE,gBAAgB;YACzB,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,eAAe;SACxB;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 lifecycleSuccess,\n parseAutomaticBranchSwitchSetting,\n type BranchPreparationValue,\n type BonfireConfigInput,\n type BonfireIdentity,\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\";\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};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const 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 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 (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const getCurrentUser = cache(() => getSession());\n const prepareIdentity = production\n ? undefined\n : automaticBranchSwitch === \"enabled\" && lifecycle\n ? lifecycle.prepareBranch.bind(lifecycle)\n : async () =>\n lifecycleSuccess({\n status: \"disabled\",\n } satisfies BranchPreparationValue);\n const prototypeActions = createPrototypeActions({\n production,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\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 style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n prepareIdentity,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n agents: prototypeAgentActions,\n routes: prototypeRoutes,\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"create-bonfire-next.js","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,iCAAiC,EACjC,mBAAmB,GAKpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,GAO7B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,mCAAmC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AAO,EAAE,gBAAgB;YACzB,UAAU,EAAE,iBAAiB;YAC7B,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,EAAE,GAAG,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE;SAC7D;QACD,IAAI,EAAE;YACJ,UAAU;YACV,cAAc;YACd,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,MAAM;SACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { join, resolve } from \"node:path\";\nimport {\n defineConfig,\n getGitManagementCapabilities,\n parseAutomaticBranchSwitchSetting,\n parseGitModeSetting,\n type BonfireConfigInput,\n type BonfireIdentity,\n type GitManagementCapabilities,\n type GitMode,\n} from \"@ebay-dt/bonfire-core\";\nimport {\n GitHubCliClient,\n LocalPrototypeLifecycle,\n PrototypeAgentService,\n PrototypeCatalog,\n resolvePrototypeCatalogPaths,\n type DeploymentProvider,\n type GitHubCliClientLike,\n type PreparePrototypeFiles,\n type PrototypeAgentServiceLike,\n type PrototypeCatalogLike,\n type PrototypeLifecycle,\n} from \"@ebay-dt/bonfire-node\";\nimport type { PrototypeWatcher } from \"@ebay-dt/bonfire-node/watcher\";\nimport { cache, type CSSProperties } from \"react\";\nimport { createAuthProxy } from \"./auth-boundary.js\";\nimport { createAuthRoutes } from \"./auth-routes.js\";\nimport {\n createLoginPageModel,\n getLoginPageSearchParams,\n type LoginSearchParams,\n} from \"./login-page-model.js\";\nimport { createSessionAdapter } from \"./session.js\";\nimport { createPrototypeActions } from \"./prototype-actions.js\";\nimport { createPrototypeAgentActions } from \"./agent-actions.js\";\nimport { createPrototypeDashboardModelLoader } from \"./prototype-dashboard.js\";\nimport { createPrototypeEnvironmentModelLoader } from \"./prototype-environment.js\";\nimport { createPrototypeRoutes } from \"./prototype-routes.js\";\nimport { createEntrySynchronizationCoordinator } from \"./entry-coordinator.js\";\nimport { createRepositoryActions } from \"./repository-actions.js\";\nimport { createRepositoryRoutes } from \"./repository-routes.js\";\n\nexport type CreateBonfireNextOptions = BonfireConfigInput & {\n repositoryRoot: string;\n prototypeRoot?: string;\n primaryBranch?: string;\n sessionSecret?: string;\n githubCli?: GitHubCliClientLike;\n prototypeCatalog?: PrototypeCatalogLike;\n prototypeAgents?: PrototypeAgentServiceLike;\n prototypeLifecycle?: PrototypeLifecycle;\n deploymentProvider?: DeploymentProvider;\n prototypeWatcher?: PrototypeWatcher;\n preparePrototypeFiles?: PreparePrototypeFiles;\n disableAutoBranchSwitch?: string;\n gitMode?: GitMode;\n};\n\nexport type PrototypeCapabilities = {\n deployment: boolean;\n git: GitManagementCapabilities;\n};\n\ntype AppLayoutModel = {\n htmlProps: {\n style: CSSProperties;\n };\n headerProps: {\n applicationName: string;\n user: BonfireIdentity | null;\n };\n};\n\ntype CustomProperties = CSSProperties &\n Record<`--${string}`, string | number | undefined>;\n\nconst APP_HEADER_BLOCK_SIZE_PROPERTY = \"--app-header-block-size\";\nconst APP_HEADER_PRESENT_BLOCK_SIZE = \"2.5rem\";\n\nexport function createBonfireNext(options: CreateBonfireNextOptions) {\n const config = defineConfig({\n appId: options.appId,\n name: options.name,\n auth: options.auth,\n ...(options.themes === undefined ? {} : { themes: options.themes }),\n });\n const production = process.env.NODE_ENV === \"production\";\n if (options.prototypeLifecycle && options.deploymentProvider) {\n throw new Error(\n \"prototypeLifecycle and deploymentProvider cannot be supplied together\",\n );\n }\n if (options.prototypeLifecycle && options.preparePrototypeFiles) {\n throw new Error(\n \"prototypeLifecycle and preparePrototypeFiles cannot be supplied together\",\n );\n }\n const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(\n options.disableAutoBranchSwitch,\n );\n const gitMode = parseGitModeSetting(\n options.gitMode ?? process.env.BF_GIT_MODE,\n );\n const injectedLifecycleMode = options.prototypeLifecycle?.gitMode;\n if (\n options.prototypeLifecycle !== undefined &&\n ((gitMode === \"manual\" && injectedLifecycleMode !== \"manual\") ||\n (injectedLifecycleMode !== undefined && injectedLifecycleMode !== gitMode))\n ) {\n throw new TypeError(\n gitMode === \"manual\"\n ? \"prototypeLifecycle must declare manual mode when gitMode is manual\"\n : \"prototypeLifecycle gitMode does not match configured gitMode\",\n );\n }\n const session = createSessionAdapter({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const githubCli =\n options.githubCli ??\n new GitHubCliClient({ hostname: config.auth.github.hostname });\n const getSession = session.getSession;\n const prototypeCatalog =\n options.prototypeCatalog ??\n new PrototypeCatalog({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n themeRegistry: config.themes,\n });\n const lifecycle =\n options.prototypeLifecycle ??\n (production\n ? null\n : new LocalPrototypeLifecycle({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n primaryBranch: options.primaryBranch,\n automaticBranchSwitch,\n gitMode,\n applicationId: config.appId,\n catalog: prototypeCatalog,\n deploymentProvider: options.deploymentProvider,\n preparePrototypeFiles: options.preparePrototypeFiles,\n themeRegistry: config.themes,\n }));\n const deploymentAvailable =\n !production &&\n gitMode === \"managed\" &&\n (options.deploymentProvider !== undefined ||\n options.prototypeLifecycle?.deploy !== undefined);\n const entrySynchronization = createEntrySynchronizationCoordinator({\n lifecycle,\n onStatus: production\n ? undefined\n : ({ identity, status, result }) => {\n if (status === \"started\") {\n console.info(\n `[bonfire] Preparing repository branch for ${identity.login}…`,\n );\n } else if (status === \"deferred\") {\n console.warn(\n `[bonfire] Branch preparation for ${identity.login} is taking longer than 10s; continuing page rendering while it finishes.`,\n );\n } else if (result?.status === \"ready\") {\n console.info(\n `[bonfire] Branch preparation completed for ${identity.login}.`,\n );\n } else if (result?.status === \"disabled\") {\n console.info(\n `[bonfire] Branch preparation skipped for ${identity.login}.`,\n );\n } else {\n console.warn(\n `[bonfire] Branch preparation completed with repository attention for ${identity.login}.`,\n );\n }\n },\n });\n const getCurrentUser = cache(() => getSession());\n const prototypeActions = createPrototypeActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n themeRegistry: config.themes,\n });\n const repositoryActions = createRepositoryActions({\n production,\n gitMode,\n getCurrentUser: getSession,\n lifecycle,\n entrySynchronizationInFlight: entrySynchronization.isInFlight,\n waitForEntrySynchronization: entrySynchronization.waitForCompletion,\n });\n const repositoryRoutes = createRepositoryRoutes({\n production,\n actions: repositoryActions,\n });\n const prototypeAgents = production\n ? null\n : (options.prototypeAgents ??\n new PrototypeAgentService({\n runtime: resolvePrototypeCatalogPaths({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: options.prototypeRoot,\n }),\n catalog: prototypeCatalog,\n }));\n const prototypeAgentActions = createPrototypeAgentActions({\n production,\n getCurrentUser: getSession,\n agents: prototypeAgents,\n });\n let prototypeWatcher = options.prototypeWatcher;\n const getWatcher = async () => {\n if (prototypeWatcher) return prototypeWatcher;\n if (production) return null;\n\n const { createPrototypeWatcher } =\n await import(\"@ebay-dt/bonfire-node/watcher\");\n prototypeWatcher = createPrototypeWatcher({\n repositoryRoot: options.repositoryRoot,\n prototypeRoot: resolve(\n options.repositoryRoot,\n options.prototypeRoot ?? join(\"src\", \"app\", \"(prototypes)\"),\n ),\n });\n return prototypeWatcher;\n };\n const prototypeRoutes = createPrototypeRoutes({\n production,\n getCurrentUser: getSession,\n lifecycle,\n getWatcher,\n });\n const getDashboardModel = createPrototypeDashboardModelLoader({\n applicationName: config.name,\n production,\n catalog: prototypeCatalog,\n getCurrentUser,\n themeRegistry: config.themes,\n });\n const { getRouteModel, getCurrentRouteModel: getCurrentRouteModelUncached } =\n createPrototypeEnvironmentModelLoader({\n catalog: prototypeCatalog,\n themeRegistry: config.themes,\n });\n const getCurrentRouteModel = cache(getCurrentRouteModelUncached);\n const getAppLayoutModel = cache(async (): Promise<AppLayoutModel> => {\n const user = production ? null : await getCurrentUser();\n if (user !== null) await entrySynchronization.synchronize(user);\n const style: CustomProperties = {\n [APP_HEADER_BLOCK_SIZE_PROPERTY]:\n user === null ? \"0px\" : APP_HEADER_PRESENT_BLOCK_SIZE,\n };\n\n return {\n htmlProps: { style },\n headerProps: {\n applicationName: config.name,\n user,\n },\n };\n });\n async function getLoginPageModel(\n searchParams?: LoginSearchParams | Promise<LoginSearchParams>,\n ) {\n // Keep Next's navigation module out of route-handler bundles. The same\n // factory instance supplies both route handlers and server-page helpers.\n const { redirect } = await import(\"next/navigation.js\");\n if (production) redirect(\"/\");\n if (await getSession()) redirect(\"/\");\n\n const params = await getLoginPageSearchParams(searchParams);\n return createLoginPageModel(config, params);\n }\n const proxy = createAuthProxy({\n appId: config.appId,\n sessionSecret: options.sessionSecret,\n production,\n });\n const routes = createAuthRoutes({\n production,\n githubCli,\n createSession: session.createSession,\n clearSession: session.clearSession,\n });\n return {\n prototypes: {\n getDashboardModel,\n getRouteModel,\n getCurrentRouteModel,\n getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),\n capabilities: {\n deployment: deploymentAvailable,\n git: {\n ...getGitManagementCapabilities(gitMode),\n ...(production\n ? {\n filesystemLifecycle: false,\n gitObservation: false,\n save: false,\n discard: false,\n getUpdates: false,\n deploy: false,\n }\n : {}),\n },\n } satisfies PrototypeCapabilities,\n lifecycle,\n actions: prototypeActions,\n repository: repositoryActions,\n agents: prototypeAgentActions,\n routes: { ...prototypeRoutes, repository: repositoryRoutes },\n },\n auth: {\n getSession,\n getCurrentUser,\n getAppLayoutModel,\n getLoginPageModel,\n proxy,\n routes,\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BonfireIdentity, BranchPreparationValue } from "@ebay-dt/bonfire-core";
|
|
2
|
+
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
|
+
type EntryLifecycle = Pick<PrototypeLifecycle, "prepareBranch">;
|
|
4
|
+
export type EntrySynchronizationStatus = "started" | "deferred" | "completed";
|
|
5
|
+
export type EntrySynchronizationCoordinator = {
|
|
6
|
+
synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;
|
|
7
|
+
waitForCompletion(identity: BonfireIdentity): Promise<void>;
|
|
8
|
+
isInFlight(identity: BonfireIdentity): boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Coordinates the first authenticated repository attempt for each identity in
|
|
12
|
+
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
13
|
+
* not repeated until the process is restarted.
|
|
14
|
+
*
|
|
15
|
+
* 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
|
+
* page render to proceed with deferred preparation.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createEntrySynchronizationCoordinator(options: {
|
|
20
|
+
lifecycle: EntryLifecycle | null;
|
|
21
|
+
waitMs?: number;
|
|
22
|
+
onStatus?(event: {
|
|
23
|
+
identity: BonfireIdentity;
|
|
24
|
+
status: EntrySynchronizationStatus;
|
|
25
|
+
result?: BranchPreparationValue;
|
|
26
|
+
}): void;
|
|
27
|
+
}): EntrySynchronizationCoordinator;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=entry-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,KAAK,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAOhE,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAE9E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/E,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC;CAChD,CAAC;AAIF;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CAAC,OAAO,EAAE;IAC7D,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,CAAC,KAAK,EAAE;QACf,QAAQ,EAAE,eAAe,CAAC;QAC1B,MAAM,EAAE,0BAA0B,CAAC;QACnC,MAAM,CAAC,EAAE,sBAAsB,CAAC;KACjC,GAAG,IAAI,CAAC;CACV,GAAG,+BAA+B,CA0FlC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the\n * page render to proceed with deferred preparation.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(\n () =>\n ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n );\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const DEFAULT_ENTRY_WAIT_MS = 10_000;
|
|
2
|
+
/**
|
|
3
|
+
* Coordinates the first authenticated repository attempt for each identity in
|
|
4
|
+
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
5
|
+
* not repeated until the process is restarted.
|
|
6
|
+
*
|
|
7
|
+
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
8
|
+
* timed-out request continues the operation in-process while allowing the
|
|
9
|
+
* page render to proceed with deferred preparation.
|
|
10
|
+
*/
|
|
11
|
+
export function createEntrySynchronizationCoordinator(options) {
|
|
12
|
+
const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;
|
|
13
|
+
const inFlight = new Map();
|
|
14
|
+
const completed = new Map();
|
|
15
|
+
const deferredReported = new Set();
|
|
16
|
+
function report(event) {
|
|
17
|
+
try {
|
|
18
|
+
options.onStatus?.(event);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Observability must never affect authentication or page rendering.
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function createRenderWait(identity, completion) {
|
|
25
|
+
if (waitMs <= 0)
|
|
26
|
+
return completion;
|
|
27
|
+
let timeout;
|
|
28
|
+
const deferred = new Promise((resolve) => {
|
|
29
|
+
timeout = setTimeout(() => {
|
|
30
|
+
if (!deferredReported.has(identity.login)) {
|
|
31
|
+
deferredReported.add(identity.login);
|
|
32
|
+
report({ identity, status: "deferred" });
|
|
33
|
+
}
|
|
34
|
+
resolve({ status: "deferred" });
|
|
35
|
+
}, waitMs);
|
|
36
|
+
});
|
|
37
|
+
return Promise.race([completion, deferred]).finally(() => {
|
|
38
|
+
if (timeout !== undefined)
|
|
39
|
+
clearTimeout(timeout);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function synchronize(identity) {
|
|
43
|
+
if (options.lifecycle === null)
|
|
44
|
+
return null;
|
|
45
|
+
const previous = completed.get(identity.login);
|
|
46
|
+
if (previous !== undefined)
|
|
47
|
+
return previous;
|
|
48
|
+
const active = inFlight.get(identity.login);
|
|
49
|
+
if (active !== undefined)
|
|
50
|
+
return active.renderWait;
|
|
51
|
+
report({ identity, status: "started" });
|
|
52
|
+
const attempt = options.lifecycle
|
|
53
|
+
.prepareBranch(identity)
|
|
54
|
+
.then((result) => result.ok
|
|
55
|
+
? result.value
|
|
56
|
+
: { status: "unsafe" })
|
|
57
|
+
.catch(() => ({ status: "unsafe" }));
|
|
58
|
+
let completion;
|
|
59
|
+
completion = attempt
|
|
60
|
+
.then((result) => {
|
|
61
|
+
completed.set(identity.login, result);
|
|
62
|
+
report({ identity, status: "completed", result });
|
|
63
|
+
return result;
|
|
64
|
+
})
|
|
65
|
+
.finally(() => {
|
|
66
|
+
deferredReported.delete(identity.login);
|
|
67
|
+
if (inFlight.get(identity.login)?.completion === completion) {
|
|
68
|
+
inFlight.delete(identity.login);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const renderWait = createRenderWait(identity, completion);
|
|
72
|
+
inFlight.set(identity.login, { completion, renderWait });
|
|
73
|
+
return renderWait;
|
|
74
|
+
}
|
|
75
|
+
async function waitForCompletion(identity) {
|
|
76
|
+
await inFlight.get(identity.login)?.completion;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
synchronize,
|
|
80
|
+
waitForCompletion,
|
|
81
|
+
isInFlight: (identity) => inFlight.has(identity.login),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=entry-coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAqBA,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,qCAAqC,CAAC,OAQrD;IACC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAAC;IACvD,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C;QACH,CAAC,CAAC,CAAC;QACL,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAEzD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,KAAK,UAAU,iBAAiB,CAAC,QAAyB;QACxD,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACjD,CAAC;IAED,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;KACvD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the\n * page render to proceed with deferred preparation.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(\n () =>\n ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n );\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createBonfireNext, type CreateBonfireNextOptions, type PrototypeCapabilities, } from "./create-bonfire-next.js";
|
|
2
2
|
export { createDeploymentProvider, DeploymentProviderError, type CreateDeploymentProviderOptions, type DeploymentProvider, type DeploymentProviderErrorKind, type DeploymentProviderResult, } from "@ebay-dt/bonfire-node";
|
|
3
3
|
export type { PrototypeActions } from "./prototype-actions.js";
|
|
4
|
+
export type { RepositoryActions } from "./repository-actions.js";
|
|
5
|
+
export type { RepositoryRoutes } from "./repository-routes.js";
|
|
4
6
|
export type { PrototypeAgentActions } from "./agent-actions.js";
|
|
5
7
|
export type { PrototypeRoutes } from "./prototype-routes.js";
|
|
6
8
|
export type { PrototypeRouteModel } from "./prototype-environment.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,+BAA+B,EACpC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export {\n createBonfireNext,\n type CreateBonfireNextOptions,\n type PrototypeCapabilities,\n} from \"./create-bonfire-next.js\";\nexport {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"@ebay-dt/bonfire-node\";\nexport type { PrototypeActions } from \"./prototype-actions.js\";\nexport type { PrototypeAgentActions } from \"./agent-actions.js\";\nexport type { PrototypeRoutes } from \"./prototype-routes.js\";\nexport type { PrototypeRouteModel } from \"./prototype-environment.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,+BAA+B,EACpC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export {\n createBonfireNext,\n type CreateBonfireNextOptions,\n type PrototypeCapabilities,\n} from \"./create-bonfire-next.js\";\nexport {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"@ebay-dt/bonfire-node\";\nexport type { PrototypeActions } from \"./prototype-actions.js\";\nexport type { RepositoryActions } from \"./repository-actions.js\";\nexport type { RepositoryRoutes } from \"./repository-routes.js\";\nexport type { PrototypeAgentActions } from \"./agent-actions.js\";\nexport type { PrototypeRoutes } from \"./prototype-routes.js\";\nexport type { PrototypeRouteModel } from \"./prototype-environment.js\";\n"]}
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAKxB,MAAM,uBAAuB,CAAC","sourcesContent":["export {\n createBonfireNext,\n type CreateBonfireNextOptions,\n type PrototypeCapabilities,\n} from \"./create-bonfire-next.js\";\nexport {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"@ebay-dt/bonfire-node\";\nexport type { PrototypeActions } from \"./prototype-actions.js\";\nexport type { PrototypeAgentActions } from \"./agent-actions.js\";\nexport type { PrototypeRoutes } from \"./prototype-routes.js\";\nexport type { PrototypeRouteModel } from \"./prototype-environment.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAKxB,MAAM,uBAAuB,CAAC","sourcesContent":["export {\n createBonfireNext,\n type CreateBonfireNextOptions,\n type PrototypeCapabilities,\n} from \"./create-bonfire-next.js\";\nexport {\n createDeploymentProvider,\n DeploymentProviderError,\n type CreateDeploymentProviderOptions,\n type DeploymentProvider,\n type DeploymentProviderErrorKind,\n type DeploymentProviderResult,\n} from \"@ebay-dt/bonfire-node\";\nexport type { PrototypeActions } from \"./prototype-actions.js\";\nexport type { RepositoryActions } from \"./repository-actions.js\";\nexport type { RepositoryRoutes } from \"./repository-routes.js\";\nexport type { PrototypeAgentActions } from \"./agent-actions.js\";\nexport type { PrototypeRoutes } from \"./prototype-routes.js\";\nexport type { PrototypeRouteModel } from \"./prototype-environment.js\";\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 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 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>>;
|
|
@@ -11,6 +11,7 @@ export type PrototypeActions = {
|
|
|
11
11
|
};
|
|
12
12
|
export type PrototypeActionsOptions = {
|
|
13
13
|
production: boolean;
|
|
14
|
+
gitMode: GitMode;
|
|
14
15
|
getCurrentUser: () => Promise<BonfireIdentity | null>;
|
|
15
16
|
lifecycle: PrototypeLifecycle | null;
|
|
16
17
|
themeRegistry?: ThemeRegistry;
|
|
@@ -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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AM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAeF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAkNlB","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { lifecycleFailure, parseCreatePrototypeInput, parseDuplicatePrototypeInput, parseEditPrototypeInput, parsePrototypeCommandInput, LifecycleInputError, } from "@ebay-dt/bonfire-core";
|
|
2
|
+
function isManualLifecycleCompatible(options) {
|
|
3
|
+
return options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual";
|
|
4
|
+
}
|
|
2
5
|
function logUnexpectedFailure(operation) {
|
|
3
6
|
console.error(`Bonfire prototype ${operation} failed unexpectedly.`);
|
|
4
7
|
}
|
|
5
8
|
export function createPrototypeActions(options) {
|
|
6
9
|
async function create(input) {
|
|
7
|
-
if (options.production ||
|
|
10
|
+
if (options.production ||
|
|
11
|
+
options.lifecycle === null ||
|
|
12
|
+
!isManualLifecycleCompatible(options)) {
|
|
8
13
|
return lifecycleFailure("forbidden");
|
|
9
14
|
}
|
|
10
15
|
try {
|
|
@@ -22,7 +27,9 @@ export function createPrototypeActions(options) {
|
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
async function duplicate(input) {
|
|
25
|
-
if (options.production ||
|
|
30
|
+
if (options.production ||
|
|
31
|
+
options.lifecycle === null ||
|
|
32
|
+
!isManualLifecycleCompatible(options)) {
|
|
26
33
|
return lifecycleFailure("forbidden");
|
|
27
34
|
}
|
|
28
35
|
try {
|
|
@@ -40,7 +47,9 @@ export function createPrototypeActions(options) {
|
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
async function edit(input) {
|
|
43
|
-
if (options.production ||
|
|
50
|
+
if (options.production ||
|
|
51
|
+
options.lifecycle === null ||
|
|
52
|
+
!isManualLifecycleCompatible(options)) {
|
|
44
53
|
return lifecycleFailure("forbidden");
|
|
45
54
|
}
|
|
46
55
|
try {
|
|
@@ -58,7 +67,9 @@ export function createPrototypeActions(options) {
|
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
async function deletePrototype(input) {
|
|
61
|
-
if (options.production ||
|
|
70
|
+
if (options.production ||
|
|
71
|
+
options.lifecycle === null ||
|
|
72
|
+
!isManualLifecycleCompatible(options)) {
|
|
62
73
|
return lifecycleFailure("forbidden");
|
|
63
74
|
}
|
|
64
75
|
try {
|
|
@@ -76,7 +87,9 @@ export function createPrototypeActions(options) {
|
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
async function save(input) {
|
|
79
|
-
if (options.production ||
|
|
90
|
+
if (options.production ||
|
|
91
|
+
options.lifecycle === null ||
|
|
92
|
+
options.gitMode === "manual") {
|
|
80
93
|
return lifecycleFailure("forbidden");
|
|
81
94
|
}
|
|
82
95
|
try {
|
|
@@ -94,7 +107,9 @@ export function createPrototypeActions(options) {
|
|
|
94
107
|
}
|
|
95
108
|
}
|
|
96
109
|
async function discard(input) {
|
|
97
|
-
if (options.production ||
|
|
110
|
+
if (options.production ||
|
|
111
|
+
options.lifecycle === null ||
|
|
112
|
+
options.gitMode === "manual") {
|
|
98
113
|
return lifecycleFailure("forbidden");
|
|
99
114
|
}
|
|
100
115
|
try {
|
|
@@ -112,8 +127,9 @@ export function createPrototypeActions(options) {
|
|
|
112
127
|
}
|
|
113
128
|
}
|
|
114
129
|
async function deploy(input) {
|
|
115
|
-
if (options.production)
|
|
130
|
+
if (options.production || options.gitMode === "manual") {
|
|
116
131
|
return lifecycleFailure("forbidden");
|
|
132
|
+
}
|
|
117
133
|
let parsedInput;
|
|
118
134
|
try {
|
|
119
135
|
parsedInput = parsePrototypeCommandInput(input);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAepB,MAAM,uBAAuB,CAAC;AAgC/B,SAAS,oBAAoB,CAC3B,SAC4E;IAE5E,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAgC;IAEhC,KAAK,UAAU,MAAM,CACnB,KAA2B;QAE3B,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YACrD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAChD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;Y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AC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (options.production || options.lifecycle === null) {\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 (options.production || options.lifecycle === null) {\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 (options.production || options.lifecycle === null) {\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 (options.production || options.lifecycle === null) {\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 (options.production || options.lifecycle === null) {\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 (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production) return lifecycleFailure(\"forbidden\");\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAgBpB,MAAM,uBAAuB,CAAC;AAiC/B,SAAS,2BAA2B,CAClC,OAAgC;IAEhC,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CAAC;AACjF,CAAC;AAED,SAAS,oBAAoB,CAC3B,SAC4E;IAE5E,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAgC;IAEhC,KAAK,UAAU,MAAM,CACnB,KAA2B;QAE3B,IACE,OAAO,CAAC,UAAU;YAClB,OAAO,CAAC,SAAS,KAAK,IAAI;YAC1B,CAAC,2BAA2B,CAAC,OAAO,CAAC,EACrC,CAAC;YACD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAChD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;YAClE,OAAO,MAAM,OAAO,CAAC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,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|