@ebay-dt/bonfire-next 0.1.0 → 0.2.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +24 -10
  2. package/dist/client/index.d.ts +1 -1
  3. package/dist/client/index.d.ts.map +1 -1
  4. package/dist/client/index.js +1 -1
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/client/lifecycle-provider.d.ts +5 -2
  7. package/dist/client/lifecycle-provider.d.ts.map +1 -1
  8. package/dist/client/lifecycle-provider.js +6 -5
  9. package/dist/client/lifecycle-provider.js.map +1 -1
  10. package/dist/server/agent-actions.d.ts +2 -1
  11. package/dist/server/agent-actions.d.ts.map +1 -1
  12. package/dist/server/agent-actions.js +27 -1
  13. package/dist/server/agent-actions.js.map +1 -1
  14. package/dist/server/auth-routes.d.ts +1 -2
  15. package/dist/server/auth-routes.d.ts.map +1 -1
  16. package/dist/server/auth-routes.js +0 -28
  17. package/dist/server/auth-routes.js.map +1 -1
  18. package/dist/server/create-bonfire-next.d.ts +21 -2
  19. package/dist/server/create-bonfire-next.d.ts.map +1 -1
  20. package/dist/server/create-bonfire-next.js +77 -10
  21. package/dist/server/create-bonfire-next.js.map +1 -1
  22. package/dist/server/entry-coordinator.d.ts +29 -0
  23. package/dist/server/entry-coordinator.d.ts.map +1 -0
  24. package/dist/server/entry-coordinator.js +84 -0
  25. package/dist/server/entry-coordinator.js.map +1 -0
  26. package/dist/server/index.d.ts +2 -0
  27. package/dist/server/index.d.ts.map +1 -1
  28. package/dist/server/index.js.map +1 -1
  29. package/dist/server/prototype-actions.d.ts +3 -1
  30. package/dist/server/prototype-actions.d.ts.map +1 -1
  31. package/dist/server/prototype-actions.js +61 -7
  32. package/dist/server/prototype-actions.js.map +1 -1
  33. package/dist/server/prototype-source-link.d.ts +11 -0
  34. package/dist/server/prototype-source-link.d.ts.map +1 -0
  35. package/dist/server/prototype-source-link.js +59 -0
  36. package/dist/server/prototype-source-link.js.map +1 -0
  37. package/dist/server/repository-actions.d.ts +24 -0
  38. package/dist/server/repository-actions.d.ts.map +1 -0
  39. package/dist/server/repository-actions.js +174 -0
  40. package/dist/server/repository-actions.js.map +1 -0
  41. package/dist/server/repository-routes.d.ts +12 -0
  42. package/dist/server/repository-routes.d.ts.map +1 -0
  43. package/dist/server/repository-routes.js +43 -0
  44. package/dist/server/repository-routes.js.map +1 -0
  45. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAepB,MAAM,uBAAuB,CAAC;AAgC/B,SAAS,oBAAoB,CAC3B,SAC4E;IAE5E,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAgC;IAEhC,KAAK,UAAU,MAAM,CACnB,KAA2B;QAE3B,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YACrD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAChD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;YAClE,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CACnC,QAAQ,EACR,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CACxD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;gBACzC,OAAO,gBAAgB,CAAC,eAAe,C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C;QAE7D,IAAI,WAAkC,CAAC;QACvC,IAAI,CAAC;YACH,WAAW,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;gBACzC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAC3C,CAAC;YACD,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC/B,OAAO,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,QAAgC,CAAC;QACrC,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5C,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,QAAQ,KAAK,IAAI;YAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAElE,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAC/B,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM;QACN,SAAS;QACT,IAAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction logUnexpectedFailure(\n operation:\n \"create\" | \"duplicate\" | \"edit\" | \"delete\" | \"save\" | \"discard\" | \"deploy\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (options.production || options.lifecycle === null) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production) return lifecycleFailure(\"forbidden\");\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n };\n}\n"]}
