@donotdev/functions 0.2.2 → 0.2.3
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/README.md +1 -1
- package/lib/chunks/chunk-6NXIK35R.js +23 -0
- package/lib/chunks/chunk-6NXIK35R.js.map +7 -0
- package/lib/chunks/chunk-EZKRLLSQ.js +22 -0
- package/lib/chunks/{chunk-OZX5ZG44.js.map → chunk-EZKRLLSQ.js.map} +1 -1
- package/lib/chunks/chunk-F3PHE627.js +22 -0
- package/lib/chunks/chunk-F3PHE627.js.map +7 -0
- package/lib/chunks/chunk-F3WBFWPO.js +151 -0
- package/lib/chunks/chunk-F3WBFWPO.js.map +7 -0
- package/lib/chunks/chunk-G5DRV3DH.js +22 -0
- package/lib/chunks/chunk-G5DRV3DH.js.map +7 -0
- package/lib/chunks/{chunk-2A4FPYNB.js → chunk-GDIUOJMD.js} +2 -2
- package/lib/chunks/chunk-GDIUOJMD.js.map +7 -0
- package/lib/chunks/chunk-Q2WLRFOE.js +22 -0
- package/lib/chunks/chunk-Q2WLRFOE.js.map +7 -0
- package/lib/chunks/chunk-QXIOO2RL.js +22 -0
- package/lib/chunks/chunk-QXIOO2RL.js.map +7 -0
- package/lib/chunks/{chunk-PJCJ5H2O.js → chunk-UH445BGK.js} +2 -2
- package/lib/chunks/chunk-W6W4L44F.js +22 -0
- package/lib/chunks/chunk-W6W4L44F.js.map +7 -0
- package/lib/chunks/chunk-W74UL7AY.js +22 -0
- package/lib/chunks/chunk-W74UL7AY.js.map +7 -0
- package/lib/chunks/{monitoring-UIDJS2KA.js → monitoring-LXNVBD3G.js} +2 -2
- package/lib/chunks/{rateLimiter-WNWHI3B4.js → rateLimiter-GG5LPWXJ.js} +2 -2
- package/lib/chunks/{server-RYGEBS2B.js → server-NODQAE3F.js} +2 -2
- package/lib/firebase/crud/aggregate.d.ts +1 -1
- package/lib/firebase/index.js +1 -1
- package/lib/firebase/index.js.map +3 -3
- package/lib/shared/billing/checkoutValidation.d.ts +1 -1
- package/lib/shared/billing/createCheckout.d.ts +1 -1
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +2 -2
- package/lib/shared/billing/orderWebhook.d.ts +29 -2
- package/lib/shared/billing/stripePinned.d.ts +43 -0
- package/lib/shared/denoEnv.d.ts +25 -0
- package/lib/shared/github.d.ts +0 -8
- package/lib/shared/index.js +1 -1
- package/lib/shared/logger.d.ts +14 -14
- package/lib/shared/utils/external/subscription.d.ts +0 -8
- package/lib/shared/utils.d.ts +15 -3
- package/lib/supabase/auth/deleteAccount.d.ts +34 -2
- package/lib/supabase/crud/create.d.ts +0 -8
- package/lib/supabase/crud/entityStore.d.ts +13 -0
- package/lib/supabase/crud/update.d.ts +0 -8
- package/lib/supabase/index.d.ts +1 -0
- package/lib/supabase/index.js +1 -1
- package/lib/supabase/index.js.map +4 -4
- package/lib/vercel/api/index.js +1 -1
- package/lib/vercel/api/index.js.map +3 -3
- package/package.json +9 -9
- package/src/firebase/auth/getCustomClaims.ts +2 -0
- package/src/firebase/auth/getUserAuthStatus.ts +2 -0
- package/src/firebase/auth/removeCustomClaims.ts +2 -0
- package/src/firebase/auth/setCustomClaims.ts +3 -0
- package/src/firebase/baseFunction.ts +5 -2
- package/src/firebase/billing/changePlan.ts +6 -5
- package/src/firebase/billing/createCustomerPortal.ts +6 -4
- package/src/firebase/billing/refreshSubscriptionStatus.ts +7 -5
- package/src/firebase/billing/webhookHandler.ts +4 -4
- package/src/firebase/crud/aggregate.ts +41 -12
- package/src/firebase/crud/bulk.ts +7 -0
- package/src/firebase/crud/create.ts +21 -8
- package/src/firebase/crud/delete.ts +6 -1
- package/src/firebase/crud/get.ts +9 -2
- package/src/firebase/crud/list.ts +18 -8
- package/src/firebase/crud/update.ts +15 -7
- package/src/firebase/helpers/githubAccessHelper.ts +3 -0
- package/src/firebase/helpers/githubTeamAccessHelper.ts +1 -0
- package/src/firebase/oauth/exchangeToken.ts +4 -0
- package/src/firebase/oauth/getConnections.ts +1 -1
- package/src/firebase/oauth/githubAccess.ts +3 -0
- package/src/firebase/oauth/refreshToken.ts +1 -0
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +4 -1
- package/src/shared/ai/classifyAIError.ts +18 -10
- package/src/shared/ai/createAIRoute.ts +2 -1
- package/src/shared/ai/resolveModelTier.ts +2 -1
- package/src/shared/billing/__tests__/createCheckout.test.ts +94 -0
- package/src/shared/billing/__tests__/firestoreIdempotency.emulator.test.ts +1 -1
- package/src/shared/billing/__tests__/webhookHandler.test.ts +108 -0
- package/src/shared/billing/checkoutValidation.ts +19 -2
- package/src/shared/billing/createCheckout.ts +56 -11
- package/src/shared/billing/helpers/subscriptionManagement.ts +14 -10
- package/src/shared/billing/orderWebhook.ts +69 -1
- package/src/shared/billing/stripeClient.ts +2 -1
- package/src/shared/billing/stripePinned.ts +71 -0
- package/src/shared/billing/tierWebhookEvents.ts +3 -2
- package/src/shared/billing/webhookHandler.ts +5 -1
- package/src/shared/crud/bulkCore.ts +3 -2
- package/src/shared/denoEnv.ts +29 -0
- package/src/shared/email/createEmailRoute.ts +2 -2
- package/src/shared/errorHandling.ts +8 -8
- package/src/shared/firebase.ts +26 -9
- package/src/shared/github.ts +15 -5
- package/src/shared/logger.ts +37 -38
- package/src/shared/schema.ts +6 -10
- package/src/shared/utils/external/date.ts +4 -4
- package/src/shared/utils/external/subscription.ts +2 -89
- package/src/shared/utils/firebaseHelpers.ts +2 -0
- package/src/shared/utils/internal/idempotency.ts +3 -0
- package/src/shared/utils/internal/monitoring.ts +6 -5
- package/src/shared/utils/internal/validation.ts +2 -0
- package/src/shared/utils/schemaValidation.ts +1 -0
- package/src/shared/utils/validation.ts +10 -20
- package/src/shared/utils.ts +12 -7
- package/src/supabase/__tests__/aggregate.test.ts +132 -0
- package/src/supabase/auth/__tests__/deleteAccount.test.ts +102 -0
- package/src/supabase/auth/deleteAccount.ts +72 -5
- package/src/supabase/billing/refreshSubscriptionStatus.ts +6 -5
- package/src/supabase/crud/aggregate.ts +85 -72
- package/src/supabase/crud/bulk.ts +3 -0
- package/src/supabase/crud/create.ts +13 -9
- package/src/supabase/crud/delete.ts +2 -1
- package/src/supabase/crud/entityStore.ts +1 -1
- package/src/supabase/crud/get.ts +2 -1
- package/src/supabase/crud/list.ts +23 -17
- package/src/supabase/crud/update.ts +9 -6
- package/src/supabase/edgeFunction.ts +2 -1
- package/src/supabase/email/createEmailFunction.ts +2 -1
- package/src/supabase/index.ts +1 -0
- package/src/supabase/oauth/exchangeToken.ts +1 -0
- package/src/supabase/oauth/getConnections.ts +1 -1
- package/src/supabase/oauth/refreshToken.ts +1 -0
- package/src/supabase/utils/idempotency.ts +1 -1
- package/src/supabase/utils/monitoring.ts +1 -0
- package/src/vercel/api/billing/change-plan.ts +6 -5
- package/src/vercel/api/billing/refresh-subscription-status.ts +3 -1
- package/src/vercel/api/crud/bulk.ts +7 -2
- package/src/vercel/api/crud/create.ts +6 -3
- package/src/vercel/api/crud/delete.ts +5 -2
- package/src/vercel/api/crud/get.ts +5 -2
- package/src/vercel/api/crud/list.ts +6 -3
- package/src/vercel/api/crud/update.ts +6 -3
- package/src/vercel/api/oauth/check-github-access.ts +1 -0
- package/src/vercel/api/oauth/exchange-token.ts +5 -2
- package/src/vercel/api/oauth/grant-github-access.ts +1 -0
- package/src/vercel/api/oauth/revoke-github-access.ts +1 -0
- package/src/vercel/baseFunction.ts +5 -1
- package/lib/chunks/chunk-2A4FPYNB.js.map +0 -7
- package/lib/chunks/chunk-2IFFIUFV.js +0 -23
- package/lib/chunks/chunk-2IFFIUFV.js.map +0 -7
- package/lib/chunks/chunk-FQSQGOBN.js +0 -22
- package/lib/chunks/chunk-FQSQGOBN.js.map +0 -7
- package/lib/chunks/chunk-G4FO76EA.js +0 -22
- package/lib/chunks/chunk-G4FO76EA.js.map +0 -7
- package/lib/chunks/chunk-LSM5Y2E5.js +0 -22
- package/lib/chunks/chunk-LSM5Y2E5.js.map +0 -7
- package/lib/chunks/chunk-M4JV2JCF.js +0 -22
- package/lib/chunks/chunk-M4JV2JCF.js.map +0 -7
- package/lib/chunks/chunk-OZX5ZG44.js +0 -22
- package/lib/chunks/chunk-PWAGW4R6.js +0 -22
- package/lib/chunks/chunk-PWAGW4R6.js.map +0 -7
- package/lib/chunks/chunk-UYI56E6Q.js +0 -151
- package/lib/chunks/chunk-UYI56E6Q.js.map +0 -7
- package/lib/chunks/chunk-ZVHC2CAV.js +0 -22
- package/lib/chunks/chunk-ZVHC2CAV.js.map +0 -7
- package/lib/shared/utils/functionWrapper.d.ts +0 -36
- package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -122
- package/src/shared/utils/functionWrapper.ts +0 -73
- /package/lib/chunks/{chunk-PJCJ5H2O.js.map → chunk-UH445BGK.js.map} +0 -0
- /package/lib/chunks/{monitoring-UIDJS2KA.js.map → monitoring-LXNVBD3G.js.map} +0 -0
- /package/lib/chunks/{rateLimiter-WNWHI3B4.js.map → rateLimiter-GG5LPWXJ.js.map} +0 -0
- /package/lib/chunks/{server-RYGEBS2B.js.map → server-NODQAE3F.js.map} +0 -0
|
@@ -32,7 +32,7 @@ export declare function validateCheckoutUrl(url: string, name: string): void;
|
|
|
32
32
|
* Sanitize client metadata: enforce string values, strip script injection.
|
|
33
33
|
* Length limits are checked on the final metadata ({@link assertStripeMetadata}).
|
|
34
34
|
*/
|
|
35
|
-
export declare function sanitizeMetadata(metadata: Record<string,
|
|
35
|
+
export declare function sanitizeMetadata(metadata: Record<string, unknown>): Record<string, string>;
|
|
36
36
|
/**
|
|
37
37
|
* Throw a validation error when metadata exceeds Stripe's limits
|
|
38
38
|
* ({@link STRIPE_METADATA_LIMITS}), instead of letting Stripe answer 400.
|
|
@@ -68,7 +68,7 @@ export interface AuthCheckoutProvider {
|
|
|
68
68
|
* 3. `beforeCheckout` hook (block/allow)
|
|
69
69
|
* 4. StripeOrder: reject inclusive manual Tax Rates, `resolveLineItems` prices every line
|
|
70
70
|
* and may set per-order session options (`ResolvedOrder.session`: tax rates,
|
|
71
|
-
* payment methods, expiry, invoice footer)
|
|
71
|
+
* payment methods, expiry, invoice footer, existing Stripe customer)
|
|
72
72
|
* 5. Validate metadata against Stripe limits, create the session through the provider
|
|
73
73
|
*
|
|
74
74
|
* Server-owned metadata (`userId`, `billingConfigKey`, `orderId`) is written after
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BillingAuthProvider } from '@donotdev/core/server';
|
|
1
|
+
import type { BillingAuthProvider, StripeBackConfig } from '@donotdev/core/server';
|
|
2
2
|
/**
|
|
3
3
|
* Cancel user subscription at period end
|
|
4
4
|
*
|
|
@@ -17,7 +17,7 @@ export declare function cancelUserSubscription(userId: string, authProvider: Bil
|
|
|
17
17
|
* @since 0.0.1
|
|
18
18
|
* @author AMBROISE PARK Consulting
|
|
19
19
|
*/
|
|
20
|
-
export declare function changeUserPlan(userId: string, newPriceId: string, billingConfigKey: string, billingConfig:
|
|
20
|
+
export declare function changeUserPlan(userId: string, newPriceId: string, billingConfigKey: string, billingConfig: StripeBackConfig, authProvider: BillingAuthProvider): Promise<{
|
|
21
21
|
success: boolean;
|
|
22
22
|
newTier: string;
|
|
23
23
|
newPrice: number;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview StripeOrder webhook handling
|
|
3
3
|
* @description Maps Checkout Session events of one-time, multi-line orders to the
|
|
4
|
-
* app's order hooks (`onOrderPaid`, `onOrderPaymentFailed`, `onOrderExpired`)
|
|
4
|
+
* app's order hooks (`onOrderPaid`, `onOrderPaymentFailed`, `onOrderExpired`), and
|
|
5
|
+
* `customer.tax_id.updated` to `onTaxIdUpdated`.
|
|
5
6
|
* Hook errors propagate: the webhook answers non-2xx and Stripe retries.
|
|
6
7
|
*
|
|
7
8
|
* @version 0.2.0
|
|
@@ -9,7 +10,7 @@
|
|
|
9
10
|
* @author AMBROISE PARK Consulting
|
|
10
11
|
*/
|
|
11
12
|
import type Stripe from 'stripe';
|
|
12
|
-
import type { CheckoutSessionSnapshot, PaidLineItem, StripeOrderBackItem } from '@donotdev/core/server';
|
|
13
|
+
import type { CheckoutSessionSnapshot, PaidLineItem, StripeBackConfig, StripeOrderBackItem, TaxIdSnapshot } from '@donotdev/core/server';
|
|
13
14
|
/**
|
|
14
15
|
* Checkout Session events that concern orders.
|
|
15
16
|
*
|
|
@@ -73,3 +74,29 @@ export declare function listPaidLineItems(stripe: Stripe, sessionId: string): Pr
|
|
|
73
74
|
* @author AMBROISE PARK Consulting
|
|
74
75
|
*/
|
|
75
76
|
export declare function handleOrderSessionEvent(eventType: OrderSessionEventType, eventId: string, apiVersion: string | null, session: Stripe.Checkout.Session, billingConfigKey: string, orderItem: StripeOrderBackItem, stripe: Stripe): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Map a Stripe TaxId to the provider-neutral snapshot given to `onTaxIdUpdated`.
|
|
79
|
+
*
|
|
80
|
+
* @param taxId - TaxId from a `customer.tax_id.updated` event
|
|
81
|
+
* @returns Snapshot
|
|
82
|
+
*
|
|
83
|
+
* @version 0.2.0
|
|
84
|
+
* @since 0.2.3
|
|
85
|
+
* @author AMBROISE PARK Consulting
|
|
86
|
+
*/
|
|
87
|
+
export declare function toTaxIdSnapshot(taxId: Stripe.TaxId): TaxIdSnapshot;
|
|
88
|
+
/**
|
|
89
|
+
* Handle `customer.tax_id.updated`: run `onTaxIdUpdated` of every StripeOrder item
|
|
90
|
+
* that defines it, once per distinct function. Called by `processWebhook` after
|
|
91
|
+
* signature verification and idempotency reservation (same path as order events).
|
|
92
|
+
*
|
|
93
|
+
* @param eventId - Stripe event ID
|
|
94
|
+
* @param taxId - TaxId from the event
|
|
95
|
+
* @param config - App back config
|
|
96
|
+
* @throws When a hook throws (the webhook answers non-2xx and Stripe retries)
|
|
97
|
+
*
|
|
98
|
+
* @version 0.2.0
|
|
99
|
+
* @since 0.2.3
|
|
100
|
+
* @author AMBROISE PARK Consulting
|
|
101
|
+
*/
|
|
102
|
+
export declare function handleTaxIdUpdated(eventId: string, taxId: Stripe.TaxId, config: StripeBackConfig): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Typed access to Stripe fields of the pinned API version
|
|
3
|
+
* @description The Stripe SDK types follow the latest API version only, while
|
|
4
|
+
* requests run at `STRIPE_API_VERSION_PIN` (pre-basil). Fields that basil
|
|
5
|
+
* moved (subscription period, invoice subscription) are read here, through one
|
|
6
|
+
* documented cast, instead of `as any` at every call site. Internal: not
|
|
7
|
+
* re-exported from any package entry.
|
|
8
|
+
*
|
|
9
|
+
* @version 0.1.0
|
|
10
|
+
* @since 0.2.2
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
import type Stripe from 'stripe';
|
|
14
|
+
/** Subscription fields present at `STRIPE_API_VERSION_PIN`, dropped from the latest SDK types. */
|
|
15
|
+
interface PinnedSubscriptionFields {
|
|
16
|
+
current_period_start: number;
|
|
17
|
+
current_period_end: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Period fields of a subscription at the pinned API version.
|
|
21
|
+
*
|
|
22
|
+
* @version 0.1.0
|
|
23
|
+
* @since 0.2.2
|
|
24
|
+
* @author AMBROISE PARK Consulting
|
|
25
|
+
*/
|
|
26
|
+
export declare function pinnedSubscriptionPeriod(subscription: Stripe.Subscription): PinnedSubscriptionFields;
|
|
27
|
+
/**
|
|
28
|
+
* Subscription id of an invoice at the pinned API version.
|
|
29
|
+
*
|
|
30
|
+
* @version 0.1.0
|
|
31
|
+
* @since 0.2.2
|
|
32
|
+
* @author AMBROISE PARK Consulting
|
|
33
|
+
*/
|
|
34
|
+
export declare function pinnedInvoiceSubscriptionId(invoice: Stripe.Invoice): string | null;
|
|
35
|
+
/**
|
|
36
|
+
* Narrows a value to one of a readonly list of literals.
|
|
37
|
+
*
|
|
38
|
+
* @version 0.1.0
|
|
39
|
+
* @since 0.2.2
|
|
40
|
+
* @author AMBROISE PARK Consulting
|
|
41
|
+
*/
|
|
42
|
+
export declare function isOneOf<T extends string>(values: readonly T[], value: string): value is T;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Typed access to the Deno env from cross-runtime code
|
|
3
|
+
* @description Supabase Edge Functions run on Deno, Firebase/Vercel on Node.
|
|
4
|
+
* This package compiles against the Node lib types, which have no `Deno`
|
|
5
|
+
* global. Internal: not re-exported from any package entry.
|
|
6
|
+
*
|
|
7
|
+
* @version 0.1.0
|
|
8
|
+
* @since 0.2.2
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
/** The part of the Deno namespace read by this package. */
|
|
12
|
+
interface DenoEnvNamespace {
|
|
13
|
+
env?: {
|
|
14
|
+
get(key: string): string | undefined;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Deno env accessor, when running on Deno.
|
|
19
|
+
*
|
|
20
|
+
* @version 0.1.0
|
|
21
|
+
* @since 0.2.2
|
|
22
|
+
* @author AMBROISE PARK Consulting
|
|
23
|
+
*/
|
|
24
|
+
export declare function getDenoEnv(): DenoEnvNamespace['env'];
|
|
25
|
+
export {};
|
package/lib/shared/github.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview GitHub API Service for functions
|
|
3
|
-
* @description Server-safe GitHub API utilities for repository management
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.0.1
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
/** Configuration for authenticating with the GitHub API. */
|
|
10
2
|
export interface GitHubApiConfig {
|
|
11
3
|
accessToken: string;
|
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 E,B as F,C as G,D as N,E as O,F as P,G as $,H as aa,I as ba,J as
|
|
21
|
+
import{A as E,B as F,C as G,D as N,E as O,F as P,G as $,H as aa,I as ba,J as Ca,K as Da,L as Ea,M as Fa,N as Ga,O as Ha,P as Ia,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-Q2WLRFOE.js";import{a as H,b as I,c as J,d as K,e as L,f as M,g as wa,h as za}from"../chunks/chunk-EZKRLLSQ.js";import{a as e,b as f,c as ca,d as Aa,e as Ba}from"../chunks/chunk-G5DRV3DH.js";import{A as ya,a as b,b as da,d as ea,e as fa,f as ga,g as ha,j as ia,k as ja,l as ka,m as la,n as ma,o as na,p as oa,q as pa,r as qa,s as ra,t as sa,u as ta,v as ua,y as va,z as xa}from"../chunks/chunk-F3WBFWPO.js";import"../chunks/chunk-6NXIK35R.js";import{N as a}from"../chunks/chunk-W74UL7AY.js";import{a as Q,b as R,c as S,d as T,e as U}from"../chunks/chunk-GDIUOJMD.js";import{a as V,b as W,c as X,d as Y,e as Z,f as _}from"../chunks/chunk-UH445BGK.js";import"../chunks/chunk-W6W4L44F.js";import"../chunks/chunk-AYY7UXNI.js";export{H as AuthBackendSchema,_ as DEFAULT_RATE_LIMITS,a as DoNotDevError,c as GitHubApiService,ia as MIN_ORDER_API_VERSION,ja as ORDER_ID_METADATA_KEY,ka as PRODUCT_ID_METADATA_KEY,ta as RESERVATION_LEASE_MS,sa as ReservationLostError,j as StripeValidationSchemas,xa as WEBHOOK_EVENTS_SQL,ua as WEBHOOK_EVENT_RETENTION_MS,K as assertAdmin,J as assertAuthenticated,da as calculateCost,C as calculateSubscriptionEndDate,F as cancelUserSubscription,O as checkIdempotency,R as checkPaymentFailureRate,S as checkPaymentVolume,V as checkRateLimit,W as checkRateLimitWithFirestore,ga as classifyAIError,U as cleanupOldMetrics,qa as createCheckoutAlgorithm,x as createFirebaseCallable,v as createFirebaseFunction,y as createFirebaseFunctionExports,wa as createFirestoreIdempotencyStore,d as createGitHubApiService,za as createInMemoryIdempotencyStore,e as createMetadata,Ba as createResendProvider,ya as createSupabaseIdempotencyStore,Ea as createTimestamp,A as createVercelApiHandler,w as createVercelFunction,z as createVercelHandler,Ca as exchangeTokenAlgorithm,ca as executeBulk,i as filterVisibleFields,D as findReferences,T as getPaymentMetricsSummary,Z as getRateLimitStatus,E as getTierFromPriceId,G as getUserSubscription,h as getVisibleFields,Da as grantAccessAlgorithm,ea as handleAIRequest,Aa as handleEmailRequest,b as handleError,na as handleOrderSessionEvent,pa as handleTaxIdUpdated,N as initializeFirebaseAdmin,g as isFieldVisible,Ga as isTimestamp,ma as listPaidLineItems,ha as mapClassifiedToHTTP,I as parseAuthBackend,Ia as prepareForFirestore,va as processWebhook,Q as recordPaymentMetrics,X as resetRateLimit,Y as resetRateLimitInFirestore,fa as resolveModelForTier,$ as safeJsonParse,P as storeIdempotencyResult,la as toCheckoutSessionSnapshot,B as toISOString,oa as toTaxIdSnapshot,Fa as toTimestamp,Ha as transformFirestoreData,f as updateMetadata,ra as updateUserSubscription,aa as validateCollectionName,ba as validateDocument,n as validateEmail,m as validateGitHubUsername,r as validateMetadata,l as validatePurchaseRequest,s as validateRequestData,o as validateStripePriceId,p as validateStripeSessionId,q as validateUrl,k as validateWebhookEvent,M as verifyAuthToken,L as verifyToken,t as withSchemaValidation,u as withVercelSchemaValidation};
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/lib/shared/logger.d.ts
CHANGED
|
@@ -15,9 +15,9 @@ export interface LogEntry {
|
|
|
15
15
|
level: LogLevel;
|
|
16
16
|
message: string;
|
|
17
17
|
timestamp: string;
|
|
18
|
-
context?: Record<string,
|
|
18
|
+
context?: Record<string, unknown>;
|
|
19
19
|
error?: Error;
|
|
20
|
-
metadata?: Record<string,
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Server-side logger with Sentry integration
|
|
@@ -56,7 +56,7 @@ export declare const logger: {
|
|
|
56
56
|
* @since 0.0.1
|
|
57
57
|
* @author AMBROISE PARK Consulting
|
|
58
58
|
*/
|
|
59
|
-
debug(message: string, context?: Record<string,
|
|
59
|
+
debug(message: string, context?: Record<string, unknown>): void;
|
|
60
60
|
/**
|
|
61
61
|
* Log informational messages
|
|
62
62
|
* @param message - Log message
|
|
@@ -66,7 +66,7 @@ export declare const logger: {
|
|
|
66
66
|
* @since 0.0.1
|
|
67
67
|
* @author AMBROISE PARK Consulting
|
|
68
68
|
*/
|
|
69
|
-
info(message: string, context?: Record<string,
|
|
69
|
+
info(message: string, context?: Record<string, unknown>): void;
|
|
70
70
|
/**
|
|
71
71
|
* Log warning messages
|
|
72
72
|
* @param message - Log message
|
|
@@ -76,7 +76,7 @@ export declare const logger: {
|
|
|
76
76
|
* @since 0.0.1
|
|
77
77
|
* @author AMBROISE PARK Consulting
|
|
78
78
|
*/
|
|
79
|
-
warn(message: string, context?: Record<string,
|
|
79
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
80
80
|
/**
|
|
81
81
|
* Log error messages with Sentry integration
|
|
82
82
|
* @param message - Log message
|
|
@@ -86,7 +86,7 @@ export declare const logger: {
|
|
|
86
86
|
* @since 0.0.1
|
|
87
87
|
* @author AMBROISE PARK Consulting
|
|
88
88
|
*/
|
|
89
|
-
error(message: string, context?: Record<string,
|
|
89
|
+
error(message: string, context?: Record<string, unknown>): Promise<void>;
|
|
90
90
|
/**
|
|
91
91
|
* Log fatal errors with Sentry integration
|
|
92
92
|
* @param message - Log message
|
|
@@ -96,7 +96,7 @@ export declare const logger: {
|
|
|
96
96
|
* @since 0.0.1
|
|
97
97
|
* @author AMBROISE PARK Consulting
|
|
98
98
|
*/
|
|
99
|
-
fatal(message: string, context?: Record<string,
|
|
99
|
+
fatal(message: string, context?: Record<string, unknown>): Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Core logging method
|
|
102
102
|
* @param level - Log level
|
|
@@ -109,7 +109,7 @@ export declare const logger: {
|
|
|
109
109
|
* @since 0.0.1
|
|
110
110
|
* @author AMBROISE PARK Consulting
|
|
111
111
|
*/
|
|
112
|
-
log(level: LogLevel, message: string, context?: Record<string,
|
|
112
|
+
log(level: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
113
113
|
/**
|
|
114
114
|
* Check if Sentry is enabled
|
|
115
115
|
* @returns True if Sentry is available and configured
|
|
@@ -126,10 +126,10 @@ export declare const logger: {
|
|
|
126
126
|
* @param context - Additional context to include in all logs
|
|
127
127
|
* @returns Child logger instance
|
|
128
128
|
*/
|
|
129
|
-
export declare function createChildLogger(context: Record<string,
|
|
130
|
-
debug: (message: string, additionalContext?: Record<string,
|
|
131
|
-
info: (message: string, additionalContext?: Record<string,
|
|
132
|
-
warn: (message: string, additionalContext?: Record<string,
|
|
133
|
-
error: (message: string, additionalContext?: Record<string,
|
|
134
|
-
fatal: (message: string, additionalContext?: Record<string,
|
|
129
|
+
export declare function createChildLogger(context: Record<string, unknown>): {
|
|
130
|
+
debug: (message: string, additionalContext?: Record<string, unknown>) => void;
|
|
131
|
+
info: (message: string, additionalContext?: Record<string, unknown>) => void;
|
|
132
|
+
warn: (message: string, additionalContext?: Record<string, unknown>) => void;
|
|
133
|
+
error: (message: string, additionalContext?: Record<string, unknown>) => Promise<void>;
|
|
134
|
+
fatal: (message: string, additionalContext?: Record<string, unknown>) => Promise<void>;
|
|
135
135
|
};
|
|
@@ -15,14 +15,6 @@ import type { SubscriptionClaims } from '@donotdev/core/server';
|
|
|
15
15
|
* @author AMBROISE PARK Consulting
|
|
16
16
|
*/
|
|
17
17
|
export declare function getTierFromPriceId(priceId: string): string;
|
|
18
|
-
/**
|
|
19
|
-
* Validates subscription status and updates Firebase custom claims
|
|
20
|
-
*
|
|
21
|
-
* @version 0.1.0
|
|
22
|
-
* @since 0.0.1
|
|
23
|
-
* @author AMBROISE PARK Consulting
|
|
24
|
-
*/
|
|
25
|
-
export declare function updateFirebaseUserSubscription(firebaseUid: string, subscription: any): Promise<void>;
|
|
26
18
|
/**
|
|
27
19
|
* Cancels user subscription and resets to free tier
|
|
28
20
|
*
|
package/lib/shared/utils.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared utilities for Firebase and Vercel functions
|
|
3
|
+
* @description Common utilities that can be used by both Firebase and Vercel function implementations
|
|
4
|
+
*
|
|
5
|
+
* @version 0.1.0
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import * as v from 'valibot';
|
|
1
10
|
import { DoNotDevError } from '@donotdev/core/server';
|
|
2
11
|
import type { UserRole } from '@donotdev/core/server';
|
|
3
12
|
export { DoNotDevError };
|
|
@@ -17,7 +26,10 @@ export { DoNotDevError };
|
|
|
17
26
|
* @since 0.0.1
|
|
18
27
|
* @author AMBROISE PARK Consulting
|
|
19
28
|
*/
|
|
20
|
-
export declare function getUserRole(auth:
|
|
29
|
+
export declare function getUserRole(auth: {
|
|
30
|
+
uid?: string;
|
|
31
|
+
token?: Record<string, unknown>;
|
|
32
|
+
} | null | undefined): UserRole;
|
|
21
33
|
/**
|
|
22
34
|
* Creates a standardized success response
|
|
23
35
|
*
|
|
@@ -41,7 +53,7 @@ export declare function createErrorResponse(error: unknown): {
|
|
|
41
53
|
error: {
|
|
42
54
|
code: string;
|
|
43
55
|
message: string;
|
|
44
|
-
details?:
|
|
56
|
+
details?: Record<string, unknown>;
|
|
45
57
|
};
|
|
46
58
|
};
|
|
47
59
|
/**
|
|
@@ -51,7 +63,7 @@ export declare function createErrorResponse(error: unknown): {
|
|
|
51
63
|
* @since 0.0.1
|
|
52
64
|
* @author AMBROISE PARK Consulting
|
|
53
65
|
*/
|
|
54
|
-
export declare function validateDocument(data:
|
|
66
|
+
export declare function validateDocument(data: unknown, schema?: v.GenericSchema): void;
|
|
55
67
|
/**
|
|
56
68
|
* Validates a Firestore collection name from client-supplied schema.
|
|
57
69
|
*
|
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
import type { SupabaseHandlerContext } from '../baseFunction.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link createDeleteAccount}.
|
|
4
|
+
*
|
|
5
|
+
* @version 0.2.0
|
|
6
|
+
* @since 0.2.3
|
|
7
|
+
*/
|
|
8
|
+
export interface DeleteAccountOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Runs before the auth user is deleted (close the account, anonymize data, cancel
|
|
11
|
+
* subscriptions...). Throwing refuses the deletion: the user is NOT deleted and the
|
|
12
|
+
* client receives HTTP 409 `{ error: message, code }` (`code` when the thrown error
|
|
13
|
+
* carries a string `code`). The message and code reach the browser unmasked, so
|
|
14
|
+
* throw client-safe values only — a refusal code such as `open_orders` that the
|
|
15
|
+
* client translates under `auth:deleteAccount.errors.<code>` (see `useDeleteAccount`).
|
|
16
|
+
*/
|
|
17
|
+
beforeDelete?: (ctx: SupabaseHandlerContext) => Promise<void>;
|
|
18
|
+
}
|
|
1
19
|
/**
|
|
2
20
|
* Create a Supabase Edge Function handler for account deletion.
|
|
3
21
|
*
|
|
22
|
+
* @param options - Optional `beforeDelete` step; without it, deletes the user directly
|
|
4
23
|
* @returns `(req: Request) => Promise<Response>` handler
|
|
5
24
|
*
|
|
6
25
|
* @example
|
|
@@ -10,7 +29,20 @@
|
|
|
10
29
|
* Deno.serve(createDeleteAccount());
|
|
11
30
|
* ```
|
|
12
31
|
*
|
|
13
|
-
* @
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Refuse while the account still has open orders (the SQL function raises 'open_orders')
|
|
35
|
+
* Deno.serve(
|
|
36
|
+
* createDeleteAccount({
|
|
37
|
+
* beforeDelete: async ({ supabaseAdmin, uid }) => {
|
|
38
|
+
* const { error } = await supabaseAdmin.rpc('close_my_account', { p_uid: uid });
|
|
39
|
+
* if (error) throw error; // → 409 { error: 'open_orders', code: 'P0001' }
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @version 0.2.0
|
|
14
46
|
* @since 0.5.0
|
|
15
47
|
*/
|
|
16
|
-
export declare function createDeleteAccount(): (req: Request) => Promise<Response>;
|
|
48
|
+
export declare function createDeleteAccount(options?: DeleteAccountOptions): (req: Request) => Promise<Response>;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Generic handler to create an entity in Supabase.
|
|
3
|
-
* @description Provides a reusable implementation for creating documents in PostgreSQL with validation.
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.5.0
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
import * as v from 'valibot';
|
|
10
2
|
import type { UserRole } from '@donotdev/core/server';
|
|
11
3
|
/** Request payload for creating an entity with optional idempotency. */
|
|
@@ -48,6 +48,19 @@ export interface EntityStore<Row> {
|
|
|
48
48
|
/** Updates the rows matching `where` (hidden rows included) and returns them as stored. */
|
|
49
49
|
update(where: readonly EntityStoreCondition[], patch: EntityStoreValues<Row>): Promise<Row[]>;
|
|
50
50
|
}
|
|
51
|
+
/** The PostgREST filter builder methods the store uses. */
|
|
52
|
+
export interface Filterable {
|
|
53
|
+
eq(column: string, value: unknown): this;
|
|
54
|
+
neq(column: string, value: unknown): this;
|
|
55
|
+
gt(column: string, value: unknown): this;
|
|
56
|
+
gte(column: string, value: unknown): this;
|
|
57
|
+
lt(column: string, value: unknown): this;
|
|
58
|
+
lte(column: string, value: unknown): this;
|
|
59
|
+
in(column: string, values: readonly unknown[]): this;
|
|
60
|
+
not(column: string, operator: string, value: unknown): this;
|
|
61
|
+
contains(column: string, value: unknown): this;
|
|
62
|
+
overlaps(column: string, value: unknown): this;
|
|
63
|
+
}
|
|
51
64
|
/**
|
|
52
65
|
* Creates an entity-aware CRUD store for server code.
|
|
53
66
|
*
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Generic handler to update an entity in Supabase.
|
|
3
|
-
* @description Provides a reusable implementation for updating documents in PostgreSQL with validation.
|
|
4
|
-
*
|
|
5
|
-
* @version 0.1.0
|
|
6
|
-
* @since 0.5.0
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
import * as v from 'valibot';
|
|
10
2
|
import type { UserRole } from '@donotdev/core/server';
|
|
11
3
|
/** Request payload for updating an entity by ID with optional idempotency. */
|
package/lib/supabase/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { createEdgeFunction } from './edgeFunction.js';
|
|
|
12
12
|
export type { EdgeFunctionContext, EdgeFunctionOptions, } from './edgeFunction.js';
|
|
13
13
|
export { createSupabaseAuthProvider } from './helpers/authProvider.js';
|
|
14
14
|
export { createDeleteAccount } from './auth/deleteAccount.js';
|
|
15
|
+
export type { DeleteAccountOptions } from './auth/deleteAccount.js';
|
|
15
16
|
export { createSetCustomClaims } from './auth/setCustomClaims.js';
|
|
16
17
|
export type { SetCustomClaimsOptions } from './auth/setCustomClaims.js';
|
|
17
18
|
export { createGetCustomClaims } from './auth/getCustomClaims.js';
|