@claroshq/claros 0.0.0-stage → 0.8.3
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/LICENSE +21 -0
- package/README.md +16 -2
- package/assets/dashboard/apple-touch-icon.png +0 -0
- package/assets/dashboard/assets/bricolage-grotesque-latin-ext-wght-normal-CcLUaPy7.woff2 +0 -0
- package/assets/dashboard/assets/bricolage-grotesque-latin-wght-normal-DLoelf7F.woff2 +0 -0
- package/assets/dashboard/assets/bricolage-grotesque-vietnamese-wght-normal-BUzh504Q.woff2 +0 -0
- package/assets/dashboard/assets/index-Dvs1k10B.js +23 -0
- package/assets/dashboard/assets/index-gR64IOwq.css +1 -0
- package/assets/dashboard/assets/instrument-sans-latin-ext-wght-normal-B5bTHO_g.woff2 +0 -0
- package/assets/dashboard/assets/instrument-sans-latin-wght-normal-BbzFLZTg.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/assets/dashboard/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/assets/dashboard/assets/quicksand-latin-ext-wght-normal-CrJ75Ewg.woff2 +0 -0
- package/assets/dashboard/assets/quicksand-latin-wght-normal-Buj9m_3d.woff2 +0 -0
- package/assets/dashboard/assets/quicksand-vietnamese-wght-normal-ei70gACF.woff2 +0 -0
- package/assets/dashboard/claros.js +122 -0
- package/assets/dashboard/favicon-16.png +0 -0
- package/assets/dashboard/favicon-32.png +0 -0
- package/assets/dashboard/favicon.ico +0 -0
- package/assets/dashboard/favicon.svg +17 -0
- package/assets/dashboard/fonts-license.txt +119 -0
- package/assets/dashboard/index.html +34 -0
- package/assets/migrations/0000_baseline.sql +343 -0
- package/assets/migrations/0001_kb_fts.sql +22 -0
- package/assets/migrations/0002_instance_layer.sql +51 -0
- package/assets/migrations/0003_suppressions_lower_email.sql +22 -0
- package/assets/migrations/0004_claim_tokens.sql +9 -0
- package/assets/migrations/0005_topics_transports.sql +36 -0
- package/assets/migrations/0006_ops_alerts.sql +28 -0
- package/assets/migrations/0007_integration_surface.sql +46 -0
- package/assets/migrations/0008_p5_engine.sql +31 -0
- package/assets/migrations/0009_p5b_readiness.sql +11 -0
- package/assets/migrations/meta/0000_snapshot.json +2489 -0
- package/assets/migrations/meta/0002_snapshot.json +2645 -0
- package/assets/migrations/meta/0004_snapshot.json +2698 -0
- package/assets/migrations/meta/0005_snapshot.json +2959 -0
- package/assets/migrations/meta/0006_snapshot.json +3138 -0
- package/assets/migrations/meta/0007_snapshot.json +3469 -0
- package/assets/migrations/meta/0008_snapshot.json +3709 -0
- package/assets/migrations/meta/0009_snapshot.json +3785 -0
- package/assets/migrations/meta/_journal.json +76 -0
- package/assets/worker/index.js +57863 -0
- package/bin/claros.mjs +13 -0
- package/dist/apply.d.ts +10 -0
- package/dist/apply.d.ts.map +1 -0
- package/dist/apply.js +72 -0
- package/dist/apply.js.map +1 -0
- package/dist/assets.d.ts +15 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +48 -0
- package/dist/assets.js.map +1 -0
- package/dist/claim.d.ts +12 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/claim.js +26 -0
- package/dist/claim.js.map +1 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +158 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloudflare-api.d.ts +48 -0
- package/dist/cloudflare-api.d.ts.map +1 -0
- package/dist/cloudflare-api.js +94 -0
- package/dist/cloudflare-api.js.map +1 -0
- package/dist/import.d.ts +16 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +97 -0
- package/dist/import.js.map +1 -0
- package/dist/ops.d.ts +84 -0
- package/dist/ops.d.ts.map +1 -0
- package/dist/ops.js +552 -0
- package/dist/ops.js.map +1 -0
- package/dist/state.d.ts +53 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +87 -0
- package/dist/state.js.map +1 -0
- package/dist/template.d.ts +77 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +127 -0
- package/dist/template.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/dist/version.js.map +1 -0
- package/dist/wrangler.d.ts +116 -0
- package/dist/wrangler.d.ts.map +1 -0
- package/dist/wrangler.js +210 -0
- package/dist/wrangler.js.map +1 -0
- package/package.json +53 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,YAAY,wDAAyD,CAAC;AACnF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,uEAAuE;IACvE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,kEAAkE;IAClE,YAAY,EAAE,OAAO,CAAC;IACtB,gDAAgD;IAChD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,2DAA2D;IAC3D,SAAS,EAAE,MA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AAM,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,CAMzE"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local state cache per instance: ~/.config/claros/<name>.json (mode 600).
|
|
3
|
+
*
|
|
4
|
+
* Everything in it except generated secrets can be found again on
|
|
5
|
+
* Cloudflare by name, so a missing cache is fine. Generated secrets are
|
|
6
|
+
* written here so the operator can back them up; they are never read back
|
|
7
|
+
* to overwrite a secret that exists on the Worker.
|
|
8
|
+
*
|
|
9
|
+
* Per-instance files live next to it in ~/.config/claros/<name>/:
|
|
10
|
+
* the generated wrangler.jsonc and backups/.
|
|
11
|
+
*/
|
|
12
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
export const SECRET_NAMES = ["ENCRYPTION_KEY", "UNSUBSCRIBE_SIGNING_KEY"];
|
|
16
|
+
/** Instance names: lowercase letters, digits and hyphens. */
|
|
17
|
+
export const INSTANCE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/;
|
|
18
|
+
export const DEFAULT_INSTANCE = "default";
|
|
19
|
+
/** ~/.config/claros (or $XDG_CONFIG_HOME/claros). */
|
|
20
|
+
export function defaultConfigDir() {
|
|
21
|
+
const base = process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
22
|
+
return join(base, "claros");
|
|
23
|
+
}
|
|
24
|
+
export function statePath(configDir, name) {
|
|
25
|
+
return join(configDir, `${name}.json`);
|
|
26
|
+
}
|
|
27
|
+
/** ~/.config/claros/<name>/ (created on demand, mode 700). */
|
|
28
|
+
export function instanceDir(configDir, name) {
|
|
29
|
+
const dir = join(configDir, name);
|
|
30
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
/** Resource names derived from the instance name. */
|
|
34
|
+
export function resourceNames(name) {
|
|
35
|
+
return {
|
|
36
|
+
workerName: `claros-${name}`,
|
|
37
|
+
d1Name: `claros-${name}`,
|
|
38
|
+
queues: { jobs: `claros-${name}-jobs`, dlq: `claros-${name}-jobs-dlq` },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function newState(name, accountId) {
|
|
42
|
+
return {
|
|
43
|
+
name,
|
|
44
|
+
accountId,
|
|
45
|
+
...resourceNames(name),
|
|
46
|
+
d1Id: null,
|
|
47
|
+
host: null,
|
|
48
|
+
customDomain: false,
|
|
49
|
+
deployedVersion: null,
|
|
50
|
+
versionId: null,
|
|
51
|
+
configHash: null,
|
|
52
|
+
generatedSecrets: {},
|
|
53
|
+
lastUpgradeBackup: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function loadState(configDir, name) {
|
|
57
|
+
const path = statePath(configDir, name);
|
|
58
|
+
if (!existsSync(path))
|
|
59
|
+
return null;
|
|
60
|
+
let raw;
|
|
61
|
+
try {
|
|
62
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw new Error(`${path} is not valid JSON (${err.message}). Fix or move it; everything but generated secrets is found again on Cloudflare.`);
|
|
66
|
+
}
|
|
67
|
+
const s = raw;
|
|
68
|
+
if (typeof s !== "object" || s === null || s.name !== name || typeof s.accountId !== "string") {
|
|
69
|
+
throw new Error(`${path} does not look like a Claros instance state file for "${name}".`);
|
|
70
|
+
}
|
|
71
|
+
const base = newState(name, s.accountId);
|
|
72
|
+
return {
|
|
73
|
+
...base,
|
|
74
|
+
...s,
|
|
75
|
+
queues: { ...base.queues, ...(s.queues ?? {}) },
|
|
76
|
+
generatedSecrets: { ...(s.generatedSecrets ?? {}) },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Write the state file with mode 600 (and keep it 600 if it existed). */
|
|
80
|
+
export function saveState(configDir, state) {
|
|
81
|
+
mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
|
82
|
+
const path = statePath(configDir, state.name);
|
|
83
|
+
writeFileSync(path, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
84
|
+
chmodSync(path, 0o600);
|
|
85
|
+
return path;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAU,CAAC;AAsCnF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,wCAAwC,CAAC;AAEtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAE1C,qDAAqD;AACrD,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,SAAiB,EAAE,IAAY;IACvD,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,IAAY;IACzD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAClC,SAAS,CAAC,GAAG,EAAE,EAA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AK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC9F,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,yDAAyD,IAAI,IAAI,CAAC,CAAC;IAC5F,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO;QACL,GAAG,IAAI;QACP,GAAG,CAAC;QACJ,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE;QAC/C,gBAAgB,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,gBAAgB,IAAI,EAAE,CAAC,EAAE;KACpD,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,SAAiB,EAAE,KAAoB;IAC/D,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Assets } from "./assets.js";
|
|
2
|
+
import type { InstanceState } from "./state.js";
|
|
3
|
+
/** Same value as apps/worker/wrangler.jsonc. */
|
|
4
|
+
export declare const COMPATIBILITY_DATE = "2026-11-20";
|
|
5
|
+
/** Paths that always reach the Worker before Static Assets (apps/worker/wrangler.jsonc). */
|
|
6
|
+
export declare const RUN_WORKER_FIRST: string[];
|
|
7
|
+
export declare const CRON = "*/5 * * * *";
|
|
8
|
+
/**
|
|
9
|
+
* Cloudflare Email Service sending binding, read by the Worker as env.EMAIL
|
|
10
|
+
* (apps/worker/src/transports.ts) for `cloudflare` transports.
|
|
11
|
+
*
|
|
12
|
+
* https://developers.cloudflare.com/email-service/configuration/send-bindings/
|
|
13
|
+
* A binding with only `name` and no restriction attribute "can send to any
|
|
14
|
+
* recipient"; the sender must belong to a domain onboarded to Email Service,
|
|
15
|
+
* which Cloudflare checks at send time (E_SENDER_DOMAIN_NOT_AVAILABLE), not
|
|
16
|
+
* at deploy. So every deployed instance gets it: an instance without an
|
|
17
|
+
* onboarded domain or without a `cloudflare` transport never calls it, and
|
|
18
|
+
* Claros only routes transactional topics to `cloudflare` transports.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SEND_EMAIL_BINDING = "EMAIL";
|
|
21
|
+
export interface WranglerRoute {
|
|
22
|
+
pattern: string;
|
|
23
|
+
custom_domain: true;
|
|
24
|
+
}
|
|
25
|
+
export interface GeneratedConfig {
|
|
26
|
+
name: string;
|
|
27
|
+
main: string;
|
|
28
|
+
account_id: string;
|
|
29
|
+
compatibility_date: string;
|
|
30
|
+
compatibility_flags: string[];
|
|
31
|
+
workers_dev: boolean;
|
|
32
|
+
routes: WranglerRoute[];
|
|
33
|
+
d1_databases: Array<{
|
|
34
|
+
binding: string;
|
|
35
|
+
database_name: string;
|
|
36
|
+
database_id: string;
|
|
37
|
+
migrations_dir: string;
|
|
38
|
+
}>;
|
|
39
|
+
queues: {
|
|
40
|
+
producers: Array<{
|
|
41
|
+
binding: string;
|
|
42
|
+
queue: string;
|
|
43
|
+
}>;
|
|
44
|
+
consumers: Array<Record<string, unknown>>;
|
|
45
|
+
};
|
|
46
|
+
triggers: {
|
|
47
|
+
crons: string[];
|
|
48
|
+
};
|
|
49
|
+
send_email: Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
}>;
|
|
52
|
+
assets: Record<string, unknown>;
|
|
53
|
+
vars: Record<string, string>;
|
|
54
|
+
observability: {
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface TemplateInput {
|
|
59
|
+
state: InstanceState;
|
|
60
|
+
assets: Assets;
|
|
61
|
+
/** Product public hosts (tenants.public_host) that get a custom domain route. */
|
|
62
|
+
productHosts: string[];
|
|
63
|
+
/** Leave the custom domain routes out (first deploy that only creates the Worker). */
|
|
64
|
+
withoutRoutes?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Hosts that get a custom domain route: the instance domain, then product hosts (sorted, unique). */
|
|
67
|
+
export declare function routeHosts(state: InstanceState, productHosts: string[]): string[];
|
|
68
|
+
export declare function generateConfig(input: TemplateInput): GeneratedConfig;
|
|
69
|
+
/** The file content: a short header comment, then the configuration as JSON. */
|
|
70
|
+
export declare function renderConfig(config: GeneratedConfig): string;
|
|
71
|
+
/**
|
|
72
|
+
* Stable hash of a configuration (a second deploy with the same hash is
|
|
73
|
+
* skipped). Local paths are left out: the same version run from another
|
|
74
|
+
* npx cache directory deploys the same Worker. CLAROS_VERSION is in vars.
|
|
75
|
+
*/
|
|
76
|
+
export declare function configHash(config: GeneratedConfig): string;
|
|
77
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,gDAAgD;AAChD,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAE/C,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,UAY5B,CAAC;AAEF,eAAO,MAAM,IAAI,gBAAgB,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAk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aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAKjF;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,CAmDpE;AAED,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAO5D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAQ1D"}
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wrangler.jsonc template for a deployed instance.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the development template apps/worker/wrangler.jsonc (bindings,
|
|
5
|
+
* queue settings, cron, assets rules); a test keeps the two in step. The
|
|
6
|
+
* deploy fills in the resource names and ids, the routes and BASE_URL.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { D1_BINDING } from "./wrangler.js";
|
|
10
|
+
/** Same value as apps/worker/wrangler.jsonc. */
|
|
11
|
+
export const COMPATIBILITY_DATE = "2026-11-20";
|
|
12
|
+
/** Paths that always reach the Worker before Static Assets (apps/worker/wrangler.jsonc). */
|
|
13
|
+
export const RUN_WORKER_FIRST = [
|
|
14
|
+
"/health",
|
|
15
|
+
"/version",
|
|
16
|
+
"/auth",
|
|
17
|
+
"/auth/*",
|
|
18
|
+
"/invite",
|
|
19
|
+
"/invite/*",
|
|
20
|
+
"/unsubscribe",
|
|
21
|
+
"/unsubscribe/*",
|
|
22
|
+
"/webhooks/*",
|
|
23
|
+
"/v1",
|
|
24
|
+
"/v1/*",
|
|
25
|
+
];
|
|
26
|
+
export const CRON = "*/5 * * * *";
|
|
27
|
+
/**
|
|
28
|
+
* Cloudflare Email Service sending binding, read by the Worker as env.EMAIL
|
|
29
|
+
* (apps/worker/src/transports.ts) for `cloudflare` transports.
|
|
30
|
+
*
|
|
31
|
+
* https://developers.cloudflare.com/email-service/configuration/send-bindings/
|
|
32
|
+
* A binding with only `name` and no restriction attribute "can send to any
|
|
33
|
+
* recipient"; the sender must belong to a domain onboarded to Email Service,
|
|
34
|
+
* which Cloudflare checks at send time (E_SENDER_DOMAIN_NOT_AVAILABLE), not
|
|
35
|
+
* at deploy. So every deployed instance gets it: an instance without an
|
|
36
|
+
* onboarded domain or without a `cloudflare` transport never calls it, and
|
|
37
|
+
* Claros only routes transactional topics to `cloudflare` transports.
|
|
38
|
+
*/
|
|
39
|
+
export const SEND_EMAIL_BINDING = "EMAIL";
|
|
40
|
+
/** Hosts that get a custom domain route: the instance domain, then product hosts (sorted, unique). */
|
|
41
|
+
export function routeHosts(state, productHosts) {
|
|
42
|
+
const hosts = [];
|
|
43
|
+
if (state.customDomain && state.host)
|
|
44
|
+
hosts.push(state.host);
|
|
45
|
+
for (const h of [...productHosts].sort())
|
|
46
|
+
if (!hosts.includes(h))
|
|
47
|
+
hosts.push(h);
|
|
48
|
+
return hosts;
|
|
49
|
+
}
|
|
50
|
+
export function generateConfig(input) {
|
|
51
|
+
const { state, assets } = input;
|
|
52
|
+
if (!state.d1Id)
|
|
53
|
+
throw new Error("internal: D1 database id unknown");
|
|
54
|
+
const routes = input.withoutRoutes
|
|
55
|
+
? []
|
|
56
|
+
: routeHosts(state, input.productHosts).map((pattern) => ({ pattern, custom_domain: true }));
|
|
57
|
+
const vars = { CLAROS_VERSION: assets.version };
|
|
58
|
+
// Without a known host BASE_URL stays unset: the Worker then refuses to
|
|
59
|
+
// send in production instead of baking a wrong URL into mail.
|
|
60
|
+
if (state.host)
|
|
61
|
+
vars.BASE_URL = `https://${state.host}`;
|
|
62
|
+
return {
|
|
63
|
+
name: state.workerName,
|
|
64
|
+
main: assets.workerMain,
|
|
65
|
+
account_id: state.accountId,
|
|
66
|
+
compatibility_date: COMPATIBILITY_DATE,
|
|
67
|
+
compatibility_flags: ["nodejs_compat"],
|
|
68
|
+
workers_dev: !state.customDomain,
|
|
69
|
+
routes,
|
|
70
|
+
d1_databases: [
|
|
71
|
+
{
|
|
72
|
+
binding: D1_BINDING,
|
|
73
|
+
database_name: state.d1Name,
|
|
74
|
+
database_id: state.d1Id,
|
|
75
|
+
migrations_dir: assets.migrationsDir,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
queues: {
|
|
79
|
+
producers: [{ binding: "JOBS", queue: state.queues.jobs }],
|
|
80
|
+
consumers: [
|
|
81
|
+
{
|
|
82
|
+
queue: state.queues.jobs,
|
|
83
|
+
max_batch_size: 10,
|
|
84
|
+
max_batch_timeout: 5,
|
|
85
|
+
max_retries: 3,
|
|
86
|
+
dead_letter_queue: state.queues.dlq,
|
|
87
|
+
},
|
|
88
|
+
{ queue: state.queues.dlq, max_batch_size: 10, max_batch_timeout: 30 },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
triggers: { crons: [CRON] },
|
|
92
|
+
send_email: [{ name: SEND_EMAIL_BINDING }],
|
|
93
|
+
assets: {
|
|
94
|
+
directory: assets.dashboardDir,
|
|
95
|
+
binding: "ASSETS",
|
|
96
|
+
not_found_handling: "none",
|
|
97
|
+
html_handling: "none",
|
|
98
|
+
run_worker_first: RUN_WORKER_FIRST,
|
|
99
|
+
},
|
|
100
|
+
vars,
|
|
101
|
+
observability: { enabled: true },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** The file content: a short header comment, then the configuration as JSON. */
|
|
105
|
+
export function renderConfig(config) {
|
|
106
|
+
return [
|
|
107
|
+
"// Generated by `claros deploy`. Changes here are overwritten on the next deploy.",
|
|
108
|
+
"// Secrets (ENCRYPTION_KEY, UNSUBSCRIBE_SIGNING_KEY) are set on the Worker, not here.",
|
|
109
|
+
JSON.stringify(config, null, 2),
|
|
110
|
+
"",
|
|
111
|
+
].join("\n");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Stable hash of a configuration (a second deploy with the same hash is
|
|
115
|
+
* skipped). Local paths are left out: the same version run from another
|
|
116
|
+
* npx cache directory deploys the same Worker. CLAROS_VERSION is in vars.
|
|
117
|
+
*/
|
|
118
|
+
export function configHash(config) {
|
|
119
|
+
const portable = {
|
|
120
|
+
...config,
|
|
121
|
+
main: "",
|
|
122
|
+
assets: { ...config.assets, directory: "" },
|
|
123
|
+
d1_databases: config.d1_databases.map((d) => ({ ...d, migrations_dir: "" })),
|
|
124
|
+
};
|
|
125
|
+
return createHash("sha256").update(JSON.stringify(portable)).digest("hex").slice(0, 16);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,gDAAgD;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE/C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,SAAS;IACT,UAAU;IACV,OAAO;IACP,SAAS;IACT,SAAS;IACT,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,aAAa;IACb,KAAK;IACL,OAAO;CACR,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,aAAa,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAoC1C,sGAAsG;AACtG,MAAM,UAAU,UAAU,CAAC,KAAoB,EAAE,YAAsB;IACrE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7D,KA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E,SAAS,EAAE,EAAE,EAAE;QAC3C,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,CAAC;KAC7E,CAAC;IACF,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAgBA,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAiB5D"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function parse(v) {
|
|
2
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(v.trim());
|
|
3
|
+
if (!m)
|
|
4
|
+
throw new Error(`Not a version: "${v}"`);
|
|
5
|
+
const pre = m[4] ? m[4].split(".").map((p) => (/^\d+$/.test(p) ? Number(p) : p)) : [];
|
|
6
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre };
|
|
7
|
+
}
|
|
8
|
+
/** Negative when a < b, 0 when equal, positive when a > b. */
|
|
9
|
+
export function compareVersions(a, b) {
|
|
10
|
+
const x = parse(a);
|
|
11
|
+
const y = parse(b);
|
|
12
|
+
for (let i = 0; i < 3; i++)
|
|
13
|
+
if (x.core[i] !== y.core[i])
|
|
14
|
+
return x.core[i] - y.core[i];
|
|
15
|
+
if (x.pre.length === 0 || y.pre.length === 0)
|
|
16
|
+
return y.pre.length - x.pre.length;
|
|
17
|
+
for (let i = 0; i < Math.max(x.pre.length, y.pre.length); i++) {
|
|
18
|
+
const p = x.pre[i];
|
|
19
|
+
const q = y.pre[i];
|
|
20
|
+
if (p === undefined)
|
|
21
|
+
return -1;
|
|
22
|
+
if (q === undefined)
|
|
23
|
+
return 1;
|
|
24
|
+
if (p === q)
|
|
25
|
+
continue;
|
|
26
|
+
if (typeof p === "number" && typeof q === "number")
|
|
27
|
+
return p - q;
|
|
28
|
+
if (typeof p === "number")
|
|
29
|
+
return -1;
|
|
30
|
+
if (typeof q === "number")
|
|
31
|
+
return 1;
|
|
32
|
+
return p < q ? -1 : 1;
|
|
33
|
+
}
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AASA,SAAS,KAAK,CAAC,CAAS;IACtB,MAAM,CAAC,GAAG,oEAAoE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9F,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtF,OAAO,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM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AK,QAAQ;YAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,CAAC;QACrC,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export interface RunResult {
|
|
2
|
+
code: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
export interface RunOptions {
|
|
7
|
+
/** Written to the child's stdin. */
|
|
8
|
+
input?: string;
|
|
9
|
+
/** Extra environment variables. */
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
/** Inherit the terminal (login); output is not captured. */
|
|
12
|
+
interactive?: boolean;
|
|
13
|
+
/** Working directory. */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}
|
|
16
|
+
export type Runner = (args: string[], opts?: RunOptions) => Promise<RunResult>;
|
|
17
|
+
/** The wrangler bin of the wrangler package this CLI depends on. */
|
|
18
|
+
export declare function wranglerBin(): string;
|
|
19
|
+
/** Runs the real wrangler (node <wrangler bin> ...args). */
|
|
20
|
+
export declare function spawnRunner(bin?: string): Runner;
|
|
21
|
+
/** A wrangler command failed. */
|
|
22
|
+
export declare class WranglerError extends Error {
|
|
23
|
+
readonly args: string[];
|
|
24
|
+
readonly result: RunResult;
|
|
25
|
+
constructor(args: string[], result: RunResult);
|
|
26
|
+
/** stdout and stderr together, for matching known error messages. */
|
|
27
|
+
get output(): string;
|
|
28
|
+
}
|
|
29
|
+
/** The first JSON value in wrangler's stdout (banners and warnings can precede it). */
|
|
30
|
+
export declare function parseJsonOutput<T>(stdout: string): T;
|
|
31
|
+
export interface WhoAmI {
|
|
32
|
+
loggedIn: boolean;
|
|
33
|
+
email?: string;
|
|
34
|
+
accounts: Array<{
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
39
|
+
export interface D1Info {
|
|
40
|
+
uuid: string;
|
|
41
|
+
name: string;
|
|
42
|
+
}
|
|
43
|
+
export type AuthCredentials = {
|
|
44
|
+
type: "oauth" | "api_token";
|
|
45
|
+
token: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "api_key";
|
|
48
|
+
key: string;
|
|
49
|
+
email: string;
|
|
50
|
+
};
|
|
51
|
+
export interface DeployResult {
|
|
52
|
+
/** Version id wrangler printed ("Current Version ID: ..."). */
|
|
53
|
+
versionId: string | null;
|
|
54
|
+
/** https URLs wrangler printed (workers.dev and custom domains). */
|
|
55
|
+
urls: string[];
|
|
56
|
+
output: string;
|
|
57
|
+
}
|
|
58
|
+
/** Name of the D1 binding in the generated configuration. */
|
|
59
|
+
export declare const D1_BINDING = "DB";
|
|
60
|
+
/**
|
|
61
|
+
* Tables `d1 export` can write: everything but SQLite and D1 internals and
|
|
62
|
+
* the FTS5 knowledge-base index (kb_fts and its shadow tables), which is
|
|
63
|
+
* rebuilt from kb_entries with `INSERT INTO kb_fts(kb_fts) VALUES('rebuild')`.
|
|
64
|
+
*/
|
|
65
|
+
export declare const D1_EXPORTABLE_TABLES_SQL = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '_cf_%' AND name NOT LIKE 'kb_fts%' ORDER BY name";
|
|
66
|
+
export declare class Wrangler {
|
|
67
|
+
private readonly run;
|
|
68
|
+
private readonly ctx;
|
|
69
|
+
constructor(run: Runner, ctx?: {
|
|
70
|
+
accountId?: string;
|
|
71
|
+
configPath?: string;
|
|
72
|
+
cwd?: string;
|
|
73
|
+
});
|
|
74
|
+
/** The same runner bound to an account and a generated configuration file. */
|
|
75
|
+
with(ctx: {
|
|
76
|
+
accountId?: string;
|
|
77
|
+
configPath?: string;
|
|
78
|
+
cwd?: string;
|
|
79
|
+
}): Wrangler;
|
|
80
|
+
private exec;
|
|
81
|
+
private ok;
|
|
82
|
+
private config;
|
|
83
|
+
whoami(): Promise<WhoAmI>;
|
|
84
|
+
login(): Promise<void>;
|
|
85
|
+
/** The credentials wrangler uses (for the few Cloudflare API reads wrangler has no command for). */
|
|
86
|
+
authToken(): Promise<AuthCredentials | null>;
|
|
87
|
+
d1List(): Promise<D1Info[]>;
|
|
88
|
+
d1Create(name: string): Promise<void>;
|
|
89
|
+
queueExists(name: string): Promise<boolean>;
|
|
90
|
+
queueCreate(name: string): Promise<void>;
|
|
91
|
+
/** Names of the Worker's secrets, or null when the Worker does not exist yet. */
|
|
92
|
+
secretNames(): Promise<string[] | null>;
|
|
93
|
+
/** Run SQL on the remote D1 database; one result set per statement. */
|
|
94
|
+
d1Execute(command: string): Promise<Array<Array<Record<string, unknown>>>>;
|
|
95
|
+
/** Migration files not yet applied to the remote D1 database. */
|
|
96
|
+
migrationsPending(): Promise<string[]>;
|
|
97
|
+
migrationsApply(): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* The current D1 Time Travel bookmark of the remote database
|
|
100
|
+
* (`wrangler d1 time-travel info DB --json` prints `{ "bookmark": "..." }`).
|
|
101
|
+
*/
|
|
102
|
+
d1Bookmark(): Promise<string>;
|
|
103
|
+
/** Regular tables of the remote D1 database (no SQLite, D1 or FTS5 internals). */
|
|
104
|
+
d1ExportableTables(): Promise<string[]>;
|
|
105
|
+
/**
|
|
106
|
+
* Export the remote D1 database as SQL. `d1 export` refuses databases with
|
|
107
|
+
* virtual tables (FTS5), so callers pass the regular tables to export.
|
|
108
|
+
*/
|
|
109
|
+
d1Export(outputFile: string, tables?: string[]): Promise<void>;
|
|
110
|
+
deploy(opts?: {
|
|
111
|
+
secretsFile?: string;
|
|
112
|
+
}): Promise<DeployResult>;
|
|
113
|
+
/** Roll the Worker back to a version (the previous one when no id is given). */
|
|
114
|
+
rollback(versionId: string | null, message: string): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=wrangler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler.d.ts","sourceRoot":"","sources":["../src/wrangler.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,4DAA4D;IAC5D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,UAAU,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAE/E,oEAAoE;AACpE,wBAAgB,WAAW,IAAI,MAAM,CAGpC;AAED,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,GAAG,SAAgB,GAAG,MAAM,CAmBvD;AAED,iCAAiC;AACjC,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS;gBADjB,IAAI,EAAE,MAAM,EAAE,EACd,MAAM,EAAE,SAAS;IAK5B,qEAAqE;IACrE,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF;AAWD,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,CAIpD;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC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