@alethialabs/platform 0.0.0-stage → 0.1.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.
- package/LICENSE +661 -0
- package/README.md +2 -2
- package/dist/enums.d.ts +8 -0
- package/dist/enums.js +17 -0
- package/dist/schema.d.ts +517 -0
- package/dist/schema.js +79 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +3 -0
- package/package.json +42 -5
package/dist/enums.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Alethia Labs <legal@alethialabs.io>
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
// Enums owned by the platform-operator plane. Deliberately does NOT re-declare the console's
|
|
4
|
+
// `billing_plan` — this package must stay self-contained (it cannot import console enums, and
|
|
5
|
+
// re-declaring one would make drizzle-kit emit a duplicate type). `plan` / `currency` are plain
|
|
6
|
+
// text columns, validated against an allow-list in the operator app.
|
|
7
|
+
import { pgEnum } from "drizzle-orm/pg-core";
|
|
8
|
+
/**
|
|
9
|
+
* How a contract is paid.
|
|
10
|
+
* - `stripe` — Stripe Invoicing (collection_method: send_invoice); the console webhook
|
|
11
|
+
* activates the plan when the subscription goes live.
|
|
12
|
+
* - `external` — off-Stripe (bank transfer / Odoo фактура); the operator sets the plan directly.
|
|
13
|
+
*/
|
|
14
|
+
export const platformCollectionMethod = pgEnum("platform_collection_method", [
|
|
15
|
+
"stripe",
|
|
16
|
+
"external",
|
|
17
|
+
]);
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import type { PlatformAuditInput } from "./types";
|
|
2
|
+
export { platformCollectionMethod } from "./enums";
|
|
3
|
+
/**
|
|
4
|
+
* The Enterprise contract an operator recorded for an org: what was agreed, for how long, how it's
|
|
5
|
+
* paid, and the external refs. Drives the org-detail contract history and (via `term_end`) the
|
|
6
|
+
* off-Stripe lapse the console already enforces in `isManualGrantExpired`.
|
|
7
|
+
*
|
|
8
|
+
* NO foreign key to `organization` — this package can't import the console's tables, and a business
|
|
9
|
+
* /forensic record shouldn't be cascade-deleted with the org it describes (same rationale as
|
|
10
|
+
* breakglass_audit). Referential integrity is enforced by the operator flow.
|
|
11
|
+
*/
|
|
12
|
+
export declare const enterpriseContract: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
13
|
+
name: "enterprise_contract";
|
|
14
|
+
schema: undefined;
|
|
15
|
+
columns: {
|
|
16
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
17
|
+
name: "id";
|
|
18
|
+
tableName: "enterprise_contract";
|
|
19
|
+
dataType: "string";
|
|
20
|
+
columnType: "PgUUID";
|
|
21
|
+
data: string;
|
|
22
|
+
driverParam: string;
|
|
23
|
+
notNull: true;
|
|
24
|
+
hasDefault: true;
|
|
25
|
+
isPrimaryKey: true;
|
|
26
|
+
isAutoincrement: false;
|
|
27
|
+
hasRuntimeDefault: false;
|
|
28
|
+
enumValues: undefined;
|
|
29
|
+
baseColumn: never;
|
|
30
|
+
identity: undefined;
|
|
31
|
+
generated: undefined;
|
|
32
|
+
}, {}, {}>;
|
|
33
|
+
organizationId: import("drizzle-orm/pg-core").PgColumn<{
|
|
34
|
+
name: "organizationId";
|
|
35
|
+
tableName: "enterprise_contract";
|
|
36
|
+
dataType: "string";
|
|
37
|
+
columnType: "PgUUID";
|
|
38
|
+
data: string;
|
|
39
|
+
driverParam: string;
|
|
40
|
+
notNull: true;
|
|
41
|
+
hasDefault: false;
|
|
42
|
+
isPrimaryKey: false;
|
|
43
|
+
isAutoincrement: false;
|
|
44
|
+
hasRuntimeDefault: false;
|
|
45
|
+
enumValues: undefined;
|
|
46
|
+
baseColumn: never;
|
|
47
|
+
identity: undefined;
|
|
48
|
+
generated: undefined;
|
|
49
|
+
}, {}, {}>;
|
|
50
|
+
plan: import("drizzle-orm/pg-core").PgColumn<{
|
|
51
|
+
name: "plan";
|
|
52
|
+
tableName: "enterprise_contract";
|
|
53
|
+
dataType: "string";
|
|
54
|
+
columnType: "PgText";
|
|
55
|
+
data: string;
|
|
56
|
+
driverParam: string;
|
|
57
|
+
notNull: true;
|
|
58
|
+
hasDefault: false;
|
|
59
|
+
isPrimaryKey: false;
|
|
60
|
+
isAutoincrement: false;
|
|
61
|
+
hasRuntimeDefault: false;
|
|
62
|
+
enumValues: [string, ...string[]];
|
|
63
|
+
baseColumn: never;
|
|
64
|
+
identity: undefined;
|
|
65
|
+
generated: undefined;
|
|
66
|
+
}, {}, {}>;
|
|
67
|
+
seats: import("drizzle-orm/pg-core").PgColumn<{
|
|
68
|
+
name: "seats";
|
|
69
|
+
tableName: "enterprise_contract";
|
|
70
|
+
dataType: "number";
|
|
71
|
+
columnType: "PgBigInt53";
|
|
72
|
+
data: number;
|
|
73
|
+
driverParam: string | number;
|
|
74
|
+
notNull: false;
|
|
75
|
+
hasDefault: false;
|
|
76
|
+
isPrimaryKey: false;
|
|
77
|
+
isAutoincrement: false;
|
|
78
|
+
hasRuntimeDefault: false;
|
|
79
|
+
enumValues: undefined;
|
|
80
|
+
baseColumn: never;
|
|
81
|
+
identity: undefined;
|
|
82
|
+
generated: undefined;
|
|
83
|
+
}, {}, {}>;
|
|
84
|
+
termStart: import("drizzle-orm/pg-core").PgColumn<{
|
|
85
|
+
name: "termStart";
|
|
86
|
+
tableName: "enterprise_contract";
|
|
87
|
+
dataType: "date";
|
|
88
|
+
columnType: "PgTimestamp";
|
|
89
|
+
data: Date;
|
|
90
|
+
driverParam: string;
|
|
91
|
+
notNull: true;
|
|
92
|
+
hasDefault: false;
|
|
93
|
+
isPrimaryKey: false;
|
|
94
|
+
isAutoincrement: false;
|
|
95
|
+
hasRuntimeDefault: false;
|
|
96
|
+
enumValues: undefined;
|
|
97
|
+
baseColumn: never;
|
|
98
|
+
identity: undefined;
|
|
99
|
+
generated: undefined;
|
|
100
|
+
}, {}, {}>;
|
|
101
|
+
termEnd: import("drizzle-orm/pg-core").PgColumn<{
|
|
102
|
+
name: "termEnd";
|
|
103
|
+
tableName: "enterprise_contract";
|
|
104
|
+
dataType: "date";
|
|
105
|
+
columnType: "PgTimestamp";
|
|
106
|
+
data: Date;
|
|
107
|
+
driverParam: string;
|
|
108
|
+
notNull: false;
|
|
109
|
+
hasDefault: false;
|
|
110
|
+
isPrimaryKey: false;
|
|
111
|
+
isAutoincrement: false;
|
|
112
|
+
hasRuntimeDefault: false;
|
|
113
|
+
enumValues: undefined;
|
|
114
|
+
baseColumn: never;
|
|
115
|
+
identity: undefined;
|
|
116
|
+
generated: undefined;
|
|
117
|
+
}, {}, {}>;
|
|
118
|
+
collectionMethod: import("drizzle-orm/pg-core").PgColumn<{
|
|
119
|
+
name: "collectionMethod";
|
|
120
|
+
tableName: "enterprise_contract";
|
|
121
|
+
dataType: "string";
|
|
122
|
+
columnType: "PgEnumColumn";
|
|
123
|
+
data: "stripe" | "external";
|
|
124
|
+
driverParam: string;
|
|
125
|
+
notNull: true;
|
|
126
|
+
hasDefault: false;
|
|
127
|
+
isPrimaryKey: false;
|
|
128
|
+
isAutoincrement: false;
|
|
129
|
+
hasRuntimeDefault: false;
|
|
130
|
+
enumValues: ["stripe", "external"];
|
|
131
|
+
baseColumn: never;
|
|
132
|
+
identity: undefined;
|
|
133
|
+
generated: undefined;
|
|
134
|
+
}, {}, {}>;
|
|
135
|
+
amountCents: import("drizzle-orm/pg-core").PgColumn<{
|
|
136
|
+
name: "amountCents";
|
|
137
|
+
tableName: "enterprise_contract";
|
|
138
|
+
dataType: "number";
|
|
139
|
+
columnType: "PgBigInt53";
|
|
140
|
+
data: number;
|
|
141
|
+
driverParam: string | number;
|
|
142
|
+
notNull: false;
|
|
143
|
+
hasDefault: false;
|
|
144
|
+
isPrimaryKey: false;
|
|
145
|
+
isAutoincrement: false;
|
|
146
|
+
hasRuntimeDefault: false;
|
|
147
|
+
enumValues: undefined;
|
|
148
|
+
baseColumn: never;
|
|
149
|
+
identity: undefined;
|
|
150
|
+
generated: undefined;
|
|
151
|
+
}, {}, {}>;
|
|
152
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
153
|
+
name: "currency";
|
|
154
|
+
tableName: "enterprise_contract";
|
|
155
|
+
dataType: "string";
|
|
156
|
+
columnType: "PgText";
|
|
157
|
+
data: string;
|
|
158
|
+
driverParam: string;
|
|
159
|
+
notNull: true;
|
|
160
|
+
hasDefault: true;
|
|
161
|
+
isPrimaryKey: false;
|
|
162
|
+
isAutoincrement: false;
|
|
163
|
+
hasRuntimeDefault: false;
|
|
164
|
+
enumValues: [string, ...string[]];
|
|
165
|
+
baseColumn: never;
|
|
166
|
+
identity: undefined;
|
|
167
|
+
generated: undefined;
|
|
168
|
+
}, {}, {}>;
|
|
169
|
+
contractRef: import("drizzle-orm/pg-core").PgColumn<{
|
|
170
|
+
name: "contractRef";
|
|
171
|
+
tableName: "enterprise_contract";
|
|
172
|
+
dataType: "string";
|
|
173
|
+
columnType: "PgText";
|
|
174
|
+
data: string;
|
|
175
|
+
driverParam: string;
|
|
176
|
+
notNull: false;
|
|
177
|
+
hasDefault: false;
|
|
178
|
+
isPrimaryKey: false;
|
|
179
|
+
isAutoincrement: false;
|
|
180
|
+
hasRuntimeDefault: false;
|
|
181
|
+
enumValues: [string, ...string[]];
|
|
182
|
+
baseColumn: never;
|
|
183
|
+
identity: undefined;
|
|
184
|
+
generated: undefined;
|
|
185
|
+
}, {}, {}>;
|
|
186
|
+
invoiceRef: import("drizzle-orm/pg-core").PgColumn<{
|
|
187
|
+
name: "invoiceRef";
|
|
188
|
+
tableName: "enterprise_contract";
|
|
189
|
+
dataType: "string";
|
|
190
|
+
columnType: "PgText";
|
|
191
|
+
data: string;
|
|
192
|
+
driverParam: string;
|
|
193
|
+
notNull: false;
|
|
194
|
+
hasDefault: false;
|
|
195
|
+
isPrimaryKey: false;
|
|
196
|
+
isAutoincrement: false;
|
|
197
|
+
hasRuntimeDefault: false;
|
|
198
|
+
enumValues: [string, ...string[]];
|
|
199
|
+
baseColumn: never;
|
|
200
|
+
identity: undefined;
|
|
201
|
+
generated: undefined;
|
|
202
|
+
}, {}, {}>;
|
|
203
|
+
notes: import("drizzle-orm/pg-core").PgColumn<{
|
|
204
|
+
name: "notes";
|
|
205
|
+
tableName: "enterprise_contract";
|
|
206
|
+
dataType: "string";
|
|
207
|
+
columnType: "PgText";
|
|
208
|
+
data: string;
|
|
209
|
+
driverParam: string;
|
|
210
|
+
notNull: false;
|
|
211
|
+
hasDefault: false;
|
|
212
|
+
isPrimaryKey: false;
|
|
213
|
+
isAutoincrement: false;
|
|
214
|
+
hasRuntimeDefault: false;
|
|
215
|
+
enumValues: [string, ...string[]];
|
|
216
|
+
baseColumn: never;
|
|
217
|
+
identity: undefined;
|
|
218
|
+
generated: undefined;
|
|
219
|
+
}, {}, {}>;
|
|
220
|
+
stripeCustomerId: import("drizzle-orm/pg-core").PgColumn<{
|
|
221
|
+
name: "stripeCustomerId";
|
|
222
|
+
tableName: "enterprise_contract";
|
|
223
|
+
dataType: "string";
|
|
224
|
+
columnType: "PgText";
|
|
225
|
+
data: string;
|
|
226
|
+
driverParam: string;
|
|
227
|
+
notNull: false;
|
|
228
|
+
hasDefault: false;
|
|
229
|
+
isPrimaryKey: false;
|
|
230
|
+
isAutoincrement: false;
|
|
231
|
+
hasRuntimeDefault: false;
|
|
232
|
+
enumValues: [string, ...string[]];
|
|
233
|
+
baseColumn: never;
|
|
234
|
+
identity: undefined;
|
|
235
|
+
generated: undefined;
|
|
236
|
+
}, {}, {}>;
|
|
237
|
+
stripeSubscriptionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
238
|
+
name: "stripeSubscriptionId";
|
|
239
|
+
tableName: "enterprise_contract";
|
|
240
|
+
dataType: "string";
|
|
241
|
+
columnType: "PgText";
|
|
242
|
+
data: string;
|
|
243
|
+
driverParam: string;
|
|
244
|
+
notNull: false;
|
|
245
|
+
hasDefault: false;
|
|
246
|
+
isPrimaryKey: false;
|
|
247
|
+
isAutoincrement: false;
|
|
248
|
+
hasRuntimeDefault: false;
|
|
249
|
+
enumValues: [string, ...string[]];
|
|
250
|
+
baseColumn: never;
|
|
251
|
+
identity: undefined;
|
|
252
|
+
generated: undefined;
|
|
253
|
+
}, {}, {}>;
|
|
254
|
+
createdByEmail: import("drizzle-orm/pg-core").PgColumn<{
|
|
255
|
+
name: "createdByEmail";
|
|
256
|
+
tableName: "enterprise_contract";
|
|
257
|
+
dataType: "string";
|
|
258
|
+
columnType: "PgText";
|
|
259
|
+
data: string;
|
|
260
|
+
driverParam: string;
|
|
261
|
+
notNull: true;
|
|
262
|
+
hasDefault: false;
|
|
263
|
+
isPrimaryKey: false;
|
|
264
|
+
isAutoincrement: false;
|
|
265
|
+
hasRuntimeDefault: false;
|
|
266
|
+
enumValues: [string, ...string[]];
|
|
267
|
+
baseColumn: never;
|
|
268
|
+
identity: undefined;
|
|
269
|
+
generated: undefined;
|
|
270
|
+
}, {}, {}>;
|
|
271
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
272
|
+
name: "createdAt";
|
|
273
|
+
tableName: "enterprise_contract";
|
|
274
|
+
dataType: "date";
|
|
275
|
+
columnType: "PgTimestamp";
|
|
276
|
+
data: Date;
|
|
277
|
+
driverParam: string;
|
|
278
|
+
notNull: true;
|
|
279
|
+
hasDefault: true;
|
|
280
|
+
isPrimaryKey: false;
|
|
281
|
+
isAutoincrement: false;
|
|
282
|
+
hasRuntimeDefault: false;
|
|
283
|
+
enumValues: undefined;
|
|
284
|
+
baseColumn: never;
|
|
285
|
+
identity: undefined;
|
|
286
|
+
generated: undefined;
|
|
287
|
+
}, {}, {}>;
|
|
288
|
+
revokedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
289
|
+
name: "revokedAt";
|
|
290
|
+
tableName: "enterprise_contract";
|
|
291
|
+
dataType: "date";
|
|
292
|
+
columnType: "PgTimestamp";
|
|
293
|
+
data: Date;
|
|
294
|
+
driverParam: string;
|
|
295
|
+
notNull: false;
|
|
296
|
+
hasDefault: false;
|
|
297
|
+
isPrimaryKey: false;
|
|
298
|
+
isAutoincrement: false;
|
|
299
|
+
hasRuntimeDefault: false;
|
|
300
|
+
enumValues: undefined;
|
|
301
|
+
baseColumn: never;
|
|
302
|
+
identity: undefined;
|
|
303
|
+
generated: undefined;
|
|
304
|
+
}, {}, {}>;
|
|
305
|
+
revokedByEmail: import("drizzle-orm/pg-core").PgColumn<{
|
|
306
|
+
name: "revokedByEmail";
|
|
307
|
+
tableName: "enterprise_contract";
|
|
308
|
+
dataType: "string";
|
|
309
|
+
columnType: "PgText";
|
|
310
|
+
data: string;
|
|
311
|
+
driverParam: string;
|
|
312
|
+
notNull: false;
|
|
313
|
+
hasDefault: false;
|
|
314
|
+
isPrimaryKey: false;
|
|
315
|
+
isAutoincrement: false;
|
|
316
|
+
hasRuntimeDefault: false;
|
|
317
|
+
enumValues: [string, ...string[]];
|
|
318
|
+
baseColumn: never;
|
|
319
|
+
identity: undefined;
|
|
320
|
+
generated: undefined;
|
|
321
|
+
}, {}, {}>;
|
|
322
|
+
};
|
|
323
|
+
dialect: "pg";
|
|
324
|
+
}>;
|
|
325
|
+
/**
|
|
326
|
+
* Append-only WORM audit of every platform-operator mutation. One row is committed BEFORE the act
|
|
327
|
+
* (`phase='attempt'`, so a mutation that crashes mid-flight is still on record) and a second after
|
|
328
|
+
* (`phase='result'` with the outcome) — never an UPDATE. `reason` is REQUIRED.
|
|
329
|
+
*
|
|
330
|
+
* Immutability is enforced by a BEFORE UPDATE OR DELETE / TRUNCATE trigger in the console's
|
|
331
|
+
* programmables.sql (copied from breakglass_audit) — triggers are NOT bypassed by BYPASSRLS, so the
|
|
332
|
+
* row is immutable even to the service role that writes it. Like `enterprise_contract`, it carries
|
|
333
|
+
* no FK: an ON DELETE action would trip that trigger and jam the parent delete.
|
|
334
|
+
*/
|
|
335
|
+
export declare const platformAudit: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
336
|
+
name: "platform_audit";
|
|
337
|
+
schema: undefined;
|
|
338
|
+
columns: {
|
|
339
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
340
|
+
name: "id";
|
|
341
|
+
tableName: "platform_audit";
|
|
342
|
+
dataType: "number";
|
|
343
|
+
columnType: "PgBigInt53";
|
|
344
|
+
data: number;
|
|
345
|
+
driverParam: string | number;
|
|
346
|
+
notNull: true;
|
|
347
|
+
hasDefault: true;
|
|
348
|
+
isPrimaryKey: true;
|
|
349
|
+
isAutoincrement: false;
|
|
350
|
+
hasRuntimeDefault: false;
|
|
351
|
+
enumValues: undefined;
|
|
352
|
+
baseColumn: never;
|
|
353
|
+
identity: "byDefault";
|
|
354
|
+
generated: undefined;
|
|
355
|
+
}, {}, {}>;
|
|
356
|
+
actorEmail: import("drizzle-orm/pg-core").PgColumn<{
|
|
357
|
+
name: "actorEmail";
|
|
358
|
+
tableName: "platform_audit";
|
|
359
|
+
dataType: "string";
|
|
360
|
+
columnType: "PgText";
|
|
361
|
+
data: string;
|
|
362
|
+
driverParam: string;
|
|
363
|
+
notNull: true;
|
|
364
|
+
hasDefault: false;
|
|
365
|
+
isPrimaryKey: false;
|
|
366
|
+
isAutoincrement: false;
|
|
367
|
+
hasRuntimeDefault: false;
|
|
368
|
+
enumValues: [string, ...string[]];
|
|
369
|
+
baseColumn: never;
|
|
370
|
+
identity: undefined;
|
|
371
|
+
generated: undefined;
|
|
372
|
+
}, {}, {}>;
|
|
373
|
+
action: import("drizzle-orm/pg-core").PgColumn<{
|
|
374
|
+
name: "action";
|
|
375
|
+
tableName: "platform_audit";
|
|
376
|
+
dataType: "string";
|
|
377
|
+
columnType: "PgText";
|
|
378
|
+
data: string;
|
|
379
|
+
driverParam: string;
|
|
380
|
+
notNull: true;
|
|
381
|
+
hasDefault: false;
|
|
382
|
+
isPrimaryKey: false;
|
|
383
|
+
isAutoincrement: false;
|
|
384
|
+
hasRuntimeDefault: false;
|
|
385
|
+
enumValues: [string, ...string[]];
|
|
386
|
+
baseColumn: never;
|
|
387
|
+
identity: undefined;
|
|
388
|
+
generated: undefined;
|
|
389
|
+
}, {}, {}>;
|
|
390
|
+
targetOrgId: import("drizzle-orm/pg-core").PgColumn<{
|
|
391
|
+
name: "targetOrgId";
|
|
392
|
+
tableName: "platform_audit";
|
|
393
|
+
dataType: "string";
|
|
394
|
+
columnType: "PgUUID";
|
|
395
|
+
data: string;
|
|
396
|
+
driverParam: string;
|
|
397
|
+
notNull: false;
|
|
398
|
+
hasDefault: false;
|
|
399
|
+
isPrimaryKey: false;
|
|
400
|
+
isAutoincrement: false;
|
|
401
|
+
hasRuntimeDefault: false;
|
|
402
|
+
enumValues: undefined;
|
|
403
|
+
baseColumn: never;
|
|
404
|
+
identity: undefined;
|
|
405
|
+
generated: undefined;
|
|
406
|
+
}, {}, {}>;
|
|
407
|
+
input: import("drizzle-orm/pg-core").PgColumn<{
|
|
408
|
+
name: "input";
|
|
409
|
+
tableName: "platform_audit";
|
|
410
|
+
dataType: "json";
|
|
411
|
+
columnType: "PgJsonb";
|
|
412
|
+
data: PlatformAuditInput;
|
|
413
|
+
driverParam: unknown;
|
|
414
|
+
notNull: false;
|
|
415
|
+
hasDefault: false;
|
|
416
|
+
isPrimaryKey: false;
|
|
417
|
+
isAutoincrement: false;
|
|
418
|
+
hasRuntimeDefault: false;
|
|
419
|
+
enumValues: undefined;
|
|
420
|
+
baseColumn: never;
|
|
421
|
+
identity: undefined;
|
|
422
|
+
generated: undefined;
|
|
423
|
+
}, {}, {
|
|
424
|
+
$type: PlatformAuditInput;
|
|
425
|
+
}>;
|
|
426
|
+
reason: import("drizzle-orm/pg-core").PgColumn<{
|
|
427
|
+
name: "reason";
|
|
428
|
+
tableName: "platform_audit";
|
|
429
|
+
dataType: "string";
|
|
430
|
+
columnType: "PgText";
|
|
431
|
+
data: string;
|
|
432
|
+
driverParam: string;
|
|
433
|
+
notNull: true;
|
|
434
|
+
hasDefault: false;
|
|
435
|
+
isPrimaryKey: false;
|
|
436
|
+
isAutoincrement: false;
|
|
437
|
+
hasRuntimeDefault: false;
|
|
438
|
+
enumValues: [string, ...string[]];
|
|
439
|
+
baseColumn: never;
|
|
440
|
+
identity: undefined;
|
|
441
|
+
generated: undefined;
|
|
442
|
+
}, {}, {}>;
|
|
443
|
+
phase: import("drizzle-orm/pg-core").PgColumn<{
|
|
444
|
+
name: "phase";
|
|
445
|
+
tableName: "platform_audit";
|
|
446
|
+
dataType: "string";
|
|
447
|
+
columnType: "PgText";
|
|
448
|
+
data: string;
|
|
449
|
+
driverParam: string;
|
|
450
|
+
notNull: true;
|
|
451
|
+
hasDefault: false;
|
|
452
|
+
isPrimaryKey: false;
|
|
453
|
+
isAutoincrement: false;
|
|
454
|
+
hasRuntimeDefault: false;
|
|
455
|
+
enumValues: [string, ...string[]];
|
|
456
|
+
baseColumn: never;
|
|
457
|
+
identity: undefined;
|
|
458
|
+
generated: undefined;
|
|
459
|
+
}, {}, {}>;
|
|
460
|
+
outcome: import("drizzle-orm/pg-core").PgColumn<{
|
|
461
|
+
name: "outcome";
|
|
462
|
+
tableName: "platform_audit";
|
|
463
|
+
dataType: "string";
|
|
464
|
+
columnType: "PgText";
|
|
465
|
+
data: string;
|
|
466
|
+
driverParam: string;
|
|
467
|
+
notNull: false;
|
|
468
|
+
hasDefault: false;
|
|
469
|
+
isPrimaryKey: false;
|
|
470
|
+
isAutoincrement: false;
|
|
471
|
+
hasRuntimeDefault: false;
|
|
472
|
+
enumValues: [string, ...string[]];
|
|
473
|
+
baseColumn: never;
|
|
474
|
+
identity: undefined;
|
|
475
|
+
generated: undefined;
|
|
476
|
+
}, {}, {}>;
|
|
477
|
+
detail: import("drizzle-orm/pg-core").PgColumn<{
|
|
478
|
+
name: "detail";
|
|
479
|
+
tableName: "platform_audit";
|
|
480
|
+
dataType: "string";
|
|
481
|
+
columnType: "PgText";
|
|
482
|
+
data: string;
|
|
483
|
+
driverParam: string;
|
|
484
|
+
notNull: false;
|
|
485
|
+
hasDefault: false;
|
|
486
|
+
isPrimaryKey: false;
|
|
487
|
+
isAutoincrement: false;
|
|
488
|
+
hasRuntimeDefault: false;
|
|
489
|
+
enumValues: [string, ...string[]];
|
|
490
|
+
baseColumn: never;
|
|
491
|
+
identity: undefined;
|
|
492
|
+
generated: undefined;
|
|
493
|
+
}, {}, {}>;
|
|
494
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
495
|
+
name: "createdAt";
|
|
496
|
+
tableName: "platform_audit";
|
|
497
|
+
dataType: "date";
|
|
498
|
+
columnType: "PgTimestamp";
|
|
499
|
+
data: Date;
|
|
500
|
+
driverParam: string;
|
|
501
|
+
notNull: true;
|
|
502
|
+
hasDefault: true;
|
|
503
|
+
isPrimaryKey: false;
|
|
504
|
+
isAutoincrement: false;
|
|
505
|
+
hasRuntimeDefault: false;
|
|
506
|
+
enumValues: undefined;
|
|
507
|
+
baseColumn: never;
|
|
508
|
+
identity: undefined;
|
|
509
|
+
generated: undefined;
|
|
510
|
+
}, {}, {}>;
|
|
511
|
+
};
|
|
512
|
+
dialect: "pg";
|
|
513
|
+
}>;
|
|
514
|
+
export type EnterpriseContract = typeof enterpriseContract.$inferSelect;
|
|
515
|
+
export type NewEnterpriseContract = typeof enterpriseContract.$inferInsert;
|
|
516
|
+
export type PlatformAuditRow = typeof platformAudit.$inferSelect;
|
|
517
|
+
export type NewPlatformAudit = typeof platformAudit.$inferInsert;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Alethia Labs <legal@alethialabs.io>
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
|
+
// The platform-operator schema — the Enterprise contract record and the append-only audit of every
|
|
4
|
+
// operator mutation. Owned by this package and shared with the staff app (apps/admin), which holds
|
|
5
|
+
// ALL the operator logic; the console re-exports this only so its single drizzle-kit migrator
|
|
6
|
+
// creates the tables (see apps/console/lib/db/schema/platform.ts). The console never reads them.
|
|
7
|
+
//
|
|
8
|
+
// Deliberately self-contained: no imports from the console (no `organization` FK, no billing enums),
|
|
9
|
+
// mirroring @repo/support. `plan`/`currency` are text, validated in the operator app.
|
|
10
|
+
import { bigint, index, jsonb, pgTable, text, timestamp, uuid, } from "drizzle-orm/pg-core";
|
|
11
|
+
import { platformCollectionMethod } from "./enums";
|
|
12
|
+
// Re-exported so the console's schema barrel (which drizzle-kit scans) SEES the pgEnum and emits
|
|
13
|
+
// its CREATE TYPE. Without this the generated migration references the type but never creates it.
|
|
14
|
+
export { platformCollectionMethod } from "./enums";
|
|
15
|
+
/**
|
|
16
|
+
* The Enterprise contract an operator recorded for an org: what was agreed, for how long, how it's
|
|
17
|
+
* paid, and the external refs. Drives the org-detail contract history and (via `term_end`) the
|
|
18
|
+
* off-Stripe lapse the console already enforces in `isManualGrantExpired`.
|
|
19
|
+
*
|
|
20
|
+
* NO foreign key to `organization` — this package can't import the console's tables, and a business
|
|
21
|
+
* /forensic record shouldn't be cascade-deleted with the org it describes (same rationale as
|
|
22
|
+
* breakglass_audit). Referential integrity is enforced by the operator flow.
|
|
23
|
+
*/
|
|
24
|
+
export const enterpriseContract = pgTable("enterprise_contract", {
|
|
25
|
+
id: uuid().primaryKey().defaultRandom(),
|
|
26
|
+
organizationId: uuid().notNull(),
|
|
27
|
+
plan: text().notNull(),
|
|
28
|
+
seats: bigint({ mode: "number" }),
|
|
29
|
+
termStart: timestamp({ withTimezone: true }).notNull(),
|
|
30
|
+
/** null = open-ended (never lapses). */
|
|
31
|
+
termEnd: timestamp({ withTimezone: true }),
|
|
32
|
+
collectionMethod: platformCollectionMethod().notNull(),
|
|
33
|
+
amountCents: bigint({ mode: "number" }),
|
|
34
|
+
currency: text().default("usd").notNull(),
|
|
35
|
+
/** The signed contract / MSA reference. */
|
|
36
|
+
contractRef: text(),
|
|
37
|
+
/** Stripe invoice id, Odoo фактура number, or a bank reference. */
|
|
38
|
+
invoiceRef: text(),
|
|
39
|
+
notes: text(),
|
|
40
|
+
/** Set when collection_method = 'stripe', so the operator can trace the Stripe objects. */
|
|
41
|
+
stripeCustomerId: text(),
|
|
42
|
+
stripeSubscriptionId: text(),
|
|
43
|
+
createdByEmail: text().notNull(),
|
|
44
|
+
createdAt: timestamp({ withTimezone: true }).defaultNow().notNull(),
|
|
45
|
+
revokedAt: timestamp({ withTimezone: true }),
|
|
46
|
+
revokedByEmail: text(),
|
|
47
|
+
}, (t) => [
|
|
48
|
+
index("idx_enterprise_contract_org").on(t.organizationId),
|
|
49
|
+
index("idx_enterprise_contract_term_end").on(t.termEnd),
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* Append-only WORM audit of every platform-operator mutation. One row is committed BEFORE the act
|
|
53
|
+
* (`phase='attempt'`, so a mutation that crashes mid-flight is still on record) and a second after
|
|
54
|
+
* (`phase='result'` with the outcome) — never an UPDATE. `reason` is REQUIRED.
|
|
55
|
+
*
|
|
56
|
+
* Immutability is enforced by a BEFORE UPDATE OR DELETE / TRUNCATE trigger in the console's
|
|
57
|
+
* programmables.sql (copied from breakglass_audit) — triggers are NOT bypassed by BYPASSRLS, so the
|
|
58
|
+
* row is immutable even to the service role that writes it. Like `enterprise_contract`, it carries
|
|
59
|
+
* no FK: an ON DELETE action would trip that trigger and jam the parent delete.
|
|
60
|
+
*/
|
|
61
|
+
export const platformAudit = pgTable("platform_audit", {
|
|
62
|
+
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity(),
|
|
63
|
+
actorEmail: text().notNull(),
|
|
64
|
+
/** grant_enterprise | create_enterprise_org | revoke_contract | … */
|
|
65
|
+
action: text().notNull(),
|
|
66
|
+
/** null only on a create-org attempt (the org id is the result). */
|
|
67
|
+
targetOrgId: uuid(),
|
|
68
|
+
input: jsonb().$type(),
|
|
69
|
+
reason: text().notNull(),
|
|
70
|
+
/** 'attempt' | 'result' */
|
|
71
|
+
phase: text().notNull(),
|
|
72
|
+
/** 'ok' | 'error' — null on an attempt row. */
|
|
73
|
+
outcome: text(),
|
|
74
|
+
detail: text(),
|
|
75
|
+
createdAt: timestamp({ withTimezone: true }).defaultNow().notNull(),
|
|
76
|
+
}, (t) => [
|
|
77
|
+
index("idx_platform_audit_org").on(t.targetOrgId),
|
|
78
|
+
index("idx_platform_audit_created").on(t.createdAt),
|
|
79
|
+
]);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PlatformCollectionMethod } from "./enums";
|
|
2
|
+
/** The typed shape of `platform_audit.input` — what the operator asked for, verbatim. */
|
|
3
|
+
export interface PlatformAuditInput {
|
|
4
|
+
plan?: string;
|
|
5
|
+
seats?: number | null;
|
|
6
|
+
termMonths?: number | null;
|
|
7
|
+
collectionMethod?: PlatformCollectionMethod;
|
|
8
|
+
amountCents?: number | null;
|
|
9
|
+
currency?: string;
|
|
10
|
+
contractRef?: string | null;
|
|
11
|
+
invoiceRef?: string | null;
|
|
12
|
+
ownerEmail?: string | null;
|
|
13
|
+
orgName?: string | null;
|
|
14
|
+
slug?: string | null;
|
|
15
|
+
stripeCustomerId?: string | null;
|
|
16
|
+
stripeSubscriptionId?: string | null;
|
|
17
|
+
}
|
package/dist/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@alethialabs/platform",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Alethia platform records: enterprise contracts and the platform audit log, as Drizzle schema, enums and types.",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"author": "Alethia Labs <legal@alethialabs.io>",
|
|
7
|
+
"homepage": "https://alethialabs.io",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/alethialabs-io/alethialabs.git",
|
|
11
|
+
"directory": "packages/platform"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/alethialabs-io/alethialabs/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"**/*.css"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
"./schema": {
|
|
22
|
+
"types": "./dist/schema.d.ts",
|
|
23
|
+
"default": "./dist/schema.js"
|
|
24
|
+
},
|
|
25
|
+
"./enums": {
|
|
26
|
+
"types": "./dist/enums.d.ts",
|
|
27
|
+
"default": "./dist/enums.js"
|
|
28
|
+
},
|
|
29
|
+
"./types": {
|
|
30
|
+
"types": "./dist/types.d.ts",
|
|
31
|
+
"default": "./dist/types.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"drizzle-orm": "^0.45.4"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|