@composable-os/cli 0.0.0-stage → 0.1.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/LICENSE +109 -0
  2. package/README.md +24 -2
  3. package/dist/accounts-UHYLCLEY.js +45 -0
  4. package/dist/blocks-5IFU25J6.js +233 -0
  5. package/dist/chunk-2ABSVMGB.js +13 -0
  6. package/dist/chunk-2IVEVPMY.js +669 -0
  7. package/dist/chunk-2TWV3SVB.js +349 -0
  8. package/dist/chunk-2XC5JLBO.js +1931 -0
  9. package/dist/chunk-324WJXNP.js +320 -0
  10. package/dist/chunk-5KSXSK7Y.js +47 -0
  11. package/dist/chunk-6ELZRNUU.js +116 -0
  12. package/dist/chunk-6UWRT4VM.js +220 -0
  13. package/dist/chunk-6WGFA2IV.js +643 -0
  14. package/dist/chunk-6XTU2MTP.js +11278 -0
  15. package/dist/chunk-7CQGMVDO.js +63 -0
  16. package/dist/chunk-7D4GKZOX.js +615 -0
  17. package/dist/chunk-7OGCMQXG.js +284 -0
  18. package/dist/chunk-DHS2CV2M.js +139 -0
  19. package/dist/chunk-DU6OIFOU.js +2358 -0
  20. package/dist/chunk-E4WCYTCT.js +347 -0
  21. package/dist/chunk-E64SG24J.js +88 -0
  22. package/dist/chunk-FJIZGS5Q.js +698 -0
  23. package/dist/chunk-GYTEW66E.js +50 -0
  24. package/dist/chunk-HDIOVFAZ.js +544 -0
  25. package/dist/chunk-K34UKWEI.js +298 -0
  26. package/dist/chunk-KGHA67HG.js +765 -0
  27. package/dist/chunk-LAAL4YGR.js +365 -0
  28. package/dist/chunk-LO6WGU5Y.js +26189 -0
  29. package/dist/chunk-MBIKVRAC.js +1425 -0
  30. package/dist/chunk-P6UWZ6QQ.js +426 -0
  31. package/dist/chunk-PDD2ETVF.js +1302 -0
  32. package/dist/chunk-UB4I2QKR.js +31575 -0
  33. package/dist/chunk-WHKJGF36.js +2418 -0
  34. package/dist/chunk-XIDLW3EP.js +15471 -0
  35. package/dist/chunk-YFTLIEWU.js +504 -0
  36. package/dist/chunk-YNUZRTPH.js +182 -0
  37. package/dist/chunk-ZAWES2UD.js +9364 -0
  38. package/dist/chunk-ZZFWMVJO.js +704 -0
  39. package/dist/cli-5UNY5G5L.js +136 -0
  40. package/dist/cli-UYZMVQMR.js +24534 -0
  41. package/dist/cli.js +25 -0
  42. package/dist/client-repo-SE4EKG6W.js +55 -0
  43. package/dist/create.js +25 -0
  44. package/dist/fields-FTWWMD7N.js +50 -0
  45. package/dist/grants-LOW6TSWD.js +32 -0
  46. package/dist/invoke-6KVT6WJI.js +41 -0
  47. package/dist/moves-E2HKYCTK.js +41 -0
  48. package/dist/order-U4KZLLSJ.js +19 -0
  49. package/dist/person-UHLVBVLR.js +67 -0
  50. package/dist/plan-on-sale-TJPFCNL7.js +26 -0
  51. package/dist/platform/migrations/0001_init.sql +59 -0
  52. package/dist/platform/migrations/0002_users_settings.sql +34 -0
  53. package/dist/platform/migrations/0003_people_organisations.sql +225 -0
  54. package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
  55. package/dist/platform/migrations/0005_views_audit.sql +79 -0
  56. package/dist/platform/migrations/0006_search.sql +223 -0
  57. package/dist/platform/migrations/0007_crm_views.sql +141 -0
  58. package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
  59. package/dist/platform/migrations/0010_approval_queue.sql +90 -0
  60. package/dist/platform/migrations/0011_connected_apps.sql +36 -0
  61. package/dist/platform/migrations/0020_extensions.sql +373 -0
  62. package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
  63. package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
  64. package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
  65. package/dist/platform/migrations/0061_audit_retention.sql +95 -0
  66. package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
  67. package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
  68. package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
  69. package/dist/platform/migrations/0065_storage_stats.sql +13 -0
  70. package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
  71. package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
  72. package/dist/platform/migrations/0100_stage_history.sql +54 -0
  73. package/dist/platform/migrations/0110_integrations.sql +103 -0
  74. package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
  75. package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
  76. package/dist/platform/migrations/0130_automations.sql +113 -0
  77. package/dist/platform/migrations/0131_notifications.sql +29 -0
  78. package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
  79. package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
  80. package/dist/platform/migrations/0160_releases.sql +41 -0
  81. package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
  82. package/dist/platform/migrations/0170_automation_connections.sql +32 -0
  83. package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
  84. package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
  85. package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
  86. package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
  87. package/dist/platform/migrations/0210_daily_digest.sql +33 -0
  88. package/dist/platform/migrations/0220_entitlements.sql +13 -0
  89. package/dist/platform/migrations/0221_support_grants.sql +33 -0
  90. package/dist/platform/migrations/0250_judge.sql +11 -0
  91. package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
  92. package/dist/platform/migrations/0252_judge_usage.sql +14 -0
  93. package/dist/platform/migrations/0255_summary_checks.sql +9 -0
  94. package/dist/platform/migrations/0256_outbound_check.sql +9 -0
  95. package/dist/platform/migrations/0260_ai_usage.sql +20 -0
  96. package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
  97. package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
  98. package/dist/platform/migrations/0320_duplicates.sql +41 -0
  99. package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
  100. package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
  101. package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
  102. package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
  103. package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
  104. package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
  105. package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
  106. package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
  107. package/dist/platform/migrations/0362_voice_usage.sql +17 -0
  108. package/dist/platform/migrations/0365_routines.sql +38 -0
  109. package/dist/platform/migrations/0370_approval_execution.sql +20 -0
  110. package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
  111. package/dist/platform/migrations/0380_rec_views.sql +94 -0
  112. package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
  113. package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
  114. package/dist/platform/migrations/0402_erase_requests.sql +34 -0
  115. package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
  116. package/dist/platform/migrations/0411_device_sessions.sql +33 -0
  117. package/dist/platform/migrations/0420_transition_history.sql +100 -0
  118. package/dist/platform/migrations/0421_orders.sql +134 -0
  119. package/dist/platform/migrations/0422_order_payments.sql +109 -0
  120. package/dist/platform/migrations/0440_capacity.sql +100 -0
  121. package/dist/platform/migrations/0441_capacity_views.sql +40 -0
  122. package/dist/platform/migrations/0450_order_grants.sql +21 -0
  123. package/dist/platform/migrations/0451_pack_roles.sql +18 -0
  124. package/dist/platform/migrations/0460_content.sql +59 -0
  125. package/dist/platform/migrations/0461_media.sql +52 -0
  126. package/dist/platform/migrations/0470_publish_versions.sql +36 -0
  127. package/dist/platform/migrations/0471_permission_grants.sql +18 -0
  128. package/dist/platform/migrations/0490_staff_invites.sql +40 -0
  129. package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
  130. package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
  131. package/dist/platform/migrations/0500_published_media_field.sql +25 -0
  132. package/dist/platform/migrations/0501_import_keys.sql +23 -0
  133. package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
  134. package/dist/platform/migrations/0516_order_tax.sql +63 -0
  135. package/dist/platform/migrations/0520_publish_requests.sql +20 -0
  136. package/dist/platform/migrations/0530_subscriptions.sql +173 -0
  137. package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
  138. package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
  139. package/dist/platform/migrations/0533_allowances.sql +262 -0
  140. package/dist/platform/migrations/0560_recurring.sql +75 -0
  141. package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
  142. package/dist/platform/migrations/0581_once_per_person.sql +34 -0
  143. package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
  144. package/dist/platform/migrations/0610_waitlists.sql +54 -0
  145. package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
  146. package/dist/platform/migrations/0650_person_links.sql +90 -0
  147. package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
  148. package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
  149. package/dist/platform/sdk/allowance.ts +522 -0
  150. package/dist/platform/sdk/automation-check.ts +534 -0
  151. package/dist/platform/sdk/automation.ts +743 -0
  152. package/dist/platform/sdk/behaviour.ts +215 -0
  153. package/dist/platform/sdk/capacity.ts +303 -0
  154. package/dist/platform/sdk/contract.ts +909 -0
  155. package/dist/platform/sdk/document.ts +935 -0
  156. package/dist/platform/sdk/field-types.ts +111 -0
  157. package/dist/platform/sdk/formula/ast.ts +72 -0
  158. package/dist/platform/sdk/formula/compile.ts +454 -0
  159. package/dist/platform/sdk/formula/index.ts +4 -0
  160. package/dist/platform/sdk/formula/parser.ts +417 -0
  161. package/dist/platform/sdk/index.ts +36 -0
  162. package/dist/platform/sdk/manifest.ts +1785 -0
  163. package/dist/platform/sdk/media.ts +108 -0
  164. package/dist/platform/sdk/permissions.ts +60 -0
  165. package/dist/platform/sdk/recurring.ts +321 -0
  166. package/dist/platform/sdk/renamed.ts +63 -0
  167. package/dist/platform/sdk/rich-text-fixture.ts +68 -0
  168. package/dist/platform/sdk/rich-text.ts +221 -0
  169. package/dist/platform/sdk/runtime.ts +410 -0
  170. package/dist/platform/sdk/sellable.ts +1138 -0
  171. package/dist/platform/sdk/slug.ts +25 -0
  172. package/dist/platform/sdk/states.ts +598 -0
  173. package/dist/platform/sdk/testing.ts +847 -0
  174. package/dist/platform/sdk/unique.ts +81 -0
  175. package/dist/products-2H5DR232.js +11 -0
  176. package/dist/run-7P4RQALH.js +648 -0
  177. package/dist/run-PO3W5BFA.js +508 -0
  178. package/dist/run-ZCGFMEZF.js +309 -0
  179. package/dist/src-CRO35DYY.js +46 -0
  180. package/dist/src-I3IJ4NKC.js +354 -0
  181. package/dist/token-MOJUA2U6.js +70 -0
  182. package/dist/token-util-TENRN4V7.js +6 -0
  183. package/dist/visibility-TVXZ67FD.js +41 -0
  184. package/package.json +33 -4
