@ebay-dt/bonfire-next 0.1.0-alpha.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +305 -0
  3. package/dist/client/index.d.ts +2 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +2 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/lifecycle-provider.d.ts +12 -0
  8. package/dist/client/lifecycle-provider.d.ts.map +1 -0
  9. package/dist/client/lifecycle-provider.js +58 -0
  10. package/dist/client/lifecycle-provider.js.map +1 -0
  11. package/dist/server/auth-boundary.d.ts +9 -0
  12. package/dist/server/auth-boundary.d.ts.map +1 -0
  13. package/dist/server/auth-boundary.js +25 -0
  14. package/dist/server/auth-boundary.js.map +1 -0
  15. package/dist/server/auth-routes.d.ts +17 -0
  16. package/dist/server/auth-routes.d.ts.map +1 -0
  17. package/dist/server/auth-routes.js +103 -0
  18. package/dist/server/auth-routes.js.map +1 -0
  19. package/dist/server/create-bonfire-next.d.ts +69 -0
  20. package/dist/server/create-bonfire-next.d.ts.map +1 -0
  21. package/dist/server/create-bonfire-next.js +137 -0
  22. package/dist/server/create-bonfire-next.js.map +1 -0
  23. package/dist/server/index.d.ts +4 -0
  24. package/dist/server/index.d.ts.map +1 -0
  25. package/dist/server/index.js +2 -0
  26. package/dist/server/index.js.map +1 -0
  27. package/dist/server/login-page-model.d.ts +16 -0
  28. package/dist/server/login-page-model.d.ts.map +1 -0
  29. package/dist/server/login-page-model.js +28 -0
  30. package/dist/server/login-page-model.js.map +1 -0
  31. package/dist/server/prototype-actions.d.ts +15 -0
  32. package/dist/server/prototype-actions.d.ts.map +1 -0
  33. package/dist/server/prototype-actions.js +80 -0
  34. package/dist/server/prototype-actions.js.map +1 -0
  35. package/dist/server/prototype-dashboard.d.ts +13 -0
  36. package/dist/server/prototype-dashboard.d.ts.map +1 -0
  37. package/dist/server/prototype-dashboard.js +65 -0
  38. package/dist/server/prototype-dashboard.js.map +1 -0
  39. package/dist/server/prototype-routes.d.ts +16 -0
  40. package/dist/server/prototype-routes.d.ts.map +1 -0
  41. package/dist/server/prototype-routes.js +127 -0
  42. package/dist/server/prototype-routes.js.map +1 -0
  43. package/dist/server/session.d.ts +47 -0
  44. package/dist/server/session.d.ts.map +1 -0
  45. package/dist/server/session.js +105 -0
  46. package/dist/server/session.js.map +1 -0
  47. package/package.json +65 -0
