@aglyn/aglyn 1.0.0-beta.270 → 1.0.0-beta.272

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 (90) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/account-preferences.d.ts +50 -0
  3. package/src/lib/app-utils/account-preferences.js +96 -0
  4. package/src/lib/app-utils/account-preferences.js.map +1 -1
  5. package/src/lib/app-utils/activity-labels.js +2 -0
  6. package/src/lib/app-utils/activity-labels.js.map +1 -1
  7. package/src/lib/app-utils/analytics-events.d.ts +16 -2
  8. package/src/lib/app-utils/analytics-events.js +2 -0
  9. package/src/lib/app-utils/analytics-events.js.map +1 -1
  10. package/src/lib/app-utils/append-only-history.d.ts +94 -0
  11. package/src/lib/app-utils/append-only-history.js +73 -0
  12. package/src/lib/app-utils/append-only-history.js.map +1 -0
  13. package/src/lib/app-utils/bundle-intent.d.ts +186 -0
  14. package/src/lib/app-utils/bundle-intent.js +386 -0
  15. package/src/lib/app-utils/bundle-intent.js.map +1 -0
  16. package/src/lib/app-utils/client-build.d.ts +207 -0
  17. package/src/lib/app-utils/client-build.js +237 -0
  18. package/src/lib/app-utils/client-build.js.map +1 -0
  19. package/src/lib/app-utils/console-routes.d.ts +4 -0
  20. package/src/lib/app-utils/console-routes.js +2 -0
  21. package/src/lib/app-utils/console-routes.js.map +1 -1
  22. package/src/lib/app-utils/docs-help-sections.generated.js +13 -6
  23. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  24. package/src/lib/app-utils/docs-help.generated.d.ts +11 -5
  25. package/src/lib/app-utils/docs-help.generated.js +31 -2
  26. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  27. package/src/lib/app-utils/docs-index.generated.js +105 -35
  28. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  29. package/src/lib/app-utils/margin-utilization.js +6 -4
  30. package/src/lib/app-utils/margin-utilization.js.map +1 -1
  31. package/src/lib/app-utils/media-filter.d.ts +26 -0
  32. package/src/lib/app-utils/media-filter.js +32 -0
  33. package/src/lib/app-utils/media-filter.js.map +1 -1
  34. package/src/lib/app-utils/onboarding-deep-link.d.ts +36 -2
  35. package/src/lib/app-utils/onboarding-deep-link.js +48 -5
  36. package/src/lib/app-utils/onboarding-deep-link.js.map +1 -1
  37. package/src/lib/app-utils/operator-alerts.js +21 -0
  38. package/src/lib/app-utils/operator-alerts.js.map +1 -1
  39. package/src/lib/app-utils/owner-approval-record.d.ts +102 -0
  40. package/src/lib/app-utils/owner-approval-record.js +148 -0
  41. package/src/lib/app-utils/owner-approval-record.js.map +1 -0
  42. package/src/lib/app-utils/plan-card-meters.d.ts +96 -0
  43. package/src/lib/app-utils/plan-card-meters.js +197 -0
  44. package/src/lib/app-utils/plan-card-meters.js.map +1 -0
  45. package/src/lib/app-utils/plan-entitlements.d.ts +183 -67
  46. package/src/lib/app-utils/plan-entitlements.js +213 -58
  47. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  48. package/src/lib/app-utils/release-flags.d.ts +1 -1
  49. package/src/lib/app-utils/release-flags.js +22 -0
  50. package/src/lib/app-utils/release-flags.js.map +1 -1
  51. package/src/lib/app-utils/server.d.ts +4 -0
  52. package/src/lib/app-utils/server.js +7 -0
  53. package/src/lib/app-utils/server.js.map +1 -1
  54. package/src/lib/app-utils/site-care-project.d.ts +227 -0
  55. package/src/lib/app-utils/site-care-project.js +423 -0
  56. package/src/lib/app-utils/site-care-project.js.map +1 -0
  57. package/src/lib/app-utils/site-care.d.ts +291 -0
  58. package/src/lib/app-utils/site-care.js +310 -0
  59. package/src/lib/app-utils/site-care.js.map +1 -0
  60. package/src/lib/app-utils/upgrade-proposal.d.ts +29 -4
  61. package/src/lib/app-utils/upgrade-proposal.js +60 -9
  62. package/src/lib/app-utils/upgrade-proposal.js.map +1 -1
  63. package/src/lib/foundation/definitions/org-billing.types.d.ts +40 -10
  64. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  65. package/src/lib/foundation/definitions/organization.types.d.ts +3 -1
  66. package/src/lib/foundation/definitions/organization.types.js.map +1 -1
  67. package/src/lib/foundation/definitions/platform.types.d.ts +20 -0
  68. package/src/lib/foundation/definitions/platform.types.js.map +1 -1
  69. package/src/lib/foundation/index.d.ts +1 -1
  70. package/src/lib/foundation/index.js.map +1 -1
  71. package/src/lib/plugin-manager/feature-plugins.d.ts +48 -0
  72. package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
  73. package/src/lib/plugin-manager/first-party-plugins.generated.js +16 -0
  74. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  75. package/src/lib/plugin-manager/plugin-ai-capabilities.d.ts +19 -0
  76. package/src/lib/plugin-manager/plugin-ai-capabilities.js.map +1 -1
  77. package/src/lib/plugin-manager/plugin-domain-search.d.ts +81 -0
  78. package/src/lib/plugin-manager/plugin-domain-search.js +63 -0
  79. package/src/lib/plugin-manager/plugin-domain-search.js.map +1 -0
  80. package/src/lib/plugin-manager/plugin-entitlements.d.ts +23 -5
  81. package/src/lib/plugin-manager/plugin-entitlements.js +10 -0
  82. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  83. package/src/lib/plugin-manager/plugin-media-ingest.d.ts +18 -1
  84. package/src/lib/plugin-manager/plugin-media-ingest.js.map +1 -1
  85. package/src/lib/plugin-manager/plugin-site-resources.d.ts +74 -0
  86. package/src/lib/plugin-manager/plugin-site-resources.js +135 -0
  87. package/src/lib/plugin-manager/plugin-site-resources.js.map +1 -0
  88. package/src/lib/plugin-manager/purchase-gate-preclearance.d.ts +61 -0
  89. package/src/lib/plugin-manager/purchase-gate-preclearance.js +102 -0
  90. package/src/lib/plugin-manager/purchase-gate-preclearance.js.map +1 -0
