@simplelayer/graniteer-core 0.2.3 → 0.3.1

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 (36) hide show
  1. package/dist/agreementPortalEmail.js +10 -10
  2. package/dist/billingPortalLinkEmail.js +8 -8
  3. package/dist/bookingAgreementEmail.js +3 -3
  4. package/dist/checkoutSessionParams.d.ts +13 -0
  5. package/dist/checkoutSessionParams.js +38 -2
  6. package/dist/commonsDeposit.js +3 -3
  7. package/dist/dayPassConfirmation.js +7 -7
  8. package/dist/dunningEmails.js +5 -5
  9. package/dist/entitlements.d.ts +17 -0
  10. package/dist/entitlements.js +33 -0
  11. package/dist/functions/admin-cancel-membership.d.ts +3 -1
  12. package/dist/functions/admin-cancel-membership.js +9 -1
  13. package/dist/functions/admin-change-membership-plan.d.ts +3 -1
  14. package/dist/functions/admin-change-membership-plan.js +9 -1
  15. package/dist/functions/admin-create-booking.js +38 -8
  16. package/dist/functions/admin-onboard-connect-account.d.ts +47 -0
  17. package/dist/functions/admin-onboard-connect-account.js +197 -0
  18. package/dist/functions/admin-revoke-agreement.js +4 -4
  19. package/dist/functions/admin-undo-membership-cancel.d.ts +3 -1
  20. package/dist/functions/admin-undo-membership-cancel.js +9 -1
  21. package/dist/functions/create-day-pass-checkout.d.ts +2 -0
  22. package/dist/functions/create-day-pass-checkout.js +30 -1
  23. package/dist/functions/create-subscription-checkout.d.ts +3 -0
  24. package/dist/functions/create-subscription-checkout.js +11 -0
  25. package/dist/functions/stripe-db-reconcile.d.ts +4 -0
  26. package/dist/functions/stripe-db-reconcile.js +15 -3
  27. package/dist/functions/stripe-webhook.js +14 -0
  28. package/dist/functions/voice-membership-signup.d.ts +1 -0
  29. package/dist/functions/voice-membership-signup.js +4 -0
  30. package/dist/mailArrivalEmail.js +6 -6
  31. package/dist/membershipWelcome.js +26 -26
  32. package/dist/paymentLinkEmail.js +9 -9
  33. package/dist/printBilling.js +47 -47
  34. package/dist/signedUnpaidReminderEmail.js +9 -9
  35. package/dist/supportTicketEmail.js +7 -7
  36. package/package.json +9 -1
