@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,330 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
parseCsv
|
|
4
|
+
} from "./chunk-Z4IKF23A.js";
|
|
5
|
+
|
|
6
|
+
// src/rostering-import/engine.ts
|
|
7
|
+
var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
8
|
+
var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
9
|
+
var ROWS_MAX = 1e3;
|
|
10
|
+
var TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
11
|
+
function realDate(date) {
|
|
12
|
+
const m = DATE.exec(date);
|
|
13
|
+
if (!m) return false;
|
|
14
|
+
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
15
|
+
const at = new Date(Date.UTC(y, mo - 1, d));
|
|
16
|
+
return at.getUTCFullYear() === y && at.getUTCMonth() === mo - 1 && at.getUTCDate() === d;
|
|
17
|
+
}
|
|
18
|
+
function weekdaysOf(text) {
|
|
19
|
+
const words = text.toLowerCase().split(/[\s,;/|]+/).filter(Boolean);
|
|
20
|
+
if (!words.length) return null;
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const word of words) {
|
|
23
|
+
const day = WEEKDAYS.find((d) => word.startsWith(d));
|
|
24
|
+
if (!day) return null;
|
|
25
|
+
if (!out.includes(day)) out.push(day);
|
|
26
|
+
}
|
|
27
|
+
return WEEKDAYS.filter((d) => out.includes(d));
|
|
28
|
+
}
|
|
29
|
+
function readRosterFile(text, name = "roster.csv") {
|
|
30
|
+
const problems = [];
|
|
31
|
+
const at = (line) => `${name}:${line}`;
|
|
32
|
+
const table = parseCsv(text.replace(/^/, ""));
|
|
33
|
+
const header = table[0];
|
|
34
|
+
if (!header) return { rows: [], problems: [{ file: name, message: "the file is empty" }] };
|
|
35
|
+
const names = header.cells.map(
|
|
36
|
+
(c) => c.trim().toLowerCase().replace(/[\s-]+/g, "_")
|
|
37
|
+
);
|
|
38
|
+
const column = (...options) => names.findIndex((n) => options.includes(n));
|
|
39
|
+
const col = {
|
|
40
|
+
duty: column("duty", "duty_name"),
|
|
41
|
+
time: column("time", "start_time", "starts_at"),
|
|
42
|
+
length: column("length", "minutes", "length_minutes"),
|
|
43
|
+
weekdays: column("weekdays", "days"),
|
|
44
|
+
firstDate: column("first_date", "from", "from_date"),
|
|
45
|
+
lastDate: column("last_date", "until", "until_date"),
|
|
46
|
+
date: column("date"),
|
|
47
|
+
staff: column("staff_email", "email", "staff"),
|
|
48
|
+
zone: column("zone", "timezone", "time_zone"),
|
|
49
|
+
place: column("place", "where")
|
|
50
|
+
};
|
|
51
|
+
if (col.duty < 0 || col.time < 0 || col.length < 0) {
|
|
52
|
+
problems.push({
|
|
53
|
+
file: at(header.line),
|
|
54
|
+
message: `the header must name duty, time and length (it has: ${names.join(", ") || "nothing"})`
|
|
55
|
+
});
|
|
56
|
+
return { rows: [], problems };
|
|
57
|
+
}
|
|
58
|
+
if (col.weekdays < 0 && col.date < 0) {
|
|
59
|
+
problems.push({
|
|
60
|
+
file: at(header.line),
|
|
61
|
+
message: "the header must name weekdays (with first_date) or date"
|
|
62
|
+
});
|
|
63
|
+
return { rows: [], problems };
|
|
64
|
+
}
|
|
65
|
+
const rows = [];
|
|
66
|
+
for (const { line, cells } of table.slice(1)) {
|
|
67
|
+
const cell = (i) => i >= 0 ? (cells[i] ?? "").trim() : "";
|
|
68
|
+
const problem = (message) => problems.push({ file: at(line), message });
|
|
69
|
+
const duty = cell(col.duty);
|
|
70
|
+
const time = cell(col.time);
|
|
71
|
+
const length = Number(cell(col.length));
|
|
72
|
+
const days = cell(col.weekdays);
|
|
73
|
+
const date = cell(col.date);
|
|
74
|
+
const firstDate = cell(col.firstDate);
|
|
75
|
+
const lastDate = cell(col.lastDate);
|
|
76
|
+
const email = cell(col.staff).toLowerCase();
|
|
77
|
+
const zone = cell(col.zone);
|
|
78
|
+
const place = cell(col.place);
|
|
79
|
+
if (!duty) {
|
|
80
|
+
problem("no duty");
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (duty.length > 200) {
|
|
84
|
+
problem("the duty's name is longer than 200 characters");
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!TIME.test(time)) {
|
|
88
|
+
problem(`the time is not HH:MM: "${time}"`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!Number.isInteger(length) || length < 1 || length > 1440) {
|
|
92
|
+
problem(`the length is not whole minutes from 1 to 1440: "${cell(col.length)}"`);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
96
|
+
problem(`not an email address: "${cell(col.staff)}"`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (zone && !/^[A-Za-z_]+(\/[A-Za-z0-9_+-]+)*$/.test(zone)) {
|
|
100
|
+
problem(`not a time zone: "${zone}"`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const base = {
|
|
104
|
+
line,
|
|
105
|
+
duty,
|
|
106
|
+
time,
|
|
107
|
+
length,
|
|
108
|
+
...email ? { staffEmail: email } : {},
|
|
109
|
+
...zone ? { zone } : {},
|
|
110
|
+
...place ? { place } : {}
|
|
111
|
+
};
|
|
112
|
+
if (days && date) {
|
|
113
|
+
problem("a row is either a weekly pattern (weekdays) or one shift (date), not both");
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (date) {
|
|
117
|
+
if (!realDate(date)) {
|
|
118
|
+
problem(`the date is not a real date (YYYY-MM-DD): "${date}"`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
rows.push({ ...base, date });
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const weekdays = weekdaysOf(days);
|
|
125
|
+
if (!weekdays) {
|
|
126
|
+
problem(`the weekdays are not days of the week: "${days}"`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (!realDate(firstDate)) {
|
|
130
|
+
problem(`a weekly pattern needs a real first_date (YYYY-MM-DD): "${firstDate}"`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (lastDate && (!realDate(lastDate) || lastDate < firstDate)) {
|
|
134
|
+
problem(`the last_date is not a real date on or after the first: "${lastDate}"`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
rows.push({ ...base, weekdays, firstDate, ...lastDate ? { lastDate } : {} });
|
|
138
|
+
}
|
|
139
|
+
if (!rows.length && !problems.length) {
|
|
140
|
+
problems.push({ file: name, message: "no rows under the header" });
|
|
141
|
+
}
|
|
142
|
+
if (rows.length > ROWS_MAX) {
|
|
143
|
+
problems.push({
|
|
144
|
+
file: name,
|
|
145
|
+
message: `${rows.length} rows: at most ${ROWS_MAX} are checked and imported in one run. Split the file.`
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return { rows, problems };
|
|
149
|
+
}
|
|
150
|
+
var DUTY = "rostering.duty";
|
|
151
|
+
var SERIES = "rostering.dutyseries";
|
|
152
|
+
var SHIFT = "rostering.shift";
|
|
153
|
+
function labelOf(row) {
|
|
154
|
+
const when = row.date ? `${row.date} ${row.time}` : `${(row.weekdays ?? []).join(" ")} ${row.time} from ${row.firstDate}`;
|
|
155
|
+
return `${row.duty}, ${when}, ${row.length} minutes, ${row.staffEmail ? "its person" : "nobody"}`;
|
|
156
|
+
}
|
|
157
|
+
async function runRosterImport(file, host, options) {
|
|
158
|
+
const name = options.name ?? "roster.csv";
|
|
159
|
+
const report = { apply: options.apply, rows: [], dutiesCreated: [], problems: [] };
|
|
160
|
+
const accounts = /* @__PURE__ */ new Map();
|
|
161
|
+
for (const email of new Set(file.rows.flatMap((r) => r.staffEmail ? [r.staffEmail] : []))) {
|
|
162
|
+
const found = await host.call("user.list", {
|
|
163
|
+
filter: { field: "email", op: "eq", value: email }
|
|
164
|
+
});
|
|
165
|
+
const id = found.items.find((u) => u.email.toLowerCase() === email)?.id;
|
|
166
|
+
if (id) accounts.set(email, id);
|
|
167
|
+
}
|
|
168
|
+
for (const row of file.rows) {
|
|
169
|
+
if (row.staffEmail && !accounts.has(row.staffEmail)) {
|
|
170
|
+
report.problems.push({
|
|
171
|
+
file: `${name}:${row.line}`,
|
|
172
|
+
message: `no staff account has ${row.staffEmail}: invite them first (an import never makes an account)`
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (report.problems.length) return report;
|
|
177
|
+
const duties = /* @__PURE__ */ new Map();
|
|
178
|
+
for (const dutyName of new Set(file.rows.map((r) => r.duty))) {
|
|
179
|
+
const found = await host.call("record.list", {
|
|
180
|
+
object: DUTY,
|
|
181
|
+
filter: { field: "name", op: "eq", value: dutyName },
|
|
182
|
+
limit: 1
|
|
183
|
+
});
|
|
184
|
+
const id = found.items[0]?.id;
|
|
185
|
+
if (id) duties.set(dutyName, id);
|
|
186
|
+
}
|
|
187
|
+
const plans = file.rows.map((row) => ({
|
|
188
|
+
key: `line ${row.line}`,
|
|
189
|
+
kind: duties.has(row.duty) ? { object: DUTY, id: duties.get(row.duty) } : null,
|
|
190
|
+
account: row.staffEmail ? accounts.get(row.staffEmail) ?? null : null,
|
|
191
|
+
time: row.time,
|
|
192
|
+
length: row.length,
|
|
193
|
+
...row.zone ? { zone: row.zone } : {},
|
|
194
|
+
...row.date ? { date: row.date } : {
|
|
195
|
+
weekdays: row.weekdays,
|
|
196
|
+
firstDate: row.firstDate,
|
|
197
|
+
...row.lastDate ? { lastDate: row.lastDate } : {}
|
|
198
|
+
}
|
|
199
|
+
}));
|
|
200
|
+
if (plans.length > ROWS_MAX) {
|
|
201
|
+
report.problems.push({ file: name, message: `more than ${ROWS_MAX} rows: split the file` });
|
|
202
|
+
return report;
|
|
203
|
+
}
|
|
204
|
+
const answers = (await host.call("x.rostering.planCheck", { plans })).plans;
|
|
205
|
+
for (const [i, row] of file.rows.entries()) {
|
|
206
|
+
const answer = answers[i];
|
|
207
|
+
const entry = {
|
|
208
|
+
line: row.line,
|
|
209
|
+
label: labelOf(row),
|
|
210
|
+
dates: answer.dates,
|
|
211
|
+
clashes: answer.clashes,
|
|
212
|
+
away: answer.away,
|
|
213
|
+
notQualified: answer.notQualified,
|
|
214
|
+
outcome: "dry_run"
|
|
215
|
+
};
|
|
216
|
+
report.rows.push(entry);
|
|
217
|
+
if (!options.apply) continue;
|
|
218
|
+
let duty = duties.get(row.duty);
|
|
219
|
+
if (!duty) {
|
|
220
|
+
duty = (await host.call("record.create", {
|
|
221
|
+
object: DUTY,
|
|
222
|
+
values: { name: row.duty, ...row.place ? { place: row.place } : {} }
|
|
223
|
+
})).id;
|
|
224
|
+
duties.set(row.duty, duty);
|
|
225
|
+
report.dutiesCreated.push(row.duty);
|
|
226
|
+
options.progress?.(`Duty ${row.duty} added.`);
|
|
227
|
+
}
|
|
228
|
+
const account = row.staffEmail ? accounts.get(row.staffEmail) ?? null : null;
|
|
229
|
+
if (row.date) {
|
|
230
|
+
const first = answer.first;
|
|
231
|
+
if (!first) continue;
|
|
232
|
+
const there2 = await host.call("record.list", {
|
|
233
|
+
object: SHIFT,
|
|
234
|
+
filter: {
|
|
235
|
+
and: [
|
|
236
|
+
{ field: "duty", op: "eq", value: duty },
|
|
237
|
+
{ field: "startsAt", op: "eq", value: first.startsAt }
|
|
238
|
+
]
|
|
239
|
+
},
|
|
240
|
+
limit: 1
|
|
241
|
+
});
|
|
242
|
+
const existing = there2.items[0];
|
|
243
|
+
if (existing) {
|
|
244
|
+
const same2 = existing.values.endsAt === first.endsAt && (existing.values.staff ?? null) === (account && !answer.clashes.length ? account : null);
|
|
245
|
+
entry.outcome = same2 ? "exists" : "differs";
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const staffed = account && !answer.clashes.length ? { staff: account } : {};
|
|
249
|
+
await host.call("record.create", {
|
|
250
|
+
object: SHIFT,
|
|
251
|
+
values: {
|
|
252
|
+
duty,
|
|
253
|
+
startsAt: first.startsAt,
|
|
254
|
+
endsAt: first.endsAt,
|
|
255
|
+
...row.zone ? { timezone: row.zone } : {},
|
|
256
|
+
...staffed
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
entry.outcome = "created";
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const there = await host.call("record.list", {
|
|
263
|
+
object: SERIES,
|
|
264
|
+
filter: { field: "duty", op: "eq", value: duty },
|
|
265
|
+
limit: 200
|
|
266
|
+
});
|
|
267
|
+
const same = there.items.find(
|
|
268
|
+
(s) => s.values.time === row.time && s.values.firstDate === row.firstDate && JSON.stringify([...s.values.weekdays ?? []].sort()) === JSON.stringify([...row.weekdays ?? []].sort())
|
|
269
|
+
);
|
|
270
|
+
if (same) {
|
|
271
|
+
const unchanged = (same.values.staff ?? null) === account && same.values.length === row.length && (same.values.lastDate ?? null) === (row.lastDate ?? null);
|
|
272
|
+
entry.outcome = unchanged ? "exists" : "differs";
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
await host.call("record.create", {
|
|
276
|
+
object: SERIES,
|
|
277
|
+
values: {
|
|
278
|
+
duty,
|
|
279
|
+
weekdays: row.weekdays,
|
|
280
|
+
time: row.time,
|
|
281
|
+
length: row.length,
|
|
282
|
+
firstDate: row.firstDate,
|
|
283
|
+
...row.lastDate ? { lastDate: row.lastDate } : {},
|
|
284
|
+
...row.zone ? { timezone: row.zone } : {},
|
|
285
|
+
...account ? { staff: account } : {}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
entry.outcome = "created";
|
|
289
|
+
}
|
|
290
|
+
return report;
|
|
291
|
+
}
|
|
292
|
+
function rosterReportLines(report, name) {
|
|
293
|
+
if (report.problems.length) {
|
|
294
|
+
return [
|
|
295
|
+
`Nothing was written: ${report.problems.length} problem(s).`,
|
|
296
|
+
...report.problems.map((p) => ` ${p.file}: ${p.message}`)
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
const lines = [];
|
|
300
|
+
let clashes = 0;
|
|
301
|
+
for (const row of report.rows) {
|
|
302
|
+
const verb = row.outcome === "created" ? "made" : row.outcome === "exists" ? "already there" : row.outcome === "differs" ? "already there with another person, length or last date: left as it is (change it on the roster)" : "would be made";
|
|
303
|
+
lines.push(`${name}:${row.line} ${row.label}: ${row.dates} shift(s) ${verb}.`);
|
|
304
|
+
for (const c of row.clashes) {
|
|
305
|
+
clashes++;
|
|
306
|
+
lines.push(
|
|
307
|
+
` clash on ${c.date}: already on ${c.other.title} at ${c.other.startsAt}${c.ended ? " (both over: reported only)" : ": made with nobody on it"}`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (row.away.length) lines.push(` warning: away on ${row.away.join(", ")}`);
|
|
311
|
+
if (row.notQualified) lines.push(" warning: not marked as qualified for this duty");
|
|
312
|
+
}
|
|
313
|
+
if (report.dutiesCreated.length) lines.push(`Duties added: ${report.dutiesCreated.join(", ")}.`);
|
|
314
|
+
if (clashes) {
|
|
315
|
+
lines.push(
|
|
316
|
+
`${clashes} date(s) clash: whoever rosters is told, and puts someone on them from the roster.`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
lines.push(
|
|
320
|
+
report.apply ? "Done. Each pattern's shifts are made by the host over the next minutes, as far ahead as the duty horizon." : "Dry run: nothing was written. Run again with --apply to make them."
|
|
321
|
+
);
|
|
322
|
+
return lines;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export {
|
|
326
|
+
realDate,
|
|
327
|
+
readRosterFile,
|
|
328
|
+
runRosterImport,
|
|
329
|
+
rosterReportLines
|
|
330
|
+
};
|
|
@@ -10,23 +10,24 @@ import {
|
|
|
10
10
|
POLICY_CALIBRATED,
|
|
11
11
|
SHAPE_CALIBRATED,
|
|
12
12
|
STATEMENTS_CALIBRATED,
|
|
13
|
-
coreRegistry
|
|
14
|
-
|
|
15
|
-
} from "./chunk-UB4I2QKR.js";
|
|
13
|
+
coreRegistry
|
|
14
|
+
} from "./chunk-HCG6T53D.js";
|
|
16
15
|
import {
|
|
17
16
|
JOB_CHANGE_CALIBRATED,
|
|
18
17
|
ROUTINE_GATE_CALIBRATED,
|
|
19
|
-
choice
|
|
20
|
-
|
|
18
|
+
choice,
|
|
19
|
+
toolOperation
|
|
20
|
+
} from "./chunk-2B6YUYZV.js";
|
|
21
21
|
import {
|
|
22
22
|
AUDIENCES,
|
|
23
23
|
audiencesOf,
|
|
24
|
-
forPacks
|
|
25
|
-
|
|
24
|
+
forPacks,
|
|
25
|
+
isDeviceOperation
|
|
26
|
+
} from "./chunk-KMFMD52Z.js";
|
|
26
27
|
import {
|
|
27
28
|
external_exports,
|
|
28
29
|
toManifest
|
|
29
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-U72NEGCT.js";
|
|
30
31
|
|
|
31
32
|
// ../core/src/judge/questions/orchestrator-suggest.ts
|
|
32
33
|
var ORCHESTRATOR_PLACEMENT = "orchestrator.suggest";
|
|
@@ -50,6 +51,20 @@ var ORCHESTRATOR_CALIBRATED = {
|
|
|
50
51
|
// ../core/src/http/contract.ts
|
|
51
52
|
var API_VERSION = "v1";
|
|
52
53
|
var SERVED_API_VERSIONS = Object.freeze([API_VERSION]);
|
|
54
|
+
var OWNER_CLIENT_OPERATIONS = Object.freeze([
|
|
55
|
+
"today.get",
|
|
56
|
+
"today.rows",
|
|
57
|
+
"today.alerts",
|
|
58
|
+
"today.setAlerts",
|
|
59
|
+
"approval.list",
|
|
60
|
+
"approval.get",
|
|
61
|
+
"approval.approve",
|
|
62
|
+
"approval.reject",
|
|
63
|
+
"notification.list",
|
|
64
|
+
"notification.unreadCount",
|
|
65
|
+
"notification.markRead",
|
|
66
|
+
"user.me"
|
|
67
|
+
]);
|
|
53
68
|
function jsonSchema(schema, io) {
|
|
54
69
|
try {
|
|
55
70
|
const out = external_exports.toJSONSchema(schema, { unrepresentable: "any", io });
|
|
@@ -62,11 +77,14 @@ function jsonSchema(schema, io) {
|
|
|
62
77
|
function staleGroup(name) {
|
|
63
78
|
const [first, second] = name.split(".");
|
|
64
79
|
if (first === "me" || first === "my") return "self";
|
|
80
|
+
if (first === "recurring") return "record";
|
|
65
81
|
if (first === "x") return `x.${second}`;
|
|
66
82
|
return first ?? name;
|
|
67
83
|
}
|
|
68
84
|
function buildContract(operations) {
|
|
69
|
-
const callable = operations.filter(
|
|
85
|
+
const callable = operations.filter(
|
|
86
|
+
(op) => !op.toolOnly && !op.deskOnly && !isDeviceOperation(op)
|
|
87
|
+
);
|
|
70
88
|
const queries = callable.filter((op) => op.risk === "read");
|
|
71
89
|
const entries = callable.map((op) => {
|
|
72
90
|
const kind = op.risk === "read" ? "query" : "mutation";
|
|
@@ -134,6 +152,10 @@ var STOP = new Set(
|
|
|
134
152
|
)
|
|
135
153
|
);
|
|
136
154
|
|
|
155
|
+
// ../core/src/people-codes/identify.ts
|
|
156
|
+
var NAME_LOCK_MS = 5 * 6e4;
|
|
157
|
+
var STAND_IN_SALT = new Uint8Array(16);
|
|
158
|
+
|
|
137
159
|
// ../client-gen/src/product.ts
|
|
138
160
|
function releaseContract(perAudience, packs, extensions) {
|
|
139
161
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -155,13 +177,7 @@ function releaseContract(perAudience, packs, extensions) {
|
|
|
155
177
|
const [first, id] = name.split(".");
|
|
156
178
|
if (first === "x" && id && own.has(id)) merged.delete(name);
|
|
157
179
|
}
|
|
158
|
-
const
|
|
159
|
-
const manifest = toManifest(extension);
|
|
160
|
-
return Object.entries(manifest.tools).map(
|
|
161
|
-
([name, tool]) => toolOperation(manifest, name, tool, "shipped")
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
for (const op of buildContract(tools).operations) merged.set(op.name, op);
|
|
180
|
+
for (const op of buildContract(extensionTools(extensions)).operations) merged.set(op.name, op);
|
|
165
181
|
const version = perAudience[0]?.version ?? "v1";
|
|
166
182
|
return {
|
|
167
183
|
version,
|
|
@@ -169,13 +185,15 @@ function releaseContract(perAudience, packs, extensions) {
|
|
|
169
185
|
};
|
|
170
186
|
}
|
|
171
187
|
function productContract(extensions) {
|
|
172
|
-
|
|
188
|
+
return buildContract([...coreRegistry.list(), ...extensionTools(extensions)]);
|
|
189
|
+
}
|
|
190
|
+
function extensionTools(extensions) {
|
|
191
|
+
return extensions.flatMap((extension) => {
|
|
173
192
|
const manifest = toManifest(extension);
|
|
174
193
|
return Object.entries(manifest.tools).map(
|
|
175
194
|
([name, tool]) => toolOperation(manifest, name, tool, "shipped")
|
|
176
195
|
);
|
|
177
196
|
});
|
|
178
|
-
return buildContract([...coreRegistry.list(), ...tools]);
|
|
179
197
|
}
|
|
180
198
|
|
|
181
199
|
// ../client-gen/src/schema-ts.ts
|
|
@@ -199,7 +217,7 @@ function schemaToTs(schema, ctx = { defs: {}, depth: 0 }) {
|
|
|
199
217
|
if (ctx.depth > MAX_DEPTH) return "unknown";
|
|
200
218
|
const s = schema;
|
|
201
219
|
const next = { ...ctx, depth: ctx.depth + 1 };
|
|
202
|
-
const defs = s.$defs
|
|
220
|
+
const defs = s.$defs;
|
|
203
221
|
if (defs) next.defs = { ...ctx.defs, ...defs };
|
|
204
222
|
if (typeof s.$ref === "string") {
|
|
205
223
|
const match = /^#\/\$defs\/(.+)$/.exec(s.$ref);
|
|
@@ -263,7 +281,7 @@ function objectType(s, ctx) {
|
|
|
263
281
|
}
|
|
264
282
|
|
|
265
283
|
// ../client-gen/src/render.ts
|
|
266
|
-
var ENTRY_POINTS = ["customer", "staff"];
|
|
284
|
+
var ENTRY_POINTS = ["customer", "staff", "practitioner"];
|
|
267
285
|
function pascal(name) {
|
|
268
286
|
return name.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join("");
|
|
269
287
|
}
|
|
@@ -273,8 +291,13 @@ function doc(op) {
|
|
|
273
291
|
* ${text}
|
|
274
292
|
*/`;
|
|
275
293
|
}
|
|
294
|
+
var WHOSE = {
|
|
295
|
+
customer: "operations open to customers and the public",
|
|
296
|
+
staff: "operations open to staff",
|
|
297
|
+
practitioner: "operations open to practitioners"
|
|
298
|
+
};
|
|
276
299
|
function operationsFor(contract, entry) {
|
|
277
|
-
const audiences = entry === "customer" ? ["customer", "public"] : ["staff"];
|
|
300
|
+
const audiences = entry === "customer" ? ["customer", "public"] : entry === "practitioner" ? ["practitioner"] : ["staff"];
|
|
278
301
|
return contract.operations.filter((op) => op.audiences.some((a) => audiences.includes(a)));
|
|
279
302
|
}
|
|
280
303
|
function renderEntry(contract, entry, options) {
|
|
@@ -284,7 +307,7 @@ function renderEntry(contract, entry, options) {
|
|
|
284
307
|
const factory = `create${pascal(entry)}Client`;
|
|
285
308
|
const lines = [
|
|
286
309
|
`// Generated by \`cos client generate\` for the ${options.product} product, API ${contract.version}: the`,
|
|
287
|
-
`// ${entry
|
|
310
|
+
`// ${WHOSE[entry]}. Do not edit; generate again.`,
|
|
288
311
|
`import { type ClientOptions, createClient } from ${JSON.stringify(runtime)};`,
|
|
289
312
|
"",
|
|
290
313
|
"/** Every operation's input, output and kind. */",
|
|
@@ -340,13 +363,32 @@ function renderRoleClient(staff, role, options) {
|
|
|
340
363
|
});
|
|
341
364
|
const text = renderEntry({ version: staff.version, operations }, "staff", options);
|
|
342
365
|
const factory = `create${pascal(role.name)}Client`;
|
|
366
|
+
const grants = options.grants?.length ? `
|
|
367
|
+
// With the grants ${options.grants.join(", ")}: the tools a human admin's grant of each opens (ADR 0600).` : "";
|
|
343
368
|
return text.replace(
|
|
344
369
|
/^\/\/ Generated by .*\n\/\/ .*\n/,
|
|
345
370
|
`// Generated by \`cos client generate\` for the ${options.product} product, API ${staff.version}: the
|
|
346
|
-
// operations the ${role.name} role may call, and no other staff operation. Do not edit; generate again
|
|
371
|
+
// operations the ${role.name} role may call, and no other staff operation. Do not edit; generate again.${grants}
|
|
347
372
|
`
|
|
348
373
|
).replaceAll("createStaffClient", factory).replaceAll("StaffClient", `${pascal(role.name)}Client`);
|
|
349
374
|
}
|
|
375
|
+
function renderOwnerClient(staff, owner, options) {
|
|
376
|
+
const allowed = new Set(owner.operations);
|
|
377
|
+
const missing = owner.operations.filter((n) => !staff.operations.some((op) => op.name === n));
|
|
378
|
+
if (missing.length) {
|
|
379
|
+
throw new Error(`The owner's client names ${missing.join(", ")}, not in the staff contract`);
|
|
380
|
+
}
|
|
381
|
+
const operations = staff.operations.filter((op) => allowed.has(op.name));
|
|
382
|
+
const text = renderEntry({ version: staff.version, operations }, "staff", options);
|
|
383
|
+
return text.replace(
|
|
384
|
+
/^\/\/ Generated by .*\n\/\/ .*\n/,
|
|
385
|
+
`// Generated by \`cos client generate\` for the ${options.product} product, API ${staff.version}: the
|
|
386
|
+
// operations the owner's client may call (Today, the approvals, the notice inbox), and no other
|
|
387
|
+
// staff operation. Any staff account may sign in with it: the host decides every call. Do not
|
|
388
|
+
// edit; generate again.
|
|
389
|
+
`
|
|
390
|
+
).replaceAll("createStaffClient", "createOwnerClient").replaceAll("StaffClient", "OwnerClient");
|
|
391
|
+
}
|
|
350
392
|
function renderClient(contract, options) {
|
|
351
393
|
return Object.fromEntries(
|
|
352
394
|
ENTRY_POINTS.map((entry) => [`${entry}.ts`, renderEntry(contract, entry, options)])
|
|
@@ -361,5 +403,6 @@ export {
|
|
|
361
403
|
operationsFor,
|
|
362
404
|
renderEntry,
|
|
363
405
|
renderRoleClient,
|
|
406
|
+
renderOwnerClient,
|
|
364
407
|
renderClient
|
|
365
408
|
};
|