@odla-ai/chapter 0.31.3 → 0.32.0
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/README.md +100 -2
- package/dist/{chunk-QWMP6TSM.js → chunk-BBCT7U3D.js} +282 -2
- package/dist/chunk-BBCT7U3D.js.map +1 -0
- package/dist/{copy-context-HAhNTZdl.d.ts → copy-context-BXBEdp4p.d.ts} +3 -3
- package/dist/index.cjs +363 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -5
- package/dist/index.d.ts +79 -5
- package/dist/index.js +363 -142
- package/dist/index.js.map +1 -1
- package/dist/ui/admin/index.d.ts +2 -2
- package/dist/ui/index.d.ts +2 -2
- package/dist/ui/index.js +5 -1
- package/dist/ui/member/index.d.ts +74 -3
- package/dist/ui/member/index.js +5 -1
- package/dist/worker/index.cjs.map +1 -1
- package/dist/worker/index.d.cts +3 -3
- package/dist/worker/index.d.ts +3 -3
- package/dist/worker/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-QWMP6TSM.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,154 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
2
|
import { defineCrm } from "@odla-ai/crm";
|
|
3
3
|
|
|
4
|
+
// src/member.ts
|
|
5
|
+
import { assertFieldCondition, resolveFieldStates } from "@odla-ai/crm";
|
|
6
|
+
|
|
7
|
+
// src/application-id.ts
|
|
8
|
+
var APPLICATION_ID_DOMAIN = "odla-ai/chapter/application/v1:";
|
|
9
|
+
async function applicationIdForSubmission(submissionId) {
|
|
10
|
+
const input = new TextEncoder().encode(`${APPLICATION_ID_DOMAIN}${submissionId}`);
|
|
11
|
+
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", input)).slice(0, 16);
|
|
12
|
+
bytes[6] = bytes[6] & 15 | 128;
|
|
13
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
14
|
+
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/member.ts
|
|
19
|
+
var DEFAULT_REQUIRED = ["firstName", "lastName", "email", "referral", "whoYouAre", "message"];
|
|
20
|
+
var DEFAULT_OPTIONAL = ["referralName", "linkedin", "phone", "state"];
|
|
21
|
+
var SCHEMA_FIELD = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
22
|
+
function resolveApplication(a) {
|
|
23
|
+
const required = a?.required ?? DEFAULT_REQUIRED;
|
|
24
|
+
const optional = a?.optional ?? DEFAULT_OPTIONAL;
|
|
25
|
+
for (const [name, arr] of [["required", required], ["optional", optional]]) {
|
|
26
|
+
if (!Array.isArray(arr) || !arr.every((f) => typeof f === "string" && f !== "")) {
|
|
27
|
+
throw new Error(`defineChapter.application.${name}: must be an array of field-name strings`);
|
|
28
|
+
}
|
|
29
|
+
const unsafe = arr.find((field) => !SCHEMA_FIELD.test(field));
|
|
30
|
+
if (unsafe) {
|
|
31
|
+
throw new Error(`defineChapter.application.${name}: field "${unsafe}" must match ${SCHEMA_FIELD.source}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const duplicate = [...required, ...optional].find((field, index, fields) => fields.indexOf(field) !== index);
|
|
35
|
+
if (duplicate) {
|
|
36
|
+
throw new Error(`defineChapter.application: duplicate field "${duplicate}" across required/optional lists`);
|
|
37
|
+
}
|
|
38
|
+
if (a?.profileFields !== void 0 && (!Array.isArray(a.profileFields) || !a.profileFields.every((f) => typeof f === "string" && f !== ""))) {
|
|
39
|
+
throw new Error("defineChapter.application.profileFields: must be an array of field-name strings");
|
|
40
|
+
}
|
|
41
|
+
if (a?.crmFields !== void 0 && (!Array.isArray(a.crmFields) || !a.crmFields.every((f) => typeof f === "string" && f !== ""))) {
|
|
42
|
+
throw new Error("defineChapter.application.crmFields: must be an array of field-name strings");
|
|
43
|
+
}
|
|
44
|
+
const conditions = a?.conditions ?? {};
|
|
45
|
+
for (const [field, declared] of Object.entries(conditions)) {
|
|
46
|
+
for (const key of ["visibleWhen", "requiredWhen"]) {
|
|
47
|
+
const expression = declared?.[key];
|
|
48
|
+
if (expression === void 0) continue;
|
|
49
|
+
if (typeof expression !== "string" || !expression.trim()) {
|
|
50
|
+
throw new Error(`defineChapter.application.conditions.${field}.${key}: must be a non-empty CEL condition`);
|
|
51
|
+
}
|
|
52
|
+
assertFieldCondition(expression, `defineChapter.application.conditions.${field}.${key}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
required,
|
|
57
|
+
optional,
|
|
58
|
+
conditions,
|
|
59
|
+
maxLen: a?.maxLen ?? {},
|
|
60
|
+
defaultMaxLen: a?.defaultMaxLen ?? 2e3,
|
|
61
|
+
bodyCap: a?.bodyCap ?? 32768,
|
|
62
|
+
requireDisclaimerAck: a?.requireDisclaimerAck ?? true,
|
|
63
|
+
profileFields: a?.profileFields ?? [],
|
|
64
|
+
crmFields: a?.crmFields ?? [],
|
|
65
|
+
maxArrayLen: a?.maxArrayLen ?? 100,
|
|
66
|
+
validateEmail: a?.validateEmail ?? true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
70
|
+
function isValidEmail(value) {
|
|
71
|
+
return typeof value === "string" && EMAIL_RE.test(value);
|
|
72
|
+
}
|
|
73
|
+
function clampArray(value, max) {
|
|
74
|
+
if (!Array.isArray(value)) return value;
|
|
75
|
+
return value.filter((x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean").slice(0, max);
|
|
76
|
+
}
|
|
77
|
+
function hasDisclaimerAck(fields) {
|
|
78
|
+
return fields.disclaimerAck === true || fields.disclaimerAck === "true";
|
|
79
|
+
}
|
|
80
|
+
var IDENTITY_FIELDS = /* @__PURE__ */ new Set(["email", "firstName", "lastName"]);
|
|
81
|
+
function applicantProfile(chapter, fields) {
|
|
82
|
+
const app = chapter.application;
|
|
83
|
+
const allowed = (f) => app.profileFields.includes(f);
|
|
84
|
+
const profile = {};
|
|
85
|
+
for (const f of [...app.required, ...app.optional]) {
|
|
86
|
+
if (IDENTITY_FIELDS.has(f) || !allowed(f)) continue;
|
|
87
|
+
const v = fields[f];
|
|
88
|
+
if (typeof v === "string" && v.trim() !== "") profile[f] = v.trim();
|
|
89
|
+
}
|
|
90
|
+
if (fields.focus !== void 0 && allowed("focus")) profile.focus = clampArray(fields.focus, app.maxArrayLen);
|
|
91
|
+
return Object.keys(profile).length > 0 ? profile : void 0;
|
|
92
|
+
}
|
|
93
|
+
async function submitApplication(db, chapter, fields, opts) {
|
|
94
|
+
const app = chapter.application;
|
|
95
|
+
const fieldStates = resolveFieldStates(app.conditions ?? {}, fields, app.required);
|
|
96
|
+
for (const [f, state] of Object.entries(fieldStates)) {
|
|
97
|
+
if (!state.required) continue;
|
|
98
|
+
const v = fields[f];
|
|
99
|
+
if (typeof v !== "string" || v.trim() === "") return { ok: false, error: `${f} is required` };
|
|
100
|
+
}
|
|
101
|
+
for (const f of [...app.required, ...app.optional]) {
|
|
102
|
+
const v = fields[f];
|
|
103
|
+
const cap = app.maxLen[f] ?? app.defaultMaxLen;
|
|
104
|
+
if (typeof v === "string" && v.length > cap) return { ok: false, error: `${f} exceeds ${cap} characters` };
|
|
105
|
+
}
|
|
106
|
+
if (app.validateEmail && typeof fields.email === "string" && !isValidEmail(fields.email)) {
|
|
107
|
+
return { ok: false, error: "email must be a valid email address" };
|
|
108
|
+
}
|
|
109
|
+
const acked = hasDisclaimerAck(fields);
|
|
110
|
+
if (app.requireDisclaimerAck && !acked) {
|
|
111
|
+
return { ok: false, error: "disclaimerAck is required" };
|
|
112
|
+
}
|
|
113
|
+
const id2 = opts.submissionId ? await applicationIdForSubmission(opts.submissionId) : opts.newId();
|
|
114
|
+
const row = { id: id2, status: chapter.pipeline.initial, createdAt: opts.now };
|
|
115
|
+
for (const f of [...app.required, ...app.optional]) {
|
|
116
|
+
if (fieldStates[f]?.visible === false) continue;
|
|
117
|
+
if (typeof fields[f] === "string") row[f] = fields[f].trim();
|
|
118
|
+
}
|
|
119
|
+
if (fields.focus !== void 0) row.focus = clampArray(fields.focus, app.maxArrayLen);
|
|
120
|
+
if (opts.groupId) row.groupId = opts.groupId;
|
|
121
|
+
if (typeof fields.tierId === "string" && fields.tierId) {
|
|
122
|
+
if (opts.tierIds && !opts.tierIds.includes(fields.tierId)) {
|
|
123
|
+
return { ok: false, error: "tierId is not an offered tier" };
|
|
124
|
+
}
|
|
125
|
+
row.tierId = fields.tierId;
|
|
126
|
+
}
|
|
127
|
+
if (acked) row.disclaimerAckAt = opts.now;
|
|
128
|
+
const { duplicate } = await db.transact(
|
|
129
|
+
[{ t: "update", ns: "applications", id: id2, attrs: row }],
|
|
130
|
+
opts.submissionId ? { mutationId: `join:${opts.submissionId}` } : void 0
|
|
131
|
+
);
|
|
132
|
+
return { ok: true, id: id2, duplicate, status: chapter.pipeline.initial, disclaimerAckAt: acked ? opts.now : null };
|
|
133
|
+
}
|
|
134
|
+
function joinConfig(group, paymentsReady2, tiers2 = [], conditions = {}) {
|
|
135
|
+
return {
|
|
136
|
+
id: group.id,
|
|
137
|
+
name: group.name,
|
|
138
|
+
standardPriceCents: group.standardPriceCents ?? 0,
|
|
139
|
+
foundingDiscountCents: group.foundingDiscountCents ?? 0,
|
|
140
|
+
tiers: [...tiers2],
|
|
141
|
+
// The browser evaluates the same conditions the server enforces.
|
|
142
|
+
conditions,
|
|
143
|
+
disclaimerText: group.disclaimerText ?? "",
|
|
144
|
+
refundPolicyText: group.refundPolicyText ?? "",
|
|
145
|
+
trustCopy: group.trustCopy ?? "",
|
|
146
|
+
commitmentText: group.commitmentText ?? "",
|
|
147
|
+
normsText: group.normsText ?? "",
|
|
148
|
+
paymentsReady: paymentsReady2
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
4
152
|
// src/schema.ts
|
|
5
153
|
function attr(type, flags = {}) {
|
|
6
154
|
return {
|
|
@@ -75,6 +223,47 @@ var applications = {
|
|
|
75
223
|
canceled: attr("boolean", { optional: true })
|
|
76
224
|
}
|
|
77
225
|
};
|
|
226
|
+
var APPLICATION_INPUT_FIELDS = /* @__PURE__ */ new Set([
|
|
227
|
+
"firstName",
|
|
228
|
+
"lastName",
|
|
229
|
+
"email",
|
|
230
|
+
"referral",
|
|
231
|
+
"referralName",
|
|
232
|
+
"whoYouAre",
|
|
233
|
+
"focus",
|
|
234
|
+
"linkedin",
|
|
235
|
+
"message",
|
|
236
|
+
"phone",
|
|
237
|
+
"state"
|
|
238
|
+
]);
|
|
239
|
+
function applicationsFor(application) {
|
|
240
|
+
const attrs = {};
|
|
241
|
+
for (const [name, spec] of Object.entries(applications.attrs)) {
|
|
242
|
+
attrs[name] = {
|
|
243
|
+
...spec,
|
|
244
|
+
optional: APPLICATION_INPUT_FIELDS.has(name) ? true : spec.optional
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const apply = (field, optional) => {
|
|
248
|
+
const existing = Object.hasOwn(attrs, field) ? attrs[field] : void 0;
|
|
249
|
+
if (existing && !APPLICATION_INPUT_FIELDS.has(field)) {
|
|
250
|
+
throw new Error(`defineChapter.application: field "${field}" is reserved by the applications schema`);
|
|
251
|
+
}
|
|
252
|
+
if (existing && existing.type !== "string") {
|
|
253
|
+
throw new Error(`defineChapter.application: field "${field}" is not a configurable string field`);
|
|
254
|
+
}
|
|
255
|
+
const spec = existing ? { ...existing, optional } : attr("string", { optional });
|
|
256
|
+
Object.defineProperty(attrs, field, {
|
|
257
|
+
value: spec,
|
|
258
|
+
enumerable: true,
|
|
259
|
+
configurable: true,
|
|
260
|
+
writable: true
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
for (const field of application.required) apply(field, false);
|
|
264
|
+
for (const field of application.optional) apply(field, true);
|
|
265
|
+
return { attrs };
|
|
266
|
+
}
|
|
78
267
|
var groups = {
|
|
79
268
|
attrs: {
|
|
80
269
|
id: id(),
|
|
@@ -146,10 +335,10 @@ var emailLog = {
|
|
|
146
335
|
sentAt: attr("number", { indexed: true })
|
|
147
336
|
}
|
|
148
337
|
};
|
|
149
|
-
function chapterDb(mode, auth, includeNetworkNotes = false) {
|
|
338
|
+
function chapterDb(mode, auth, includeNetworkNotes = false, application = resolveApplication(void 0)) {
|
|
150
339
|
const entities = {};
|
|
151
340
|
if (mode === "chapter") {
|
|
152
|
-
entities.applications =
|
|
341
|
+
entities.applications = applicationsFor(application);
|
|
153
342
|
entities.groups = groups;
|
|
154
343
|
entities.tiers = tiers;
|
|
155
344
|
entities.meetings = meetings;
|
|
@@ -412,145 +601,6 @@ function canApprove(status, p) {
|
|
|
412
601
|
return p.approvableFrom.includes(status);
|
|
413
602
|
}
|
|
414
603
|
|
|
415
|
-
// src/member.ts
|
|
416
|
-
import { assertFieldCondition, resolveFieldStates } from "@odla-ai/crm";
|
|
417
|
-
|
|
418
|
-
// src/application-id.ts
|
|
419
|
-
var APPLICATION_ID_DOMAIN = "odla-ai/chapter/application/v1:";
|
|
420
|
-
async function applicationIdForSubmission(submissionId) {
|
|
421
|
-
const input = new TextEncoder().encode(`${APPLICATION_ID_DOMAIN}${submissionId}`);
|
|
422
|
-
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", input)).slice(0, 16);
|
|
423
|
-
bytes[6] = bytes[6] & 15 | 128;
|
|
424
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
425
|
-
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
426
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// src/member.ts
|
|
430
|
-
var DEFAULT_REQUIRED = ["firstName", "lastName", "email", "referral", "whoYouAre", "message"];
|
|
431
|
-
var DEFAULT_OPTIONAL = ["referralName", "linkedin", "phone", "state"];
|
|
432
|
-
function resolveApplication(a) {
|
|
433
|
-
const required = a?.required ?? DEFAULT_REQUIRED;
|
|
434
|
-
const optional = a?.optional ?? DEFAULT_OPTIONAL;
|
|
435
|
-
for (const [name, arr] of [["required", required], ["optional", optional]]) {
|
|
436
|
-
if (!Array.isArray(arr) || !arr.every((f) => typeof f === "string" && f !== "")) {
|
|
437
|
-
throw new Error(`defineChapter.application.${name}: must be an array of field-name strings`);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
if (a?.profileFields !== void 0 && (!Array.isArray(a.profileFields) || !a.profileFields.every((f) => typeof f === "string" && f !== ""))) {
|
|
441
|
-
throw new Error("defineChapter.application.profileFields: must be an array of field-name strings");
|
|
442
|
-
}
|
|
443
|
-
if (a?.crmFields !== void 0 && (!Array.isArray(a.crmFields) || !a.crmFields.every((f) => typeof f === "string" && f !== ""))) {
|
|
444
|
-
throw new Error("defineChapter.application.crmFields: must be an array of field-name strings");
|
|
445
|
-
}
|
|
446
|
-
const conditions = a?.conditions ?? {};
|
|
447
|
-
for (const [field, declared] of Object.entries(conditions)) {
|
|
448
|
-
for (const key of ["visibleWhen", "requiredWhen"]) {
|
|
449
|
-
const expression = declared?.[key];
|
|
450
|
-
if (expression === void 0) continue;
|
|
451
|
-
if (typeof expression !== "string" || !expression.trim()) {
|
|
452
|
-
throw new Error(`defineChapter.application.conditions.${field}.${key}: must be a non-empty CEL condition`);
|
|
453
|
-
}
|
|
454
|
-
assertFieldCondition(expression, `defineChapter.application.conditions.${field}.${key}`);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return {
|
|
458
|
-
required,
|
|
459
|
-
optional,
|
|
460
|
-
conditions,
|
|
461
|
-
maxLen: a?.maxLen ?? {},
|
|
462
|
-
defaultMaxLen: a?.defaultMaxLen ?? 2e3,
|
|
463
|
-
bodyCap: a?.bodyCap ?? 32768,
|
|
464
|
-
requireDisclaimerAck: a?.requireDisclaimerAck ?? true,
|
|
465
|
-
profileFields: a?.profileFields ?? [],
|
|
466
|
-
crmFields: a?.crmFields ?? [],
|
|
467
|
-
maxArrayLen: a?.maxArrayLen ?? 100,
|
|
468
|
-
validateEmail: a?.validateEmail ?? true
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
472
|
-
function isValidEmail(value) {
|
|
473
|
-
return typeof value === "string" && EMAIL_RE.test(value);
|
|
474
|
-
}
|
|
475
|
-
function clampArray(value, max) {
|
|
476
|
-
if (!Array.isArray(value)) return value;
|
|
477
|
-
return value.filter((x) => typeof x === "string" || typeof x === "number" || typeof x === "boolean").slice(0, max);
|
|
478
|
-
}
|
|
479
|
-
function hasDisclaimerAck(fields) {
|
|
480
|
-
return fields.disclaimerAck === true || fields.disclaimerAck === "true";
|
|
481
|
-
}
|
|
482
|
-
var IDENTITY_FIELDS = /* @__PURE__ */ new Set(["email", "firstName", "lastName"]);
|
|
483
|
-
function applicantProfile(chapter, fields) {
|
|
484
|
-
const app = chapter.application;
|
|
485
|
-
const allowed = (f) => app.profileFields.includes(f);
|
|
486
|
-
const profile = {};
|
|
487
|
-
for (const f of [...app.required, ...app.optional]) {
|
|
488
|
-
if (IDENTITY_FIELDS.has(f) || !allowed(f)) continue;
|
|
489
|
-
const v = fields[f];
|
|
490
|
-
if (typeof v === "string" && v.trim() !== "") profile[f] = v.trim();
|
|
491
|
-
}
|
|
492
|
-
if (fields.focus !== void 0 && allowed("focus")) profile.focus = clampArray(fields.focus, app.maxArrayLen);
|
|
493
|
-
return Object.keys(profile).length > 0 ? profile : void 0;
|
|
494
|
-
}
|
|
495
|
-
async function submitApplication(db, chapter, fields, opts) {
|
|
496
|
-
const app = chapter.application;
|
|
497
|
-
const fieldStates = resolveFieldStates(app.conditions ?? {}, fields, app.required);
|
|
498
|
-
for (const [f, state] of Object.entries(fieldStates)) {
|
|
499
|
-
if (!state.required) continue;
|
|
500
|
-
const v = fields[f];
|
|
501
|
-
if (typeof v !== "string" || v.trim() === "") return { ok: false, error: `${f} is required` };
|
|
502
|
-
}
|
|
503
|
-
for (const f of [...app.required, ...app.optional]) {
|
|
504
|
-
const v = fields[f];
|
|
505
|
-
const cap = app.maxLen[f] ?? app.defaultMaxLen;
|
|
506
|
-
if (typeof v === "string" && v.length > cap) return { ok: false, error: `${f} exceeds ${cap} characters` };
|
|
507
|
-
}
|
|
508
|
-
if (app.validateEmail && typeof fields.email === "string" && !isValidEmail(fields.email)) {
|
|
509
|
-
return { ok: false, error: "email must be a valid email address" };
|
|
510
|
-
}
|
|
511
|
-
const acked = hasDisclaimerAck(fields);
|
|
512
|
-
if (app.requireDisclaimerAck && !acked) {
|
|
513
|
-
return { ok: false, error: "disclaimerAck is required" };
|
|
514
|
-
}
|
|
515
|
-
const id2 = opts.submissionId ? await applicationIdForSubmission(opts.submissionId) : opts.newId();
|
|
516
|
-
const row = { id: id2, status: chapter.pipeline.initial, createdAt: opts.now };
|
|
517
|
-
for (const f of [...app.required, ...app.optional]) {
|
|
518
|
-
if (fieldStates[f]?.visible === false) continue;
|
|
519
|
-
if (typeof fields[f] === "string") row[f] = fields[f].trim();
|
|
520
|
-
}
|
|
521
|
-
if (fields.focus !== void 0) row.focus = clampArray(fields.focus, app.maxArrayLen);
|
|
522
|
-
if (opts.groupId) row.groupId = opts.groupId;
|
|
523
|
-
if (typeof fields.tierId === "string" && fields.tierId) {
|
|
524
|
-
if (opts.tierIds && !opts.tierIds.includes(fields.tierId)) {
|
|
525
|
-
return { ok: false, error: "tierId is not an offered tier" };
|
|
526
|
-
}
|
|
527
|
-
row.tierId = fields.tierId;
|
|
528
|
-
}
|
|
529
|
-
if (acked) row.disclaimerAckAt = opts.now;
|
|
530
|
-
const { duplicate } = await db.transact(
|
|
531
|
-
[{ t: "update", ns: "applications", id: id2, attrs: row }],
|
|
532
|
-
opts.submissionId ? { mutationId: `join:${opts.submissionId}` } : void 0
|
|
533
|
-
);
|
|
534
|
-
return { ok: true, id: id2, duplicate, status: chapter.pipeline.initial, disclaimerAckAt: acked ? opts.now : null };
|
|
535
|
-
}
|
|
536
|
-
function joinConfig(group, paymentsReady2, tiers2 = [], conditions = {}) {
|
|
537
|
-
return {
|
|
538
|
-
id: group.id,
|
|
539
|
-
name: group.name,
|
|
540
|
-
standardPriceCents: group.standardPriceCents ?? 0,
|
|
541
|
-
foundingDiscountCents: group.foundingDiscountCents ?? 0,
|
|
542
|
-
tiers: [...tiers2],
|
|
543
|
-
// The browser evaluates the same conditions the server enforces.
|
|
544
|
-
conditions,
|
|
545
|
-
disclaimerText: group.disclaimerText ?? "",
|
|
546
|
-
refundPolicyText: group.refundPolicyText ?? "",
|
|
547
|
-
trustCopy: group.trustCopy ?? "",
|
|
548
|
-
commitmentText: group.commitmentText ?? "",
|
|
549
|
-
normsText: group.normsText ?? "",
|
|
550
|
-
paymentsReady: paymentsReady2
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
604
|
// src/copy-defaults-admin.ts
|
|
555
605
|
var DEFAULT_ADMIN_COPY = {
|
|
556
606
|
auth: {
|
|
@@ -1099,7 +1149,7 @@ function defineChapter(config) {
|
|
|
1099
1149
|
const copy = resolveChapterCopy(config.copy);
|
|
1100
1150
|
const network = resolveNetwork(config, crm);
|
|
1101
1151
|
const formation = resolveLeaderFormation(config.formation, crm);
|
|
1102
|
-
const { schema, rules } = chapterDb(mode, auth, network.targets.length > 0);
|
|
1152
|
+
const { schema, rules } = chapterDb(mode, auth, network.targets.length > 0, application);
|
|
1103
1153
|
const services = config.services ?? ["db", "calendar", "o11y"];
|
|
1104
1154
|
const account = config.account ?? "none";
|
|
1105
1155
|
if (account !== "invite" && account !== "create" && account !== "none") {
|
|
@@ -2477,9 +2527,178 @@ async function loadTiers(db, group) {
|
|
|
2477
2527
|
async function loadOfferableTiers(db, group, hasSecretKey) {
|
|
2478
2528
|
return offerableTiers(await loadTiers(db, group), group, hasSecretKey);
|
|
2479
2529
|
}
|
|
2530
|
+
|
|
2531
|
+
// src/membership-page.ts
|
|
2532
|
+
var MEMBERSHIP_PAGE_RENDERER = "membership-cards-v1";
|
|
2533
|
+
var TIER_ID = /^[a-z][a-z0-9-]{0,79}$/;
|
|
2534
|
+
var VARIANTS = /* @__PURE__ */ new Set(["standard", "featured", "supporting"]);
|
|
2535
|
+
var ROOT_KEYS = /* @__PURE__ */ new Set(["schemaVersion", "renderer", "tiers", "footnoteMarkdown"]);
|
|
2536
|
+
var TIER_KEYS = /* @__PURE__ */ new Set([
|
|
2537
|
+
"tierId",
|
|
2538
|
+
"variant",
|
|
2539
|
+
"badge",
|
|
2540
|
+
"summaryMarkdown",
|
|
2541
|
+
"priceEyebrow",
|
|
2542
|
+
"compareAtPriceCents",
|
|
2543
|
+
"billingLabel",
|
|
2544
|
+
"priceNoteMarkdown",
|
|
2545
|
+
"capacity",
|
|
2546
|
+
"benefits",
|
|
2547
|
+
"callout",
|
|
2548
|
+
"ctaLabel"
|
|
2549
|
+
]);
|
|
2550
|
+
var CALLOUT_KEYS = /* @__PURE__ */ new Set(["label", "bodyMarkdown"]);
|
|
2551
|
+
var CAPACITY_KEYS = /* @__PURE__ */ new Set(["total", "label"]);
|
|
2552
|
+
var MAX_TIERS = 20;
|
|
2553
|
+
var MAX_BENEFITS = 24;
|
|
2554
|
+
var MAX_MARKDOWN = 65536;
|
|
2555
|
+
var MAX_LABEL = 160;
|
|
2556
|
+
var objectRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
2557
|
+
function rejectUnknownKeys(value, allowed, path, errors) {
|
|
2558
|
+
for (const key of Object.keys(value)) {
|
|
2559
|
+
if (!allowed.has(key)) errors.push(`${path}.${key} is not supported`);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
function boundedString(value, path, errors, max, required = false) {
|
|
2563
|
+
if (value === void 0) {
|
|
2564
|
+
if (required) errors.push(`${path} is required`);
|
|
2565
|
+
return void 0;
|
|
2566
|
+
}
|
|
2567
|
+
if (typeof value !== "string") {
|
|
2568
|
+
errors.push(`${path} must be a string`);
|
|
2569
|
+
return void 0;
|
|
2570
|
+
}
|
|
2571
|
+
const text = value.trim();
|
|
2572
|
+
if (required && !text) errors.push(`${path} is required`);
|
|
2573
|
+
if (text.length > max) errors.push(`${path} must be at most ${max.toLocaleString("en-US")} characters`);
|
|
2574
|
+
return text;
|
|
2575
|
+
}
|
|
2576
|
+
function validateMembershipPageDocument(input, options = {}) {
|
|
2577
|
+
const errors = [];
|
|
2578
|
+
const root = objectRecord(input);
|
|
2579
|
+
if (!root) return { ok: false, errors: ["document must be an object"] };
|
|
2580
|
+
rejectUnknownKeys(root, ROOT_KEYS, "document", errors);
|
|
2581
|
+
if (root.schemaVersion !== 1) errors.push("document.schemaVersion must be 1");
|
|
2582
|
+
if (root.renderer !== MEMBERSHIP_PAGE_RENDERER) {
|
|
2583
|
+
errors.push(`document.renderer must be "${MEMBERSHIP_PAGE_RENDERER}"`);
|
|
2584
|
+
}
|
|
2585
|
+
if (!Array.isArray(root.tiers)) errors.push("document.tiers must be an array");
|
|
2586
|
+
const rawTiers = Array.isArray(root.tiers) ? root.tiers : [];
|
|
2587
|
+
if (Array.isArray(root.tiers) && rawTiers.length === 0) errors.push("document.tiers must include at least one tier");
|
|
2588
|
+
if (rawTiers.length > MAX_TIERS) errors.push(`document.tiers supports at most ${MAX_TIERS} entries`);
|
|
2589
|
+
const authority = new Map((options.tiers ?? []).map((tier) => [tier.id, tier]));
|
|
2590
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2591
|
+
const tiers2 = [];
|
|
2592
|
+
for (const [index, raw] of rawTiers.slice(0, MAX_TIERS).entries()) {
|
|
2593
|
+
const path = `document.tiers[${index}]`;
|
|
2594
|
+
const item = objectRecord(raw);
|
|
2595
|
+
if (!item) {
|
|
2596
|
+
errors.push(`${path} must be an object`);
|
|
2597
|
+
continue;
|
|
2598
|
+
}
|
|
2599
|
+
rejectUnknownKeys(item, TIER_KEYS, path, errors);
|
|
2600
|
+
const tierId = boundedString(item.tierId, `${path}.tierId`, errors, 80, true) ?? "";
|
|
2601
|
+
if (tierId && !TIER_ID.test(tierId)) errors.push(`${path}.tierId must be a lowercase kebab-case id`);
|
|
2602
|
+
if (seen.has(tierId)) errors.push(`${path}.tierId duplicates "${tierId}"`);
|
|
2603
|
+
seen.add(tierId);
|
|
2604
|
+
if (authority.size && !authority.has(tierId)) errors.push(`${path}.tierId "${tierId}" is not an offered tier`);
|
|
2605
|
+
const variant = item.variant;
|
|
2606
|
+
if (variant !== void 0 && (typeof variant !== "string" || !VARIANTS.has(variant))) {
|
|
2607
|
+
errors.push(`${path}.variant must be standard, featured, or supporting`);
|
|
2608
|
+
}
|
|
2609
|
+
const compareAt = item.compareAtPriceCents;
|
|
2610
|
+
if (compareAt !== void 0 && (!Number.isInteger(compareAt) || Number(compareAt) < 0 || Number(compareAt) > 1e8)) {
|
|
2611
|
+
errors.push(`${path}.compareAtPriceCents must be an integer from 0 to 100,000,000`);
|
|
2612
|
+
}
|
|
2613
|
+
const actual = authority.get(tierId)?.priceCents;
|
|
2614
|
+
if (Number.isInteger(compareAt) && actual !== void 0 && Number(compareAt) <= actual) {
|
|
2615
|
+
errors.push(`${path}.compareAtPriceCents must be greater than the authoritative tier price`);
|
|
2616
|
+
}
|
|
2617
|
+
let benefits;
|
|
2618
|
+
if (item.benefits !== void 0) {
|
|
2619
|
+
if (!Array.isArray(item.benefits)) errors.push(`${path}.benefits must be an array`);
|
|
2620
|
+
else {
|
|
2621
|
+
if (item.benefits.length > MAX_BENEFITS) errors.push(`${path}.benefits supports at most ${MAX_BENEFITS} entries`);
|
|
2622
|
+
benefits = item.benefits.slice(0, MAX_BENEFITS).flatMap((benefit, benefitIndex) => {
|
|
2623
|
+
const text = boundedString(benefit, `${path}.benefits[${benefitIndex}]`, errors, 2e3, true);
|
|
2624
|
+
return text ? [text] : [];
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
let callout;
|
|
2629
|
+
if (item.callout !== void 0) {
|
|
2630
|
+
const rawCallout = objectRecord(item.callout);
|
|
2631
|
+
if (!rawCallout) errors.push(`${path}.callout must be an object`);
|
|
2632
|
+
else {
|
|
2633
|
+
rejectUnknownKeys(rawCallout, CALLOUT_KEYS, `${path}.callout`, errors);
|
|
2634
|
+
const bodyMarkdown = boundedString(rawCallout.bodyMarkdown, `${path}.callout.bodyMarkdown`, errors, MAX_MARKDOWN, true);
|
|
2635
|
+
const label = boundedString(rawCallout.label, `${path}.callout.label`, errors, MAX_LABEL);
|
|
2636
|
+
if (bodyMarkdown) callout = { ...label ? { label } : {}, bodyMarkdown };
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
let capacity;
|
|
2640
|
+
if (item.capacity !== void 0) {
|
|
2641
|
+
const rawCapacity = objectRecord(item.capacity);
|
|
2642
|
+
if (!rawCapacity) errors.push(`${path}.capacity must be an object`);
|
|
2643
|
+
else {
|
|
2644
|
+
rejectUnknownKeys(rawCapacity, CAPACITY_KEYS, `${path}.capacity`, errors);
|
|
2645
|
+
const total = rawCapacity.total;
|
|
2646
|
+
if (!Number.isInteger(total) || Number(total) < 1 || Number(total) > 1e6) {
|
|
2647
|
+
errors.push(`${path}.capacity.total must be an integer from 1 to 1,000,000`);
|
|
2648
|
+
}
|
|
2649
|
+
const label = boundedString(rawCapacity.label, `${path}.capacity.label`, errors, MAX_LABEL);
|
|
2650
|
+
if (Number.isInteger(total) && Number(total) >= 1 && Number(total) <= 1e6) {
|
|
2651
|
+
capacity = { total: Number(total), ...label ? { label } : {} };
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
const badge = boundedString(item.badge, `${path}.badge`, errors, MAX_LABEL);
|
|
2656
|
+
const summaryMarkdown = boundedString(item.summaryMarkdown, `${path}.summaryMarkdown`, errors, MAX_MARKDOWN);
|
|
2657
|
+
const priceEyebrow = boundedString(item.priceEyebrow, `${path}.priceEyebrow`, errors, MAX_LABEL);
|
|
2658
|
+
const billingLabel = boundedString(item.billingLabel, `${path}.billingLabel`, errors, MAX_LABEL);
|
|
2659
|
+
const priceNoteMarkdown = boundedString(item.priceNoteMarkdown, `${path}.priceNoteMarkdown`, errors, MAX_MARKDOWN);
|
|
2660
|
+
const ctaLabel = boundedString(item.ctaLabel, `${path}.ctaLabel`, errors, MAX_LABEL);
|
|
2661
|
+
tiers2.push({
|
|
2662
|
+
tierId,
|
|
2663
|
+
...typeof variant === "string" && VARIANTS.has(variant) ? { variant } : {},
|
|
2664
|
+
...badge ? { badge } : {},
|
|
2665
|
+
...summaryMarkdown ? { summaryMarkdown } : {},
|
|
2666
|
+
...priceEyebrow ? { priceEyebrow } : {},
|
|
2667
|
+
...Number.isInteger(compareAt) ? { compareAtPriceCents: Number(compareAt) } : {},
|
|
2668
|
+
...billingLabel ? { billingLabel } : {},
|
|
2669
|
+
...priceNoteMarkdown ? { priceNoteMarkdown } : {},
|
|
2670
|
+
...capacity ? { capacity } : {},
|
|
2671
|
+
...benefits ? { benefits } : {},
|
|
2672
|
+
...callout ? { callout } : {},
|
|
2673
|
+
...ctaLabel ? { ctaLabel } : {}
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
if (authority.size) {
|
|
2677
|
+
for (const tierId of authority.keys()) {
|
|
2678
|
+
if (!seen.has(tierId)) errors.push(`document.tiers is missing offered tier "${tierId}"`);
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
const footnoteMarkdown = boundedString(root.footnoteMarkdown, "document.footnoteMarkdown", errors, MAX_MARKDOWN);
|
|
2682
|
+
if (errors.length) return { ok: false, errors };
|
|
2683
|
+
return {
|
|
2684
|
+
ok: true,
|
|
2685
|
+
value: {
|
|
2686
|
+
schemaVersion: 1,
|
|
2687
|
+
renderer: MEMBERSHIP_PAGE_RENDERER,
|
|
2688
|
+
tiers: tiers2,
|
|
2689
|
+
...footnoteMarkdown ? { footnoteMarkdown } : {}
|
|
2690
|
+
}
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
function membershipPageDocument(input, options = {}) {
|
|
2694
|
+
const result = validateMembershipPageDocument(input, options);
|
|
2695
|
+
if (!result.ok) throw new TypeError(`Invalid membership page document: ${result.errors.join("; ")}`);
|
|
2696
|
+
return result.value;
|
|
2697
|
+
}
|
|
2480
2698
|
export {
|
|
2481
2699
|
DEFAULT_CHAPTER_COPY,
|
|
2482
2700
|
DEFAULT_SHARE_FIELDS,
|
|
2701
|
+
MEMBERSHIP_PAGE_RENDERER,
|
|
2483
2702
|
SCHEDULING_DEFAULTS,
|
|
2484
2703
|
applicantProfile,
|
|
2485
2704
|
applicationBookingUpdate,
|
|
@@ -2535,6 +2754,7 @@ export {
|
|
|
2535
2754
|
meetingRescheduleUpdate,
|
|
2536
2755
|
memberApplication,
|
|
2537
2756
|
memberSession,
|
|
2757
|
+
membershipPageDocument,
|
|
2538
2758
|
networkSourceTag,
|
|
2539
2759
|
normalizeSharedRecord,
|
|
2540
2760
|
normalizeWebhookEvent,
|
|
@@ -2573,6 +2793,7 @@ export {
|
|
|
2573
2793
|
tierPayable,
|
|
2574
2794
|
updateClerkUserMetadata,
|
|
2575
2795
|
updateClerkUserMetadataByEmail,
|
|
2796
|
+
validateMembershipPageDocument,
|
|
2576
2797
|
validateScheduling,
|
|
2577
2798
|
verifyStripeSignature,
|
|
2578
2799
|
webhookMutationId
|