@@ -0,0 +1,69 @@
1
+ import { type BonfireConfigInput, type BonfireIdentity } from "@ebay-dt/bonfire-core";
2
+ import { type GitHubCliClientLike, type PreparePrototypeFiles, type PrototypeCatalogLike, type PrototypeLifecycle } from "@ebay-dt/bonfire-node";
3
+ import type { PrototypeWatcher } from "@ebay-dt/bonfire-node/watcher";
4
+ import { type CSSProperties } from "react";
5
+ import { type LoginSearchParams } from "./login-page-model.js";
6
+ export type CreateBonfireNextOptions = {
7
+ config: BonfireConfigInput;
8
+ repositoryRoot: string;
9
+ prototypeRoot?: string;
10
+ primaryBranch?: string;
11
+ sessionSecret?: string;
12
+ githubCli?: GitHubCliClientLike;
13
+ prototypeCatalog?: PrototypeCatalogLike;
14
+ prototypeLifecycle?: PrototypeLifecycle;
15
+ prototypeWatcher?: PrototypeWatcher;
16
+ preparePrototypeFiles?: PreparePrototypeFiles;
17
+ disableAutoBranchSwitch?: string;
18
+ };
19
+ type AppLayoutModel = {
20
+ htmlProps: {
21
+ style: CSSProperties;
22
+ };
23
+ headerProps: {
24
+ applicationName: string;
25
+ user: BonfireIdentity | null;
26
+ };
27
+ };
28
+ export declare function createBonfireNext(options: CreateBonfireNextOptions): {
29
+ prototypes: {
30
+ getDashboardModel: (searchParams?: Promise<import("./prototype-dashboard.js").PrototypeDashboardSearchParams> | import("./prototype-dashboard.js").PrototypeDashboardSearchParams | undefined) => Promise<import("@ebay-dt/bonfire-core").PrototypeDashboardModel>;
31
+ getSummary: (ref: import("@ebay-dt/bonfire-core").PrototypeRef) => Promise<import("@ebay-dt/bonfire-core").PrototypeSummary | null>;
32
+ lifecycle: PrototypeLifecycle | null;
33
+ actions: import("./prototype-actions.js").PrototypeActions;
34
+ routes: import("./prototype-routes.js").PrototypeRoutes;
35
+ };
36
+ auth: {
37
+ getSession: () => Promise<{
38
+ login: string;
39
+ name: string | null;
40
+ avatar_url: string;
41
+ } | null>;
42
+ getCurrentUser: () => Promise<{
43
+ login: string;
44
+ name: string | null;
45
+ avatar_url: string;
46
+ } | null>;
47
+ getAppLayoutModel: () => Promise<AppLayoutModel>;
48
+ getLoginPageModel: (searchParams?: LoginSearchParams | Promise<LoginSearchParams>) => Promise<{
49
+ applicationName: string;
50
+ githubHostname: string;
51
+ loginUrl: string;
52
+ statusUrl: string;
53
+ returnUrl: string;
54
+ deviceUrl: string;
55
+ fallbackCommand: string;
56
+ deviceCode: string | null;
57
+ pollingActive: boolean;
58
+ error: "branch_prepare_failed" | "gh_cli_failed" | null;
59
+ }>;
60
+ proxy: (request: import("next/server.js").NextRequest) => Promise<import("next/server.js").NextResponse<unknown>>;
61
+ routes: {
62
+ login: (request: import("next/server.js").NextRequest) => Promise<import("next/server.js").NextResponse<unknown>>;
63
+ status: () => Promise<import("next/server.js").NextResponse<unknown>>;
64
+ logout: (request: import("next/server.js").NextRequest) => Promise<import("next/server.js").NextResponse<unknown>>;
65
+ };
66
+ };
67
+ };
68
+ export {};
69
+ //# sourceMappingURL=create-bonfire-next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-bonfire-next.d.ts","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAM/B,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE;QACT,KAAK,EAAE,aAAa,CAAC;KACtB,CAAC;IACF,WAAW,EAAE;QACX,eAAe,EAAE,MAAM,CAAC;QACxB,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;KAC9B,CAAC;CACH,CAAC;AAQF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;iCAgFvB,OAAO,CAAC,cAAc,CAAC;2CAgBhD,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;;;;;;;;;;;;;;;;;;;EAwChE"}
@@ -0,0 +1,137 @@
1
+ import { join, resolve } from "node:path";
2
+ import { defineConfig, lifecycleSuccess, parseAutomaticBranchSwitchSetting, } from "@ebay-dt/bonfire-core";
3
+ import { GitHubCliClient, LocalPrototypeLifecycle, PrototypeCatalog, } from "@ebay-dt/bonfire-node";
4
+ import { cache } from "react";
5
+ import { createAuthProxy } from "./auth-boundary.js";
6
+ import { createAuthRoutes } from "./auth-routes.js";
7
+ import { createLoginPageModel, getLoginPageSearchParams, } from "./login-page-model.js";
8
+ import { createSessionAdapter } from "./session.js";
9
+ import { createPrototypeActions } from "./prototype-actions.js";
10
+ import { createPrototypeDashboardModelLoader } from "./prototype-dashboard.js";
11
+ import { createPrototypeRoutes } from "./prototype-routes.js";
12
+ const APP_HEADER_BLOCK_SIZE_PROPERTY = "--app-header-block-size";
13
+ const APP_HEADER_PRESENT_BLOCK_SIZE = "2.5rem";
14
+ export function createBonfireNext(options) {
15
+ const config = defineConfig(options.config);
16
+ const production = process.env.NODE_ENV === "production";
17
+ if (options.prototypeLifecycle && options.preparePrototypeFiles) {
18
+ throw new Error("prototypeLifecycle and preparePrototypeFiles cannot be supplied together");
19
+ }
20
+ const automaticBranchSwitch = parseAutomaticBranchSwitchSetting(options.disableAutoBranchSwitch);
21
+ const session = createSessionAdapter({
22
+ appId: config.appId,
23
+ sessionSecret: options.sessionSecret,
24
+ production,
25
+ });
26
+ const githubCli = options.githubCli ??
27
+ new GitHubCliClient({ hostname: config.auth.github.hostname });
28
+ const getSession = session.getSession;
29
+ const prototypeCatalog = options.prototypeCatalog ??
30
+ new PrototypeCatalog({
31
+ repositoryRoot: options.repositoryRoot,
32
+ prototypeRoot: options.prototypeRoot,
33
+ });
34
+ const lifecycle = options.prototypeLifecycle ??
35
+ (production
36
+ ? null
37
+ : new LocalPrototypeLifecycle({
38
+ repositoryRoot: options.repositoryRoot,
39
+ prototypeRoot: options.prototypeRoot,
40
+ primaryBranch: options.primaryBranch,
41
+ automaticBranchSwitch,
42
+ catalog: prototypeCatalog,
43
+ preparePrototypeFiles: options.preparePrototypeFiles,
44
+ }));
45
+ const getCurrentUser = cache(() => getSession());
46
+ const prepareIdentity = production
47
+ ? undefined
48
+ : automaticBranchSwitch === "enabled" && lifecycle
49
+ ? lifecycle.prepareBranch.bind(lifecycle)
50
+ : async () => lifecycleSuccess({
51
+ status: "disabled",
52
+ });
53
+ const prototypeActions = createPrototypeActions({
54
+ production,
55
+ getCurrentUser: getSession,
56
+ lifecycle,
57
+ });
58
+ let prototypeWatcher = options.prototypeWatcher;
59
+ const getWatcher = async () => {
60
+ if (prototypeWatcher)
61
+ return prototypeWatcher;
62
+ if (production)
63
+ return null;
64
+ const { createPrototypeWatcher } = await import("@ebay-dt/bonfire-node/watcher");
65
+ prototypeWatcher = createPrototypeWatcher({
66
+ repositoryRoot: options.repositoryRoot,
67
+ prototypeRoot: resolve(options.repositoryRoot, options.prototypeRoot ?? join("src", "app", "(prototypes)")),
68
+ });
69
+ return prototypeWatcher;
70
+ };
71
+ const prototypeRoutes = createPrototypeRoutes({
72
+ production,
73
+ getCurrentUser: getSession,
74
+ lifecycle,
75
+ getWatcher,
76
+ });
77
+ const getDashboardModel = createPrototypeDashboardModelLoader({
78
+ applicationName: config.name,
79
+ production,
80
+ catalog: prototypeCatalog,
81
+ getCurrentUser,
82
+ });
83
+ const getAppLayoutModel = cache(async () => {
84
+ const user = production ? null : await getCurrentUser();
85
+ const style = {
86
+ [APP_HEADER_BLOCK_SIZE_PROPERTY]: user === null ? "0px" : APP_HEADER_PRESENT_BLOCK_SIZE,
87
+ };
88
+ return {
89
+ htmlProps: { style },
90
+ headerProps: {
91
+ applicationName: config.name,
92
+ user,
93
+ },
94
+ };
95
+ });
96
+ async function getLoginPageModel(searchParams) {
97
+ // Keep Next's navigation module out of route-handler bundles. The same
98
+ // factory instance supplies both route handlers and server-page helpers.
99
+ const { redirect } = await import("next/navigation.js");
100
+ if (production)
101
+ redirect("/");
102
+ if (await getSession())
103
+ redirect("/");
104
+ const params = await getLoginPageSearchParams(searchParams);
105
+ return createLoginPageModel(config, params);
106
+ }
107
+ const proxy = createAuthProxy({
108
+ appId: config.appId,
109
+ sessionSecret: options.sessionSecret,
110
+ production,
111
+ });
112
+ const routes = createAuthRoutes({
113
+ production,
114
+ githubCli,
115
+ createSession: session.createSession,
116
+ clearSession: session.clearSession,
117
+ prepareIdentity,
118
+ });
119
+ return {
120
+ prototypes: {
121
+ getDashboardModel,
122
+ getSummary: prototypeCatalog.getSummary.bind(prototypeCatalog),
123
+ lifecycle,
124
+ actions: prototypeActions,
125
+ routes: prototypeRoutes,
126
+ },
127
+ auth: {
128
+ getSession,
129
+ getCurrentUser,
130
+ getAppLayoutModel,
131
+ getLoginPageModel,
132
+ proxy,
133
+ routes,
134
+ },
135
+ };
136
+ }
137
+ //# sourceMappingURL=create-bonfire-next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-bonfire-next.js","sourceRoot":"","sources":["../../src/server/create-bonfire-next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iCAAiC,GAIlC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,gBAAgB,GAKjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAsB,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AA6B9D,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;AACjE,MAAM,6BAA6B,GAAG,QAAQ,CAAC;AAE/C,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IACjE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,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,EAAE;YACJ,UAAU;YACV,cAAc;YACd,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,MAAM;SACP;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createBonfireNext, type CreateBonfireNextOptions, } from "./create-bonfire-next.js";
2
+ export type { PrototypeActions } from "./prototype-actions.js";
3
+ export type { PrototypeRoutes } from "./prototype-routes.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createBonfireNext, } from "./create-bonfire-next.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAElB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { BonfireConfig } from "@ebay-dt/bonfire-core";
2
+ export type LoginSearchParams = Record<string, string | string[] | undefined>;
3
+ export declare function createLoginPageModel(config: BonfireConfig, searchParams?: LoginSearchParams): {
4
+ applicationName: string;
5
+ githubHostname: string;
6
+ loginUrl: string;
7
+ statusUrl: string;
8
+ returnUrl: string;
9
+ deviceUrl: string;
10
+ fallbackCommand: string;
11
+ deviceCode: string | null;
12
+ pollingActive: boolean;
13
+ error: "branch_prepare_failed" | "gh_cli_failed" | null;
14
+ };
15
+ export declare function getLoginPageSearchParams(searchParams?: LoginSearchParams | Promise<LoginSearchParams>): Promise<LoginSearchParams>;
16
+ //# sourceMappingURL=login-page-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-page-model.d.ts","sourceRoot":"","sources":["../../src/server/login-page-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AAQ9E,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,YAAY,CAAC,EAAE,iBAAiB;;;;;;;;;;;EAuBjC;AAED,wBAAsB,wBAAwB,CAC5C,YAAY,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,8BAG9D"}
@@ -0,0 +1,28 @@
1
+ const DEVICE_CODE_PATTERN = /^[A-Za-z0-9-]{1,64}$/;
2
+ function singleValue(value) {
3
+ return typeof value === "string" ? value : null;
4
+ }
5
+ export function createLoginPageModel(config, searchParams) {
6
+ const auth = singleValue(searchParams?.auth);
7
+ const error = singleValue(searchParams?.error);
8
+ const code = singleValue(searchParams?.code);
9
+ const pollingActive = auth === "started";
10
+ return {
11
+ applicationName: config.name,
12
+ githubHostname: config.auth.github.hostname,
13
+ loginUrl: "/auth/login",
14
+ statusUrl: "/auth/status",
15
+ returnUrl: "/",
16
+ deviceUrl: `https://${config.auth.github.hostname}/login/device`,
17
+ fallbackCommand: `gh auth login --hostname ${config.auth.github.hostname}`,
18
+ deviceCode: pollingActive && code && DEVICE_CODE_PATTERN.test(code) ? code : null,
19
+ pollingActive,
20
+ error: error === "gh_cli_failed" || error === "branch_prepare_failed"
21
+ ? error
22
+ : null,
23
+ };
24
+ }
25
+ export async function getLoginPageSearchParams(searchParams) {
26
+ return (await searchParams) ?? {};
27
+ }
28
+ //# sourceMappingURL=login-page-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-page-model.js","sourceRoot":"","sources":["../../src/server/login-page-model.ts"],"names":[],"mappings":"AAOA,MAAM,mBAAmB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reatePrototypeValue, type DiscardPrototypeInput, type DiscardPrototypeValue, type DuplicatePrototypeInput, type DuplicatePrototypeValue, type LifecycleResult, type SavePrototypeInput, type SavePrototypeValue, type BonfireIdentity } from "@ebay-dt/bonfire-core";
2
+ import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
3
+ export type PrototypeActions = {
4
+ create(input: CreatePrototypeInput): Promise<LifecycleResult<CreatePrototypeValue>>;
5
+ duplicate(input: DuplicatePrototypeInput): Promise<LifecycleResult<DuplicatePrototypeValue>>;
6
+ save(input: SavePrototypeInput): Promise<LifecycleResult<SavePrototypeValue>>;
7
+ discard(input: DiscardPrototypeInput): Promise<LifecycleResult<DiscardPrototypeValue>>;
8
+ };
9
+ export type PrototypeActionsOptions = {
10
+ production: boolean;
11
+ getCurrentUser: () => Promise<BonfireIdentity | null>;
12
+ lifecycle: PrototypeLifecycle | null;
13
+ };
14
+ export declare function createPrototypeActions(options: PrototypeActionsOptions): PrototypeActions;
15
+ //# sourceMappingURL=prototype-actions.d.ts.map
@@ -0,0 +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,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CACJ,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAClD,SAAS,CACP,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC9E,OAAO,CACL,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACtC,CAAC;AAQF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,gBAAgB,CA8FlB"}
@@ -0,0 +1,80 @@
1
+ import { lifecycleFailure, parseCreatePrototypeInput, parseDiscardPrototypeInput, parseDuplicatePrototypeInput, parseSavePrototypeInput, LifecycleInputError, } from "@ebay-dt/bonfire-core";
2
+ function logUnexpectedFailure(operation) {
3
+ console.error(`Bonfire prototype ${operation} failed unexpectedly.`);
4
+ }
5
+ export function createPrototypeActions(options) {
6
+ async function create(input) {
7
+ if (options.production || options.lifecycle === null) {
8
+ return lifecycleFailure("forbidden");
9
+ }
10
+ try {
11
+ const identity = await options.getCurrentUser();
12
+ if (identity === null)
13
+ return lifecycleFailure("unauthenticated");
14
+ return await options.lifecycle.create(identity, parseCreatePrototypeInput(input));
15
+ }
16
+ catch (error) {
17
+ if (error instanceof LifecycleInputError) {
18
+ return lifecycleFailure("invalid-input");
19
+ }
20
+ logUnexpectedFailure("create");
21
+ return lifecycleFailure("unexpected-failure");
22
+ }
23
+ }
24
+ async function duplicate(input) {
25
+ if (options.production || options.lifecycle === null) {
26
+ return lifecycleFailure("forbidden");
27
+ }
28
+ try {
29
+ const identity = await options.getCurrentUser();
30
+ if (identity === null)
31
+ return lifecycleFailure("unauthenticated");
32
+ return await options.lifecycle.duplicate(identity, parseDuplicatePrototypeInput(input));
33
+ }
34
+ catch (error) {
35
+ if (error instanceof LifecycleInputError) {
36
+ return lifecycleFailure("invalid-input");
37
+ }
38
+ logUnexpectedFailure("duplicate");
39
+ return lifecycleFailure("unexpected-failure");
40
+ }
41
+ }
42
+ async function save(input) {
43
+ if (options.production || options.lifecycle === null) {
44
+ return lifecycleFailure("forbidden");
45
+ }
46
+ try {
47
+ const identity = await options.getCurrentUser();
48
+ if (identity === null)
49
+ return lifecycleFailure("unauthenticated");
50
+ return await options.lifecycle.save(identity, parseSavePrototypeInput(input));
51
+ }
52
+ catch (error) {
53
+ if (error instanceof LifecycleInputError) {
54
+ return lifecycleFailure("invalid-input");
55
+ }
56
+ logUnexpectedFailure("save");
57
+ return lifecycleFailure("unexpected-failure");
58
+ }
59
+ }
60
+ async function discard(input) {
61
+ if (options.production || options.lifecycle === null) {
62
+ return lifecycleFailure("forbidden");
63
+ }
64
+ try {
65
+ const identity = await options.getCurrentUser();
66
+ if (identity === null)
67
+ return lifecycleFailure("unauthenticated");
68
+ return await options.lifecycle.discard(identity, parseDiscardPrototypeInput(input));
69
+ }
70
+ catch (error) {
71
+ if (error instanceof LifecycleInputError) {
72
+ return lifecycleFailure("invalid-input");
73
+ }
74
+ logUnexpectedFailure("discard");
75
+ return lifecycleFailure("unexpected-failure");
76
+ }
77
+ }
78
+ return { create, duplicate, save, discard };
79
+ }
80
+ //# sourceMappingURL=prototype-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-actions.js","sourceRoot":"","sources":["../../src/server/prototype-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,GAWpB,MAAM,uBAAuB,CAAC;AAsB/B,SAAS,oBAAoB,CAC3B,SAAsD;IAEtD,OAAO,CAAC,KAAK,CAAC,qBAAqB,SAAS,uBAAuB,CAAC,CAAC;AACvE,CA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AS,CAAC,OAAO,CACpC,QAAQ,EACR,0BAA0B,CAAC,KAAK,CAAC,CAClC,CAAC;QACJ,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,SAAS,CAAC,CAAC;YAChC,OAAO,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type PrototypeDashboardModel, type BonfireIdentity } from "@ebay-dt/bonfire-core";
2
+ import type { PrototypeCatalogLike } from "@ebay-dt/bonfire-node";
3
+ export type PrototypeDashboardSearchParams = Record<string, string | string[] | undefined>;
4
+ type DashboardSearchParamsInput = PrototypeDashboardSearchParams | Promise<PrototypeDashboardSearchParams> | undefined;
5
+ type PrototypeDashboardLoaderOptions = {
6
+ applicationName: string;
7
+ production: boolean;
8
+ catalog: PrototypeCatalogLike;
9
+ getCurrentUser: () => Promise<BonfireIdentity | null>;
10
+ };
11
+ export declare function createPrototypeDashboardModelLoader(options: PrototypeDashboardLoaderOptions): (searchParams?: DashboardSearchParamsInput) => Promise<PrototypeDashboardModel>;
12
+ export {};
13
+ //# sourceMappingURL=prototype-dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-dashboard.d.ts","sourceRoot":"","sources":["../../src/server/prototype-dashboard.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,MAAM,MAAM,8BAA8B,GAAG,MAAM,CACjD,MAAM,EACN,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAC9B,CAAC;AAEF,KAAK,0BAA0B,GAC3B,8BAA8B,GAC9B,OAAO,CAAC,8BAA8B,CAAC,GACvC,SAAS,CAAC;AAEd,KAAK,+BAA+B,GAAG;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;CACvD,CAAC;AAkDF,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,+BAA+B,mBAGvB,0BAA0B,KACxC,OAAO,CAAC,uBAAuB,CAAC,CAoBpC"}
@@ -0,0 +1,65 @@
1
+ import { connection } from "next/server.js";
2
+ import { definePrototypeRef, filterPrototypes, getPrototypeAuthorOptions, sortPrototypes, } from "@ebay-dt/bonfire-core";
3
+ const MAX_QUERY_VALUE_LENGTH = 128;
4
+ const VALID_SORTS = new Set([
5
+ "recent",
6
+ "alphabetical",
7
+ "deployed",
8
+ ]);
9
+ function singleQueryValue(value) {
10
+ if (typeof value !== "string")
11
+ return null;
12
+ if (value.length > MAX_QUERY_VALUE_LENGTH)
13
+ return null;
14
+ return value;
15
+ }
16
+ function normalizeSort(value) {
17
+ const scalar = singleQueryValue(value);
18
+ return scalar !== null &&
19
+ VALID_SORTS.has(scalar)
20
+ ? scalar
21
+ : "recent";
22
+ }
23
+ function normalizeAuthor(value, currentLogin) {
24
+ const scalar = singleQueryValue(value);
25
+ if (scalar === "all")
26
+ return "all";
27
+ if (scalar === "mine")
28
+ return currentLogin === null ? "all" : "mine";
29
+ if (scalar === null)
30
+ return "all";
31
+ try {
32
+ return definePrototypeRef({ login: scalar, slug: "prototype" }).login;
33
+ }
34
+ catch {
35
+ return "all";
36
+ }
37
+ }
38
+ async function normalizeSearchParams(searchParams, currentLogin) {
39
+ const params = (await searchParams) ?? {};
40
+ return {
41
+ author: normalizeAuthor(params.author, currentLogin),
42
+ sort: normalizeSort(params.sort),
43
+ };
44
+ }
45
+ export function createPrototypeDashboardModelLoader(options) {
46
+ return async function getDashboardModel(searchParams) {
47
+ await connection();
48
+ const [summaries, currentUser] = await Promise.all([
49
+ options.catalog.scan(),
50
+ options.production ? Promise.resolve(null) : options.getCurrentUser(),
51
+ ]);
52
+ const currentLogin = currentUser?.login ?? null;
53
+ const query = await normalizeSearchParams(searchParams, currentLogin);
54
+ const filtered = filterPrototypes(summaries, query.author, currentLogin);
55
+ const visibleSummaries = sortPrototypes(filtered, query.sort);
56
+ return {
57
+ applicationName: options.applicationName,
58
+ query,
59
+ authorOptions: getPrototypeAuthorOptions(summaries, currentLogin),
60
+ showMine: currentUser !== null,
61
+ summaries: visibleSummaries,
62
+ };
63
+ };
64
+ }
65
+ //# sourceMappingURL=prototype-dashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-dashboard.js","sourceRoot":"","sources":["../../src/server/prototype-dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,GAIf,MAAM,uBAAuB,CAAC;AAoB/B,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAgC;IACzD,QAAQ;IACR,cAAc;IACd,UAAU;CACX,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,sBAAsB;QAAE,OAAO,IAAI,CAAC;IACvD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO,MAAM,KAAK,IAAI;QACpB,WAAW,CAAC,GAAG,CAAC,MA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tE,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,WAAW,EAAE,KAAK,IAAI,IAAI,CAAC;QAChD,MAAM,KAAK,GAAG,MAAM,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QACtE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAE9D,OAAO;YACL,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,KAAK;YACL,aAAa,EAAE,yBAAyB,CAAC,SAAS,EAAE,YAAY,CAAC;YACjE,QAAQ,EAAE,WAAW,KAAK,IAAI;YAC9B,SAAS,EAAE,gBAAgB;SAC5B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { NextRequest } from "next/server.js";
2
+ import { type BonfireIdentity } from "@ebay-dt/bonfire-core";
3
+ import type { PrototypeLifecycle } from "@ebay-dt/bonfire-node";
4
+ import type { PrototypeWatcher } from "@ebay-dt/bonfire-node/watcher";
5
+ type PrototypeRouteOptions = {
6
+ production: boolean;
7
+ getCurrentUser: () => Promise<BonfireIdentity | null>;
8
+ lifecycle: PrototypeLifecycle | null;
9
+ getWatcher: () => Promise<PrototypeWatcher | null>;
10
+ };
11
+ export type PrototypeRoutes = {
12
+ dirty(request: NextRequest): Promise<Response>;
13
+ };
14
+ export declare function createPrototypeRoutes(options: PrototypeRouteOptions): PrototypeRoutes;
15
+ export {};
16
+ //# sourceMappingURL=prototype-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype-routes.d.ts","sourceRoot":"","sources":["../../src/server/prototype-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAItE,KAAK,qBAAqB,GAAG;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtD,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAChD,CAAC;AAoBF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,qBAAqB,GAC7B,eAAe,CA2GjB"}
@@ -0,0 +1,127 @@
1
+ import { definePrototypeRef, } from "@ebay-dt/bonfire-core";
2
+ const encoder = new TextEncoder();
3
+ function errorResponse(status) {
4
+ return new Response(null, {
5
+ status,
6
+ headers: { "Cache-Control": "no-store" },
7
+ });
8
+ }
9
+ function dirtyMessage(status) {
10
+ return encoder.encode(`data: ${JSON.stringify({ dirty: status === "dirty" })}\n\n`);
11
+ }
12
+ function queryValue(request, name) {
13
+ const values = request.nextUrl.searchParams.getAll(name);
14
+ return values.length === 1 ? values[0] : null;
15
+ }
16
+ export function createPrototypeRoutes(options) {
17
+ async function dirty(request) {
18
+ if (options.production)
19
+ return errorResponse(404);
20
+ const identity = await options.getCurrentUser();
21
+ if (identity === null)
22
+ return errorResponse(401);
23
+ const login = queryValue(request, "login");
24
+ const slug = queryValue(request, "slug");
25
+ if (login === null || slug === null)
26
+ return errorResponse(400);
27
+ let ref;
28
+ try {
29
+ ref = definePrototypeRef({ login, slug });
30
+ }
31
+ catch {
32
+ return errorResponse(400);
33
+ }
34
+ if (ref.login !== identity.login)
35
+ return errorResponse(403);
36
+ if (options.lifecycle === null)
37
+ return errorResponse(404);
38
+ let initial;
39
+ try {
40
+ initial = await options.lifecycle.getDirtyState(identity, { ref });
41
+ }
42
+ catch {
43
+ return errorResponse(500);
44
+ }
45
+ if (!initial.ok) {
46
+ switch (initial.error.code) {
47
+ case "unauthenticated":
48
+ return errorResponse(401);
49
+ case "forbidden":
50
+ return errorResponse(403);
51
+ case "invalid-input":
52
+ return errorResponse(400);
53
+ case "not-found":
54
+ return errorResponse(404);
55
+ default:
56
+ return errorResponse(500);
57
+ }
58
+ }
59
+ let watcher;
60
+ try {
61
+ watcher = await options.getWatcher();
62
+ }
63
+ catch {
64
+ return errorResponse(500);
65
+ }
66
+ if (watcher === null)
67
+ return errorResponse(404);
68
+ let closeStream = () => undefined;
69
+ const stream = new ReadableStream({
70
+ start(controller) {
71
+ let closed = false;
72
+ let unsubscribe = () => undefined;
73
+ const close = () => {
74
+ if (closed)
75
+ return;
76
+ closed = true;
77
+ unsubscribe();
78
+ request.signal.removeEventListener("abort", close);
79
+ try {
80
+ controller.close();
81
+ }
82
+ catch {
83
+ // The stream may already have been closed by the client.
84
+ }
85
+ };
86
+ closeStream = close;
87
+ request.signal.addEventListener("abort", close, { once: true });
88
+ if (request.signal.aborted) {
89
+ close();
90
+ return;
91
+ }
92
+ try {
93
+ controller.enqueue(dirtyMessage(initial.value.status));
94
+ unsubscribe = watcher.subscribe({
95
+ ref,
96
+ initial: initial.value,
97
+ onChange(value) {
98
+ if (closed)
99
+ return;
100
+ try {
101
+ controller.enqueue(dirtyMessage(value.status));
102
+ }
103
+ catch {
104
+ close();
105
+ }
106
+ },
107
+ });
108
+ }
109
+ catch {
110
+ close();
111
+ }
112
+ },
113
+ cancel() {
114
+ closeStream();
115
+ },
116
+ });
117
+ return new Response(stream, {
118
+ headers: {
119
+ "Cache-Control": "no-cache, no-store",
120
+ Connection: "keep-alive",
121
+ "Content-Type": "text/event-stream",
122
+ },
123
+ });
124
+ }
125
+ return { dirty };
126
+ }
127
+ //# sourceMappingURL=prototype-routes.js.map