1
+ {"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,GAgBpB,MAAM,uBAAuB,CAAC;AAoC/B,SAAS,2BAA2B,CAClC,OAAgC;IAEhC,OAAO,CACL,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,OAAO,KAAK,QAAQ,CACxE,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAC3B,SAQmB;IAEnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAgC;IAEhC,KAAK,UAAU,MAAM,CACnB,KAA2B;QAE3B,IACE,OAAO,CAAC,UAAU;YAClB,OAAO,CAAC,SAAS,KAAK,IAAI;YAC1B,CAAC,2BAA2B,CAAC,OAAO,CAAC,EACrC,CAAC;YACD,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAChD,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;YAClE,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,CACnC,QAAQ,EACR,yBAAyB,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CACxD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;gBACzC,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAC3C,CAAC;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AAI;QACJ,MAAM,EAAE,eAAe;QACvB,IAAI;QACJ,OAAO;QACP,MAAM;QACN,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {\n lifecycleFailure,\n parseCreatePrototypeInput,\n parseDuplicatePrototypeInput,\n parseEditPrototypeInput,\n parsePrototypeCommandInput,\n LifecycleInputError,\n type CreatePrototypeInput,\n type CreatePrototypeValue,\n type DeletePrototypeValue,\n type DeploymentValue,\n type DiscardPrototypeValue,\n type DuplicatePrototypeInput,\n type DuplicatePrototypeValue,\n type EditPrototypeInput,\n type EditPrototypeValue,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type SavePrototypeValue,\n type BonfireIdentity,\n type ThemeRegistry,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type PrototypeActions = {\n create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>>;\n duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>>;\n edit(input: EditPrototypeInput): Promise<LifecycleResult<EditPrototypeValue>>;\n delete(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>>;\n save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>>;\n discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>>;\n deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n retryPublish?(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>>;\n};\n\nexport type PrototypeActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: PrototypeLifecycle | null;\n themeRegistry?: ThemeRegistry;\n};\n\nfunction isManualLifecycleCompatible(\n options: PrototypeActionsOptions,\n): boolean {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction logUnexpectedFailure(\n operation:\n | \"create\"\n | \"duplicate\"\n | \"edit\"\n | \"delete\"\n | \"save\"\n | \"discard\"\n | \"deploy\"\n | \"retry-publish\",\n) {\n console.error(`Bonfire prototype ${operation} failed unexpectedly.`);\n}\n\nexport function createPrototypeActions(\n options: PrototypeActionsOptions,\n): PrototypeActions {\n async function create(\n input: CreatePrototypeInput,\n ): Promise<LifecycleResult<CreatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.create(\n identity,\n parseCreatePrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"create\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function duplicate(\n input: DuplicatePrototypeInput,\n ): Promise<LifecycleResult<DuplicatePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.duplicate(\n identity,\n parseDuplicatePrototypeInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"duplicate\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function edit(\n input: EditPrototypeInput,\n ): Promise<LifecycleResult<EditPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.edit(\n identity,\n parseEditPrototypeInput(input, options.themeRegistry),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"edit\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function deletePrototype(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeletePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !isManualLifecycleCompatible(options)\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.delete(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"delete\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function save(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<SavePrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.save(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"save\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function discard(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DiscardPrototypeValue>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\"\n ) {\n return lifecycleFailure(\"forbidden\");\n }\n\n try {\n const identity = await options.getCurrentUser();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n return await options.lifecycle.discard(\n identity,\n parsePrototypeCommandInput(input),\n );\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"discard\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function retryPublish(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n if (\n options.lifecycle === null ||\n options.lifecycle.retryPublish === undefined\n ) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n try {\n return await options.lifecycle.retryPublish(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"retry-publish\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n async function deploy(\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<DeploymentValue>> {\n if (options.production || options.gitMode === \"manual\") {\n return lifecycleFailure(\"forbidden\");\n }\n\n let parsedInput: PrototypeCommandInput;\n try {\n parsedInput = parsePrototypeCommandInput(input);\n } catch (error) {\n if (error instanceof LifecycleInputError) {\n return lifecycleFailure(\"invalid-input\");\n }\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n if (options.lifecycle === null) {\n return lifecycleFailure(\"deployment-unavailable\");\n }\n\n let identity: BonfireIdentity | null;\n try {\n identity = await options.getCurrentUser();\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"unexpected-failure\");\n }\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n\n try {\n return await options.lifecycle.deploy(identity, parsedInput);\n } catch {\n logUnexpectedFailure(\"deploy\");\n return lifecycleFailure(\"deployment-failure\");\n }\n }\n\n return {\n create,\n duplicate,\n edit,\n delete: deletePrototype,\n save,\n discard,\n deploy,\n retryPublish,\n };\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /** Only return a canonical HTTPS URL on the configured GitHub host. */
2
+ export declare function gitHubRepositoryUrl(remote: string, hostname: string): string | null;
3
+ export declare function getPrototypeSourceRepository(options: {
4
+ repositoryRoot: string;
5
+ prototypeRoot?: string;
6
+ hostname: string;
7
+ }): Promise<{
8
+ url: string;
9
+ prototypeDirectory: string;
10
+ } | undefined>;
11
+ //# sourceMappingURL=prototype-source-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-source-link.d.ts","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAQA,uEAAuE;AACvE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAmCf;AAED,wBAAsB,4BAA4B,CAAC,OAAO,EAAE;IAC1D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAqBnE","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { relative, sep } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { resolvePrototypeCatalogPaths } from \"@ebay-dt/bonfire-node\";\n\nconst execFileAsync = promisify(execFile);\nconst GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;\n\n/** Only return a canonical HTTPS URL on the configured GitHub host. */\nexport function gitHubRepositoryUrl(\n remote: string,\n hostname: string,\n): string | null {\n const value = remote.trim();\n let pathname: string;\n if (value.startsWith(`git@${hostname}:`)) {\n pathname = value.slice(`git@${hostname}:`.length);\n } else {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return null;\n }\n if (\n parsed.hostname !== hostname ||\n ![\"https:\", \"ssh:\"].includes(parsed.protocol) ||\n parsed.port !== \"\" ||\n parsed.search !== \"\" ||\n parsed.hash !== \"\" ||\n parsed.password !== \"\" ||\n (parsed.protocol === \"ssh:\"\n ? parsed.username !== \"git\"\n : parsed.username !== \"\")\n ) {\n return null;\n }\n pathname = parsed.pathname.replace(/^\\//u, \"\");\n }\n const segments = pathname.replace(/\\.git$/u, \"\").split(\"/\");\n if (\n segments.length !== 2 ||\n segments.some((segment) => !GITHUB_NAME.test(segment))\n ) {\n return null;\n }\n return `https://${hostname}/${segments[0]}/${segments[1]}`;\n}\n\nexport async function getPrototypeSourceRepository(options: {\n repositoryRoot: string;\n prototypeRoot?: string;\n hostname: string;\n}): Promise<{ url: string; prototypeDirectory: string } | undefined> {\n try {\n const { stdout } = await execFileAsync(\n \"git\",\n [\"-C\", options.repositoryRoot, \"config\", \"--get\", \"remote.origin.url\"],\n { timeout: 2_000, maxBuffer: 4_096 },\n );\n const url = gitHubRepositoryUrl(stdout, options.hostname);\n if (url === null) return undefined;\n const paths = resolvePrototypeCatalogPaths(options);\n const prototypeDirectory = relative(\n paths.repositoryRoot,\n paths.prototypeRoot,\n )\n .split(sep)\n .join(\"/\");\n return { url, prototypeDirectory };\n } catch {\n // A missing or unsupported origin should not block the application header.\n return undefined;\n }\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import { execFile } from "node:child_process";
2
+ import { relative, sep } from "node:path";
3
+ import { promisify } from "node:util";
4
+ import { resolvePrototypeCatalogPaths } from "@ebay-dt/bonfire-node";
5
+ const execFileAsync = promisify(execFile);
6
+ const GITHUB_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/u;
7
+ /** Only return a canonical HTTPS URL on the configured GitHub host. */
8
+ export function gitHubRepositoryUrl(remote, hostname) {
9
+ const value = remote.trim();
10
+ let pathname;
11
+ if (value.startsWith(`git@${hostname}:`)) {
12
+ pathname = value.slice(`git@${hostname}:`.length);
13
+ }
14
+ else {
15
+ let parsed;
16
+ try {
17
+ parsed = new URL(value);
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ if (parsed.hostname !== hostname ||
23
+ !["https:", "ssh:"].includes(parsed.protocol) ||
24
+ parsed.port !== "" ||
25
+ parsed.search !== "" ||
26
+ parsed.hash !== "" ||
27
+ parsed.password !== "" ||
28
+ (parsed.protocol === "ssh:"
29
+ ? parsed.username !== "git"
30
+ : parsed.username !== "")) {
31
+ return null;
32
+ }
33
+ pathname = parsed.pathname.replace(/^\//u, "");
34
+ }
35
+ const segments = pathname.replace(/\.git$/u, "").split("/");
36
+ if (segments.length !== 2 ||
37
+ segments.some((segment) => !GITHUB_NAME.test(segment))) {
38
+ return null;
39
+ }
40
+ return `https://${hostname}/${segments[0]}/${segments[1]}`;
41
+ }
42
+ export async function getPrototypeSourceRepository(options) {
43
+ try {
44
+ const { stdout } = await execFileAsync("git", ["-C", options.repositoryRoot, "config", "--get", "remote.origin.url"], { timeout: 2_000, maxBuffer: 4_096 });
45
+ const url = gitHubRepositoryUrl(stdout, options.hostname);
46
+ if (url === null)
47
+ return undefined;
48
+ const paths = resolvePrototypeCatalogPaths(options);
49
+ const prototypeDirectory = relative(paths.repositoryRoot, paths.prototypeRoot)
50
+ .split(sep)
51
+ .join("/");
52
+ return { url, prototypeDirectory };
53
+ }
54
+ catch {
55
+ // A missing or unsupported origin should not block the application header.
56
+ return undefined;
57
+ }
58
+ }
59
+ //# sourceMappingURL=prototype-source-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-source-link.js","sourceRoot":"","sources":["../../src/server/prototype-source-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EA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ep } 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,24 @@
1
+ import { type BonfireIdentity, type GitMode, type LifecycleResult, type PrototypeCommandInput, type RepositorySummary } from "@ebay-dt/bonfire-core";
2
+ import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
3
+ export type RepositoryActions = {
4
+ getSummary(): Promise<LifecycleResult<RepositorySummary>>;
5
+ check(): Promise<LifecycleResult<RepositorySummary>>;
6
+ applyUpdates(): Promise<LifecycleResult<RepositorySummary>>;
7
+ retry(): Promise<LifecycleResult<RepositorySummary>>;
8
+ save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;
9
+ discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;
10
+ };
11
+ type RepositoryLifecycle = Pick<PrototypeLifecycle, "gitMode" | "getRepositorySummary" | "checkRepositorySummary" | "prepareBranch"> & Partial<Pick<PrototypeLifecycle, "save" | "discard">>;
12
+ export type RepositoryActionsOptions = {
13
+ production: boolean;
14
+ gitMode: GitMode;
15
+ getCurrentUser: () => Promise<BonfireIdentity | null>;
16
+ lifecycle: RepositoryLifecycle | null;
17
+ now?: () => number;
18
+ checkThrottleMs?: number;
19
+ entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;
20
+ waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;
21
+ };
22
+ export declare function createRepositoryActions(options: RepositoryActionsOptions): RepositoryActions;
23
+ export {};
24
+ //# sourceMappingURL=repository-actions.d.ts.map
@@ -0,0 +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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\n type BonfireIdentity,\n type GitMode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositorySummary>>;\n retry(): Promise<LifecycleResult<RepositorySummary>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
@@ -0,0 +1,174 @@
1
+ import { getGitManagementCapabilities, lifecycleFailure, lifecycleSuccess, } from "@ebay-dt/bonfire-core";
2
+ const DEFAULT_CHECK_THROTTLE_MS = 30_000;
3
+ function compatible(options) {
4
+ return (options.gitMode !== "manual" || options.lifecycle?.gitMode === "manual");
5
+ }
6
+ function unavailable() {
7
+ return lifecycleFailure("forbidden");
8
+ }
9
+ function checkingSummary(mode) {
10
+ return {
11
+ mode,
12
+ readiness: "checking",
13
+ updateCheck: "checking",
14
+ changes: [],
15
+ attention: [],
16
+ capabilities: getGitManagementCapabilities(mode),
17
+ };
18
+ }
19
+ export function createRepositoryActions(options) {
20
+ const now = options.now ?? Date.now;
21
+ const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;
22
+ const checking = new Map();
23
+ const previousChecks = new Map();
24
+ const checkGenerations = new Map();
25
+ function invalidateChecks(login) {
26
+ previousChecks.delete(login);
27
+ checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);
28
+ }
29
+ async function identityOrFailure() {
30
+ try {
31
+ const identity = await options.getCurrentUser();
32
+ return identity;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ async function getSummary() {
39
+ if (options.production ||
40
+ options.lifecycle === null ||
41
+ !compatible(options)) {
42
+ return unavailable();
43
+ }
44
+ const identity = await identityOrFailure();
45
+ if (identity === null)
46
+ return lifecycleFailure("unauthenticated");
47
+ if (options.entrySynchronizationInFlight?.(identity)) {
48
+ return lifecycleSuccess(checkingSummary(options.gitMode));
49
+ }
50
+ try {
51
+ return await options.lifecycle.getRepositorySummary(identity);
52
+ }
53
+ catch {
54
+ return lifecycleFailure("unexpected-failure");
55
+ }
56
+ }
57
+ async function check() {
58
+ if (options.production ||
59
+ options.lifecycle === null ||
60
+ !compatible(options)) {
61
+ return unavailable();
62
+ }
63
+ const identity = await identityOrFailure();
64
+ if (identity === null)
65
+ return lifecycleFailure("unauthenticated");
66
+ if (options.entrySynchronizationInFlight?.(identity)) {
67
+ if (options.waitForEntrySynchronization !== undefined) {
68
+ await options.waitForEntrySynchronization(identity);
69
+ }
70
+ if (options.entrySynchronizationInFlight?.(identity)) {
71
+ return lifecycleSuccess(checkingSummary(options.gitMode));
72
+ }
73
+ }
74
+ const generation = checkGenerations.get(identity.login) ?? 0;
75
+ const previous = previousChecks.get(identity.login);
76
+ if (previous !== undefined && now() - previous.at < throttleMs) {
77
+ return previous.result;
78
+ }
79
+ const active = checking.get(identity.login);
80
+ if (active !== undefined && active.generation === generation) {
81
+ return active.promise;
82
+ }
83
+ const attempt = (async () => {
84
+ try {
85
+ const result = options.gitMode === "manual" ||
86
+ typeof options.lifecycle.checkRepositorySummary !== "function"
87
+ ? await options.lifecycle.getRepositorySummary(identity)
88
+ : await options.lifecycle.checkRepositorySummary(identity);
89
+ if (result.ok &&
90
+ (checkGenerations.get(identity.login) ?? 0) === generation) {
91
+ previousChecks.set(identity.login, { at: now(), result });
92
+ }
93
+ return result;
94
+ }
95
+ catch {
96
+ return lifecycleFailure("unexpected-failure");
97
+ }
98
+ })();
99
+ checking.set(identity.login, { generation, promise: attempt });
100
+ try {
101
+ return await attempt;
102
+ }
103
+ finally {
104
+ if (checking.get(identity.login)?.promise === attempt) {
105
+ checking.delete(identity.login);
106
+ }
107
+ }
108
+ }
109
+ async function scopedMutation(operation, input) {
110
+ if (options.production ||
111
+ options.lifecycle === null ||
112
+ options.gitMode === "manual" ||
113
+ !compatible(options)) {
114
+ return unavailable();
115
+ }
116
+ const identity = await identityOrFailure();
117
+ if (identity === null)
118
+ return lifecycleFailure("unauthenticated");
119
+ const mutation = options.lifecycle[operation];
120
+ if (mutation === undefined)
121
+ return unavailable();
122
+ invalidateChecks(identity.login);
123
+ try {
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;
132
+ }
133
+ catch {
134
+ console.error(`Bonfire repository ${operation} failed unexpectedly`);
135
+ return lifecycleFailure("unexpected-failure");
136
+ }
137
+ finally {
138
+ invalidateChecks(identity.login);
139
+ }
140
+ }
141
+ async function applyUpdates() {
142
+ if (options.production ||
143
+ options.lifecycle === null ||
144
+ options.gitMode === "manual" ||
145
+ !compatible(options)) {
146
+ return unavailable();
147
+ }
148
+ const identity = await identityOrFailure();
149
+ if (identity === null)
150
+ return lifecycleFailure("unauthenticated");
151
+ invalidateChecks(identity.login);
152
+ try {
153
+ const preparation = await options.lifecycle.prepareBranch(identity);
154
+ if (!preparation.ok)
155
+ return lifecycleFailure(preparation.error.code);
156
+ return await options.lifecycle.getRepositorySummary(identity);
157
+ }
158
+ catch {
159
+ return lifecycleFailure("unexpected-failure");
160
+ }
161
+ finally {
162
+ invalidateChecks(identity.login);
163
+ }
164
+ }
165
+ return {
166
+ getSummary,
167
+ check,
168
+ applyUpdates,
169
+ retry: applyUpdates,
170
+ save: (input) => scopedMutation("save", input),
171
+ discard: (input) => scopedMutation("discard", input),
172
+ };
173
+ }
174
+ //# sourceMappingURL=repository-actions.js.map
@@ -0,0 +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,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,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ode,\n type LifecycleResult,\n type PrototypeCommandInput,\n type RepositorySummary,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\nexport type RepositoryActions = {\n getSummary(): Promise<LifecycleResult<RepositorySummary>>;\n check(): Promise<LifecycleResult<RepositorySummary>>;\n applyUpdates(): Promise<LifecycleResult<RepositorySummary>>;\n retry(): Promise<LifecycleResult<RepositorySummary>>;\n save?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n discard?(input: PrototypeCommandInput): Promise<LifecycleResult<unknown>>;\n};\n\ntype RepositoryLifecycle = Pick<\n PrototypeLifecycle,\n | \"gitMode\"\n | \"getRepositorySummary\"\n | \"checkRepositorySummary\"\n | \"prepareBranch\"\n> &\n Partial<Pick<PrototypeLifecycle, \"save\" | \"discard\">>;\n\nexport type RepositoryActionsOptions = {\n production: boolean;\n gitMode: GitMode;\n getCurrentUser: () => Promise<BonfireIdentity | null>;\n lifecycle: RepositoryLifecycle | null;\n now?: () => number;\n checkThrottleMs?: number;\n entrySynchronizationInFlight?: (identity: BonfireIdentity) => boolean;\n waitForEntrySynchronization?: (identity: BonfireIdentity) => Promise<void>;\n};\n\nconst DEFAULT_CHECK_THROTTLE_MS = 30_000;\n\nfunction compatible(options: RepositoryActionsOptions) {\n return (\n options.gitMode !== \"manual\" || options.lifecycle?.gitMode === \"manual\"\n );\n}\n\nfunction unavailable<T>(): LifecycleResult<T> {\n return lifecycleFailure(\"forbidden\");\n}\n\nfunction checkingSummary(mode: GitMode): RepositorySummary {\n return {\n mode,\n readiness: \"checking\",\n updateCheck: \"checking\",\n changes: [],\n attention: [],\n capabilities: getGitManagementCapabilities(mode),\n };\n}\n\nexport function createRepositoryActions(\n options: RepositoryActionsOptions,\n): RepositoryActions {\n const now = options.now ?? Date.now;\n const throttleMs = options.checkThrottleMs ?? DEFAULT_CHECK_THROTTLE_MS;\n const checking = new Map<\n string,\n {\n generation: number;\n promise: Promise<LifecycleResult<RepositorySummary>>;\n }\n >();\n const previousChecks = new Map<\n string,\n { at: number; result: LifecycleResult<RepositorySummary> }\n >();\n const checkGenerations = new Map<string, number>();\n\n function invalidateChecks(login: string) {\n previousChecks.delete(login);\n checkGenerations.set(login, (checkGenerations.get(login) ?? 0) + 1);\n }\n\n async function identityOrFailure() {\n try {\n const identity = await options.getCurrentUser();\n return identity;\n } catch {\n return null;\n }\n }\n\n async function getSummary(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n try {\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n }\n\n async function check(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n if (options.entrySynchronizationInFlight?.(identity)) {\n if (options.waitForEntrySynchronization !== undefined) {\n await options.waitForEntrySynchronization(identity);\n }\n if (options.entrySynchronizationInFlight?.(identity)) {\n return lifecycleSuccess(checkingSummary(options.gitMode));\n }\n }\n\n const generation = checkGenerations.get(identity.login) ?? 0;\n const previous = previousChecks.get(identity.login);\n if (previous !== undefined && now() - previous.at < throttleMs) {\n return previous.result;\n }\n const active = checking.get(identity.login);\n if (active !== undefined && active.generation === generation) {\n return active.promise;\n }\n\n const attempt = (async () => {\n try {\n const result =\n options.gitMode === \"manual\" ||\n typeof options.lifecycle!.checkRepositorySummary !== \"function\"\n ? await options.lifecycle!.getRepositorySummary(identity)\n : await options.lifecycle!.checkRepositorySummary(identity);\n if (\n result.ok &&\n (checkGenerations.get(identity.login) ?? 0) === generation\n ) {\n previousChecks.set(identity.login, { at: now(), result });\n }\n return result;\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n }\n })();\n checking.set(identity.login, { generation, promise: attempt });\n try {\n return await attempt;\n } finally {\n if (checking.get(identity.login)?.promise === attempt) {\n checking.delete(identity.login);\n }\n }\n }\n\n async function scopedMutation(\n operation: \"save\" | \"discard\",\n input: PrototypeCommandInput,\n ): Promise<LifecycleResult<unknown>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n const mutation = options.lifecycle[operation];\n if (mutation === undefined) return unavailable();\n invalidateChecks(identity.login);\n try {\n const result = (await Reflect.apply(mutation, options.lifecycle, [\n identity,\n input,\n ])) as LifecycleResult<unknown>;\n if (!result.ok) {\n console.error(\n `Bonfire repository ${operation} failed: ${result.error.code}`,\n );\n }\n return result;\n } catch {\n console.error(`Bonfire repository ${operation} failed unexpectedly`);\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n async function applyUpdates(): Promise<LifecycleResult<RepositorySummary>> {\n if (\n options.production ||\n options.lifecycle === null ||\n options.gitMode === \"manual\" ||\n !compatible(options)\n ) {\n return unavailable();\n }\n const identity = await identityOrFailure();\n if (identity === null) return lifecycleFailure(\"unauthenticated\");\n invalidateChecks(identity.login);\n try {\n const preparation = await options.lifecycle.prepareBranch(identity);\n if (!preparation.ok) return lifecycleFailure(preparation.error.code);\n return await options.lifecycle.getRepositorySummary(identity);\n } catch {\n return lifecycleFailure(\"unexpected-failure\");\n } finally {\n invalidateChecks(identity.login);\n }\n }\n\n return {\n getSummary,\n check,\n applyUpdates,\n retry: applyUpdates,\n save: (input) => scopedMutation(\"save\", input),\n discard: (input) => scopedMutation(\"discard\", input),\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { RepositoryActions } from "./repository-actions.js";
2
+ export type RepositoryRoutes = {
3
+ summary(): Promise<Response>;
4
+ check(): Promise<Response>;
5
+ update(): Promise<Response>;
6
+ retry(): Promise<Response>;
7
+ };
8
+ export declare function createRepositoryRoutes(options: {
9
+ production: boolean;
10
+ actions: RepositoryActions;
11
+ }): RepositoryRoutes;
12
+ //# sourceMappingURL=repository-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-routes.d.ts","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAC;AAuBF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,gBAAgB,CAwBnB","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n};\n\nfunction responseFor(\n result: Awaited<ReturnType<RepositoryActions[\"getSummary\"]>>,\n) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n };\n}\n"]}
@@ -0,0 +1,43 @@
1
+ import { NextResponse } from "next/server.js";
2
+ function responseFor(result) {
3
+ if (result.ok) {
4
+ return NextResponse.json(result.value, {
5
+ headers: { "Cache-Control": "no-store" },
6
+ });
7
+ }
8
+ const status = result.error.code === "unauthenticated"
9
+ ? 401
10
+ : result.error.code === "forbidden"
11
+ ? 403
12
+ : 500;
13
+ return new NextResponse(null, {
14
+ status,
15
+ headers: { "Cache-Control": "no-store" },
16
+ });
17
+ }
18
+ export function createRepositoryRoutes(options) {
19
+ const unavailable = () => new Response(null, { status: 404 });
20
+ return {
21
+ async summary() {
22
+ return options.production
23
+ ? unavailable()
24
+ : responseFor(await options.actions.getSummary());
25
+ },
26
+ async check() {
27
+ return options.production
28
+ ? unavailable()
29
+ : responseFor(await options.actions.check());
30
+ },
31
+ async update() {
32
+ return options.production
33
+ ? unavailable()
34
+ : responseFor(await options.actions.applyUpdates());
35
+ },
36
+ async retry() {
37
+ return options.production
38
+ ? unavailable()
39
+ : responseFor(await options.actions.retry());
40
+ },
41
+ };
42
+ }
43
+ //# sourceMappingURL=repository-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-routes.js","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAU9C,SAAS,WAAW,CAClB,MAA4D;IAE5D,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,OAAO,EAAE,EAAE,eAAe,EAA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AE,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n};\n\nfunction responseFor(\n result: Awaited<ReturnType<RepositoryActions[\"getSummary\"]>>,\n) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebay-dt/bonfire-next",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-alpha.10",
4
4
  "description": "Next.js server integration for Bonfire.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -31,18 +31,18 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@ebay-dt/bonfire-core": "0.1.0",
35
- "@ebay-dt/bonfire-node": "0.1.0",
34
+ "@ebay-dt/bonfire-core": "0.2.0-alpha.10",
35
+ "@ebay-dt/bonfire-node": "0.2.0-alpha.10",
36
36
  "jose": "^6.1.3"
37
37
  },
38
38
  "peerDependencies": {
39
- "@ebay-dt/bonfire-react": "0.1.0",
39
+ "@ebay-dt/bonfire-react": "0.2.0-alpha.10",
40
40
  "next": ">=16.2 <17",
41
41
  "react": ">=19.2 <20",
42
42
  "react-dom": ">=19.2 <20"
43
43
  },
44
44
  "devDependencies": {
45
- "@ebay-dt/bonfire-react": "0.1.0",
45
+ "@ebay-dt/bonfire-react": "0.2.0-alpha.10",
46
46
  "@repo/eslint-config": "0.0.0",
47
47
  "@repo/typescript-config": "0.0.0",
48
48
  "@types/node": "20.19.43",