@aglyn/tenant-data-admin 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.
- 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/domain-ownership.d.ts +205 -0
- package/src/lib/server/domain-ownership.js +575 -0
- package/src/lib/server/domain-ownership.js.map +1 -0
- package/src/lib/server/erase.d.ts +17 -0
- package/src/lib/server/erase.js +21 -0
- package/src/lib/server/erase.js.map +1 -1
- 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 +53 -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 +123 -0
- package/src/lib/server/site-care-inbound.js +197 -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/sso-provisioning.d.ts +6 -0
- package/src/lib/server/sso-provisioning.js +7 -0
- package/src/lib/server/sso-provisioning.js.map +1 -1
- 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,169 @@
|
|
|
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 SiteCareProject, type SiteCareProjectAcceptance, type SiteCareProjectInvoice } from '@aglyn/aglyn/app-utils/site-care-project';
|
|
19
|
+
import { type SiteCareEmailResult } from './site-care-emails';
|
|
20
|
+
import { type SiteCareActor, type SiteCareDeps } from './site-care-requests';
|
|
21
|
+
/**
|
|
22
|
+
* SITE CARE PROJECTS, WITH FIRESTORE AND STRIPE (AGL-3970).
|
|
23
|
+
*
|
|
24
|
+
* The staff "Charge for work": a flat-quoted project on the org
|
|
25
|
+
* (`orgs/{orgId}/siteCareProjects/{id}`) holding the scope, the quote, the
|
|
26
|
+
* owner's recorded yes, every invoice it raised and the launch, with an
|
|
27
|
+
* append-only history beside it (`…/siteCareProjects/{id}/siteCareHistory`).
|
|
28
|
+
* None of it is in the Firestore rules: every read and write passes the
|
|
29
|
+
* console's routes, as Site Care requests do.
|
|
30
|
+
*
|
|
31
|
+
* The same discipline as Site Care extra time, from the same modules:
|
|
32
|
+
* every change writes its history row in the same batch or transaction as
|
|
33
|
+
* the change, and a staff member's change writes its `adminAudit` row there
|
|
34
|
+
* too. Money moves in two steps around the Stripe calls — a `creating`
|
|
35
|
+
* invoice and its `invoice.requested` row commit first, then the calls under
|
|
36
|
+
* the invoice's own idempotency key, then the result and its row together —
|
|
37
|
+
* so a success with no row behind it is a `creating` invoice the
|
|
38
|
+
* reconciliation reports and a retry adopts. Reversals write their intent
|
|
39
|
+
* row before the call, keyed by the invoice's own key.
|
|
40
|
+
*
|
|
41
|
+
* The arithmetic is `@aglyn/aglyn/app-utils/site-care-project`, the yes
|
|
42
|
+
* `owner-approval-record`, the row `append-only-history`, the Stripe calls
|
|
43
|
+
* `site-care-project-stripe.ts`.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SITE_CARE_PROJECTS_COLLECTION = "siteCareProjects";
|
|
46
|
+
export interface SiteCareProjectQuoteInput {
|
|
47
|
+
title: unknown;
|
|
48
|
+
scope: unknown;
|
|
49
|
+
kind: unknown;
|
|
50
|
+
estimatedHours: unknown;
|
|
51
|
+
/** A price above the computed one; blank means the computed one. */
|
|
52
|
+
priceUsd?: unknown;
|
|
53
|
+
}
|
|
54
|
+
/** Quotes a project on a workspace. Nothing bills until the owner's yes is recorded. */
|
|
55
|
+
export declare function createSiteCareProject(firestore: FirebaseFirestore.Firestore, input: SiteCareProjectQuoteInput & {
|
|
56
|
+
orgId: string;
|
|
57
|
+
actor: SiteCareActor;
|
|
58
|
+
}, deps?: SiteCareDeps): Promise<{
|
|
59
|
+
projectId: string;
|
|
60
|
+
project: SiteCareProject;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Changes a project's name, scope or price, with a reason — only until the
|
|
64
|
+
* first invoice is sent. Any change is a new quote version, so a yes the
|
|
65
|
+
* owner gave to the old one no longer invoices anything.
|
|
66
|
+
*/
|
|
67
|
+
export declare function editSiteCareProject(firestore: FirebaseFirestore.Firestore, input: SiteCareProjectQuoteInput & {
|
|
68
|
+
orgId: string;
|
|
69
|
+
projectId: string;
|
|
70
|
+
actor: SiteCareActor;
|
|
71
|
+
reason: unknown;
|
|
72
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProject>;
|
|
73
|
+
/**
|
|
74
|
+
* Records — or corrects — how and when the owner accepted the quote as it
|
|
75
|
+
* stands, and emails them the confirmation of the scope and price that is
|
|
76
|
+
* the written record. Nothing is invoiced before this.
|
|
77
|
+
*/
|
|
78
|
+
export declare function recordSiteCareProjectAcceptance(firestore: FirebaseFirestore.Firestore, input: {
|
|
79
|
+
orgId: string;
|
|
80
|
+
projectId: string;
|
|
81
|
+
actor: SiteCareActor & {
|
|
82
|
+
uid: string;
|
|
83
|
+
};
|
|
84
|
+
acceptance: Record<string, unknown>;
|
|
85
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProjectAcceptance>;
|
|
86
|
+
/**
|
|
87
|
+
* Raises the project's next invoice — the whole price, or the deposit —
|
|
88
|
+
* on the owner's current yes, and emails them the pay link.
|
|
89
|
+
*/
|
|
90
|
+
export declare function sendSiteCareProjectInvoice(firestore: FirebaseFirestore.Firestore, input: {
|
|
91
|
+
orgId: string;
|
|
92
|
+
projectId: string;
|
|
93
|
+
actor: SiteCareActor;
|
|
94
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProjectInvoice>;
|
|
95
|
+
/** Re-runs an invoice that failed, or whose result never landed, under its own key. */
|
|
96
|
+
export declare function retrySiteCareProjectInvoice(firestore: FirebaseFirestore.Firestore, input: {
|
|
97
|
+
orgId: string;
|
|
98
|
+
projectId: string;
|
|
99
|
+
seq: number;
|
|
100
|
+
actor: SiteCareActor;
|
|
101
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProjectInvoice>;
|
|
102
|
+
/** Emails the owner an open invoice's pay link again. */
|
|
103
|
+
export declare function resendSiteCareProjectInvoice(firestore: FirebaseFirestore.Firestore, input: {
|
|
104
|
+
orgId: string;
|
|
105
|
+
projectId: string;
|
|
106
|
+
seq: number;
|
|
107
|
+
actor: SiteCareActor;
|
|
108
|
+
}, deps?: SiteCareDeps): Promise<SiteCareEmailResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Marks the project launched. A half-and-half project raises its balance
|
|
111
|
+
* invoice from the same record, in the same step, and emails the pay link.
|
|
112
|
+
* Launch comes after the first invoice is paid: both splits are paid up
|
|
113
|
+
* front before work starts.
|
|
114
|
+
*/
|
|
115
|
+
export declare function launchSiteCareProject(firestore: FirebaseFirestore.Firestore, input: {
|
|
116
|
+
orgId: string;
|
|
117
|
+
projectId: string;
|
|
118
|
+
actor: SiteCareActor;
|
|
119
|
+
}, deps?: SiteCareDeps): Promise<{
|
|
120
|
+
project: SiteCareProject;
|
|
121
|
+
invoice: SiteCareProjectInvoice | null;
|
|
122
|
+
}>;
|
|
123
|
+
export type SiteCareProjectPaymentOutcome = 'recorded' | 'already' | 'ignored';
|
|
124
|
+
/**
|
|
125
|
+
* Records a project invoice as paid — from the billing webhook's
|
|
126
|
+
* `invoice.paid`, or from staff's "Check payments" when a delivery was
|
|
127
|
+
* missed — and emails the owner the receipt. Idempotent: a redelivery of a
|
|
128
|
+
* payment already recorded changes nothing and sends nothing.
|
|
129
|
+
*/
|
|
130
|
+
export declare function recordSiteCareProjectPayment(firestore: FirebaseFirestore.Firestore, input: {
|
|
131
|
+
orgId: string;
|
|
132
|
+
invoiceId: string;
|
|
133
|
+
metadata: Readonly<Record<string, string>>;
|
|
134
|
+
amountPaidCents: number;
|
|
135
|
+
paidOutOfBand?: boolean;
|
|
136
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProjectPaymentOutcome>;
|
|
137
|
+
/**
|
|
138
|
+
* Reads each unpaid invoice of a project from Stripe and records any that
|
|
139
|
+
* were paid, for a webhook delivery that never arrived.
|
|
140
|
+
*/
|
|
141
|
+
export declare function checkSiteCareProjectPayments(firestore: FirebaseFirestore.Firestore, input: {
|
|
142
|
+
orgId: string;
|
|
143
|
+
projectId: string;
|
|
144
|
+
}, deps?: SiteCareDeps): Promise<{
|
|
145
|
+
recorded: number;
|
|
146
|
+
}>;
|
|
147
|
+
export type SiteCareProjectReversal = 'void' | 'credit' | 'refund';
|
|
148
|
+
/**
|
|
149
|
+
* Voids an unpaid invoice, credits it, or refunds a paid one — from the
|
|
150
|
+
* record, with a reason, never by hand in Stripe. The intent row commits
|
|
151
|
+
* before the call; the owner is emailed the outcome.
|
|
152
|
+
*/
|
|
153
|
+
export declare function reverseSiteCareProjectInvoice(firestore: FirebaseFirestore.Firestore, input: {
|
|
154
|
+
orgId: string;
|
|
155
|
+
projectId: string;
|
|
156
|
+
seq: number;
|
|
157
|
+
actor: SiteCareActor;
|
|
158
|
+
action: unknown;
|
|
159
|
+
reason: unknown;
|
|
160
|
+
}, deps?: SiteCareDeps): Promise<SiteCareProjectInvoice>;
|
|
161
|
+
export interface SiteCareProjectView {
|
|
162
|
+
projectId: string;
|
|
163
|
+
project: SiteCareProject;
|
|
164
|
+
history: Array<AppendOnlyHistoryRow & {
|
|
165
|
+
$id: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
/** A workspace's projects, newest first, each with its history. */
|
|
169
|
+
export declare function readSiteCareProjects(firestore: FirebaseFirestore.Firestore, orgId: string): Promise<SiteCareProjectView[]>;
|