@@ -0,0 +1,291 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { type OwnerApprovalRecord } from './owner-approval-record';
18
+ /**
19
+ * SITE CARE REQUESTS: THE ARITHMETIC (AGL-3959).
20
+ *
21
+ * A Site Care owner asks for a change by email or from the console, and the
22
+ * request is a support ticket tagged `siteCare`. Staff open it (a timer
23
+ * starts), make the change, and close it with one number: the minutes. This
24
+ * module is everything about that which needs no Firestore and no Stripe —
25
+ * the month a request counts in, how its minutes are counted against the
26
+ * included hour, what the close allows, what extra time bills, and the
27
+ * statement the month adds up to. The routes, the staff panel, the owner's
28
+ * Billing card and the reconciliation all read it, so they cannot disagree.
29
+ *
30
+ * ## The rules, from the Decision Log of 2026-10-19
31
+ *
32
+ * - The included hour is `SITE_CARE_INCLUDED_MINUTES` a month, no rollover,
33
+ * plus any goodwill minutes staff add to that month. Each request counts
34
+ * against it in `SITE_CARE_INCLUDED_BLOCK_MINUTES` blocks, rounded UP.
35
+ * - A request's share of the hour is fixed when it closes, against what the
36
+ * month's earlier requests left. Correcting one request's minutes later
37
+ * recomputes that request alone, against the same remainder, so a fix
38
+ * never moves a charge on a request nobody touched.
39
+ * - Past the hour, extra time bills at `SITE_CARE_EXTRA_HOUR_USD` per
40
+ * STARTED hour — whole hours, rounded up — and never less than the hours
41
+ * the owner approved. With no approval on file, or more time than was
42
+ * approved, the close is blocked: ask the owner first, or absorb it (no
43
+ * charge, the minutes still count).
44
+ */
45
+ /** The `kind` a Site Care support ticket carries. */
46
+ export declare const SITE_CARE_TICKET_KIND = "siteCare";
47
+ /** Site Care's promise: done within two business days. */
48
+ export declare const SITE_CARE_RESPONSE_BUSINESS_DAYS = 2;
49
+ /** The zone a Site Care month is drawn in: where the work is done. */
50
+ export declare const SITE_CARE_TIME_ZONE = "America/Chicago";
51
+ /** The close's minutes are rounded up to this step. */
52
+ export declare const SITE_CARE_CLOSE_STEP_MINUTES = 5;
53
+ /** The most minutes one request may log. */
54
+ export declare const SITE_CARE_MAX_REQUEST_MINUTES: number;
55
+ /**
56
+ * The tax code the extra-time item is billed under: the code every Aglyn
57
+ * product carries (the Decision Log of 2026-10-18), read off the Site Care
58
+ * product, which is checked to carry it before anything is charged.
59
+ */
60
+ export declare const SITE_CARE_EXTRA_TIME_TAX_CODE = "txcd_10103001";
61
+ /**
62
+ * WHERE A CHANGE IS EMAILED (AGL-3997): the support address. Site Care has no
63
+ * address of its own. An owner writes to the support address they already
64
+ * know, and a message to it from a member of a workspace with Site Care files
65
+ * itself as a request; every other message is ordinary support mail. The
66
+ * support mailbox also delivers each message to `support@<inbound mail
67
+ * domain>`, where the mail provider announces it, and every Site Care email
68
+ * replies to `support+<requestId>@<inbound mail domain>`, so an answer joins
69
+ * its own request.
70
+ */
71
+ export declare const SITE_CARE_INBOUND_LOCAL_PART = "support";
72
+ /**
73
+ * The operator's support address, from the operator identity: what an owner
74
+ * is told to email a change to, and what the intake reads as one. `null` on
75
+ * a deployment that publishes no support address, where Request a change on
76
+ * a site's dashboard is the only way in.
77
+ */
78
+ export declare function siteCareSupportAddress(): string | null;
79
+ /**
80
+ * The Reply-To of a Site Care email: `support+<requestId>@<domain>` for an
81
+ * email about one request, so the answer joins it; the support address for
82
+ * one about no single request (a statement, a project), so the answer reaches
83
+ * the support inbox like any other message to it.
84
+ */
85
+ export declare function siteCareReplyAddress(requestId: string | null, domain: string, supportEmail?: string | null): string;
86
+ /** The longest title and message a request keeps. */
87
+ export declare const SITE_CARE_SUBJECT_MAX = 150;
88
+ export declare const SITE_CARE_BODY_MAX = 5000;
89
+ /** Stripe's limit on an invoice item's description is generous; ours is not. */
90
+ export declare const SITE_CARE_LINE_DESCRIPTION_MAX = 480;
91
+ /** Where a request came from. */
92
+ export type SiteCareSource = 'email' | 'console';
93
+ /**
94
+ * Where an extra-time charge stands, as the platform recorded it.
95
+ *
96
+ * `creating` is written BEFORE the Stripe call and `pending` after it, so a
97
+ * call that succeeded with no row behind it shows as `creating` with no item
98
+ * id — which the reconciliation reports. Whether a `pending` item has been
99
+ * invoiced yet is read from Stripe when it matters, never assumed.
100
+ */
101
+ export type SiteCareChargeStatus = 'creating' | 'pending' | 'failed' | 'voided' | 'credited' | 'refunded';
102
+ /** Charges that still bill, or are about to. */
103
+ export declare const SITE_CARE_LIVE_CHARGE_STATUSES: readonly SiteCareChargeStatus[];
104
+ export interface SiteCareCharge {
105
+ status: SiteCareChargeStatus;
106
+ /** Whole hours billed. */
107
+ hours: number;
108
+ /** `hours × rate`, in cents, before tax. */
109
+ amountCents: number;
110
+ /** The invoice line description, exactly as it was sent. */
111
+ description: string;
112
+ /** The key the create was sent under, so a retry makes nothing twice. */
113
+ idempotencyKey: string;
114
+ invoiceItemId: string | null;
115
+ /** The invoice the item landed on, once read. */
116
+ invoiceId: string | null;
117
+ creditNoteId: string | null;
118
+ refundId: string | null;
119
+ /** What Stripe said, when a call failed. */
120
+ error: string | null;
121
+ updatedAtMs: number;
122
+ }
123
+ /** The site publish that shipped the change, from the site's activity log. */
124
+ export interface SiteCarePublishLink {
125
+ hostId: string;
126
+ activityId: string;
127
+ action: string;
128
+ targetName: string | null;
129
+ targetId: string | null;
130
+ atMs: number;
131
+ }
132
+ /** The `siteCare` map on a Site Care ticket. */
133
+ export interface SiteCareRequest {
134
+ source: SiteCareSource;
135
+ hostId: string | null;
136
+ requesterEmail: string | null;
137
+ state: 'open' | 'closed';
138
+ /** The month the request counts in: opened, until it closes; then closed. */
139
+ month: string;
140
+ timerStartedAtMs: number | null;
141
+ timerStartedByUid: string | null;
142
+ closedAtMs: number | null;
143
+ /** The one number staff entered at close, or the latest correction of it. */
144
+ minutesLogged: number | null;
145
+ /** The timer's own minutes at close, unrounded, for the record. */
146
+ timerMinutes: number | null;
147
+ countedMinutes: number;
148
+ includedMinutesUsed: number;
149
+ overMinutes: number;
150
+ billedHours: number;
151
+ absorbed: boolean;
152
+ approval: OwnerApprovalRecord | null;
153
+ charge: SiteCareCharge | null;
154
+ /** How many charges this request has ever started; keys each one. */
155
+ chargeSeq: number;
156
+ publish: SiteCarePublishLink | null;
157
+ }
158
+ /** Whether a value is a `YYYY-MM` month key. */
159
+ export declare function isSiteCareMonthKey(value: unknown): value is string;
160
+ /** The month an instant falls in, in Site Care's zone: `2026-10`. */
161
+ export declare function siteCareMonthKey(ms: number): string;
162
+ /** The month before a month key. */
163
+ export declare function previousSiteCareMonthKey(key: string): string;
164
+ /** "October 2026". */
165
+ export declare function siteCareMonthLabel(key: string): string;
166
+ /** The document id of an org's month: `{orgId}_{YYYY-MM}`, and the ticket field. */
167
+ export declare function siteCareOrgMonth(orgId: string, month: string): string;
168
+ /** "45 min", "1 h", "1 h 15 min". */
169
+ export declare function formatSiteCareMinutes(minutes: number): string;
170
+ /** "$79", "$158.00" → always whole-dollar style when whole. */
171
+ export declare function formatSiteCareUsd(cents: number): string;
172
+ /**
173
+ * The close's number from the timer: elapsed minutes rounded UP to the next
174
+ * five, and never less than five — a request somebody opened and closed was
175
+ * still a request worked.
176
+ */
177
+ export declare function closeMinutesFromTimer(startedAtMs: number | null, nowMs: number): number;
178
+ /** Staff's number read back, or null when it is not a usable count of minutes. */
179
+ export declare function readSiteCareMinutes(value: unknown): number | null;
180
+ /** Minutes as they count against the included hour: whole blocks, rounded up. */
181
+ export declare function countedSiteCareMinutes(minutes: number): number;
182
+ /** The month's included minutes: the hour plus goodwill. */
183
+ export declare function siteCareIncludedPool(goodwillMinutes: number): number;
184
+ export interface SiteCareAllocation {
185
+ countedMinutes: number;
186
+ includedMinutesUsed: number;
187
+ overMinutes: number;
188
+ /** Whole hours the over-time needs, rounded up; 0 when within the hour. */
189
+ requiredHours: number;
190
+ /** Included minutes the month had left before this request. */
191
+ remainingBefore: number;
192
+ }
193
+ /**
194
+ * One request's minutes against what the month's OTHER closed requests left
195
+ * of the included pool.
196
+ */
197
+ export declare function allocateSiteCareMinutes(input: {
198
+ minutes: number;
199
+ otherIncludedUsed: number;
200
+ goodwillMinutes: number;
201
+ }): SiteCareAllocation;
202
+ export type SiteCareCloseVerdict = {
203
+ ok: true;
204
+ billedHours: number;
205
+ absorbed: boolean;
206
+ } | {
207
+ ok: false;
208
+ /** No approval on file, or one for fewer hours than the work took. */
209
+ reason: 'no-approval' | 'approval-exceeded';
210
+ requiredHours: number;
211
+ approvedHours: number | null;
212
+ };
213
+ /**
214
+ * What a close (or a correction) may do with a request's extra time.
215
+ *
216
+ * Within the hour nothing bills. Past it, `absorb` closes with no charge;
217
+ * otherwise an approval must cover the whole hours needed, and the bill is
218
+ * the larger of those and the approved hours — the approved amount is the
219
+ * floor. Nothing bills without the owner's recorded yes.
220
+ */
221
+ export declare function siteCareCloseVerdict(input: {
222
+ requiredHours: number;
223
+ approval: Pick<OwnerApprovalRecord, 'hours'> | null;
224
+ absorb: boolean;
225
+ }): SiteCareCloseVerdict;
226
+ /** Extra time in cents, before tax. */
227
+ export declare function siteCareExtraTimeCents(hours: number): number;
228
+ /** One request as the month's statement counts it. */
229
+ export interface SiteCareStatementRequest {
230
+ requestId: string;
231
+ title: string;
232
+ state: 'open' | 'closed';
233
+ closedAtMs: number | null;
234
+ minutesLogged: number | null;
235
+ countedMinutes: number;
236
+ includedMinutesUsed: number;
237
+ overMinutes: number;
238
+ billedHours: number;
239
+ absorbed: boolean;
240
+ chargeStatus: SiteCareChargeStatus | null;
241
+ chargeCents: number;
242
+ }
243
+ export interface SiteCareMonthStatement {
244
+ month: string;
245
+ monthLabel: string;
246
+ includedMinutes: number;
247
+ goodwillMinutes: number;
248
+ poolMinutes: number;
249
+ requests: number;
250
+ openRequests: number;
251
+ minutesLogged: number;
252
+ countedMinutes: number;
253
+ includedMinutesUsed: number;
254
+ minutesLeft: number;
255
+ /** Hours on charges that still bill. */
256
+ extraHoursBilled: number;
257
+ extraBilledCents: number;
258
+ /** Cents voided, credited or refunded. */
259
+ extraReversedCents: number;
260
+ }
261
+ /** A request's facts as the statement reads them, from the stored map. */
262
+ export declare function siteCareStatementRequest(requestId: string, title: string, request: Partial<SiteCareRequest> | null | undefined): SiteCareStatementRequest;
263
+ /** The month, summed. */
264
+ export declare function siteCareMonthStatement(input: {
265
+ month: string;
266
+ requests: readonly SiteCareStatementRequest[];
267
+ goodwillMinutes: number;
268
+ }): SiteCareMonthStatement;
269
+ /** The month's totals in one line, as the statement and the invoice line say them. */
270
+ export declare function siteCareMonthSentence(statement: SiteCareMonthStatement): string;
271
+ /**
272
+ * The extra-time invoice line's description: the request, its minutes, the
273
+ * hours billed and why, and the month's statement — what the owner reads on
274
+ * the invoice, and what the reconciliation compares Stripe's copy against.
275
+ */
276
+ export declare function siteCareExtraTimeDescription(input: {
277
+ title: string;
278
+ minutesLogged: number;
279
+ overMinutes: number;
280
+ billedHours: number;
281
+ approvedHours: number | null;
282
+ statement: SiteCareMonthStatement;
283
+ }): string;
284
+ /** A charge's standing in the owner's words. */
285
+ export declare function siteCareChargeWords(status: SiteCareChargeStatus | null): string;
286
+ /** Whether a site activity row is a publish a request can be linked to. */
287
+ export declare function isSiteCarePublishAction(action: unknown): boolean;
288
+ /** A publish link as a sentence: "Published “Home” on Oct 19, 2026, 3:04 PM". */
289
+ export declare function siteCarePublishSentence(publish: SiteCarePublishLink | null, formatDate: (ms: number) => string): string | null;
290
+ /** A date as the owner's emails and statement write it, in Site Care's zone. */
291
+ export declare function formatSiteCareDate(ms: number): string;
@@ -0,0 +1,310 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { SITE_CARE_EXTRA_HOUR_USD, SITE_CARE_INCLUDED_BLOCK_MINUTES, SITE_CARE_INCLUDED_MINUTES } from "./plan-entitlements.js";
17
+ import { operatorIdentity } from "./operator-identity.js";
18
+ import { describeHours } from "./owner-approval-record.js";
19
+ /**
20
+ * SITE CARE REQUESTS: THE ARITHMETIC (AGL-3959).
21
+ *
22
+ * A Site Care owner asks for a change by email or from the console, and the
23
+ * request is a support ticket tagged `siteCare`. Staff open it (a timer
24
+ * starts), make the change, and close it with one number: the minutes. This
25
+ * module is everything about that which needs no Firestore and no Stripe —
26
+ * the month a request counts in, how its minutes are counted against the
27
+ * included hour, what the close allows, what extra time bills, and the
28
+ * statement the month adds up to. The routes, the staff panel, the owner's
29
+ * Billing card and the reconciliation all read it, so they cannot disagree.
30
+ *
31
+ * ## The rules, from the Decision Log of 2026-10-19
32
+ *
33
+ * - The included hour is `SITE_CARE_INCLUDED_MINUTES` a month, no rollover,
34
+ * plus any goodwill minutes staff add to that month. Each request counts
35
+ * against it in `SITE_CARE_INCLUDED_BLOCK_MINUTES` blocks, rounded UP.
36
+ * - A request's share of the hour is fixed when it closes, against what the
37
+ * month's earlier requests left. Correcting one request's minutes later
38
+ * recomputes that request alone, against the same remainder, so a fix
39
+ * never moves a charge on a request nobody touched.
40
+ * - Past the hour, extra time bills at `SITE_CARE_EXTRA_HOUR_USD` per
41
+ * STARTED hour — whole hours, rounded up — and never less than the hours
42
+ * the owner approved. With no approval on file, or more time than was
43
+ * approved, the close is blocked: ask the owner first, or absorb it (no
44
+ * charge, the minutes still count).
45
+ */ /** The `kind` a Site Care support ticket carries. */ export const SITE_CARE_TICKET_KIND = 'siteCare';
46
+ /** Site Care's promise: done within two business days. */ export const SITE_CARE_RESPONSE_BUSINESS_DAYS = 2;
47
+ /** The zone a Site Care month is drawn in: where the work is done. */ export const SITE_CARE_TIME_ZONE = 'America/Chicago';
48
+ /** The close's minutes are rounded up to this step. */ export const SITE_CARE_CLOSE_STEP_MINUTES = 5;
49
+ /** The most minutes one request may log. */ export const SITE_CARE_MAX_REQUEST_MINUTES = 60 * 40;
50
+ /**
51
+ * The tax code the extra-time item is billed under: the code every Aglyn
52
+ * product carries (the Decision Log of 2026-10-18), read off the Site Care
53
+ * product, which is checked to carry it before anything is charged.
54
+ */ export const SITE_CARE_EXTRA_TIME_TAX_CODE = 'txcd_10103001';
55
+ /**
56
+ * WHERE A CHANGE IS EMAILED (AGL-3997): the support address. Site Care has no
57
+ * address of its own. An owner writes to the support address they already
58
+ * know, and a message to it from a member of a workspace with Site Care files
59
+ * itself as a request; every other message is ordinary support mail. The
60
+ * support mailbox also delivers each message to `support@<inbound mail
61
+ * domain>`, where the mail provider announces it, and every Site Care email
62
+ * replies to `support+<requestId>@<inbound mail domain>`, so an answer joins
63
+ * its own request.
64
+ */ export const SITE_CARE_INBOUND_LOCAL_PART = 'support';
65
+ /**
66
+ * The operator's support address, from the operator identity: what an owner
67
+ * is told to email a change to, and what the intake reads as one. `null` on
68
+ * a deployment that publishes no support address, where Request a change on
69
+ * a site's dashboard is the only way in.
70
+ */ export function siteCareSupportAddress() {
71
+ return operatorIdentity().supportEmail;
72
+ }
73
+ /**
74
+ * The Reply-To of a Site Care email: `support+<requestId>@<domain>` for an
75
+ * email about one request, so the answer joins it; the support address for
76
+ * one about no single request (a statement, a project), so the answer reaches
77
+ * the support inbox like any other message to it.
78
+ */ export function siteCareReplyAddress(requestId, domain, supportEmail = siteCareSupportAddress()) {
79
+ if (requestId) return `${SITE_CARE_INBOUND_LOCAL_PART}+${requestId}@${domain}`;
80
+ return supportEmail != null ? supportEmail : `${SITE_CARE_INBOUND_LOCAL_PART}@${domain}`;
81
+ }
82
+ /** The longest title and message a request keeps. */ export const SITE_CARE_SUBJECT_MAX = 150;
83
+ export const SITE_CARE_BODY_MAX = 5000;
84
+ /** Stripe's limit on an invoice item's description is generous; ours is not. */ export const SITE_CARE_LINE_DESCRIPTION_MAX = 480;
85
+ /** Charges that still bill, or are about to. */ export const SITE_CARE_LIVE_CHARGE_STATUSES = [
86
+ 'creating',
87
+ 'pending'
88
+ ];
89
+ /** Whether a value is a `YYYY-MM` month key. */ export function isSiteCareMonthKey(value) {
90
+ return typeof value === 'string' && /^\d{4}-(0[1-9]|1[0-2])$/.test(value);
91
+ }
92
+ /** The month an instant falls in, in Site Care's zone: `2026-10`. */ export function siteCareMonthKey(ms) {
93
+ var _ref, _ref1;
94
+ var _parts_find, _parts_find1;
95
+ const parts = new Intl.DateTimeFormat('en-US', {
96
+ timeZone: SITE_CARE_TIME_ZONE,
97
+ year: 'numeric',
98
+ month: '2-digit'
99
+ }).formatToParts(new Date(ms));
100
+ const year = (_ref = (_parts_find = parts.find((part)=>part.type === 'year')) == null ? void 0 : _parts_find.value) != null ? _ref : '1970';
101
+ const month = (_ref1 = (_parts_find1 = parts.find((part)=>part.type === 'month')) == null ? void 0 : _parts_find1.value) != null ? _ref1 : '01';
102
+ return `${year}-${month}`;
103
+ }
104
+ /** The month before a month key. */ export function previousSiteCareMonthKey(key) {
105
+ const [year, month] = key.split('-').map(Number);
106
+ return month === 1 ? `${year - 1}-12` : `${year}-${String(month - 1).padStart(2, '0')}`;
107
+ }
108
+ /** "October 2026". */ export function siteCareMonthLabel(key) {
109
+ if (!isSiteCareMonthKey(key)) return key;
110
+ const [year, month] = key.split('-').map(Number);
111
+ return new Date(Date.UTC(year, month - 1, 15)).toLocaleString('en-US', {
112
+ month: 'long',
113
+ year: 'numeric',
114
+ timeZone: 'UTC'
115
+ });
116
+ }
117
+ /** The document id of an org's month: `{orgId}_{YYYY-MM}`, and the ticket field. */ export function siteCareOrgMonth(orgId, month) {
118
+ return `${orgId}_${month}`;
119
+ }
120
+ /** "45 min", "1 h", "1 h 15 min". */ export function formatSiteCareMinutes(minutes) {
121
+ const total = Math.max(0, Math.round(Number(minutes) || 0));
122
+ if (total < 60) return `${total} min`;
123
+ const hours = Math.floor(total / 60);
124
+ const rest = total % 60;
125
+ return rest ? `${hours} h ${rest} min` : `${hours} h`;
126
+ }
127
+ /** "$79", "$158.00" → always whole-dollar style when whole. */ export function formatSiteCareUsd(cents) {
128
+ const dollars = Math.round(Number(cents) || 0) / 100;
129
+ return Number.isInteger(dollars) ? `$${dollars}` : `$${dollars.toFixed(2)}`;
130
+ }
131
+ /**
132
+ * The close's number from the timer: elapsed minutes rounded UP to the next
133
+ * five, and never less than five — a request somebody opened and closed was
134
+ * still a request worked.
135
+ */ export function closeMinutesFromTimer(startedAtMs, nowMs) {
136
+ if (!startedAtMs || nowMs <= startedAtMs) return SITE_CARE_CLOSE_STEP_MINUTES;
137
+ const elapsed = (nowMs - startedAtMs) / 60000;
138
+ const rounded = Math.ceil(elapsed / SITE_CARE_CLOSE_STEP_MINUTES) * SITE_CARE_CLOSE_STEP_MINUTES;
139
+ return Math.min(SITE_CARE_MAX_REQUEST_MINUTES, Math.max(SITE_CARE_CLOSE_STEP_MINUTES, rounded));
140
+ }
141
+ /** Staff's number read back, or null when it is not a usable count of minutes. */ export function readSiteCareMinutes(value) {
142
+ const minutes = Number(value);
143
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > SITE_CARE_MAX_REQUEST_MINUTES) {
144
+ return null;
145
+ }
146
+ return minutes;
147
+ }
148
+ /** Minutes as they count against the included hour: whole blocks, rounded up. */ export function countedSiteCareMinutes(minutes) {
149
+ const value = Math.max(0, Number(minutes) || 0);
150
+ return Math.ceil(value / SITE_CARE_INCLUDED_BLOCK_MINUTES) * SITE_CARE_INCLUDED_BLOCK_MINUTES;
151
+ }
152
+ /** The month's included minutes: the hour plus goodwill. */ export function siteCareIncludedPool(goodwillMinutes) {
153
+ return SITE_CARE_INCLUDED_MINUTES + Math.max(0, Math.floor(Number(goodwillMinutes) || 0));
154
+ }
155
+ /**
156
+ * One request's minutes against what the month's OTHER closed requests left
157
+ * of the included pool.
158
+ */ export function allocateSiteCareMinutes(input) {
159
+ const countedMinutes = countedSiteCareMinutes(input.minutes);
160
+ const remainingBefore = Math.max(0, siteCareIncludedPool(input.goodwillMinutes) - Math.max(0, input.otherIncludedUsed));
161
+ const includedMinutesUsed = Math.min(countedMinutes, remainingBefore);
162
+ const overMinutes = countedMinutes - includedMinutesUsed;
163
+ return {
164
+ countedMinutes,
165
+ includedMinutesUsed,
166
+ overMinutes,
167
+ requiredHours: overMinutes > 0 ? Math.ceil(overMinutes / 60) : 0,
168
+ remainingBefore
169
+ };
170
+ }
171
+ /**
172
+ * What a close (or a correction) may do with a request's extra time.
173
+ *
174
+ * Within the hour nothing bills. Past it, `absorb` closes with no charge;
175
+ * otherwise an approval must cover the whole hours needed, and the bill is
176
+ * the larger of those and the approved hours — the approved amount is the
177
+ * floor. Nothing bills without the owner's recorded yes.
178
+ */ export function siteCareCloseVerdict(input) {
179
+ if (input.requiredHours <= 0) return {
180
+ ok: true,
181
+ billedHours: 0,
182
+ absorbed: false
183
+ };
184
+ if (input.absorb) return {
185
+ ok: true,
186
+ billedHours: 0,
187
+ absorbed: true
188
+ };
189
+ if (!input.approval) {
190
+ return {
191
+ ok: false,
192
+ reason: 'no-approval',
193
+ requiredHours: input.requiredHours,
194
+ approvedHours: null
195
+ };
196
+ }
197
+ if (input.approval.hours < input.requiredHours) {
198
+ return {
199
+ ok: false,
200
+ reason: 'approval-exceeded',
201
+ requiredHours: input.requiredHours,
202
+ approvedHours: input.approval.hours
203
+ };
204
+ }
205
+ return {
206
+ ok: true,
207
+ billedHours: Math.max(input.requiredHours, input.approval.hours),
208
+ absorbed: false
209
+ };
210
+ }
211
+ /** Extra time in cents, before tax. */ export function siteCareExtraTimeCents(hours) {
212
+ return Math.max(0, Math.floor(hours)) * SITE_CARE_EXTRA_HOUR_USD * 100;
213
+ }
214
+ /** A request's facts as the statement reads them, from the stored map. */ export function siteCareStatementRequest(requestId, title, request) {
215
+ var _ref, _ref1, _ref2, _ref3;
216
+ const charge = (_ref = request == null ? void 0 : request.charge) != null ? _ref : null;
217
+ return {
218
+ requestId,
219
+ title,
220
+ state: (request == null ? void 0 : request.state) === 'closed' ? 'closed' : 'open',
221
+ closedAtMs: (_ref1 = request == null ? void 0 : request.closedAtMs) != null ? _ref1 : null,
222
+ minutesLogged: (_ref2 = request == null ? void 0 : request.minutesLogged) != null ? _ref2 : null,
223
+ countedMinutes: Number(request == null ? void 0 : request.countedMinutes) || 0,
224
+ includedMinutesUsed: Number(request == null ? void 0 : request.includedMinutesUsed) || 0,
225
+ overMinutes: Number(request == null ? void 0 : request.overMinutes) || 0,
226
+ billedHours: Number(request == null ? void 0 : request.billedHours) || 0,
227
+ absorbed: (request == null ? void 0 : request.absorbed) === true,
228
+ chargeStatus: (_ref3 = charge == null ? void 0 : charge.status) != null ? _ref3 : null,
229
+ chargeCents: Number(charge == null ? void 0 : charge.amountCents) || 0
230
+ };
231
+ }
232
+ /** The month, summed. */ export function siteCareMonthStatement(input) {
233
+ const closed = input.requests.filter((request)=>request.state === 'closed');
234
+ const goodwillMinutes = Math.max(0, Math.floor(Number(input.goodwillMinutes) || 0));
235
+ const poolMinutes = siteCareIncludedPool(goodwillMinutes);
236
+ const includedMinutesUsed = closed.reduce((sum, r)=>sum + r.includedMinutesUsed, 0);
237
+ const live = closed.filter((r)=>r.chargeStatus !== null && SITE_CARE_LIVE_CHARGE_STATUSES.includes(r.chargeStatus));
238
+ const reversed = closed.filter((r)=>r.chargeStatus === 'voided' || r.chargeStatus === 'credited' || r.chargeStatus === 'refunded');
239
+ return {
240
+ month: input.month,
241
+ monthLabel: siteCareMonthLabel(input.month),
242
+ includedMinutes: SITE_CARE_INCLUDED_MINUTES,
243
+ goodwillMinutes,
244
+ poolMinutes,
245
+ requests: input.requests.length,
246
+ openRequests: input.requests.length - closed.length,
247
+ minutesLogged: closed.reduce((sum, r)=>{
248
+ var _r_minutesLogged;
249
+ return sum + ((_r_minutesLogged = r.minutesLogged) != null ? _r_minutesLogged : 0);
250
+ }, 0),
251
+ countedMinutes: closed.reduce((sum, r)=>sum + r.countedMinutes, 0),
252
+ includedMinutesUsed,
253
+ minutesLeft: Math.max(0, poolMinutes - includedMinutesUsed),
254
+ extraHoursBilled: live.reduce((sum, r)=>sum + r.billedHours, 0),
255
+ extraBilledCents: live.reduce((sum, r)=>sum + r.chargeCents, 0),
256
+ extraReversedCents: reversed.reduce((sum, r)=>sum + r.chargeCents, 0)
257
+ };
258
+ }
259
+ /** The month's totals in one line, as the statement and the invoice line say them. */ export function siteCareMonthSentence(statement) {
260
+ const requests = `${statement.requests} ${statement.requests === 1 ? 'request' : 'requests'}`;
261
+ return `${statement.monthLabel}: ${requests}, ${formatSiteCareMinutes(statement.minutesLogged)} of work, ` + `${statement.includedMinutesUsed} of ${statement.poolMinutes} included minutes used` + (statement.extraHoursBilled > 0 ? `, ${describeHours(statement.extraHoursBilled)} of extra time billed` : '') + '.';
262
+ }
263
+ /**
264
+ * The extra-time invoice line's description: the request, its minutes, the
265
+ * hours billed and why, and the month's statement — what the owner reads on
266
+ * the invoice, and what the reconciliation compares Stripe's copy against.
267
+ */ export function siteCareExtraTimeDescription(input) {
268
+ const title = input.title.length > 80 ? `${input.title.slice(0, 79)}…` : input.title;
269
+ const approved = input.approvedHours && input.approvedHours > Math.ceil(input.overMinutes / 60) ? ` (the ${describeHours(input.approvedHours)} you approved)` : '';
270
+ const line = `Site Care extra time — “${title}”: ${formatSiteCareMinutes(input.minutesLogged)} of work, ` + `${formatSiteCareMinutes(input.overMinutes)} past the included hour, billed as ` + `${describeHours(input.billedHours)}${approved} at $${SITE_CARE_EXTRA_HOUR_USD}/hour. ` + siteCareMonthSentence(input.statement);
271
+ return line.length > SITE_CARE_LINE_DESCRIPTION_MAX ? `${line.slice(0, SITE_CARE_LINE_DESCRIPTION_MAX - 1)}…` : line;
272
+ }
273
+ /** A charge's standing in the owner's words. */ export function siteCareChargeWords(status) {
274
+ switch(status){
275
+ case 'creating':
276
+ case 'pending':
277
+ return 'On your next invoice';
278
+ case 'failed':
279
+ return 'Not billed';
280
+ case 'voided':
281
+ return 'Removed, not billed';
282
+ case 'credited':
283
+ return 'Credited back';
284
+ case 'refunded':
285
+ return 'Refunded';
286
+ default:
287
+ return 'Included';
288
+ }
289
+ }
290
+ /** Whether a site activity row is a publish a request can be linked to. */ export function isSiteCarePublishAction(action) {
291
+ return typeof action === 'string' && /^published\b/i.test(action.trim());
292
+ }
293
+ /** A publish link as a sentence: "Published “Home” on Oct 19, 2026, 3:04 PM". */ export function siteCarePublishSentence(publish, formatDate) {
294
+ if (!publish) return null;
295
+ const what = publish.targetName ? ` “${publish.targetName}”` : '';
296
+ return `${publish.action}${what} on ${formatDate(publish.atMs)}`;
297
+ }
298
+ /** A date as the owner's emails and statement write it, in Site Care's zone. */ export function formatSiteCareDate(ms) {
299
+ return new Date(ms).toLocaleString('en-US', {
300
+ timeZone: SITE_CARE_TIME_ZONE,
301
+ month: 'short',
302
+ day: 'numeric',
303
+ year: 'numeric',
304
+ hour: 'numeric',
305
+ minute: '2-digit',
306
+ timeZoneName: 'short'
307
+ });
308
+ }
309
+
310
+ //# sourceMappingURL=site-care.js.map