@composable-os/cli 0.1.0-beta.10 → 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-X4CKM3HL.js → accounts-GOCNY6WI.js} +17 -14
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-YWDHEBOK.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-VY64DMQO.js → chunk-2B6YUYZV.js} +23576 -11674
- package/dist/{run-RT2HVWMK.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/chunk-5D7BDF4Y.js +141 -0
- package/dist/{chunk-WO6D3XP3.js → chunk-6CM3WZG5.js} +13 -2470
- package/dist/chunk-CIBJGB5H.js +962 -0
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/chunk-JX4IFWNT.js +330 -0
- package/dist/{chunk-A4NTSYWV.js → chunk-KFHKNXGH.js} +786 -386
- 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-LJFLENFC.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-Y7JZFSTQ.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-6VXHPKGG.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-IFG4FRW5.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-CP6BXI6F.js → chunk-U72NEGCT.js} +8818 -3829
- package/dist/{chunk-WC5LHBBA.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/chunk-Z7OVQ6BC.js +713 -0
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-2DFENR62.js → cli-OKQHHSOE.js} +17 -23
- package/dist/{cli-YIOVSKOD.js → cli-VYSD2S4Z.js} +231 -82
- package/dist/cli.js +5 -5
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-2NC7LSYE.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-PUWD65BC.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-YOZTFV4Q.js} +11 -11
- package/dist/plan-on-sale-H4F26YIN.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/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 +103 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +514 -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 +1313 -66
- 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 +595 -1
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +220 -64
- 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-Y7T4TVOL.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PZUCSDDL.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-XTOD7EXW.js → src-52VERUPK.js} +312 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/visibility-SZCINPP4.js +58 -0
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-6UPUF4ML.js +0 -29998
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-GYSGVT6R.js +0 -284
- package/dist/chunk-JJHHNV46.js +0 -227
- package/dist/chunk-K6T42YCH.js +0 -704
- package/dist/chunk-M7A6FR2Z.js +0 -2586
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-Q4N55M2Z.js +0 -552
- package/dist/chunk-QGGJ2G6Z.js +0 -349
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/chunk-YJJHF65I.js +0 -759
- package/dist/chunk-Z3RMMB6S.js +0 -668
- 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
- package/dist/visibility-DLGHU4YN.js +0 -33
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
CORE_OBJECTS,
|
|
4
4
|
getObject,
|
|
5
5
|
isCoreObject,
|
|
6
|
+
listObjects,
|
|
6
7
|
setExtensionObjects
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-RSEWEFAV.js";
|
|
8
9
|
import {
|
|
9
10
|
BASE_TABLES
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CIBJGB5H.js";
|
|
11
12
|
import {
|
|
12
13
|
EXTENSION_ID_RE,
|
|
13
14
|
FIELD_NAME_RE,
|
|
@@ -23,10 +24,16 @@ import {
|
|
|
23
24
|
external_exports,
|
|
24
25
|
formulaTypeOf,
|
|
25
26
|
isDocumentType,
|
|
27
|
+
isRestrictedField,
|
|
26
28
|
onStep,
|
|
29
|
+
sellableFinance,
|
|
27
30
|
spendsOnList,
|
|
28
31
|
validateDocument
|
|
29
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-U72NEGCT.js";
|
|
33
|
+
import {
|
|
34
|
+
ValidationError,
|
|
35
|
+
setDeclaredUniqueKeys
|
|
36
|
+
} from "./chunk-RGKJKC5T.js";
|
|
30
37
|
|
|
31
38
|
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/object-utils.js
|
|
32
39
|
function isUndefined(obj) {
|
|
@@ -8881,6 +8888,18 @@ function parseParameter(param) {
|
|
|
8881
8888
|
return parseValueExpression(param);
|
|
8882
8889
|
}
|
|
8883
8890
|
|
|
8891
|
+
// ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-compiler/compiled-query.js
|
|
8892
|
+
var CompiledQuery = freeze({
|
|
8893
|
+
raw(sql2, parameters = []) {
|
|
8894
|
+
return freeze({
|
|
8895
|
+
sql: sql2,
|
|
8896
|
+
query: RawNode.createWithSql(sql2),
|
|
8897
|
+
parameters: freeze(parameters),
|
|
8898
|
+
queryId: createQueryId()
|
|
8899
|
+
});
|
|
8900
|
+
}
|
|
8901
|
+
});
|
|
8902
|
+
|
|
8884
8903
|
// ../core/src/extensions/naming.ts
|
|
8885
8904
|
var IDENT_RE = /^[a-z][a-z0-9_]{0,120}$/;
|
|
8886
8905
|
function ident(name) {
|
|
@@ -9001,322 +9020,14 @@ function viewColumnName(extension, target, local) {
|
|
|
9001
9020
|
return target.startsWith(`${extension}.`) ? column : ident(`${extension}__${column}`);
|
|
9002
9021
|
}
|
|
9003
9022
|
|
|
9004
|
-
// ../core/src/errors.ts
|
|
9005
|
-
var OperationError = class extends Error {
|
|
9006
|
-
constructor(code, message, details) {
|
|
9007
|
-
super(message);
|
|
9008
|
-
this.code = code;
|
|
9009
|
-
this.details = details;
|
|
9010
|
-
}
|
|
9011
|
-
code;
|
|
9012
|
-
details;
|
|
9013
|
-
name = "OperationError";
|
|
9014
|
-
toJSON() {
|
|
9015
|
-
return {
|
|
9016
|
-
code: this.code,
|
|
9017
|
-
message: this.message,
|
|
9018
|
-
...this.details === void 0 ? {} : { details: this.details }
|
|
9019
|
-
};
|
|
9020
|
-
}
|
|
9021
|
-
};
|
|
9022
|
-
var UnknownOperationError = class extends OperationError {
|
|
9023
|
-
name = "UnknownOperationError";
|
|
9024
|
-
constructor(name) {
|
|
9025
|
-
super("unknown_operation", `No operation named "${name}"`);
|
|
9026
|
-
}
|
|
9027
|
-
};
|
|
9028
|
-
var ValidationError = class extends OperationError {
|
|
9029
|
-
name = "ValidationError";
|
|
9030
|
-
constructor(message, details) {
|
|
9031
|
-
super("invalid_input", message, details);
|
|
9032
|
-
}
|
|
9033
|
-
};
|
|
9034
|
-
var ForbiddenError = class extends OperationError {
|
|
9035
|
-
name = "ForbiddenError";
|
|
9036
|
-
constructor(message, details) {
|
|
9037
|
-
super("forbidden", message, details);
|
|
9038
|
-
}
|
|
9039
|
-
};
|
|
9040
|
-
var GateDeniedError = class extends OperationError {
|
|
9041
|
-
name = "GateDeniedError";
|
|
9042
|
-
constructor(message, details) {
|
|
9043
|
-
super("denied", message, details);
|
|
9044
|
-
}
|
|
9045
|
-
};
|
|
9046
|
-
var PendingApprovalError = class extends OperationError {
|
|
9047
|
-
name = "PendingApprovalError";
|
|
9048
|
-
pending;
|
|
9049
|
-
constructor(pending) {
|
|
9050
|
-
super("pending_approval", pending.message, pending);
|
|
9051
|
-
this.pending = pending;
|
|
9052
|
-
}
|
|
9053
|
-
};
|
|
9054
|
-
var RunsOnApprovalError = class extends OperationError {
|
|
9055
|
-
constructor(uses) {
|
|
9056
|
-
super(
|
|
9057
|
-
"runs_on_approval",
|
|
9058
|
-
`This uses ${uses}, which a dry run does not touch: it runs only when it is approved`,
|
|
9059
|
-
{ uses }
|
|
9060
|
-
);
|
|
9061
|
-
this.uses = uses;
|
|
9062
|
-
}
|
|
9063
|
-
uses;
|
|
9064
|
-
name = "RunsOnApprovalError";
|
|
9065
|
-
};
|
|
9066
|
-
var RateLimitedError = class extends OperationError {
|
|
9067
|
-
name = "RateLimitedError";
|
|
9068
|
-
constructor(message, details) {
|
|
9069
|
-
super("rate_limited", message, details);
|
|
9070
|
-
}
|
|
9071
|
-
};
|
|
9072
|
-
var PlanLimitError = class extends OperationError {
|
|
9073
|
-
name = "PlanLimitError";
|
|
9074
|
-
constructor(message, details) {
|
|
9075
|
-
super("plan_limit", message, details);
|
|
9076
|
-
}
|
|
9077
|
-
};
|
|
9078
|
-
var NotFoundError = class extends OperationError {
|
|
9079
|
-
name = "NotFoundError";
|
|
9080
|
-
constructor(object, id) {
|
|
9081
|
-
super("not_found", `No ${object} with id ${id}`, { object, id });
|
|
9082
|
-
}
|
|
9083
|
-
};
|
|
9084
|
-
var ConflictError = class extends OperationError {
|
|
9085
|
-
name = "ConflictError";
|
|
9086
|
-
constructor(message, details) {
|
|
9087
|
-
super("conflict", message, details);
|
|
9088
|
-
}
|
|
9089
|
-
};
|
|
9090
|
-
var NeedsOwnApprovalError = class extends ConflictError {
|
|
9091
|
-
name = "NeedsOwnApprovalError";
|
|
9092
|
-
constructor(operation, calls) {
|
|
9093
|
-
super(
|
|
9094
|
-
`${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.`,
|
|
9095
|
-
{ needsOwnApproval: calls, operation }
|
|
9096
|
-
);
|
|
9097
|
-
}
|
|
9098
|
-
};
|
|
9099
|
-
var ConfigError = class extends OperationError {
|
|
9100
|
-
name = "ConfigError";
|
|
9101
|
-
constructor(message) {
|
|
9102
|
-
super("config", message);
|
|
9103
|
-
}
|
|
9104
|
-
};
|
|
9105
|
-
var declaredUniqueKeys = /* @__PURE__ */ new Set();
|
|
9106
|
-
function setDeclaredUniqueKeys(keys) {
|
|
9107
|
-
declaredUniqueKeys = keys;
|
|
9108
|
-
}
|
|
9109
|
-
function toOperationError(error) {
|
|
9110
|
-
if (error instanceof OperationError) return error;
|
|
9111
|
-
if (error instanceof Error && error.name === "AiAllowanceError") {
|
|
9112
|
-
return new PlanLimitError(error.message, { reason: "platform_ai" });
|
|
9113
|
-
}
|
|
9114
|
-
const capacity = capacityRefusal(error);
|
|
9115
|
-
if (capacity) return capacity;
|
|
9116
|
-
const allowance = allowanceRefusal(error);
|
|
9117
|
-
if (allowance) return allowance;
|
|
9118
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
9119
|
-
if (message.includes("core_order_stale")) {
|
|
9120
|
-
return new ConflictError("The order changed while this was being applied. Try again.", {
|
|
9121
|
-
reason: "order_stale"
|
|
9122
|
-
});
|
|
9123
|
-
}
|
|
9124
|
-
if (message.includes("core_subscription_stale")) {
|
|
9125
|
-
return new ConflictError("The subscription changed while this was being applied. Try again.", {
|
|
9126
|
-
reason: "subscription_stale"
|
|
9127
|
-
});
|
|
9128
|
-
}
|
|
9129
|
-
if (message.includes("core_subscription_trial_taken")) {
|
|
9130
|
-
return new ConflictError(
|
|
9131
|
-
"A checkout with this free trial was opened at the same moment. Start again to get it.",
|
|
9132
|
-
{ rule: "trial_held" }
|
|
9133
|
-
);
|
|
9134
|
-
}
|
|
9135
|
-
if (message.includes("UNIQUE constraint failed: core_sellable_once")) {
|
|
9136
|
-
return new ConflictError(
|
|
9137
|
-
"This is one per person, and another order for it was started at the same moment",
|
|
9138
|
-
{ rule: "once_per_person", reason: "held" }
|
|
9139
|
-
);
|
|
9140
|
-
}
|
|
9141
|
-
if (message.includes("UNIQUE constraint failed: core_subscription_grant")) {
|
|
9142
|
-
return new ConflictError(
|
|
9143
|
-
"This subscription's grant was made by another event at the same moment. Try again.",
|
|
9144
|
-
{ reason: "subscription_grant" }
|
|
9145
|
-
);
|
|
9146
|
-
}
|
|
9147
|
-
if (message.includes("core_subscription_offer_held")) {
|
|
9148
|
-
return new ConflictError(
|
|
9149
|
-
"A checkout for this offer was opened at the same moment, or the offer was taken or withdrawn. Start again.",
|
|
9150
|
-
{ rule: "offer_held" }
|
|
9151
|
-
);
|
|
9152
|
-
}
|
|
9153
|
-
if (message.includes("core_subscription_offer_stale")) {
|
|
9154
|
-
return new ConflictError(
|
|
9155
|
-
"The offer changed while this was being done, so nothing was changed. Try again.",
|
|
9156
|
-
{ rule: "offer_changed" }
|
|
9157
|
-
);
|
|
9158
|
-
}
|
|
9159
|
-
if (message.includes("UNIQUE constraint failed: core_subscription_offer")) {
|
|
9160
|
-
return new ConflictError(
|
|
9161
|
-
"Another import wrote one of these offers at the same moment. Run the import again.",
|
|
9162
|
-
{ rule: "offer_key" }
|
|
9163
|
-
);
|
|
9164
|
-
}
|
|
9165
|
-
if (message.includes(
|
|
9166
|
-
"UNIQUE constraint failed: core_transition_history.object_type, core_transition_history.record_id"
|
|
9167
|
-
)) {
|
|
9168
|
-
return new ConflictError(
|
|
9169
|
-
"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.",
|
|
9170
|
-
{ reason: "moved_meanwhile" }
|
|
9171
|
-
);
|
|
9172
|
-
}
|
|
9173
|
-
if (message.includes("UNIQUE constraint failed: core_publish_version")) {
|
|
9174
|
-
return new ConflictError(
|
|
9175
|
-
"Another version of this record was published at the same moment, so this one was not. Read its versions again before publishing.",
|
|
9176
|
-
{ reason: "published_meanwhile" }
|
|
9177
|
-
);
|
|
9178
|
-
}
|
|
9179
|
-
if (message.includes("core_recurrence_stale")) {
|
|
9180
|
-
return new ConflictError(
|
|
9181
|
-
"The schedule or a booking changed while this was being done, so nothing was changed. Try again.",
|
|
9182
|
-
{ rule: "recurring_stale" }
|
|
9183
|
-
);
|
|
9184
|
-
}
|
|
9185
|
-
if (message.includes("core_claim_live")) {
|
|
9186
|
-
return new ConflictError(
|
|
9187
|
-
"This record took a place while it was being deleted, so it was not. Move it out first.",
|
|
9188
|
-
{ rule: "capacity", reason: "claim_live" }
|
|
9189
|
-
);
|
|
9190
|
-
}
|
|
9191
|
-
if (message.includes("UNIQUE constraint failed: core_recurrence_occurrence")) {
|
|
9192
|
-
return new ConflictError(
|
|
9193
|
-
"Another run made these records at the same moment. Nothing was changed.",
|
|
9194
|
-
{
|
|
9195
|
-
rule: "recurring_occurrence"
|
|
9196
|
-
}
|
|
9197
|
-
);
|
|
9198
|
-
}
|
|
9199
|
-
const unique = /UNIQUE constraint failed: ([\w.]+(?:, [\w.]+)*)/.exec(message);
|
|
9200
|
-
if (unique?.[1] && declaredUniqueKeys.has(unique[1])) {
|
|
9201
|
-
return new ConflictError(
|
|
9202
|
-
"A record like this one was made at the same moment, so this one was not",
|
|
9203
|
-
{
|
|
9204
|
-
rule: "unique",
|
|
9205
|
-
constraint: unique[1]
|
|
9206
|
-
}
|
|
9207
|
-
);
|
|
9208
|
-
}
|
|
9209
|
-
if (unique) {
|
|
9210
|
-
return new ConflictError("A record with that value already exists", {
|
|
9211
|
-
constraint: unique[1]
|
|
9212
|
-
});
|
|
9213
|
-
}
|
|
9214
|
-
if (/FOREIGN KEY constraint failed/.test(message)) {
|
|
9215
|
-
return new ValidationError("A referenced record does not exist");
|
|
9216
|
-
}
|
|
9217
|
-
if (/CHECK constraint failed/.test(message)) {
|
|
9218
|
-
return new ValidationError("A value is not allowed", { reason: message });
|
|
9219
|
-
}
|
|
9220
|
-
return new OperationError("internal", "Internal error", { reason: message });
|
|
9221
|
-
}
|
|
9222
|
-
var ALLOWANCE_REFUSED = /core_allowance_refused (\{[^{}]*\})/;
|
|
9223
|
-
var ALLOWANCE_MESSAGES = {
|
|
9224
|
-
no_uses_left: "No uses left in this period",
|
|
9225
|
-
spent_meanwhile: "Another booking took the last use at the same moment. Try again",
|
|
9226
|
-
not_theirs: "That pass or membership is not this person's",
|
|
9227
|
-
not_live: "That pass or membership cannot be used now (paused, ended or void)",
|
|
9228
|
-
not_yet_valid: "That pass or membership is not valid yet at this time",
|
|
9229
|
-
ended: "That pass or membership has ended by this time",
|
|
9230
|
-
no_holder: "Nothing this person holds can pay for this",
|
|
9231
|
-
not_covered: "That pass or membership does not cover this"
|
|
9232
|
-
};
|
|
9233
|
-
function allowanceMessage(details) {
|
|
9234
|
-
const base = ALLOWANCE_MESSAGES[details.reason] ?? "The allowance refused this";
|
|
9235
|
-
return details.reason === "no_uses_left" && details.uses !== void 0 ? `${base}: ${details.used ?? details.uses} of ${details.uses} spent` : base;
|
|
9236
|
-
}
|
|
9237
|
-
function allowanceRefusal(error) {
|
|
9238
|
-
if (error instanceof OperationError) return null;
|
|
9239
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
9240
|
-
const match = ALLOWANCE_REFUSED.exec(message);
|
|
9241
|
-
if (match) {
|
|
9242
|
-
let payload;
|
|
9243
|
-
try {
|
|
9244
|
-
payload = JSON.parse(match[1]);
|
|
9245
|
-
} catch {
|
|
9246
|
-
return new ValidationError("The allowance refused this", { rule: "allowance" });
|
|
9247
|
-
}
|
|
9248
|
-
const details = {
|
|
9249
|
-
rule: "allowance",
|
|
9250
|
-
reason: String(payload.reason),
|
|
9251
|
-
...typeof payload.object === "string" ? { object: payload.object } : {},
|
|
9252
|
-
...typeof payload.record === "string" ? { record: payload.record } : {},
|
|
9253
|
-
...typeof payload.period === "string" ? { period: payload.period } : {},
|
|
9254
|
-
...typeof payload.uses === "number" ? { uses: payload.uses } : {},
|
|
9255
|
-
...typeof payload.used === "number" ? { used: payload.used } : {},
|
|
9256
|
-
...typeof payload.at === "string" ? { at: payload.at } : {}
|
|
9257
|
-
};
|
|
9258
|
-
if (details.reason === "no_uses_left") {
|
|
9259
|
-
return new ConflictError(
|
|
9260
|
-
"Another booking took the last use at the same moment, so nothing was changed. Try again.",
|
|
9261
|
-
{ ...details, reason: "spent_meanwhile" }
|
|
9262
|
-
);
|
|
9263
|
-
}
|
|
9264
|
-
return new ValidationError(allowanceMessage(details), { ...details });
|
|
9265
|
-
}
|
|
9266
|
-
if (message.includes("UNIQUE constraint failed: core_allowance_use.spender_type")) {
|
|
9267
|
-
return new ConflictError(
|
|
9268
|
-
"This record spent a use at the same moment in another change, so nothing was changed.",
|
|
9269
|
-
{ rule: "allowance", reason: "spent_meanwhile" }
|
|
9270
|
-
);
|
|
9271
|
-
}
|
|
9272
|
-
return null;
|
|
9273
|
-
}
|
|
9274
|
-
var CAPACITY_REFUSED = /core_capacity_refused (\{[^{}]*\})/;
|
|
9275
|
-
function capacityRefusal(error) {
|
|
9276
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
9277
|
-
const match = CAPACITY_REFUSED.exec(message);
|
|
9278
|
-
if (match) {
|
|
9279
|
-
let payload;
|
|
9280
|
-
try {
|
|
9281
|
-
payload = JSON.parse(match[1]);
|
|
9282
|
-
} catch {
|
|
9283
|
-
return new ValidationError("Not enough places", { rule: "capacity" });
|
|
9284
|
-
}
|
|
9285
|
-
if (payload.asked > 0) {
|
|
9286
|
-
const details2 = {
|
|
9287
|
-
rule: "capacity",
|
|
9288
|
-
object: payload.object,
|
|
9289
|
-
record: payload.record,
|
|
9290
|
-
asked: payload.asked,
|
|
9291
|
-
available: payload.available
|
|
9292
|
-
};
|
|
9293
|
-
return new ValidationError(
|
|
9294
|
-
`Not enough places: asked for ${payload.asked}, ${payload.available} left`,
|
|
9295
|
-
details2
|
|
9296
|
-
);
|
|
9297
|
-
}
|
|
9298
|
-
const details = {
|
|
9299
|
-
rule: "capacity",
|
|
9300
|
-
object: payload.object,
|
|
9301
|
-
record: payload.record,
|
|
9302
|
-
places: payload.places,
|
|
9303
|
-
held: payload.held,
|
|
9304
|
-
taken: payload.taken
|
|
9305
|
-
};
|
|
9306
|
-
return new ValidationError(
|
|
9307
|
-
`Places cannot be fewer than are claimed: ${payload.held} held and ${payload.taken} taken`,
|
|
9308
|
-
details
|
|
9309
|
-
);
|
|
9310
|
-
}
|
|
9311
|
-
if (message.includes("core_capacity_within_places")) {
|
|
9312
|
-
return new ValidationError("Not enough places", { rule: "capacity" });
|
|
9313
|
-
}
|
|
9314
|
-
return null;
|
|
9315
|
-
}
|
|
9316
|
-
|
|
9317
9023
|
// ../core/src/fields/field-types.ts
|
|
9318
9024
|
var DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
9319
|
-
var DATETIME_RE = /^\d{4}-\d{2}-\d{2}T\d
|
|
9025
|
+
var DATETIME_RE = /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d(:[0-5]\d(\.\d{1,9})?)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)$/;
|
|
9026
|
+
function isDatetime(value) {
|
|
9027
|
+
if (!DATETIME_RE.test(value) || !Number.isFinite(Date.parse(value))) return false;
|
|
9028
|
+
const [y, m, d] = value.slice(0, 10).split("-").map(Number);
|
|
9029
|
+
return m >= 1 && m <= 12 && d >= 1 && new Date(Date.UTC(y, m - 1, d)).getUTCDate() === d;
|
|
9030
|
+
}
|
|
9320
9031
|
var nullable = (schema) => schema.nullable();
|
|
9321
9032
|
var text = (max) => external_exports.string().max(max);
|
|
9322
9033
|
var identity = (value) => value === void 0 ? null : value;
|
|
@@ -9460,7 +9171,7 @@ var FIELD_TYPE_REGISTRY = {
|
|
|
9460
9171
|
filterType: () => "datetime",
|
|
9461
9172
|
multi: () => false,
|
|
9462
9173
|
sortable: () => true,
|
|
9463
|
-
schema: () => nullable(external_exports.string().
|
|
9174
|
+
schema: () => nullable(external_exports.string().refine(isDatetime, "Expected an ISO-8601 timestamp")),
|
|
9464
9175
|
toStorage: identity,
|
|
9465
9176
|
fromStorage: identity,
|
|
9466
9177
|
csv: {
|
|
@@ -9560,6 +9271,18 @@ var FIELD_TYPE_REGISTRY = {
|
|
|
9560
9271
|
"text",
|
|
9561
9272
|
external_exports.string().max(120).regex(SLUG_RE, "Lowercase letters and digits in words joined by hyphens")
|
|
9562
9273
|
),
|
|
9274
|
+
// A checklist template, by id (stage 45 step 4b, ADR 0650): an active one, checked on write.
|
|
9275
|
+
checklist: {
|
|
9276
|
+
storage: "TEXT",
|
|
9277
|
+
filterType: () => "id",
|
|
9278
|
+
multi: () => false,
|
|
9279
|
+
sortable: () => false,
|
|
9280
|
+
schema: () => nullable(external_exports.string().min(1).max(64)),
|
|
9281
|
+
toStorage: identity,
|
|
9282
|
+
fromStorage: identity,
|
|
9283
|
+
csv: csvText,
|
|
9284
|
+
widget: { display: "checklist", edit: "checklist" }
|
|
9285
|
+
},
|
|
9563
9286
|
formula: {
|
|
9564
9287
|
storage: null,
|
|
9565
9288
|
// Replaced by the formula's result type when the registry is built.
|
|
@@ -9671,6 +9394,11 @@ function formulaEnvironment(state, object, extension) {
|
|
|
9671
9394
|
env.createdAt = { type: "datetime", sql: "t.created_at" };
|
|
9672
9395
|
env.updatedAt = { type: "datetime", sql: "t.updated_at" };
|
|
9673
9396
|
const owner = splitObjectName(object)?.extension;
|
|
9397
|
+
const own = state.objects.find((o) => o.name === object);
|
|
9398
|
+
if (own?.definition.publishable && owner === extension) {
|
|
9399
|
+
env.publishedAt = { type: "datetime", sql: "pub.published_at" };
|
|
9400
|
+
env.publishedVersion = { type: "number", sql: "pub.version" };
|
|
9401
|
+
}
|
|
9674
9402
|
addFields(
|
|
9675
9403
|
env,
|
|
9676
9404
|
active.filter((f) => f.extensionId === owner),
|
|
@@ -9765,6 +9493,11 @@ function buildViews(state) {
|
|
|
9765
9493
|
columns.push(...capacity.columns);
|
|
9766
9494
|
joins.push(...capacity.joins);
|
|
9767
9495
|
}
|
|
9496
|
+
if (object.definition.stock) {
|
|
9497
|
+
const stock = stockView(object.name);
|
|
9498
|
+
columns.push(...stock.columns);
|
|
9499
|
+
joins.push(...stock.joins);
|
|
9500
|
+
}
|
|
9768
9501
|
if (object.definition.publishable) {
|
|
9769
9502
|
const published = publishedView(object.name);
|
|
9770
9503
|
columns.push(...published.columns);
|
|
@@ -9780,7 +9513,7 @@ function buildViews(state) {
|
|
|
9780
9513
|
`CREATE VIEW ${view} AS SELECT ${columns.join(", ")} FROM ${ident(object.tableName)} t${joins.length ? ` ${joins.join(" ")}` : ""} WHERE t.deleted_at IS NULL`
|
|
9781
9514
|
);
|
|
9782
9515
|
if (object.definition.publishable) {
|
|
9783
|
-
build.creates.push(liveViewSql(object, own
|
|
9516
|
+
build.creates.push(liveViewSql(object, own));
|
|
9784
9517
|
}
|
|
9785
9518
|
}
|
|
9786
9519
|
for (const object of state.objects) {
|
|
@@ -9788,11 +9521,12 @@ function buildViews(state) {
|
|
|
9788
9521
|
}
|
|
9789
9522
|
return build;
|
|
9790
9523
|
}
|
|
9791
|
-
function liveViewSql(object, own
|
|
9524
|
+
function liveViewSql(object, own) {
|
|
9792
9525
|
const publishable = object.definition.publishable;
|
|
9793
9526
|
const content = new Set(publishable.content);
|
|
9794
9527
|
const columns = ["t.id", "t.created_at", "pub.published_at AS updated_at", "t.created_by"];
|
|
9795
9528
|
for (const field of own) {
|
|
9529
|
+
if (isRestrictedField(field.definition)) continue;
|
|
9796
9530
|
const as = viewColumnName(object.extensionId, object.name, field.localName);
|
|
9797
9531
|
if (field.type === "formula" || !field.columnName) {
|
|
9798
9532
|
columns.push(`NULL AS ${as}`);
|
|
@@ -9815,11 +9549,16 @@ function liveViewSql(object, own, capacity) {
|
|
|
9815
9549
|
const joins = [
|
|
9816
9550
|
`JOIN core_publish_version pub ON pub.object_type = ${sqlString(object.name)} AND pub.record_id = t.id AND pub.current = 1`
|
|
9817
9551
|
];
|
|
9818
|
-
if (capacity) {
|
|
9552
|
+
if (object.definition.capacity) {
|
|
9819
9553
|
const view = capacityView(object.name);
|
|
9820
9554
|
columns.push(...view.columns);
|
|
9821
9555
|
joins.push(...view.joins);
|
|
9822
9556
|
}
|
|
9557
|
+
if (object.definition.stock) {
|
|
9558
|
+
const view = stockView(object.name);
|
|
9559
|
+
columns.push(...view.columns);
|
|
9560
|
+
joins.push(...view.joins);
|
|
9561
|
+
}
|
|
9823
9562
|
columns.push(
|
|
9824
9563
|
`pub.version AS ${PUBLISHED_COLUMNS.publishedVersion}`,
|
|
9825
9564
|
`pub.published_at AS ${PUBLISHED_COLUMNS.publishedAt}`,
|
|
@@ -9849,6 +9588,17 @@ function capacityView(object) {
|
|
|
9849
9588
|
]
|
|
9850
9589
|
};
|
|
9851
9590
|
}
|
|
9591
|
+
function stockView(object) {
|
|
9592
|
+
const name = `'${object.replaceAll("'", "''")}'`;
|
|
9593
|
+
return {
|
|
9594
|
+
joins: [`LEFT JOIN core_capacity stk ON stk.object_type = ${name} AND stk.record_id = t.id`],
|
|
9595
|
+
columns: [
|
|
9596
|
+
`coalesce(stk.places, 0) - coalesce(stk.taken, 0) AS ${STOCK_COLUMNS.onHand}`,
|
|
9597
|
+
`coalesce(stk.held, 0) AS ${STOCK_COLUMNS.held}`,
|
|
9598
|
+
`max(coalesce(stk.places, 0) - coalesce(stk.taken, 0) - coalesce(stk.held, 0), 0) AS ${STOCK_COLUMNS.available}`
|
|
9599
|
+
]
|
|
9600
|
+
};
|
|
9601
|
+
}
|
|
9852
9602
|
function allowanceView(object) {
|
|
9853
9603
|
const name = `'${object.replaceAll("'", "''")}'`;
|
|
9854
9604
|
return {
|
|
@@ -9998,6 +9748,43 @@ var CAPACITY_FIELDS = [
|
|
|
9998
9748
|
description: "Places left (the record's and its pool's, whichever is fewer). Empty: unlimited."
|
|
9999
9749
|
}
|
|
10000
9750
|
];
|
|
9751
|
+
var STOCK_COLUMNS = {
|
|
9752
|
+
onHand: "_stk_on_hand",
|
|
9753
|
+
held: "_stk_held",
|
|
9754
|
+
available: "_stk_available"
|
|
9755
|
+
};
|
|
9756
|
+
var STOCK_FIELDS = [
|
|
9757
|
+
{
|
|
9758
|
+
name: "onHand",
|
|
9759
|
+
label: "On hand",
|
|
9760
|
+
type: "number",
|
|
9761
|
+
column: STOCK_COLUMNS.onHand,
|
|
9762
|
+
filterable: true,
|
|
9763
|
+
sortable: true,
|
|
9764
|
+
readOnly: true,
|
|
9765
|
+
description: "How many there are, sold ones gone. Changed only by stock movements."
|
|
9766
|
+
},
|
|
9767
|
+
{
|
|
9768
|
+
name: "held",
|
|
9769
|
+
label: "Held",
|
|
9770
|
+
type: "number",
|
|
9771
|
+
column: STOCK_COLUMNS.held,
|
|
9772
|
+
filterable: true,
|
|
9773
|
+
sortable: true,
|
|
9774
|
+
readOnly: true,
|
|
9775
|
+
description: "How many orders being paid for hold."
|
|
9776
|
+
},
|
|
9777
|
+
{
|
|
9778
|
+
name: "available",
|
|
9779
|
+
label: "Available",
|
|
9780
|
+
type: "number",
|
|
9781
|
+
column: STOCK_COLUMNS.available,
|
|
9782
|
+
filterable: true,
|
|
9783
|
+
sortable: true,
|
|
9784
|
+
readOnly: true,
|
|
9785
|
+
description: "On hand less held: how many can be sold now."
|
|
9786
|
+
}
|
|
9787
|
+
];
|
|
10001
9788
|
var ALLOWANCE_COLUMNS = { used: "_alw_used", left: "_alw_left" };
|
|
10002
9789
|
var ALLOWANCE_FIELDS = [
|
|
10003
9790
|
{
|
|
@@ -10055,7 +9842,8 @@ function allowanceDefinition(object) {
|
|
|
10055
9842
|
local: { ...sp.local ?? {} },
|
|
10056
9843
|
...sp.movedFrom ? { movedFrom: { ...sp.movedFrom } } : {},
|
|
10057
9844
|
paidBy: [...sp.paidBy ?? []],
|
|
10058
|
-
...sp.waived ? { waived: sp.waived } : {}
|
|
9845
|
+
...sp.waived ? { waived: sp.waived } : {},
|
|
9846
|
+
...sp.released ? { released: sp.released } : {}
|
|
10059
9847
|
};
|
|
10060
9848
|
}
|
|
10061
9849
|
function capacityDefinition(object, own) {
|
|
@@ -10071,17 +9859,157 @@ function capacityDefinition(object, own) {
|
|
|
10071
9859
|
releaseOnRefund: declared.releaseOnRefund ?? true
|
|
10072
9860
|
};
|
|
10073
9861
|
}
|
|
9862
|
+
function stockDefinition(object, own) {
|
|
9863
|
+
const declared = object.definition.stock;
|
|
9864
|
+
if (!declared) return void 0;
|
|
9865
|
+
const nameOf = (local) => own.find((f) => f.localName === local)?.name ?? local;
|
|
9866
|
+
return {
|
|
9867
|
+
...declared.reorderAt ? { reorderAt: nameOf(declared.reorderAt) } : {},
|
|
9868
|
+
...declared.reorderQty ? { reorderQty: nameOf(declared.reorderQty) } : {},
|
|
9869
|
+
show: declared.show ?? "availability",
|
|
9870
|
+
...declared.lowAt !== void 0 ? { lowAt: declared.lowAt } : {},
|
|
9871
|
+
...declared.notify ? { notify: declared.notify } : {}
|
|
9872
|
+
};
|
|
9873
|
+
}
|
|
9874
|
+
function stockMovesDefinition(object, own) {
|
|
9875
|
+
const declared = object.definition.stockMoves;
|
|
9876
|
+
if (!declared) return void 0;
|
|
9877
|
+
const fieldOf = (local) => own.find((f) => f.localName === local);
|
|
9878
|
+
const on = fieldOf(declared.on);
|
|
9879
|
+
const through = declared.through ? fieldOf(declared.through) : void 0;
|
|
9880
|
+
if (!on?.definition.to || declared.through && !through?.definition.to) return void 0;
|
|
9881
|
+
const nameOf = (local) => local === void 0 ? void 0 : fieldOf(local)?.name ?? local;
|
|
9882
|
+
const kind = declared.kind ?? (declared.move === "add" ? "received" : declared.move === "set" ? "counted" : "written_off");
|
|
9883
|
+
return {
|
|
9884
|
+
move: declared.move,
|
|
9885
|
+
on: on.name,
|
|
9886
|
+
object: on.definition.to,
|
|
9887
|
+
quantity: nameOf(declared.quantity),
|
|
9888
|
+
when: declared.when,
|
|
9889
|
+
...through ? { through: through.name, throughObject: through.definition.to } : {},
|
|
9890
|
+
kind,
|
|
9891
|
+
...declared.unitCost ? { unitCost: nameOf(declared.unitCost) } : {},
|
|
9892
|
+
...declared.note ? { note: nameOf(declared.note) } : {}
|
|
9893
|
+
};
|
|
9894
|
+
}
|
|
10074
9895
|
function claimsDefinition(object, own) {
|
|
10075
9896
|
const declared = object.definition.claims;
|
|
10076
9897
|
if (!declared) return {};
|
|
10077
9898
|
const on = own.find((f) => f.localName === declared.on);
|
|
10078
9899
|
if (!on?.definition.to) return {};
|
|
9900
|
+
const waitlist = declared.waitlist;
|
|
9901
|
+
const named = (local) => local === void 0 ? void 0 : own.find((f) => f.localName === local)?.name ?? local;
|
|
10079
9902
|
return {
|
|
10080
9903
|
claims: {
|
|
10081
9904
|
on: on.name,
|
|
10082
9905
|
object: on.definition.to,
|
|
10083
9906
|
held: [...declared.held ?? []],
|
|
10084
|
-
confirmed: [...declared.confirmed ?? []]
|
|
9907
|
+
confirmed: [...declared.confirmed ?? []],
|
|
9908
|
+
...waitlist ? {
|
|
9909
|
+
waitlist: {
|
|
9910
|
+
state: waitlist.state,
|
|
9911
|
+
promote: waitlist.promote,
|
|
9912
|
+
until: waitlist.until,
|
|
9913
|
+
promotedAt: named(waitlist.promotedAt),
|
|
9914
|
+
passedOverAt: named(waitlist.passedOverAt),
|
|
9915
|
+
passedOverReason: named(waitlist.passedOverReason)
|
|
9916
|
+
}
|
|
9917
|
+
} : {}
|
|
9918
|
+
}
|
|
9919
|
+
};
|
|
9920
|
+
}
|
|
9921
|
+
function intakeDefinition(object, own) {
|
|
9922
|
+
const declared = object.definition.intake;
|
|
9923
|
+
if (!declared) return {};
|
|
9924
|
+
if (declared.role !== "submission") return { intake: declared };
|
|
9925
|
+
const formObject = own.find((f) => f.localName === declared.form)?.definition.to ?? "";
|
|
9926
|
+
return { intake: { ...declared, formObject } };
|
|
9927
|
+
}
|
|
9928
|
+
function staffedDefinition(object, own) {
|
|
9929
|
+
const declared = object.definition.staffed;
|
|
9930
|
+
if (!declared) return {};
|
|
9931
|
+
const holder = declared.who.account ? own.find((f) => f.localName === declared.who.field)?.definition.to : void 0;
|
|
9932
|
+
const timesFromObject = declared.timesFrom ? own.find((f) => f.localName === declared.timesFrom)?.definition.to : void 0;
|
|
9933
|
+
return {
|
|
9934
|
+
staffed: {
|
|
9935
|
+
...declared,
|
|
9936
|
+
who: {
|
|
9937
|
+
field: declared.who.field,
|
|
9938
|
+
...declared.who.account ? { account: declared.who.account, object: holder } : {}
|
|
9939
|
+
},
|
|
9940
|
+
live: [...declared.live],
|
|
9941
|
+
...declared.open ? {
|
|
9942
|
+
open: {
|
|
9943
|
+
...declared.open,
|
|
9944
|
+
...declared.open.closedBy ? {
|
|
9945
|
+
closedBy: {
|
|
9946
|
+
...declared.open.closedBy,
|
|
9947
|
+
object: `${object.extensionId}.${declared.open.closedBy.object}`
|
|
9948
|
+
}
|
|
9949
|
+
} : {}
|
|
9950
|
+
}
|
|
9951
|
+
} : {},
|
|
9952
|
+
...declared.evidence ? {
|
|
9953
|
+
evidence: {
|
|
9954
|
+
...declared.evidence,
|
|
9955
|
+
object: `${object.extensionId}.${declared.evidence.object}`
|
|
9956
|
+
}
|
|
9957
|
+
} : {},
|
|
9958
|
+
...timesFromObject ? { timesFromObject } : {}
|
|
9959
|
+
}
|
|
9960
|
+
};
|
|
9961
|
+
}
|
|
9962
|
+
function workedOnDefinition(object, own) {
|
|
9963
|
+
const declared = object.definition.workedOn;
|
|
9964
|
+
if (!declared) return {};
|
|
9965
|
+
const partOfObject = declared.partOf ? own.find((f) => f.localName === declared.partOf)?.definition.to : void 0;
|
|
9966
|
+
return {
|
|
9967
|
+
workedOn: {
|
|
9968
|
+
...declared,
|
|
9969
|
+
live: [...declared.live],
|
|
9970
|
+
...partOfObject ? { partOfObject } : {}
|
|
9971
|
+
}
|
|
9972
|
+
};
|
|
9973
|
+
}
|
|
9974
|
+
function occupiesDefinition(object, own) {
|
|
9975
|
+
const declared = object.definition.occupies;
|
|
9976
|
+
if (!declared) return {};
|
|
9977
|
+
const target = (local) => own.find((f) => f.localName === local)?.definition.to;
|
|
9978
|
+
const margin = (m) => {
|
|
9979
|
+
if (!m) return void 0;
|
|
9980
|
+
const [first, second] = m.field.split(".");
|
|
9981
|
+
return second === void 0 ? { field: first } : { field: second, via: first, viaObject: target(first) };
|
|
9982
|
+
};
|
|
9983
|
+
const before = margin(declared.before);
|
|
9984
|
+
const after = margin(declared.after);
|
|
9985
|
+
const title = margin(declared.title === void 0 ? void 0 : { field: declared.title });
|
|
9986
|
+
return {
|
|
9987
|
+
occupies: {
|
|
9988
|
+
thing: declared.thing,
|
|
9989
|
+
thingObject: target(declared.thing) ?? "",
|
|
9990
|
+
starts: declared.starts,
|
|
9991
|
+
ends: declared.ends,
|
|
9992
|
+
live: [...declared.live],
|
|
9993
|
+
...before ? { before } : {},
|
|
9994
|
+
...after ? { after } : {},
|
|
9995
|
+
...declared.only ? { only: declared.only } : {},
|
|
9996
|
+
...declared.provisional ? { provisional: [...declared.provisional] } : {},
|
|
9997
|
+
...title ? { title } : {}
|
|
9998
|
+
}
|
|
9999
|
+
};
|
|
10000
|
+
}
|
|
10001
|
+
function checklistsDefinition(object, own) {
|
|
10002
|
+
const declared = object.definition.checklists;
|
|
10003
|
+
if (!declared) return {};
|
|
10004
|
+
const [first, second] = declared.template.split(".");
|
|
10005
|
+
const viaObject2 = second !== void 0 ? own.find((f) => f.localName === first)?.definition.to : void 0;
|
|
10006
|
+
return {
|
|
10007
|
+
checklists: {
|
|
10008
|
+
template: second !== void 0 ? { field: second, via: first, viaObject: viaObject2 } : { field: first },
|
|
10009
|
+
who: declared.who,
|
|
10010
|
+
opens: declared.opens,
|
|
10011
|
+
closes: declared.closes,
|
|
10012
|
+
live: [...declared.live]
|
|
10085
10013
|
}
|
|
10086
10014
|
};
|
|
10087
10015
|
}
|
|
@@ -10113,7 +10041,8 @@ function recurringDefinition(object) {
|
|
|
10113
10041
|
object: named(declared.horizonAtLeast.object),
|
|
10114
10042
|
field: declared.horizonAtLeast.field
|
|
10115
10043
|
}
|
|
10116
|
-
} : {}
|
|
10044
|
+
} : {},
|
|
10045
|
+
...declared.horizonSetting ? { horizonSetting: { extension: object.extensionId, name: declared.horizonSetting } } : {}
|
|
10117
10046
|
}
|
|
10118
10047
|
};
|
|
10119
10048
|
}
|
|
@@ -10126,6 +10055,7 @@ function sellableDefinition(object, own) {
|
|
|
10126
10055
|
const currency = declared.currency ?? priceField?.definition.currency;
|
|
10127
10056
|
const { amount, balanceDue } = declared.deposit ?? {};
|
|
10128
10057
|
const grants = declared.grants;
|
|
10058
|
+
const finance = sellableFinance(declared.finance);
|
|
10129
10059
|
return {
|
|
10130
10060
|
price: nameOf(declared.price),
|
|
10131
10061
|
...currency ? { currency } : {},
|
|
@@ -10146,6 +10076,23 @@ function sellableDefinition(object, own) {
|
|
|
10146
10076
|
}
|
|
10147
10077
|
} : {},
|
|
10148
10078
|
...declared.onePerPerson ? { onePerPerson: nameOf(declared.onePerPerson) } : {},
|
|
10079
|
+
// Paths (`event.startsAt`) stay as declared, as moves' do; a field of the object is named.
|
|
10080
|
+
finance: finance.at?.includes(".") === false ? { ...finance, at: nameOf(finance.at) } : finance,
|
|
10081
|
+
// Paths (`class.classType.dropInPrice`) stay as declared: the host's path reader names each
|
|
10082
|
+
// part as the declaring extension's (ADR 0505); a field of the object is named here.
|
|
10083
|
+
...declared.moves ? {
|
|
10084
|
+
moves: {
|
|
10085
|
+
held: declared.moves.held,
|
|
10086
|
+
paid: declared.moves.paid,
|
|
10087
|
+
expired: declared.moves.expired,
|
|
10088
|
+
refund: [...declared.moves.refund ?? []],
|
|
10089
|
+
...declared.moves.price ? { price: { ...declared.moves.price } } : {},
|
|
10090
|
+
...declared.moves.title ? { title: declared.moves.title } : {},
|
|
10091
|
+
...declared.moves.order ? { order: nameOf(declared.moves.order) } : {},
|
|
10092
|
+
...declared.moves.guest ? { guest: true } : {},
|
|
10093
|
+
...declared.moves.holdCap ? { holdCap: { ...declared.moves.holdCap } } : {}
|
|
10094
|
+
}
|
|
10095
|
+
} : {},
|
|
10149
10096
|
...declared.tax ? {
|
|
10150
10097
|
tax: {
|
|
10151
10098
|
code: declared.tax.code,
|
|
@@ -10169,6 +10116,13 @@ function sellableDefinition(object, own) {
|
|
|
10169
10116
|
recurring: {
|
|
10170
10117
|
interval: declared.recurring.interval,
|
|
10171
10118
|
trialDays: opt(declared.recurring.trialDays),
|
|
10119
|
+
...declared.recurring.pause ? {
|
|
10120
|
+
pause: {
|
|
10121
|
+
minDays: opt(declared.recurring.pause.minDays),
|
|
10122
|
+
maxDays: opt(declared.recurring.pause.maxDays)
|
|
10123
|
+
}
|
|
10124
|
+
} : {},
|
|
10125
|
+
...declared.recurring.coolingOff ? { coolingOff: { setting: declared.recurring.coolingOff.setting } } : {},
|
|
10172
10126
|
...declared.recurring.grants ? {
|
|
10173
10127
|
grants: {
|
|
10174
10128
|
...declared.recurring.grants,
|
|
@@ -10178,6 +10132,20 @@ function sellableDefinition(object, own) {
|
|
|
10178
10132
|
}
|
|
10179
10133
|
} : {}
|
|
10180
10134
|
}
|
|
10135
|
+
} : {},
|
|
10136
|
+
// A path (`item.whereSold`) stays as declared, as moves' do; a field of the object is named.
|
|
10137
|
+
...declared.goods ? {
|
|
10138
|
+
goods: declared.goods.soldIn ? {
|
|
10139
|
+
soldIn: declared.goods.soldIn.includes(".") ? declared.goods.soldIn : nameOf(declared.goods.soldIn)
|
|
10140
|
+
} : {}
|
|
10141
|
+
} : {},
|
|
10142
|
+
...declared.delivery ? {
|
|
10143
|
+
delivery: {
|
|
10144
|
+
kind: nameOf(declared.delivery.kind),
|
|
10145
|
+
freeOver: opt(declared.delivery.freeOver),
|
|
10146
|
+
countries: opt(declared.delivery.countries),
|
|
10147
|
+
active: opt(declared.delivery.active)
|
|
10148
|
+
}
|
|
10181
10149
|
} : {}
|
|
10182
10150
|
};
|
|
10183
10151
|
}
|
|
@@ -10267,7 +10235,17 @@ var SYSTEM_FIELDS = [
|
|
|
10267
10235
|
];
|
|
10268
10236
|
function buildRegistry(state) {
|
|
10269
10237
|
const map = /* @__PURE__ */ new Map();
|
|
10270
|
-
const active = state.fields.filter(
|
|
10238
|
+
const active = state.fields.filter(
|
|
10239
|
+
(f) => f.status === "active" && !isRestrictedField(f.definition)
|
|
10240
|
+
);
|
|
10241
|
+
const restrictedOf = (object) => state.fields.filter(
|
|
10242
|
+
(f) => f.status === "active" && f.object === object.name && f.extensionId === object.extensionId && isRestrictedField(f.definition)
|
|
10243
|
+
).map((f) => ({
|
|
10244
|
+
name: f.name,
|
|
10245
|
+
label: f.definition.label,
|
|
10246
|
+
permission: f.definition.restricted,
|
|
10247
|
+
fieldType: f.type === "longText" ? "longText" : "text"
|
|
10248
|
+
}));
|
|
10271
10249
|
for (const [name, core] of Object.entries(CORE_OBJECTS)) {
|
|
10272
10250
|
const extra = active.filter((f) => f.object === name).flatMap((f) => [registryField(f, name), ...documentPathFields(f, name)]);
|
|
10273
10251
|
if (extra.length) map.set(name, { ...core, fields: [...core.fields, ...extra] });
|
|
@@ -10284,14 +10262,27 @@ function buildRegistry(state) {
|
|
|
10284
10262
|
);
|
|
10285
10263
|
const capacity = capacityDefinition(object, own);
|
|
10286
10264
|
const sellable = sellableDefinition(object, own);
|
|
10265
|
+
const stock = stockDefinition(object, own);
|
|
10266
|
+
const stockMoves = stockMovesDefinition(object, own);
|
|
10287
10267
|
const allowance = allowanceDefinition(object);
|
|
10268
|
+
const discount = object.definition.discount ? {
|
|
10269
|
+
...object.definition.discount,
|
|
10270
|
+
...object.definition.discount.codes ? {
|
|
10271
|
+
codes: {
|
|
10272
|
+
...object.definition.discount.codes,
|
|
10273
|
+
object: `${object.extensionId}.${object.definition.discount.codes.object}`
|
|
10274
|
+
}
|
|
10275
|
+
} : {}
|
|
10276
|
+
} : void 0;
|
|
10288
10277
|
const publishable = object.definition.publishable;
|
|
10278
|
+
const restricted = restrictedOf(object);
|
|
10289
10279
|
const fields = [
|
|
10290
10280
|
...SYSTEM_FIELDS,
|
|
10291
10281
|
...own.map((f) => registryField(f, object.name)),
|
|
10292
10282
|
...foreign.map((f) => registryField(f, object.name)),
|
|
10293
10283
|
...[...own, ...foreign].flatMap((f) => documentPathFields(f, object.name)),
|
|
10294
10284
|
...capacity ? CAPACITY_FIELDS : [],
|
|
10285
|
+
...stock ? STOCK_FIELDS : [],
|
|
10295
10286
|
...allowance?.kind === "holder" ? ALLOWANCE_FIELDS : [],
|
|
10296
10287
|
...publishable ? PUBLISHED_FIELDS : []
|
|
10297
10288
|
];
|
|
@@ -10311,11 +10302,29 @@ function buildRegistry(state) {
|
|
|
10311
10302
|
...object.definition.stages ? { stages: object.definition.stages } : {},
|
|
10312
10303
|
...capacity ? { capacity } : {},
|
|
10313
10304
|
...sellable ? { sellable } : {},
|
|
10305
|
+
...stock ? { stock } : {},
|
|
10306
|
+
...stockMoves ? { stockMoves } : {},
|
|
10314
10307
|
...allowance ? { allowance } : {},
|
|
10308
|
+
...discount ? { discount } : {},
|
|
10309
|
+
...object.definition.agreements ? { agreements: object.definition.agreements } : {},
|
|
10310
|
+
...object.definition.healthNotes ? { healthNotes: object.definition.healthNotes } : {},
|
|
10311
|
+
...restricted.length ? { restricted } : {},
|
|
10315
10312
|
...object.definition.states ? { states: object.definition.states } : {},
|
|
10313
|
+
...object.definition.signals?.length ? { signals: object.definition.signals } : {},
|
|
10316
10314
|
...claimsDefinition(object, own),
|
|
10317
10315
|
...object.definition.unique?.length ? { unique: object.definition.unique } : {},
|
|
10318
10316
|
...recurringDefinition(object),
|
|
10317
|
+
...staffedDefinition(object, own),
|
|
10318
|
+
...workedOnDefinition(object, own),
|
|
10319
|
+
...occupiesDefinition(object, own),
|
|
10320
|
+
...object.definition.calendarEntry ? {
|
|
10321
|
+
calendarEntry: {
|
|
10322
|
+
...object.definition.calendarEntry,
|
|
10323
|
+
live: [...object.definition.calendarEntry.live]
|
|
10324
|
+
}
|
|
10325
|
+
} : {},
|
|
10326
|
+
...intakeDefinition(object, own),
|
|
10327
|
+
...checklistsDefinition(object, own),
|
|
10319
10328
|
...object.definition.owner ? { ownerField: object.definition.owner } : {},
|
|
10320
10329
|
...object.definition.customer ? { customer: object.definition.customer } : {},
|
|
10321
10330
|
...object.definition.public ? { public: object.definition.public } : {},
|
|
@@ -10326,7 +10335,18 @@ function buildRegistry(state) {
|
|
|
10326
10335
|
publishable: {
|
|
10327
10336
|
content: [...publishable.content],
|
|
10328
10337
|
...publishable.slug ? { slug: publishable.slug } : {},
|
|
10329
|
-
...publishable.date ? { date: publishable.date } : {}
|
|
10338
|
+
...publishable.date ? { date: publishable.date } : {},
|
|
10339
|
+
...publishable.publishIn ? { publishIn: [...publishable.publishIn] } : {},
|
|
10340
|
+
...publishable.acknowledge ? {
|
|
10341
|
+
acknowledge: {
|
|
10342
|
+
who: publishable.acknowledge.who,
|
|
10343
|
+
manage: publishable.acknowledge.manage,
|
|
10344
|
+
...publishable.acknowledge.managed ? { managed: [...publishable.acknowledge.managed] } : {},
|
|
10345
|
+
...publishable.acknowledge.owner ? { owner: publishable.acknowledge.owner } : {},
|
|
10346
|
+
...publishable.acknowledge.notices ? { notices: publishable.acknowledge.notices } : {}
|
|
10347
|
+
}
|
|
10348
|
+
} : {},
|
|
10349
|
+
...publishable.staffRead ? { staffRead: true } : {}
|
|
10330
10350
|
}
|
|
10331
10351
|
} : {},
|
|
10332
10352
|
...object.definition.navigationOrder !== void 0 ? { navigationOrder: object.definition.navigationOrder } : {},
|
|
@@ -10357,7 +10377,7 @@ async function refreshSchemaRegistry(db) {
|
|
|
10357
10377
|
const objects = buildRegistry(state);
|
|
10358
10378
|
const storage = /* @__PURE__ */ new Map();
|
|
10359
10379
|
for (const f of state.fields) {
|
|
10360
|
-
if (f.status !== "active") continue;
|
|
10380
|
+
if (f.status !== "active" || isRestrictedField(f.definition)) continue;
|
|
10361
10381
|
const owner = state.objects.find((o) => o.name === f.object);
|
|
10362
10382
|
storage.set(`${f.object}|${f.name}`, {
|
|
10363
10383
|
extension: f.extensionId,
|
|
@@ -10464,7 +10484,14 @@ var originSchema = external_exports.object({
|
|
|
10464
10484
|
/** The extension whose code made the call (actor `extension`). */
|
|
10465
10485
|
extensionId: external_exports.string().optional(),
|
|
10466
10486
|
/** The agent that made the call (job_…, ADR 0344). Its session is `job:<id>`. */
|
|
10467
|
-
jobId: external_exports.string().optional()
|
|
10487
|
+
jobId: external_exports.string().optional(),
|
|
10488
|
+
/**
|
|
10489
|
+
* A staff call over a device session (ADR 0455), not a browser's: the company's app on a phone
|
|
10490
|
+
* (a role client or the owner's client, on the device's one staff session, ADR 0451) or the
|
|
10491
|
+
* command line's import door. Set by the HTTP surface from the session, never from the request;
|
|
10492
|
+
* recorded in the audit row. A setup change is never made or approved from it (stage 60, ADR 0872).
|
|
10493
|
+
*/
|
|
10494
|
+
staffDevice: external_exports.boolean().optional()
|
|
10468
10495
|
});
|
|
10469
10496
|
var ROLES = ["admin", "member", "viewer"];
|
|
10470
10497
|
var PERMISSIONS = [
|
|
@@ -10479,11 +10506,49 @@ var PERMISSIONS = [
|
|
|
10479
10506
|
"settings:manage",
|
|
10480
10507
|
"orders:refund",
|
|
10481
10508
|
"records:publish",
|
|
10482
|
-
"subscriptions:manage"
|
|
10509
|
+
"subscriptions:manage",
|
|
10510
|
+
"people:link",
|
|
10511
|
+
"agreements:manage",
|
|
10512
|
+
"agreements:paper",
|
|
10513
|
+
"agreements:health",
|
|
10514
|
+
"agreements:desk",
|
|
10515
|
+
"checklists:write",
|
|
10516
|
+
"invoices:write",
|
|
10517
|
+
"invoices:send",
|
|
10518
|
+
"invoices:credit",
|
|
10519
|
+
"invoices:payments",
|
|
10520
|
+
"accounting:manage",
|
|
10521
|
+
"inbox:read",
|
|
10522
|
+
"inbox:work",
|
|
10523
|
+
"inbox:manage",
|
|
10524
|
+
"notes:clients",
|
|
10525
|
+
"notes:sensitive",
|
|
10526
|
+
"notes:manage",
|
|
10527
|
+
"journeys:read",
|
|
10528
|
+
"journeys:manage",
|
|
10529
|
+
"journeys:publish",
|
|
10530
|
+
"orders:discount",
|
|
10531
|
+
"orders:payments",
|
|
10532
|
+
"people:cards",
|
|
10533
|
+
"stock:adjust",
|
|
10534
|
+
"finance:read",
|
|
10535
|
+
"finance:close",
|
|
10536
|
+
"bookingSystem:manage",
|
|
10537
|
+
"practitioners:manage"
|
|
10538
|
+
];
|
|
10539
|
+
var CORE_PERMISSION_NAMESPACES = [
|
|
10540
|
+
...new Set(PERMISSIONS.map((p) => p.split(":")[0]))
|
|
10483
10541
|
];
|
|
10484
10542
|
var ROLE_PERMISSIONS = {
|
|
10485
|
-
viewer: ["records:read"],
|
|
10486
|
-
member: [
|
|
10543
|
+
viewer: ["records:read", "inbox:read"],
|
|
10544
|
+
member: [
|
|
10545
|
+
"records:read",
|
|
10546
|
+
"records:write",
|
|
10547
|
+
"journeys:read",
|
|
10548
|
+
"people:cards",
|
|
10549
|
+
"inbox:read",
|
|
10550
|
+
"inbox:work"
|
|
10551
|
+
],
|
|
10487
10552
|
admin: PERMISSIONS
|
|
10488
10553
|
};
|
|
10489
10554
|
function roleHasPermission(role, permission) {
|
|
@@ -10492,8 +10557,40 @@ function roleHasPermission(role, permission) {
|
|
|
10492
10557
|
var GRANTABLE_PERMISSIONS = [
|
|
10493
10558
|
"records:publish",
|
|
10494
10559
|
"orders:refund",
|
|
10495
|
-
"subscriptions:manage"
|
|
10560
|
+
"subscriptions:manage",
|
|
10561
|
+
"people:link",
|
|
10562
|
+
"agreements:manage",
|
|
10563
|
+
"agreements:paper",
|
|
10564
|
+
"agreements:health",
|
|
10565
|
+
"agreements:desk",
|
|
10566
|
+
"checklists:write",
|
|
10567
|
+
"invoices:write",
|
|
10568
|
+
"invoices:send",
|
|
10569
|
+
"invoices:credit",
|
|
10570
|
+
"invoices:payments",
|
|
10571
|
+
"accounting:manage",
|
|
10572
|
+
"notes:clients",
|
|
10573
|
+
"notes:sensitive",
|
|
10574
|
+
"notes:manage",
|
|
10575
|
+
"journeys:manage",
|
|
10576
|
+
"journeys:publish",
|
|
10577
|
+
"orders:discount",
|
|
10578
|
+
"orders:payments",
|
|
10579
|
+
"people:cards",
|
|
10580
|
+
"stock:adjust",
|
|
10581
|
+
"finance:read",
|
|
10582
|
+
"finance:close",
|
|
10583
|
+
"bookingSystem:manage",
|
|
10584
|
+
"practitioners:manage"
|
|
10496
10585
|
];
|
|
10586
|
+
var RESTRICTED_CORE_PERMISSIONS = [
|
|
10587
|
+
"notes:clients",
|
|
10588
|
+
"notes:sensitive",
|
|
10589
|
+
"notes:manage",
|
|
10590
|
+
"orders:payments",
|
|
10591
|
+
"invoices:payments"
|
|
10592
|
+
];
|
|
10593
|
+
var FIXED_ROLE_CORE_GRANTS = ["people:cards", "agreements:desk"];
|
|
10497
10594
|
function holdsPermission(user, grants, permission) {
|
|
10498
10595
|
return roleHasPermission(user.role, permission) || GRANTABLE_PERMISSIONS.includes(permission) && (grants ?? []).includes(permission);
|
|
10499
10596
|
}
|
|
@@ -10501,10 +10598,15 @@ var MCP_SCOPES = ["read", "write", "admin"];
|
|
|
10501
10598
|
function grantableScopes(role) {
|
|
10502
10599
|
return role === "admin" ? [...MCP_SCOPES] : ["read", "write"];
|
|
10503
10600
|
}
|
|
10601
|
+
function placedAs(principal) {
|
|
10602
|
+
if (principal.kind === "device") throw new Error("An enrolled device places no order");
|
|
10603
|
+
if (principal.kind === "practitioner") throw new Error("A practitioner places no order");
|
|
10604
|
+
return principal.kind;
|
|
10605
|
+
}
|
|
10504
10606
|
function staffPrincipal(user) {
|
|
10505
10607
|
return Object.freeze({ kind: "staff", userId: user.id, role: user.role });
|
|
10506
10608
|
}
|
|
10507
|
-
var OUTSIDE_ACTORS = ["customer", "public"];
|
|
10609
|
+
var OUTSIDE_ACTORS = ["customer", "public", "device", "practitioner"];
|
|
10508
10610
|
var ALL_ACTORS = [...ACTORS, ...OUTSIDE_ACTORS];
|
|
10509
10611
|
|
|
10510
10612
|
// ../core/src/records/columns.ts
|
|
@@ -10514,10 +10616,181 @@ function viewColumnOf(field) {
|
|
|
10514
10616
|
return match?.[1] ?? null;
|
|
10515
10617
|
}
|
|
10516
10618
|
|
|
10619
|
+
// ../core/src/visibility/guardians.ts
|
|
10620
|
+
var GUARDIAN_LINK = "guardian";
|
|
10621
|
+
function guardianProblems(object) {
|
|
10622
|
+
const declared = object.customer?.guardians;
|
|
10623
|
+
if (!declared || !object.customer) return [];
|
|
10624
|
+
const problems = [];
|
|
10625
|
+
if (object.name === "person") {
|
|
10626
|
+
problems.push("a Person's own record cannot open to their guardians");
|
|
10627
|
+
}
|
|
10628
|
+
if (declared.madeBy !== void 0) {
|
|
10629
|
+
const name = declared.madeBy;
|
|
10630
|
+
const field = object.fields.find((f) => f.name === name);
|
|
10631
|
+
if (!field?.column || field.fieldType !== "relation" || field.options?.to !== "person" || field.options.many) {
|
|
10632
|
+
problems.push(`customer.guardians.madeBy "${name}" must be a relation to one person`);
|
|
10633
|
+
} else if (!field.readOnly) {
|
|
10634
|
+
problems.push(`customer.guardians.madeBy "${name}" must be read-only: the host sets it`);
|
|
10635
|
+
}
|
|
10636
|
+
if (name === object.customer.field) {
|
|
10637
|
+
problems.push("customer.guardians.madeBy cannot be the customer field");
|
|
10638
|
+
}
|
|
10639
|
+
if (object.customer.write.includes(name)) {
|
|
10640
|
+
problems.push(
|
|
10641
|
+
`customer.guardians.madeBy "${name}" is set by the host: customer.write may not list it`
|
|
10642
|
+
);
|
|
10643
|
+
}
|
|
10644
|
+
}
|
|
10645
|
+
return problems;
|
|
10646
|
+
}
|
|
10647
|
+
function dependantsSql(personId) {
|
|
10648
|
+
return sql`SELECT l.dependant_id FROM core_person_link l JOIN core_person d ON d.id = l.dependant_id AND d.deleted_at IS NULL JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL WHERE l.guardian_id = ${personId} AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL`;
|
|
10649
|
+
}
|
|
10650
|
+
function ownersWhere(column, personId, dependants) {
|
|
10651
|
+
const own = sql`${sql.ref(column)} = ${personId}`;
|
|
10652
|
+
return dependants ? sql`(${own} OR ${sql.ref(column)} IN (${dependantsSql(personId)}))` : own;
|
|
10653
|
+
}
|
|
10654
|
+
async function isLiveDependant(db, guardianId, personId) {
|
|
10655
|
+
if (guardianId === personId) return false;
|
|
10656
|
+
const { rows } = await sql`SELECT 1 AS one WHERE ${personId} IN (${dependantsSql(guardianId)})`.execute(db);
|
|
10657
|
+
return rows.length > 0;
|
|
10658
|
+
}
|
|
10659
|
+
function linkGuardStatement(guardianId, dependantId) {
|
|
10660
|
+
return CompiledQuery.raw(
|
|
10661
|
+
"INSERT INTO core_person_link_guard (guardian_id, dependant_id) VALUES (?, ?)",
|
|
10662
|
+
[guardianId, dependantId]
|
|
10663
|
+
);
|
|
10664
|
+
}
|
|
10665
|
+
async function familyOf(reader) {
|
|
10666
|
+
const principal = reader.principal;
|
|
10667
|
+
if (principal.kind !== "customer") return { self: null, dependants: [], guardians: [] };
|
|
10668
|
+
const me = principal.personId;
|
|
10669
|
+
const [own, dependants, guardians] = await Promise.all([
|
|
10670
|
+
sql`SELECT display_name AS name FROM core_person WHERE id = ${me} AND deleted_at IS NULL`.execute(
|
|
10671
|
+
reader.db
|
|
10672
|
+
),
|
|
10673
|
+
sql`SELECT p.id AS id, p.display_name AS name FROM core_person p WHERE p.id IN (${dependantsSql(me)}) ORDER BY p.display_name, p.id`.execute(
|
|
10674
|
+
reader.db
|
|
10675
|
+
),
|
|
10676
|
+
sql`SELECT p.id AS id, p.display_name AS name FROM core_person_link l JOIN core_person p ON p.id = l.guardian_id AND p.deleted_at IS NULL JOIN core_person me ON me.id = l.dependant_id AND me.deleted_at IS NULL WHERE l.dependant_id = ${me} AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL ORDER BY p.display_name, p.id`.execute(
|
|
10677
|
+
reader.db
|
|
10678
|
+
)
|
|
10679
|
+
]);
|
|
10680
|
+
const shown = (rows) => rows.map((row) => ({ personId: String(row.id), name: String(row.name) }));
|
|
10681
|
+
return {
|
|
10682
|
+
self: { personId: me, name: String(own.rows[0]?.name ?? "") },
|
|
10683
|
+
dependants: shown(dependants.rows),
|
|
10684
|
+
guardians: shown(guardians.rows)
|
|
10685
|
+
};
|
|
10686
|
+
}
|
|
10687
|
+
async function dependantFirstNames(reader) {
|
|
10688
|
+
const principal = reader.principal;
|
|
10689
|
+
if (principal.kind !== "customer") return /* @__PURE__ */ new Map();
|
|
10690
|
+
const { rows } = await sql`SELECT p.id AS id, p.given_name AS given, p.display_name AS name FROM core_person p WHERE p.id IN (${dependantsSql(principal.personId)})`.execute(
|
|
10691
|
+
reader.db
|
|
10692
|
+
);
|
|
10693
|
+
return new Map(
|
|
10694
|
+
rows.map((row) => {
|
|
10695
|
+
const given = (row.given ?? "").trim();
|
|
10696
|
+
const display = (row.name ?? "").trim();
|
|
10697
|
+
return [String(row.id), given || display.split(/\s+/)[0] || display || "Child"];
|
|
10698
|
+
})
|
|
10699
|
+
);
|
|
10700
|
+
}
|
|
10701
|
+
async function recordsMadeFor(db, guardianId, dependantId) {
|
|
10702
|
+
const out = [];
|
|
10703
|
+
for (const object of listObjects()) {
|
|
10704
|
+
const declared = object.customer;
|
|
10705
|
+
const madeBy = declared?.guardians?.madeBy;
|
|
10706
|
+
if (!declared || !madeBy) continue;
|
|
10707
|
+
const owner = object.fields.find((f) => f.name === declared.field);
|
|
10708
|
+
const maker = object.fields.find((f) => f.name === madeBy);
|
|
10709
|
+
const ownerColumn = owner ? viewColumnOf(owner) : null;
|
|
10710
|
+
const makerColumn = maker ? viewColumnOf(maker) : null;
|
|
10711
|
+
if (!ownerColumn || !makerColumn) continue;
|
|
10712
|
+
const { rows } = await sql`SELECT count(*) AS n FROM ${sql.table(object.source)} WHERE ${sql.ref(ownerColumn)} = ${dependantId} AND ${sql.ref(makerColumn)} = ${guardianId}`.execute(
|
|
10713
|
+
db
|
|
10714
|
+
);
|
|
10715
|
+
const count = Number(rows[0]?.n ?? 0);
|
|
10716
|
+
if (count) out.push({ object: object.name, label: object.plural ?? object.label, count });
|
|
10717
|
+
}
|
|
10718
|
+
return out;
|
|
10719
|
+
}
|
|
10720
|
+
async function sharedEmailWarning(db, guardianId, dependantId) {
|
|
10721
|
+
const { rows } = await sql`SELECT DISTINCT e.email AS shared FROM core_person_emails e WHERE e.person_id = ${dependantId} AND (e.email IN (SELECT g.email FROM core_person_emails g WHERE g.person_id = ${guardianId}) OR e.email IN (SELECT c.email FROM core_customer c WHERE c.person_id IS NULL OR c.person_id != ${dependantId}))`.execute(
|
|
10722
|
+
db
|
|
10723
|
+
);
|
|
10724
|
+
if (!rows.length) return null;
|
|
10725
|
+
return `The child's record has an email that is also the parent's or another account's (${rows.map((r) => r.shared).join(", ")}). Signing in with it would open that account as the child's: give the child their own address or none.`;
|
|
10726
|
+
}
|
|
10727
|
+
async function hasLiveGuardian(db, personId) {
|
|
10728
|
+
const { rows } = await sql`SELECT 1 AS one FROM core_person_link l JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL WHERE l.dependant_id = ${personId} AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL LIMIT 1`.execute(
|
|
10729
|
+
db
|
|
10730
|
+
);
|
|
10731
|
+
return rows.length > 0;
|
|
10732
|
+
}
|
|
10733
|
+
var ADDRESSES_PER_STATEMENT = 90;
|
|
10734
|
+
function mailboxSql(column) {
|
|
10735
|
+
const e = sql.ref(column);
|
|
10736
|
+
const local = sql`CASE WHEN instr(${e}, '+') > 1 AND instr(${e}, '+') < instr(${e}, '@') THEN substr(${e}, 1, instr(${e}, '+') - 1) ELSE substr(${e}, 1, instr(${e}, '@') - 1) END`;
|
|
10737
|
+
const tagless = sql`CASE WHEN instr(${e}, '+') > 1 AND instr(${e}, '+') < instr(${e}, '@') THEN substr(${e}, 1, instr(${e}, '+') - 1) || substr(${e}, instr(${e}, '@')) ELSE ${e} END`;
|
|
10738
|
+
return sql`(CASE WHEN substr(${e}, instr(${e}, '@') + 1) IN ('gmail.com', 'googlemail.com') THEN replace(${local}, '.', '') || '@gmail.com' ELSE ${tagless} END)`;
|
|
10739
|
+
}
|
|
10740
|
+
async function peopleAtAddresses(db, mailboxes) {
|
|
10741
|
+
const out = /* @__PURE__ */ new Map();
|
|
10742
|
+
const all = [...new Set(mailboxes)];
|
|
10743
|
+
const form = mailboxSql("e.email");
|
|
10744
|
+
for (let i = 0; i < all.length; i += ADDRESSES_PER_STATEMENT) {
|
|
10745
|
+
const chunk = all.slice(i, i + ADDRESSES_PER_STATEMENT);
|
|
10746
|
+
const { rows } = await sql`SELECT ${form} AS folded, p.id AS id, ${childSql()} AS child FROM core_person_emails e JOIN core_person p ON p.id = e.person_id AND p.deleted_at IS NULL WHERE e.live = 1 AND ${form} IN (${sql.join(chunk)})`.execute(
|
|
10747
|
+
db
|
|
10748
|
+
);
|
|
10749
|
+
collectHolders(out, rows);
|
|
10750
|
+
}
|
|
10751
|
+
return out;
|
|
10752
|
+
}
|
|
10753
|
+
async function peopleAtNumbers(db, numbers) {
|
|
10754
|
+
const out = /* @__PURE__ */ new Map();
|
|
10755
|
+
const all = [...new Set(numbers)];
|
|
10756
|
+
for (let i = 0; i < all.length; i += ADDRESSES_PER_STATEMENT) {
|
|
10757
|
+
const chunk = all.slice(i, i + ADDRESSES_PER_STATEMENT);
|
|
10758
|
+
const { rows } = await sql`SELECT n.number_normalised AS folded, p.id AS id, ${childSql()} AS child FROM core_person_phones n JOIN core_person p ON p.id = n.person_id AND p.deleted_at IS NULL WHERE n.number_normalised IN (${sql.join(chunk)})`.execute(
|
|
10759
|
+
db
|
|
10760
|
+
);
|
|
10761
|
+
collectHolders(out, rows);
|
|
10762
|
+
}
|
|
10763
|
+
return out;
|
|
10764
|
+
}
|
|
10765
|
+
function childSql() {
|
|
10766
|
+
return sql`EXISTS (SELECT 1 FROM core_person_link l JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL WHERE l.dependant_id = p.id AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL)`;
|
|
10767
|
+
}
|
|
10768
|
+
function collectHolders(out, rows) {
|
|
10769
|
+
for (const row of rows) {
|
|
10770
|
+
const holders = out.get(row.folded) ?? [];
|
|
10771
|
+
if (!holders.some((h) => h.id === row.id)) {
|
|
10772
|
+
holders.push({ id: row.id, child: Number(row.child) === 1 });
|
|
10773
|
+
}
|
|
10774
|
+
out.set(row.folded, holders);
|
|
10775
|
+
}
|
|
10776
|
+
}
|
|
10777
|
+
async function livePersonAfterMerges(db, personId) {
|
|
10778
|
+
let id = personId;
|
|
10779
|
+
for (let hop = 0; hop < 5; hop += 1) {
|
|
10780
|
+
const { rows } = await sql`SELECT deleted_at, merged_into_id FROM core_person WHERE id = ${id}`.execute(db);
|
|
10781
|
+
const row = rows[0];
|
|
10782
|
+
if (!row) return null;
|
|
10783
|
+
if (row.deleted_at === null) return id;
|
|
10784
|
+
if (!row.merged_into_id) return null;
|
|
10785
|
+
id = row.merged_into_id;
|
|
10786
|
+
}
|
|
10787
|
+
return null;
|
|
10788
|
+
}
|
|
10789
|
+
|
|
10517
10790
|
// ../core/src/visibility/public.ts
|
|
10518
10791
|
function publicProblems(object) {
|
|
10519
10792
|
const problems = readProblems(object, "public");
|
|
10520
|
-
if (object.public && object.customer) {
|
|
10793
|
+
if (object.public && object.customer && !object.publishable) {
|
|
10521
10794
|
problems.unshift("an object declares customer or public, not both");
|
|
10522
10795
|
}
|
|
10523
10796
|
if (object.public && object.publishable) problems.push(...contentProblems(object));
|
|
@@ -10528,9 +10801,7 @@ function contentProblems(object) {
|
|
|
10528
10801
|
const publishable = object.publishable;
|
|
10529
10802
|
if (!declared || !publishable) return [];
|
|
10530
10803
|
const problems = [];
|
|
10531
|
-
if (!publishable.slug) {
|
|
10532
|
-
problems.push("a publishable object the public reads names its slug (publishable.slug)");
|
|
10533
|
-
} else if (!declared.read.includes(publishable.slug)) {
|
|
10804
|
+
if (publishable.slug && !declared.read.includes(publishable.slug)) {
|
|
10534
10805
|
problems.push(`public.read lists the slug "${publishable.slug}": it is how the public reads`);
|
|
10535
10806
|
}
|
|
10536
10807
|
const content = new Set(publishable.content);
|
|
@@ -10544,8 +10815,19 @@ function contentProblems(object) {
|
|
|
10544
10815
|
problems.push(`public.read lists "${name}", a path of a document that is not content`);
|
|
10545
10816
|
}
|
|
10546
10817
|
}
|
|
10547
|
-
if (object.
|
|
10548
|
-
problems.push("a publishable object the public reads declares no
|
|
10818
|
+
if (object.customerVia) {
|
|
10819
|
+
problems.push("a publishable object the public reads declares no customerVia");
|
|
10820
|
+
}
|
|
10821
|
+
if (object.customer) {
|
|
10822
|
+
if (publishable.slug) problems.push("a publishable object with an author has no slug");
|
|
10823
|
+
if (declared.read.includes(object.customer.field)) {
|
|
10824
|
+
problems.push(`public.read lists "${object.customer.field}", the author`);
|
|
10825
|
+
}
|
|
10826
|
+
for (const name of declared.read) {
|
|
10827
|
+
if (object.customer.write.includes(name) && !content.has(name)) {
|
|
10828
|
+
problems.push(`public.read lists "${name}", which the author writes and is not content`);
|
|
10829
|
+
}
|
|
10830
|
+
}
|
|
10549
10831
|
}
|
|
10550
10832
|
return problems;
|
|
10551
10833
|
}
|
|
@@ -10580,13 +10862,23 @@ function readProblems(object, key) {
|
|
|
10580
10862
|
if (typeof condition === "string") problems.push(condition);
|
|
10581
10863
|
return problems;
|
|
10582
10864
|
}
|
|
10583
|
-
function resolveCondition(object, declared, key = "public") {
|
|
10865
|
+
function resolveCondition(object, declared, key = "public", depth = 0) {
|
|
10584
10866
|
const { when } = declared;
|
|
10585
10867
|
if (!when) return null;
|
|
10868
|
+
const list = Array.isArray(when) ? when : [when];
|
|
10869
|
+
const resolved = [];
|
|
10870
|
+
for (const condition of list) {
|
|
10871
|
+
const one = resolveOne(object, condition, key, depth);
|
|
10872
|
+
if (typeof one === "string") return one;
|
|
10873
|
+
resolved.push(one);
|
|
10874
|
+
}
|
|
10875
|
+
return resolved;
|
|
10876
|
+
}
|
|
10877
|
+
function resolveOne(object, when, key, depth) {
|
|
10586
10878
|
const fieldOf = (o, name) => o.fields.find((f) => f.name === name);
|
|
10587
10879
|
if (when.via === void 0) {
|
|
10588
|
-
const own = fieldOf(object, when.field);
|
|
10589
|
-
if (
|
|
10880
|
+
const own = when.field === void 0 ? void 0 : fieldOf(object, when.field);
|
|
10881
|
+
if (own?.fieldType !== "select" || !own.column || !when.in) {
|
|
10590
10882
|
return `${key}.when.field "${when.field}" must be a select field`;
|
|
10591
10883
|
}
|
|
10592
10884
|
return { column: own.column, values: [...when.in] };
|
|
@@ -10594,11 +10886,27 @@ function resolveCondition(object, declared, key = "public") {
|
|
|
10594
10886
|
const via = fieldOf(object, when.via);
|
|
10595
10887
|
const to = via?.options?.to;
|
|
10596
10888
|
const target = to ? getObject(to) : void 0;
|
|
10597
|
-
if (
|
|
10889
|
+
if (via?.fieldType !== "relation" || via.options?.many || !via.column || !target) {
|
|
10598
10890
|
return `${key}.when.via "${when.via}" must be a relation to one record`;
|
|
10599
10891
|
}
|
|
10600
|
-
|
|
10601
|
-
|
|
10892
|
+
if (when.field === void 0 && when.in === void 0) {
|
|
10893
|
+
if (key !== "public") return `${key}.when.via "${when.via}" alone is the public's`;
|
|
10894
|
+
const declared = target.public;
|
|
10895
|
+
if (!declared) return `public.when.via "${when.via}" alone: ${target.name} declares no public`;
|
|
10896
|
+
if (depth > 0) return `public.when.via "${when.via}" alone: one step only, no chains`;
|
|
10897
|
+
const conditions = resolveCondition(target, declared, "public", depth + 1);
|
|
10898
|
+
if (typeof conditions === "string") return conditions;
|
|
10899
|
+
return {
|
|
10900
|
+
column: via.column,
|
|
10901
|
+
values: [],
|
|
10902
|
+
public: {
|
|
10903
|
+
source: target.publishable ? liveViewOf(target.name) : target.source,
|
|
10904
|
+
conditions: conditions ?? []
|
|
10905
|
+
}
|
|
10906
|
+
};
|
|
10907
|
+
}
|
|
10908
|
+
const tested = when.field === void 0 ? void 0 : fieldOf(target, when.field);
|
|
10909
|
+
if (tested?.fieldType !== "select" || !tested.column || !when.in) {
|
|
10602
10910
|
return `${key}.when.field "${when.field}" must be a select field of ${target.name}`;
|
|
10603
10911
|
}
|
|
10604
10912
|
return {
|
|
@@ -10655,6 +10963,7 @@ function customerProblems(object) {
|
|
|
10655
10963
|
if (!declared) return [];
|
|
10656
10964
|
const problems = [];
|
|
10657
10965
|
const field = (name) => object.fields.find((f) => f.name === name);
|
|
10966
|
+
const restricted = new Set((object.restricted ?? []).map((f) => f.name));
|
|
10658
10967
|
const owner = field(declared.field);
|
|
10659
10968
|
if (!owner?.column) {
|
|
10660
10969
|
problems.push(`customer.field "${declared.field}" is not a single-valued field`);
|
|
@@ -10670,6 +10979,7 @@ function customerProblems(object) {
|
|
|
10670
10979
|
]) {
|
|
10671
10980
|
if (new Set(names).size !== names.length) problems.push(`customer.${key} lists a field twice`);
|
|
10672
10981
|
for (const name of names) {
|
|
10982
|
+
if (restricted.has(name)) continue;
|
|
10673
10983
|
const f = field(name);
|
|
10674
10984
|
if (!f) problems.push(`customer.${key} lists "${name}", which is not a field`);
|
|
10675
10985
|
else if (!viewColumnOf(f))
|
|
@@ -10686,6 +10996,7 @@ function customerProblems(object) {
|
|
|
10686
10996
|
problems.push(`customer.write lists "${name}", which customer.read does not`);
|
|
10687
10997
|
}
|
|
10688
10998
|
}
|
|
10999
|
+
problems.push(...guardianProblems(object));
|
|
10689
11000
|
return problems;
|
|
10690
11001
|
}
|
|
10691
11002
|
function customerScope(object, personId) {
|
|
@@ -10708,6 +11019,8 @@ function customerScope(object, personId) {
|
|
|
10708
11019
|
columns,
|
|
10709
11020
|
writable: new Set(declared.write),
|
|
10710
11021
|
declaration: declared,
|
|
11022
|
+
dependants: declared.guardians !== void 0,
|
|
11023
|
+
dependantsWrite: declared.guardians?.write === true,
|
|
10711
11024
|
...shared ? { shared } : {}
|
|
10712
11025
|
};
|
|
10713
11026
|
}
|
|
@@ -10746,10 +11059,56 @@ function unknownObject(name) {
|
|
|
10746
11059
|
return new ValidationError(`Unknown object "${name}"`, { object: name });
|
|
10747
11060
|
}
|
|
10748
11061
|
|
|
11062
|
+
// ../core/src/visibility/notes.ts
|
|
11063
|
+
var NOTE_LEVELS = [
|
|
11064
|
+
"staff",
|
|
11065
|
+
"coaches",
|
|
11066
|
+
"sensitive"
|
|
11067
|
+
];
|
|
11068
|
+
function noteRights(viewer) {
|
|
11069
|
+
const { principal } = viewer;
|
|
11070
|
+
if (principal.kind !== "staff") return null;
|
|
11071
|
+
if (viewer.actor !== "human") return null;
|
|
11072
|
+
const holds = (permission) => holdsPermission({ role: principal.role }, viewer.permissionGrants, permission);
|
|
11073
|
+
return {
|
|
11074
|
+
userId: principal.userId,
|
|
11075
|
+
clients: holds("notes:clients"),
|
|
11076
|
+
sensitive: holds("notes:sensitive"),
|
|
11077
|
+
manage: holds("notes:manage")
|
|
11078
|
+
};
|
|
11079
|
+
}
|
|
11080
|
+
function readsEveryNote(rights, level) {
|
|
11081
|
+
if (level === "staff") return true;
|
|
11082
|
+
if (!rights) return false;
|
|
11083
|
+
return level === "coaches" ? rights.clients : rights.sensitive;
|
|
11084
|
+
}
|
|
11085
|
+
function noteScopeWhere(viewer, alias) {
|
|
11086
|
+
const rights = noteRights(viewer);
|
|
11087
|
+
const level = sql.ref(`${alias}.level`);
|
|
11088
|
+
if (!rights) return sql`${level} = 'staff'`;
|
|
11089
|
+
if (rights.clients && rights.sensitive) return null;
|
|
11090
|
+
const me = rights.userId;
|
|
11091
|
+
const authored = sql`(${sql.ref(`${alias}.author_user_id`)} = ${me} AND EXISTS (SELECT 1 FROM core_user nu WHERE nu.id = ${me} AND nu.deactivated_at IS NULL))`;
|
|
11092
|
+
const caredFor = sql`EXISTS (SELECT 1 FROM core_activity_links nl JOIN core_person_carer nc ON nc.person_id = nl.record_id AND nc.user_id = ${me} AND nc.ended_at IS NULL JOIN core_person np ON np.id = nc.person_id AND np.deleted_at IS NULL WHERE nl.activity_id = ${sql.ref(`${alias}.id`)} AND nl.object_type = 'person')`;
|
|
11093
|
+
const coaches = rights.clients ? sql`1 = 1` : sql`(${authored} OR ${caredFor})`;
|
|
11094
|
+
const sensitive = rights.sensitive ? sql`1 = 1` : authored;
|
|
11095
|
+
return sql`(${level} = 'staff' OR (${level} = 'coaches' AND ${coaches}) OR (${level} = 'sensitive' AND ${sensitive}))`;
|
|
11096
|
+
}
|
|
11097
|
+
function hiddenNoteIds(viewer) {
|
|
11098
|
+
const scope = noteScopeWhere(viewer, "hn");
|
|
11099
|
+
if (!scope) return sql`(SELECT NULL WHERE 0)`;
|
|
11100
|
+
return sql`(SELECT hn.id FROM core_activity hn WHERE hn.level != 'staff' AND NOT ${scope})`;
|
|
11101
|
+
}
|
|
11102
|
+
function noteLevelGuard(id, level) {
|
|
11103
|
+
return sql`INSERT INTO core_note_guard (expected, actual) SELECT 1, count(*) FROM core_activity WHERE id = ${id} AND level = ${level}`;
|
|
11104
|
+
}
|
|
11105
|
+
|
|
10749
11106
|
// ../core/src/visibility/via.ts
|
|
10750
11107
|
function customerViaProblems(object) {
|
|
10751
11108
|
const declared = object.customerVia;
|
|
10752
|
-
|
|
11109
|
+
return declared ? checkVia(object, declared).problems : [];
|
|
11110
|
+
}
|
|
11111
|
+
function checkVia(object, declared) {
|
|
10753
11112
|
const problems = [];
|
|
10754
11113
|
if (object.customer) {
|
|
10755
11114
|
problems.push("an object that declares a customer cannot also declare customerVia");
|
|
@@ -10766,7 +11125,7 @@ function customerViaProblems(object) {
|
|
|
10766
11125
|
}
|
|
10767
11126
|
const link = resolveLink(object, declared);
|
|
10768
11127
|
if (typeof link === "string") problems.push(link);
|
|
10769
|
-
return problems;
|
|
11128
|
+
return { problems, link: typeof link === "string" ? null : link };
|
|
10770
11129
|
}
|
|
10771
11130
|
function resolveLink(object, declared) {
|
|
10772
11131
|
const from = getObject(declared.from);
|
|
@@ -10787,13 +11146,18 @@ function resolveLink(object, declared) {
|
|
|
10787
11146
|
if (!from.customer.read.includes(declared.field)) {
|
|
10788
11147
|
return `customerVia.field "${declared.field}" must be one the customer of ${from.name} may read`;
|
|
10789
11148
|
}
|
|
10790
|
-
return {
|
|
11149
|
+
return {
|
|
11150
|
+
source: from.source,
|
|
11151
|
+
pointer: pointer.column,
|
|
11152
|
+
owner: owner.column,
|
|
11153
|
+
dependants: from.customer.guardians !== void 0
|
|
11154
|
+
};
|
|
10791
11155
|
}
|
|
10792
11156
|
function customerViaScope(object, personId) {
|
|
10793
11157
|
const declared = object.customerVia;
|
|
10794
11158
|
if (!declared) return null;
|
|
10795
|
-
const problems =
|
|
10796
|
-
if (problems.length) {
|
|
11159
|
+
const { problems, link } = checkVia(object, declared);
|
|
11160
|
+
if (problems.length || !link) {
|
|
10797
11161
|
throw new Error(`${object.name}: invalid customerVia declaration: ${problems.join("; ")}`);
|
|
10798
11162
|
}
|
|
10799
11163
|
const shared = signedInScope(object) ?? publicScope(object);
|
|
@@ -10812,7 +11176,7 @@ function customerViaScope(object, personId) {
|
|
|
10812
11176
|
personId,
|
|
10813
11177
|
fields,
|
|
10814
11178
|
columns: [...columns].map(([column, shownOn]) => ({ column, shownOn })),
|
|
10815
|
-
link
|
|
11179
|
+
link,
|
|
10816
11180
|
public: shared,
|
|
10817
11181
|
declaration: declared
|
|
10818
11182
|
};
|
|
@@ -10844,6 +11208,8 @@ function scopeOf(principal, given, throughOwnRecords = true) {
|
|
|
10844
11208
|
return customerScope(object, principal.personId) ?? (throughOwnRecords ? customerViaScope(object, principal.personId) : null) ?? signedInScope(object) ?? publicScope(object) ?? NONE;
|
|
10845
11209
|
case "public":
|
|
10846
11210
|
return publicScope(object) ?? NONE;
|
|
11211
|
+
case "practitioner":
|
|
11212
|
+
return NONE;
|
|
10847
11213
|
default:
|
|
10848
11214
|
return NONE;
|
|
10849
11215
|
}
|
|
@@ -10887,14 +11253,15 @@ function buyableSource(ctx, object) {
|
|
|
10887
11253
|
}
|
|
10888
11254
|
function reachedWhere(scope) {
|
|
10889
11255
|
const { link } = scope;
|
|
10890
|
-
|
|
11256
|
+
const owners = ownersWhere(link.owner, scope.personId, link.dependants);
|
|
11257
|
+
return sql`id IN (SELECT ${sql.ref(link.pointer)} FROM ${sql.table(link.source)} WHERE ${owners} AND ${sql.ref(link.pointer)} IS NOT NULL)`;
|
|
10891
11258
|
}
|
|
10892
11259
|
function sourceOf(scope, definition, name) {
|
|
10893
11260
|
switch (scope.kind) {
|
|
10894
11261
|
case "all":
|
|
10895
11262
|
return sql`${sql.table(definition.source)}`.as(name);
|
|
10896
11263
|
case "customer": {
|
|
10897
|
-
const own =
|
|
11264
|
+
const own = ownersWhere(scope.column, scope.personId, scope.dependants);
|
|
10898
11265
|
if (!scope.shared) {
|
|
10899
11266
|
const columns2 = sql.join(scope.columns.map((column) => sql.ref(column)));
|
|
10900
11267
|
return sql`(SELECT ${columns2} FROM ${sql.table(definition.source)} WHERE ${own})`.as(
|
|
@@ -10943,8 +11310,14 @@ function previewSource(object, id) {
|
|
|
10943
11310
|
definition.source
|
|
10944
11311
|
);
|
|
10945
11312
|
}
|
|
10946
|
-
function conditionSql(
|
|
10947
|
-
if (!
|
|
11313
|
+
function conditionSql(conditions) {
|
|
11314
|
+
if (!conditions?.length) return sql`1 = 1`;
|
|
11315
|
+
return sql`(${sql.join(conditions.map(oneConditionSql), sql` AND `)})`;
|
|
11316
|
+
}
|
|
11317
|
+
function oneConditionSql(condition) {
|
|
11318
|
+
if (condition.public) {
|
|
11319
|
+
return sql`${sql.ref(condition.column)} IN (SELECT id FROM ${sql.table(condition.public.source)} WHERE ${conditionSql(condition.public.conditions)})`;
|
|
11320
|
+
}
|
|
10948
11321
|
const values = sql.join(condition.values.map((value) => sql`${value}`));
|
|
10949
11322
|
return condition.via ? sql`${sql.ref(condition.column)} IN (SELECT id FROM ${sql.table(condition.via.source)} WHERE ${sql.ref(condition.via.column)} IN (${values}))` : sql`${sql.ref(condition.column)} IN (${values})`;
|
|
10950
11323
|
}
|
|
@@ -10955,21 +11328,35 @@ function ownedSource(ctx, object, alias) {
|
|
|
10955
11328
|
case "all":
|
|
10956
11329
|
return sql`${sql.table(object.source)}`.as(name);
|
|
10957
11330
|
case "customer":
|
|
10958
|
-
return sql`(SELECT id FROM ${sql.table(object.source)} WHERE ${
|
|
11331
|
+
return sql`(SELECT id, ${sql.ref(scope.column)} AS owner FROM ${sql.table(object.source)} WHERE ${ownersWhere(scope.column, scope.personId, scope.dependantsWrite)})`.as(
|
|
10959
11332
|
name
|
|
10960
11333
|
);
|
|
10961
11334
|
default:
|
|
10962
11335
|
throw unknownObject(object.name);
|
|
10963
11336
|
}
|
|
10964
11337
|
}
|
|
11338
|
+
function ownReadSource(ctx, object, alias) {
|
|
11339
|
+
const scope = scopeOf(ctx.principal, object);
|
|
11340
|
+
if (scope.kind !== "customer") throw unknownObject(object.name);
|
|
11341
|
+
return sql`(SELECT id, ${sql.ref(scope.column)} AS owner FROM ${sql.table(object.source)} WHERE ${ownersWhere(scope.column, scope.personId, scope.dependants)})`.as(
|
|
11342
|
+
alias
|
|
11343
|
+
);
|
|
11344
|
+
}
|
|
10965
11345
|
function visibleTable(ctx, object, alias) {
|
|
10966
11346
|
const definition = resolve(object);
|
|
10967
11347
|
const table = isCoreObject(definition.name) ? CORE_SOURCES[definition.name].table : Object.hasOwn(BASE_TABLES, definition.name) ? BASE_TABLES[definition.name] : objectTableOf(definition.name);
|
|
10968
11348
|
if (!table) throw new Error(`${definition.name} has no record table`);
|
|
10969
11349
|
const scope = scopeOf(ctx.principal, definition);
|
|
10970
11350
|
switch (scope.kind) {
|
|
10971
|
-
case "all":
|
|
11351
|
+
case "all": {
|
|
11352
|
+
const notes = definition.name === "activity" ? noteScopeWhere(ctx, "n") : null;
|
|
11353
|
+
if (notes) {
|
|
11354
|
+
return sql`(SELECT * FROM ${sql.table(ident(table))} n WHERE ${notes})`.as(
|
|
11355
|
+
alias ?? table
|
|
11356
|
+
);
|
|
11357
|
+
}
|
|
10972
11358
|
return sql`${sql.table(ident(table))}`.as(alias ?? table);
|
|
11359
|
+
}
|
|
10973
11360
|
default:
|
|
10974
11361
|
throw unknownObject(definition.name);
|
|
10975
11362
|
}
|
|
@@ -11027,59 +11414,71 @@ export {
|
|
|
11027
11414
|
DynamicTableBuilder,
|
|
11028
11415
|
parseTable,
|
|
11029
11416
|
sql,
|
|
11030
|
-
|
|
11031
|
-
UnknownOperationError,
|
|
11032
|
-
ValidationError,
|
|
11033
|
-
ForbiddenError,
|
|
11034
|
-
GateDeniedError,
|
|
11035
|
-
PendingApprovalError,
|
|
11036
|
-
RunsOnApprovalError,
|
|
11037
|
-
RateLimitedError,
|
|
11038
|
-
PlanLimitError,
|
|
11039
|
-
NotFoundError,
|
|
11040
|
-
ConflictError,
|
|
11041
|
-
NeedsOwnApprovalError,
|
|
11042
|
-
ConfigError,
|
|
11043
|
-
toOperationError,
|
|
11044
|
-
allowanceMessage,
|
|
11417
|
+
CompiledQuery,
|
|
11045
11418
|
viewColumnOf,
|
|
11046
|
-
|
|
11047
|
-
|
|
11419
|
+
RISK_CLASSES,
|
|
11420
|
+
ACTORS,
|
|
11421
|
+
originSchema,
|
|
11422
|
+
ROLES,
|
|
11423
|
+
PERMISSIONS,
|
|
11424
|
+
CORE_PERMISSION_NAMESPACES,
|
|
11425
|
+
roleHasPermission,
|
|
11426
|
+
GRANTABLE_PERMISSIONS,
|
|
11427
|
+
RESTRICTED_CORE_PERMISSIONS,
|
|
11428
|
+
FIXED_ROLE_CORE_GRANTS,
|
|
11429
|
+
holdsPermission,
|
|
11430
|
+
MCP_SCOPES,
|
|
11431
|
+
grantableScopes,
|
|
11432
|
+
placedAs,
|
|
11433
|
+
staffPrincipal,
|
|
11434
|
+
ALL_ACTORS,
|
|
11048
11435
|
ident,
|
|
11049
11436
|
isCoreTarget,
|
|
11050
11437
|
splitObjectName,
|
|
11051
11438
|
objectTable,
|
|
11052
11439
|
objectView,
|
|
11440
|
+
viewOf,
|
|
11053
11441
|
sideTable,
|
|
11054
11442
|
columnName,
|
|
11055
11443
|
registryFieldName,
|
|
11444
|
+
FIELD_TYPE_REGISTRY,
|
|
11445
|
+
formulaFromStorage,
|
|
11056
11446
|
loadSchemaState,
|
|
11057
11447
|
coreFormulaFields,
|
|
11058
11448
|
buildViews,
|
|
11059
11449
|
liveViewOf,
|
|
11060
11450
|
PUBLISHED_FIELDS,
|
|
11061
11451
|
CAPACITY_FIELDS,
|
|
11452
|
+
STOCK_FIELDS,
|
|
11062
11453
|
ALLOWANCE_FIELDS,
|
|
11063
11454
|
fieldStorage,
|
|
11064
11455
|
objectTableOf,
|
|
11065
11456
|
refreshSchemaRegistry,
|
|
11066
11457
|
mergeOptions,
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
11073
|
-
|
|
11074
|
-
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11458
|
+
GUARDIAN_LINK,
|
|
11459
|
+
guardianProblems,
|
|
11460
|
+
dependantsSql,
|
|
11461
|
+
isLiveDependant,
|
|
11462
|
+
linkGuardStatement,
|
|
11463
|
+
familyOf,
|
|
11464
|
+
dependantFirstNames,
|
|
11465
|
+
recordsMadeFor,
|
|
11466
|
+
sharedEmailWarning,
|
|
11467
|
+
hasLiveGuardian,
|
|
11468
|
+
peopleAtAddresses,
|
|
11469
|
+
peopleAtNumbers,
|
|
11470
|
+
livePersonAfterMerges,
|
|
11079
11471
|
publicProblems,
|
|
11080
11472
|
signedInProblems,
|
|
11081
11473
|
customerProblems,
|
|
11474
|
+
customerScope,
|
|
11082
11475
|
unknownObject,
|
|
11476
|
+
NOTE_LEVELS,
|
|
11477
|
+
noteRights,
|
|
11478
|
+
readsEveryNote,
|
|
11479
|
+
noteScopeWhere,
|
|
11480
|
+
hiddenNoteIds,
|
|
11481
|
+
noteLevelGuard,
|
|
11083
11482
|
customerViaProblems,
|
|
11084
11483
|
scopeOf,
|
|
11085
11484
|
visibleObject,
|
|
@@ -11087,6 +11486,7 @@ export {
|
|
|
11087
11486
|
buyableSource,
|
|
11088
11487
|
previewSource,
|
|
11089
11488
|
ownedSource,
|
|
11489
|
+
ownReadSource,
|
|
11090
11490
|
visibleTable,
|
|
11091
11491
|
orgReader
|
|
11092
11492
|
};
|