@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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// The `workedOn` declaration (stage 58 step 1, ADR 0850): a record time can be recorded against (a
|
|
2
|
+
// job). Its manifest schema and contract checks live here; the host's side (the time entries,
|
|
3
|
+
// refused by the database when one person's overlap) is packages/core/src/staffing/time.ts.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Time can be recorded against this record (ADR 0850): a job a tradesperson spends three hours
|
|
9
|
+
* on. A staff member's **time entry** is the one record of time worked; an entry against a shift
|
|
10
|
+
* (a `staffed` record) is against the roster, an entry against a `workedOn` record is against the
|
|
11
|
+
* job, and an entry against neither is other work. The record keeps no hours of its own: its
|
|
12
|
+
* time is the entries against it, read through the host (the same entries pay counts), never a
|
|
13
|
+
* second "time spent" record, and never in a `rec_*` view.
|
|
14
|
+
*
|
|
15
|
+
* - `live`: the states of the object's `states` in which time may be recorded against it. A
|
|
16
|
+
* record in any other state, or in the Trash, takes no new time.
|
|
17
|
+
* - `title`: a field of this object, shown on the entry, the timesheet and the export.
|
|
18
|
+
* - `kind` (optional): a relation (one record) of this object, shown as the export's kind.
|
|
19
|
+
* - `place` (optional): a field, or `relation.field`, shown beside the entry.
|
|
20
|
+
* - `readers`: a permission of this extension's tools: who reads the time recorded against a
|
|
21
|
+
* record (person, date, minutes and state; never a note).
|
|
22
|
+
* - `partOf` (optional), on a `staffed` object only (a scheduled visit to a site): a relation (one
|
|
23
|
+
* record) to another of this extension's objects that declares `workedOn` (the job); time
|
|
24
|
+
* recorded against the visit also counts to it.
|
|
25
|
+
*
|
|
26
|
+
* Only shipped packs and the org's own extensions declare it: time worked feeds pay.
|
|
27
|
+
*/
|
|
28
|
+
export interface WorkedOnSpec {
|
|
29
|
+
live: readonly string[];
|
|
30
|
+
title: string;
|
|
31
|
+
kind?: string;
|
|
32
|
+
place?: string;
|
|
33
|
+
readers: string;
|
|
34
|
+
partOf?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fieldName = z.string().max(40);
|
|
38
|
+
|
|
39
|
+
export const workedOnManifestSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
42
|
+
title: fieldName,
|
|
43
|
+
kind: fieldName.optional(),
|
|
44
|
+
place: z.string().max(81).optional(),
|
|
45
|
+
readers: z.string().max(80),
|
|
46
|
+
partOf: fieldName.optional(),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
export type WorkedOnManifest = z.infer<typeof workedOnManifestSchema>;
|
|
50
|
+
|
|
51
|
+
/** Reports problems with `objects.<name>.workedOn` through `contract`. */
|
|
52
|
+
export function checkObjectWorkedOn(
|
|
53
|
+
m: ExtensionManifest,
|
|
54
|
+
name: string,
|
|
55
|
+
object: ObjectManifest,
|
|
56
|
+
contract: (path: string, message: string) => void,
|
|
57
|
+
): void {
|
|
58
|
+
const declared = object.workedOn;
|
|
59
|
+
if (!declared) return;
|
|
60
|
+
const at = `objects.${name}.workedOn`;
|
|
61
|
+
const own = (o: ObjectManifest, local: string): FieldManifest | undefined =>
|
|
62
|
+
Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
63
|
+
|
|
64
|
+
// The states in which time may be recorded against it.
|
|
65
|
+
const states = object.states;
|
|
66
|
+
if (!states) {
|
|
67
|
+
contract(`${at}.live`, `${name} must declare states: time is recorded in some of them`);
|
|
68
|
+
} else {
|
|
69
|
+
const field = own(object, states.field);
|
|
70
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
71
|
+
for (const state of declared.live) {
|
|
72
|
+
if (!values.has(state)) contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
73
|
+
}
|
|
74
|
+
if (new Set(declared.live).size !== declared.live.length) {
|
|
75
|
+
contract(`${at}.live`, "List each state once");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// What it is called, of what kind, and where.
|
|
80
|
+
const title = own(object, declared.title);
|
|
81
|
+
if (!title || title.many) {
|
|
82
|
+
contract(`${at}.title`, `"${declared.title}" must be a field (one value) of ${name}`);
|
|
83
|
+
}
|
|
84
|
+
if (declared.kind !== undefined) {
|
|
85
|
+
const kind = own(object, declared.kind);
|
|
86
|
+
if (kind?.type !== "relation" || kind.many) {
|
|
87
|
+
contract(`${at}.kind`, `"${declared.kind}" must be a relation field (one record) of ${name}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (declared.place !== undefined) {
|
|
91
|
+
const [first, second, ...rest] = declared.place.split(".");
|
|
92
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
93
|
+
if (!field || rest.length || (second !== undefined && field.type !== "relation")) {
|
|
94
|
+
contract(
|
|
95
|
+
`${at}.place`,
|
|
96
|
+
`"${declared.place}" must be a field of ${name}, or a relation of it and a field of what it names`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Who reads its time: a permission this extension's tools declare.
|
|
102
|
+
const permissions = new Set(
|
|
103
|
+
Object.values(m.tools).flatMap((t) =>
|
|
104
|
+
t.permission === undefined
|
|
105
|
+
? []
|
|
106
|
+
: typeof t.permission === "string"
|
|
107
|
+
? [t.permission]
|
|
108
|
+
: t.permission,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
if (!declared.readers.startsWith(`${m.id}:`) || !permissions.has(declared.readers)) {
|
|
112
|
+
contract(
|
|
113
|
+
`${at}.readers`,
|
|
114
|
+
`"${declared.readers}" must be a permission of this extension's tools (${m.id}:<word>)`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// What a staffed visit's time also counts to.
|
|
119
|
+
if (declared.partOf !== undefined) {
|
|
120
|
+
if (!object.staffed) {
|
|
121
|
+
contract(`${at}.partOf`, `Only a shift (an object that declares staffed) is part of a job`);
|
|
122
|
+
}
|
|
123
|
+
const via = own(object, declared.partOf);
|
|
124
|
+
const target = via?.type === "relation" && !via.many ? via.to : undefined;
|
|
125
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
126
|
+
const job = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
127
|
+
if (!job || local === name || !job.workedOn || job.workedOn.partOf !== undefined) {
|
|
128
|
+
contract(
|
|
129
|
+
`${at}.partOf`,
|
|
130
|
+
`"${declared.partOf}" must be a relation field (one record) to another of this extension's objects that declares workedOn`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
readRosterFile,
|
|
4
|
+
rosterReportLines,
|
|
5
|
+
runRosterImport
|
|
6
|
+
} from "./chunk-EPDTPGZJ.js";
|
|
7
|
+
import "./chunk-Z4IKF23A.js";
|
|
8
|
+
import {
|
|
9
|
+
hostOf,
|
|
10
|
+
withRunSession
|
|
11
|
+
} from "./chunk-LX2TTLVY.js";
|
|
12
|
+
import "./chunk-U72NEGCT.js";
|
|
13
|
+
import "./chunk-5KSXSK7Y.js";
|
|
14
|
+
|
|
15
|
+
// src/rostering-import/run.ts
|
|
16
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
17
|
+
import { basename } from "node:path";
|
|
18
|
+
var ROSTER_USAGE = "Usage: cos rostering import <roster.csv> --host <url> [--email <you>] [--apply]";
|
|
19
|
+
async function rosteringImport(positional, flags, io) {
|
|
20
|
+
const path = positional[0];
|
|
21
|
+
if (!path) {
|
|
22
|
+
io.err(
|
|
23
|
+
`${ROSTER_USAGE}
|
|
24
|
+
|
|
25
|
+
The file: a header naming duty, time and length, and weekdays with first_date (a weekly pattern) or date (one shift); optionally staff_email, last_date, zone and place. A dry run unless --apply. See docs/importing.md.`
|
|
26
|
+
);
|
|
27
|
+
return 2;
|
|
28
|
+
}
|
|
29
|
+
const host = hostOf(flags.host, io);
|
|
30
|
+
if (!host) return 2;
|
|
31
|
+
if (!existsSync(path) || !statSync(path).isFile()) {
|
|
32
|
+
io.err(`${path} is not a file`);
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
const name = basename(path);
|
|
36
|
+
const file = readRosterFile(readFileSync(path, "utf8"), name);
|
|
37
|
+
if (file.problems.length) {
|
|
38
|
+
io.err(`Nothing was sent: ${file.problems.length} problem(s) in ${name}.`);
|
|
39
|
+
for (const p of file.problems) io.err(` ${p.file}: ${p.message}`);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
io.out(
|
|
43
|
+
`${file.rows.length} row(s) in ${name}.${flags.apply ? "" : " A dry run: nothing is written."}`
|
|
44
|
+
);
|
|
45
|
+
return withRunSession(host, flags.email, io, "cos rostering import", async (on) => {
|
|
46
|
+
try {
|
|
47
|
+
const report = await runRosterImport(file, on, {
|
|
48
|
+
apply: Boolean(flags.apply),
|
|
49
|
+
name,
|
|
50
|
+
progress: (line) => io.out(line)
|
|
51
|
+
});
|
|
52
|
+
for (const line of rosterReportLines(report, name)) {
|
|
53
|
+
(report.problems.length ? io.err : io.out)(line);
|
|
54
|
+
}
|
|
55
|
+
return report.problems.length ? 1 : 0;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
io.err(`Error: ${error.message}`);
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
ROSTER_USAGE,
|
|
64
|
+
rosteringImport
|
|
65
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
coursesReportLines,
|
|
4
|
+
runCoursesImport
|
|
5
|
+
} from "./chunk-2CCHB37H.js";
|
|
6
|
+
import {
|
|
7
|
+
readCoursesFolder
|
|
8
|
+
} from "./chunk-Z4IKF23A.js";
|
|
9
|
+
import {
|
|
10
|
+
confirmer,
|
|
11
|
+
hostOf,
|
|
12
|
+
withRunSession
|
|
13
|
+
} from "./chunk-LX2TTLVY.js";
|
|
14
|
+
import "./chunk-U72NEGCT.js";
|
|
15
|
+
import "./chunk-5KSXSK7Y.js";
|
|
16
|
+
|
|
17
|
+
// src/courses-import/run.ts
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import {
|
|
20
|
+
closeSync,
|
|
21
|
+
existsSync,
|
|
22
|
+
openSync,
|
|
23
|
+
readdirSync,
|
|
24
|
+
readFileSync,
|
|
25
|
+
readSync,
|
|
26
|
+
statSync
|
|
27
|
+
} from "node:fs";
|
|
28
|
+
import { join, resolve } from "node:path";
|
|
29
|
+
var filesIn = (dir) => existsSync(dir) ? readdirSync(dir).filter((n) => statSync(join(dir, n)).isFile()) : [];
|
|
30
|
+
function readCoursesDisk(dir) {
|
|
31
|
+
const root = resolve(dir);
|
|
32
|
+
if (!existsSync(root) || !statSync(root).isDirectory()) throw new Error(`${dir} is not a folder`);
|
|
33
|
+
const json = (sub) => new Map(
|
|
34
|
+
filesIn(join(root, sub)).filter((n) => n.toLowerCase().endsWith(".json")).map((n) => [n, readFileSync(join(root, sub, n), "utf8")])
|
|
35
|
+
);
|
|
36
|
+
const bytes = (sub) => new Map(
|
|
37
|
+
filesIn(join(root, sub)).map(
|
|
38
|
+
(n) => [n, new Uint8Array(readFileSync(join(root, sub, n)))]
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
const text = (name) => existsSync(join(root, name)) ? readFileSync(join(root, name), "utf8") : null;
|
|
42
|
+
return {
|
|
43
|
+
courses: json("courses"),
|
|
44
|
+
bundles: json("bundles"),
|
|
45
|
+
videos: new Map(
|
|
46
|
+
filesIn(join(root, "videos")).map(
|
|
47
|
+
(n) => [n, statSync(join(root, "videos", n)).size]
|
|
48
|
+
)
|
|
49
|
+
),
|
|
50
|
+
captions: bytes("captions"),
|
|
51
|
+
pictures: bytes("pictures"),
|
|
52
|
+
downloads: bytes("downloads"),
|
|
53
|
+
access: text("access.csv"),
|
|
54
|
+
progress: text("progress.csv")
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function videoOnDisk(path) {
|
|
58
|
+
const size = statSync(path).size;
|
|
59
|
+
const hash = createHash("sha256");
|
|
60
|
+
const fd = openSync(path, "r");
|
|
61
|
+
try {
|
|
62
|
+
const buffer = Buffer.alloc(8 * 1024 * 1024);
|
|
63
|
+
for (let at = 0; at < size; ) {
|
|
64
|
+
const read = readSync(fd, buffer, 0, buffer.length, at);
|
|
65
|
+
if (!read) break;
|
|
66
|
+
hash.update(buffer.subarray(0, read));
|
|
67
|
+
at += read;
|
|
68
|
+
}
|
|
69
|
+
} finally {
|
|
70
|
+
closeSync(fd);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
size,
|
|
74
|
+
sha256: hash.digest("hex"),
|
|
75
|
+
async read(offset, length) {
|
|
76
|
+
const handle = openSync(path, "r");
|
|
77
|
+
try {
|
|
78
|
+
const out = Buffer.alloc(length);
|
|
79
|
+
const got = readSync(handle, out, 0, length, offset);
|
|
80
|
+
return new Uint8Array(out.subarray(0, got));
|
|
81
|
+
} finally {
|
|
82
|
+
closeSync(handle);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function coursesImport(positional, flags, io) {
|
|
88
|
+
const dir = positional[0];
|
|
89
|
+
if (!dir) {
|
|
90
|
+
io.err(
|
|
91
|
+
"Usage: cos courses import <folder> --host <https://host> [--email <you>] [--dry-run] [--publish] [--yes] [--wait <minutes>]\n\nThe folder: courses/*.json, bundles/*.json, videos/, captions/, pictures/, downloads/, access.csv, progress.csv. See docs/importing.md."
|
|
92
|
+
);
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
const host = hostOf(flags.host, io);
|
|
96
|
+
if (!host) return 2;
|
|
97
|
+
const plan = readCoursesFolder(readCoursesDisk(dir));
|
|
98
|
+
if (plan.problems.length) {
|
|
99
|
+
io.err(`Nothing was written: ${plan.problems.length} problem(s) in ${dir}.`);
|
|
100
|
+
for (const p of plan.problems) io.err(` ${p.file}: ${p.message}`);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
io.out(
|
|
104
|
+
`${plan.courses.length} course(s), ${plan.bundles.length} bundle(s), ${plan.videos.size} video(s), ${plan.access.length} access row(s) and ${plan.progress?.length ?? 0} progress row(s) in ${dir}.`
|
|
105
|
+
);
|
|
106
|
+
const videos = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const v of plan.videos.values()) {
|
|
108
|
+
if (v.file) {
|
|
109
|
+
io.out(`Reading videos/${v.file}\u2026`);
|
|
110
|
+
videos.set(v.file, videoOnDisk(join(resolve(dir), "videos", v.file)));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return withRunSession(host, flags.email, io, "cos courses import", async (on) => {
|
|
114
|
+
const report = await runCoursesImport(plan, on, {
|
|
115
|
+
dryRun: Boolean(flags.dryRun),
|
|
116
|
+
publish: Boolean(flags.publish),
|
|
117
|
+
confirm: confirmer(io, flags.yes),
|
|
118
|
+
videoFiles: (name) => videos.get(name),
|
|
119
|
+
waitMs: (flags.wait ?? 10) * 6e4,
|
|
120
|
+
progress: (line) => io.out(line)
|
|
121
|
+
});
|
|
122
|
+
for (const line of coursesReportLines(report, Boolean(flags.dryRun))) {
|
|
123
|
+
(report.problems.length ? io.err : io.out)(line);
|
|
124
|
+
}
|
|
125
|
+
return report.problems.length ? 1 : report.waiting.length ? 3 : 0;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
coursesImport,
|
|
130
|
+
readCoursesDisk
|
|
131
|
+
};
|