@composable-os/cli 0.1.0-beta.10 → 0.1.0-beta.11
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/dist/{accounts-X4CKM3HL.js → accounts-UHYLCLEY.js} +10 -11
- package/dist/{blocks-YWDHEBOK.js → blocks-5IFU25J6.js} +2 -2
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/{chunk-QGGJ2G6Z.js → chunk-2TWV3SVB.js} +3 -3
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/{chunk-YJJHF65I.js → chunk-6WGFA2IV.js} +58 -174
- package/dist/{chunk-A4NTSYWV.js → chunk-6XTU2MTP.js} +196 -10
- package/dist/{chunk-Q4N55M2Z.js → chunk-7D4GKZOX.js} +66 -3
- package/dist/{chunk-GYSGVT6R.js → chunk-7OGCMQXG.js} +9 -9
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/{chunk-LJFLENFC.js → chunk-E64SG24J.js} +1 -1
- package/dist/{chunk-Z3RMMB6S.js → chunk-FJIZGS5Q.js} +45 -15
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-LAAL4YGR.js} +4 -4
- package/dist/{chunk-CP6BXI6F.js → chunk-LO6WGU5Y.js} +1338 -974
- package/dist/{chunk-Y7JZFSTQ.js → chunk-MBIKVRAC.js} +6 -6
- package/dist/{chunk-WC5LHBBA.js → chunk-P6UWZ6QQ.js} +1 -1
- package/dist/{chunk-6VXHPKGG.js → chunk-PDD2ETVF.js} +8 -8
- package/dist/{chunk-6UPUF4ML.js → chunk-UB4I2QKR.js} +1957 -380
- package/dist/{chunk-M7A6FR2Z.js → chunk-WHKJGF36.js} +154 -322
- package/dist/{chunk-VY64DMQO.js → chunk-XIDLW3EP.js} +190 -21
- package/dist/{chunk-IFG4FRW5.js → chunk-YFTLIEWU.js} +1 -1
- package/dist/{chunk-JJHHNV46.js → chunk-YNUZRTPH.js} +5 -50
- package/dist/{chunk-WO6D3XP3.js → chunk-ZAWES2UD.js} +31 -18
- package/dist/{chunk-K6T42YCH.js → chunk-ZZFWMVJO.js} +5 -5
- package/dist/{cli-2DFENR62.js → cli-5UNY5G5L.js} +22 -20
- package/dist/{cli-YIOVSKOD.js → cli-UYZMVQMR.js} +16 -13
- package/dist/cli.js +1 -1
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-SE4EKG6W.js} +2 -2
- package/dist/create.js +1 -1
- package/dist/{fields-2NC7LSYE.js → fields-FTWWMD7N.js} +3 -3
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/{order-PUWD65BC.js → order-U4KZLLSJ.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-UHLVBVLR.js} +9 -10
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/capacity.ts +102 -0
- package/dist/platform/sdk/contract.ts +25 -0
- package/dist/platform/sdk/manifest.ts +77 -1
- package/dist/platform/sdk/sellable.ts +251 -1
- package/dist/platform/sdk/states.ts +163 -49
- package/dist/{run-RT2HVWMK.js → run-7P4RQALH.js} +2 -2
- package/dist/{run-PZUCSDDL.js → run-PO3W5BFA.js} +1 -1
- package/dist/{run-Y7T4TVOL.js → run-ZCGFMEZF.js} +2 -2
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/{src-XTOD7EXW.js → src-I3IJ4NKC.js} +8 -2
- package/dist/{visibility-DLGHU4YN.js → visibility-TVXZ67FD.js} +12 -4
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/grants-QXMKYMGB.js +0 -32
- package/dist/invoke-I3NNNXVL.js +0 -39
- package/dist/plan-on-sale-NB774CQL.js +0 -26
- package/dist/src-GYS6NBQB.js +0 -44
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ENTRY_POINTS,
|
|
4
|
+
operationsFor,
|
|
5
|
+
productContract,
|
|
6
|
+
releaseContract,
|
|
7
|
+
renderClient,
|
|
8
|
+
renderEntry,
|
|
9
|
+
renderRoleClient,
|
|
10
|
+
schemaToTs
|
|
11
|
+
} from "./chunk-LAAL4YGR.js";
|
|
12
|
+
import "./chunk-UB4I2QKR.js";
|
|
13
|
+
import "./chunk-DHS2CV2M.js";
|
|
14
|
+
import "./chunk-K34UKWEI.js";
|
|
15
|
+
import "./chunk-2IVEVPMY.js";
|
|
16
|
+
import "./chunk-6WGFA2IV.js";
|
|
17
|
+
import "./chunk-WHKJGF36.js";
|
|
18
|
+
import "./chunk-324WJXNP.js";
|
|
19
|
+
import "./chunk-7OGCMQXG.js";
|
|
20
|
+
import "./chunk-XIDLW3EP.js";
|
|
21
|
+
import "./chunk-FJIZGS5Q.js";
|
|
22
|
+
import "./chunk-ZAWES2UD.js";
|
|
23
|
+
import "./chunk-E64SG24J.js";
|
|
24
|
+
import "./chunk-YNUZRTPH.js";
|
|
25
|
+
import "./chunk-6ELZRNUU.js";
|
|
26
|
+
import "./chunk-2TWV3SVB.js";
|
|
27
|
+
import "./chunk-ZZFWMVJO.js";
|
|
28
|
+
import "./chunk-2XC5JLBO.js";
|
|
29
|
+
import "./chunk-DU6OIFOU.js";
|
|
30
|
+
import "./chunk-KGHA67HG.js";
|
|
31
|
+
import "./chunk-6UWRT4VM.js";
|
|
32
|
+
import "./chunk-6XTU2MTP.js";
|
|
33
|
+
import "./chunk-YFTLIEWU.js";
|
|
34
|
+
import "./chunk-7D4GKZOX.js";
|
|
35
|
+
import "./chunk-LO6WGU5Y.js";
|
|
36
|
+
import "./chunk-5KSXSK7Y.js";
|
|
37
|
+
export {
|
|
38
|
+
ENTRY_POINTS,
|
|
39
|
+
operationsFor,
|
|
40
|
+
productContract,
|
|
41
|
+
releaseContract,
|
|
42
|
+
renderClient,
|
|
43
|
+
renderEntry,
|
|
44
|
+
renderRoleClient,
|
|
45
|
+
schemaToTs
|
|
46
|
+
};
|
|
@@ -170,8 +170,11 @@ import {
|
|
|
170
170
|
validateDocument,
|
|
171
171
|
validateManifest,
|
|
172
172
|
valueMatchSchema,
|
|
173
|
-
viewManifestSchema
|
|
174
|
-
|
|
173
|
+
viewManifestSchema,
|
|
174
|
+
waitlistManifestSchema,
|
|
175
|
+
windowBoundSchema,
|
|
176
|
+
windowChecks
|
|
177
|
+
} from "./chunk-LO6WGU5Y.js";
|
|
175
178
|
import "./chunk-5KSXSK7Y.js";
|
|
176
179
|
export {
|
|
177
180
|
ALLOWANCE_PERIODS,
|
|
@@ -344,5 +347,8 @@ export {
|
|
|
344
347
|
validateManifest,
|
|
345
348
|
valueMatchSchema,
|
|
346
349
|
viewManifestSchema,
|
|
350
|
+
waitlistManifestSchema,
|
|
351
|
+
windowBoundSchema,
|
|
352
|
+
windowChecks,
|
|
347
353
|
external_exports as z
|
|
348
354
|
};
|
|
@@ -3,29 +3,37 @@ import {
|
|
|
3
3
|
buyableSource,
|
|
4
4
|
customerProblems,
|
|
5
5
|
customerViaProblems,
|
|
6
|
+
familyOf,
|
|
7
|
+
guardianProblems,
|
|
6
8
|
orgReader,
|
|
7
9
|
ownedSource,
|
|
8
10
|
previewSource,
|
|
9
11
|
publicProblems,
|
|
12
|
+
recordsMadeFor,
|
|
10
13
|
scopeOf,
|
|
14
|
+
sharedEmailWarning,
|
|
11
15
|
signedInProblems,
|
|
12
16
|
visibleObject,
|
|
13
17
|
visibleSource,
|
|
14
18
|
visibleTable
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
+
} from "./chunk-6XTU2MTP.js";
|
|
20
|
+
import "./chunk-YFTLIEWU.js";
|
|
21
|
+
import "./chunk-7D4GKZOX.js";
|
|
22
|
+
import "./chunk-LO6WGU5Y.js";
|
|
19
23
|
import "./chunk-5KSXSK7Y.js";
|
|
20
24
|
export {
|
|
21
25
|
buyableSource,
|
|
22
26
|
customerProblems,
|
|
23
27
|
customerViaProblems,
|
|
28
|
+
familyOf,
|
|
29
|
+
guardianProblems,
|
|
24
30
|
orgReader,
|
|
25
31
|
ownedSource,
|
|
26
32
|
previewSource,
|
|
27
33
|
publicProblems,
|
|
34
|
+
recordsMadeFor,
|
|
28
35
|
scopeOf,
|
|
36
|
+
sharedEmailWarning,
|
|
29
37
|
signedInProblems,
|
|
30
38
|
visibleObject,
|
|
31
39
|
visibleSource,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composable-os/cli",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.11",
|
|
4
4
|
"license": "FSL-1.1-ALv2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"esbuild": "0.28.2",
|
|
31
31
|
"typescript": "6.0.3",
|
|
32
|
-
"@composable-os/sdk": "0.1.0-beta.
|
|
32
|
+
"@composable-os/sdk": "0.1.0-beta.11",
|
|
33
33
|
"zod": "4.6.7"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/dist/chunk-6GDEDOV7.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
ACTORS,
|
|
4
|
-
PERMISSIONS,
|
|
5
|
-
RISK_CLASSES
|
|
6
|
-
} from "./chunk-A4NTSYWV.js";
|
|
7
|
-
|
|
8
|
-
// ../core/src/audiences.ts
|
|
9
|
-
var AUDIENCES = ["staff", "customer", "public"];
|
|
10
|
-
var DEFAULT_AUDIENCES = Object.freeze(["staff"]);
|
|
11
|
-
var OUTSIDE_RISK_CLASSES = Object.freeze(["read", "write"]);
|
|
12
|
-
function audiencesOf(op) {
|
|
13
|
-
return op.audiences ?? DEFAULT_AUDIENCES;
|
|
14
|
-
}
|
|
15
|
-
function isOpenOutside(op) {
|
|
16
|
-
return audiencesOf(op).some((audience) => audience !== "staff");
|
|
17
|
-
}
|
|
18
|
-
function audienceOf(principal) {
|
|
19
|
-
return principal.kind;
|
|
20
|
-
}
|
|
21
|
-
function allowsAudience(op, principal) {
|
|
22
|
-
return audiencesOf(op).includes(audienceOf(principal));
|
|
23
|
-
}
|
|
24
|
-
function audienceProblems(op) {
|
|
25
|
-
const problems = [];
|
|
26
|
-
const declared = op.audiences;
|
|
27
|
-
if (declared !== void 0) {
|
|
28
|
-
if (!Array.isArray(declared) || declared.length === 0) {
|
|
29
|
-
problems.push("audiences must list at least one of staff, customer, public");
|
|
30
|
-
return problems;
|
|
31
|
-
}
|
|
32
|
-
if (declared.some((a) => !AUDIENCES.includes(a))) {
|
|
33
|
-
problems.push("audiences must be a subset of staff, customer, public");
|
|
34
|
-
return problems;
|
|
35
|
-
}
|
|
36
|
-
if (new Set(declared).size !== declared.length) problems.push("audiences lists one twice");
|
|
37
|
-
}
|
|
38
|
-
if (isOpenOutside(op) && !OUTSIDE_RISK_CLASSES.includes(op.risk)) {
|
|
39
|
-
const who = audiencesOf(op).filter((a) => a !== "staff");
|
|
40
|
-
problems.push(
|
|
41
|
-
`an operation open to ${who.join(" and ")} callers must have risk class read or write, not ${op.risk} (ADR 0402)`
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return problems;
|
|
45
|
-
}
|
|
46
|
-
function packOf(name) {
|
|
47
|
-
const [first, id] = name.split(".");
|
|
48
|
-
return first === "x" && id ? id : void 0;
|
|
49
|
-
}
|
|
50
|
-
function forPacks(file, installed) {
|
|
51
|
-
return {
|
|
52
|
-
...file,
|
|
53
|
-
operations: file.operations.filter((op) => {
|
|
54
|
-
const pack = op.pack ?? packOf(op.name);
|
|
55
|
-
return pack === void 0 || installed.includes(pack);
|
|
56
|
-
}).map(({ pack: _pack, ...op }) => op)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// ../core/src/operation.ts
|
|
61
|
-
var AFTER_COMMIT = /* @__PURE__ */ Symbol("afterCommit");
|
|
62
|
-
function afterCommit(read) {
|
|
63
|
-
return { [AFTER_COMMIT]: read };
|
|
64
|
-
}
|
|
65
|
-
function isAfterCommit(value) {
|
|
66
|
-
return typeof value === "object" && value !== null && AFTER_COMMIT in value;
|
|
67
|
-
}
|
|
68
|
-
function runAfterCommit(value) {
|
|
69
|
-
return value[AFTER_COMMIT]();
|
|
70
|
-
}
|
|
71
|
-
function recordHostChange(ctx, change) {
|
|
72
|
-
(ctx.recordHostChange ?? ctx.recordChange)(change);
|
|
73
|
-
}
|
|
74
|
-
function personsTool(ctx, extensionId) {
|
|
75
|
-
const caller = ctx.extension;
|
|
76
|
-
if (!caller || !extensionId || caller.id !== extensionId) return null;
|
|
77
|
-
const tool = caller.tool;
|
|
78
|
-
return tool?.humanOnly && tool.permission ? tool.name : null;
|
|
79
|
-
}
|
|
80
|
-
var HOST_TOOLS = /* @__PURE__ */ new WeakSet();
|
|
81
|
-
function markHostTool(op) {
|
|
82
|
-
HOST_TOOLS.add(op);
|
|
83
|
-
}
|
|
84
|
-
function isHostTool(op) {
|
|
85
|
-
return HOST_TOOLS.has(op);
|
|
86
|
-
}
|
|
87
|
-
var OPERATION_NAME_RE = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
|
|
88
|
-
function defineOperation(definition) {
|
|
89
|
-
const problems = operationProblems(definition);
|
|
90
|
-
if (problems.length) {
|
|
91
|
-
throw new Error(`Operation ${definition.name}: ${problems.join("; ")}`);
|
|
92
|
-
}
|
|
93
|
-
return Object.freeze({ ...definition });
|
|
94
|
-
}
|
|
95
|
-
function operationProblems(op) {
|
|
96
|
-
const problems = [];
|
|
97
|
-
if (!OPERATION_NAME_RE.test(op.name ?? "")) problems.push("name must be <object>.<verb>");
|
|
98
|
-
if (typeof op.description !== "string" || op.description.trim().length < 20) {
|
|
99
|
-
problems.push("description must explain what it does, when to use it and side effects");
|
|
100
|
-
}
|
|
101
|
-
if (!op.input || typeof op.input.safeParse !== "function") problems.push("input schema missing");
|
|
102
|
-
if (!op.output || typeof op.output.safeParse !== "function") {
|
|
103
|
-
problems.push("output schema missing");
|
|
104
|
-
}
|
|
105
|
-
if (!PERMISSIONS.includes(op.permission)) problems.push("permission missing or unknown");
|
|
106
|
-
if (op.packPermission !== void 0) {
|
|
107
|
-
const extension = /^x\.([a-z][a-z0-9]{1,29})\./.exec(op.name ?? "")?.[1];
|
|
108
|
-
if (!extension) problems.push("packPermission is for extension tools only");
|
|
109
|
-
else if (!op.packPermission.startsWith(`${extension}:`)) {
|
|
110
|
-
problems.push(`packPermission is named ${extension}:<word>`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!RISK_CLASSES.includes(op.risk)) problems.push("risk class missing or unknown");
|
|
114
|
-
if (op.actors && (op.actors.length === 0 || op.actors.some((a) => !ACTORS.includes(a)))) {
|
|
115
|
-
problems.push("actors must list known actor types");
|
|
116
|
-
}
|
|
117
|
-
if (typeof op.handler !== "function") problems.push("handler missing");
|
|
118
|
-
problems.push(...audienceProblems(op));
|
|
119
|
-
if (op.hostInternal !== void 0) {
|
|
120
|
-
if (op.hostInternal !== true) problems.push("hostInternal is true or left out");
|
|
121
|
-
if (op.name?.startsWith("x.")) problems.push("an extension tool can never be hostInternal");
|
|
122
|
-
if (!isOpenOutside(op)) {
|
|
123
|
-
problems.push("hostInternal is only for an operation open to customer or public callers");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (op.toolOnly !== void 0) {
|
|
127
|
-
if (op.toolOnly !== true) problems.push("toolOnly is true or left out");
|
|
128
|
-
if (op.name?.startsWith("x.")) problems.push("an extension tool cannot be toolOnly");
|
|
129
|
-
if (!audiencesOf(op).includes("customer")) {
|
|
130
|
-
problems.push("toolOnly is only for an operation open to customer callers");
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (isOpenOutside(op) && op.alwaysReview) {
|
|
134
|
-
problems.push("an operation open to customer or public callers is never queued for review");
|
|
135
|
-
}
|
|
136
|
-
if ((op.risk === "bulk-write" || op.risk === "destructive") && op.name.endsWith("Many")) {
|
|
137
|
-
if (typeof op.bulkSize !== "function") problems.push("batch operations need bulkSize");
|
|
138
|
-
}
|
|
139
|
-
return problems;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export {
|
|
143
|
-
AUDIENCES,
|
|
144
|
-
OUTSIDE_RISK_CLASSES,
|
|
145
|
-
audiencesOf,
|
|
146
|
-
allowsAudience,
|
|
147
|
-
forPacks,
|
|
148
|
-
afterCommit,
|
|
149
|
-
isAfterCommit,
|
|
150
|
-
runAfterCommit,
|
|
151
|
-
recordHostChange,
|
|
152
|
-
personsTool,
|
|
153
|
-
markHostTool,
|
|
154
|
-
isHostTool,
|
|
155
|
-
defineOperation,
|
|
156
|
-
operationProblems
|
|
157
|
-
};
|
package/dist/chunk-O2UIZHND.js
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
external_exports
|
|
4
|
-
} from "./chunk-CP6BXI6F.js";
|
|
5
|
-
|
|
6
|
-
// ../core/src/time/local.ts
|
|
7
|
-
function zoneOffset(at, timeZone) {
|
|
8
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
9
|
-
timeZone,
|
|
10
|
-
hourCycle: "h23",
|
|
11
|
-
year: "numeric",
|
|
12
|
-
month: "2-digit",
|
|
13
|
-
day: "2-digit",
|
|
14
|
-
hour: "2-digit",
|
|
15
|
-
minute: "2-digit",
|
|
16
|
-
second: "2-digit"
|
|
17
|
-
}).formatToParts(new Date(at));
|
|
18
|
-
const n = (type) => Number(parts.find((p) => p.type === type)?.value);
|
|
19
|
-
return Date.UTC(n("year"), n("month") - 1, n("day"), n("hour"), n("minute"), n("second")) - at;
|
|
20
|
-
}
|
|
21
|
-
function realWallClock(y, m, d, h = 0, mi = 0, s = 0) {
|
|
22
|
-
const at = new Date(Date.UTC(y, m - 1, d, h, mi, s));
|
|
23
|
-
return at.getUTCFullYear() === y && at.getUTCMonth() === m - 1 && at.getUTCDate() === d && at.getUTCHours() === h && at.getUTCMinutes() === mi && at.getUTCSeconds() === s;
|
|
24
|
-
}
|
|
25
|
-
var offsetFormatters = /* @__PURE__ */ new Map();
|
|
26
|
-
function offsetFormatter(timeZone) {
|
|
27
|
-
let f = offsetFormatters.get(timeZone);
|
|
28
|
-
if (!f) {
|
|
29
|
-
f = new Intl.DateTimeFormat("en-US", {
|
|
30
|
-
timeZone,
|
|
31
|
-
hourCycle: "h23",
|
|
32
|
-
year: "numeric",
|
|
33
|
-
month: "2-digit",
|
|
34
|
-
day: "2-digit",
|
|
35
|
-
hour: "2-digit",
|
|
36
|
-
minute: "2-digit",
|
|
37
|
-
second: "2-digit",
|
|
38
|
-
weekday: "short"
|
|
39
|
-
});
|
|
40
|
-
offsetFormatters.set(timeZone, f);
|
|
41
|
-
}
|
|
42
|
-
return f;
|
|
43
|
-
}
|
|
44
|
-
var WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
45
|
-
var pad = (n) => String(n).padStart(2, "0");
|
|
46
|
-
function localParts(at, timeZone) {
|
|
47
|
-
const ms = typeof at === "number" ? at : new Date(at).getTime();
|
|
48
|
-
const parts = Object.fromEntries(
|
|
49
|
-
offsetFormatter(timeZone).formatToParts(new Date(ms)).map((p) => [p.type, p.value])
|
|
50
|
-
);
|
|
51
|
-
const year = Number(parts.year);
|
|
52
|
-
const month = Number(parts.month);
|
|
53
|
-
const day = Number(parts.day);
|
|
54
|
-
const hour = Number(parts.hour) % 24;
|
|
55
|
-
const minute = Number(parts.minute);
|
|
56
|
-
const second = Number(parts.second);
|
|
57
|
-
return {
|
|
58
|
-
year,
|
|
59
|
-
month,
|
|
60
|
-
day,
|
|
61
|
-
hour,
|
|
62
|
-
minute,
|
|
63
|
-
second,
|
|
64
|
-
weekday: WEEKDAYS.indexOf(String(parts.weekday)) + 1,
|
|
65
|
-
date: `${year}-${pad(month)}-${pad(day)}`,
|
|
66
|
-
minuteOfDay: hour * 60 + minute
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
var HOUR = 36e5;
|
|
70
|
-
function wallClockToInstant(wall, timeZone) {
|
|
71
|
-
const asUtc = Date.UTC(
|
|
72
|
-
wall.year,
|
|
73
|
-
wall.month - 1,
|
|
74
|
-
wall.day,
|
|
75
|
-
wall.hour ?? 0,
|
|
76
|
-
wall.minute ?? 0,
|
|
77
|
-
wall.second ?? 0
|
|
78
|
-
);
|
|
79
|
-
const before = zoneOffset(asUtc - 14 * HOUR, timeZone);
|
|
80
|
-
const after = zoneOffset(asUtc + 14 * HOUR, timeZone);
|
|
81
|
-
const reads = (at) => {
|
|
82
|
-
const p = localParts(at, timeZone);
|
|
83
|
-
return Date.UTC(p.year, p.month - 1, p.day, p.hour, p.minute, p.second) === asUtc - (asUtc % 1e3 + 1e3) % 1e3;
|
|
84
|
-
};
|
|
85
|
-
const candidates = [asUtc - before, asUtc - after].filter(reads).sort((a, b) => a - b);
|
|
86
|
-
return candidates[0] ?? asUtc - before;
|
|
87
|
-
}
|
|
88
|
-
function wallClockToIso(wall, timeZone) {
|
|
89
|
-
return new Date(wallClockToInstant(wall, timeZone)).toISOString();
|
|
90
|
-
}
|
|
91
|
-
function addLocalDays(date, days) {
|
|
92
|
-
const at = new Date(Date.UTC(date.year, date.month - 1, date.day + days));
|
|
93
|
-
return { year: at.getUTCFullYear(), month: at.getUTCMonth() + 1, day: at.getUTCDate() };
|
|
94
|
-
}
|
|
95
|
-
function parseLocalDate(date) {
|
|
96
|
-
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
|
|
97
|
-
if (!match) return null;
|
|
98
|
-
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
99
|
-
return realWallClock(year, month, day) ? { year, month, day } : null;
|
|
100
|
-
}
|
|
101
|
-
function requireDate(date) {
|
|
102
|
-
const parts = parseLocalDate(date);
|
|
103
|
-
if (!parts) throw new RangeError(`Not a date: ${date}`);
|
|
104
|
-
return parts;
|
|
105
|
-
}
|
|
106
|
-
function parseLocalTime(time) {
|
|
107
|
-
const match = /^(\d{2}):(\d{2})$/.exec(time.trim());
|
|
108
|
-
if (!match) return null;
|
|
109
|
-
const [h, mi] = [Number(match[1]), Number(match[2])];
|
|
110
|
-
return h < 24 && mi < 60 ? h * 60 + mi : null;
|
|
111
|
-
}
|
|
112
|
-
function wallClockOf(date, minutes) {
|
|
113
|
-
return { ...requireDate(date), hour: Math.floor(minutes / 60), minute: minutes % 60 };
|
|
114
|
-
}
|
|
115
|
-
function isoWeekday(date) {
|
|
116
|
-
const d = requireDate(date);
|
|
117
|
-
const day = new Date(Date.UTC(d.year, d.month - 1, d.day)).getUTCDay();
|
|
118
|
-
return day === 0 ? 7 : day;
|
|
119
|
-
}
|
|
120
|
-
function localDaysBefore(at, days, timeZone) {
|
|
121
|
-
const p = localParts(at, timeZone);
|
|
122
|
-
const date = addLocalDays(p, -days);
|
|
123
|
-
const ms = (at % 1e3 + 1e3) % 1e3;
|
|
124
|
-
const wall = { ...date, hour: p.hour, minute: p.minute, second: p.second };
|
|
125
|
-
return wallClockToInstant(wall, timeZone) + ms;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ../core/src/orders/settings.ts
|
|
129
|
-
var ORDER_CURRENCY_SETTING = "order_currency";
|
|
130
|
-
var ORDER_EXPIRY_SETTING = "order_expiry_minutes";
|
|
131
|
-
var ORDER_MIN_PART_SETTING = "order_min_part_payment";
|
|
132
|
-
var currencySchema = external_exports.string().trim().transform((value) => value.toUpperCase()).pipe(external_exports.string().regex(/^[A-Z]{3}$/, "A currency is three letters, such as AUD")).refine(isKnownCurrency, "Not a currency this platform knows");
|
|
133
|
-
var DEFAULT_ORDER_EXPIRY_MINUTES = 15;
|
|
134
|
-
var orderExpiryMinutesSchema = external_exports.number().int().min(5).max(1440);
|
|
135
|
-
var DEFAULT_MIN_PART_PAYMENT = 1e3;
|
|
136
|
-
var minPartPaymentSchema = external_exports.number().int().min(1).max(1e8);
|
|
137
|
-
function isKnownCurrency(code) {
|
|
138
|
-
return Intl.supportedValuesOf("currency").includes(code);
|
|
139
|
-
}
|
|
140
|
-
function currencyDecimals(currency) {
|
|
141
|
-
return new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions().maximumFractionDigits ?? 2;
|
|
142
|
-
}
|
|
143
|
-
function toMinorUnits(price, currency) {
|
|
144
|
-
if (typeof price !== "number" || !Number.isFinite(price) || price < 0) return null;
|
|
145
|
-
const scaled = price * 10 ** currencyDecimals(currency);
|
|
146
|
-
const minor = Math.round(scaled);
|
|
147
|
-
return Math.abs(scaled - minor) < 1e-6 && Number.isSafeInteger(minor) ? minor : null;
|
|
148
|
-
}
|
|
149
|
-
async function loadSetting(db, key, schema) {
|
|
150
|
-
return load(db, key, schema);
|
|
151
|
-
}
|
|
152
|
-
async function load(db, key, schema) {
|
|
153
|
-
const row = await db.selectFrom("core_settings").select("value").where("key", "=", key).executeTakeFirst();
|
|
154
|
-
if (!row) return null;
|
|
155
|
-
try {
|
|
156
|
-
const parsed = schema.safeParse(JSON.parse(row.value));
|
|
157
|
-
return parsed.success ? parsed.data : null;
|
|
158
|
-
} catch {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function loadOrderCurrency(db) {
|
|
163
|
-
return load(db, ORDER_CURRENCY_SETTING, currencySchema);
|
|
164
|
-
}
|
|
165
|
-
async function loadOrderExpiryMinutes(db) {
|
|
166
|
-
return await load(db, ORDER_EXPIRY_SETTING, orderExpiryMinutesSchema) ?? DEFAULT_ORDER_EXPIRY_MINUTES;
|
|
167
|
-
}
|
|
168
|
-
async function loadMinPartPayment(db) {
|
|
169
|
-
return await load(db, ORDER_MIN_PART_SETTING, minPartPaymentSchema) ?? DEFAULT_MIN_PART_PAYMENT;
|
|
170
|
-
}
|
|
171
|
-
var ORDER_TAX_SETTING = "order_tax";
|
|
172
|
-
var ORDER_TAX_CODES_SETTING = "order_tax_codes";
|
|
173
|
-
var taxCodeSchema = external_exports.string().trim().regex(/^txcd_\d{8}$/, "A product tax code is txcd_ and eight digits, from Stripe's list");
|
|
174
|
-
var taxCodesSchema = external_exports.record(external_exports.string().min(1).max(80), taxCodeSchema);
|
|
175
|
-
async function loadOrderTax(db) {
|
|
176
|
-
return await load(db, ORDER_TAX_SETTING, external_exports.boolean()) ?? false;
|
|
177
|
-
}
|
|
178
|
-
async function loadOrderTaxCodes(db) {
|
|
179
|
-
return await load(db, ORDER_TAX_CODES_SETTING, taxCodesSchema) ?? {};
|
|
180
|
-
}
|
|
181
|
-
var ORDER_RETURN_ORIGINS_SETTING = "order_return_origins";
|
|
182
|
-
var ORDER_RETURN_ORIGINS_MAX = 20;
|
|
183
|
-
var returnOriginSchema = external_exports.string().trim().max(200).transform((value, ctx) => {
|
|
184
|
-
const origin = originOf(value);
|
|
185
|
-
if (!origin || origin !== value.replace(/\/+$/, "")) {
|
|
186
|
-
ctx.addIssue({
|
|
187
|
-
code: "custom",
|
|
188
|
-
message: "An origin is https://host (or http://localhost:port), with no path"
|
|
189
|
-
});
|
|
190
|
-
return external_exports.NEVER;
|
|
191
|
-
}
|
|
192
|
-
return origin;
|
|
193
|
-
});
|
|
194
|
-
var returnOriginsSchema = external_exports.array(returnOriginSchema).max(ORDER_RETURN_ORIGINS_MAX);
|
|
195
|
-
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
196
|
-
function originOf(url) {
|
|
197
|
-
let parsed;
|
|
198
|
-
try {
|
|
199
|
-
parsed = new URL(url);
|
|
200
|
-
} catch {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
if (parsed.username || parsed.password) return null;
|
|
204
|
-
if (parsed.protocol === "https:") return parsed.origin;
|
|
205
|
-
if (parsed.protocol === "http:" && LOCAL_HOSTS.has(parsed.hostname)) return parsed.origin;
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
async function loadReturnOrigins(db) {
|
|
209
|
-
return await load(db, ORDER_RETURN_ORIGINS_SETTING, returnOriginsSchema) ?? [];
|
|
210
|
-
}
|
|
211
|
-
function isAllowedReturnUrl(url, origins) {
|
|
212
|
-
const origin = originOf(url);
|
|
213
|
-
return origin !== null && url.length <= 2e3 && origins.includes(origin);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
zoneOffset,
|
|
218
|
-
realWallClock,
|
|
219
|
-
localParts,
|
|
220
|
-
wallClockToInstant,
|
|
221
|
-
wallClockToIso,
|
|
222
|
-
addLocalDays,
|
|
223
|
-
parseLocalDate,
|
|
224
|
-
parseLocalTime,
|
|
225
|
-
wallClockOf,
|
|
226
|
-
isoWeekday,
|
|
227
|
-
localDaysBefore,
|
|
228
|
-
ORDER_CURRENCY_SETTING,
|
|
229
|
-
ORDER_EXPIRY_SETTING,
|
|
230
|
-
ORDER_MIN_PART_SETTING,
|
|
231
|
-
currencySchema,
|
|
232
|
-
orderExpiryMinutesSchema,
|
|
233
|
-
minPartPaymentSchema,
|
|
234
|
-
currencyDecimals,
|
|
235
|
-
toMinorUnits,
|
|
236
|
-
loadSetting,
|
|
237
|
-
loadOrderCurrency,
|
|
238
|
-
loadOrderExpiryMinutes,
|
|
239
|
-
loadMinPartPayment,
|
|
240
|
-
ORDER_TAX_SETTING,
|
|
241
|
-
ORDER_TAX_CODES_SETTING,
|
|
242
|
-
taxCodesSchema,
|
|
243
|
-
loadOrderTax,
|
|
244
|
-
loadOrderTaxCodes,
|
|
245
|
-
ORDER_RETURN_ORIGINS_SETTING,
|
|
246
|
-
returnOriginsSchema,
|
|
247
|
-
loadReturnOrigins,
|
|
248
|
-
isAllowedReturnUrl
|
|
249
|
-
};
|