@ebay-dt/bonfire-next 0.2.0-alpha.8 → 0.2.0
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 +8 -0
- package/dist/server/create-bonfire-next.d.ts.map +1 -1
- package/dist/server/create-bonfire-next.js +18 -30
- package/dist/server/create-bonfire-next.js.map +1 -1
- package/dist/server/prototype-actions.d.ts +3 -1
- package/dist/server/prototype-actions.d.ts.map +1 -1
- package/dist/server/prototype-actions.js +47 -3
- package/dist/server/prototype-actions.js.map +1 -1
- package/dist/server/prototype-routes.d.ts.map +1 -1
- package/dist/server/prototype-routes.js +19 -3
- package/dist/server/prototype-routes.js.map +1 -1
- package/dist/server/prototype-source-link.d.ts +13 -0
- package/dist/server/prototype-source-link.d.ts.map +1 -0
- package/dist/server/prototype-source-link.js +65 -0
- package/dist/server/prototype-source-link.js.map +1 -0
- package/dist/server/repository-actions.d.ts +6 -6
- package/dist/server/repository-actions.d.ts.map +1 -1
- package/dist/server/repository-actions.js +62 -24
- package/dist/server/repository-actions.js.map +1 -1
- package/dist/server/repository-routes.d.ts +1 -0
- package/dist/server/repository-routes.d.ts.map +1 -1
- package/dist/server/repository-routes.js +7 -0
- package/dist/server/repository-routes.js.map +1 -1
- package/package.json +5 -5
- package/dist/server/entry-coordinator.d.ts +0 -29
- package/dist/server/entry-coordinator.d.ts.map +0 -1
- package/dist/server/entry-coordinator.js +0 -84
- package/dist/server/entry-coordinator.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-routes.d.ts","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repository-routes.d.ts","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;CACvC,CAAC;AAqBF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC9C,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,gBAAgB,CAgCnB","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport { lifecycleFailure, type LifecycleResult } from \"@ebay-dt/bonfire-core\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n retryPreparation(): Promise<Response>;\n};\n\nfunction responseFor<Value>(result: LifecycleResult<Value>) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n async retryPreparation() {\n return options.production\n ? unavailable()\n : responseFor(\n await (options.actions.retryPreparation?.() ??\n Promise.resolve(lifecycleFailure(\"forbidden\"))),\n );\n },\n };\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextResponse } from "next/server.js";
|
|
2
|
+
import { lifecycleFailure } from "@ebay-dt/bonfire-core";
|
|
2
3
|
function responseFor(result) {
|
|
3
4
|
if (result.ok) {
|
|
4
5
|
return NextResponse.json(result.value, {
|
|
@@ -38,6 +39,12 @@ export function createRepositoryRoutes(options) {
|
|
|
38
39
|
? unavailable()
|
|
39
40
|
: responseFor(await options.actions.retry());
|
|
40
41
|
},
|
|
42
|
+
async retryPreparation() {
|
|
43
|
+
return options.production
|
|
44
|
+
? unavailable()
|
|
45
|
+
: responseFor(await (options.actions.retryPreparation?.() ??
|
|
46
|
+
Promise.resolve(lifecycleFailure("forbidden"))));
|
|
47
|
+
},
|
|
41
48
|
};
|
|
42
49
|
}
|
|
43
50
|
//# sourceMappingURL=repository-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-routes.js","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"repository-routes.js","sourceRoot":"","sources":["../../src/server/repository-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAW/E,SAAS,WAAW,CAAQ,MAA8B;IACxD,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YACrC,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE;SACzC,CAAC,CAAC;I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AAK,CAAC,gBAAgB;YACpB,OAAO,OAAO,CAAC,UAAU;gBACvB,CAAC,CAAC,WAAW,EAAE;gBACf,CAAC,CAAC,WAAW,CACT,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE;oBACzC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAClD,CAAC;QACR,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { NextResponse } from \"next/server.js\";\nimport { lifecycleFailure, type LifecycleResult } from \"@ebay-dt/bonfire-core\";\nimport type { RepositoryActions } from \"./repository-actions.js\";\n\nexport type RepositoryRoutes = {\n summary(): Promise<Response>;\n check(): Promise<Response>;\n update(): Promise<Response>;\n retry(): Promise<Response>;\n retryPreparation(): Promise<Response>;\n};\n\nfunction responseFor<Value>(result: LifecycleResult<Value>) {\n if (result.ok) {\n return NextResponse.json(result.value, {\n headers: { \"Cache-Control\": \"no-store\" },\n });\n }\n\n const status =\n result.error.code === \"unauthenticated\"\n ? 401\n : result.error.code === \"forbidden\"\n ? 403\n : 500;\n return new NextResponse(null, {\n status,\n headers: { \"Cache-Control\": \"no-store\" },\n });\n}\n\nexport function createRepositoryRoutes(options: {\n production: boolean;\n actions: RepositoryActions;\n}): RepositoryRoutes {\n const unavailable = () => new Response(null, { status: 404 });\n return {\n async summary() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.getSummary());\n },\n async check() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.check());\n },\n async update() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.applyUpdates());\n },\n async retry() {\n return options.production\n ? unavailable()\n : responseFor(await options.actions.retry());\n },\n async retryPreparation() {\n return options.production\n ? unavailable()\n : responseFor(\n await (options.actions.retryPreparation?.() ??\n Promise.resolve(lifecycleFailure(\"forbidden\"))),\n );\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebay-dt/bonfire-next",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Next.js server integration for Bonfire.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ebay-dt/bonfire-core": "0.2.0
|
|
35
|
-
"@ebay-dt/bonfire-node": "0.2.0
|
|
34
|
+
"@ebay-dt/bonfire-core": "0.2.0",
|
|
35
|
+
"@ebay-dt/bonfire-node": "0.2.0",
|
|
36
36
|
"jose": "^6.1.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@ebay-dt/bonfire-react": "0.2.0
|
|
39
|
+
"@ebay-dt/bonfire-react": "0.2.0",
|
|
40
40
|
"next": ">=16.2 <17",
|
|
41
41
|
"react": ">=19.2 <20",
|
|
42
42
|
"react-dom": ">=19.2 <20"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@ebay-dt/bonfire-react": "0.2.0
|
|
45
|
+
"@ebay-dt/bonfire-react": "0.2.0",
|
|
46
46
|
"@repo/eslint-config": "0.0.0",
|
|
47
47
|
"@repo/typescript-config": "0.0.0",
|
|
48
48
|
"@types/node": "20.19.43",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { BonfireIdentity, BranchPreparationValue } from "@ebay-dt/bonfire-core";
|
|
2
|
-
import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
|
|
3
|
-
type EntryLifecycle = Pick<PrototypeLifecycle, "prepareBranch">;
|
|
4
|
-
export type EntrySynchronizationStatus = "started" | "deferred" | "completed";
|
|
5
|
-
export type EntrySynchronizationCoordinator = {
|
|
6
|
-
synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;
|
|
7
|
-
waitForCompletion(identity: BonfireIdentity): Promise<void>;
|
|
8
|
-
isInFlight(identity: BonfireIdentity): boolean;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Coordinates the first authenticated repository attempt for each identity in
|
|
12
|
-
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
13
|
-
* not repeated until the process is restarted.
|
|
14
|
-
*
|
|
15
|
-
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
16
|
-
* timed-out request continues the operation in-process while allowing the
|
|
17
|
-
* page render to proceed with deferred preparation.
|
|
18
|
-
*/
|
|
19
|
-
export declare function createEntrySynchronizationCoordinator(options: {
|
|
20
|
-
lifecycle: EntryLifecycle | null;
|
|
21
|
-
waitMs?: number;
|
|
22
|
-
onStatus?(event: {
|
|
23
|
-
identity: BonfireIdentity;
|
|
24
|
-
status: EntrySynchronizationStatus;
|
|
25
|
-
result?: BranchPreparationValue;
|
|
26
|
-
}): void;
|
|
27
|
-
}): EntrySynchronizationCoordinator;
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=entry-coordinator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.d.ts","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,KAAK,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAOhE,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;AAE9E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC/E,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC;CAChD,CAAC;AAIF;;;;;;;;GAQG;AACH,wBAAgB,qCAAqC,CAAC,OAAO,EAAE;IAC7D,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,CAAC,KAAK,EAAE;QACf,QAAQ,EAAE,eAAe,CAAC;QAC1B,MAAM,EAAE,0BAA0B,CAAC;QACnC,MAAM,CAAC,EAAE,sBAAsB,CAAC;KACjC,GAAG,IAAI,CAAC;CACV,GAAG,+BAA+B,CA0FlC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the\n * page render to proceed with deferred preparation.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(\n () =>\n ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n );\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
const DEFAULT_ENTRY_WAIT_MS = 10_000;
|
|
2
|
-
/**
|
|
3
|
-
* Coordinates the first authenticated repository attempt for each identity in
|
|
4
|
-
* this process. Concurrent tabs share one promise, and a completed attempt is
|
|
5
|
-
* not repeated until the process is restarted.
|
|
6
|
-
*
|
|
7
|
-
* The wait budget is intentionally shorter than the Git operation timeout. A
|
|
8
|
-
* timed-out request continues the operation in-process while allowing the
|
|
9
|
-
* page render to proceed with deferred preparation.
|
|
10
|
-
*/
|
|
11
|
-
export function createEntrySynchronizationCoordinator(options) {
|
|
12
|
-
const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;
|
|
13
|
-
const inFlight = new Map();
|
|
14
|
-
const completed = new Map();
|
|
15
|
-
const deferredReported = new Set();
|
|
16
|
-
function report(event) {
|
|
17
|
-
try {
|
|
18
|
-
options.onStatus?.(event);
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// Observability must never affect authentication or page rendering.
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function createRenderWait(identity, completion) {
|
|
25
|
-
if (waitMs <= 0)
|
|
26
|
-
return completion;
|
|
27
|
-
let timeout;
|
|
28
|
-
const deferred = new Promise((resolve) => {
|
|
29
|
-
timeout = setTimeout(() => {
|
|
30
|
-
if (!deferredReported.has(identity.login)) {
|
|
31
|
-
deferredReported.add(identity.login);
|
|
32
|
-
report({ identity, status: "deferred" });
|
|
33
|
-
}
|
|
34
|
-
resolve({ status: "deferred" });
|
|
35
|
-
}, waitMs);
|
|
36
|
-
});
|
|
37
|
-
return Promise.race([completion, deferred]).finally(() => {
|
|
38
|
-
if (timeout !== undefined)
|
|
39
|
-
clearTimeout(timeout);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async function synchronize(identity) {
|
|
43
|
-
if (options.lifecycle === null)
|
|
44
|
-
return null;
|
|
45
|
-
const previous = completed.get(identity.login);
|
|
46
|
-
if (previous !== undefined)
|
|
47
|
-
return previous;
|
|
48
|
-
const active = inFlight.get(identity.login);
|
|
49
|
-
if (active !== undefined)
|
|
50
|
-
return active.renderWait;
|
|
51
|
-
report({ identity, status: "started" });
|
|
52
|
-
const attempt = options.lifecycle
|
|
53
|
-
.prepareBranch(identity)
|
|
54
|
-
.then((result) => result.ok
|
|
55
|
-
? result.value
|
|
56
|
-
: { status: "unsafe" })
|
|
57
|
-
.catch(() => ({ status: "unsafe" }));
|
|
58
|
-
let completion;
|
|
59
|
-
completion = attempt
|
|
60
|
-
.then((result) => {
|
|
61
|
-
completed.set(identity.login, result);
|
|
62
|
-
report({ identity, status: "completed", result });
|
|
63
|
-
return result;
|
|
64
|
-
})
|
|
65
|
-
.finally(() => {
|
|
66
|
-
deferredReported.delete(identity.login);
|
|
67
|
-
if (inFlight.get(identity.login)?.completion === completion) {
|
|
68
|
-
inFlight.delete(identity.login);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const renderWait = createRenderWait(identity, completion);
|
|
72
|
-
inFlight.set(identity.login, { completion, renderWait });
|
|
73
|
-
return renderWait;
|
|
74
|
-
}
|
|
75
|
-
async function waitForCompletion(identity) {
|
|
76
|
-
await inFlight.get(identity.login)?.completion;
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
synchronize,
|
|
80
|
-
waitForCompletion,
|
|
81
|
-
isInFlight: (identity) => inFlight.has(identity.login),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=entry-coordinator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-coordinator.js","sourceRoot":"","sources":["../../src/server/entry-coordinator.ts"],"names":[],"mappings":"AAqBA,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAErC;;;;;;;;GAQG;AACH,MAAM,UAAU,qCAAqC,CAAC,OAQrD;IACC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAAC;IACvD,M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;QACH,CAAC,CAAC,CAAC;QACL,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1D,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAEzD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,KAAK,UAAU,iBAAiB,CAAC,QAAyB;QACxD,MAAM,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACjD,CAAC;IAED,OAAO;QACL,WAAW;QACX,iBAAiB;QACjB,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;KACvD,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BonfireIdentity,\n BranchPreparationValue,\n} from \"@ebay-dt/bonfire-core\";\nimport type { PrototypeLifecycle } from \"@ebay-dt/bonfire-node\";\n\ntype EntryLifecycle = Pick<PrototypeLifecycle, \"prepareBranch\">;\n\ntype InFlightAttempt = {\n completion: Promise<BranchPreparationValue>;\n renderWait: Promise<BranchPreparationValue>;\n};\n\nexport type EntrySynchronizationStatus = \"started\" | \"deferred\" | \"completed\";\n\nexport type EntrySynchronizationCoordinator = {\n synchronize(identity: BonfireIdentity): Promise<BranchPreparationValue | null>;\n waitForCompletion(identity: BonfireIdentity): Promise<void>;\n isInFlight(identity: BonfireIdentity): boolean;\n};\n\nconst DEFAULT_ENTRY_WAIT_MS = 10_000;\n\n/**\n * Coordinates the first authenticated repository attempt for each identity in\n * this process. Concurrent tabs share one promise, and a completed attempt is\n * not repeated until the process is restarted.\n *\n * The wait budget is intentionally shorter than the Git operation timeout. A\n * timed-out request continues the operation in-process while allowing the\n * page render to proceed with deferred preparation.\n */\nexport function createEntrySynchronizationCoordinator(options: {\n lifecycle: EntryLifecycle | null;\n waitMs?: number;\n onStatus?(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }): void;\n}): EntrySynchronizationCoordinator {\n const waitMs = options.waitMs ?? DEFAULT_ENTRY_WAIT_MS;\n const inFlight = new Map<string, InFlightAttempt>();\n const completed = new Map<string, BranchPreparationValue>();\n const deferredReported = new Set<string>();\n\n function report(event: {\n identity: BonfireIdentity;\n status: EntrySynchronizationStatus;\n result?: BranchPreparationValue;\n }) {\n try {\n options.onStatus?.(event);\n } catch {\n // Observability must never affect authentication or page rendering.\n }\n }\n\n function createRenderWait(\n identity: BonfireIdentity,\n completion: Promise<BranchPreparationValue>,\n ) {\n if (waitMs <= 0) return completion;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const deferred = new Promise<BranchPreparationValue>((resolve) => {\n timeout = setTimeout(() => {\n if (!deferredReported.has(identity.login)) {\n deferredReported.add(identity.login);\n report({ identity, status: \"deferred\" });\n }\n resolve({ status: \"deferred\" });\n }, waitMs);\n });\n\n return Promise.race([completion, deferred]).finally(() => {\n if (timeout !== undefined) clearTimeout(timeout);\n });\n }\n\n async function synchronize(identity: BonfireIdentity) {\n if (options.lifecycle === null) return null;\n\n const previous = completed.get(identity.login);\n if (previous !== undefined) return previous;\n\n const active = inFlight.get(identity.login);\n if (active !== undefined) return active.renderWait;\n\n report({ identity, status: \"started\" });\n const attempt = options.lifecycle\n .prepareBranch(identity)\n .then((result) =>\n result.ok\n ? result.value\n : ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n )\n .catch(\n () =>\n ({ status: \"unsafe\" } satisfies BranchPreparationValue),\n );\n\n let completion!: Promise<BranchPreparationValue>;\n completion = attempt\n .then((result) => {\n completed.set(identity.login, result);\n report({ identity, status: \"completed\", result });\n return result;\n })\n .finally(() => {\n deferredReported.delete(identity.login);\n if (inFlight.get(identity.login)?.completion === completion) {\n inFlight.delete(identity.login);\n }\n });\n const renderWait = createRenderWait(identity, completion);\n inFlight.set(identity.login, { completion, renderWait });\n\n return renderWait;\n }\n\n async function waitForCompletion(identity: BonfireIdentity) {\n await inFlight.get(identity.login)?.completion;\n }\n\n return {\n synchronize,\n waitForCompletion,\n isInFlight: (identity) => inFlight.has(identity.login),\n };\n}\n"]}
|