@@ -45,22 +45,22 @@ export function gcCodeOf(e) {
45
45
  * minimum is applied on this side. v14 also had a per-period `>= 50` inside
46
46
  * M-11's claim UPDATE; that predicate is DELETED, because it silently billed
47
47
  * a member who owed $9.30 nothing at all, every month (T-85). */
48
- export const ELIGIBILITY_SQL = `
49
- select p.membership_id,
50
- array_agg(p.id order by p.period_month) as period_ids,
51
- array_agg(distinct p.period_month) as period_months,
52
- sum(p.charge_cents_total)::integer as amount_cents
53
- from public.print_usage_periods p
54
- where p.status = 'pending_bill'
55
- and p.billing_run_id is null
56
- and p.billed_run_id is null
57
- and p.charge_cents_total > 0
58
- group by p.membership_id
59
- having sum(p.charge_cents_total) >= ${STRIPE_MIN_CENTS}
60
- and not exists (
61
- select 1 from public.print_billing_runs r
62
- where r.membership_id = p.membership_id
63
- and r.completed_at is null
48
+ export const ELIGIBILITY_SQL = `
49
+ select p.membership_id,
50
+ array_agg(p.id order by p.period_month) as period_ids,
51
+ array_agg(distinct p.period_month) as period_months,
52
+ sum(p.charge_cents_total)::integer as amount_cents
53
+ from public.print_usage_periods p
54
+ where p.status = 'pending_bill'
55
+ and p.billing_run_id is null
56
+ and p.billed_run_id is null
57
+ and p.charge_cents_total > 0
58
+ group by p.membership_id
59
+ having sum(p.charge_cents_total) >= ${STRIPE_MIN_CENTS}
60
+ and not exists (
61
+ select 1 from public.print_billing_runs r
62
+ where r.membership_id = p.membership_id
63
+ and r.completed_at is null
64
64
  )`;
65
65
  /** [v18/B12-1] The baseline query. The ORDER BY and LIMIT MUST live in a
66
66
  * subquery: v6..v17 printed an ungrouped avg() with a bare ORDER BY, which
@@ -69,41 +69,41 @@ having sum(p.charge_cents_total) >= ${STRIPE_MIN_CENTS}
69
69
  * a 25x baseline error on the v18 fixture (T-46b). Returns BOTH operands rule 2
70
70
  * needs; the old form returned no count at all, so the rule was unimplementable
71
71
  * from its own stated input. */
72
- export const BASELINE_SQL = `
73
- select coalesce(avg(b.billed_amount_cents), 0)::numeric as baseline_cents,
74
- count(*)::integer as qualifying_periods
75
- from (
76
- select p.billed_amount_cents, p.period_month
77
- from public.print_usage_periods p
78
- where p.membership_id = $1
79
- and p.status = 'billed'
80
- and p.billed_amount_cents > 0
81
- order by p.period_month desc
82
- limit ${BASELINE_WINDOW}
72
+ export const BASELINE_SQL = `
73
+ select coalesce(avg(b.billed_amount_cents), 0)::numeric as baseline_cents,
74
+ count(*)::integer as qualifying_periods
75
+ from (
76
+ select p.billed_amount_cents, p.period_month
77
+ from public.print_usage_periods p
78
+ where p.membership_id = $1
79
+ and p.status = 'billed'
80
+ and p.billed_amount_cents > 0
81
+ order by p.period_month desc
82
+ limit ${BASELINE_WINDOW}
83
83
  ) b`;
84
84
  /** section 5.3's escalation ladder. A held run gets louder rather than expiring —
85
85
  * an automatic expiry that frees the periods is exactly what created the
86
86
  * double-charge hole in R7 F4 / R8 F2. */
87
- export const STUCK_ESCALATION_SQL = `
88
- insert into public.ops_events (kind, severity, detail, dedupe_key)
89
- select
90
- 'print_billing_run_stuck',
91
- case
92
- when r.updated_at < now() - interval '7 days' then 'critical'
93
- when r.updated_at < now() - interval '24 hours' then 'error'
94
- else 'warning'
95
- end,
96
- jsonb_build_object(
97
- 'run_id', r.id, 'membership_id', r.membership_id, 'status', r.status,
98
- 'hold_reason', r.hold_reason, 'amount_cents', r.amount_cents,
99
- 'stripe_invoice_id', r.stripe_invoice_id,
100
- 'stuck_for', now() - r.updated_at,
101
- 'blocking_future_runs_for_membership', true),
102
- 'print_billing_run_stuck:' || r.id::text || ':'
103
- || (now() at time zone 'UTC')::date::text
104
- from public.print_billing_runs r
105
- where r.completed_at is null
106
- and r.status = 'held'
87
+ export const STUCK_ESCALATION_SQL = `
88
+ insert into public.ops_events (kind, severity, detail, dedupe_key)
89
+ select
90
+ 'print_billing_run_stuck',
91
+ case
92
+ when r.updated_at < now() - interval '7 days' then 'critical'
93
+ when r.updated_at < now() - interval '24 hours' then 'error'
94
+ else 'warning'
95
+ end,
96
+ jsonb_build_object(
97
+ 'run_id', r.id, 'membership_id', r.membership_id, 'status', r.status,
98
+ 'hold_reason', r.hold_reason, 'amount_cents', r.amount_cents,
99
+ 'stripe_invoice_id', r.stripe_invoice_id,
100
+ 'stuck_for', now() - r.updated_at,
101
+ 'blocking_future_runs_for_membership', true),
102
+ 'print_billing_run_stuck:' || r.id::text || ':'
103
+ || (now() at time zone 'UTC')::date::text
104
+ from public.print_billing_runs r
105
+ where r.completed_at is null
106
+ and r.status = 'held'
107
107
  on conflict (dedupe_key) where dedupe_key is not null do nothing`;
108
108
  /** Rules 1-3 of section 4.2's gate. The two gates are INDEPENDENT and both are
109
109
  * evaluated — a run can trip the cap without the ratio and vice versa, and
@@ -78,15 +78,15 @@ export async function sendSignedUnpaidReminderEmail(supabase, { email, name, por
78
78
  const office = (officeNumber || '').trim();
79
79
  const officeClause = office ? ` for office ${esc(office)}` : '';
80
80
  const subject = `Almost there — your ${operator.shortName} agreement is signed, just the retainer left`;
81
- const html = `<div style="background:#F6F6F6;padding:24px 0;margin:0"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;background:#F6F6F6"><tr><td align="center" style="padding:0 12px"><table role="presentation" width="560" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;max-width:560px;width:100%;background:#FFFFFF;border-radius:10px"><tr><td style="padding:24px">
82
- <h2 style="margin:0 0 12px 0;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:22px">Your signature is in — one step left</h2>
83
- ${p(`Hi ${esc(greetingName)},`)}
84
- ${p(`Thanks for signing your ${operator.name} private office agreement${officeClause}. We just need your service retainer to finish setting things up.`)}
85
- ${p('<strong>Review your terms and pay your retainer</strong> in your secure agreement portal:')}
86
- ${p(`<a href="${esc(portalUrl)}" style="color:#C98A5E">Review and pay your retainer →</a>`)}
87
- ${p('Your monthly billing starts only after the retainer is paid, so nothing happens until you complete this step. This portal link is unique to your agreement, so please don\'t forward it.')}
88
- ${p(`Questions in the meantime? Just reply to this email or reach us at <a href="mailto:${operator.supportEmail}" style="color:#C98A5E">${operator.supportEmail}</a>.`)}
89
- ${p(`Thanks,<br />The ${operator.name} team`)}
81
+ const html = `<div style="background:#F6F6F6;padding:24px 0;margin:0"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;background:#F6F6F6"><tr><td align="center" style="padding:0 12px"><table role="presentation" width="560" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;max-width:560px;width:100%;background:#FFFFFF;border-radius:10px"><tr><td style="padding:24px">
82
+ <h2 style="margin:0 0 12px 0;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:22px">Your signature is in — one step left</h2>
83
+ ${p(`Hi ${esc(greetingName)},`)}
84
+ ${p(`Thanks for signing your ${operator.name} private office agreement${officeClause}. We just need your service retainer to finish setting things up.`)}
85
+ ${p('<strong>Review your terms and pay your retainer</strong> in your secure agreement portal:')}
86
+ ${p(`<a href="${esc(portalUrl)}" style="color:#C98A5E">Review and pay your retainer →</a>`)}
87
+ ${p('Your monthly billing starts only after the retainer is paid, so nothing happens until you complete this step. This portal link is unique to your agreement, so please don\'t forward it.')}
88
+ ${p(`Questions in the meantime? Just reply to this email or reach us at <a href="mailto:${operator.supportEmail}" style="color:#C98A5E">${operator.supportEmail}</a>.`)}
89
+ ${p(`Thanks,<br />The ${operator.name} team`)}
90
90
  </td></tr></table></td></tr></table></div>`;
91
91
  const emailRes = await fetch(`${GHL_BASE}/conversations/messages`, {
92
92
  method: 'POST', headers,
@@ -64,13 +64,13 @@ export async function sendSupportTicketEmail(supabase, { ticketId, submitterName
64
64
  if (!contactId)
65
65
  throw new Error('ghl_upsert_no_contact_id');
66
66
  const p = (t) => `<p style="margin:0 0 8px 0;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:22px">${t}</p>`;
67
- const html = `<div style="background:#F6F6F6;padding:24px 0;margin:0"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;background:#F6F6F6"><tr><td align="center" style="padding:0 12px"><table role="presentation" width="560" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;max-width:560px;width:100%;background:#FFFFFF;border-radius:10px"><tr><td style="padding:24px">
68
- <h2 style="margin:0 0 12px 0;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:22px">New support ticket — ${esc(operator.name)}</h2>
69
- ${p(`<strong>From:</strong> ${esc(submitterName)} &lt;${esc(submitterEmail)}&gt;`)}
70
- ${p(`<strong>Subject:</strong> ${esc(subject)}`)}
71
- ${p(`<strong>Ticket:</strong> ${esc(ticketId)}`)}
72
- <div style="margin:12px 0;padding:12px;background:#F6F6F6;border-radius:6px;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:22px;white-space:pre-wrap">${esc(message)}</div>
73
- ${p(`Manage this ticket at <a href="https://${esc(operator.domain)}/admin/support-tickets/" style="color:#C98A5E">/admin/support-tickets/</a>.`)}
67
+ const html = `<div style="background:#F6F6F6;padding:24px 0;margin:0"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;background:#F6F6F6"><tr><td align="center" style="padding:0 12px"><table role="presentation" width="560" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;max-width:560px;width:100%;background:#FFFFFF;border-radius:10px"><tr><td style="padding:24px">
68
+ <h2 style="margin:0 0 12px 0;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:22px">New support ticket — ${esc(operator.name)}</h2>
69
+ ${p(`<strong>From:</strong> ${esc(submitterName)} &lt;${esc(submitterEmail)}&gt;`)}
70
+ ${p(`<strong>Subject:</strong> ${esc(subject)}`)}
71
+ ${p(`<strong>Ticket:</strong> ${esc(ticketId)}`)}
72
+ <div style="margin:12px 0;padding:12px;background:#F6F6F6;border-radius:6px;color:#22263B;font-family:Inter,Arial,sans-serif;font-size:14px;line-height:22px;white-space:pre-wrap">${esc(message)}</div>
73
+ ${p(`Manage this ticket at <a href="https://${esc(operator.domain)}/admin/support-tickets/" style="color:#C98A5E">/admin/support-tickets/</a>.`)}
74
74
  </td></tr></table></td></tr></table></div>`;
75
75
  const emailRes = await fetch(`${GHL_BASE}/conversations/messages`, {
76
76
  method: 'POST', headers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -117,6 +117,10 @@
117
117
  "types": "./dist/conductorAdmin.d.ts",
118
118
  "default": "./dist/conductorAdmin.js"
119
119
  },
120
+ "./entitlements": {
121
+ "types": "./dist/entitlements.d.ts",
122
+ "default": "./dist/entitlements.js"
123
+ },
120
124
  "./email-change": {
121
125
  "types": "./dist/email-templates/email-change.d.ts",
122
126
  "default": "./dist/email-templates/email-change.js"
@@ -317,6 +321,10 @@
317
321
  "types": "./dist/functions/admin-mint-portal-link.d.ts",
318
322
  "default": "./dist/functions/admin-mint-portal-link.js"
319
323
  },
324
+ "./functions/admin-onboard-connect-account": {
325
+ "types": "./dist/functions/admin-onboard-connect-account.d.ts",
326
+ "default": "./dist/functions/admin-onboard-connect-account.js"
327
+ },
320
328
  "./functions/admin-photo-upload": {
321
329
  "types": "./dist/functions/admin-photo-upload.d.ts",
322
330
  "default": "./dist/functions/admin-photo-upload.js"