@aglyn/tenant-data-admin 1.0.0-beta.270 → 1.0.0-beta.271
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/package.json +7 -7
- package/src/lib/server/append-only-history-write.d.ts +38 -0
- package/src/lib/server/append-only-history-write.js +60 -0
- package/src/lib/server/append-only-history-write.js.map +1 -0
- package/src/lib/server/billing-addons.d.ts +58 -32
- package/src/lib/server/billing-addons.js +100 -86
- package/src/lib/server/billing-addons.js.map +1 -1
- package/src/lib/server/bundle-links.d.ts +166 -0
- package/src/lib/server/bundle-links.js +286 -0
- package/src/lib/server/bundle-links.js.map +1 -0
- package/src/lib/server/client-build.d.ts +74 -0
- package/src/lib/server/client-build.js +264 -0
- package/src/lib/server/client-build.js.map +1 -0
- package/src/lib/server/host-memberships.d.ts +35 -2
- package/src/lib/server/host-memberships.js +63 -2
- package/src/lib/server/host-memberships.js.map +1 -1
- package/src/lib/server/org-billing.d.ts +4 -2
- package/src/lib/server/org-billing.js +5 -0
- package/src/lib/server/org-billing.js.map +1 -1
- package/src/lib/server/site-care-emails.d.ts +52 -0
- package/src/lib/server/site-care-emails.js +97 -0
- package/src/lib/server/site-care-emails.js.map +1 -0
- package/src/lib/server/site-care-inbound.d.ts +80 -0
- package/src/lib/server/site-care-inbound.js +171 -0
- package/src/lib/server/site-care-inbound.js.map +1 -0
- package/src/lib/server/site-care-project-reconcile.d.ts +64 -0
- package/src/lib/server/site-care-project-reconcile.js +211 -0
- package/src/lib/server/site-care-project-reconcile.js.map +1 -0
- package/src/lib/server/site-care-project-stripe.d.ts +114 -0
- package/src/lib/server/site-care-project-stripe.js +305 -0
- package/src/lib/server/site-care-project-stripe.js.map +1 -0
- package/src/lib/server/site-care-projects.d.ts +169 -0
- package/src/lib/server/site-care-projects.js +882 -0
- package/src/lib/server/site-care-projects.js.map +1 -0
- package/src/lib/server/site-care-reconcile.d.ts +81 -0
- package/src/lib/server/site-care-reconcile.js +349 -0
- package/src/lib/server/site-care-reconcile.js.map +1 -0
- package/src/lib/server/site-care-requests.d.ts +243 -0
- package/src/lib/server/site-care-requests.js +1414 -0
- package/src/lib/server/site-care-requests.js.map +1 -0
- package/src/lib/server/site-care-stripe.d.ts +175 -0
- package/src/lib/server/site-care-stripe.js +375 -0
- package/src/lib/server/site-care-stripe.js.map +1 -0
- package/src/lib/server/upgrade-proposal.d.ts +40 -1
- package/src/lib/server/upgrade-proposal.js +92 -50
- package/src/lib/server/upgrade-proposal.js.map +1 -1
- package/src/tenancy.d.ts +1 -0
- package/src/tenancy.js +2 -0
- package/src/tenancy.js.map +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/site-care-reconcile.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n previousSiteCareMonthKey,\n siteCareExtraTimeCents,\n siteCareMonthKey,\n siteCareMonthStatement,\n siteCareStatementRequest,\n type SiteCareRequest,\n} from '@aglyn/aglyn/app-utils/site-care'\nimport { readOrgBilling } from './org-billing'\nimport { raiseOperatorAlert } from './operator-alerts'\nimport { readSiteCareRequest } from './site-care-requests'\nimport {\n reconcileSiteCareProjects,\n type SiteCareProjectFindingCode,\n} from './site-care-project-reconcile'\nimport {\n listSiteCareExtraTimeItems,\n readExtraTimeItem,\n type SiteCareStripeOptions,\n type StripeExtraTimeItem,\n} from './site-care-stripe'\n\n/**\n * THE SITE CARE RECONCILIATION (AGL-3959).\n *\n * Once a day, for the current month and the one before: each request's\n * billed hours against the Stripe invoice item that carries them — amount,\n * quantity and description — and each month's billed total against the sum\n * of its Stripe items. Any difference is a finding, and a workspace-month\n * with findings raises `billing.siteCareReconciliation` (Should know)\n * rather than passing silently. The same shape as the pricing-drift check:\n * it compares and reports, and never changes anything on either side — the\n * fix is a person's, from the request.\n *\n * What it catches, by construction of how charges are written:\n * - a Stripe item with no row behind it (the call succeeded, the record did\n * not land): a `creating` charge, or an item no request claims;\n * - a row with no Stripe object: a `pending` charge whose item is gone, or a\n * `failed` one still owing hours;\n * - an item somebody edited in the Stripe dashboard: amount, quantity or\n * description that no longer match the request.\n */\n\nexport type SiteCareFindingCode =\n | 'charge-stuck'\n | 'charge-failed'\n | 'item-missing'\n | 'item-mismatch'\n | 'item-not-voided'\n | 'item-without-row'\n | 'hours-mismatch'\n | 'month-total'\n | 'no-customer'\n // A flat-quoted project's invoices (AGL-3970), in the same check.\n | SiteCareProjectFindingCode\n\nexport interface SiteCareFinding {\n orgId: string\n month: string\n requestId: string | null\n code: SiteCareFindingCode\n detail: string\n}\n\nexport interface SiteCareReconcileReport {\n months: string[]\n orgs: number\n requests: number\n /** Projects compared (AGL-3970). */\n projects: number\n findings: SiteCareFinding[]\n alerted: number\n errors: string[]\n}\n\ninterface RequestRow {\n id: string\n orgId: string\n subject: string\n request: SiteCareRequest\n}\n\n/** Compares one workspace's requests with its Stripe items. Pure. */\nexport function compareSiteCareCharges(input: {\n orgId: string\n requests: readonly RequestRow[]\n items: readonly StripeExtraTimeItem[]\n /** Items read one by one because the listing did not reach them. */\n readItems?: ReadonlyMap<string, { deleted: boolean; item: StripeExtraTimeItem | null }>\n}): SiteCareFinding[] {\n const findings: SiteCareFinding[] = []\n const byId = new Map(input.items.map((item) => [item.id, item]))\n const claimed = new Set<string>()\n const months = new Set<string>()\n for (const row of input.requests) {\n const { request } = row\n months.add(request.month)\n const charge = request.charge\n const at = { orgId: input.orgId, month: request.month, requestId: row.id }\n if (!charge) {\n if (request.billedHours > 0) {\n findings.push({ ...at, code: 'hours-mismatch', detail: `“${row.subject}” bills ${request.billedHours} h with no charge recorded.` })\n }\n continue\n }\n if (charge.invoiceItemId) claimed.add(charge.invoiceItemId)\n const fromStripe = charge.invoiceItemId\n ? (byId.get(charge.invoiceItemId) ?? input.readItems?.get(charge.invoiceItemId)?.item ?? null)\n : (input.items.find((item) => item.requestId === row.id) ?? null)\n const deleted = charge.invoiceItemId ? input.readItems?.get(charge.invoiceItemId)?.deleted === true : false\n if (fromStripe) claimed.add(fromStripe.id)\n switch (charge.status) {\n case 'creating':\n findings.push({\n ...at,\n code: 'charge-stuck',\n detail: fromStripe\n ? `“${row.subject}”: Stripe item ${fromStripe.id} exists but the request never recorded it. Retry the charge to record it.`\n : `“${row.subject}”: a charge was started and never finished. Retry it.`,\n })\n break\n case 'failed':\n findings.push({ ...at, code: 'charge-failed', detail: `“${row.subject}”: ${charge.hours} h owed with no Stripe item (${charge.error ?? 'failed'}).` })\n break\n case 'pending': {\n if (!fromStripe || deleted) {\n findings.push({ ...at, code: 'item-missing', detail: `“${row.subject}”: Stripe item ${charge.invoiceItemId} is gone.` })\n break\n }\n const expected = siteCareExtraTimeCents(charge.hours)\n const problems: string[] = []\n if (fromStripe.amountCents !== expected) problems.push(`amount ${fromStripe.amountCents} ≠ ${expected}`)\n if (fromStripe.quantity !== charge.hours) problems.push(`quantity ${fromStripe.quantity} ≠ ${charge.hours}`)\n if (fromStripe.description !== charge.description) problems.push('description differs')\n if (problems.length) {\n findings.push({ ...at, code: 'item-mismatch', detail: `“${row.subject}” (${fromStripe.id}): ${problems.join(', ')}.` })\n }\n if (request.billedHours !== charge.hours && !request.absorbed) {\n findings.push({ ...at, code: 'hours-mismatch', detail: `“${row.subject}”: billed ${request.billedHours} h but the charge is ${charge.hours} h.` })\n }\n break\n }\n case 'voided':\n if (fromStripe && !deleted) {\n findings.push({ ...at, code: 'item-not-voided', detail: `“${row.subject}”: voided here, but Stripe item ${fromStripe.id} is still there.` })\n }\n break\n default:\n break\n }\n }\n for (const item of input.items) {\n if (claimed.has(item.id)) continue\n findings.push({\n orgId: input.orgId,\n month: [...months][0] ?? '',\n requestId: item.requestId || null,\n code: 'item-without-row',\n detail: `Stripe item ${item.id} (${item.amountCents} cents) names request ${item.requestId}, which does not record it.`,\n })\n }\n // The month's total against Stripe's.\n for (const month of months) {\n const inMonth = input.requests.filter((row) => row.request.month === month)\n const statement = siteCareMonthStatement({\n month,\n goodwillMinutes: 0,\n requests: inMonth.map((row) => siteCareStatementRequest(row.id, row.subject, row.request)),\n })\n const stripeTotal = inMonth\n .filter((row) => row.request.charge?.status === 'pending' && row.request.charge.invoiceItemId)\n .reduce((sum, row) => {\n const id = String(row.request.charge?.invoiceItemId)\n const item = byId.get(id) ?? input.readItems?.get(id)?.item ?? null\n return sum + (item ? item.amountCents : 0)\n }, 0)\n const pendingRecorded = inMonth\n .filter((row) => row.request.charge?.status === 'pending')\n .reduce((sum, row) => sum + (row.request.charge?.amountCents ?? 0), 0)\n if (stripeTotal !== pendingRecorded) {\n findings.push({\n orgId: input.orgId,\n month,\n requestId: null,\n code: 'month-total',\n detail: `The ${month} statement bills ${statement.extraBilledCents} cents (${pendingRecorded} on pending items) and Stripe holds ${stripeTotal}.`,\n })\n }\n }\n return findings\n}\n\n/** Runs the check over the current and previous month. */\nexport async function reconcileSiteCare(\n firestore: FirebaseFirestore.Firestore,\n input: { nowMs?: number; dryRun: boolean; stripe?: SiteCareStripeOptions },\n): Promise<SiteCareReconcileReport> {\n const nowMs = input.nowMs ?? Date.now()\n const current = siteCareMonthKey(nowMs)\n const months = [current, previousSiteCareMonthKey(current)]\n const snapshot = await firestore.collection('supportTickets').where('siteCareMonth', 'in', months).limit(2000).get()\n const byOrg = new Map<string, RequestRow[]>()\n for (const doc of snapshot.docs) {\n const request = readSiteCareRequest(doc.get('siteCare'))\n const orgId = String(doc.get('orgId') ?? '')\n if (!request || !orgId || request.state !== 'closed') continue\n const rows = byOrg.get(orgId) ?? []\n rows.push({ id: doc.id, orgId, subject: String(doc.get('subject') ?? ''), request })\n byOrg.set(orgId, rows)\n }\n const report: SiteCareReconcileReport = {\n months,\n orgs: byOrg.size,\n requests: [...byOrg.values()].reduce((sum, rows) => sum + rows.length, 0),\n projects: 0,\n findings: [],\n alerted: 0,\n errors: [],\n }\n // Seventy days reaches back past the start of the previous month.\n const sinceMs = nowMs - 70 * 24 * 60 * 60 * 1000\n for (const [orgId, rows] of byOrg) {\n try {\n const charged = rows.filter((row) => row.request.charge)\n if (!charged.length) continue\n const billing = await readOrgBilling(orgId)\n const customerId = String((billing as { stripeCustomerId?: unknown }).stripeCustomerId ?? '')\n if (!customerId) {\n report.findings.push({ orgId, month: current, requestId: null, code: 'no-customer', detail: 'Charges are recorded but the workspace has no Stripe customer.' })\n continue\n }\n const listed = await listSiteCareExtraTimeItems({ customerId, sinceMs }, input.stripe)\n if (listed.ok === false) {\n report.errors.push(`${orgId}: ${listed.error}`)\n continue\n }\n const listedIds = new Set(listed.items.map((item) => item.id))\n const readItems = new Map<string, { deleted: boolean; item: StripeExtraTimeItem | null }>()\n for (const row of charged) {\n const id = row.request.charge?.invoiceItemId\n if (!id || listedIds.has(id)) continue\n const read = await readExtraTimeItem(id, input.stripe)\n if (read.ok === false) {\n report.errors.push(`${orgId}/${row.id}: ${read.error}`)\n continue\n }\n readItems.set(id, {\n deleted: read.state.stage === 'deleted',\n item:\n read.state.stage === 'deleted'\n ? null\n : {\n id,\n amountCents: read.state.amountCents,\n quantity: read.state.quantity,\n description: read.state.description,\n requestId: String(read.state.metadata['siteCareRequestId'] ?? row.id),\n month: String(read.state.metadata['month'] ?? row.request.month),\n },\n })\n }\n // Only items for these months' requests are judged here: an older\n // month's item inside the listing window belongs to a month this run\n // does not read.\n const requestIds = new Set(rows.map((row) => row.id))\n const items = listed.items.filter(\n (item) => requestIds.has(item.requestId) || months.includes(item.month),\n )\n const findings = compareSiteCareCharges({ orgId, requests: rows, items, readItems })\n report.findings.push(...findings)\n if (input.dryRun || !findings.length) continue\n const byMonth = new Map<string, SiteCareFinding[]>()\n for (const finding of findings) {\n const list = byMonth.get(finding.month) ?? []\n list.push(finding)\n byMonth.set(finding.month, list)\n }\n const orgSnap = await firestore.collection('orgs').doc(orgId).get()\n const orgName = String(orgSnap.get('name') ?? orgId)\n for (const [month, list] of byMonth) {\n const result = await raiseOperatorAlert('billing.siteCareReconciliation', {\n dedupeKey: `${orgId}:${month}`,\n context: {\n orgId,\n orgName,\n month,\n count: list.length,\n findings: list.map((finding) => finding.detail).join(' '),\n },\n orgId,\n })\n if (result.outcome !== 'deduped' && result.outcome !== 'below-threshold') report.alerted += 1\n }\n } catch (error) {\n report.errors.push(`${orgId}: ${error instanceof Error ? error.message : String(error)}`)\n }\n }\n await reconcileProjectsInto(firestore, report, { nowMs, dryRun: input.dryRun, stripe: input.stripe })\n return report\n}\n\n/**\n * The flat-quoted projects (AGL-3970), in the same run and on the same\n * alert: one per workspace with findings, deduplicated a day like the\n * month's, its `month` naming the projects rather than a month.\n */\nasync function reconcileProjectsInto(\n firestore: FirebaseFirestore.Firestore,\n report: SiteCareReconcileReport,\n input: { nowMs: number; dryRun: boolean; stripe?: SiteCareStripeOptions },\n): Promise<void> {\n const current = siteCareMonthKey(input.nowMs)\n let projects\n try {\n projects = await reconcileSiteCareProjects(firestore, { nowMs: input.nowMs, stripe: input.stripe })\n } catch (error) {\n report.errors.push(`projects: ${error instanceof Error ? error.message : String(error)}`)\n return\n }\n report.projects = projects.projects\n report.errors.push(...projects.errors)\n const byOrg = new Map<string, SiteCareFinding[]>()\n for (const finding of projects.findings) {\n const row: SiteCareFinding = {\n orgId: finding.orgId,\n month: current,\n requestId: finding.projectId,\n code: finding.code,\n detail: finding.detail,\n }\n report.findings.push(row)\n const list = byOrg.get(finding.orgId) ?? []\n list.push(row)\n byOrg.set(finding.orgId, list)\n }\n if (input.dryRun) return\n for (const [orgId, list] of byOrg) {\n try {\n const orgSnap = await firestore.collection('orgs').doc(orgId).get()\n const result = await raiseOperatorAlert('billing.siteCareReconciliation', {\n dedupeKey: `${orgId}:projects`,\n context: {\n orgId,\n orgName: String(orgSnap.get('name') ?? orgId),\n month: 'projects',\n count: list.length,\n findings: list.map((finding) => finding.detail).join(' '),\n },\n orgId,\n })\n if (result.outcome !== 'deduped' && result.outcome !== 'below-threshold') report.alerted += 1\n } catch (error) {\n report.errors.push(`${orgId}: ${error instanceof Error ? error.message : String(error)}`)\n }\n }\n}\n"],"names":["previousSiteCareMonthKey","siteCareExtraTimeCents","siteCareMonthKey","siteCareMonthStatement","siteCareStatementRequest","readOrgBilling","raiseOperatorAlert","readSiteCareRequest","reconcileSiteCareProjects","listSiteCareExtraTimeItems","readExtraTimeItem","compareSiteCareCharges","input","findings","byId","Map","items","map","item","id","claimed","Set","months","row","requests","request","add","month","charge","at","orgId","requestId","billedHours","push","code","detail","subject","invoiceItemId","fromStripe","get","readItems","find","deleted","status","hours","error","expected","problems","amountCents","quantity","description","length","join","absorbed","has","inMonth","filter","statement","goodwillMinutes","stripeTotal","reduce","sum","String","pendingRecorded","extraBilledCents","reconcileSiteCare","firestore","nowMs","Date","now","current","snapshot","collection","where","limit","byOrg","doc","docs","state","rows","set","report","orgs","size","values","projects","alerted","errors","sinceMs","orgSnap","charged","billing","customerId","stripeCustomerId","listed","stripe","ok","listedIds","read","stage","metadata","requestIds","includes","dryRun","byMonth","finding","list","orgName","result","dedupeKey","context","count","outcome","Error","message","reconcileProjectsInto","projectId"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,sBAAsB,EACtBC,gBAAgB,EAChBC,sBAAsB,EACtBC,wBAAwB,QAEnB,mCAAkC;AACzC,SAASC,cAAc,QAAQ,mBAAe;AAC9C,SAASC,kBAAkB,QAAQ,uBAAmB;AACtD,SAASC,mBAAmB,QAAQ,0BAAsB;AAC1D,SACEC,yBAAyB,QAEpB,mCAA+B;AACtC,SACEC,0BAA0B,EAC1BC,iBAAiB,QAGZ,wBAAoB;AA8D3B,mEA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mBAAmB,kCAAkC;gBACxEuG,WAAW,GAAG/E,MAAM,SAAS,CAAC;gBAC9BgF,SAAS;oBACPhF;oBACA6E,SAAS7C,QAAO2B,eAAAA,QAAQlD,GAAG,CAAC,mBAAZkD,eAAuB3D;oBACvCH,OAAO;oBACPoF,OAAOL,KAAKvD,MAAM;oBAClBtC,UAAU6F,KAAKzF,GAAG,CAAC,CAACwF,UAAYA,QAAQtE,MAAM,EAAEiB,IAAI,CAAC;gBACvD;gBACAtB;YACF;YACA,IAAI8E,OAAOI,OAAO,KAAK,aAAaJ,OAAOI,OAAO,KAAK,mBAAmB/B,OAAOK,OAAO,IAAI;QAC9F,EAAE,OAAOzC,OAAO;YACdoC,OAAOM,MAAM,CAACtD,IAAI,CAAC,GAAGH,MAAM,EAAE,EAAEe,iBAAiBoE,QAAQpE,MAAMqE,OAAO,GAAGpD,OAAOjB,QAAQ;QAC1F;IACF;AACF"}
|
|
@@ -0,0 +1,243 @@
|
|
|
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 AppendOnlyHistoryRow } from '@aglyn/aglyn/app-utils/append-only-history';
|
|
18
|
+
import { type OwnerApprovalRecord } from '@aglyn/aglyn/app-utils/owner-approval-record';
|
|
19
|
+
import { type SiteCareCharge, type SiteCareCloseVerdict, type SiteCareMonthStatement, type SiteCarePublishLink, type SiteCareRequest, type SiteCareSource } from '@aglyn/aglyn/app-utils/site-care';
|
|
20
|
+
import { sendSiteCareEmail, type SiteCareEmailResult } from './site-care-emails';
|
|
21
|
+
import { type SiteCareStripeOptions } from './site-care-stripe';
|
|
22
|
+
export declare const SITE_CARE_HISTORY_COLLECTION = "siteCareHistory";
|
|
23
|
+
export declare const SITE_CARE_MONTHS_COLLECTION = "siteCareMonths";
|
|
24
|
+
/** Who did something. `uid` null is the platform itself. */
|
|
25
|
+
export interface SiteCareActor {
|
|
26
|
+
uid: string | null;
|
|
27
|
+
email: string | null;
|
|
28
|
+
}
|
|
29
|
+
/** A refusal the caller turns into a response. */
|
|
30
|
+
export declare class SiteCareError extends Error {
|
|
31
|
+
readonly status: number;
|
|
32
|
+
readonly detail: Record<string, unknown> | null;
|
|
33
|
+
constructor(message: string, status?: number, detail?: Record<string, unknown> | null);
|
|
34
|
+
}
|
|
35
|
+
/** The seams a spec replaces. */
|
|
36
|
+
export interface SiteCareDeps {
|
|
37
|
+
now?: () => number;
|
|
38
|
+
stripe?: SiteCareStripeOptions;
|
|
39
|
+
email?: typeof sendSiteCareEmail;
|
|
40
|
+
}
|
|
41
|
+
/** A fresh request's map. */
|
|
42
|
+
export declare function newSiteCareRequest(input: {
|
|
43
|
+
source: SiteCareSource;
|
|
44
|
+
hostId: string | null;
|
|
45
|
+
requesterEmail: string | null;
|
|
46
|
+
month: string;
|
|
47
|
+
}): SiteCareRequest;
|
|
48
|
+
/** A stored map read back with every field present. */
|
|
49
|
+
export declare function readSiteCareRequest(value: unknown): SiteCareRequest | null;
|
|
50
|
+
/** The org document joined with its billing keys, as `hasSiteCare` reads it. */
|
|
51
|
+
export declare function readSiteCareOrg(firestore: FirebaseFirestore.Firestore, orgId: string): Promise<Record<string, unknown> | null>;
|
|
52
|
+
/** Whether a workspace has Site Care in force. */
|
|
53
|
+
export declare function orgHasSiteCare(org: Record<string, unknown> | null): boolean;
|
|
54
|
+
/** The owner's address, from the owner's member row. */
|
|
55
|
+
export declare function siteCareOwnerEmail(firestore: FirebaseFirestore.Firestore, orgId: string, org: Record<string, unknown> | null): Promise<string | null>;
|
|
56
|
+
export interface OpenSiteCareRequestInput {
|
|
57
|
+
orgId: string;
|
|
58
|
+
org: Record<string, unknown>;
|
|
59
|
+
hostId: string | null;
|
|
60
|
+
subject: string;
|
|
61
|
+
body: string;
|
|
62
|
+
requester: SiteCareActor;
|
|
63
|
+
source: SiteCareSource;
|
|
64
|
+
/**
|
|
65
|
+
* A received message's id, when the request came by email: the ticket is
|
|
66
|
+
* keyed by it, so a provider redelivering the same message opens nothing
|
|
67
|
+
* twice.
|
|
68
|
+
*/
|
|
69
|
+
dedupeKey?: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** A document id derived from a received message, alphanumeric so it fits a reply address. */
|
|
72
|
+
export declare function siteCareMessageDocId(prefix: string, key: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Opens a request: the tagged ticket, its first message, the opening history
|
|
75
|
+
* row, the staff notice and the "we have your request" email. Shared by the
|
|
76
|
+
* console's "Request a change" and the inbound address.
|
|
77
|
+
*/
|
|
78
|
+
export declare function openSiteCareRequest(firestore: FirebaseFirestore.Firestore, input: OpenSiteCareRequestInput, deps?: SiteCareDeps): Promise<{
|
|
79
|
+
ticketId: string;
|
|
80
|
+
dueAtMs: number;
|
|
81
|
+
duplicate?: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Adds a reply that arrived by email to its request's thread. The sender
|
|
85
|
+
* must be a member of the request's workspace.
|
|
86
|
+
*/
|
|
87
|
+
export declare function appendSiteCareReply(firestore: FirebaseFirestore.Firestore, input: {
|
|
88
|
+
ticketId: string;
|
|
89
|
+
from: SiteCareActor;
|
|
90
|
+
body: string;
|
|
91
|
+
dedupeKey?: string | null;
|
|
92
|
+
}, deps?: SiteCareDeps): Promise<{
|
|
93
|
+
appended: boolean;
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Starts the request's timer the first time staff open it. A second open,
|
|
97
|
+
* a reload or another staff member opening it changes nothing.
|
|
98
|
+
*/
|
|
99
|
+
export declare function startSiteCareTimer(firestore: FirebaseFirestore.Firestore, input: {
|
|
100
|
+
ticketId: string;
|
|
101
|
+
actor: SiteCareActor;
|
|
102
|
+
}, deps?: SiteCareDeps): Promise<SiteCareRequest>;
|
|
103
|
+
/** Why a close or a correction is blocked, as the staff panel says it. */
|
|
104
|
+
export declare function siteCareBlockedMessage(verdict: Extract<SiteCareCloseVerdict, {
|
|
105
|
+
ok: false;
|
|
106
|
+
}>): string;
|
|
107
|
+
/**
|
|
108
|
+
* The newest publish on any of the workspace's sites since `sinceMs`, from
|
|
109
|
+
* each site's activity log — the change the request shipped.
|
|
110
|
+
*/
|
|
111
|
+
export declare function findSiteCarePublish(firestore: FirebaseFirestore.Firestore, orgId: string, sinceMs: number): Promise<SiteCarePublishLink | null>;
|
|
112
|
+
/** Re-runs a charge that failed, or whose result never landed. */
|
|
113
|
+
export declare function retrySiteCareCharge(firestore: FirebaseFirestore.Firestore, input: {
|
|
114
|
+
ticketId: string;
|
|
115
|
+
actor: SiteCareActor;
|
|
116
|
+
}, deps?: SiteCareDeps): Promise<SiteCareCharge | null>;
|
|
117
|
+
export interface CloseSiteCareInput {
|
|
118
|
+
ticketId: string;
|
|
119
|
+
actor: SiteCareActor;
|
|
120
|
+
minutes: unknown;
|
|
121
|
+
absorb?: boolean;
|
|
122
|
+
}
|
|
123
|
+
export interface CloseSiteCareResult {
|
|
124
|
+
request: SiteCareRequest;
|
|
125
|
+
statement: SiteCareMonthStatement;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Closes a request with one number. Refuses with the verdict when the
|
|
129
|
+
* minutes take the month past the included hour and no approval covers it
|
|
130
|
+
* — the panel then offers "Ask the owner first" and "Absorb it".
|
|
131
|
+
*/
|
|
132
|
+
export declare function closeSiteCareRequest(firestore: FirebaseFirestore.Firestore, input: CloseSiteCareInput, deps?: SiteCareDeps): Promise<CloseSiteCareResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Records — or corrects — how the owner said yes to extra time, and emails
|
|
135
|
+
* them the confirmation that is the written record.
|
|
136
|
+
*/
|
|
137
|
+
export declare function recordSiteCareApproval(firestore: FirebaseFirestore.Firestore, input: {
|
|
138
|
+
ticketId: string;
|
|
139
|
+
actor: SiteCareActor & {
|
|
140
|
+
uid: string;
|
|
141
|
+
};
|
|
142
|
+
approval: Record<string, unknown>;
|
|
143
|
+
}, deps?: SiteCareDeps): Promise<OwnerApprovalRecord>;
|
|
144
|
+
/**
|
|
145
|
+
* Changes the minutes on a closed request, with a reason, and recomputes its
|
|
146
|
+
* share of the included hour and its extra time: a pending item is corrected
|
|
147
|
+
* or deleted, a new one is added only under an approval. The owner gets a
|
|
148
|
+
* "corrected" summary with the before and after.
|
|
149
|
+
*/
|
|
150
|
+
export declare function correctSiteCareMinutes(firestore: FirebaseFirestore.Firestore, input: {
|
|
151
|
+
ticketId: string;
|
|
152
|
+
actor: SiteCareActor;
|
|
153
|
+
minutes: unknown;
|
|
154
|
+
reason: unknown;
|
|
155
|
+
absorb?: boolean;
|
|
156
|
+
}, deps?: SiteCareDeps): Promise<CloseSiteCareResult>;
|
|
157
|
+
/**
|
|
158
|
+
* The idempotency key of a correction's Stripe call: the charge's own key
|
|
159
|
+
* and the id of the history row that records the correction. A clock would
|
|
160
|
+
* make every retry a new request to Stripe; the row id makes it the same one.
|
|
161
|
+
*/
|
|
162
|
+
export declare function siteCareCorrectionKey(chargeKey: string, correctionId: string): string;
|
|
163
|
+
/**
|
|
164
|
+
* Voids, credits or refunds a request's extra-time charge, with a reason —
|
|
165
|
+
* deleted before its invoice finalizes, credited after, refunded once paid.
|
|
166
|
+
* `absorb` also records that the request is not charged for its extra time.
|
|
167
|
+
*/
|
|
168
|
+
export declare function reverseSiteCareCharge(firestore: FirebaseFirestore.Firestore, input: {
|
|
169
|
+
ticketId: string;
|
|
170
|
+
actor: SiteCareActor;
|
|
171
|
+
reason: unknown;
|
|
172
|
+
absorb?: boolean;
|
|
173
|
+
}, deps?: SiteCareDeps): Promise<SiteCareCharge>;
|
|
174
|
+
/** Adds included minutes to a workspace's month, with a reason. */
|
|
175
|
+
export declare function addSiteCareGoodwill(firestore: FirebaseFirestore.Firestore, input: {
|
|
176
|
+
orgId: string;
|
|
177
|
+
month: unknown;
|
|
178
|
+
minutes: unknown;
|
|
179
|
+
reason: unknown;
|
|
180
|
+
actor: SiteCareActor;
|
|
181
|
+
}, deps?: SiteCareDeps): Promise<{
|
|
182
|
+
goodwillMinutes: number;
|
|
183
|
+
}>;
|
|
184
|
+
export interface SiteCareMonthRequestView {
|
|
185
|
+
ticketId: string;
|
|
186
|
+
subject: string;
|
|
187
|
+
status: string;
|
|
188
|
+
request: SiteCareRequest;
|
|
189
|
+
history: Array<AppendOnlyHistoryRow & {
|
|
190
|
+
$id: string;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
export interface SiteCareMonthView {
|
|
194
|
+
orgId: string;
|
|
195
|
+
month: string;
|
|
196
|
+
statement: SiteCareMonthStatement;
|
|
197
|
+
goodwillMinutes: number;
|
|
198
|
+
requests: SiteCareMonthRequestView[];
|
|
199
|
+
monthHistory: Array<AppendOnlyHistoryRow & {
|
|
200
|
+
$id: string;
|
|
201
|
+
}>;
|
|
202
|
+
}
|
|
203
|
+
/** Every request of a workspace's month, each with its history, and the totals. */
|
|
204
|
+
export declare function readSiteCareMonth(firestore: FirebaseFirestore.Firestore, input: {
|
|
205
|
+
orgId: string;
|
|
206
|
+
month: string;
|
|
207
|
+
}): Promise<SiteCareMonthView>;
|
|
208
|
+
/** One request as the statement lists it, in the owner's words. */
|
|
209
|
+
export declare function siteCareStatementLine(view: SiteCareMonthRequestView): string;
|
|
210
|
+
/** Every recorded row of the month, oldest first, as dated lines. */
|
|
211
|
+
export declare function siteCareStatementHistory(view: SiteCareMonthView): string[];
|
|
212
|
+
/** Emails the owner the month's statement, on demand. */
|
|
213
|
+
export declare function sendSiteCareStatement(firestore: FirebaseFirestore.Firestore, input: {
|
|
214
|
+
orgId: string;
|
|
215
|
+
month: string;
|
|
216
|
+
actor: SiteCareActor;
|
|
217
|
+
}, deps?: SiteCareDeps): Promise<SiteCareEmailResult>;
|
|
218
|
+
/**
|
|
219
|
+
* "This one is bigger than Site Care covers, here is the quote": staff send
|
|
220
|
+
* it from the request; it lands on the thread and in the owner's inbox. The
|
|
221
|
+
* invoice itself is the staff "Charge for work" (AGL-3970).
|
|
222
|
+
*/
|
|
223
|
+
export declare function sendSiteCareQuote(firestore: FirebaseFirestore.Firestore, input: {
|
|
224
|
+
ticketId: string;
|
|
225
|
+
actor: SiteCareActor;
|
|
226
|
+
amountUsd: unknown;
|
|
227
|
+
scope: unknown;
|
|
228
|
+
}, deps?: SiteCareDeps): Promise<SiteCareEmailResult>;
|
|
229
|
+
export interface SiteCareRequestPanel {
|
|
230
|
+
ticketId: string;
|
|
231
|
+
orgId: string;
|
|
232
|
+
subject: string;
|
|
233
|
+
request: SiteCareRequest;
|
|
234
|
+
history: Array<AppendOnlyHistoryRow & {
|
|
235
|
+
$id: string;
|
|
236
|
+
}>;
|
|
237
|
+
/** The close's prefilled number, from the timer. */
|
|
238
|
+
suggestedMinutes: number;
|
|
239
|
+
/** What this request's month looks like with its other requests. */
|
|
240
|
+
monthMinutesLeft: number;
|
|
241
|
+
}
|
|
242
|
+
/** Everything the staff panel shows for one request. */
|
|
243
|
+
export declare function readSiteCareRequestPanel(firestore: FirebaseFirestore.Firestore, ticketId: string, deps?: SiteCareDeps): Promise<SiteCareRequestPanel>;
|