@ebay-dt/bonfire-next 0.2.0-alpha.0 → 0.2.0-alpha.11
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 +7 -0
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +14 -28
- 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 +4 -1
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +83 -2
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/prototype-source-link.d.ts +11 -0
- package/dist/server/prototype-source-link.d.ts.map +1 -0
- package/dist/server/prototype-source-link.js +59 -0
- package/dist/server/prototype-source-link.js.map +1 -0
- package/dist/server/repository-actions.d.ts +6 -4
- package/dist/server/repository-actions.d.ts.map +1 -1
- package/dist/server/repository-actions.js +71 -3
- 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
|
@@ -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,uBAA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AAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CAkNlB","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype-actions.d.ts","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,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,SAA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ototypeInput,\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,6 +1,6 @@
|
|
|
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
|
-
return options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual";
|
|
3
|
+
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
4
4
|
}
|
|
5
5
|
function logUnexpectedFailure(operation) {
|
|
6
6
|
console.error(`Bonfire prototype ${operation} failed unexpectedly.`);
|
|
@@ -126,6 +126,84 @@ 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
|
+
}
|
|
170
|
+
async function retryPublish(input) {
|
|
171
|
+
if (options.production || options.gitMode === "manual") {
|
|
172
|
+
return lifecycleFailure("forbidden");
|
|
173
|
+
}
|
|
174
|
+
if (options.lifecycle === null ||
|
|
175
|
+
options.lifecycle.retryPublish === undefined) {
|
|
176
|
+
return lifecycleFailure("deployment-unavailable");
|
|
177
|
+
}
|
|
178
|
+
let parsedInput;
|
|
179
|
+
try {
|
|
180
|
+
parsedInput = parsePrototypeCommandInput(input);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (error instanceof LifecycleInputError) {
|
|
184
|
+
return lifecycleFailure("invalid-input");
|
|
185
|
+
}
|
|
186
|
+
logUnexpectedFailure("retry-publish");
|
|
187
|
+
return lifecycleFailure("deployment-failure");
|
|
188
|
+
}
|
|
189
|
+
let identity;
|
|
190
|
+
try {
|
|
191
|
+
identity = await options.getCurrentUser();
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
logUnexpectedFailure("retry-publish");
|
|
195
|
+
return lifecycleFailure("unexpected-failure");
|
|
196
|
+
}
|
|
197
|
+
if (identity === null)
|
|
198
|
+
return lifecycleFailure("unauthenticated");
|
|
199
|
+
try {
|
|
200
|
+
return await options.lifecycle.retryPublish(identity, parsedInput);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
logUnexpectedFailure("retry-publish");
|
|
204
|
+
return lifecycleFailure("deployment-failure");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
129
207
|
async function deploy(input) {
|
|
130
208
|
if (options.production || options.gitMode === "manual") {
|
|
131
209
|
return lifecycleFailure("forbidden");
|
|
@@ -170,6 +248,9 @@ export function createPrototypeActions(options) {
|
|
|
170
248
|
save,
|
|
171
249
|
discard,
|
|
172
250
|
deploy,
|
|
251
|
+
retryPublish,
|
|
252
|
+
getPendingRecovery,
|
|
253
|
+
retryPendingPublication,
|
|
173
254
|
};
|
|
174
255
|
}
|
|
175
256
|
//# sourceMappingURL=prototype-actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,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,SAAS,CAAC,MAAM,CACnC,QAAQ,EACR,yBAAyB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AC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAiBpB,MAAM,uBAAuB,CAAC;AAwC/B,SAAS,2BAA2B,CAClC,OAAgC;IAEhC,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,S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AAC","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"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Only return a canonical HTTPS URL on the configured GitHub host. */
|
|
2
|
+
export declare function gitHubRepositoryUrl(remote: string, hostname: string): string | null;
|
|
3
|
+
export declare function getPrototypeSourceRepository(options: {
|
|
4
|
+
repositoryRoot: string;
|
|
5
|
+
prototypeRoot?: string;
|
|
6
|
+
hostname: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
url: string;
|
|
9
|
+
prototypeDirectory: string;
|
|
10
|
+
} | undefined>;
|
|
11
|
+
//# sourceMappingURL=prototype-source-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prototype-source-link.d.ts","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAQA,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAmCf;AAED,wBAAsB,4BAA4B,CAAC,OAAO,EAAE;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAqBnE","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { resolvePrototypeCatalogPaths } from \"@ebay-dt/bonfire-node\";\n\nconst execFileAsync = promisify(execFile);\nconst GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;\n\n/** Only return a canonical HTTPS URL on the configured GitHub host. */\nexport function gitHubRepositoryUrl(\n remote: string,\n hostname: string,\n): string | null {\n const value = remote.trim();\n let pathname: string;\n if (value.startsWith(`git@${hostname}:`)) {\n pathname = value.slice(`git@${hostname}:`.length);\n } else {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (\n parsed.hostname !== hostname ||\n ![\"https:\", \"ssh:\"].includes(parsed.protocol) ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.password !== \"\" ||\n (parsed.protocol === \"ssh:\"\n ? parsed.username !== \"git\"\n : parsed.username !== \"\")\n ) {\n return null;\n }\n pathname = parsed.pathname.replace(/^\\//u, \"\");\n }\n const segments = pathname.replace(/\\.git$/u, \"\").split(\"/\");\n if (\n segments.length !== 2 ||\n segments.some((segment) => !GITHUB_NAME.test(segment))\n ) {\n return null;\n }\n return `https://${hostname}/${segments[0]}/${segments[1]}`;\n}\n\nexport async function getPrototypeSourceRepository(options: {\n repositoryRoot: string;\n prototypeRoot?: string;\n hostname: string;\n}): Promise<{ url: string; prototypeDirectory: string } | undefined> {\n try {\n const { stdout } = await execFileAsync(\n \"git\",\n [\"-C\", options.repositoryRoot, \"config\", \"--get\", \"remote.origin.url\"],\n { timeout: 2_000, maxBuffer: 4_096 },\n );\n const url = gitHubRepositoryUrl(stdout, options.hostname);\n if (url === null) return undefined;\n const paths = resolvePrototypeCatalogPaths(options);\n const prototypeDirectory = relative(\n paths.repositoryRoot,\n paths.prototypeRoot,\n )\n .split(sep)\n .join(\"/\");\n return { url, prototypeDirectory };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { relative, sep } from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { resolvePrototypeCatalogPaths } from "@ebay-dt/bonfire-node";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
6
|
+
const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;
|
|
7
|
+
/** Only return a canonical HTTPS URL on the configured GitHub host. */
|
|
8
|
+
export function gitHubRepositoryUrl(remote, hostname) {
|
|
9
|
+
const value = remote.trim();
|
|
10
|
+
let pathname;
|
|
11
|
+
if (value.startsWith(`git@${hostname}:`)) {
|
|
12
|
+
pathname = value.slice(`git@${hostname}:`.length);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
let parsed;
|
|
16
|
+
try {
|
|
17
|
+
parsed = new URL(value);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (parsed.hostname !== hostname ||
|
|
23
|
+
!["https:", "ssh:"].includes(parsed.protocol) ||
|
|
24
|
+
parsed.port !== "" ||
|
|
25
|
+
parsed.search !== "" ||
|
|
26
|
+
parsed.hash !== "" ||
|
|
27
|
+
parsed.password !== "" ||
|
|
28
|
+
(parsed.protocol === "ssh:"
|
|
29
|
+
? parsed.username !== "git"
|
|
30
|
+
: parsed.username !== "")) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
pathname = parsed.pathname.replace(/^\//u, "");
|
|
34
|
+
}
|
|
35
|
+
const segments = pathname.replace(/\.git$/u, "").split("/");
|
|
36
|
+
if (segments.length !== 2 ||
|
|
37
|
+
segments.some((segment) => !GITHUB_NAME.test(segment))) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return `https://${hostname}/${segments[0]}/${segments[1]}`;
|
|
41
|
+
}
|
|
42
|
+
export async function getPrototypeSourceRepository(options) {
|
|
43
|
+
try {
|
|
44
|
+
const { stdout } = await execFileAsync("git", ["-C", options.repositoryRoot, "config", "--get", "remote.origin.url"], { timeout: 2_000, maxBuffer: 4_096 });
|
|
45
|
+
const url = gitHubRepositoryUrl(stdout, options.hostname);
|
|
46
|
+
if (url === null)
|
|
47
|
+
return undefined;
|
|
48
|
+
const paths = resolvePrototypeCatalogPaths(options);
|
|
49
|
+
const prototypeDirectory = relative(paths.repositoryRoot, paths.prototypeRoot)
|
|
50
|
+
.split(sep)
|
|
51
|
+
.join("/");
|
|
52
|
+
return { url, prototypeDirectory };
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// A missing or unsupported origin should not block the application header.
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=prototype-source-link.js.map
|
|
@@ -0,0 +1 @@
|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C,GAAG,CAAC;aACV,IAAI,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { resolvePrototypeCatalogPaths } from \"@ebay-dt/bonfire-node\";\n\nconst execFileAsync = promisify(execFile);\nconst GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;\n\n/** Only return a canonical HTTPS URL on the configured GitHub host. */\nexport function gitHubRepositoryUrl(\n remote: string,\n hostname: string,\n): string | null {\n const value = remote.trim();\n let pathname: string;\n if (value.startsWith(`git@${hostname}:`)) {\n pathname = value.slice(`git@${hostname}:`.length);\n } else {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (\n parsed.hostname !== hostname ||\n ![\"https:\", \"ssh:\"].includes(parsed.protocol) ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.password !== \"\" ||\n (parsed.protocol === \"ssh:\"\n ? parsed.username !== \"git\"\n : parsed.username !== \"\")\n ) {\n return null;\n }\n pathname = parsed.pathname.replace(/^\\//u, \"\");\n }\n const segments = pathname.replace(/\\.git$/u, \"\").split(\"/\");\n if (\n segments.length !== 2 ||\n segments.some((segment) => !GITHUB_NAME.test(segment))\n ) {\n return null;\n }\n return `https://${hostname}/${segments[0]}/${segments[1]}`;\n}\n\nexport async function getPrototypeSourceRepository(options: {\n repositoryRoot: string;\n prototypeRoot?: string;\n hostname: string;\n}): Promise<{ url: string; prototypeDirectory: string } | undefined> {\n try {\n const { stdout } = await execFileAsync(\n \"git\",\n [\"-C\", options.repositoryRoot, \"config\", \"--get\", \"remote.origin.url\"],\n { timeout: 2_000, maxBuffer: 4_096 },\n );\n const url = gitHubRepositoryUrl(stdout, options.hostname);\n if (url === null) return undefined;\n const paths = resolvePrototypeCatalogPaths(options);\n const prototypeDirectory = relative(\n paths.repositoryRoot,\n paths.prototypeRoot,\n )\n .split(sep)\n .join(\"/\");\n return { url, prototypeDirectory };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
|
|
@@ -1,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;AAuBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAoKnB","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 options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n return await mutation(identity, input);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repository-actions.d.ts","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1D,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrD,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAChE,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,0BAA0B,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3E,CAAC;AAEF,KAAK,mBAAmB,GAAG,IAAI,CAC7B,kBAAkB,EAChB,SAAS,GACT,sBAAsB,GACtB,wBAAwB,GACxB,eAAe,CAClB,GACC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,CAAC,CAAC,CAAC;AAEhF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB,CAAC,EAAE,yBAAyB,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4BAA4B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC;IACtE,2BAA2B,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E,CAAC;AAyBF,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAqPnB","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getGitManagementCapabilities, lifecycleFailure, lifecycleSuccess, } from "@ebay-dt/bonfire-core";
|
|
2
2
|
const DEFAULT_CHECK_THROTTLE_MS = 30_000;
|
|
3
3
|
function compatible(options) {
|
|
4
|
-
return options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual";
|
|
4
|
+
return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
|
|
5
5
|
}
|
|
6
6
|
function unavailable() {
|
|
7
7
|
return lifecycleFailure("forbidden");
|
|
@@ -121,15 +121,44 @@ export function createRepositoryActions(options) {
|
|
|
121
121
|
return unavailable();
|
|
122
122
|
invalidateChecks(identity.login);
|
|
123
123
|
try {
|
|
124
|
-
|
|
124
|
+
const result = (await Reflect.apply(mutation, options.lifecycle, [
|
|
125
|
+
identity,
|
|
126
|
+
input,
|
|
127
|
+
]));
|
|
128
|
+
if (!result.ok) {
|
|
129
|
+
console.error(`Bonfire repository ${operation} failed: ${result.error.code}`);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
125
132
|
}
|
|
126
133
|
catch {
|
|
134
|
+
console.error(`Bonfire repository ${operation} failed unexpectedly`);
|
|
127
135
|
return lifecycleFailure("unexpected-failure");
|
|
128
136
|
}
|
|
129
137
|
finally {
|
|
130
138
|
invalidateChecks(identity.login);
|
|
131
139
|
}
|
|
132
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
|
+
}
|
|
133
162
|
async function applyUpdates() {
|
|
134
163
|
if (options.production ||
|
|
135
164
|
options.lifecycle === null ||
|
|
@@ -145,7 +174,45 @@ export function createRepositoryActions(options) {
|
|
|
145
174
|
const preparation = await options.lifecycle.prepareBranch(identity);
|
|
146
175
|
if (!preparation.ok)
|
|
147
176
|
return lifecycleFailure(preparation.error.code);
|
|
148
|
-
|
|
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
|
+
});
|
|
149
216
|
}
|
|
150
217
|
catch {
|
|
151
218
|
return lifecycleFailure("unexpected-failure");
|
|
@@ -159,6 +226,7 @@ export function createRepositoryActions(options) {
|
|
|
159
226
|
check,
|
|
160
227
|
applyUpdates,
|
|
161
228
|
retry: applyUpdates,
|
|
229
|
+
retryPreparation,
|
|
162
230
|
save: (input) => scopedMutation("save", input),
|
|
163
231
|
discard: (input) => scopedMutation("discard", input),
|
|
164
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,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CAAC;AACjF,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;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AAC,CAAC;YACrE,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAChE,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,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 options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\";\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n return await mutation(identity, input);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"repository-actions.js","sourceRoot":"","sources":["../../src/server/repository-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,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,EAMr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AW,CAAC,KAAK;gBAC9B,cAAc;gBACd,GAAG,CAAC,qBAAqB,KAAK,SAAS;oBACrC,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,qBAAqB,EAAE,CAAC;aAC/B,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;gBAAS,CAAC;YACT,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU;QACV,KAAK;QACL,YAAY;QACZ,KAAK,EAAE,YAAY;QACnB,gBAAgB;QAChB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;QAC9C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,KAAK,CAAC;KACrD,CAAC;AACJ,CAAC","sourcesContent":["import {\n getGitManagementCapabilities,\n lifecycleFailure,\n lifecycleSuccess,\n type BonfireIdentity,\n type GitMode,\n type AutomaticBranchSwitchMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n type RepositoryUpdateValue,\n type DependencyPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retry(): Promise<LifecycleResult<RepositoryUpdateValue>>;\n retryPreparation?(): Promise<LifecycleResult<DependencyPreparationValue>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\" | \"prepareDependencies\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n automaticBranchSwitch?: AutomaticBranchSwitchMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function retryPreparation(): Promise<\n LifecycleResult<DependencyPreparationValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n options.automaticBranchSwitch === \"disabled\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.lifecycle.prepareDependencies === undefined) {\n return lifecycleFailure(\"forbidden\");\n }\n try {\n return await options.lifecycle.prepareDependencies();\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function applyUpdates(): Promise<\n LifecycleResult<RepositoryUpdateValue>\n > {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n let dependencyPreparation: DependencyPreparationValue | undefined;\n const dependencyPaths =\n preparation.value.effects.dependencyPaths ?? [];\n const preparationRequired =\n preparation.value.effects.preparationRequired === true ||\n dependencyPaths.length > 0;\n // Deferred/unsafe Git reconciliation is not an install boundary. In\n // particular, never install against a partially applied baseline.\n if (\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies !== undefined\n ) {\n const dependencies = await options.lifecycle.prepareDependencies(\n dependencyPaths,\n );\n if (!dependencies.ok) return lifecycleFailure(dependencies.error.code);\n dependencyPreparation = dependencies.value;\n } else if (\n preparationRequired &&\n preparation.value.status === \"ready\" &&\n preparationRequired &&\n options.lifecycle.prepareDependencies === undefined\n ) {\n // A lifecycle that cannot perform the shared preparation contract is\n // incompatible with a required update; do not silently claim ready.\n return lifecycleFailure(\"forbidden\");\n }\n let summaryRefresh: RepositoryUpdateValue[\"summaryRefresh\"];\n try {\n const refreshed =\n await options.lifecycle.getRepositorySummary(identity);\n summaryRefresh = refreshed.ok\n ? { status: \"refreshed\", summary: refreshed.value }\n : { status: \"failed\", error: refreshed.error.code };\n } catch {\n summaryRefresh = { status: \"failed\", error: \"unexpected-failure\" };\n }\n return lifecycleSuccess({\n preparation: preparation.value,\n summaryRefresh,\n ...(dependencyPreparation === undefined\n ? {}\n : { dependencyPreparation }),\n });\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n retryPreparation,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
|