@fragno-dev/cloudflare-fragment 0.0.1

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 (64) hide show
  1. package/LICENSE.md +16 -0
  2. package/README.md +92 -0
  3. package/dist/browser/client/react.d.ts +290 -0
  4. package/dist/browser/client/react.d.ts.map +1 -0
  5. package/dist/browser/client/react.js +166 -0
  6. package/dist/browser/client/react.js.map +1 -0
  7. package/dist/browser/client/solid.d.ts +292 -0
  8. package/dist/browser/client/solid.d.ts.map +1 -0
  9. package/dist/browser/client/solid.js +136 -0
  10. package/dist/browser/client/solid.js.map +1 -0
  11. package/dist/browser/client/svelte.d.ts +287 -0
  12. package/dist/browser/client/svelte.d.ts.map +1 -0
  13. package/dist/browser/client/svelte.js +134 -0
  14. package/dist/browser/client/svelte.js.map +1 -0
  15. package/dist/browser/client/vanilla.d.ts +316 -0
  16. package/dist/browser/client/vanilla.d.ts.map +1 -0
  17. package/dist/browser/client/vanilla.js +160 -0
  18. package/dist/browser/client/vanilla.js.map +1 -0
  19. package/dist/browser/client/vue.d.ts +290 -0
  20. package/dist/browser/client/vue.d.ts.map +1 -0
  21. package/dist/browser/client/vue.js +133 -0
  22. package/dist/browser/client/vue.js.map +1 -0
  23. package/dist/browser/client-Bk-J98pf.d.ts +679 -0
  24. package/dist/browser/client-Bk-J98pf.d.ts.map +1 -0
  25. package/dist/browser/index.d.ts +2027 -0
  26. package/dist/browser/index.d.ts.map +1 -0
  27. package/dist/browser/index.js +27 -0
  28. package/dist/browser/index.js.map +1 -0
  29. package/dist/browser/schema-Bt-h9kGf.js +2348 -0
  30. package/dist/browser/schema-Bt-h9kGf.js.map +1 -0
  31. package/dist/node/cloudflare-api.d.ts +106 -0
  32. package/dist/node/cloudflare-api.d.ts.map +1 -0
  33. package/dist/node/cloudflare-api.js +146 -0
  34. package/dist/node/cloudflare-api.js.map +1 -0
  35. package/dist/node/contracts.d.ts +288 -0
  36. package/dist/node/contracts.d.ts.map +1 -0
  37. package/dist/node/contracts.js +66 -0
  38. package/dist/node/contracts.js.map +1 -0
  39. package/dist/node/definition.d.ts +339 -0
  40. package/dist/node/definition.d.ts.map +1 -0
  41. package/dist/node/definition.js +417 -0
  42. package/dist/node/definition.js.map +1 -0
  43. package/dist/node/deployment-tag.d.ts +13 -0
  44. package/dist/node/deployment-tag.d.ts.map +1 -0
  45. package/dist/node/deployment-tag.js +73 -0
  46. package/dist/node/deployment-tag.js.map +1 -0
  47. package/dist/node/index.d.ts +786 -0
  48. package/dist/node/index.d.ts.map +1 -0
  49. package/dist/node/index.js +35 -0
  50. package/dist/node/index.js.map +1 -0
  51. package/dist/node/routes.d.ts +520 -0
  52. package/dist/node/routes.d.ts.map +1 -0
  53. package/dist/node/routes.js +100 -0
  54. package/dist/node/routes.js.map +1 -0
  55. package/dist/node/schema.d.ts +11 -0
  56. package/dist/node/schema.d.ts.map +1 -0
  57. package/dist/node/schema.js +24 -0
  58. package/dist/node/schema.js.map +1 -0
  59. package/dist/node/script-name.d.ts +13 -0
  60. package/dist/node/script-name.d.ts.map +1 -0
  61. package/dist/node/script-name.js +35 -0
  62. package/dist/node/script-name.js.map +1 -0
  63. package/dist/tsconfig.tsbuildinfo +1 -0
  64. package/package.json +98 -0