@@ -0,0 +1,309 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ parseCsv
4
+ } from "./chunk-P6UWZ6QQ.js";
5
+ import {
6
+ sessionHost,
7
+ signInForRun
8
+ } from "./chunk-E4WCYTCT.js";
9
+ import "./chunk-LO6WGU5Y.js";
10
+ import "./chunk-5KSXSK7Y.js";
11
+
12
+ // src/offers-import/run.ts
13
+ import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";
14
+ import { basename } from "node:path";
15
+
16
+ // src/offers-import/engine.ts
17
+ var EMAIL_HEADERS = ["email", "email_address"];
18
+ var DATE_HEADERS = ["paid_up_to", "free_until", "paid_until"];
19
+ var REFERENCE_HEADERS = ["reference", "ref", "subscription_id", "old_reference"];
20
+ var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
21
+ var MOMENT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(\.\d+)?)?(Z|[+-](\d{2}):(\d{2}))$/;
22
+ function realPaidUpDate(when) {
23
+ const m = DATE.exec(when) ?? MOMENT.exec(when);
24
+ if (!m) return false;
25
+ const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
26
+ const [h, mi, s] = [Number(m[4] ?? 0), Number(m[5] ?? 0), Number(m[6] ?? 0)];
27
+ if (m[9] !== void 0 && (Number(m[9]) > 14 || Number(m[10]) > 59)) return false;
28
+ const at = new Date(Date.UTC(y, mo - 1, d, h, mi, s));
29
+ return at.getUTCFullYear() === y && at.getUTCMonth() === mo - 1 && at.getUTCDate() === d && at.getUTCHours() === h && at.getUTCMinutes() === mi && at.getUTCSeconds() === s;
30
+ }
31
+ function readOffersFile(text, name = "offers.csv") {
32
+ const problems = [];
33
+ const at = (line) => `${name}:${line}`;
34
+ const table = parseCsv(text.replace(/^/, ""));
35
+ const header = table[0];
36
+ if (!header) return { rows: [], problems: [{ file: name, message: "the file is empty" }] };
37
+ const names = header.cells.map(
38
+ (c) => c.trim().toLowerCase().replace(/[\s-]+/g, "_")
39
+ );
40
+ const column = (options) => names.findIndex((n) => options.includes(n));
41
+ const email = column(EMAIL_HEADERS);
42
+ const date = column(DATE_HEADERS);
43
+ const reference = column(REFERENCE_HEADERS);
44
+ if (email < 0 || date < 0) {
45
+ problems.push({
46
+ file: at(header.line),
47
+ message: `the header must name ${EMAIL_HEADERS[0]} and ${DATE_HEADERS[0]} (it has: ${names.join(", ") || "nothing"})`
48
+ });
49
+ return { rows: [], problems };
50
+ }
51
+ const rows = [];
52
+ const seen = /* @__PURE__ */ new Map();
53
+ for (const { line, cells } of table.slice(1)) {
54
+ const address = (cells[email] ?? "").trim().toLowerCase();
55
+ const when = (cells[date] ?? "").trim();
56
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address)) {
57
+ problems.push({ file: at(line), message: `not an email address: "${cells[email] ?? ""}"` });
58
+ continue;
59
+ }
60
+ if (!realPaidUpDate(when)) {
61
+ problems.push({
62
+ file: at(line),
63
+ message: `the paid-up date is not a real date (YYYY-MM-DD) or moment with its offset: "${when}"`
64
+ });
65
+ continue;
66
+ }
67
+ const before = seen.get(address);
68
+ if (before !== void 0) {
69
+ problems.push({ file: at(line), message: `${address} is on line ${before} already` });
70
+ continue;
71
+ }
72
+ seen.set(address, line);
73
+ const ref = reference >= 0 ? (cells[reference] ?? "").trim() : "";
74
+ rows.push({ line, email: address, freeUntil: when, ...ref ? { reference: ref } : {} });
75
+ }
76
+ if (!rows.length && !problems.length) {
77
+ problems.push({ file: name, message: "no rows under the header" });
78
+ }
79
+ return { rows, problems };
80
+ }
81
+ var OFFERS_BATCH = 50;
82
+ async function resolvePlan(host, spec) {
83
+ const [object, id] = spec.split(":");
84
+ const title = (r) => String(r.title ?? r.values?.title ?? r.values?.name ?? r.id);
85
+ if (id) {
86
+ let found;
87
+ try {
88
+ found = await host.call("record.get", { object, id });
89
+ } catch (error) {
90
+ if (error.code === "not_found") {
91
+ throw new Error(`No ${object} record ${id} on the host.`);
92
+ }
93
+ throw error;
94
+ }
95
+ return { object, id, title: title(found) };
96
+ }
97
+ const page = await host.call("record.list", { object, limit: 50 });
98
+ if (page.items.length === 1) {
99
+ const only = page.items[0];
100
+ return { object, id: only.id, title: title(only) };
101
+ }
102
+ if (!page.items.length) throw new Error(`The host has no ${object} record to offer.`);
103
+ throw new Error(
104
+ `The host has ${page.items.length} ${object} records; name one with --plan ${object}:<id>:
105
+ ` + page.items.map((r) => ` ${object}:${r.id} ${title(r)}`).join("\n")
106
+ );
107
+ }
108
+ var PROBLEM = /* @__PURE__ */ new Set(["unmatched", "several_people", "invalid", "conflict"]);
109
+ async function runOffersImport(file, host, options) {
110
+ const call = async (batch, dryRun) => {
111
+ const input = {
112
+ plan: { object: options.plan.object, id: options.plan.id },
113
+ rows: batch.map(({ email, freeUntil, reference }) => ({
114
+ email,
115
+ freeUntil,
116
+ ...reference ? { reference } : {}
117
+ })),
118
+ dryRun,
119
+ invite: options.invite,
120
+ reissue: Boolean(options.reissue)
121
+ };
122
+ for (let attempt = 1; ; attempt += 1) {
123
+ try {
124
+ return await host.call("subscription.offer.import", input);
125
+ } catch (error) {
126
+ const e = error;
127
+ if (attempt >= 3 || e.code !== "conflict" || e.details?.rule !== "offer_changed") {
128
+ throw error;
129
+ }
130
+ }
131
+ }
132
+ };
133
+ const send = async (dryRun) => {
134
+ const out = [];
135
+ for (let i = 0; i < file.rows.length; i += OFFERS_BATCH) {
136
+ const batch = file.rows.slice(i, i + OFFERS_BATCH);
137
+ const answer = await call(batch, dryRun);
138
+ answer.results.forEach((r, n) => {
139
+ out.push({ ...r, line: batch[n].line });
140
+ });
141
+ if (!dryRun)
142
+ options.progress?.(
143
+ `Wrote ${Math.min(i + OFFERS_BATCH, file.rows.length)} of ${file.rows.length}\u2026`
144
+ );
145
+ }
146
+ return out;
147
+ };
148
+ const checked = await send(true);
149
+ const rows = options.dryRun ? checked : await send(false);
150
+ return {
151
+ plan: options.plan,
152
+ dryRun: options.dryRun,
153
+ rows,
154
+ problems: rows.filter((r) => PROBLEM.has(r.outcome))
155
+ };
156
+ }
157
+ var NOTE_WORDS = {
158
+ past: "the paid-up date has passed: it cannot be taken; they subscribe as anyone does",
159
+ under_48_hours: "under 48 hours to the paid-up date: taking it now is charged at once (the provider needs 48 hours for free time)",
160
+ taken: "taken already",
161
+ withdrawn: "withdrawn by staff; to give this person a fresh offer, run again with --reissue (the withdrawn one stays as it was)",
162
+ reissued: "a fresh offer beside the one staff withdrew",
163
+ held: "a checkout from it is still open at the payment provider on the old date; run again once it expires (within a day) or is completed",
164
+ held_unconfirmed: "the payment provider could not say whether its checkout is still open; run again later",
165
+ completing: "its checkout was completed: the subscription is being confirmed",
166
+ another_person: "the address now belongs to another person",
167
+ twice: "the address is in this import twice",
168
+ "merge them first": "more than one person has this address: merge them first",
169
+ "no person has this address": "no person has this address: import the people first"
170
+ };
171
+ function offersReportLines(report, name = "offers.csv") {
172
+ const lines = [];
173
+ const count = (o) => report.rows.filter((r) => r.outcome === o).length;
174
+ const verb = report.dryRun ? "would be" : "were";
175
+ lines.push(
176
+ `Continuation offers on ${report.plan.title} (${report.plan.object}:${report.plan.id}): ${count("created")} ${verb} created, ${count("updated")} updated, ${count("unchanged")} unchanged; ${report.problems.length} not written.`
177
+ );
178
+ for (const r of report.rows) {
179
+ if (!PROBLEM.has(r.outcome) && !r.note) continue;
180
+ const why = r.note ? NOTE_WORDS[r.note] ?? r.note : r.outcome;
181
+ lines.push(
182
+ ` ${name}:${r.line} ${r.email}: ${PROBLEM.has(r.outcome) ? `${r.outcome}: ` : ""}${why}`
183
+ );
184
+ }
185
+ const usable = report.rows.filter((r) => !PROBLEM.has(r.outcome) && r.note !== "past");
186
+ const invited = usable.filter((r) => r.signIn === "invited").length;
187
+ const cannot = usable.filter((r) => r.signIn === null).length;
188
+ if (invited) lines.push(`${invited} address(es) ${verb} invited to sign in.`);
189
+ for (const r of report.rows.filter((x) => x.signIn === "invite_refused")) {
190
+ lines.push(
191
+ ` ${name}:${r.line} ${r.email}: cannot be invited (an erased person's address); the rest went ahead`
192
+ );
193
+ }
194
+ if (cannot) {
195
+ lines.push(
196
+ `${cannot} of these people have no customer account and no invite. They can sign in to take their offer while customer sign-up is open, or while the setting "anyone starting a subscription" is on and the plan is on sale (Settings \u2192 Users); otherwise run again with --invite (users:manage) to invite them, which works under every sign-up setting.`
197
+ );
198
+ }
199
+ if (!report.dryRun) {
200
+ lines.push(
201
+ "Nothing is sent to anyone. Tell each person to sign in on the site with this address and continue their subscription there; the report (Subscriptions, Continuation offers) says who has, so you end exactly those old subscriptions at their period's end."
202
+ );
203
+ }
204
+ return lines;
205
+ }
206
+
207
+ // src/offers-import/run.ts
208
+ var OFFERS_USAGE = "Usage: cos subscriptions offers import <offers.csv> --host <url> --plan <object>[:<id>] [--email <you>] [--dry-run] [--invite] [--reissue]\n cos subscriptions offers report --host <url> [--status taken|open|expired|withdrawn] [--out <file.csv>] [--email <you>]";
209
+ function hostOf(flag, io) {
210
+ const host = flag?.replace(/\/+$/, "");
211
+ if (!host || !/^https?:\/\//.test(host)) {
212
+ io.err("--host is the host's address, e.g. https://admin.example.com");
213
+ return null;
214
+ }
215
+ return host;
216
+ }
217
+ async function offersImport(positional, flags, io) {
218
+ const path = positional[0];
219
+ if (!path) {
220
+ io.err(
221
+ `${OFFERS_USAGE}
222
+
223
+ The file: a header naming email and paid_up_to (and optionally reference), one row a person. See docs/importing.md.`
224
+ );
225
+ return 2;
226
+ }
227
+ const host = hostOf(flags.host, io);
228
+ if (!host) return 2;
229
+ if (!flags.plan || !/^[a-z][a-z0-9]*\.[a-z][a-z0-9]*(:[A-Za-z0-9_-]+)?$/.test(flags.plan)) {
230
+ io.err(
231
+ "--plan is the plan's object, e.g. courses.plan (or courses.plan:<id> when there are several)"
232
+ );
233
+ return 2;
234
+ }
235
+ if (!existsSync(path) || !statSync(path).isFile()) {
236
+ io.err(`${path} is not a file`);
237
+ return 2;
238
+ }
239
+ const name = basename(path);
240
+ const file = readOffersFile(readFileSync(path, "utf8"), name);
241
+ if (file.problems.length) {
242
+ io.err(`Nothing was sent: ${file.problems.length} problem(s) in ${name}.`);
243
+ for (const p of file.problems) io.err(` ${p.file}: ${p.message}`);
244
+ return 1;
245
+ }
246
+ io.out(`${file.rows.length} person(s) in ${name}.`);
247
+ let session;
248
+ try {
249
+ session = await signInForRun(host, flags.email, io, "cos subscriptions offers import");
250
+ } catch (error) {
251
+ io.err(`Could not sign in: ${error.message}`);
252
+ return 1;
253
+ }
254
+ try {
255
+ const on = sessionHost(host, () => session.headers());
256
+ const plan = await resolvePlan(on, flags.plan);
257
+ const report = await runOffersImport(file, on, {
258
+ plan,
259
+ dryRun: Boolean(flags.dryRun),
260
+ invite: Boolean(flags.invite),
261
+ reissue: Boolean(flags.reissue),
262
+ progress: (line) => io.out(line)
263
+ });
264
+ for (const line of offersReportLines(report, name)) {
265
+ (report.problems.length ? io.err : io.out)(line);
266
+ }
267
+ return report.problems.length ? 1 : 0;
268
+ } catch (error) {
269
+ io.err(`Error: ${error.message}`);
270
+ return 1;
271
+ } finally {
272
+ await session.signOut();
273
+ }
274
+ }
275
+ async function offersReport(flags, io) {
276
+ const host = hostOf(flags.host, io);
277
+ if (!host) return 2;
278
+ if (flags.status && !["taken", "open", "expired", "withdrawn"].includes(flags.status)) {
279
+ io.err("--status is taken, open, expired or withdrawn");
280
+ return 2;
281
+ }
282
+ let session;
283
+ try {
284
+ session = await signInForRun(host, flags.email, io, "cos subscriptions offers report");
285
+ } catch (error) {
286
+ io.err(`Could not sign in: ${error.message}`);
287
+ return 1;
288
+ }
289
+ try {
290
+ const file = await sessionHost(host, () => session.headers()).call("subscription.offer.export", flags.status ? { status: flags.status } : {});
291
+ if (flags.out) {
292
+ writeFileSync(flags.out, file.csv);
293
+ io.out(`${file.rowCount} offer(s) written to ${flags.out}.`);
294
+ } else {
295
+ io.out(file.csv.trimEnd());
296
+ }
297
+ return 0;
298
+ } catch (error) {
299
+ io.err(`Error: ${error.message}`);
300
+ return 1;
301
+ } finally {
302
+ await session.signOut();
303
+ }
304
+ }
305
+ export {
306
+ OFFERS_USAGE,
307
+ offersImport,
308
+ offersReport
309
+ };
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ENTRY_POINTS,
4
+ operationsFor,
5
+ productContract,
6
+ releaseContract,
7
+ renderClient,
8
+ renderEntry,
9
+ renderRoleClient,
10
+ schemaToTs
11
+ } from "./chunk-LAAL4YGR.js";
12
+ import "./chunk-UB4I2QKR.js";
13
+ import "./chunk-DHS2CV2M.js";
14
+ import "./chunk-K34UKWEI.js";
15
+ import "./chunk-2IVEVPMY.js";
16
+ import "./chunk-6WGFA2IV.js";
17
+ import "./chunk-WHKJGF36.js";
18
+ import "./chunk-324WJXNP.js";
19
+ import "./chunk-7OGCMQXG.js";
20
+ import "./chunk-XIDLW3EP.js";
21
+ import "./chunk-FJIZGS5Q.js";
22
+ import "./chunk-ZAWES2UD.js";
23
+ import "./chunk-E64SG24J.js";
24
+ import "./chunk-YNUZRTPH.js";
25
+ import "./chunk-6ELZRNUU.js";
26
+ import "./chunk-2TWV3SVB.js";
27
+ import "./chunk-ZZFWMVJO.js";
28
+ import "./chunk-2XC5JLBO.js";
29
+ import "./chunk-DU6OIFOU.js";
30
+ import "./chunk-KGHA67HG.js";
31
+ import "./chunk-6UWRT4VM.js";
32
+ import "./chunk-6XTU2MTP.js";
33
+ import "./chunk-YFTLIEWU.js";
34
+ import "./chunk-7D4GKZOX.js";
35
+ import "./chunk-LO6WGU5Y.js";
36
+ import "./chunk-5KSXSK7Y.js";
37
+ export {
38
+ ENTRY_POINTS,
39
+ operationsFor,
40
+ productContract,
41
+ releaseContract,
42
+ renderClient,
43
+ renderEntry,
44
+ renderRoleClient,
45
+ schemaToTs
46
+ };
@@ -0,0 +1,354 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ ALLOWANCE_PERIODS,
4
+ ALLOWANCE_VALUES,
5
+ AUTOMATION_TRIGGER_TYPES,
6
+ AutomationStepError,
7
+ BASE_AUTOMATION_FIELDS,
8
+ CAPACITY_SHOW,
9
+ CAPACITY_VALUES,
10
+ CAPTION_LANGUAGE_RE,
11
+ CONTRACT_VERSION,
12
+ CORE_AUTOMATION_FIELDS,
13
+ CORE_FORMULA_FIELDS,
14
+ CORE_OBJECT_NAMES,
15
+ DEFAULT_WAIT_TIMEOUT,
16
+ DOCUMENT_DEFAULT_BYTES,
17
+ DOCUMENT_DEFAULT_TEXT,
18
+ DOCUMENT_MAX_BYTES,
19
+ DOCUMENT_MAX_DEPTH,
20
+ DOCUMENT_MAX_ISSUES,
21
+ DOCUMENT_MAX_LIST,
22
+ DOCUMENT_MAX_PATHS,
23
+ DOCUMENT_MAX_TEXT,
24
+ EXTENSION_ID_RE,
25
+ EXTENSION_PERMISSION_RE,
26
+ FIELD_NAME_RE,
27
+ FIELD_TYPES,
28
+ FILE_NODE,
29
+ FORBIDDEN_OPERATION_PREFIXES,
30
+ GATEKEEPER_MODULES,
31
+ GRANT_SOURCES,
32
+ HOST_MODULES,
33
+ IMAGE_MAX_BYTES,
34
+ IMAGE_SCHEMA,
35
+ LOSSLESS_TYPE_CHANGES,
36
+ MAX_TOTAL_WAIT_DAYS,
37
+ MEDIA_CAPTION_MAX_BYTES,
38
+ MEDIA_FILE_MAX_BYTES,
39
+ MEDIA_FILE_TYPES,
40
+ MEDIA_KINDS,
41
+ MEDIA_MAX_BYTES,
42
+ MEDIA_TYPES,
43
+ MEDIA_VIDEO_MAX_BYTES,
44
+ MEDIA_VIDEO_MAX_SECONDS,
45
+ MEDIA_VIDEO_TYPE,
46
+ MOVERS,
47
+ NOTIFY_OPERATION,
48
+ OBJECT_NAME_RE,
49
+ OLD_OPS_MODULE,
50
+ OLD_OPS_SPECIFIER,
51
+ OLD_VIEW_PREFIX,
52
+ OPS_MODULE,
53
+ OPS_SPECIFIER,
54
+ OpsCallError,
55
+ PUBLISHED_FIELD_NAMES,
56
+ RECORD_EVENTS,
57
+ RECURRING_HORIZON_DAYS,
58
+ RECURRING_HORIZON_MAX,
59
+ RELATION_CORE_TARGETS,
60
+ RESERVED_FIELD_NAMES,
61
+ RICH_TEXT_BLOCKS,
62
+ RICH_TEXT_DEFAULT_BYTES,
63
+ RICH_TEXT_FIXTURE,
64
+ RICH_TEXT_FIXTURE_MEDIA,
65
+ RICH_TEXT_MARKS,
66
+ RICH_TEXT_MEDIA_OBJECT,
67
+ RICH_TEXT_SCHEMA,
68
+ SLUG_FROM_TITLE_MAX,
69
+ SLUG_MAX,
70
+ SLUG_RE,
71
+ STAGE_TYPES,
72
+ SUBSCRIPTION_GRANT_STATES,
73
+ SUPPORTED_CONTRACT_VERSIONS,
74
+ SYNC_EVENT_TYPES,
75
+ TAX_CODE_PATTERN,
76
+ TOOL_AUDIENCES,
77
+ TOOL_NAME_RE,
78
+ TOOL_RISKS,
79
+ VIDEO_MAX_BYTES,
80
+ VIDEO_NODE,
81
+ VIDEO_SCHEMA,
82
+ VIEW_PREFIX,
83
+ WAIT_EVENT_RE,
84
+ WEEKDAYS,
85
+ allowanceManifestSchema,
86
+ automationConditionSchema,
87
+ automationConnectionSchema,
88
+ automationManifestSchema,
89
+ automationRailsSchema,
90
+ automationStepSchema,
91
+ automationTriggerSchema,
92
+ buildAutomationContext,
93
+ buildContext,
94
+ capacityManifestSchema,
95
+ checkAutomation,
96
+ checkDocumentSchema,
97
+ checkGrant,
98
+ checkGrantedHolder,
99
+ checkObjectAllowance,
100
+ checkObjectCapacity,
101
+ checkObjectClaims,
102
+ checkObjectRecurring,
103
+ checkObjectSellable,
104
+ checkObjectStates,
105
+ checkObjectUnique,
106
+ claimsManifestSchema,
107
+ cronIssues,
108
+ customerWritable,
109
+ dashboardManifestSchema,
110
+ declaredModules,
111
+ defineAutomation,
112
+ defineExtension,
113
+ defineTool,
114
+ documentBytes,
115
+ documentJsonPath,
116
+ documentMaxBytesOf,
117
+ documentMediaReach,
118
+ documentPathNode,
119
+ documentRefs,
120
+ documentSchemaOf,
121
+ durationMs,
122
+ durationSchema,
123
+ external_exports,
124
+ fieldManifestSchema,
125
+ formatDocumentIssue,
126
+ formulaFields,
127
+ formulaTypeOf,
128
+ hasMarkup,
129
+ hostFilledFields,
130
+ isDocumentHref,
131
+ isDocumentType,
132
+ isExtension,
133
+ isLosslessChange,
134
+ isWebVtt,
135
+ manifestSchema,
136
+ maxBytesOf,
137
+ mediaProblem,
138
+ moveOrigins,
139
+ notificationInput,
140
+ objectManifestSchema,
141
+ onRejectedSchema,
142
+ onStep,
143
+ permissionsManifestSchema,
144
+ recipientSchema,
145
+ recordActionManifestSchema,
146
+ recordViewManifestSchema,
147
+ recurringManifestSchema,
148
+ redactDocument,
149
+ renamedMessage,
150
+ renamedView,
151
+ resolveFieldPath,
152
+ roleManifestSchema,
153
+ runAutomation,
154
+ runExtension,
155
+ sellableManifestSchema,
156
+ settingManifestSchema,
157
+ slugify,
158
+ sniffFileType,
159
+ sniffMediaType,
160
+ sniffUpload,
161
+ spenderAllows,
162
+ spendsOnList,
163
+ staffOnlyPathsOf,
164
+ stagesManifestSchema,
165
+ statesManifestSchema,
166
+ toManifest,
167
+ toolManifestSchema,
168
+ triggerObject,
169
+ uniqueManifestSchema,
170
+ validateDocument,
171
+ validateManifest,
172
+ valueMatchSchema,
173
+ viewManifestSchema,
174
+ waitlistManifestSchema,
175
+ windowBoundSchema,
176
+ windowChecks
177
+ } from "./chunk-LO6WGU5Y.js";
178
+ import "./chunk-5KSXSK7Y.js";
179
+ export {
180
+ ALLOWANCE_PERIODS,
181
+ ALLOWANCE_VALUES,
182
+ AUTOMATION_TRIGGER_TYPES,
183
+ AutomationStepError,
184
+ BASE_AUTOMATION_FIELDS,
185
+ CAPACITY_SHOW,
186
+ CAPACITY_VALUES,
187
+ CAPTION_LANGUAGE_RE,
188
+ CONTRACT_VERSION,
189
+ CORE_AUTOMATION_FIELDS,
190
+ CORE_FORMULA_FIELDS,
191
+ CORE_OBJECT_NAMES,
192
+ DEFAULT_WAIT_TIMEOUT,
193
+ DOCUMENT_DEFAULT_BYTES,
194
+ DOCUMENT_DEFAULT_TEXT,
195
+ DOCUMENT_MAX_BYTES,
196
+ DOCUMENT_MAX_DEPTH,
197
+ DOCUMENT_MAX_ISSUES,
198
+ DOCUMENT_MAX_LIST,
199
+ DOCUMENT_MAX_PATHS,
200
+ DOCUMENT_MAX_TEXT,
201
+ EXTENSION_ID_RE,
202
+ EXTENSION_PERMISSION_RE,
203
+ FIELD_NAME_RE,
204
+ FIELD_TYPES,
205
+ FILE_NODE,
206
+ FORBIDDEN_OPERATION_PREFIXES,
207
+ GATEKEEPER_MODULES,
208
+ GRANT_SOURCES,
209
+ HOST_MODULES,
210
+ IMAGE_MAX_BYTES,
211
+ IMAGE_SCHEMA,
212
+ LOSSLESS_TYPE_CHANGES,
213
+ MAX_TOTAL_WAIT_DAYS,
214
+ MEDIA_CAPTION_MAX_BYTES,
215
+ MEDIA_FILE_MAX_BYTES,
216
+ MEDIA_FILE_TYPES,
217
+ MEDIA_KINDS,
218
+ MEDIA_MAX_BYTES,
219
+ MEDIA_TYPES,
220
+ MEDIA_VIDEO_MAX_BYTES,
221
+ MEDIA_VIDEO_MAX_SECONDS,
222
+ MEDIA_VIDEO_TYPE,
223
+ MOVERS,
224
+ NOTIFY_OPERATION,
225
+ OBJECT_NAME_RE,
226
+ OLD_OPS_MODULE,
227
+ OLD_OPS_SPECIFIER,
228
+ OLD_VIEW_PREFIX,
229
+ OPS_MODULE,
230
+ OPS_SPECIFIER,
231
+ OpsCallError,
232
+ PUBLISHED_FIELD_NAMES,
233
+ RECORD_EVENTS,
234
+ RECURRING_HORIZON_DAYS,
235
+ RECURRING_HORIZON_MAX,
236
+ RELATION_CORE_TARGETS,
237
+ RESERVED_FIELD_NAMES,
238
+ RICH_TEXT_BLOCKS,
239
+ RICH_TEXT_DEFAULT_BYTES,
240
+ RICH_TEXT_FIXTURE,
241
+ RICH_TEXT_FIXTURE_MEDIA,
242
+ RICH_TEXT_MARKS,
243
+ RICH_TEXT_MEDIA_OBJECT,
244
+ RICH_TEXT_SCHEMA,
245
+ SLUG_FROM_TITLE_MAX,
246
+ SLUG_MAX,
247
+ SLUG_RE,
248
+ STAGE_TYPES,
249
+ SUBSCRIPTION_GRANT_STATES,
250
+ SUPPORTED_CONTRACT_VERSIONS,
251
+ SYNC_EVENT_TYPES,
252
+ TAX_CODE_PATTERN,
253
+ TOOL_AUDIENCES,
254
+ TOOL_NAME_RE,
255
+ TOOL_RISKS,
256
+ VIDEO_MAX_BYTES,
257
+ VIDEO_NODE,
258
+ VIDEO_SCHEMA,
259
+ VIEW_PREFIX,
260
+ WAIT_EVENT_RE,
261
+ WEEKDAYS,
262
+ allowanceManifestSchema,
263
+ automationConditionSchema,
264
+ automationConnectionSchema,
265
+ automationManifestSchema,
266
+ automationRailsSchema,
267
+ automationStepSchema,
268
+ automationTriggerSchema,
269
+ buildAutomationContext,
270
+ buildContext,
271
+ capacityManifestSchema,
272
+ checkAutomation,
273
+ checkDocumentSchema,
274
+ checkGrant,
275
+ checkGrantedHolder,
276
+ checkObjectAllowance,
277
+ checkObjectCapacity,
278
+ checkObjectClaims,
279
+ checkObjectRecurring,
280
+ checkObjectSellable,
281
+ checkObjectStates,
282
+ checkObjectUnique,
283
+ claimsManifestSchema,
284
+ cronIssues,
285
+ customerWritable,
286
+ dashboardManifestSchema,
287
+ declaredModules,
288
+ defineAutomation,
289
+ defineExtension,
290
+ defineTool,
291
+ documentBytes,
292
+ documentJsonPath,
293
+ documentMaxBytesOf,
294
+ documentMediaReach,
295
+ documentPathNode,
296
+ documentRefs,
297
+ documentSchemaOf,
298
+ durationMs,
299
+ durationSchema,
300
+ fieldManifestSchema,
301
+ formatDocumentIssue,
302
+ formulaFields,
303
+ formulaTypeOf,
304
+ hasMarkup,
305
+ hostFilledFields,
306
+ isDocumentHref,
307
+ isDocumentType,
308
+ isExtension,
309
+ isLosslessChange,
310
+ isWebVtt,
311
+ manifestSchema,
312
+ maxBytesOf,
313
+ mediaProblem,
314
+ moveOrigins,
315
+ notificationInput,
316
+ objectManifestSchema,
317
+ onRejectedSchema,
318
+ onStep,
319
+ permissionsManifestSchema,
320
+ recipientSchema,
321
+ recordActionManifestSchema,
322
+ recordViewManifestSchema,
323
+ recurringManifestSchema,
324
+ redactDocument,
325
+ renamedMessage,
326
+ renamedView,
327
+ resolveFieldPath,
328
+ roleManifestSchema,
329
+ runAutomation,
330
+ runExtension,
331
+ sellableManifestSchema,
332
+ settingManifestSchema,
333
+ slugify,
334
+ sniffFileType,
335
+ sniffMediaType,
336
+ sniffUpload,
337
+ spenderAllows,
338
+ spendsOnList,
339
+ staffOnlyPathsOf,
340
+ stagesManifestSchema,
341
+ statesManifestSchema,
342
+ toManifest,
343
+ toolManifestSchema,
344
+ triggerObject,
345
+ uniqueManifestSchema,
346
+ validateDocument,
347
+ validateManifest,
348
+ valueMatchSchema,
349
+ viewManifestSchema,
350
+ waitlistManifestSchema,
351
+ windowBoundSchema,
352
+ windowChecks,
353
+ external_exports as z
354
+ };