@donotdev/functions 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guidelines/VERCEL.md +2 -2
- package/lib/chunks/{chunk-UH445BGK.js → chunk-2N73OZFE.js} +2 -2
- package/lib/chunks/chunk-472JD6X7.js +22 -0
- package/lib/chunks/chunk-472JD6X7.js.map +7 -0
- package/lib/chunks/{chunk-QXIOO2RL.js → chunk-BTWJEJCV.js} +2 -2
- package/lib/chunks/chunk-CN6WXKYF.js +22 -0
- package/lib/chunks/chunk-CN6WXKYF.js.map +7 -0
- package/lib/chunks/{chunk-GDIUOJMD.js → chunk-DGBZDD6D.js} +2 -2
- package/lib/chunks/chunk-GBZQPOX4.js +151 -0
- package/lib/chunks/{chunk-F3WBFWPO.js.map → chunk-GBZQPOX4.js.map} +3 -3
- package/lib/chunks/chunk-ORBGTVJI.js +22 -0
- package/lib/chunks/{chunk-EZKRLLSQ.js.map → chunk-ORBGTVJI.js.map} +1 -1
- package/lib/chunks/chunk-R3I7U5QT.js +22 -0
- package/lib/chunks/chunk-R3I7U5QT.js.map +7 -0
- package/lib/chunks/{chunk-6NXIK35R.js → chunk-XWMG2FWZ.js} +2 -2
- package/lib/chunks/{chunk-6NXIK35R.js.map → chunk-XWMG2FWZ.js.map} +1 -1
- package/lib/chunks/chunk-ZCY6GTIC.js +22 -0
- package/lib/chunks/chunk-ZCY6GTIC.js.map +7 -0
- package/lib/chunks/{monitoring-LXNVBD3G.js → monitoring-KF7FRUQ6.js} +2 -2
- package/lib/chunks/{rateLimiter-GG5LPWXJ.js → rateLimiter-S7TITXOD.js} +2 -2
- package/lib/chunks/{server-NODQAE3F.js → server-SU4BVPPF.js} +2 -2
- package/lib/firebase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/firebase/crud/create.d.ts +22 -1
- package/lib/firebase/crud/update.d.ts +27 -3
- package/lib/firebase/index.js +1 -1
- package/lib/firebase/index.js.map +3 -3
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +2 -8
- package/lib/shared/billing/index.d.ts +2 -0
- package/lib/shared/billing/verifyOrderCheckout.d.ts +53 -0
- package/lib/shared/crud/bulkCore.d.ts +38 -10
- package/lib/shared/crud/index.d.ts +1 -0
- package/lib/shared/crud/written.d.ts +21 -0
- package/lib/shared/index.d.ts +0 -1
- package/lib/shared/index.js +1 -1
- package/lib/shared/utils.d.ts +0 -9
- package/lib/supabase/crud/bulk.d.ts +7 -0
- package/lib/supabase/crud/create.d.ts +5 -1
- package/lib/supabase/crud/entityStore.d.ts +54 -14
- package/lib/supabase/crud/update.d.ts +7 -2
- package/lib/supabase/index.d.ts +4 -0
- package/lib/supabase/index.js +1 -1
- package/lib/supabase/index.js.map +4 -4
- package/lib/vercel/api/crud/create.d.ts +6 -1
- package/lib/vercel/api/crud/update.d.ts +8 -1
- package/lib/vercel/api/index.js +1 -1
- package/package.json +3 -3
- package/src/firebase/auth/removeCustomClaims.ts +31 -1
- package/src/firebase/auth/setCustomClaims.ts +3 -0
- package/src/firebase/crud/__tests__/bulk.test.ts +50 -1
- package/src/firebase/crud/__tests__/create.test.ts +64 -0
- package/src/firebase/crud/__tests__/update.test.ts +97 -0
- package/src/firebase/crud/aggregate.ts +10 -21
- package/src/firebase/crud/bulk.ts +23 -10
- package/src/firebase/crud/create.ts +19 -18
- package/src/firebase/crud/get.ts +3 -12
- package/src/firebase/crud/list.ts +5 -4
- package/src/firebase/crud/update.ts +35 -19
- package/src/firebase/registerCrudFunctions.ts +1 -0
- package/src/shared/__tests__/bulkCore.test.ts +191 -0
- package/src/shared/__tests__/removeCustomClaims.test.ts +117 -0
- package/src/shared/__tests__/setCustomClaims.test.ts +103 -0
- package/src/shared/__tests__/utils.test.ts +0 -30
- package/src/shared/billing/__tests__/updateUserSubscription.test.ts +139 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.exports.test.ts +47 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.supabase.integration.test.ts +107 -0
- package/src/shared/billing/__tests__/verifyOrderCheckout.test.ts +233 -0
- package/src/shared/billing/helpers/updateUserSubscription.ts +10 -14
- package/src/shared/billing/index.ts +2 -0
- package/src/shared/billing/verifyOrderCheckout.ts +142 -0
- package/src/shared/crud/bulkCore.ts +110 -81
- package/src/shared/crud/index.ts +1 -0
- package/src/shared/crud/written.ts +56 -0
- package/src/shared/index.d.ts +0 -9
- package/src/shared/index.ts +0 -1
- package/src/shared/utils.ts +0 -43
- package/src/supabase/__tests__/bulk.test.ts +60 -2
- package/src/supabase/__tests__/create.test.ts +86 -0
- package/src/supabase/__tests__/entityStore.test.ts +91 -25
- package/src/supabase/__tests__/update.test.ts +107 -0
- package/src/supabase/auth/removeCustomClaims.ts +7 -2
- package/src/supabase/auth/setCustomClaims.ts +4 -2
- package/src/supabase/crud/bulk.ts +47 -0
- package/src/supabase/crud/create.ts +14 -24
- package/src/supabase/crud/entityStore.ts +106 -17
- package/src/supabase/crud/get.ts +3 -12
- package/src/supabase/crud/list.ts +5 -4
- package/src/supabase/crud/update.ts +20 -18
- package/src/supabase/index.ts +7 -0
- package/src/supabase/registerCrudFunctions.ts +1 -0
- package/src/vercel/__tests__/bulk.test.ts +16 -8
- package/src/vercel/api/crud/bulk.ts +27 -4
- package/src/vercel/api/crud/create.ts +17 -19
- package/src/vercel/api/crud/get.ts +5 -6
- package/src/vercel/api/crud/list.ts +4 -5
- package/src/vercel/api/crud/update.ts +20 -18
- package/lib/chunks/chunk-EZKRLLSQ.js +0 -22
- package/lib/chunks/chunk-F3PHE627.js +0 -22
- package/lib/chunks/chunk-F3PHE627.js.map +0 -7
- package/lib/chunks/chunk-F3WBFWPO.js +0 -151
- package/lib/chunks/chunk-G5DRV3DH.js +0 -22
- package/lib/chunks/chunk-G5DRV3DH.js.map +0 -7
- package/lib/chunks/chunk-Q2WLRFOE.js +0 -22
- package/lib/chunks/chunk-Q2WLRFOE.js.map +0 -7
- package/lib/chunks/chunk-W74UL7AY.js +0 -22
- package/lib/chunks/chunk-W74UL7AY.js.map +0 -7
- package/lib/shared/schema.d.ts +0 -56
- package/src/shared/__tests__/schema.test.ts +0 -219
- package/src/shared/schema.ts +0 -188
- /package/lib/chunks/{chunk-UH445BGK.js.map → chunk-2N73OZFE.js.map} +0 -0
- /package/lib/chunks/{chunk-QXIOO2RL.js.map → chunk-BTWJEJCV.js.map} +0 -0
- /package/lib/chunks/{chunk-GDIUOJMD.js.map → chunk-DGBZDD6D.js.map} +0 -0
- /package/lib/chunks/{monitoring-LXNVBD3G.js.map → monitoring-KF7FRUQ6.js.map} +0 -0
- /package/lib/chunks/{rateLimiter-GG5LPWXJ.js.map → rateLimiter-S7TITXOD.js.map} +0 -0
- /package/lib/chunks/{server-NODQAE3F.js.map → server-SU4BVPPF.js.map} +0 -0
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview User subscription update utilities
|
|
3
|
-
* @description Functions for updating user subscription data
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.0.1
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
import type { BillingAuthProvider, SubscriptionUpdate } from '@donotdev/core/server';
|
|
10
2
|
/**
|
|
11
3
|
* Platform-agnostic subscription update using dependency injection
|
|
12
4
|
* Works on Firebase Functions, Vercel, AWS Lambda, etc.
|
|
5
|
+
* Validates canonical auth claims; one-time payments may have no billing customer.
|
|
6
|
+
* Billing identifiers are preserved when supplied, never fabricated from a user ID.
|
|
13
7
|
*
|
|
14
8
|
* @version 0.1.0
|
|
15
9
|
* @since 0.0.1
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
9
|
export * from './createCheckout.js';
|
|
10
|
+
/** Read-only order verification and its separate retrieval/binding dependencies. */
|
|
11
|
+
export * from './verifyOrderCheckout.js';
|
|
10
12
|
export * from './helpers/index.js';
|
|
11
13
|
export * from './webhookHandler.js';
|
|
12
14
|
export * from './idempotency.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only StripeOrder verification for an authenticated return-page handler.
|
|
3
|
+
* Persisted app binding is mandatory; Stripe metadata is corroboration, not authority.
|
|
4
|
+
*/
|
|
5
|
+
import type Stripe from 'stripe';
|
|
6
|
+
import type { StripeBackConfig, VerifyOrderCheckoutRequest, VerifyOrderCheckoutResult } from '@donotdev/core/server';
|
|
7
|
+
/** App-owned persisted association, read from authoritative storage (never request metadata). */
|
|
8
|
+
export interface OrderCheckoutBinding {
|
|
9
|
+
orderId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
billingConfigKey: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Read dependencies only. Separate from StripeSessionProvider so existing checkout
|
|
16
|
+
* providers remain compatible. userId must come from verified handler context.
|
|
17
|
+
*/
|
|
18
|
+
export interface VerifyOrderCheckoutDependencies {
|
|
19
|
+
userId: string;
|
|
20
|
+
billingConfig: StripeBackConfig;
|
|
21
|
+
/** Retrieve from Stripe using server credentials; no browser-supplied session objects. */
|
|
22
|
+
retrieveStripeSession(sessionId: string): Promise<Pick<Stripe.Checkout.Session, 'id' | 'mode' | 'status' | 'payment_status' | 'metadata'>>;
|
|
23
|
+
/**
|
|
24
|
+
* Read the persisted order/session binding, scoped to the authenticated owner
|
|
25
|
+
* and config. Return absence if not authorized/found; never infer it from Stripe.
|
|
26
|
+
* The algorithm independently checks every returned binding field.
|
|
27
|
+
*/
|
|
28
|
+
resolveOrderBinding(request: VerifyOrderCheckoutRequest & {
|
|
29
|
+
userId: string;
|
|
30
|
+
}): Promise<OrderCheckoutBinding | null | undefined>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Verify an owner's StripeOrder session against server config and persisted binding.
|
|
34
|
+
* All validation, authorization and dependency failures expose the same safe error.
|
|
35
|
+
* Server diagnostics contain fixed stage/category labels only, never dependency
|
|
36
|
+
* errors or request/customer data. Logging failure cannot replace the public error.
|
|
37
|
+
* No writes, checkout hooks or fulfillment hooks run. A successful read reports
|
|
38
|
+
* payment state only: complete/unpaid is pending; paid/no_payment_required does not
|
|
39
|
+
* prove onOrderPaid has run. Existing webhook fulfillment remains authoritative.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* // Inside createSupabaseHandler(..., v.unknown(), (data, ctx) => ...)
|
|
44
|
+
* // The algorithm performs mandatory request validation itself.
|
|
45
|
+
* return verifyOrderCheckoutAlgorithm(data, {
|
|
46
|
+
* userId: ctx.uid,
|
|
47
|
+
* billingConfig,
|
|
48
|
+
* retrieveStripeSession: (id) => stripe.checkout.sessions.retrieve(id),
|
|
49
|
+
* resolveOrderBinding, // app-owned authoritative, read-only resolver
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function verifyOrderCheckoutAlgorithm(input: unknown, dependencies: VerifyOrderCheckoutDependencies): Promise<VerifyOrderCheckoutResult>;
|
|
@@ -27,11 +27,13 @@ export type BulkRowSchema = v.BaseSchema<unknown, any, v.BaseIssue<unknown>>;
|
|
|
27
27
|
/**
|
|
28
28
|
* A prepared insert row passed to the caller-supplied `transact` callback.
|
|
29
29
|
* When {@link ExecuteBulkParams.mintInsertId} is provided, `id` is the minted
|
|
30
|
-
* value
|
|
31
|
-
* the
|
|
30
|
+
* value (a client id never addresses a stored document). Otherwise it is the
|
|
31
|
+
* id the client supplied (a pre-minted id other rows reference, BULK_ACROSS.md
|
|
32
|
+
* "Pre-Minted IDs"), also kept on `row.id`, or the empty string when the
|
|
33
|
+
* storage layer mints its own.
|
|
32
34
|
*/
|
|
33
35
|
export interface PreparedInsert {
|
|
34
|
-
/** Minted
|
|
36
|
+
/** Minted id, else the client-supplied id, else the empty string (the target mints its own). */
|
|
35
37
|
id: string;
|
|
36
38
|
/** Fully stamped row ready for storage. */
|
|
37
39
|
row: Record<string, unknown>;
|
|
@@ -66,10 +68,26 @@ export interface ExecuteBulkParams<TRow = unknown> {
|
|
|
66
68
|
ops: BulkRequest;
|
|
67
69
|
/** Valibot schema validating each insert row. */
|
|
68
70
|
createSchema: BulkRowSchema;
|
|
69
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* `createSchemas(entity).draft`: drafts saved incomplete (CRUD rule 5). Required as soon
|
|
73
|
+
* as a draft row is sent: a draft without it is rejected (`invalid-argument`), never
|
|
74
|
+
* validated as a create.
|
|
75
|
+
*/
|
|
70
76
|
draftCreateSchema?: BulkRowSchema;
|
|
71
|
-
/**
|
|
77
|
+
/** `createSchemas(entity).update`: update patches (CRUD rules 2, 5). */
|
|
72
78
|
updateSchema: BulkRowSchema;
|
|
79
|
+
/**
|
|
80
|
+
* Reads the stored rows of the updated ids (application field names, keyed by id).
|
|
81
|
+
* Called once, before validation, when the bulk carries updates: the stored row
|
|
82
|
+
* gives each patch its status and a published draft its whole record
|
|
83
|
+
* (`prepareUpdate`, as on the client). An updated id missing
|
|
84
|
+
* from the result is rejected (`not-found`). Required as soon as the bulk carries
|
|
85
|
+
* updates: an update without it is rejected (`internal`, a configuration error),
|
|
86
|
+
* never validated by its patch status alone. Every target passes it: Firestore,
|
|
87
|
+
* Supabase and Vercel read their store; the GraphQL / REST-CRUD server aids
|
|
88
|
+
* forward the consumer's `readStored` option.
|
|
89
|
+
*/
|
|
90
|
+
readStored?: (ids: readonly string[]) => Promise<ReadonlyMap<string, Record<string, unknown>>>;
|
|
73
91
|
/** Per-bucket required roles. Missing entries are treated as "no bucket allowed". */
|
|
74
92
|
access: EntityAccessConfig;
|
|
75
93
|
/** Authenticated caller id (for metadata + audit). */
|
|
@@ -137,12 +155,17 @@ export interface ExecuteBulkParams<TRow = unknown> {
|
|
|
137
155
|
* 4. Per-bucket ACL — for each populated bucket, asserts the caller's role
|
|
138
156
|
* clears the corresponding `access.{create|update|delete}`. A missing
|
|
139
157
|
* role on a populated bucket is a configuration error and is rejected.
|
|
140
|
-
* 5. Per-row validation —
|
|
141
|
-
*
|
|
142
|
-
*
|
|
158
|
+
* 5. Per-row validation — the CRUD rules (`prepareCreate` / `prepareUpdate`,
|
|
159
|
+
* core/schemas crud/), the stored rows read once with `readStored` (updates
|
|
160
|
+
* without it → `internal`; an updated id with no stored row → `not-found`).
|
|
161
|
+
* The first failure throws `validation-failed` (wire: `invalid-argument`)
|
|
162
|
+
* naming `inserts[i]` / `updates[i]`. Unknown fields are logged, not written.
|
|
163
|
+
* What is stored is the rules' `written`, never the raw row.
|
|
143
164
|
* 6. Id minting — if `mintInsertId` is supplied, every insert gets a fresh
|
|
144
|
-
* id stamped onto its {@link PreparedInsert}. Otherwise
|
|
145
|
-
* the
|
|
165
|
+
* id stamped onto its {@link PreparedInsert}. Otherwise a client-supplied
|
|
166
|
+
* `id` is kept (on the row and as `PreparedInsert.id`; the create schema
|
|
167
|
+
* excludes it, it is restored after validation), else `id` is `""` and the
|
|
168
|
+
* storage layer mints its own.
|
|
146
169
|
* 7. Metadata stamping — `stampInsertMetadata` / `stampUpdateMetadata` run
|
|
147
170
|
* per row / per patch if provided.
|
|
148
171
|
* 8. `transact(prepared)` runs exactly once. Must be atomic. Throws
|
|
@@ -164,8 +187,12 @@ export interface ExecuteBulkParams<TRow = unknown> {
|
|
|
164
187
|
* @throws {DoNotDevError} `invalid-argument` on wire-schema failure, per-row
|
|
165
188
|
* validation failure, or collision (wrapped for callers that only rethrow
|
|
166
189
|
* `DoNotDevError`).
|
|
190
|
+
* @throws {DoNotDevError} `not-found` when an updated id has no stored row
|
|
191
|
+
* (`readStored`).
|
|
167
192
|
* @throws {DoNotDevError} `permission-denied` when the caller's role cannot
|
|
168
193
|
* satisfy a populated bucket's access requirement.
|
|
194
|
+
* @throws {DoNotDevError} `internal` when the bulk carries updates but no
|
|
195
|
+
* `readStored` is configured.
|
|
169
196
|
* @throws {DoNotDevError} `internal` when the `transact` return value fails
|
|
170
197
|
* {@link BulkResponseSchema}.
|
|
171
198
|
*
|
|
@@ -182,6 +209,7 @@ export interface ExecuteBulkParams<TRow = unknown> {
|
|
|
182
209
|
* access,
|
|
183
210
|
* uid,
|
|
184
211
|
* userRole,
|
|
212
|
+
* readStored: async (ids) => new Map((await db.getRows(ids)).map((row) => [row.id, row])),
|
|
185
213
|
* mintInsertId: () => crypto.randomUUID(),
|
|
186
214
|
* stampInsertMetadata: (row, uid) => ({
|
|
187
215
|
* ...row,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PreparedWrite } from '@donotdev/core/server';
|
|
2
|
+
/**
|
|
3
|
+
* The values a server write stores.
|
|
4
|
+
*
|
|
5
|
+
* @param result - The CRUD rule result
|
|
6
|
+
* @param collection - Collection written (named in the log and the error)
|
|
7
|
+
* @param locator - Write site / row (e.g. `update`, `inserts[2]`)
|
|
8
|
+
* @returns The rule's `written`
|
|
9
|
+
* @throws {DoNotDevError} `invalid-argument` with `details.validationErrors` (the server wire
|
|
10
|
+
* contract, a Firebase `FunctionsErrorCode`) when the write is invalid
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const row = writtenOf(prepareCreate(schemas, payload), collection, 'create');
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @version 0.1.0
|
|
18
|
+
* @since 0.3.0
|
|
19
|
+
* @author AMBROISE PARK Consulting
|
|
20
|
+
*/
|
|
21
|
+
export declare function writtenOf(result: PreparedWrite, collection: string, locator: string): Record<string, unknown>;
|
package/lib/shared/index.d.ts
CHANGED
package/lib/shared/index.js
CHANGED
|
@@ -18,5 +18,5 @@ if (typeof globalThis !== 'undefined') {
|
|
|
18
18
|
globalThis.global = globalThis;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
import{A as
|
|
21
|
+
import{A as K,B as L,C as M,D as Y,E as Z,F as _,G as Ba,H as Ca,I as Da,J as Ea,K as Fa,L as Ga,M as Ha,a as c,b as d,c as g,d as h,e as i,f as j,g as k,h as l,i as m,j as n,k as o,l as p,m as q,n as r,o as s,p as t,q as u,r as v,s as w,t as x,u as y,v as z,w as A,x as B,y as C,z as D}from"../chunks/chunk-CN6WXKYF.js";import{a as E,b as F,c as G,d as H,e as I,f as J,g as va,h as ya}from"../chunks/chunk-ORBGTVJI.js";import{a as e,b as f,c as $,d as aa,e as pa,f as za,g as Aa}from"../chunks/chunk-R3I7U5QT.js";import{A as xa,a as b,b as ba,d as ca,e as da,f as ea,g as fa,j as ga,k as ha,l as ia,m as ja,n as ka,o as la,p as ma,q as na,r as oa,s as qa,t as ra,u as sa,v as ta,y as ua,z as wa}from"../chunks/chunk-GBZQPOX4.js";import"../chunks/chunk-XWMG2FWZ.js";import{V as a}from"../chunks/chunk-ZCY6GTIC.js";import{a as N,b as O,c as P,d as Q,e as R}from"../chunks/chunk-DGBZDD6D.js";import{a as S,b as T,c as U,d as V,e as W,f as X}from"../chunks/chunk-2N73OZFE.js";import"../chunks/chunk-W6W4L44F.js";import"../chunks/chunk-AYY7UXNI.js";export{E as AuthBackendSchema,X as DEFAULT_RATE_LIMITS,a as DoNotDevError,c as GitHubApiService,ga as MIN_ORDER_API_VERSION,ha as ORDER_ID_METADATA_KEY,ia as PRODUCT_ID_METADATA_KEY,sa as RESERVATION_LEASE_MS,ra as ReservationLostError,g as StripeValidationSchemas,wa as WEBHOOK_EVENTS_SQL,ta as WEBHOOK_EVENT_RETENTION_MS,H as assertAdmin,G as assertAuthenticated,ba as calculateCost,z as calculateSubscriptionEndDate,C as cancelUserSubscription,L as checkIdempotency,O as checkPaymentFailureRate,P as checkPaymentVolume,S as checkRateLimit,T as checkRateLimitWithFirestore,ea as classifyAIError,R as cleanupOldMetrics,oa as createCheckoutAlgorithm,u as createFirebaseCallable,s as createFirebaseFunction,v as createFirebaseFunctionExports,va as createFirestoreIdempotencyStore,d as createGitHubApiService,ya as createInMemoryIdempotencyStore,e as createMetadata,Aa as createResendProvider,xa as createSupabaseIdempotencyStore,Da as createTimestamp,x as createVercelApiHandler,t as createVercelFunction,w as createVercelHandler,Ba as exchangeTokenAlgorithm,aa as executeBulk,A as findReferences,Q as getPaymentMetricsSummary,W as getRateLimitStatus,B as getTierFromPriceId,D as getUserSubscription,Ca as grantAccessAlgorithm,ca as handleAIRequest,za as handleEmailRequest,b as handleError,la as handleOrderSessionEvent,na as handleTaxIdUpdated,K as initializeFirebaseAdmin,Fa as isTimestamp,ka as listPaidLineItems,fa as mapClassifiedToHTTP,F as parseAuthBackend,Ha as prepareForFirestore,ua as processWebhook,N as recordPaymentMetrics,U as resetRateLimit,V as resetRateLimitInFirestore,da as resolveModelForTier,Y as safeJsonParse,M as storeIdempotencyResult,ja as toCheckoutSessionSnapshot,y as toISOString,ma as toTaxIdSnapshot,Ea as toTimestamp,Ga as transformFirestoreData,f as updateMetadata,qa as updateUserSubscription,Z as validateCollectionName,_ as validateDocument,k as validateEmail,j as validateGitHubUsername,o as validateMetadata,i as validatePurchaseRequest,p as validateRequestData,l as validateStripePriceId,m as validateStripeSessionId,n as validateUrl,h as validateWebhookEvent,J as verifyAuthToken,pa as verifyOrderCheckoutAlgorithm,I as verifyToken,q as withSchemaValidation,r as withVercelSchemaValidation,$ as writtenOf};
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* @since 0.0.1
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
|
-
import * as v from 'valibot';
|
|
10
9
|
import { DoNotDevError } from '@donotdev/core/server';
|
|
11
10
|
import type { UserRole } from '@donotdev/core/server';
|
|
12
11
|
export { DoNotDevError };
|
|
@@ -56,14 +55,6 @@ export declare function createErrorResponse(error: unknown): {
|
|
|
56
55
|
details?: Record<string, unknown>;
|
|
57
56
|
};
|
|
58
57
|
};
|
|
59
|
-
/**
|
|
60
|
-
* Validates document data
|
|
61
|
-
*
|
|
62
|
-
* @version 0.1.0
|
|
63
|
-
* @since 0.0.1
|
|
64
|
-
* @author AMBROISE PARK Consulting
|
|
65
|
-
*/
|
|
66
|
-
export declare function validateDocument(data: unknown, schema?: v.GenericSchema): void;
|
|
67
58
|
/**
|
|
68
59
|
* Validates a Firestore collection name from client-supplied schema.
|
|
69
60
|
*
|
|
@@ -27,6 +27,13 @@ export type BulkEntityRequest = BulkRequest;
|
|
|
27
27
|
* which wraps `BEGIN ... COMMIT` — any failure triggers `ROLLBACK` and the
|
|
28
28
|
* client observes a rejected promise with no partial state.
|
|
29
29
|
*
|
|
30
|
+
* The stored rows of the updated ids are read before the RPC (their status picks
|
|
31
|
+
* each patch's schema, the CRUD rules). The statuses read are passed as
|
|
32
|
+
* `p_expected_statuses`; `crud_bulk` locks each updated row (`FOR UPDATE`) and
|
|
33
|
+
* rejects the whole bulk (`unavailable`, nothing written) when a status changed in
|
|
34
|
+
* between. Requires the `crud_bulk_status_guard` migration (5-argument
|
|
35
|
+
* `crud_bulk`); against an older database the RPC call fails (function not found).
|
|
36
|
+
*
|
|
30
37
|
* The factory returns a handler that is auto-registered as `bulk_${collection}`
|
|
31
38
|
* by {@link createSupabaseCrudFunctions}.
|
|
32
39
|
*
|
|
@@ -8,8 +8,12 @@ export type CreateEntityRequest = {
|
|
|
8
8
|
/**
|
|
9
9
|
* Create a Supabase Edge Function handler for creating an entity.
|
|
10
10
|
*
|
|
11
|
+
* Status rule: a create without status gets `DEFAULT_STATUS_VALUE`; the CRUD rules
|
|
12
|
+
* picks the draft or create schema; the parse output is inserted, never the raw payload.
|
|
13
|
+
*
|
|
11
14
|
* @param collection - The Supabase table name
|
|
12
|
-
* @param
|
|
15
|
+
* @param createDocumentSchema - The create schema (`createSchemas(entity).create`)
|
|
16
|
+
* @param draftDocumentSchema - The draft schema (`createSchemas(entity).draft`)
|
|
13
17
|
* @param requiredRole - Minimum role required for this operation
|
|
14
18
|
* @returns A `(req: Request) => Promise<Response>` handler for Deno.serve
|
|
15
19
|
*/
|
|
@@ -8,15 +8,20 @@
|
|
|
8
8
|
* database policy hides them from non-admin users; the service role bypasses that
|
|
9
9
|
* policy, so the store re-applies it on reads).
|
|
10
10
|
*
|
|
11
|
-
* No role or visibility masking: the caller is trusted server code.
|
|
12
|
-
*
|
|
11
|
+
* No role or visibility masking: the caller is trusted server code. Writes are
|
|
12
|
+
* still validated: each insert row / patch against the schema of its resulting
|
|
13
|
+
* status (the CRUD rules: `create`, `draft` or `update`; a patch reads the matched
|
|
14
|
+
* rows first, their stored status counts), and the parse output is what is written.
|
|
15
|
+
* A caller-chosen insert `id` is kept. Insert and patch types come from the descriptor (`CreateInput`,
|
|
16
|
+
* `DraftInput`, `UpdatePatch`: write classes `program`, `user`, `derived`).
|
|
17
|
+
* Atomic multi-table writes stay in SQL functions (`client.rpc`).
|
|
13
18
|
*
|
|
14
|
-
* @version 0.
|
|
19
|
+
* @version 0.2.0
|
|
15
20
|
* @since 0.5.0
|
|
16
21
|
* @author AMBROISE PARK Consulting
|
|
17
22
|
*/
|
|
18
23
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
|
19
|
-
import type { AnyEntity, InferEntityRow } from '@donotdev/core/server';
|
|
24
|
+
import type { AnyEntity, CreateInput, DraftInput, InferEntityRow, UpdatePatch } from '@donotdev/core/server';
|
|
20
25
|
/** Filter operators, same vocabulary as the list handler and the client CRUD. */
|
|
21
26
|
export type EntityStoreOperator = '==' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not-in' | 'array-contains' | 'array-contains-any';
|
|
22
27
|
/** `[field, operator, value]`; field is an entity field name. */
|
|
@@ -31,22 +36,56 @@ export interface EntityStoreQuery {
|
|
|
31
36
|
/** Also return draft / deleted rows (default false). */
|
|
32
37
|
includeHidden?: boolean;
|
|
33
38
|
}
|
|
34
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Loose write values: any subset of the row's fields; `null` clears a nullable column.
|
|
41
|
+
* Default insert / patch type of {@link EntityStore}; `createEntityStore` narrows
|
|
42
|
+
* them to the descriptor types.
|
|
43
|
+
*/
|
|
35
44
|
export type EntityStoreValues<Row> = {
|
|
36
45
|
[K in keyof Row]?: Row[K] | null;
|
|
37
46
|
};
|
|
38
|
-
/**
|
|
39
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Insert row of an entity store: a create, or a draft (`status: 'draft'`), with an
|
|
49
|
+
* optional caller-chosen `id` (write class never, but a minted id is allowed on
|
|
50
|
+
* insert: other rows may reference it).
|
|
51
|
+
*/
|
|
52
|
+
export type EntityStoreInsert<E extends AnyEntity> = (CreateInput<E> | DraftInput<E>) & {
|
|
53
|
+
id?: string;
|
|
54
|
+
};
|
|
55
|
+
/** Patch of an entity store: an update, or a draft write (`status: 'draft'`). */
|
|
56
|
+
export type EntityStorePatch<E extends AnyEntity> = UpdatePatch<E> | DraftInput<E>;
|
|
57
|
+
/**
|
|
58
|
+
* Entity-aware CRUD bound to one entity and one Supabase client.
|
|
59
|
+
*
|
|
60
|
+
* @template Row - Stored row
|
|
61
|
+
* @template Insert - Insert row type
|
|
62
|
+
* @template Patch - Update patch type
|
|
63
|
+
*/
|
|
64
|
+
export interface EntityStore<Row, Insert = EntityStoreValues<Row>, Patch = EntityStoreValues<Row>> {
|
|
40
65
|
/** Rows matching the query. */
|
|
41
66
|
list(query?: EntityStoreQuery): Promise<Row[]>;
|
|
42
67
|
/** The single row matching the query, or null; more than one row is an error. */
|
|
43
68
|
find(query: EntityStoreQuery): Promise<Row | null>;
|
|
44
69
|
/** Row by id, or null (hidden rows only with `includeHidden`). */
|
|
45
70
|
get(id: string, options?: Pick<EntityStoreQuery, 'includeHidden' | 'select'>): Promise<Row | null>;
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Validates and inserts rows (CRUD create rules, `prepareCreate`); returns them as
|
|
73
|
+
* stored (database defaults and triggers applied). Unknown fields are logged, not
|
|
74
|
+
* written. A row's string `id` is kept (a minted id other rows reference); without
|
|
75
|
+
* one the database mints it.
|
|
76
|
+
*/
|
|
77
|
+
insert(values: readonly Insert[]): Promise<Row[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Validates the patch against each row matching `where` (hidden rows included; CRUD
|
|
80
|
+
* update rules, `prepareUpdate` on each stored row), then updates those rows; returns
|
|
81
|
+
* them as stored. Unknown fields are logged, not written.
|
|
82
|
+
*/
|
|
83
|
+
update(where: readonly EntityStoreCondition[], patch: Patch): Promise<Row[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Logical delete (CRUD rule 3) of the rows matching `where`: the update
|
|
86
|
+
* `{ status: 'deleted' }`. The hard delete is not part of the store.
|
|
87
|
+
*/
|
|
88
|
+
remove(where: readonly EntityStoreCondition[]): Promise<void>;
|
|
50
89
|
}
|
|
51
90
|
/** The PostgREST filter builder methods the store uses. */
|
|
52
91
|
export interface Filterable {
|
|
@@ -66,7 +105,8 @@ export interface Filterable {
|
|
|
66
105
|
*
|
|
67
106
|
* @param client - Supabase client the store runs with (service role in Edge Functions)
|
|
68
107
|
* @param entity - Entity from `defineEntity()`; its collection is the table
|
|
69
|
-
* @returns Store whose rows use the entity field names
|
|
108
|
+
* @returns Store whose rows use the entity field names; writes validated per status
|
|
109
|
+
* @throws DoNotDevError `invalid-argument` on an unknown field or a write that fails its schema
|
|
70
110
|
*
|
|
71
111
|
* @example
|
|
72
112
|
* ```typescript
|
|
@@ -78,7 +118,7 @@ export interface Filterable {
|
|
|
78
118
|
* const rows = await products.list({ where: [['id', 'in', ids]], select: ['name', 'sku'] });
|
|
79
119
|
* ```
|
|
80
120
|
*
|
|
81
|
-
* @version 0.
|
|
121
|
+
* @version 0.2.0
|
|
82
122
|
* @since 0.5.0
|
|
83
123
|
*/
|
|
84
|
-
export declare function createEntityStore<E extends AnyEntity>(client: SupabaseClient, entity: E): EntityStore<InferEntityRow<E>>;
|
|
124
|
+
export declare function createEntityStore<E extends AnyEntity>(client: SupabaseClient, entity: E): EntityStore<InferEntityRow<E>, EntityStoreInsert<E>, EntityStorePatch<E>>;
|
|
@@ -9,9 +9,14 @@ export type UpdateEntityRequest = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Create a Supabase Edge Function handler for updating an entity.
|
|
11
11
|
*
|
|
12
|
+
* CRUD update rules (`prepareUpdate`, core/schemas crud/update), as on the client: the
|
|
13
|
+
* stored row gives the patch its status and a published draft its whole record. The
|
|
14
|
+
* rules' `written` (parsed sent keys) is stored, never the raw payload.
|
|
15
|
+
*
|
|
12
16
|
* @param collection - The Supabase table name
|
|
13
|
-
* @param documentSchema - The
|
|
17
|
+
* @param documentSchema - The update schema (`createSchemas(entity).update`): validates what a non-draft update writes (the whole merged row when it enters a visible status)
|
|
18
|
+
* @param draftDocumentSchema - The draft schema (`createSchemas(entity).draft`): validates the resulting row of a draft
|
|
14
19
|
* @param requiredRole - Minimum role required for this operation
|
|
15
20
|
* @returns A `(req: Request) => Promise<Response>` handler for Deno.serve
|
|
16
21
|
*/
|
|
17
|
-
export declare function createSupabaseUpdateEntity(collection: string, documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>, requiredRole: UserRole): (req: Request) => Promise<Response>;
|
|
22
|
+
export declare function createSupabaseUpdateEntity(collection: string, documentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>, draftDocumentSchema: v.BaseSchema<unknown, any, v.BaseIssue<unknown>>, requiredRole: UserRole): (req: Request) => Promise<Response>;
|
package/lib/supabase/index.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export { ReservationLostError } from '../shared/billing/idempotencyContract.js';
|
|
|
25
25
|
export type { IdempotencyStore, ReservationResult, } from '../shared/billing/idempotencyContract.js';
|
|
26
26
|
export { createCheckoutAlgorithm } from '../shared/billing/createCheckout.js';
|
|
27
27
|
export type { StripeSessionProvider } from '../shared/billing/createCheckout.js';
|
|
28
|
+
/** Read-only verification for authenticated app handlers; fulfillment stays in webhooks. */
|
|
29
|
+
export { verifyOrderCheckoutAlgorithm } from '../shared/billing/verifyOrderCheckout.js';
|
|
30
|
+
/** Separate read dependencies; existing checkout providers need no new methods. */
|
|
31
|
+
export type { OrderCheckoutBinding, VerifyOrderCheckoutDependencies, } from '../shared/billing/verifyOrderCheckout.js';
|
|
28
32
|
export { STRIPE_API_VERSION_PIN } from '../shared/billing/apiVersion.js';
|
|
29
33
|
export { createCancelSubscription } from './billing/cancelSubscription.js';
|
|
30
34
|
export { createChangePlan } from './billing/changePlan.js';
|