@@ -0,0 +1,106 @@
1
+ import Cloudflare, { ClientOptions } from "cloudflare";
2
+ import { ScriptUpdateParams, ScriptUpdateResponse } from "cloudflare/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts";
3
+
4
+ //#region src/cloudflare-api.d.ts
5
+ type CloudflareDispatchNamespaceBinding = {
6
+ get(name: string, args?: Record<string, unknown>, options?: unknown): unknown;
7
+ };
8
+ type CloudflareDispatchNamespaceDescriptor = {
9
+ binding: CloudflareDispatchNamespaceBinding;
10
+ namespace: string;
11
+ };
12
+ type CloudflareDispatcherConfig = string | CloudflareDispatchNamespaceDescriptor;
13
+ type CloudflareApiClientConfig = {
14
+ apiToken: string;
15
+ fetchImplementation?: ClientOptions["fetch"];
16
+ maxRetries?: number;
17
+ };
18
+ type CloudflareApiClient = Cloudflare;
19
+ type CloudflareScriptUpdateParams = ScriptUpdateParams;
20
+ type CloudflareScriptUpdateResponse = ScriptUpdateResponse;
21
+ type DeployCloudflareWorkerInput = {
22
+ accountId: string;
23
+ dispatchNamespace: string;
24
+ scriptName: string;
25
+ entrypoint: string;
26
+ moduleContent: string;
27
+ compatibilityDate: string;
28
+ compatibilityFlags: string[];
29
+ tags?: string[];
30
+ ifMatch?: string | null;
31
+ };
32
+ type ReconcileCloudflareWorkerDeploymentInput = {
33
+ accountId: string;
34
+ dispatchNamespace: string;
35
+ appId: string;
36
+ deploymentId: string;
37
+ expectedLiveEtag: string | null;
38
+ deploymentTagPrefix?: string;
39
+ scriptName: string;
40
+ entrypoint: string;
41
+ moduleContent: string;
42
+ compatibilityDate: string;
43
+ compatibilityFlags: string[];
44
+ scriptTags?: string[];
45
+ };
46
+ type CloudflareDeploymentReconciliationResult = {
47
+ action: "already-deployed";
48
+ deploymentTag: string;
49
+ currentDeploymentTag: string;
50
+ currentDeploymentId: string | null;
51
+ currentEtag: string | null;
52
+ currentModifiedOn: string | null;
53
+ } | {
54
+ action: "uploaded";
55
+ deploymentTag: string;
56
+ response: CloudflareScriptUpdateResponse;
57
+ } | {
58
+ action: "superseded";
59
+ deploymentTag: string;
60
+ currentDeploymentTag: string;
61
+ currentDeploymentId: string | null;
62
+ currentEtag: string | null;
63
+ currentModifiedOn: string | null;
64
+ };
65
+ type CloudflareCurrentDeployment = {
66
+ deploymentTag: string;
67
+ deploymentId: string | null;
68
+ } | null;
69
+ type CloudflareScriptState = {
70
+ etag: string | null;
71
+ modifiedOn: string | null;
72
+ } | null;
73
+ declare const resolveCloudflareDispatchNamespaceName: (dispatcher: CloudflareDispatcherConfig) => string;
74
+ declare const buildCloudflareScriptTags: (dynamicTags: string | string[], staticTags?: string[]) => string[];
75
+ declare const createCloudflareApiClient: ({
76
+ apiToken,
77
+ fetchImplementation,
78
+ maxRetries
79
+ }: CloudflareApiClientConfig) => CloudflareApiClient;
80
+ declare const listCloudflareScriptTags: (client: CloudflareApiClient, input: {
81
+ accountId: string;
82
+ dispatchNamespace: string;
83
+ scriptName: string;
84
+ }) => Promise<string[]>;
85
+ declare const getCloudflareCurrentDeployment: (client: CloudflareApiClient, input: {
86
+ accountId: string;
87
+ dispatchNamespace: string;
88
+ scriptName: string;
89
+ deploymentTagPrefix?: string;
90
+ }) => Promise<CloudflareCurrentDeployment>;
91
+ declare const getCloudflareScriptState: (client: CloudflareApiClient, input: {
92
+ accountId: string;
93
+ dispatchNamespace: string;
94
+ scriptName: string;
95
+ }) => Promise<CloudflareScriptState>;
96
+ declare const deployCloudflareWorker: (client: CloudflareApiClient, input: DeployCloudflareWorkerInput) => Promise<Cloudflare.WorkersForPlatforms.Dispatch.Namespaces.Scripts.ScriptUpdateResponse>;
97
+ declare const reconcileCloudflareWorkerDeployment: (client: CloudflareApiClient, input: ReconcileCloudflareWorkerDeploymentInput) => Promise<CloudflareDeploymentReconciliationResult>;
98
+ declare const getCloudflareApiError: (error: unknown) => {
99
+ status: any;
100
+ code: string;
101
+ message: string;
102
+ details: Record<string, unknown> | undefined;
103
+ } | null;
104
+ //#endregion
105
+ export { CloudflareApiClient, CloudflareCurrentDeployment, CloudflareDeploymentReconciliationResult, CloudflareDispatchNamespaceBinding, CloudflareDispatchNamespaceDescriptor, CloudflareDispatcherConfig, CloudflareScriptState, CloudflareScriptUpdateParams, CloudflareScriptUpdateResponse, DeployCloudflareWorkerInput, ReconcileCloudflareWorkerDeploymentInput, buildCloudflareScriptTags, createCloudflareApiClient, deployCloudflareWorker, getCloudflareApiError, getCloudflareCurrentDeployment, getCloudflareScriptState, listCloudflareScriptTags, reconcileCloudflareWorkerDeployment, resolveCloudflareDispatchNamespaceName };
106
+ //# sourceMappingURL=cloudflare-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-api.d.ts","names":[],"sources":["../../src/cloudflare-api.ts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A,UAAA;AAAA,MACD,OAAA;AAAA,cA0BU,8BAAA,GACX,MAAA,EAAQ,mBAAA,EACR,KAAA;EACE,SAAA;EACA,iBAAA;EACA,UAAA;EACA,mBAAA;AAAA,MAED,OAAA,CAAQ,2BAAA;AAAA,cAcE,wBAAA,GACX,MAAA,EAAQ,mBAAA,EACR,KAAA;EACE,SAAA;EACA,iBAAA;EACA,UAAA;AAAA,MAED,OAAA,CAAQ,qBAAA;AAAA,cAuBE,sBAAA,GACX,MAAA,EAAQ,mBAAA,EACR,KAAA,EAAO,2BAAA,KAA2B,OAAA,CAAA,UAAA,CAAA,mBAAA,CAAA,QAAA,CAAA,UAAA,CAAA,OAAA,CAAA,oBAAA;AAAA,cA+BvB,mCAAA,GACX,MAAA,EAAQ,mBAAA,EACR,KAAA,EAAO,wCAAA,KACN,OAAA,CAAQ,wCAAA;AAAA,cAmEE,qBAAA,GAAyB,KAAA;;;;WAerC,MAAA;AAAA"}
@@ -0,0 +1,146 @@
1
+ import { buildCloudflareAppTag, buildCloudflareDeploymentTag, findCloudflareDeploymentTag, getCloudflareDeploymentIdFromTag, sanitizeCloudflareTag } from "./deployment-tag.js";
2
+ import Cloudflare, { NotFoundError, toFile } from "cloudflare";
3
+
4
+ //#region src/cloudflare-api.ts
5
+ const isRecord = (value) => typeof value === "object" && value !== null;
6
+ const readNamespaceCandidate = (value) => {
7
+ if (typeof value !== "string") return null;
8
+ const trimmed = value.trim();
9
+ return trimmed.length > 0 ? trimmed : null;
10
+ };
11
+ const unique = (items) => {
12
+ return Array.from(new Set(items));
13
+ };
14
+ const hasBindingDescriptor = (value) => {
15
+ return typeof value === "object" && value !== null && "binding" in value;
16
+ };
17
+ const resolveCloudflareDispatchNamespaceName = (dispatcher) => {
18
+ if (typeof dispatcher === "string") {
19
+ const namespace = readNamespaceCandidate(dispatcher);
20
+ if (namespace) return namespace;
21
+ } else if (hasBindingDescriptor(dispatcher)) {
22
+ const namespace = readNamespaceCandidate(dispatcher.namespace);
23
+ if (namespace) return namespace;
24
+ }
25
+ throw new Error("Cloudflare fragment requires a dispatch namespace name. Pass `dispatcher: \"my-namespace\"` or `dispatcher: { binding: env.DISPATCHER, namespace: \"my-namespace\" }`.");
26
+ };
27
+ const buildCloudflareScriptTags = (dynamicTags, staticTags = []) => {
28
+ const normalizedDynamicTags = Array.isArray(dynamicTags) ? dynamicTags : [dynamicTags];
29
+ return unique([...staticTags, ...normalizedDynamicTags].map(sanitizeCloudflareTag).filter((tag) => tag.length > 0));
30
+ };
31
+ const createCloudflareApiClient = ({ apiToken, fetchImplementation, maxRetries = 0 }) => {
32
+ return new Cloudflare({
33
+ apiToken,
34
+ fetch: fetchImplementation,
35
+ maxRetries
36
+ });
37
+ };
38
+ const listCloudflareScriptTags = async (client, input) => {
39
+ try {
40
+ const tags = await client.workersForPlatforms.dispatch.namespaces.scripts.tags.list(input.dispatchNamespace, input.scriptName, { account_id: input.accountId });
41
+ const results = [];
42
+ for await (const tag of tags) results.push(tag);
43
+ return results;
44
+ } catch (error) {
45
+ if (error instanceof NotFoundError) return [];
46
+ throw error;
47
+ }
48
+ };
49
+ const getCloudflareCurrentDeployment = async (client, input) => {
50
+ const deploymentTag = findCloudflareDeploymentTag(await listCloudflareScriptTags(client, input), input.deploymentTagPrefix);
51
+ if (deploymentTag === null) return null;
52
+ return {
53
+ deploymentTag,
54
+ deploymentId: getCloudflareDeploymentIdFromTag(deploymentTag, input.deploymentTagPrefix)
55
+ };
56
+ };
57
+ const getCloudflareScriptState = async (client, input) => {
58
+ try {
59
+ const script = await client.workersForPlatforms.dispatch.namespaces.scripts.get(input.dispatchNamespace, input.scriptName, { account_id: input.accountId });
60
+ return {
61
+ etag: script.script?.etag ?? null,
62
+ modifiedOn: script.modified_on ?? null
63
+ };
64
+ } catch (error) {
65
+ if (error instanceof NotFoundError) return null;
66
+ throw error;
67
+ }
68
+ };
69
+ const deployCloudflareWorker = async (client, input) => {
70
+ const moduleFile = await toFile(new TextEncoder().encode(input.moduleContent), input.entrypoint, { type: "application/javascript+module" });
71
+ const params = {
72
+ account_id: input.accountId,
73
+ metadata: {
74
+ main_module: input.entrypoint,
75
+ compatibility_date: input.compatibilityDate,
76
+ compatibility_flags: input.compatibilityFlags.length > 0 ? input.compatibilityFlags : void 0,
77
+ tags: input.tags && input.tags.length > 0 ? input.tags : void 0
78
+ },
79
+ files: [moduleFile]
80
+ };
81
+ return await client.workersForPlatforms.dispatch.namespaces.scripts.update(input.dispatchNamespace, input.scriptName, params, input.ifMatch ? { headers: { "If-Match": input.ifMatch } } : void 0);
82
+ };
83
+ const reconcileCloudflareWorkerDeployment = async (client, input) => {
84
+ const appTag = buildCloudflareAppTag(input.appId, input.deploymentTagPrefix);
85
+ const deploymentTag = buildCloudflareDeploymentTag(input.deploymentId, input.deploymentTagPrefix);
86
+ try {
87
+ return {
88
+ action: "uploaded",
89
+ deploymentTag,
90
+ response: await deployCloudflareWorker(client, {
91
+ accountId: input.accountId,
92
+ dispatchNamespace: input.dispatchNamespace,
93
+ scriptName: input.scriptName,
94
+ entrypoint: input.entrypoint,
95
+ moduleContent: input.moduleContent,
96
+ compatibilityDate: input.compatibilityDate,
97
+ compatibilityFlags: input.compatibilityFlags,
98
+ tags: buildCloudflareScriptTags([appTag, deploymentTag], input.scriptTags),
99
+ ifMatch: input.expectedLiveEtag
100
+ })
101
+ };
102
+ } catch (error) {
103
+ if (getCloudflareApiError(error)?.status !== 412) throw error;
104
+ const [currentDeployment, scriptState] = await Promise.all([getCloudflareCurrentDeployment(client, {
105
+ accountId: input.accountId,
106
+ dispatchNamespace: input.dispatchNamespace,
107
+ scriptName: input.scriptName,
108
+ deploymentTagPrefix: input.deploymentTagPrefix
109
+ }), getCloudflareScriptState(client, {
110
+ accountId: input.accountId,
111
+ dispatchNamespace: input.dispatchNamespace,
112
+ scriptName: input.scriptName
113
+ })]);
114
+ if (currentDeployment?.deploymentTag === deploymentTag) return {
115
+ action: "already-deployed",
116
+ deploymentTag,
117
+ currentDeploymentTag: currentDeployment.deploymentTag,
118
+ currentDeploymentId: currentDeployment.deploymentId,
119
+ currentEtag: scriptState?.etag ?? null,
120
+ currentModifiedOn: scriptState?.modifiedOn ?? null
121
+ };
122
+ if (currentDeployment !== null) return {
123
+ action: "superseded",
124
+ deploymentTag,
125
+ currentDeploymentTag: currentDeployment.deploymentTag,
126
+ currentDeploymentId: currentDeployment.deploymentId,
127
+ currentEtag: scriptState?.etag ?? null,
128
+ currentModifiedOn: scriptState?.modifiedOn ?? null
129
+ };
130
+ throw error;
131
+ }
132
+ };
133
+ const getCloudflareApiError = (error) => {
134
+ if (!(error instanceof Cloudflare.APIError)) return null;
135
+ const [firstError] = error.errors;
136
+ return {
137
+ status: error.status,
138
+ code: firstError?.code === void 0 || firstError?.code === null ? error.name : String(firstError.code),
139
+ message: firstError?.message ?? error.message,
140
+ details: isRecord(error.error) ? error.error : void 0
141
+ };
142
+ };
143
+
144
+ //#endregion
145
+ export { buildCloudflareScriptTags, createCloudflareApiClient, deployCloudflareWorker, getCloudflareApiError, getCloudflareCurrentDeployment, getCloudflareScriptState, listCloudflareScriptTags, reconcileCloudflareWorkerDeployment, resolveCloudflareDispatchNamespaceName };
146
+ //# sourceMappingURL=cloudflare-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare-api.js","names":[],"sources":["../../src/cloudflare-api.ts"],"sourcesContent":["import Cloudflare, {\n NotFoundError,\n toFile,\n type ClientOptions as CloudflareClientOptions,\n} from \"cloudflare\";\nimport type {\n ScriptUpdateParams,\n ScriptUpdateResponse,\n} from \"cloudflare/resources/workers-for-platforms/dispatch/namespaces/scripts/scripts\";\n\nimport {\n buildCloudflareAppTag,\n buildCloudflareDeploymentTag,\n findCloudflareDeploymentTag,\n getCloudflareDeploymentIdFromTag,\n sanitizeCloudflareTag,\n} from \"./deployment-tag\";\n\nexport type CloudflareDispatchNamespaceBinding = {\n get(name: string, args?: Record<string, unknown>, options?: unknown): unknown;\n};\n\nexport type CloudflareDispatchNamespaceDescriptor = {\n binding: CloudflareDispatchNamespaceBinding;\n namespace: string;\n};\n\nexport type CloudflareDispatcherConfig = string | CloudflareDispatchNamespaceDescriptor;\n\ntype CloudflareApiClientConfig = {\n apiToken: string;\n fetchImplementation?: CloudflareClientOptions[\"fetch\"];\n maxRetries?: number;\n};\n\nexport type CloudflareApiClient = Cloudflare;\nexport type CloudflareScriptUpdateParams = ScriptUpdateParams;\nexport type CloudflareScriptUpdateResponse = ScriptUpdateResponse;\n\nexport type DeployCloudflareWorkerInput = {\n accountId: string;\n dispatchNamespace: string;\n scriptName: string;\n entrypoint: string;\n moduleContent: string;\n compatibilityDate: string;\n compatibilityFlags: string[];\n tags?: string[];\n ifMatch?: string | null;\n};\n\nexport type ReconcileCloudflareWorkerDeploymentInput = {\n accountId: string;\n dispatchNamespace: string;\n appId: string;\n deploymentId: string;\n expectedLiveEtag: string | null;\n deploymentTagPrefix?: string;\n scriptName: string;\n entrypoint: string;\n moduleContent: string;\n compatibilityDate: string;\n compatibilityFlags: string[];\n scriptTags?: string[];\n};\n\nexport type CloudflareDeploymentReconciliationResult =\n | {\n action: \"already-deployed\";\n deploymentTag: string;\n currentDeploymentTag: string;\n currentDeploymentId: string | null;\n currentEtag: string | null;\n currentModifiedOn: string | null;\n }\n | {\n action: \"uploaded\";\n deploymentTag: string;\n response: CloudflareScriptUpdateResponse;\n }\n | {\n action: \"superseded\";\n deploymentTag: string;\n currentDeploymentTag: string;\n currentDeploymentId: string | null;\n currentEtag: string | null;\n currentModifiedOn: string | null;\n };\n\nexport type CloudflareCurrentDeployment = {\n deploymentTag: string;\n deploymentId: string | null;\n} | null;\n\nexport type CloudflareScriptState = {\n etag: string | null;\n modifiedOn: string | null;\n} | null;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst readNamespaceCandidate = (value: unknown) => {\n if (typeof value !== \"string\") {\n return null;\n }\n\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : null;\n};\n\nconst unique = <T>(items: T[]) => {\n return Array.from(new Set(items));\n};\n\nconst hasBindingDescriptor = (\n value: CloudflareDispatcherConfig,\n): value is CloudflareDispatchNamespaceDescriptor => {\n return typeof value === \"object\" && value !== null && \"binding\" in value;\n};\n\nexport const resolveCloudflareDispatchNamespaceName = (dispatcher: CloudflareDispatcherConfig) => {\n if (typeof dispatcher === \"string\") {\n const namespace = readNamespaceCandidate(dispatcher);\n if (namespace) {\n return namespace;\n }\n } else if (hasBindingDescriptor(dispatcher)) {\n const namespace = readNamespaceCandidate(dispatcher.namespace);\n if (namespace) {\n return namespace;\n }\n }\n\n throw new Error(\n 'Cloudflare fragment requires a dispatch namespace name. Pass `dispatcher: \"my-namespace\"` or `dispatcher: { binding: env.DISPATCHER, namespace: \"my-namespace\" }`.',\n );\n};\n\nexport const buildCloudflareScriptTags = (\n dynamicTags: string | string[],\n staticTags: string[] = [],\n) => {\n const normalizedDynamicTags = Array.isArray(dynamicTags) ? dynamicTags : [dynamicTags];\n\n return unique(\n [...staticTags, ...normalizedDynamicTags]\n .map(sanitizeCloudflareTag)\n .filter((tag) => tag.length > 0),\n );\n};\n\nexport const createCloudflareApiClient = ({\n apiToken,\n fetchImplementation,\n maxRetries = 0,\n}: CloudflareApiClientConfig): CloudflareApiClient => {\n return new Cloudflare({\n apiToken,\n fetch: fetchImplementation,\n maxRetries,\n });\n};\n\nexport const listCloudflareScriptTags = async (\n client: CloudflareApiClient,\n input: {\n accountId: string;\n dispatchNamespace: string;\n scriptName: string;\n },\n) => {\n try {\n const tags = await client.workersForPlatforms.dispatch.namespaces.scripts.tags.list(\n input.dispatchNamespace,\n input.scriptName,\n {\n account_id: input.accountId,\n },\n );\n const results: string[] = [];\n\n for await (const tag of tags) {\n results.push(tag);\n }\n\n return results;\n } catch (error) {\n if (error instanceof NotFoundError) {\n return [];\n }\n\n throw error;\n }\n};\n\nexport const getCloudflareCurrentDeployment = async (\n client: CloudflareApiClient,\n input: {\n accountId: string;\n dispatchNamespace: string;\n scriptName: string;\n deploymentTagPrefix?: string;\n },\n): Promise<CloudflareCurrentDeployment> => {\n const remoteTags = await listCloudflareScriptTags(client, input);\n const deploymentTag = findCloudflareDeploymentTag(remoteTags, input.deploymentTagPrefix);\n\n if (deploymentTag === null) {\n return null;\n }\n\n return {\n deploymentTag,\n deploymentId: getCloudflareDeploymentIdFromTag(deploymentTag, input.deploymentTagPrefix),\n };\n};\n\nexport const getCloudflareScriptState = async (\n client: CloudflareApiClient,\n input: {\n accountId: string;\n dispatchNamespace: string;\n scriptName: string;\n },\n): Promise<CloudflareScriptState> => {\n try {\n const script = await client.workersForPlatforms.dispatch.namespaces.scripts.get(\n input.dispatchNamespace,\n input.scriptName,\n {\n account_id: input.accountId,\n },\n );\n\n return {\n etag: script.script?.etag ?? null,\n modifiedOn: script.modified_on ?? null,\n };\n } catch (error) {\n if (error instanceof NotFoundError) {\n return null;\n }\n\n throw error;\n }\n};\n\nexport const deployCloudflareWorker = async (\n client: CloudflareApiClient,\n input: DeployCloudflareWorkerInput,\n) => {\n const moduleFile = await toFile(new TextEncoder().encode(input.moduleContent), input.entrypoint, {\n type: \"application/javascript+module\",\n });\n const params: CloudflareScriptUpdateParams = {\n account_id: input.accountId,\n metadata: {\n main_module: input.entrypoint,\n compatibility_date: input.compatibilityDate,\n compatibility_flags:\n input.compatibilityFlags.length > 0 ? input.compatibilityFlags : undefined,\n tags: input.tags && input.tags.length > 0 ? input.tags : undefined,\n },\n files: [moduleFile],\n };\n\n return await client.workersForPlatforms.dispatch.namespaces.scripts.update(\n input.dispatchNamespace,\n input.scriptName,\n params,\n input.ifMatch\n ? {\n headers: {\n \"If-Match\": input.ifMatch,\n },\n }\n : undefined,\n );\n};\n\nexport const reconcileCloudflareWorkerDeployment = async (\n client: CloudflareApiClient,\n input: ReconcileCloudflareWorkerDeploymentInput,\n): Promise<CloudflareDeploymentReconciliationResult> => {\n const appTag = buildCloudflareAppTag(input.appId, input.deploymentTagPrefix);\n const deploymentTag = buildCloudflareDeploymentTag(input.deploymentId, input.deploymentTagPrefix);\n try {\n const response = await deployCloudflareWorker(client, {\n accountId: input.accountId,\n dispatchNamespace: input.dispatchNamespace,\n scriptName: input.scriptName,\n entrypoint: input.entrypoint,\n moduleContent: input.moduleContent,\n compatibilityDate: input.compatibilityDate,\n compatibilityFlags: input.compatibilityFlags,\n tags: buildCloudflareScriptTags([appTag, deploymentTag], input.scriptTags),\n ifMatch: input.expectedLiveEtag,\n });\n\n return {\n action: \"uploaded\",\n deploymentTag,\n response,\n };\n } catch (error) {\n const cloudflareError = getCloudflareApiError(error);\n if (cloudflareError?.status !== 412) {\n throw error;\n }\n\n const [currentDeployment, scriptState] = await Promise.all([\n getCloudflareCurrentDeployment(client, {\n accountId: input.accountId,\n dispatchNamespace: input.dispatchNamespace,\n scriptName: input.scriptName,\n deploymentTagPrefix: input.deploymentTagPrefix,\n }),\n getCloudflareScriptState(client, {\n accountId: input.accountId,\n dispatchNamespace: input.dispatchNamespace,\n scriptName: input.scriptName,\n }),\n ]);\n\n if (currentDeployment?.deploymentTag === deploymentTag) {\n return {\n action: \"already-deployed\",\n deploymentTag,\n currentDeploymentTag: currentDeployment.deploymentTag,\n currentDeploymentId: currentDeployment.deploymentId,\n currentEtag: scriptState?.etag ?? null,\n currentModifiedOn: scriptState?.modifiedOn ?? null,\n };\n }\n\n if (currentDeployment !== null) {\n return {\n action: \"superseded\",\n deploymentTag,\n currentDeploymentTag: currentDeployment.deploymentTag,\n currentDeploymentId: currentDeployment.deploymentId,\n currentEtag: scriptState?.etag ?? null,\n currentModifiedOn: scriptState?.modifiedOn ?? null,\n };\n }\n\n throw error;\n }\n};\n\nexport const getCloudflareApiError = (error: unknown) => {\n if (!(error instanceof Cloudflare.APIError)) {\n return null;\n }\n\n const [firstError] = error.errors;\n return {\n status: error.status,\n code:\n firstError?.code === undefined || firstError?.code === null\n ? error.name\n : String(firstError.code),\n message: firstError?.message ?? error.message,\n details: isRecord(error.error) ? error.error : undefined,\n };\n};\n"],"m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"zod";
2
+
3
+ //#region src/contracts.d.ts
4
+ declare const SUPPORTED_DEPLOYMENT_FORMAT = "esmodule";
5
+ declare const DEFAULT_DEPLOYMENT_ENTRYPOINT = "index.mjs";
6
+ declare const cloudflareDeploymentStatusSchema: z.ZodEnum<{
7
+ queued: "queued";
8
+ deploying: "deploying";
9
+ succeeded: "succeeded";
10
+ failed: "failed";
11
+ }>;
12
+ declare const cloudflareDeployScriptSchema: z.ZodObject<{
13
+ type: z.ZodDefault<z.ZodEnum<{
14
+ esmodule: "esmodule";
15
+ }>>;
16
+ entrypoint: z.ZodDefault<z.ZodString>;
17
+ content: z.ZodString;
18
+ }, z.core.$strip>;
19
+ declare const cloudflareDeployRequestSchema: z.ZodObject<{
20
+ script: z.ZodObject<{
21
+ type: z.ZodDefault<z.ZodEnum<{
22
+ esmodule: "esmodule";
23
+ }>>;
24
+ entrypoint: z.ZodDefault<z.ZodString>;
25
+ content: z.ZodString;
26
+ }, z.core.$strip>;
27
+ compatibilityDate: z.ZodOptional<z.ZodString>;
28
+ compatibilityFlags: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ }, z.core.$strip>;
30
+ declare const cloudflareDeploymentSummarySchema: z.ZodObject<{
31
+ id: z.ZodString;
32
+ appId: z.ZodString;
33
+ scriptName: z.ZodString;
34
+ status: z.ZodEnum<{
35
+ queued: "queued";
36
+ deploying: "deploying";
37
+ succeeded: "succeeded";
38
+ failed: "failed";
39
+ }>;
40
+ format: z.ZodLiteral<"esmodule">;
41
+ entrypoint: z.ZodString;
42
+ sourceByteLength: z.ZodNumber;
43
+ compatibilityDate: z.ZodString;
44
+ compatibilityFlags: z.ZodArray<z.ZodString>;
45
+ attemptCount: z.ZodNumber;
46
+ queuedAt: z.ZodString;
47
+ startedAt: z.ZodNullable<z.ZodString>;
48
+ completedAt: z.ZodNullable<z.ZodString>;
49
+ errorCode: z.ZodNullable<z.ZodString>;
50
+ errorMessage: z.ZodNullable<z.ZodString>;
51
+ cloudflare: z.ZodNullable<z.ZodObject<{
52
+ etag: z.ZodNullable<z.ZodString>;
53
+ modifiedOn: z.ZodNullable<z.ZodString>;
54
+ }, z.core.$strip>>;
55
+ createdAt: z.ZodString;
56
+ updatedAt: z.ZodString;
57
+ }, z.core.$strip>;
58
+ declare const cloudflareDeploymentDetailSchema: z.ZodObject<{
59
+ id: z.ZodString;
60
+ appId: z.ZodString;
61
+ scriptName: z.ZodString;
62
+ status: z.ZodEnum<{
63
+ queued: "queued";
64
+ deploying: "deploying";
65
+ succeeded: "succeeded";
66
+ failed: "failed";
67
+ }>;
68
+ format: z.ZodLiteral<"esmodule">;
69
+ entrypoint: z.ZodString;
70
+ sourceByteLength: z.ZodNumber;
71
+ compatibilityDate: z.ZodString;
72
+ compatibilityFlags: z.ZodArray<z.ZodString>;
73
+ attemptCount: z.ZodNumber;
74
+ queuedAt: z.ZodString;
75
+ startedAt: z.ZodNullable<z.ZodString>;
76
+ completedAt: z.ZodNullable<z.ZodString>;
77
+ errorCode: z.ZodNullable<z.ZodString>;
78
+ errorMessage: z.ZodNullable<z.ZodString>;
79
+ cloudflare: z.ZodNullable<z.ZodObject<{
80
+ etag: z.ZodNullable<z.ZodString>;
81
+ modifiedOn: z.ZodNullable<z.ZodString>;
82
+ }, z.core.$strip>>;
83
+ createdAt: z.ZodString;
84
+ updatedAt: z.ZodString;
85
+ sourceCode: z.ZodString;
86
+ }, z.core.$strip>;
87
+ declare const cloudflareAppSummarySchema: z.ZodObject<{
88
+ id: z.ZodString;
89
+ scriptName: z.ZodString;
90
+ latestDeployment: z.ZodNullable<z.ZodObject<{
91
+ id: z.ZodString;
92
+ appId: z.ZodString;
93
+ scriptName: z.ZodString;
94
+ status: z.ZodEnum<{
95
+ queued: "queued";
96
+ deploying: "deploying";
97
+ succeeded: "succeeded";
98
+ failed: "failed";
99
+ }>;
100
+ format: z.ZodLiteral<"esmodule">;
101
+ entrypoint: z.ZodString;
102
+ sourceByteLength: z.ZodNumber;
103
+ compatibilityDate: z.ZodString;
104
+ compatibilityFlags: z.ZodArray<z.ZodString>;
105
+ attemptCount: z.ZodNumber;
106
+ queuedAt: z.ZodString;
107
+ startedAt: z.ZodNullable<z.ZodString>;
108
+ completedAt: z.ZodNullable<z.ZodString>;
109
+ errorCode: z.ZodNullable<z.ZodString>;
110
+ errorMessage: z.ZodNullable<z.ZodString>;
111
+ cloudflare: z.ZodNullable<z.ZodObject<{
112
+ etag: z.ZodNullable<z.ZodString>;
113
+ modifiedOn: z.ZodNullable<z.ZodString>;
114
+ }, z.core.$strip>>;
115
+ createdAt: z.ZodString;
116
+ updatedAt: z.ZodString;
117
+ }, z.core.$strip>>;
118
+ createdAt: z.ZodString;
119
+ updatedAt: z.ZodString;
120
+ }, z.core.$strip>;
121
+ declare const cloudflareAppStateSchema: z.ZodObject<{
122
+ id: z.ZodString;
123
+ scriptName: z.ZodString;
124
+ latestDeployment: z.ZodNullable<z.ZodObject<{
125
+ id: z.ZodString;
126
+ appId: z.ZodString;
127
+ scriptName: z.ZodString;
128
+ status: z.ZodEnum<{
129
+ queued: "queued";
130
+ deploying: "deploying";
131
+ succeeded: "succeeded";
132
+ failed: "failed";
133
+ }>;
134
+ format: z.ZodLiteral<"esmodule">;
135
+ entrypoint: z.ZodString;
136
+ sourceByteLength: z.ZodNumber;
137
+ compatibilityDate: z.ZodString;
138
+ compatibilityFlags: z.ZodArray<z.ZodString>;
139
+ attemptCount: z.ZodNumber;
140
+ queuedAt: z.ZodString;
141
+ startedAt: z.ZodNullable<z.ZodString>;
142
+ completedAt: z.ZodNullable<z.ZodString>;
143
+ errorCode: z.ZodNullable<z.ZodString>;
144
+ errorMessage: z.ZodNullable<z.ZodString>;
145
+ cloudflare: z.ZodNullable<z.ZodObject<{
146
+ etag: z.ZodNullable<z.ZodString>;
147
+ modifiedOn: z.ZodNullable<z.ZodString>;
148
+ }, z.core.$strip>>;
149
+ createdAt: z.ZodString;
150
+ updatedAt: z.ZodString;
151
+ }, z.core.$strip>>;
152
+ createdAt: z.ZodString;
153
+ updatedAt: z.ZodString;
154
+ liveDeployment: z.ZodNullable<z.ZodObject<{
155
+ id: z.ZodString;
156
+ appId: z.ZodString;
157
+ scriptName: z.ZodString;
158
+ status: z.ZodEnum<{
159
+ queued: "queued";
160
+ deploying: "deploying";
161
+ succeeded: "succeeded";
162
+ failed: "failed";
163
+ }>;
164
+ format: z.ZodLiteral<"esmodule">;
165
+ entrypoint: z.ZodString;
166
+ sourceByteLength: z.ZodNumber;
167
+ compatibilityDate: z.ZodString;
168
+ compatibilityFlags: z.ZodArray<z.ZodString>;
169
+ attemptCount: z.ZodNumber;
170
+ queuedAt: z.ZodString;
171
+ startedAt: z.ZodNullable<z.ZodString>;
172
+ completedAt: z.ZodNullable<z.ZodString>;
173
+ errorCode: z.ZodNullable<z.ZodString>;
174
+ errorMessage: z.ZodNullable<z.ZodString>;
175
+ cloudflare: z.ZodNullable<z.ZodObject<{
176
+ etag: z.ZodNullable<z.ZodString>;
177
+ modifiedOn: z.ZodNullable<z.ZodString>;
178
+ }, z.core.$strip>>;
179
+ createdAt: z.ZodString;
180
+ updatedAt: z.ZodString;
181
+ }, z.core.$strip>>;
182
+ liveDeploymentError: z.ZodNullable<z.ZodString>;
183
+ deployments: z.ZodArray<z.ZodObject<{
184
+ id: z.ZodString;
185
+ appId: z.ZodString;
186
+ scriptName: z.ZodString;
187
+ status: z.ZodEnum<{
188
+ queued: "queued";
189
+ deploying: "deploying";
190
+ succeeded: "succeeded";
191
+ failed: "failed";
192
+ }>;
193
+ format: z.ZodLiteral<"esmodule">;
194
+ entrypoint: z.ZodString;
195
+ sourceByteLength: z.ZodNumber;
196
+ compatibilityDate: z.ZodString;
197
+ compatibilityFlags: z.ZodArray<z.ZodString>;
198
+ attemptCount: z.ZodNumber;
199
+ queuedAt: z.ZodString;
200
+ startedAt: z.ZodNullable<z.ZodString>;
201
+ completedAt: z.ZodNullable<z.ZodString>;
202
+ errorCode: z.ZodNullable<z.ZodString>;
203
+ errorMessage: z.ZodNullable<z.ZodString>;
204
+ cloudflare: z.ZodNullable<z.ZodObject<{
205
+ etag: z.ZodNullable<z.ZodString>;
206
+ modifiedOn: z.ZodNullable<z.ZodString>;
207
+ }, z.core.$strip>>;
208
+ createdAt: z.ZodString;
209
+ updatedAt: z.ZodString;
210
+ }, z.core.$strip>>;
211
+ }, z.core.$strip>;
212
+ declare const cloudflareAppListSchema: z.ZodObject<{
213
+ apps: z.ZodArray<z.ZodObject<{
214
+ id: z.ZodString;
215
+ scriptName: z.ZodString;
216
+ latestDeployment: z.ZodNullable<z.ZodObject<{
217
+ id: z.ZodString;
218
+ appId: z.ZodString;
219
+ scriptName: z.ZodString;
220
+ status: z.ZodEnum<{
221
+ queued: "queued";
222
+ deploying: "deploying";
223
+ succeeded: "succeeded";
224
+ failed: "failed";
225
+ }>;
226
+ format: z.ZodLiteral<"esmodule">;
227
+ entrypoint: z.ZodString;
228
+ sourceByteLength: z.ZodNumber;
229
+ compatibilityDate: z.ZodString;
230
+ compatibilityFlags: z.ZodArray<z.ZodString>;
231
+ attemptCount: z.ZodNumber;
232
+ queuedAt: z.ZodString;
233
+ startedAt: z.ZodNullable<z.ZodString>;
234
+ completedAt: z.ZodNullable<z.ZodString>;
235
+ errorCode: z.ZodNullable<z.ZodString>;
236
+ errorMessage: z.ZodNullable<z.ZodString>;
237
+ cloudflare: z.ZodNullable<z.ZodObject<{
238
+ etag: z.ZodNullable<z.ZodString>;
239
+ modifiedOn: z.ZodNullable<z.ZodString>;
240
+ }, z.core.$strip>>;
241
+ createdAt: z.ZodString;
242
+ updatedAt: z.ZodString;
243
+ }, z.core.$strip>>;
244
+ createdAt: z.ZodString;
245
+ updatedAt: z.ZodString;
246
+ }, z.core.$strip>>;
247
+ }, z.core.$strip>;
248
+ declare const cloudflareDeploymentListSchema: z.ZodObject<{
249
+ deployments: z.ZodArray<z.ZodObject<{
250
+ id: z.ZodString;
251
+ appId: z.ZodString;
252
+ scriptName: z.ZodString;
253
+ status: z.ZodEnum<{
254
+ queued: "queued";
255
+ deploying: "deploying";
256
+ succeeded: "succeeded";
257
+ failed: "failed";
258
+ }>;
259
+ format: z.ZodLiteral<"esmodule">;
260
+ entrypoint: z.ZodString;
261
+ sourceByteLength: z.ZodNumber;
262
+ compatibilityDate: z.ZodString;
263
+ compatibilityFlags: z.ZodArray<z.ZodString>;
264
+ attemptCount: z.ZodNumber;
265
+ queuedAt: z.ZodString;
266
+ startedAt: z.ZodNullable<z.ZodString>;
267
+ completedAt: z.ZodNullable<z.ZodString>;
268
+ errorCode: z.ZodNullable<z.ZodString>;
269
+ errorMessage: z.ZodNullable<z.ZodString>;
270
+ cloudflare: z.ZodNullable<z.ZodObject<{
271
+ etag: z.ZodNullable<z.ZodString>;
272
+ modifiedOn: z.ZodNullable<z.ZodString>;
273
+ }, z.core.$strip>>;
274
+ createdAt: z.ZodString;
275
+ updatedAt: z.ZodString;
276
+ }, z.core.$strip>>;
277
+ }, z.core.$strip>;
278
+ type CloudflareDeploymentStatus = z.infer<typeof cloudflareDeploymentStatusSchema>;
279
+ type CloudflareDeployRequest = z.infer<typeof cloudflareDeployRequestSchema>;
280
+ type CloudflareDeploymentSummary = z.infer<typeof cloudflareDeploymentSummarySchema>;
281
+ type CloudflareDeploymentDetail = z.infer<typeof cloudflareDeploymentDetailSchema>;
282
+ type CloudflareAppSummary = z.infer<typeof cloudflareAppSummarySchema>;
283
+ type CloudflareAppState = z.infer<typeof cloudflareAppStateSchema>;
284
+ type CloudflareAppList = z.infer<typeof cloudflareAppListSchema>;
285
+ type CloudflareDeploymentList = z.infer<typeof cloudflareDeploymentListSchema>;
286
+ //#endregion
287
+ export { CloudflareAppList, CloudflareAppState, CloudflareAppSummary, CloudflareDeployRequest, CloudflareDeploymentDetail, CloudflareDeploymentList, CloudflareDeploymentStatus, CloudflareDeploymentSummary, DEFAULT_DEPLOYMENT_ENTRYPOINT, SUPPORTED_DEPLOYMENT_FORMAT, cloudflareAppListSchema, cloudflareAppStateSchema, cloudflareAppSummarySchema, cloudflareDeployRequestSchema, cloudflareDeployScriptSchema, cloudflareDeploymentDetailSchema, cloudflareDeploymentListSchema, cloudflareDeploymentStatusSchema, cloudflareDeploymentSummarySchema };
288
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","names":[],"sources":["../../src/contracts.ts"],"mappings":";;;cAEa,2BAAA;AAAA,cACA,6BAAA;AAAA,cAMA,gCAAA,EAAgC,CAAA,CAAA,OAAA;;;;;;cAOhC,4BAAA,EAA4B,CAAA,CAAA,SAAA;;;;;;;cAM5B,6BAAA,EAA6B,CAAA,CAAA,SAAA;;;;;;;;;;;cAa7B,iCAAA,EAAiC,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqBjC,gCAAA,EAAgC,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAIhC,0BAAA,EAA0B,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAQ1B,wBAAA,EAAwB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAMxB,uBAAA,EAAuB,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAIvB,8BAAA,EAA8B,CAAA,CAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAI/B,0BAAA,GAA6B,CAAA,CAAE,KAAA,QAAa,gCAAA;AAAA,KAC5C,uBAAA,GAA0B,CAAA,CAAE,KAAA,QAAa,6BAAA;AAAA,KACzC,2BAAA,GAA8B,CAAA,CAAE,KAAA,QAAa,iCAAA;AAAA,KAC7C,0BAAA,GAA6B,CAAA,CAAE,KAAA,QAAa,gCAAA;AAAA,KAC5C,oBAAA,GAAuB,CAAA,CAAE,KAAA,QAAa,0BAAA;AAAA,KACtC,kBAAA,GAAqB,CAAA,CAAE,KAAA,QAAa,wBAAA;AAAA,KACpC,iBAAA,GAAoB,CAAA,CAAE,KAAA,QAAa,uBAAA;AAAA,KACnC,wBAAA,GAA2B,CAAA,CAAE,KAAA,QAAa,8BAAA"}
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/contracts.ts
4
+ const SUPPORTED_DEPLOYMENT_FORMAT = "esmodule";
5
+ const DEFAULT_DEPLOYMENT_ENTRYPOINT = "index.mjs";
6
+ const cloudflareCompatibilityDateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "compatibilityDate must use YYYY-MM-DD.");
7
+ const cloudflareDeploymentStatusSchema = z.enum([
8
+ "queued",
9
+ "deploying",
10
+ "succeeded",
11
+ "failed"
12
+ ]);
13
+ const cloudflareDeployScriptSchema = z.object({
14
+ type: z.enum([SUPPORTED_DEPLOYMENT_FORMAT]).default(SUPPORTED_DEPLOYMENT_FORMAT),
15
+ entrypoint: z.string().trim().min(1).default(DEFAULT_DEPLOYMENT_ENTRYPOINT),
16
+ content: z.string()
17
+ });
18
+ const cloudflareDeployRequestSchema = z.object({
19
+ script: cloudflareDeployScriptSchema,
20
+ compatibilityDate: cloudflareCompatibilityDateSchema.optional(),
21
+ compatibilityFlags: z.array(z.string().min(1)).optional()
22
+ });
23
+ const cloudflareTimestampSchema = z.string().datetime({ offset: true });
24
+ const cloudflareProviderSummarySchema = z.object({
25
+ etag: z.string().nullable(),
26
+ modifiedOn: cloudflareTimestampSchema.nullable()
27
+ });
28
+ const cloudflareDeploymentSummarySchema = z.object({
29
+ id: z.string(),
30
+ appId: z.string(),
31
+ scriptName: z.string(),
32
+ status: cloudflareDeploymentStatusSchema,
33
+ format: z.literal(SUPPORTED_DEPLOYMENT_FORMAT),
34
+ entrypoint: z.string(),
35
+ sourceByteLength: z.number().int().nonnegative(),
36
+ compatibilityDate: cloudflareCompatibilityDateSchema,
37
+ compatibilityFlags: z.array(z.string()),
38
+ attemptCount: z.number().int().nonnegative(),
39
+ queuedAt: cloudflareTimestampSchema,
40
+ startedAt: cloudflareTimestampSchema.nullable(),
41
+ completedAt: cloudflareTimestampSchema.nullable(),
42
+ errorCode: z.string().nullable(),
43
+ errorMessage: z.string().nullable(),
44
+ cloudflare: cloudflareProviderSummarySchema.nullable(),
45
+ createdAt: cloudflareTimestampSchema,
46
+ updatedAt: cloudflareTimestampSchema
47
+ });
48
+ const cloudflareDeploymentDetailSchema = cloudflareDeploymentSummarySchema.extend({ sourceCode: z.string() });
49
+ const cloudflareAppSummarySchema = z.object({
50
+ id: z.string(),
51
+ scriptName: z.string(),
52
+ latestDeployment: cloudflareDeploymentSummarySchema.nullable(),
53
+ createdAt: cloudflareTimestampSchema,
54
+ updatedAt: cloudflareTimestampSchema
55
+ });
56
+ const cloudflareAppStateSchema = cloudflareAppSummarySchema.extend({
57
+ liveDeployment: cloudflareDeploymentSummarySchema.nullable(),
58
+ liveDeploymentError: z.string().nullable(),
59
+ deployments: z.array(cloudflareDeploymentSummarySchema)
60
+ });
61
+ const cloudflareAppListSchema = z.object({ apps: z.array(cloudflareAppSummarySchema) });
62
+ const cloudflareDeploymentListSchema = z.object({ deployments: z.array(cloudflareDeploymentSummarySchema) });
63
+
64
+ //#endregion
65
+ export { DEFAULT_DEPLOYMENT_ENTRYPOINT, SUPPORTED_DEPLOYMENT_FORMAT, cloudflareAppListSchema, cloudflareAppStateSchema, cloudflareAppSummarySchema, cloudflareDeployRequestSchema, cloudflareDeployScriptSchema, cloudflareDeploymentDetailSchema, cloudflareDeploymentListSchema, cloudflareDeploymentStatusSchema, cloudflareDeploymentSummarySchema };
66
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","names":[],"sources":["../../src/contracts.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const SUPPORTED_DEPLOYMENT_FORMAT = \"esmodule\";\nexport const DEFAULT_DEPLOYMENT_ENTRYPOINT = \"index.mjs\";\n\nexport const cloudflareCompatibilityDateSchema = z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"compatibilityDate must use YYYY-MM-DD.\");\n\nexport const cloudflareDeploymentStatusSchema = z.enum([\n \"queued\",\n \"deploying\",\n \"succeeded\",\n \"failed\",\n]);\n\nexport const cloudflareDeployScriptSchema = z.object({\n type: z.enum([SUPPORTED_DEPLOYMENT_FORMAT]).default(SUPPORTED_DEPLOYMENT_FORMAT),\n entrypoint: z.string().trim().min(1).default(DEFAULT_DEPLOYMENT_ENTRYPOINT),\n content: z.string(),\n});\n\nexport const cloudflareDeployRequestSchema = z.object({\n script: cloudflareDeployScriptSchema,\n compatibilityDate: cloudflareCompatibilityDateSchema.optional(),\n compatibilityFlags: z.array(z.string().min(1)).optional(),\n});\n\nconst cloudflareTimestampSchema = z.string().datetime({ offset: true });\n\nexport const cloudflareProviderSummarySchema = z.object({\n etag: z.string().nullable(),\n modifiedOn: cloudflareTimestampSchema.nullable(),\n});\n\nexport const cloudflareDeploymentSummarySchema = z.object({\n id: z.string(),\n appId: z.string(),\n scriptName: z.string(),\n status: cloudflareDeploymentStatusSchema,\n format: z.literal(SUPPORTED_DEPLOYMENT_FORMAT),\n entrypoint: z.string(),\n sourceByteLength: z.number().int().nonnegative(),\n compatibilityDate: cloudflareCompatibilityDateSchema,\n compatibilityFlags: z.array(z.string()),\n attemptCount: z.number().int().nonnegative(),\n queuedAt: cloudflareTimestampSchema,\n startedAt: cloudflareTimestampSchema.nullable(),\n completedAt: cloudflareTimestampSchema.nullable(),\n errorCode: z.string().nullable(),\n errorMessage: z.string().nullable(),\n cloudflare: cloudflareProviderSummarySchema.nullable(),\n createdAt: cloudflareTimestampSchema,\n updatedAt: cloudflareTimestampSchema,\n});\n\nexport const cloudflareDeploymentDetailSchema = cloudflareDeploymentSummarySchema.extend({\n sourceCode: z.string(),\n});\n\nexport const cloudflareAppSummarySchema = z.object({\n id: z.string(),\n scriptName: z.string(),\n latestDeployment: cloudflareDeploymentSummarySchema.nullable(),\n createdAt: cloudflareTimestampSchema,\n updatedAt: cloudflareTimestampSchema,\n});\n\nexport const cloudflareAppStateSchema = cloudflareAppSummarySchema.extend({\n liveDeployment: cloudflareDeploymentSummarySchema.nullable(),\n liveDeploymentError: z.string().nullable(),\n deployments: z.array(cloudflareDeploymentSummarySchema),\n});\n\nexport const cloudflareAppListSchema = z.object({\n apps: z.array(cloudflareAppSummarySchema),\n});\n\nexport const cloudflareDeploymentListSchema = z.object({\n deployments: z.array(cloudflareDeploymentSummarySchema),\n});\n\nexport type CloudflareDeploymentStatus = z.infer<typeof cloudflareDeploymentStatusSchema>;\nexport type CloudflareDeployRequest = z.infer<typeof cloudflareDeployRequestSchema>;\nexport type CloudflareDeploymentSummary = z.infer<typeof cloudflareDeploymentSummarySchema>;\nexport type CloudflareDeploymentDetail = z.infer<typeof cloudflareDeploymentDetailSchema>;\nexport type CloudflareAppSummary = z.infer<typeof cloudflareAppSummarySchema>;\nexport type CloudflareAppState = z.infer<typeof cloudflareAppStateSchema>;\nexport type CloudflareAppList = z.infer<typeof cloudflareAppListSchema>;\nexport type CloudflareDeploymentList = z.infer<typeof cloudflareDeploymentListSchema>;\n"],"mappings":";;;AAEA,MAAa,8BAA8B;AAC3C,MAAa,gCAAgC;AAE7C,MAAa,oCAAoC,EAC9C,QAAQ,CACR,MAAM,uBAAuB,yCAAyC;AAEzE,MAAa,mCAAmC,EAAE,KAAK;CACrD;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAa,+BAA+B,EAAE,OAAO;CACnD,MAAM,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC,QAAQ,4BAA4B;CAChF,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,8BAA8B;CAC3E,SAAS,EAAE,QAAQ;CACpB,CAAC;AAEF,MAAa,gCAAgC,EAAE,OAAO;CACpD,QAAQ;CACR,mBAAmB,kCAAkC,UAAU;CAC/D,oBAAoB,EAAE,MA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