@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.13
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-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
- package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
- package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
- package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
- package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
- package/dist/chunk-KMFMD52Z.js +13276 -0
- package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
- package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
- package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
- package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
- package/dist/cli.js +5 -5
- package/dist/{client-repo-SE4EKG6W.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
- package/dist/gateway-DPPEQZT4.js +25 -0
- package/dist/grants-6JY4XZO7.js +27 -0
- package/dist/invoke-MRONRZ5Q.js +33 -0
- package/dist/moves-UAUCMWL5.js +36 -0
- package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0730_practitioners.sql +79 -0
- package/dist/platform/migrations/0750_routine_mail.sql +98 -0
- package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
- package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
- package/dist/platform/migrations/0811_staff_time.sql +109 -0
- package/dist/platform/migrations/0812_staff_offers.sql +112 -0
- package/dist/platform/migrations/0813_pay_periods.sql +241 -0
- package/dist/platform/migrations/0814_staff_feed.sql +47 -0
- package/dist/platform/migrations/0815_checklists.sql +237 -0
- package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
- package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
- package/dist/platform/migrations/0850_agreements.sql +271 -0
- package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
- package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
- package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
- package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
- package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
- package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
- package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
- package/dist/platform/migrations/0910_routine_messages.sql +99 -0
- package/dist/platform/migrations/0911_texts.sql +60 -0
- package/dist/platform/migrations/0913_contact_consent.sql +93 -0
- package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
- package/dist/platform/migrations/0930_stock_movements.sql +95 -0
- package/dist/platform/migrations/0931_stock_low.sql +25 -0
- package/dist/platform/migrations/0932_order_delivery.sql +78 -0
- package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
- package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
- package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
- package/dist/platform/migrations/0953_discount_uses.sql +183 -0
- package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
- package/dist/platform/migrations/0970_published_text.sql +59 -0
- package/dist/platform/migrations/0971_publish_acks.sql +68 -0
- package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
- package/dist/platform/migrations/1010_intake_links.sql +148 -0
- package/dist/platform/migrations/1030_invoices.sql +747 -0
- package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
- package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
- package/dist/platform/migrations/1090_staff_hours.sql +43 -0
- package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
- package/dist/platform/migrations/1092_client_guard.sql +26 -0
- package/dist/platform/migrations/1095_thing_time.sql +70 -0
- package/dist/platform/migrations/1130_devices.sql +162 -0
- package/dist/platform/migrations/1135_person_codes.sql +88 -0
- package/dist/platform/migrations/1150_finance_periods.sql +316 -0
- package/dist/platform/migrations/1151_payouts.sql +202 -0
- package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
- package/dist/platform/migrations/1170_journeys.sql +318 -0
- package/dist/platform/migrations/1171_person_birthday.sql +52 -0
- package/dist/platform/migrations/1175_person_signals.sql +29 -0
- package/dist/platform/migrations/1190_restricted_values.sql +25 -0
- package/dist/platform/migrations/1230_note_levels.sql +113 -0
- package/dist/platform/migrations/1231_person_carers.sql +33 -0
- package/dist/platform/migrations/1232_note_kinds.sql +122 -0
- package/dist/platform/migrations/1270_time_entries.sql +145 -0
- package/dist/platform/migrations/1271_leave.sql +249 -0
- package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
- package/dist/platform/migrations/1330_accounting.sql +260 -0
- package/dist/platform/migrations/1350_customer_feed.sql +24 -0
- package/dist/platform/migrations/1390_locations.sql +77 -0
- package/dist/platform/migrations/1410_outside_copy.sql +213 -0
- package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
- package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
- package/dist/platform/sdk/acknowledge.ts +100 -0
- package/dist/platform/sdk/agreements.ts +185 -0
- package/dist/platform/sdk/allowance.ts +98 -8
- package/dist/platform/sdk/automation-check.ts +120 -9
- package/dist/platform/sdk/automation.ts +78 -10
- package/dist/platform/sdk/behaviour.ts +26 -6
- package/dist/platform/sdk/calendar-entry.ts +258 -0
- package/dist/platform/sdk/capacity.ts +1 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +489 -27
- package/dist/platform/sdk/discount.ts +408 -0
- package/dist/platform/sdk/document.ts +4 -2
- package/dist/platform/sdk/field-types.ts +5 -0
- package/dist/platform/sdk/formula/compile.ts +10 -0
- package/dist/platform/sdk/index.ts +17 -0
- package/dist/platform/sdk/intake.ts +380 -0
- package/dist/platform/sdk/journey-signals.ts +215 -0
- package/dist/platform/sdk/manifest.ts +1236 -65
- package/dist/platform/sdk/mine.ts +161 -0
- package/dist/platform/sdk/occupies.ts +192 -0
- package/dist/platform/sdk/questions.ts +681 -0
- package/dist/platform/sdk/recurring.ts +90 -9
- package/dist/platform/sdk/restricted-fields.ts +129 -0
- package/dist/platform/sdk/rich-text.ts +112 -0
- package/dist/platform/sdk/routine-mail.ts +1272 -0
- package/dist/platform/sdk/runtime.ts +25 -12
- package/dist/platform/sdk/screens.ts +91 -0
- package/dist/platform/sdk/sellable.ts +344 -0
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +68 -26
- package/dist/platform/sdk/stock.ts +332 -0
- package/dist/platform/sdk/team.ts +83 -0
- package/dist/platform/sdk/testing.ts +70 -6
- package/dist/platform/sdk/worked-on.ts +134 -0
- package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
- package/dist/run-7ID64RA6.js +65 -0
- package/dist/run-FH7OGGTV.js +131 -0
- package/dist/run-OYZIAP6M.js +3363 -0
- package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
- package/package.json +2 -2
- package/dist/chunk-2TWV3SVB.js +0 -349
- package/dist/chunk-2XC5JLBO.js +0 -1931
- package/dist/chunk-324WJXNP.js +0 -320
- package/dist/chunk-6ELZRNUU.js +0 -116
- package/dist/chunk-6WGFA2IV.js +0 -643
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-7OGCMQXG.js +0 -284
- package/dist/chunk-FJIZGS5Q.js +0 -698
- package/dist/chunk-UB4I2QKR.js +0 -31575
- package/dist/chunk-WHKJGF36.js +0 -2418
- package/dist/chunk-YNUZRTPH.js +0 -182
- package/dist/chunk-ZZFWMVJO.js +0 -704
- package/dist/grants-LOW6TSWD.js +0 -32
- package/dist/invoke-6KVT6WJI.js +0 -41
- package/dist/moves-E2HKYCTK.js +0 -41
- package/dist/plan-on-sale-TJPFCNL7.js +0 -26
- package/dist/src-CRO35DYY.js +0 -46
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../core/src/errors.ts
|
|
4
|
+
var OperationError = class extends Error {
|
|
5
|
+
constructor(code, message, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.details = details;
|
|
9
|
+
}
|
|
10
|
+
code;
|
|
11
|
+
details;
|
|
12
|
+
name = "OperationError";
|
|
13
|
+
toJSON() {
|
|
14
|
+
return {
|
|
15
|
+
code: this.code,
|
|
16
|
+
message: this.message,
|
|
17
|
+
...this.details === void 0 ? {} : { details: this.details }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var UnknownOperationError = class extends OperationError {
|
|
22
|
+
name = "UnknownOperationError";
|
|
23
|
+
constructor(name) {
|
|
24
|
+
super("unknown_operation", `No operation named "${name}"`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var ValidationError = class extends OperationError {
|
|
28
|
+
name = "ValidationError";
|
|
29
|
+
constructor(message, details) {
|
|
30
|
+
super("invalid_input", message, details);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var ForbiddenError = class extends OperationError {
|
|
34
|
+
name = "ForbiddenError";
|
|
35
|
+
constructor(message, details) {
|
|
36
|
+
super("forbidden", message, details);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var GateDeniedError = class extends OperationError {
|
|
40
|
+
name = "GateDeniedError";
|
|
41
|
+
constructor(message, details) {
|
|
42
|
+
super("denied", message, details);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var PendingApprovalError = class extends OperationError {
|
|
46
|
+
name = "PendingApprovalError";
|
|
47
|
+
pending;
|
|
48
|
+
constructor(pending) {
|
|
49
|
+
super("pending_approval", pending.message, pending);
|
|
50
|
+
this.pending = pending;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var RunsOnApprovalError = class extends OperationError {
|
|
54
|
+
constructor(uses) {
|
|
55
|
+
super(
|
|
56
|
+
"runs_on_approval",
|
|
57
|
+
`This uses ${uses}, which a dry run does not touch: it runs only when it is approved`,
|
|
58
|
+
{ uses }
|
|
59
|
+
);
|
|
60
|
+
this.uses = uses;
|
|
61
|
+
}
|
|
62
|
+
uses;
|
|
63
|
+
name = "RunsOnApprovalError";
|
|
64
|
+
};
|
|
65
|
+
var TRY_LATER = "Too many places are being held for payment just now: try again shortly";
|
|
66
|
+
var RateLimitedError = class extends OperationError {
|
|
67
|
+
name = "RateLimitedError";
|
|
68
|
+
constructor(message, details) {
|
|
69
|
+
super("rate_limited", message, details);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var PlanLimitError = class extends OperationError {
|
|
73
|
+
name = "PlanLimitError";
|
|
74
|
+
constructor(message, details) {
|
|
75
|
+
super("plan_limit", message, details);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var SignInAgainError = class extends OperationError {
|
|
79
|
+
name = "SignInAgainError";
|
|
80
|
+
constructor(withinMinutes) {
|
|
81
|
+
super(
|
|
82
|
+
"sign_in_again",
|
|
83
|
+
`Sign in again first: this needs a sign-in within ${withinMinutes} minutes`,
|
|
84
|
+
{
|
|
85
|
+
withinMinutes
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var NotFoundError = class extends OperationError {
|
|
91
|
+
name = "NotFoundError";
|
|
92
|
+
constructor(object, id) {
|
|
93
|
+
super("not_found", `No ${object} with id ${id}`, { object, id });
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var ConflictError = class extends OperationError {
|
|
97
|
+
name = "ConflictError";
|
|
98
|
+
constructor(message, details) {
|
|
99
|
+
super("conflict", message, details);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var NeedsOwnApprovalError = class extends ConflictError {
|
|
103
|
+
name = "NeedsOwnApprovalError";
|
|
104
|
+
constructor(operation, calls) {
|
|
105
|
+
super(
|
|
106
|
+
`${operation} calls ${calls}, which needs its own approval, so it cannot be applied as one change: nothing of it was applied. Ask for ${calls} on its own, or reject this.`,
|
|
107
|
+
{ needsOwnApproval: calls, operation }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var ConfigError = class extends OperationError {
|
|
112
|
+
name = "ConfigError";
|
|
113
|
+
constructor(message) {
|
|
114
|
+
super("config", message);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var declaredUniqueKeys = /* @__PURE__ */ new Set();
|
|
118
|
+
function setDeclaredUniqueKeys(keys) {
|
|
119
|
+
declaredUniqueKeys = keys;
|
|
120
|
+
}
|
|
121
|
+
function toOperationError(error) {
|
|
122
|
+
if (error instanceof OperationError) return error;
|
|
123
|
+
if (error instanceof Error && error.name === "AiAllowanceError") {
|
|
124
|
+
return new PlanLimitError(error.message, { reason: "platform_ai" });
|
|
125
|
+
}
|
|
126
|
+
const capacity = capacityRefusal(error);
|
|
127
|
+
if (capacity) return capacity;
|
|
128
|
+
const allowance = allowanceRefusal(error);
|
|
129
|
+
if (allowance) return allowance;
|
|
130
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
131
|
+
if (message.includes("core_stock_opening_exists")) {
|
|
132
|
+
return new ConflictError(
|
|
133
|
+
"This record already has its opening stock; correct it with stock.adjust",
|
|
134
|
+
{ rule: "stock", reason: "opening_exists" }
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (message.includes("core_stock_movement_immutable")) {
|
|
138
|
+
return new ConflictError("A stock movement is never changed or removed", {
|
|
139
|
+
rule: "stock",
|
|
140
|
+
reason: "movement_immutable"
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (message.includes("core_order_stale")) {
|
|
144
|
+
return new ConflictError("The order changed while this was being applied. Try again.", {
|
|
145
|
+
reason: "order_stale"
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (message.includes("core_order_checkout_open")) {
|
|
149
|
+
return new ConflictError(
|
|
150
|
+
"The payment page for this order is already open, so its price cannot change: cancel it and start a new one",
|
|
151
|
+
{ rule: "checkout_open" }
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (message.includes("core_order_checkout_stale")) {
|
|
155
|
+
return new ConflictError(
|
|
156
|
+
"The order's price changed while its payment page was being opened. Pay again for the new price.",
|
|
157
|
+
{ rule: "price_changed" }
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (message.includes("UNIQUE constraint failed: core_order_payment.reverses")) {
|
|
161
|
+
return new ConflictError("This payment has already been reversed", {
|
|
162
|
+
rule: "payment_guard",
|
|
163
|
+
reason: "reversed"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const guard = /\b(core_order_(?:payment|refund)_[a-z]+)\b/.exec(message)?.[1];
|
|
167
|
+
if (guard && !message.includes("UNIQUE constraint failed")) {
|
|
168
|
+
return new ConflictError("This payment cannot be recorded that way", {
|
|
169
|
+
rule: "payment_guard",
|
|
170
|
+
reason: guard
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (message.includes("core_subscription_stale")) {
|
|
174
|
+
return new ConflictError("The subscription changed while this was being applied. Try again.", {
|
|
175
|
+
reason: "subscription_stale"
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (message.includes("core_subscription_trial_taken")) {
|
|
179
|
+
return new ConflictError(
|
|
180
|
+
"A checkout with this free trial was opened at the same moment. Start again to get it.",
|
|
181
|
+
{ rule: "trial_held" }
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (message.includes("UNIQUE constraint failed: core_sellable_once") || message.includes("core_sellable_once_folded")) {
|
|
185
|
+
return new ConflictError(
|
|
186
|
+
"This is one per person, and another order for it was started at the same moment",
|
|
187
|
+
{ rule: "once_per_person", reason: "held" }
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (message.includes("core_discount_use_limit")) {
|
|
191
|
+
return new ValidationError("This code is not valid here", {
|
|
192
|
+
rule: "code_not_valid",
|
|
193
|
+
field: "code"
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (message.includes("core_discount_use_auto_limit")) {
|
|
197
|
+
return new ConflictError(
|
|
198
|
+
"A price on this order was used up by another order at the same moment. Start again.",
|
|
199
|
+
{ rule: "deal_taken" }
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (message.includes("UNIQUE constraint failed: core_subscription_grant")) {
|
|
203
|
+
return new ConflictError(
|
|
204
|
+
"This subscription's grant was made by another event at the same moment. Try again.",
|
|
205
|
+
{ reason: "subscription_grant" }
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
if (message.includes("core_subscription_offer_held")) {
|
|
209
|
+
return new ConflictError(
|
|
210
|
+
"A checkout for this offer was opened at the same moment, or the offer was taken or withdrawn. Start again.",
|
|
211
|
+
{ rule: "offer_held" }
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
if (message.includes("core_subscription_offer_stale")) {
|
|
215
|
+
return new ConflictError(
|
|
216
|
+
"The offer changed while this was being done, so nothing was changed. Try again.",
|
|
217
|
+
{ rule: "offer_changed" }
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
if (message.includes("UNIQUE constraint failed: core_subscription_offer")) {
|
|
221
|
+
return new ConflictError(
|
|
222
|
+
"Another import wrote one of these offers at the same moment. Run the import again.",
|
|
223
|
+
{ rule: "offer_key" }
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (message.includes(
|
|
227
|
+
"UNIQUE constraint failed: core_transition_history.object_type, core_transition_history.record_id"
|
|
228
|
+
)) {
|
|
229
|
+
return new ConflictError(
|
|
230
|
+
"The record was moved by another change while this one was being made, so nothing was changed. Read it again: it may already be where you wanted it.",
|
|
231
|
+
{ reason: "moved_meanwhile" }
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (message.includes("UNIQUE constraint failed: core_publish_version")) {
|
|
235
|
+
return new ConflictError(
|
|
236
|
+
"Another version of this record was published at the same moment, so this one was not. Read its versions again before publishing.",
|
|
237
|
+
{ reason: "published_meanwhile" }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (message.includes("UNIQUE constraint failed: core_publish_ack")) {
|
|
241
|
+
return new ConflictError("You have already confirmed this version", {
|
|
242
|
+
reason: "already_confirmed"
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (message.includes("core_publish_ack_not_current")) {
|
|
246
|
+
return new ConflictError(
|
|
247
|
+
"A newer version was published meanwhile: read it again and confirm that one",
|
|
248
|
+
{ reason: "not_current" }
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (message.includes("core_publish_ack_not_a_person")) {
|
|
252
|
+
return new ForbiddenError("Only a person's own live account confirms", {
|
|
253
|
+
reason: "not_a_person"
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (message.includes("core_publish_ack_immutable")) {
|
|
257
|
+
return new ForbiddenError("A confirmation is never changed or deleted", {
|
|
258
|
+
reason: "immutable"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (message.includes("core_email_change_closed") || message.includes("UNIQUE constraint failed: core_customer_email_change.customer_id")) {
|
|
262
|
+
return new ConflictError(
|
|
263
|
+
"This address change was confirmed, cancelled or replaced meanwhile, so nothing was changed. Look at the account again.",
|
|
264
|
+
{ rule: "email_change_closed" }
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
if (message.includes("core_recurrence_stale")) {
|
|
268
|
+
return new ConflictError(
|
|
269
|
+
"The schedule or a booking changed while this was being done, so nothing was changed. Try again.",
|
|
270
|
+
{ rule: "recurring_stale" }
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
if (message.includes("core_staff_double_booked")) {
|
|
274
|
+
return new ConflictError(
|
|
275
|
+
"This person is already on another shift at that time, so nothing was changed.",
|
|
276
|
+
{ rule: "double_booked" }
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (message.includes("core_time_overlap")) {
|
|
280
|
+
return new ConflictError(
|
|
281
|
+
"This overlaps another of this person's time entries, so nothing was changed.",
|
|
282
|
+
{ rule: "time_overlap" }
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (message.includes("core_time_open") || message.includes("UNIQUE constraint failed: core_time_entry.account_id")) {
|
|
286
|
+
return new ConflictError("An entry is already open: finish it first, so nothing was changed.", {
|
|
287
|
+
rule: "time_open"
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (message.includes("core_thing_double_booked")) {
|
|
291
|
+
return new ConflictError("That room is already taken at that time, so nothing was changed.", {
|
|
292
|
+
rule: "room_taken"
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (message.includes("core_client_busy")) {
|
|
296
|
+
return new ConflictError(
|
|
297
|
+
"That time is not free. Nothing was changed: choose another free time.",
|
|
298
|
+
{ rule: "not_free_time" }
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (message.includes("core_intake_link_used")) {
|
|
302
|
+
return new OperationError(
|
|
303
|
+
"not_found",
|
|
304
|
+
"This link cannot be used: it may have been used already or have expired",
|
|
305
|
+
{ rule: "personal_link" }
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
if (message.includes("core_intake_link_fixed")) {
|
|
309
|
+
return new ConflictError(
|
|
310
|
+
"A personal link never changes what it is for, so nothing was changed.",
|
|
311
|
+
{
|
|
312
|
+
rule: "personal_link_fixed"
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
if (message.includes("core_staff_offer_closed")) {
|
|
317
|
+
return new ConflictError(
|
|
318
|
+
"This offer was taken, withdrawn or closed a moment before, so nothing was changed. Look again.",
|
|
319
|
+
{ rule: "offer_closed" }
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
if (message.includes("core_staff_offer_open") || message.includes("UNIQUE constraint failed: core_staff_offer")) {
|
|
323
|
+
return new ConflictError("This shift is already offered, so nothing was changed.", {
|
|
324
|
+
rule: "offer_open"
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (message.includes("core_note_changed")) {
|
|
328
|
+
return new ConflictError(
|
|
329
|
+
"The note's level changed while this was being done, so nothing was changed. Try again.",
|
|
330
|
+
{ rule: "note_changed" }
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
if (message.includes("core_staff_changed")) {
|
|
334
|
+
return new ConflictError(
|
|
335
|
+
"The roster changed while this was being done, so nothing was changed. Try again.",
|
|
336
|
+
{ rule: "roster_changed" }
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
if (message.includes("core_staff_offer_fixed") || message.includes("core_staff_offer_replaced")) {
|
|
340
|
+
return new ConflictError("An offer is never changed or replaced, so nothing was changed.", {
|
|
341
|
+
rule: "offer_fixed"
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (message.includes("core_finance_changed")) {
|
|
345
|
+
return new ConflictError(
|
|
346
|
+
"The figures changed while this month was being closed, so it was not closed. Try again.",
|
|
347
|
+
{ rule: "finance_changed" }
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (message.includes("core_finance_period_held") || message.includes("core_finance_period_overlap")) {
|
|
351
|
+
return new ConflictError(
|
|
352
|
+
"This month is already closed, or being closed, so nothing was changed.",
|
|
353
|
+
{
|
|
354
|
+
rule: "finance_period_closed"
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
if (message.includes("core_finance_period_order")) {
|
|
359
|
+
return new ConflictError(
|
|
360
|
+
"Months are closed and reopened in order, and another close or reopen landed first, so nothing was changed. Look again.",
|
|
361
|
+
{ rule: "finance_order" }
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
if (message.includes("core_finance_period_fixed") || message.includes("core_finance_counted_twice")) {
|
|
365
|
+
return new ConflictError("A closed month's figures never change, so nothing was changed.", {
|
|
366
|
+
rule: "finance_period_fixed"
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
if (message.includes("core_payout_fixed")) {
|
|
370
|
+
return new ConflictError("A recorded payout never changes, so nothing was changed.", {
|
|
371
|
+
rule: "payout_fixed"
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
if (message.includes("core_checklist_closed")) {
|
|
375
|
+
return new ConflictError(
|
|
376
|
+
"This checklist is closed (done, missed or cancelled), so nothing of it was changed.",
|
|
377
|
+
{ rule: "checklist_closed" }
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (message.includes("core_checklist_not_allowed")) {
|
|
381
|
+
return new ForbiddenError(
|
|
382
|
+
"You may not tick or finish this checklist, so nothing was changed.",
|
|
383
|
+
{
|
|
384
|
+
rule: "checklist_not_allowed"
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
if (message.includes("core_checklist_window")) {
|
|
389
|
+
return new ConflictError(
|
|
390
|
+
"This checklist is ticked on its own day only, and missed only after it.",
|
|
391
|
+
{
|
|
392
|
+
rule: "checklist_window"
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
if (message.includes("core_checklist_incomplete")) {
|
|
397
|
+
return new ValidationError(
|
|
398
|
+
"Not every required step of this checklist is ticked, so it was not marked done.",
|
|
399
|
+
{ rule: "checklist_incomplete" }
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
if (message.includes("core_checklist_note_needed")) {
|
|
403
|
+
return new ValidationError(
|
|
404
|
+
"This step asks for a note, so it was not ticked done without one.",
|
|
405
|
+
{
|
|
406
|
+
rule: "checklist_note_needed"
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
if (message.includes("core_checklist_too_many_ticks")) {
|
|
411
|
+
return new ConflictError("This step has been ticked 50 times, the most one step takes.", {
|
|
412
|
+
rule: "checklist_too_many_ticks"
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (message.includes("core_checklist_fixed")) {
|
|
416
|
+
return new ConflictError(
|
|
417
|
+
"A checklist run's steps and record never change, so nothing was changed.",
|
|
418
|
+
{
|
|
419
|
+
rule: "checklist_fixed"
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
if (message.includes("core_pay_period_locked")) {
|
|
424
|
+
return new ConflictError(
|
|
425
|
+
"This is inside a locked pay period, so nothing was changed. Whoever handles pay reopens the period first.",
|
|
426
|
+
{ rule: "pay_period_locked" }
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
if (message.includes("core_pay_period_overlap") || message.includes("core_pay_period_held") || message.includes("UNIQUE constraint failed: core_pay_period")) {
|
|
430
|
+
return new ConflictError(
|
|
431
|
+
"This pay period, or one overlapping it, is already locked, so nothing was changed.",
|
|
432
|
+
{ rule: "pay_period_held" }
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
if (message.includes("core_accounting_post_fixed") || message.includes("UNIQUE constraint failed: core_accounting_post")) {
|
|
436
|
+
return new ConflictError(
|
|
437
|
+
"An entry sent to the books, or skipped, never changes, and nothing is queued twice.",
|
|
438
|
+
{ rule: "accounting_post_fixed" }
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
if (message.includes("core_accounting_start_fixed")) {
|
|
442
|
+
return new ConflictError(
|
|
443
|
+
"Entries were already sent from the start date, so it no longer changes",
|
|
444
|
+
{ rule: "accounting_start_fixed" }
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
if (message.includes("core_pay_period_fixed")) {
|
|
448
|
+
return new ConflictError(
|
|
449
|
+
"A locked pay period and its lines never change, so nothing was changed.",
|
|
450
|
+
{
|
|
451
|
+
rule: "pay_period_fixed"
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
if (message.includes("core_leave_request_closed") || message.includes("core_leave_request_held")) {
|
|
456
|
+
return new ConflictError(
|
|
457
|
+
"This leave request was decided or cancelled a moment before, so nothing was changed. Look again.",
|
|
458
|
+
{ rule: "leave_closed" }
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
if (message.includes("core_leave_request_fixed") || message.includes("core_leave_balance_fixed")) {
|
|
462
|
+
return new ConflictError(
|
|
463
|
+
"What a leave request asked for and the balance ledger never change, so nothing was changed.",
|
|
464
|
+
{ rule: "leave_fixed" }
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
if (message.includes("core_leave_below_zero")) {
|
|
468
|
+
return new ConflictError(
|
|
469
|
+
"This leave would take the balance below zero, which its type does not allow, so nothing was changed.",
|
|
470
|
+
{ rule: "leave_below_zero" }
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
if (message.includes("UNIQUE constraint failed: core_location.name")) {
|
|
474
|
+
return new ConflictError("There is already a location with that name.", {
|
|
475
|
+
rule: "location_name"
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (message.includes("core_location_last_open")) {
|
|
479
|
+
return new ConflictError("This is the only open location, so it cannot be closed.", {
|
|
480
|
+
rule: "last_open_location"
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (message.includes("core_location_main_kept")) {
|
|
484
|
+
return new ConflictError("The main location stays the main location.", {
|
|
485
|
+
rule: "main_location"
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
if (message.includes("core_leave_type_used")) {
|
|
489
|
+
return new ConflictError(
|
|
490
|
+
"Leave or a balance is recorded in this type, so its unit cannot change and it is not removed. Make it inactive instead.",
|
|
491
|
+
{ rule: "leave_type_used" }
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
if (message.includes("UNIQUE constraint failed: core_leave_type")) {
|
|
495
|
+
return new ConflictError("There is already a leave type with that name.", {
|
|
496
|
+
rule: "leave_type_name"
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
if (message.includes("core_staff_time_backwards")) {
|
|
500
|
+
return new ValidationError("A shift must end after it starts, so nothing was changed.", {
|
|
501
|
+
rule: "staffed_time"
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
if (message.includes("core_staff_times_no_record")) {
|
|
505
|
+
return new ValidationError(
|
|
506
|
+
"This shift's times follow a record it does not name, so nothing was changed.",
|
|
507
|
+
{ rule: "times_follow" }
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
if (message.includes("core_staff_time_no_account")) {
|
|
511
|
+
return new ValidationError(
|
|
512
|
+
"This shift needs someone with an account: the profile on it holds none, so nothing was changed.",
|
|
513
|
+
{ rule: "staffed_account" }
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
if (message.includes("core_thing_time_unreadable")) {
|
|
517
|
+
return new ValidationError(
|
|
518
|
+
"A booking of a room needs a start and an end that are real times, so nothing was changed.",
|
|
519
|
+
{ rule: "occupies_time" }
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
if (message.includes("core_staff_time_unreadable")) {
|
|
523
|
+
return new ValidationError(
|
|
524
|
+
"A shift's start and end must be real times, so nothing was changed.",
|
|
525
|
+
{ rule: "staffed_time" }
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
if (message.includes("core_thing_time_backwards")) {
|
|
529
|
+
return new ValidationError(
|
|
530
|
+
"A booking of a room must end after it starts, so nothing was changed.",
|
|
531
|
+
{
|
|
532
|
+
rule: "occupies_time"
|
|
533
|
+
}
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
if (message.includes("core_claim_live")) {
|
|
537
|
+
return new ConflictError(
|
|
538
|
+
"This record took a place while it was being deleted, so it was not. Move it out first.",
|
|
539
|
+
{ rule: "capacity", reason: "claim_live" }
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
if (message.includes("core_birthday_changed")) {
|
|
543
|
+
return new ConflictError(
|
|
544
|
+
"This birthday changed while it was being saved, so nothing was changed. Look again.",
|
|
545
|
+
{ rule: "birthday", reason: "changed_meanwhile" }
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
if (message.includes("core_moved_meanwhile")) {
|
|
549
|
+
return new ConflictError(
|
|
550
|
+
"What this is for changed while it was being made (it may have been cancelled), so nothing was changed. Look again.",
|
|
551
|
+
{ rule: "state_closed", reason: "moved_meanwhile" }
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
if (message.includes("core_holds_capped")) {
|
|
555
|
+
return new RateLimitedError(TRY_LATER, { rule: "try_later" });
|
|
556
|
+
}
|
|
557
|
+
if (message.includes("core_cool_off_used")) {
|
|
558
|
+
return new ConflictError(
|
|
559
|
+
"Cooling off has been used for this member before: it is once per member.",
|
|
560
|
+
{ rule: "cooling_off", reason: "used" }
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
if (message.includes("core_cool_off_exists")) {
|
|
564
|
+
return new ConflictError(
|
|
565
|
+
"A cooling off was asked for this membership a moment ago, so nothing more was asked.",
|
|
566
|
+
{ rule: "cooling_off", reason: "asked" }
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
if (message.includes("core_cool_off_final")) {
|
|
570
|
+
return new ConflictError("This cooling off has already ended, so nothing was changed.", {
|
|
571
|
+
rule: "cooling_off",
|
|
572
|
+
reason: "ended"
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
if (message.includes("core_waitlist_not_full")) {
|
|
576
|
+
return new ConflictError("A place came free meanwhile: claim it instead of waiting.", {
|
|
577
|
+
rule: "waitlist",
|
|
578
|
+
reason: "not_full"
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
if (message.includes("core_document_immutable")) {
|
|
582
|
+
return new ForbiddenError(
|
|
583
|
+
"A sent quote, or an issued invoice or credit note, is never changed or deleted: withdraw the quote, or credit the invoice.",
|
|
584
|
+
{ rule: "document_immutable" }
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
if (message.includes("core_document_stale") || message.includes("core_document_new")) {
|
|
588
|
+
return new ConflictError(
|
|
589
|
+
"The draft changed while you were changing it (someone else saved it). Look at it again; nothing was changed.",
|
|
590
|
+
{ rule: "document_changed" }
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
if (message.includes("core_document_number") || message.includes("core_document_counter_back") || message.includes("UNIQUE constraint failed: core_quote.number_seq") || message.includes("UNIQUE constraint failed: core_invoice.number_seq") || message.includes("UNIQUE constraint failed: core_credit_note.number_seq")) {
|
|
594
|
+
return new ConflictError(
|
|
595
|
+
"The numbering changed meanwhile (a number was given, or the series was changed). Look at it again; no number was used.",
|
|
596
|
+
{ rule: "document_numbering" }
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
if (message.includes("core_invoice_event_immutable")) {
|
|
600
|
+
return new ForbiddenError("The invoice log is never changed: rows are only added.", {
|
|
601
|
+
rule: "invoice_event_immutable"
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
if (message.includes("core_agreement_version_immutable")) {
|
|
605
|
+
return new ForbiddenError("A published version of a document is never changed or deleted.", {
|
|
606
|
+
rule: "agreement_version_immutable"
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
if (message.includes("core_agreement_draft_changed") || message.includes("UNIQUE constraint failed: core_agreement_version")) {
|
|
610
|
+
return new ConflictError(
|
|
611
|
+
"The document changed while you were publishing it. Look at it again; nothing was published.",
|
|
612
|
+
{ rule: "agreement_draft_changed" }
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
if (message.includes("core_agreement_retired") || message.includes("core_agreement_not_live")) {
|
|
616
|
+
return new ConflictError("This document is not live: it cannot change there.", {
|
|
617
|
+
rule: "agreement_not_live"
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
if (message.includes("core_agreement_agree_from_back") || message.includes("core_agreement_rev_back")) {
|
|
621
|
+
return new ConflictError("What is in effect moved on meanwhile. Nothing was changed.", {
|
|
622
|
+
rule: "agreement_moved"
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
if (message.includes("core_agreements_changed")) {
|
|
626
|
+
return new ConflictError(
|
|
627
|
+
"What must be agreed to changed while this was being done, so nothing was changed. Look again.",
|
|
628
|
+
{ rule: "agreements_changed" }
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
if (message.includes("core_agreement_acceptance_immutable")) {
|
|
632
|
+
return new ForbiddenError("An acceptance is never changed or deleted.", {
|
|
633
|
+
rule: "agreement_acceptance_immutable"
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
if (message.includes("core_agreement_version_not_open")) {
|
|
637
|
+
return new ConflictError(
|
|
638
|
+
"This is not the version in effect: read the current one and agree to that.",
|
|
639
|
+
{ rule: "agreement_version_replaced" }
|
|
640
|
+
);
|
|
641
|
+
}
|
|
642
|
+
if (message.includes("core_agreement_minor_fixed") || message.includes("core_person_exists")) {
|
|
643
|
+
return new ConflictError("That record already exists; it is changed in place, not replaced.", {
|
|
644
|
+
rule: "no_replace"
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
if (message.includes("core_agreement_minor_self")) {
|
|
648
|
+
return new ForbiddenError("A parent or guardian agrees for you.", { rule: "agreement_minor" });
|
|
649
|
+
}
|
|
650
|
+
if (message.includes("core_agreement_copy_address")) {
|
|
651
|
+
return new ForbiddenError("A copy goes only to the address the host holds for it.", {
|
|
652
|
+
rule: "agreement_copy_address"
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
if (message.includes("core_agreement_hold_not_kept")) {
|
|
656
|
+
return new OperationError("not_found", "No kept acceptance with that id.", {
|
|
657
|
+
rule: "agreement_not_kept"
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
if (message.includes("core_agreement_hold_fixed")) {
|
|
661
|
+
return new ConflictError("That acceptance is already on hold.", { rule: "agreement_held" });
|
|
662
|
+
}
|
|
663
|
+
if (message.includes("core_agreement_copy_fixed")) {
|
|
664
|
+
return new ConflictError("A copy's address is fixed once it is written.", {
|
|
665
|
+
rule: "agreement_copy_fixed"
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
if (message.includes("core_agreement_desk_claim_lost")) {
|
|
669
|
+
return new ConflictError(
|
|
670
|
+
"This code was claimed elsewhere, or the session ended, a moment before. Ask the desk for a new code.",
|
|
671
|
+
{ rule: "desk_code_taken" }
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
if (message.includes("core_device_claim_lost")) {
|
|
675
|
+
return new ConflictError(
|
|
676
|
+
"This code was used on another device a moment before. Ask an admin for a new one.",
|
|
677
|
+
{ rule: "device_code_taken" }
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
if (message.includes("core_person_link_not_live")) {
|
|
681
|
+
return new OperationError("not_found", "Not found", { object: "person" });
|
|
682
|
+
}
|
|
683
|
+
if (message.includes("core_person_link_reverse")) {
|
|
684
|
+
return new ConflictError(
|
|
685
|
+
"The other way round is already linked: a child cannot also be their guardian's guardian.",
|
|
686
|
+
{ rule: "person_link_reverse" }
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
if (message.includes("UNIQUE constraint failed: core_person_link")) {
|
|
690
|
+
return new ConflictError("These two are already linked.", { rule: "person_link" });
|
|
691
|
+
}
|
|
692
|
+
if (message.includes("UNIQUE constraint failed: core_recurrence_occurrence")) {
|
|
693
|
+
return new ConflictError(
|
|
694
|
+
"Another run made these records at the same moment. Nothing was changed.",
|
|
695
|
+
{
|
|
696
|
+
rule: "recurring_occurrence"
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
const unique = /UNIQUE constraint failed: ([\w.]+(?:, [\w.]+)*)/.exec(message);
|
|
701
|
+
if (unique?.[1] && declaredUniqueKeys.has(unique[1])) {
|
|
702
|
+
return new ConflictError(
|
|
703
|
+
"A record like this one was made at the same moment, so this one was not",
|
|
704
|
+
{
|
|
705
|
+
rule: "unique",
|
|
706
|
+
constraint: unique[1]
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
if (unique) {
|
|
711
|
+
return new ConflictError("A record with that value already exists", {
|
|
712
|
+
constraint: unique[1]
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
if (/FOREIGN KEY constraint failed/.test(message)) {
|
|
716
|
+
return new ValidationError("A referenced record does not exist");
|
|
717
|
+
}
|
|
718
|
+
if (/CHECK constraint failed/.test(message)) {
|
|
719
|
+
return new ValidationError("A value is not allowed", { reason: message });
|
|
720
|
+
}
|
|
721
|
+
return new OperationError("internal", "Internal error", { reason: message });
|
|
722
|
+
}
|
|
723
|
+
var ALLOWANCE_REFUSED = /core_allowance_refused (\{[^{}]*\})/;
|
|
724
|
+
var ALLOWANCE_MESSAGES = {
|
|
725
|
+
no_uses_left: "No uses left in this period",
|
|
726
|
+
spent_meanwhile: "Another booking took the last use at the same moment. Try again",
|
|
727
|
+
not_theirs: "That pass or membership is not this person's",
|
|
728
|
+
not_live: "That pass or membership cannot be used now (paused, ended or void)",
|
|
729
|
+
not_yet_valid: "That pass or membership is not valid yet at this time",
|
|
730
|
+
ended: "That pass or membership has ended by this time",
|
|
731
|
+
no_holder: "Nothing this person holds can pay for this",
|
|
732
|
+
not_covered: "That pass or membership does not cover this"
|
|
733
|
+
};
|
|
734
|
+
function allowanceMessage(details) {
|
|
735
|
+
const base = ALLOWANCE_MESSAGES[details.reason] ?? "The allowance refused this";
|
|
736
|
+
return details.reason === "no_uses_left" && details.uses !== void 0 ? `${base}: ${details.used ?? details.uses} of ${details.uses} spent` : base;
|
|
737
|
+
}
|
|
738
|
+
function allowanceRefusal(error) {
|
|
739
|
+
if (error instanceof OperationError) return null;
|
|
740
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
741
|
+
const match = ALLOWANCE_REFUSED.exec(message);
|
|
742
|
+
if (match) {
|
|
743
|
+
let payload;
|
|
744
|
+
try {
|
|
745
|
+
payload = JSON.parse(match[1]);
|
|
746
|
+
} catch {
|
|
747
|
+
return new ValidationError("The allowance refused this", { rule: "allowance" });
|
|
748
|
+
}
|
|
749
|
+
const details = {
|
|
750
|
+
rule: "allowance",
|
|
751
|
+
reason: String(payload.reason),
|
|
752
|
+
...typeof payload.object === "string" ? { object: payload.object } : {},
|
|
753
|
+
...typeof payload.record === "string" ? { record: payload.record } : {},
|
|
754
|
+
...typeof payload.period === "string" ? { period: payload.period } : {},
|
|
755
|
+
...typeof payload.uses === "number" ? { uses: payload.uses } : {},
|
|
756
|
+
...typeof payload.used === "number" ? { used: payload.used } : {},
|
|
757
|
+
...typeof payload.at === "string" ? { at: payload.at } : {}
|
|
758
|
+
};
|
|
759
|
+
if (details.reason === "no_uses_left") {
|
|
760
|
+
return new ConflictError(
|
|
761
|
+
"Another booking took the last use at the same moment, so nothing was changed. Try again.",
|
|
762
|
+
{ ...details, reason: "spent_meanwhile" }
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
return new ValidationError(allowanceMessage(details), { ...details });
|
|
766
|
+
}
|
|
767
|
+
if (message.includes("UNIQUE constraint failed: core_allowance_use.spender_type")) {
|
|
768
|
+
return new ConflictError(
|
|
769
|
+
"This record spent a use at the same moment in another change, so nothing was changed.",
|
|
770
|
+
{ rule: "allowance", reason: "spent_meanwhile" }
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
var CAPACITY_REFUSED = /core_capacity_refused (\{[^{}]*\})/;
|
|
776
|
+
var hasStock = () => false;
|
|
777
|
+
function setStockLookup(lookup) {
|
|
778
|
+
hasStock = lookup;
|
|
779
|
+
}
|
|
780
|
+
function stockRefusal(payload) {
|
|
781
|
+
const onHand = Number(payload.places ?? 0) - Number(payload.taken ?? 0);
|
|
782
|
+
if (payload.asked > 0) {
|
|
783
|
+
return new ValidationError(
|
|
784
|
+
`Not enough in stock: asked for ${payload.asked}, ${payload.available} available`,
|
|
785
|
+
{
|
|
786
|
+
rule: "stock",
|
|
787
|
+
object: payload.object,
|
|
788
|
+
record: payload.record,
|
|
789
|
+
asked: payload.asked,
|
|
790
|
+
available: payload.available
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
if (Number(payload.held) === 0) {
|
|
795
|
+
return new ValidationError(`Not enough on hand: this would leave ${onHand}`, {
|
|
796
|
+
rule: "stock",
|
|
797
|
+
object: payload.object,
|
|
798
|
+
record: payload.record,
|
|
799
|
+
onHand,
|
|
800
|
+
held: 0
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
return new ValidationError(
|
|
804
|
+
`Stock cannot go below what unpaid orders hold: ${payload.held} held. Count again in a few minutes.`,
|
|
805
|
+
{
|
|
806
|
+
rule: "stock",
|
|
807
|
+
object: payload.object,
|
|
808
|
+
record: payload.record,
|
|
809
|
+
onHand,
|
|
810
|
+
held: payload.held
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
function capacityRefusal(error) {
|
|
815
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
816
|
+
const match = CAPACITY_REFUSED.exec(message);
|
|
817
|
+
if (match) {
|
|
818
|
+
let payload;
|
|
819
|
+
try {
|
|
820
|
+
payload = JSON.parse(match[1]);
|
|
821
|
+
} catch {
|
|
822
|
+
return new ValidationError("Not enough places", { rule: "capacity" });
|
|
823
|
+
}
|
|
824
|
+
if (hasStock(payload.object)) return stockRefusal(payload);
|
|
825
|
+
if (payload.asked > 0) {
|
|
826
|
+
const details2 = {
|
|
827
|
+
rule: "capacity",
|
|
828
|
+
object: payload.object,
|
|
829
|
+
record: payload.record,
|
|
830
|
+
asked: payload.asked,
|
|
831
|
+
available: payload.available
|
|
832
|
+
};
|
|
833
|
+
return new ValidationError(
|
|
834
|
+
`Not enough places: asked for ${payload.asked}, ${payload.available} left`,
|
|
835
|
+
details2
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
const details = {
|
|
839
|
+
rule: "capacity",
|
|
840
|
+
object: payload.object,
|
|
841
|
+
record: payload.record,
|
|
842
|
+
places: payload.places,
|
|
843
|
+
held: payload.held,
|
|
844
|
+
taken: payload.taken
|
|
845
|
+
};
|
|
846
|
+
return new ValidationError(
|
|
847
|
+
`Places cannot be fewer than are claimed: ${payload.held} held and ${payload.taken} taken`,
|
|
848
|
+
details
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
if (message.includes("core_capacity_within_places")) {
|
|
852
|
+
return new ValidationError("Not enough places", { rule: "capacity" });
|
|
853
|
+
}
|
|
854
|
+
return null;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
export {
|
|
858
|
+
OperationError,
|
|
859
|
+
UnknownOperationError,
|
|
860
|
+
ValidationError,
|
|
861
|
+
ForbiddenError,
|
|
862
|
+
GateDeniedError,
|
|
863
|
+
PendingApprovalError,
|
|
864
|
+
RunsOnApprovalError,
|
|
865
|
+
RateLimitedError,
|
|
866
|
+
PlanLimitError,
|
|
867
|
+
SignInAgainError,
|
|
868
|
+
NotFoundError,
|
|
869
|
+
ConflictError,
|
|
870
|
+
NeedsOwnApprovalError,
|
|
871
|
+
ConfigError,
|
|
872
|
+
setDeclaredUniqueKeys,
|
|
873
|
+
toOperationError,
|
|
874
|
+
allowanceMessage,
|
|
875
|
+
setStockLookup
|
|
876
|
+
};
|