@donotdev/firebase 0.0.9 → 0.0.11
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/dist/client/FirestoreAdapter.d.ts +45 -0
- package/dist/client/FirestoreAdapter.d.ts.map +1 -0
- package/dist/client/FirestoreAdapter.js +1 -0
- package/dist/client/callableProvider.d.ts +30 -0
- package/dist/client/callableProvider.d.ts.map +1 -0
- package/dist/client/callableProvider.js +1 -0
- package/dist/client/firestore.d.ts.map +1 -1
- package/dist/client/firestore.js +1 -1
- package/dist/client/functions.js +1 -1
- package/dist/client/imageProcessing.d.ts.map +1 -1
- package/dist/client/imageProcessing.js +1 -1
- package/dist/client/index.d.ts +3 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/sdk.d.ts +35 -0
- package/dist/client/sdk.d.ts.map +1 -1
- package/dist/client/sdk.js +1 -1
- package/dist/client/storage.d.ts.map +1 -1
- package/dist/client/storage.js +1 -1
- package/dist/client/storageAdapter.d.ts +33 -0
- package/dist/client/storageAdapter.d.ts.map +1 -0
- package/dist/client/storageAdapter.js +1 -0
- package/dist/server/authAdapter.d.ts +33 -0
- package/dist/server/authAdapter.d.ts.map +1 -0
- package/dist/server/authAdapter.js +1 -0
- package/dist/server/batch.d.ts +5 -4
- package/dist/server/batch.d.ts.map +1 -1
- package/dist/server/batch.js +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/init.d.ts +9 -6
- package/dist/server/init.d.ts.map +1 -1
- package/dist/server/subscription.d.ts +25 -4
- package/dist/server/subscription.d.ts.map +1 -1
- package/dist/server/subscription.js +1 -1
- package/dist/server/uniqueness.d.ts +10 -3
- package/dist/server/uniqueness.d.ts.map +1 -1
- package/dist/server/uniqueness.js +1 -1
- package/dist/server/utils.d.ts +5 -6
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/server/utils.js +1 -1
- package/dist/server/validation.d.ts +1 -1
- package/dist/server/validation.d.ts.map +1 -1
- package/dist/server/validation.js +1 -1
- package/dist/shared/types.d.ts +2 -14
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/utils.d.ts +0 -24
- package/dist/shared/utils.d.ts.map +1 -1
- package/dist/shared/utils.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { dndevSchema, ICrudAdapter, QueryOptions, PaginatedQueryResult, ListSchemaType } from '@donotdev/core';
|
|
2
|
+
import { type Unsubscribe, type FirestoreError } from './firestore';
|
|
3
|
+
/**
|
|
4
|
+
* Subscription callback for document subscriptions
|
|
5
|
+
*
|
|
6
|
+
* @version 0.0.1
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
export type SubscriptionCallback<T> = (data: T | null, error?: FirestoreError) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Subscription callback for collection subscriptions
|
|
13
|
+
*
|
|
14
|
+
* @version 0.0.1
|
|
15
|
+
* @since 0.0.1
|
|
16
|
+
* @author AMBROISE PARK Consulting
|
|
17
|
+
*/
|
|
18
|
+
export type CollectionSubscriptionCallback<T> = (data: T[], error?: FirestoreError) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Firestore backend adapter
|
|
21
|
+
* Works with any collection dynamically (collection name passed per operation)
|
|
22
|
+
*
|
|
23
|
+
* @version 0.0.1
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
* @author AMBROISE PARK Consulting
|
|
26
|
+
*/
|
|
27
|
+
export declare class FirestoreAdapter implements ICrudAdapter {
|
|
28
|
+
private firestore;
|
|
29
|
+
private firestoreInitPromise;
|
|
30
|
+
private ensureFirestore;
|
|
31
|
+
private requireFirestore;
|
|
32
|
+
private getCollectionRef;
|
|
33
|
+
get<T>(collectionName: string, id: string, schema?: dndevSchema<unknown>): Promise<T | null>;
|
|
34
|
+
set<T>(collectionName: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
|
|
35
|
+
update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
|
|
36
|
+
delete(collectionName: string, id: string): Promise<void>;
|
|
37
|
+
add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<{
|
|
38
|
+
id: string;
|
|
39
|
+
data: Record<string, unknown>;
|
|
40
|
+
}>;
|
|
41
|
+
query<T>(collectionName: string, options: QueryOptions, schema?: dndevSchema<unknown>, _schemaType?: ListSchemaType): Promise<PaginatedQueryResult<T>>;
|
|
42
|
+
subscribe<T>(collectionName: string, id: string, callback: SubscriptionCallback<T>, schema?: dndevSchema<unknown>): Unsubscribe;
|
|
43
|
+
subscribeToCollection<T>(collectionName: string, options: QueryOptions, callback: CollectionSubscriptionCallback<T>, schema?: dndevSchema<unknown>): Unsubscribe;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=FirestoreAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirestoreAdapter.d.ts","sourceRoot":"","sources":["../../src/client/FirestoreAdapter.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAsBL,KAAK,WAAW,EAChB,KAAK,cAAc,EAGpB,MAAM,aAAa,CAAC;AAMrB;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CACpC,IAAI,EAAE,CAAC,GAAG,IAAI,EACd,KAAK,CAAC,EAAE,cAAc,KACnB,IAAI,CAAC;AACV;;;;;;GAMG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,IAAI,CAC9C,IAAI,EAAE,CAAC,EAAE,EACT,KAAK,CAAC,EAAE,cAAc,KACnB,IAAI,CAAC;AAEV;;;;;;;GAOG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,O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,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,WAAW;IA4Cd,qBAAqB,CAAC,CAAC,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,8BAA8B,CAAC,CAAC,CAAC,EAC3C,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,GAC5B,WAAW;CAwEf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{wrapCrudError as d,validateWithSchema as p,ensureSpreadable as A}from"@donotdev/core";import{doc as w,getDoc as b,getDocs as B,setDoc as P,updateDoc as T,deleteDoc as x,addDoc as z,collection as D,query as m,where as q,orderBy as C,limit as I,startAfter as V,onSnapshot as R,transformFirestoreData as E,prepareForFirestore as g}from"./firestore";import{getFirebaseFirestore as M}from"./firestore";import{getFirebaseSDK as O}from"./sdk";class j{firestore;firestoreInitPromise=null;async ensureFirestore(){return this.firestore?!0:this.firestoreInitPromise?this.firestoreInitPromise:(this.firestoreInitPromise=M().then(r=>(this.firestore=r,this.firestoreInitPromise=null,!0)).catch(()=>(this.firestoreInitPromise=null,!1)),this.firestoreInitPromise)}async requireFirestore(r,e){if(await this.ensureFirestore()&&this.firestore)return this.firestore;throw d(new Error("Firestore not initialized"),"FirestoreAdapter",r,e)}async getCollectionRef(r){return!await this.ensureFirestore()||!this.firestore?null:D(this.firestore,r)}async get(r,e,n){if(!await this.ensureFirestore()||!this.firestore)return null;try{const i=w(this.firestore,r,e),a=await b(i);if(!a.exists())return null;let t=a.data();if(!t)return null;t=E(t);const o=n?p(n,t,"FirestoreAdapter.get"):t;return{...A(o),id:e}}catch(i){if(i instanceof Error&&i.message?.includes("not found"))return null;throw d(i,"FirestoreAdapter","get",r,e)}}async set(r,e,n,i){const a=await this.requireFirestore("set",r);try{const t=p(i,n,"FirestoreAdapter.set"),o=w(a,r,e),s=g(t);await P(o,s)}catch(t){throw d(t,"FirestoreAdapter","set",r,e)}}async update(r,e,n){const i=await this.requireFirestore("update",r);try{const a=w(i,r,e),t=g(n);await T(a,t)}catch(a){throw d(a,"FirestoreAdapter","update",r,e)}}async delete(r,e){const n=await this.requireFirestore("delete",r);try{const i=w(n,r,e);await x(i)}catch(i){throw d(i,"FirestoreAdapter","delete",r,e)}}async add(r,e,n){if(!await this.ensureFirestore())throw d(new Error("Firestore not initialized"),"FirestoreAdapter","add",r);try{const i=p(n,e,"FirestoreAdapter.add"),a=await this.getCollectionRef(r);if(!a)throw d(new Error("Firestore not initialized"),"FirestoreAdapter","add",r);const t=new Date().toISOString(),o=O().getCurrentUser()?.uid||"anonymous",s={...i,createdAt:t,updatedAt:t,createdById:o,updatedById:o},c=g(s),l=await z(a,c),f={...s,id:l.id};return{id:l.id,data:f}}catch(i){throw d(i,"FirestoreAdapter","add",r)}}async query(r,e,n,i){if(!await this.ensureFirestore())return{items:[]};const a=await this.getCollectionRef(r);if(!a)return{items:[]};try{const t=[];if(e.where)for(const u of e.where)t.push(q(u.field,u.operator,u.value));if(e.orderBy)for(const u of e.orderBy){const h=u.direction||"asc";t.push(C(u.field,h))}const o=e.startAfter??null;if(o){const u=await b(w(a,o));u.exists()&&t.push(V(u))}const s=e.limit?e.limit+1:void 0;s&&t.push(I(s));const c=m(a,...t),l=await B(c),f=[];l.forEach(u=>{try{let h=u.data();if(!h)return;h=E(h);const v=n?p(n,h,"FirestoreAdapter.query"):h;f.push({...A(v),id:u.id})}catch(h){throw d(h instanceof Error?h:new Error(String(h)),"FirestoreAdapter","query",r)}});const F=s?f.length>(e.limit||0):!1,y=F?f.slice(0,e.limit):f,S=y.length>0?y[y.length-1].id??null:null;return{items:y,hasMore:F,lastVisible:S,total:void 0}}catch(t){throw d(t,"FirestoreAdapter","query",r)}}subscribe(r,e,n,i){if(!this.firestore)return()=>{};const a=w(this.firestore,r,e);return R(a,t=>{try{if(!t.exists()){n(null);return}let o=t.data();o=E(o);const s=i?p(i,o,"FirestoreAdapter.subscribe"):o;n({...A(s),id:e})}catch(o){const s=d(o instanceof Error?o:new Error(String(o)),"FirestoreAdapter","subscribe",r,e);n(null,s)}},t=>{const o=d(t instanceof Error?t:new Error(String(t)),"FirestoreAdapter","subscribe",r,e);n(null,o)})}subscribeToCollection(r,e,n,i){if(!this.firestore)return()=>{};const a=D(this.firestore,r);if(!a)return()=>{};try{const t=[];if(e.where)for(const s of e.where)t.push(q(s.field,s.operator,s.value));if(e.orderBy)for(const s of e.orderBy){const c=s.direction||"asc";t.push(C(s.field,c))}e.limit&&t.push(I(e.limit));const o=m(a,...t);return R(o,s=>{try{const c=[];s.forEach(l=>{let f=l.data();f=E(f);const F=i?p(i,f,"FirestoreAdapter.subscribeToCollection"):f;c.push({...A(F),id:l.id})}),n(c)}catch(c){const l=d(c instanceof Error?c:new Error(String(c)),"FirestoreAdapter","subscribeToCollection",r);n([],l)}},s=>{const c=d(s instanceof Error?s:new Error(String(s)),"FirestoreAdapter","subscribeToCollection",r);n([],c)})}catch(t){const o=d(t instanceof Error?t:new Error(String(t)),"FirestoreAdapter","subscribeToCollection",r);return n([],o),()=>{}}}}export{j as FirestoreAdapter};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Firebase Callable Provider
|
|
3
|
+
* @description ICallableProvider implementation using Firebase Cloud Functions (httpsCallable).
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { ICallableProvider } from '@donotdev/core';
|
|
10
|
+
/**
|
|
11
|
+
* Invokes Firebase Cloud Functions via httpsCallable.
|
|
12
|
+
* Implements ICallableProvider so FunctionsAdapter uses the same interface as Supabase/custom.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { configureProviders } from '@donotdev/core';
|
|
17
|
+
* import { FirebaseCallableProvider } from '@donotdev/firebase';
|
|
18
|
+
*
|
|
19
|
+
* configureProviders({
|
|
20
|
+
* callable: new FirebaseCallableProvider(),
|
|
21
|
+
* // ...other providers
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class FirebaseCallableProvider implements ICallableProvider {
|
|
26
|
+
private readonly region;
|
|
27
|
+
constructor(region?: string);
|
|
28
|
+
call<TReq, TRes>(functionName: string, data: TReq): Promise<TRes>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=callableProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callableProvider.d.ts","sourceRoot":"","sources":["../../src/client/callableProvider.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AASxD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,wBAAyB,YAAW,iBAAiB;IAChE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,CAAC,EAAE,MAAM;IAQrB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAexE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{wrapCrudError as e,getPlatformEnvVar as o}from"@donotdev/core";import{getFirebaseFunctions as l,httpsCallable as s}from"./functions";class u{region;constructor(t){this.region=t??o("FIREBASE_FUNCTIONS_REGION")??"europe-west1"}async call(t,a){try{const r=await l(this.region);return(await s(r,t)(a)).data}catch(r){throw e(r instanceof Error?r:new Error(String(r)),"FirebaseCallableProvider","call",t)}}}export{u as FirebaseCallableProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../src/client/firestore.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"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BAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAMnE;;GAEG;AACH,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,EACL,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,SAAS,IAAI,kBAAkB,EAC/B,QAAQ,IAAI,iBAAiB,EAC7B,UAAU,IAAI,mBAAmB,GAClC,MAAM,oBAAoB,CAAC"}
|
package/dist/client/firestore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getFirestore as
|
|
1
|
+
import{getFirestore as p,connectFirestoreEmulator as c}from"firebase/firestore";import{getPlatformEnvVar as e}from"@donotdev/core";import{getFirebaseSDK as f}from"./sdk";let t=null,r=null;function F(){return t?Promise.resolve(t):r||(r=(async()=>{const s=await f().getApp(),o=p(s),n=e("NODE_ENV")==="development",i=e("USE_FIREBASE_EMULATOR")==="true";if(n&&i){const a=e("FIREBASE_EMULATOR_HOST")||"localhost",m=parseInt(e("FIREBASE_FIRESTORE_EMULATOR_PORT")||"8080");c(o,a,m)}return t=o,r=null,t})(),r)}import{getFirestore as d}from"firebase/firestore";import{doc as g,getDoc as A,getDocs as I,setDoc as R,updateDoc as O,deleteDoc as _,addDoc as v}from"firebase/firestore";import{collection as y,collectionGroup as B}from"firebase/firestore";import{query as U,where as L,orderBy as w,limit as M,limitToLast as V,startAt as b,startAfter as k,endAt as G,endBefore as N}from"firebase/firestore";import{onSnapshot as C,onSnapshotsInSync as H}from"firebase/firestore";import{writeBatch as j,runTransaction as z}from"firebase/firestore";import{serverTimestamp as Q,increment as W,arrayUnion as X,arrayRemove as Y}from"firebase/firestore";import{FieldValue as $,GeoPoint as rr}from"firebase/firestore";import{Timestamp as tr}from"firebase/firestore";import{transformFirestoreData as sr}from"../shared/transform";import{convertISOStringsToDates as ir}from"../shared/transform";import{prepareForFirestore as mr}from"../shared/transform";import{toTimestamp as cr}from"../shared/transform";import{firestoreToISOString as lr}from"../shared/transform";import{createFirestorePartialUpdate as Er}from"../shared/transform";export{$ as FieldValue,tr as FirestoreTimestampClass,rr as GeoPoint,v as addDoc,Y as arrayRemove,X as arrayUnion,y as collection,B as collectionGroup,ir as convertISOStringsToDates,Er as createFirestorePartialUpdate,_ as deleteDoc,g as doc,G as endAt,N as endBefore,lr as firestoreToISOString,A as getDoc,I as getDocs,F as getFirebaseFirestore,d as getFirestore,W as increment,M as limit,V as limitToLast,C as onSnapshot,H as onSnapshotsInSync,w as orderBy,mr as prepareForFirestore,U as query,z as runTransaction,Q as serverTimestamp,R as setDoc,k as startAfter,b as startAt,cr as toTimestamp,sr as transformFirestoreData,O as updateDoc,L as where,j as writeBatch};
|
package/dist/client/functions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getFunctions as d,connectFunctionsEmulator as m}from"firebase/functions";import{getPlatformEnvVar as
|
|
1
|
+
import{getFunctions as d,connectFunctionsEmulator as m}from"firebase/functions";import{getPlatformEnvVar as o}from"@donotdev/core";import{getFirebaseSDK as f}from"./sdk";const n=new Set;async function O(a){const r=await f().getApp(),s=a||o("FIREBASE_FUNCTIONS_REGION")||"europe-west1",c=d(r,s),i=o("NODE_ENV")==="development",l=o("USE_FIREBASE_EMULATOR")==="true";if(i&&l){const e=`${r.name}_${s}`;if(!n.has(e)){const u=o("FIREBASE_EMULATOR_HOST")||"localhost",E=o("FIREBASE_FUNCTIONS_EMULATOR_PORT")||"5001";try{m(c,u,parseInt(E)),n.add(e),typeof window<"u"&&o("NODE_ENV")}catch(t){(t instanceof Error?t.message:String(t)).includes("already")&&typeof window<"u"&&o("NODE_ENV"),n.add(e)}}}return c}import{httpsCallable as A}from"firebase/functions";export{O as getFirebaseFunctions,A as httpsCallable};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageProcessing.d.ts","sourceRoot":"","sources":["../../src/client/imageProcessing.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,oDAAoD;;;;;IAEpD,8CAA8C;;;;;IAE9C,2CAA2C;;;;;CAEnC,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,wBAAwB;IACxB,UAAU,EAAE,eAAe,CAAC;IAC5B,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,IAAI,EAAE,IAAI,CAAC;IACX,oCAAoC;IACpC,QAAQ,EAAE,YAAY,CAAC;IACvB,uBAAuB;IACvB,UAAU,EAAE,eAAe,CAAC;CAC7B;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"imageProcessing.d.ts","sourceRoot":"","sources":["../../src/client/imageProcessing.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,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E,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAwBpC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAa9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import v from"browser-image-compression";const f={full:{width:1600,height:1200},thumbnail:{width:320,height:240},medium:{width:800,height:600}};async function p(a,t){const{dimensions:e,quality:i=.9,maxSizeMB:
|
|
1
|
+
import v from"browser-image-compression";const f={full:{width:1600,height:1200},thumbnail:{width:320,height:240},medium:{width:800,height:600}};async function p(a,t){const{dimensions:e,quality:i=.9,maxSizeMB:n=2,backgroundColor:c,maintainAspectRatio:b=!0}=t,x=await v(a,{maxSizeMB:n,useWebWorker:!0}),l=await new Promise((s,u)=>{const o=new Image;o.onload=()=>s(o),o.onerror=()=>{URL.revokeObjectURL(o.src),u(new Error("Failed to load image"))},o.src=URL.createObjectURL(x)});URL.revokeObjectURL(l.src);const r=document.createElement("canvas");r.width=e.width,r.height=e.height;const m=r.getContext("2d");if(!m)throw new Error("Could not get canvas context");c?(m.fillStyle=c,m.fillRect(0,0,r.width,r.height)):m.clearRect(0,0,r.width,r.height);let w=0,g=0,d=e.width,h=e.height;if(b){const s=Math.min(e.width/l.width,e.height/l.height);d=l.width*s,h=l.height*s,w=(e.width-d)/2,g=(e.height-h)/2}return m.drawImage(l,w,g,d,h),{blob:await new Promise((s,u)=>{r.toBlob(o=>{o?s(o):u(new Error("Failed to convert canvas to blob"))},"image/webp",i)}),mimeType:"image/webp",dimensions:e}}async function R(a,t){const e=t?.fullDimensions??f.full,i=t?.thumbnailDimensions??f.thumbnail,[n,c]=await Promise.all([p(a,{dimensions:e,quality:t?.quality,maxSizeMB:t?.maxSizeMB}),p(a,{dimensions:i,quality:t?.quality??.8,maxSizeMB:1})]);return{full:n,thumbnail:c}}function B(a,t){const{maxSizeMB:e=10,allowedTypes:i=["image/jpeg","image/png","image/webp","image/gif"]}=t??{};if(!i.includes(a.type))return{valid:!1,error:`Invalid file type. Allowed: ${i.join(", ")}`};const n=a.size/(1024*1024);return n>e?{valid:!1,error:`File too large (${n.toFixed(2)}MB). Maximum: ${e}MB`}:{valid:!0}}function I(a){return new Promise((t,e)=>{const i=new FileReader;i.onload=()=>{typeof i.result=="string"?t(i.result):e(new Error("Failed to read file"))},i.onerror=()=>e(new Error("Failed to read file")),i.readAsDataURL(a)})}export{f as DEFAULT_DIMENSIONS,I as createImagePreview,p as processImage,R as processImageWithThumbnail,B as validateImageFile};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -9,5 +9,7 @@ export * from './sdk';
|
|
|
9
9
|
export * from './firestore';
|
|
10
10
|
export * from './functions';
|
|
11
11
|
export * from './storage';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './storageAdapter';
|
|
13
|
+
export * from './callableProvider';
|
|
14
|
+
export * from './FirestoreAdapter';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAGH,cAAc,OAAO,CAAC;AAGtB,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC;AAG5B,cAAc,WAAW,CAAC;AAG1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAGH,cAAc,OAAO,CAAC;AAGtB,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC;AAG5B,cAAc,WAAW,CAAC;AAG1B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./sdk";export*from"./firestore";export*from"./functions";export*from"./storage";export*from"./
|
|
1
|
+
export*from"./sdk";export*from"./firestore";export*from"./functions";export*from"./storage";export*from"./storageAdapter";export*from"./callableProvider";export*from"./FirestoreAdapter";
|
package/dist/client/sdk.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as firebaseAuth from 'firebase/auth';
|
|
2
2
|
import { GoogleAuthProvider, GithubAuthProvider, FacebookAuthProvider, TwitterAuthProvider, EmailAuthProvider, PhoneAuthProvider } from 'firebase/auth';
|
|
3
|
+
import type { SecurityContext } from '@donotdev/core';
|
|
3
4
|
import type { FirebaseApp } from 'firebase/app';
|
|
4
5
|
import type { User, UserCredential, AuthProvider, OAuthProvider, RecaptchaVerifier, Unsubscribe, ActionCodeSettings, AuthCredential, MultiFactorResolver, MultiFactorUser, AdditionalUserInfo, Persistence } from 'firebase/auth';
|
|
5
6
|
export type { User as FirebaseUser, UserInfo, OAuthCredential, AuthCredential, } from 'firebase/auth';
|
|
@@ -34,6 +35,13 @@ export { GoogleAuthProvider, GithubAuthProvider, FacebookAuthProvider, TwitterAu
|
|
|
34
35
|
declare class FirebaseSDK {
|
|
35
36
|
/** Tracks initialization state */
|
|
36
37
|
private initialized;
|
|
38
|
+
/**
|
|
39
|
+
* In-flight initialization promise — guards against concurrent calls.
|
|
40
|
+
* Boolean flag alone is insufficient: two callers can both pass the `if (this.initialized)`
|
|
41
|
+
* check before either sets it to true (TOCTOU race). The promise ensures all concurrent
|
|
42
|
+
* callers wait on the same single initialization.
|
|
43
|
+
*/
|
|
44
|
+
private _initPromise;
|
|
37
45
|
/** Firebase app instance */
|
|
38
46
|
private app;
|
|
39
47
|
/** Firebase auth instance - managed internally */
|
|
@@ -42,6 +50,32 @@ declare class FirebaseSDK {
|
|
|
42
50
|
private appCheck;
|
|
43
51
|
/** Tracks if auth emulator has been connected (can only connect once) */
|
|
44
52
|
private authEmulatorConnected;
|
|
53
|
+
/** Optional security context for audit logging + brute-force lockout (SOC2 CC6.1, CC6.2) */
|
|
54
|
+
private security;
|
|
55
|
+
/**
|
|
56
|
+
* Default lockout tracker — used when no SecurityContext is injected.
|
|
57
|
+
* When `setSecurity()` is called, delegation is to `security.authHardening` which
|
|
58
|
+
* respects the consumer's configured maxAttempts / lockoutMs.
|
|
59
|
+
* Using AuthHardening (not a raw Map) ensures a single lockout implementation across the stack.
|
|
60
|
+
*/
|
|
61
|
+
private readonly defaultHardening;
|
|
62
|
+
/**
|
|
63
|
+
* Inject a SecurityContext for audit logging + anomaly detection.
|
|
64
|
+
*
|
|
65
|
+
* @version 0.0.1
|
|
66
|
+
* @since 0.0.1
|
|
67
|
+
*/
|
|
68
|
+
setSecurity(security: SecurityContext): void;
|
|
69
|
+
/** Active hardening — SecurityContext's when injected, otherwise the default instance. */
|
|
70
|
+
private get _hardening();
|
|
71
|
+
/**
|
|
72
|
+
* Throws if email is currently locked out (SOC2 CC6.2).
|
|
73
|
+
* Uses SecurityContext.authHardening when injected (respects consumer config),
|
|
74
|
+
* otherwise the default AuthHardening instance with standard defaults.
|
|
75
|
+
*/
|
|
76
|
+
private _checkLockout;
|
|
77
|
+
private _recordLockoutFailure;
|
|
78
|
+
private _clearLockout;
|
|
45
79
|
/**
|
|
46
80
|
* Initialize Firebase app and auth
|
|
47
81
|
*
|
|
@@ -59,6 +93,7 @@ declare class FirebaseSDK {
|
|
|
59
93
|
* ```
|
|
60
94
|
*/
|
|
61
95
|
initialize(): Promise<void>;
|
|
96
|
+
private _doInitialize;
|
|
62
97
|
/**
|
|
63
98
|
* Ensure auth instance is initialized before use
|
|
64
99
|
*
|
package/dist/client/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/client/sdk.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAA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MAAM,cAAc,mBAA2C,CAAC"}
|
package/dist/client/sdk.js
CHANGED
|
@@ -18,4 +18,4 @@
|
|
|
18
18
|
* @license Commercial
|
|
19
19
|
*
|
|
20
20
|
* @module @donotdev/firebase/sdk
|
|
21
|
-
*/import{initializeApp as A,getApps as d}from"firebase/app";import{initializeAppCheck as w,ReCaptchaEnterpriseProvider as m}from"firebase/app-check";import*as i from"firebase/auth";import{GoogleAuthProvider as v}from"firebase/auth";import{createSingleton as y,getPlatformEnvVar as n,getAuthDomain as k,handleError as l}from"@donotdev/core";import{GoogleAuthProvider as O,GithubAuthProvider as K,FacebookAuthProvider as M,TwitterAuthProvider as N,OAuthProvider as L,EmailAuthProvider as H}from"firebase/auth";let a=null,u,p=!1,I=0;class f{initialized=!1;app=null;auth=null;appCheck=null;authEmulatorConnected=!1;async initialize(){if(!this.initialized)try{const e=n("FIREBASE_API_KEY"),t=n("FIREBASE_PROJECT_ID");if(!e||!t){this.initialized=!0;return}const r=k(),s={apiKey:e,authDomain:r,projectId:t,storageBucket:n("FIREBASE_STORAGE_BUCKET"),messagingSenderId:n("FIREBASE_MESSAGING_SENDER_ID"),appId:n("FIREBASE_APP_ID"),measurementId:n("FIREBASE_MEASUREMENT_ID")};if(d().length===0?this.app=A(s):this.app=d()[0]||null,this.auth=this.app?i.getAuth(this.app):null,this.auth)try{await i.setPersistence(this.auth,i.browserLocalPersistence)}catch{}const P=n("NODE_ENV")==="development",E=n("USE_FIREBASE_EMULATOR")==="true";if(P&&E&&this.auth&&!this.authEmulatorConnected){const o=n("FIREBASE_EMULATOR_HOST"),g=n("FIREBASE_EMULATOR_PORT")||"9099";if(o)try{await i.connectAuthEmulator(this.auth,`http://${o}:${g}`,{disableWarnings:!0}),this.authEmulatorConnected=!0}catch(h){const c=h instanceof Error?h.message:String(h);(c.includes("already")||c.includes("emulator-config-failed"))&&(this.authEmulatorConnected=!0)}}this.initialized=!0}catch(e){throw l(e,{showNotification:!1,severity:"warning",context:{operation:"FirebaseSDK.initialize"}}),e}}ensureInitialized(){if(!this.auth)throw new Error("Firebase Auth not initialized. Call initialize() first.");return this.auth}async initializeAppCheck(e){if(!this.app||this.appCheck)return;const t=n("RECAPTCHA_SITE_KEY");if(t)try{if(e&&typeof window<"u"){const r=n("APPCHECK_DEBUG_TOKEN");window.FIREBASE_APPCHECK_DEBUG_TOKEN=r||!0}this.appCheck=w(this.app,{provider:new m(t),isTokenAutoRefreshEnabled:!0})}catch{}}appCheckInitPromise=null;async ensureAppCheckInitialized(){if(this.appCheck||!this.initialized)return;if(this.appCheckInitPromise)return this.appCheckInitPromise;const e=n("NODE_ENV")==="development";return this.appCheckInitPromise=this.initializeAppCheck(e).then(()=>{this.appCheckInitPromise=null}).catch(t=>{throw this.appCheckInitPromise=null,t}),this.appCheckInitPromise}isAppCheckEnabled(){return this.appCheck!==null}async getApp(){if(await this.initialize(),!this.app)throw new Error("Firebase app not initialized. This should never happen after initialize().");return this.app}onAuthStateChanged(e){const t=this.ensureInitialized();return i.onAuthStateChanged(t,e)}beforeAuthStateChanged(e){const t=this.ensureInitialized();return i.beforeAuthStateChanged(t,e)}getCurrentUser(){return this.ensureInitialized().currentUser}async getRedirectResult(){const e=this.ensureInitialized(),t=Date.now(),r=t-I;return u!==void 0?u:a||(p=!0,I=t,a=i.getRedirectResult(e).then(s=>(u=s,a=null,s)).catch(s=>{throw l(s,{showNotification:!1,severity:"warning",context:{operation:"getRedirectResult"}}),a=null,p=!1,s}),a)}async signInWithRedirect(e){const t=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithRedirect(t,e)}async signInWithPopup(e){const t=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithPopup(t,e)}async signInWithEmailAndPassword(e,t){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithEmailAndPassword(r,e,t)}async createUserWithEmailAndPassword(e,t){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.createUserWithEmailAndPassword(r,e,t)}async sendPasswordResetEmail(e,t){const r=this.ensureInitialized();return i.sendPasswordResetEmail(r,e,t)}async confirmPasswordReset(e,t){const r=this.ensureInitialized();return i.confirmPasswordReset(r,e,t)}async verifyPasswordResetCode(e){const t=this.ensureInitialized();return i.verifyPasswordResetCode(t,e)}async signInWithEmailLink(e,t){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithEmailLink(r,e,t)}async sendSignInLinkToEmail(e,t){const r=this.ensureInitialized();return i.sendSignInLinkToEmail(r,e,t)}isSignInWithEmailLink(e){const t=this.ensureInitialized();return i.isSignInWithEmailLink(t,e)}async signInWithCustomToken(e){const t=this.ensureInitialized();return i.signInWithCustomToken(t,e)}async signInAnonymously(){const e=this.ensureInitialized();return i.signInAnonymously(e)}async signInWithCredential(e){const t=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithCredential(t,e)}async signInWithPhoneNumber(e,t){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithPhoneNumber(r,e,t)}async signOut(){const e=this.ensureInitialized();return i.signOut(e)}async sendEmailVerification(e,t){return i.sendEmailVerification(e,t)}async updatePassword(e,t){return i.updatePassword(e,t)}async updateEmail(e,t){return i.updateEmail(e,t)}async updateProfile(e,t){return i.updateProfile(e,t)}async reload(e){return i.reload(e)}async deleteUser(e){return i.deleteUser(e)}async getIdToken(e,t){return i.getIdToken(e,t)}async getIdTokenResult(e,t){return i.getIdTokenResult(e,t)}async linkWithCredential(e,t){return i.linkWithCredential(e,t)}async linkWithPopup(e,t){return i.linkWithPopup(e,t)}async linkWithRedirect(e,t){return i.linkWithRedirect(e,t)}async linkWithPhoneNumber(e,t,r){return i.linkWithPhoneNumber(e,t,r)}async unlink(e,t){return i.unlink(e,t)}async fetchSignInMethodsForEmail(e){const t=this.ensureInitialized();return i.fetchSignInMethodsForEmail(t,e)}async reauthenticateWithCredential(e,t){return i.reauthenticateWithCredential(e,t)}async reauthenticateWithPopup(e,t){return i.reauthenticateWithPopup(e,t)}async reauthenticateWithRedirect(e,t){return i.reauthenticateWithRedirect(e,t)}createGoogleProvider(){return new i.GoogleAuthProvider}createGithubProvider(){return new i.GithubAuthProvider}createFacebookProvider(){return new i.FacebookAuthProvider}createTwitterProvider(){return new i.TwitterAuthProvider}createMicrosoftProvider(){return new i.OAuthProvider("microsoft.com")}createAppleProvider(){return new i.OAuthProvider("apple.com")}createOAuthProvider(e){return new i.OAuthProvider(e)}createPhoneAuthProvider(){const e=this.ensureInitialized();return new i.PhoneAuthProvider(e)}createEmailAuthProvider(){return i.EmailAuthProvider}createRecaptchaVerifier(e,t){const r=this.ensureInitialized();return new i.RecaptchaVerifier(r,e,t)}multiFactor(e){return i.multiFactor(e)}getMultiFactorResolver(e){const t=this.ensureInitialized();return i.getMultiFactorResolver(t,e)}getAdditionalUserInfo(e){return i.getAdditionalUserInfo(e)}async setPersistence(e){const t=this.ensureInitialized();return i.setPersistence(t,e)}useDeviceLanguage(){const e=this.ensureInitialized();return i.useDeviceLanguage(e)}async checkActionCode(e){const t=this.ensureInitialized();return i.checkActionCode(t,e)}async applyActionCode(e){const t=this.ensureInitialized();return i.applyActionCode(t,e)}async signInWithGoogle(){const e=this.createGoogleProvider();return await this.signInWithPopup(e)}async signInWithGoogleRedirect(){const e=this.createGoogleProvider();return await this.signInWithRedirect(e)}async signInWithGitHub(){const e=this.createGithubProvider();return await this.signInWithPopup(e)}async signInWithGitHubRedirect(){const e=this.createGithubProvider();return await this.signInWithRedirect(e)}async signInWithFacebook(){const e=this.createFacebookProvider();return await this.signInWithPopup(e)}async signInWithFacebookRedirect(){const e=this.createFacebookProvider();return await this.signInWithRedirect(e)}async signInWithTwitter(){const e=this.createTwitterProvider();return await this.signInWithPopup(e)}async signInWithTwitterRedirect(){const e=this.createTwitterProvider();return await this.signInWithRedirect(e)}async signInWithMicrosoft(){const e=this.createMicrosoftProvider();return await this.signInWithPopup(e)}async signInWithMicrosoftRedirect(){const e=this.createMicrosoftProvider();return await this.signInWithRedirect(e)}async signInWithApple(){const e=this.createAppleProvider();return await this.signInWithPopup(e)}async signInWithAppleRedirect(){const e=this.createAppleProvider();return await this.signInWithRedirect(e)}async signInWithGoogleCredential(e){const t=this.createGoogleProvider(),r=v.credential(e);return await this.signInWithCredential(r)}async signInWithEmail(e,t){return await this.signInWithEmailAndPassword(e,t)}async createUserWithEmail(e,t){return await this.createUserWithEmailAndPassword(e,t)}async linkWithGoogle(e){const t=this.createGoogleProvider();return await this.linkWithPopup(e,t)}async linkWithGitHub(e){const t=this.createGithubProvider();return await this.linkWithPopup(e,t)}async linkWithFacebook(e){const t=this.createFacebookProvider();return await this.linkWithPopup(e,t)}async linkWithTwitter(e){const t=this.createTwitterProvider();return await this.linkWithPopup(e,t)}async linkWithMicrosoft(e){const t=this.createMicrosoftProvider();return await this.linkWithPopup(e,t)}async linkWithApple(e){const t=this.createAppleProvider();return await this.linkWithPopup(e,t)}reset(){this.initialized=!1,this.auth=null,this.app=null,this.appCheck=null}}const D=y(()=>new f);export{H as EmailAuthProvider,M as FacebookAuthProvider,K as GithubAuthProvider,O as GoogleAuthProvider,L as OAuthProvider,N as TwitterAuthProvider,D as getFirebaseSDK};
|
|
21
|
+
*/import{initializeApp as g,getApps as d}from"firebase/app";import{initializeAppCheck as E,ReCaptchaEnterpriseProvider as A}from"firebase/app-check";import*as i from"firebase/auth";import{GoogleAuthProvider as y}from"firebase/auth";import{createSingleton as w,getPlatformEnvVar as n,getAuthDomain as k,handleError as l}from"@donotdev/core";import{AuthHardening as m}from"@donotdev/core";import{GoogleAuthProvider as D,GithubAuthProvider as O,FacebookAuthProvider as K,TwitterAuthProvider as M,OAuthProvider as N,EmailAuthProvider as H}from"firebase/auth";let a=null,u;class f{initialized=!1;_initPromise=null;app=null;auth=null;appCheck=null;authEmulatorConnected=!1;security=null;defaultHardening=new m;setSecurity(t){this.security=t}get _hardening(){return this.security?.authHardening??this.defaultHardening}_checkLockout(t){this._hardening.checkLockout(t)}_recordLockoutFailure(t){const e=this._hardening.recordFailure(t);e.locked&&this.security?.audit({type:"auth.locked",metadata:{attempts:e.attempts}}),this.security?.audit({type:"auth.login.failure"})}_clearLockout(t){this._hardening.recordSuccess(t)}async initialize(){if(!this.initialized)return this._initPromise?this._initPromise:(this._initPromise=this._doInitialize().finally(()=>{this._initPromise=null}),this._initPromise)}async _doInitialize(){try{const t=n("FIREBASE_API_KEY"),e=n("FIREBASE_PROJECT_ID");if(!t||!e){this.initialized=!0;return}const r=k(),s={apiKey:t,authDomain:r,projectId:e,storageBucket:n("FIREBASE_STORAGE_BUCKET"),messagingSenderId:n("FIREBASE_MESSAGING_SENDER_ID"),appId:n("FIREBASE_APP_ID"),measurementId:n("FIREBASE_MEASUREMENT_ID")};if(d().length===0?this.app=g(s):this.app=d()[0]||null,this.auth=this.app?i.getAuth(this.app):null,this.auth)try{await i.setPersistence(this.auth,i.browserLocalPersistence)}catch{}const p=n("NODE_ENV")==="development",I=n("USE_FIREBASE_EMULATOR")==="true";if(p&&I&&this.auth&&!this.authEmulatorConnected){const o=n("FIREBASE_EMULATOR_HOST"),P=n("FIREBASE_EMULATOR_PORT")||"9099";if(o)try{await i.connectAuthEmulator(this.auth,`http://${o}:${P}`,{disableWarnings:!0}),this.authEmulatorConnected=!0}catch(h){const c=h instanceof Error?h.message:String(h);(c.includes("already")||c.includes("emulator-config-failed"))&&(this.authEmulatorConnected=!0)}}this.initialized=!0}catch(t){throw l(t,{showNotification:!1,severity:"warning",context:{operation:"FirebaseSDK.initialize"}}),t}}ensureInitialized(){if(!this.auth)throw new Error("Firebase Auth not initialized. Call initialize() first.");return this.auth}async initializeAppCheck(t){if(!this.app||this.appCheck)return;const e=n("RECAPTCHA_SITE_KEY");if(e)try{if(t&&typeof window<"u"){const r=n("APPCHECK_DEBUG_TOKEN");window.FIREBASE_APPCHECK_DEBUG_TOKEN=r||!0}this.appCheck=E(this.app,{provider:new A(e),isTokenAutoRefreshEnabled:!0})}catch{}}appCheckInitPromise=null;async ensureAppCheckInitialized(){if(this.appCheck||!this.initialized)return;if(this.appCheckInitPromise)return this.appCheckInitPromise;const t=n("NODE_ENV")==="development";return this.appCheckInitPromise=this.initializeAppCheck(t).then(()=>{this.appCheckInitPromise=null}).catch(e=>{throw this.appCheckInitPromise=null,e}),this.appCheckInitPromise}isAppCheckEnabled(){return this.appCheck!==null}async getApp(){if(await this.initialize(),!this.app)throw new Error("Firebase app not initialized. This should never happen after initialize().");return this.app}onAuthStateChanged(t){const e=this.ensureInitialized();return i.onAuthStateChanged(e,t)}beforeAuthStateChanged(t){const e=this.ensureInitialized();return i.beforeAuthStateChanged(e,t)}getCurrentUser(){return this.ensureInitialized().currentUser}async getRedirectResult(){const t=this.ensureInitialized();return u!==void 0?u:a||(a=i.getRedirectResult(t).then(e=>(u=e,a=null,e)).catch(e=>{throw l(e,{showNotification:!1,severity:"warning",context:{operation:"getRedirectResult"}}),a=null,e}),a)}async signInWithRedirect(t){const e=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithRedirect(e,t)}async signInWithPopup(t){const e=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithPopup(e,t)}async signInWithEmailAndPassword(t,e){this._checkLockout(t);const r=this.ensureInitialized();await this.ensureAppCheckInitialized();try{const s=await i.signInWithEmailAndPassword(r,t,e);return this._clearLockout(t),this.security?.audit({type:"auth.login.success",userId:s.user.uid,metadata:{email:t}}),s}catch(s){throw this._recordLockoutFailure(t),this.security?.audit({type:"auth.login.failure",metadata:{email:t}}),s}}async createUserWithEmailAndPassword(t,e){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.createUserWithEmailAndPassword(r,t,e)}async sendPasswordResetEmail(t,e){const r=this.ensureInitialized();return i.sendPasswordResetEmail(r,t,e)}async confirmPasswordReset(t,e){const r=this.ensureInitialized();return i.confirmPasswordReset(r,t,e)}async verifyPasswordResetCode(t){const e=this.ensureInitialized();return i.verifyPasswordResetCode(e,t)}async signInWithEmailLink(t,e){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithEmailLink(r,t,e)}async sendSignInLinkToEmail(t,e){const r=this.ensureInitialized();return i.sendSignInLinkToEmail(r,t,e)}isSignInWithEmailLink(t){const e=this.ensureInitialized();return i.isSignInWithEmailLink(e,t)}async signInWithCustomToken(t){const e=this.ensureInitialized();return i.signInWithCustomToken(e,t)}async signInAnonymously(){const t=this.ensureInitialized();return i.signInAnonymously(t)}async signInWithCredential(t){const e=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithCredential(e,t)}async signInWithPhoneNumber(t,e){const r=this.ensureInitialized();return await this.ensureAppCheckInitialized(),i.signInWithPhoneNumber(r,t,e)}async signOut(){const t=this.ensureInitialized(),e=t.currentUser;await i.signOut(t),this.security?.audit({type:"auth.logout",userId:e?.uid})}async sendEmailVerification(t,e){return i.sendEmailVerification(t,e)}async updatePassword(t,e){return i.updatePassword(t,e)}async updateEmail(t,e){return i.updateEmail(t,e)}async updateProfile(t,e){return i.updateProfile(t,e)}async reload(t){return i.reload(t)}async deleteUser(t){return i.deleteUser(t)}async getIdToken(t,e){return i.getIdToken(t,e)}async getIdTokenResult(t,e){return i.getIdTokenResult(t,e)}async linkWithCredential(t,e){return i.linkWithCredential(t,e)}async linkWithPopup(t,e){return i.linkWithPopup(t,e)}async linkWithRedirect(t,e){return i.linkWithRedirect(t,e)}async linkWithPhoneNumber(t,e,r){return i.linkWithPhoneNumber(t,e,r)}async unlink(t,e){return i.unlink(t,e)}async fetchSignInMethodsForEmail(t){const e=this.ensureInitialized();return i.fetchSignInMethodsForEmail(e,t)}async reauthenticateWithCredential(t,e){return i.reauthenticateWithCredential(t,e)}async reauthenticateWithPopup(t,e){return i.reauthenticateWithPopup(t,e)}async reauthenticateWithRedirect(t,e){return i.reauthenticateWithRedirect(t,e)}createGoogleProvider(){return new i.GoogleAuthProvider}createGithubProvider(){return new i.GithubAuthProvider}createFacebookProvider(){return new i.FacebookAuthProvider}createTwitterProvider(){return new i.TwitterAuthProvider}createMicrosoftProvider(){return new i.OAuthProvider("microsoft.com")}createAppleProvider(){return new i.OAuthProvider("apple.com")}createOAuthProvider(t){return new i.OAuthProvider(t)}createPhoneAuthProvider(){const t=this.ensureInitialized();return new i.PhoneAuthProvider(t)}createEmailAuthProvider(){return i.EmailAuthProvider}createRecaptchaVerifier(t,e){const r=this.ensureInitialized();return new i.RecaptchaVerifier(r,t,e)}multiFactor(t){return i.multiFactor(t)}getMultiFactorResolver(t){const e=this.ensureInitialized();return i.getMultiFactorResolver(e,t)}getAdditionalUserInfo(t){return i.getAdditionalUserInfo(t)}async setPersistence(t){const e=this.ensureInitialized();return i.setPersistence(e,t)}useDeviceLanguage(){const t=this.ensureInitialized();return i.useDeviceLanguage(t)}async checkActionCode(t){const e=this.ensureInitialized();return i.checkActionCode(e,t)}async applyActionCode(t){const e=this.ensureInitialized();return i.applyActionCode(e,t)}async signInWithGoogle(){const t=this.createGoogleProvider();return await this.signInWithPopup(t)}async signInWithGoogleRedirect(){const t=this.createGoogleProvider();return await this.signInWithRedirect(t)}async signInWithGitHub(){const t=this.createGithubProvider();return await this.signInWithPopup(t)}async signInWithGitHubRedirect(){const t=this.createGithubProvider();return await this.signInWithRedirect(t)}async signInWithFacebook(){const t=this.createFacebookProvider();return await this.signInWithPopup(t)}async signInWithFacebookRedirect(){const t=this.createFacebookProvider();return await this.signInWithRedirect(t)}async signInWithTwitter(){const t=this.createTwitterProvider();return await this.signInWithPopup(t)}async signInWithTwitterRedirect(){const t=this.createTwitterProvider();return await this.signInWithRedirect(t)}async signInWithMicrosoft(){const t=this.createMicrosoftProvider();return await this.signInWithPopup(t)}async signInWithMicrosoftRedirect(){const t=this.createMicrosoftProvider();return await this.signInWithRedirect(t)}async signInWithApple(){const t=this.createAppleProvider();return await this.signInWithPopup(t)}async signInWithAppleRedirect(){const t=this.createAppleProvider();return await this.signInWithRedirect(t)}async signInWithGoogleCredential(t){const e=this.createGoogleProvider(),r=y.credential(t);return await this.signInWithCredential(r)}async signInWithEmail(t,e){return await this.signInWithEmailAndPassword(t,e)}async createUserWithEmail(t,e){return await this.createUserWithEmailAndPassword(t,e)}async linkWithGoogle(t){const e=this.createGoogleProvider();return await this.linkWithPopup(t,e)}async linkWithGitHub(t){const e=this.createGithubProvider();return await this.linkWithPopup(t,e)}async linkWithFacebook(t){const e=this.createFacebookProvider();return await this.linkWithPopup(t,e)}async linkWithTwitter(t){const e=this.createTwitterProvider();return await this.linkWithPopup(t,e)}async linkWithMicrosoft(t){const e=this.createMicrosoftProvider();return await this.linkWithPopup(t,e)}async linkWithApple(t){const e=this.createAppleProvider();return await this.linkWithPopup(t,e)}reset(){this.initialized=!1,this._initPromise=null,this.auth=null,this.app=null,this.appCheck=null}}const U=w(()=>new f);export{H as EmailAuthProvider,K as FacebookAuthProvider,O as GithubAuthProvider,D as GoogleAuthProvider,N as OAuthProvider,M as TwitterAuthProvider,U as getFirebaseSDK};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/client/storage.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAQL,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/client/stor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M,WAAW,qBAAqB;IACpC,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,CAAC,CA0ChC;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,IAAI,EAAE,EACb,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAKlC"}
|
package/dist/client/storage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getStorage as
|
|
1
|
+
import{getStorage as u,ref as s,uploadBytes as w,uploadBytesResumable as U,getDownloadURL as d,deleteObject as h,listAll as I}from"firebase/storage";const F=10*1024*1024;function T(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_")}function b(e){return e.replace(/\.{2,}/g,".").replace(/^\/+|\/+$/g,"").replace(/[^a-zA-Z0-9._-]/g,"_")}function $(e,t){const a=Date.now(),o=T(t||e);return`${a}_${o}`}function z(e,t){const a=[b(t.basePath)];return t.subfolder&&a.push(b(t.subfolder)),a.push(e),a.join("/")}function D(e,t){const a=t.maxSize??F,o=e instanceof File?e.name:"blob";if(e.size>a)throw new Error(`File size (${(e.size/1024/1024).toFixed(2)}MB) exceeds maximum allowed (${(a/1024/1024).toFixed(2)}MB)`);const n=u(),r=$(o,t.filename),l=z(r,t),p=s(n,l),m=t.metadata||{},c=U(p,e,m);t.onProgress&&c.on("state_changed",i=>{const g=i.bytesTransferred/i.totalBytes*100;t.onProgress({bytesTransferred:i.bytesTransferred,totalBytes:i.totalBytes,progress:g})});const f=c.then(async()=>({url:await d(p),path:l,filename:o}));return{task:c,promise:f}}async function R(e,t){const a=t.maxSize??F;if(e.size>a)throw new Error(`File size (${(e.size/1024/1024).toFixed(2)}MB) exceeds maximum allowed (${(a/1024/1024).toFixed(2)}MB)`);const o=u(),n=$(e.name,t.filename),r=z(n,t),l=s(o,r);return await w(l,e),{url:await d(l),path:r,filename:e.name}}async function A(e,t){const a=e.map(o=>R(o,t));return Promise.all(a)}async function E(e){try{const t=u(),o=new URL(e).pathname.match(/\/o\/(.+)$/);if(o&&o[1]){const n=decodeURIComponent(o[1]),r=s(t,n);await h(r)}}catch(t){throw t}}async function L(e){try{const t=u(),a=s(t,e);await h(a)}catch(t){throw t}}async function N(e){const t=e.map(a=>E(a));await Promise.all(t)}async function B(e){const t=u(),a=s(t,e);return(await I(a)).items}async function O(e){const a=(await B(e)).map(o=>d(o));return Promise.all(a)}async function Z(e){const t=u(),a=s(t,e);return d(a)}function C(e){const t=u();return s(t,e)}async function k(e){const a=(await B(e)).map(o=>h(o));await Promise.all(a)}async function W(e,t,a){return R(e,{basePath:t,subfolder:a,maxSize:5*1024*1024})}async function X(e,t,a){return A(e,{basePath:t,subfolder:a,maxSize:5*1024*1024})}async function M(e,t,a){const{processImageWithThumbnail:o}=await import("./imageProcessing"),{full:n,thumbnail:r}=await o(e),l=u(),m=`${Date.now()}_${e.name.replace(/\.[^/.]+$/,"")}`,c=b(t),f=a?b(a):void 0,i=f?`${c}/${f}/${m}_full.webp`:`${c}/${m}_full.webp`,g=f?`${c}/${f}/${m}_thumb.webp`:`${c}/${m}_thumb.webp`,x={contentType:"image/webp",cacheControl:"public, max-age=2592000"},y=s(l,i),P=s(l,g);await Promise.all([w(y,n.blob,x),w(P,r.blob,x)]);const[S,_]=await Promise.all([d(y),d(P)]);return{fullUrl:S,thumbUrl:_,fullPath:i,thumbPath:g}}async function q(e,t,a){const o=e.map(n=>M(n,t,a));return Promise.all(o)}export{C as createStorageRef,k as deleteAllFiles,L as deleteFileByPath,E as deleteFileByUrl,N as deleteFilesByUrl,Z as getFileUrl,O as getFileUrls,B as listFiles,R as uploadFile,D as uploadFileResumable,A as uploadFiles,W as uploadImage,X as uploadImages,M as uploadProcessedImage,q as uploadProcessedImages};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Firebase Storage Adapter
|
|
3
|
+
* @description IStorageAdapter implementation using Firebase Storage.
|
|
4
|
+
* Wraps the existing Firebase storage utilities behind the provider-agnostic interface.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.0.1
|
|
7
|
+
* @since 0.5.0
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
import type { IStorageAdapter, UploadOptions, UploadResult } from '@donotdev/core';
|
|
11
|
+
/**
|
|
12
|
+
* Firebase Storage adapter implementing IStorageAdapter.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { FirebaseStorageAdapter } from '@donotdev/firebase';
|
|
17
|
+
* import { configureProviders } from '@donotdev/core';
|
|
18
|
+
*
|
|
19
|
+
* configureProviders({
|
|
20
|
+
* crud: new FirestoreAdapter(),
|
|
21
|
+
* storage: new FirebaseStorageAdapter(),
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @version 0.0.1
|
|
26
|
+
* @since 0.5.0
|
|
27
|
+
*/
|
|
28
|
+
export declare class FirebaseStorageAdapter implements IStorageAdapter {
|
|
29
|
+
upload(file: File | Blob, options?: UploadOptions): Promise<UploadResult>;
|
|
30
|
+
delete(urlOrPath: string): Promise<void>;
|
|
31
|
+
getUrl(path: string): Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=storageAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storageAdapter.d.ts","sourceRoot":"","sources":["../../src/client/storageAdapter.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,YAAY,EACb,MAAM,gBAAgB,CAAC;AAcxB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IACtD,MAAM,CACV,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC;IA6BlB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAO5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{wrapStorageError as o}from"@donotdev/core";import{uploadFileResumable as d,deleteFileByUrl as i,deleteFileByPath as p,getFileUrl as g}from"./storage";class u{async upload(e,r){try{const a=r?.storagePath??"uploads",{promise:s}=d(e,{basePath:a,filename:r?.filename,onProgress:r?.onProgress?l=>r.onProgress(l.progress):void 0}),t=await s;if(!t.url||!t.path)throw o(new Error("Upload returned no URL or path"),"FirebaseStorageAdapter","upload",a);return{url:t.url,path:t.path}}catch(a){throw o(a,"FirebaseStorageAdapter","upload",r?.storagePath||"uploads")}}async delete(e){try{e.startsWith("http")?await i(e):await p(e)}catch(r){throw o(r,"FirebaseStorageAdapter","delete",e)}}async getUrl(e){try{return await g(e)}catch(r){throw o(r,"FirebaseStorageAdapter","getUrl",e)}}}export{u as FirebaseStorageAdapter};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Firebase Server Auth Adapter
|
|
3
|
+
* @description IServerAuthAdapter implementation using Firebase Admin SDK.
|
|
4
|
+
* Wraps Firebase Admin auth operations behind the provider-agnostic interface.
|
|
5
|
+
*
|
|
6
|
+
* @version 0.0.1
|
|
7
|
+
* @since 0.5.0
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
import type { IServerAuthAdapter, VerifiedToken, ServerUserRecord } from '@donotdev/core';
|
|
11
|
+
/**
|
|
12
|
+
* Firebase Admin SDK adapter implementing IServerAuthAdapter.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { FirebaseServerAuthAdapter } from '@donotdev/firebase/server';
|
|
17
|
+
* import { configureProviders } from '@donotdev/core';
|
|
18
|
+
*
|
|
19
|
+
* configureProviders({
|
|
20
|
+
* crud: new FirestoreAdapter(),
|
|
21
|
+
* serverAuth: new FirebaseServerAuthAdapter(),
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @version 0.0.1
|
|
26
|
+
* @since 0.5.0
|
|
27
|
+
*/
|
|
28
|
+
export declare class FirebaseServerAuthAdapter implements IServerAuthAdapter {
|
|
29
|
+
verifyToken(token: string): Promise<VerifiedToken>;
|
|
30
|
+
getUser(uid: string): Promise<ServerUserRecord | null>;
|
|
31
|
+
setCustomClaims(uid: string, claims: Record<string, unknown>): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=authAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authAdapter.d.ts","sourceRoot":"","sources":["../../src/server/authAdapter.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AASxB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,yBAA0B,YAAW,kBAAkB;IAC5D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAclD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAoBtD,eAAe,CACnB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CAcjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{wrapAuthError as a}from"@donotdev/core";import{getFirebaseAdminAuth as t}from"./init";class u{async verifyToken(r){try{const e=await t().verifyIdToken(r);return{uid:e.uid,email:e.email,claims:e}}catch(e){throw a(e,"FirebaseServerAuthAdapter","verifyToken")}}async getUser(r){try{const e=await t().getUser(r);return{uid:e.uid,email:e.email,displayName:e.displayName,customClaims:e.customClaims??{}}}catch(e){if(e.code==="auth/user-not-found")return null;throw a(e,"FirebaseServerAuthAdapter","getUser",{uid:r})}}async setCustomClaims(r,e){try{const i=(await t().getUser(r)).customClaims??{};await t().setCustomUserClaims(r,{...i,...e})}catch(s){throw a(s,"FirebaseServerAuthAdapter","setCustomClaims",{uid:r})}}}export{u as FirebaseServerAuthAdapter};
|
package/dist/server/batch.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { dndevSchema } from '@donotdev/core';
|
|
2
|
+
import type { DocumentReference, DocumentSnapshot } from 'firebase-admin/firestore';
|
|
2
3
|
interface FirestoreTransaction {
|
|
3
|
-
get: (docRef:
|
|
4
|
-
set: (docRef:
|
|
5
|
-
update: (docRef:
|
|
6
|
-
delete: (docRef:
|
|
4
|
+
get: (docRef: DocumentReference) => Promise<DocumentSnapshot>;
|
|
5
|
+
set: (docRef: DocumentReference, data: Record<string, unknown>, options?: Record<string, unknown>) => FirestoreTransaction;
|
|
6
|
+
update: (docRef: DocumentReference, data: Record<string, unknown>) => FirestoreTransaction;
|
|
7
|
+
delete: (docRef: DocumentReference) => FirestoreTransaction;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Result of a batch operation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/server/batch.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CA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AAC,CAAC,GAAG,IAAI,CAAC,CAgIK,CAAC"}
|
package/dist/server/batch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as W from"valibot";import{handleError as p}from"@donotdev/core/server";import{getServerFirestore as E}from"./utils";import{prepareForFirestore as $,transformFirestoreData as B}from"../shared/transform";const w=typeof window<"u",u={async batchWrite(e,t,r,i,y={}){if(!t||!t.length)return{successes:0,failures:0};const{idField:s="id",generateIds:I=!0,maxBatchSize:C=450,removeFields:f=[],validate:D=!!i}=y,n={successes:0,failures:0,failedItems:[]};try{const d=[],h=await E();let c=h.batch(),l=0;for(let b=0;b<t.length;b++){let o=t[b];if(!o){n.failures++,n.failedItems?.push({index:b,error:new Error("Item is null or undefined")});continue}try{if(r==="delete"){if(!o[s])throw p(new Error(`Missing ID for delete operation (${s})`),{userMessage:"Unable to delete item: missing ID",severity:"error",context:{collection:e,idField:s,operation:r}});const a=h.collection(e).doc(o[s]);c.delete(a)}else{if(D&&i)try{W.parse(i,o)}catch(F){throw p(F,{userMessage:"Validation failed for item",severity:"warning",context:{collection:e,operation:r,idField:s,itemId:o[s]}})}let a=o[s];if(!a&&r==="create"&&I)a=h.collection(e).doc().id,o={...o,[s]:a};else if(!a)throw p(new Error(`Missing ID for ${r} operation (${s})`),{userMessage:`Unable to ${r} item: missing ID`,severity:"error",context:{collection:e,idField:s,operation:r}});const v=[s,...f],m=$(o,v),M=h.collection(e).doc(a);r==="create"?c.create(M,m):r==="update"&&c.update(M,m)}l++,l>=C&&(d.push({batch:c,size:l}),c=h.batch(),l=0)}catch(a){n.failures++,n.failedItems?.push({index:b,error:a instanceof Error?a:new Error(String(a))})}}l>0&&d.push({batch:c,size:l});let x=0;for(const{batch:b,size:o}of d){try{await b.commit(),n.successes+=o}catch(a){const v=a instanceof Error?a:new Error(String(a));for(let m=x;m<x+o;m++)n.failures++,n.failedItems?.push({index:m,error:v})}x+=o}return n}catch(d){throw p(d,{userMessage:`Batch ${r} operation failed for collection ${e}`,context:{collection:e,operation:r,itemCount:t.length,processedCount:n.successes+n.failures,successCount:n.successes,failureCount:n.failures}})}},async batchCreate(e,t,r,i={}){return u.batchWrite(e,t,"create",r,i)},async batchUpdate(e,t,r,i={}){return u.batchWrite(e,t,"update",r,i)},async batchDelete(e,t,r={}){if(t.length>0&&typeof t[0]=="string"){const i=r.idField||"id",y=t.map(s=>({[i]:s}));return u.batchWrite(e,y,"delete",void 0,r)}return u.batchWrite(e,t,"delete",void 0,r)},async runTransaction(e){try{return await(await E()).runTransaction(e)}catch(t){throw p(t,{userMessage:"Transaction failed"})}},async bulkGet(e,t,r={}){if(!t.length)return[];const{maxBatchSize:i=30,transform:y=!0}=r;try{const s=[];for(let f=0;f<t.length;f+=i)s.push(t.slice(f,f+i));const I=s.map(async f=>{const d=await(await E()).collection(e).where("__name__","in",f).get(),h=new Map;return d.forEach(c=>{h.set(c.id,c.data())}),f.map(c=>{const l=h.get(c);return l?y?B({id:c,...l}):{id:c,...l}:null})});return(await Promise.all(I)).flat()}catch(s){throw p(s,{userMessage:`Bulk get operation failed for collection ${e}`,context:{collection:e,idCount:t.length}})}}},g=e=>()=>{throw new Error(`Firebase Admin function '${e}' is not available in browser environments`)},U=w?g("batchWrite"):u.batchWrite,k=w?g("batchCreate"):u.batchCreate,R=w?g("batchUpdate"):u.batchUpdate,G=w?g("batchDelete"):u.batchDelete,_=w?g("runTransaction"):u.runTransaction,A=w?g("bulkGet"):u.bulkGet;export{k as batchCreate,G as batchDelete,R as batchUpdate,U as batchWrite,A as bulkGet,_ as runTransaction};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAG7B,cAAc,qBAAqB,CAAC;AAGpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAG7B,cAAc,qBAAqB,CAAC;AAGpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./init";export*from"./utils";export*from"./batch";export*from"./subscription";export*from"./validation";export*from"./uniqueness";export*from"../shared/transform";import{FieldValue as
|
|
1
|
+
export*from"./authAdapter";export*from"./init";export*from"./utils";export*from"./batch";export*from"./subscription";export*from"./validation";export*from"./uniqueness";export*from"../shared/transform";import{FieldValue as l,Query as u,Timestamp as d}from"firebase-admin/firestore";export{l as FieldValue,u as Query,d as Timestamp};
|
package/dist/server/init.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { App } from 'firebase-admin/app';
|
|
2
|
+
import type { Auth } from 'firebase-admin/auth';
|
|
3
|
+
import type { Firestore } from 'firebase-admin/firestore';
|
|
4
|
+
import type { Functions } from 'firebase-admin/functions';
|
|
2
5
|
export interface FirebaseAdminServices {
|
|
3
6
|
app: App | null;
|
|
4
|
-
auth:
|
|
5
|
-
firestore:
|
|
6
|
-
functions:
|
|
7
|
+
auth: Auth | null;
|
|
8
|
+
firestore: Firestore | null;
|
|
9
|
+
functions: Functions | null;
|
|
7
10
|
}
|
|
8
11
|
export declare function initFirebaseAdmin(): Promise<FirebaseAdminServices>;
|
|
9
12
|
export declare function getFirebaseAdminApp(): Promise<App>;
|
|
10
|
-
export declare function getFirebaseAdminAuth():
|
|
11
|
-
export declare function getFirebaseAdminFirestore():
|
|
12
|
-
export declare function getFirebaseAdminFunctions():
|
|
13
|
+
export declare function getFirebaseAdminAuth(): Auth;
|
|
14
|
+
export declare function getFirebaseAdminFirestore(): Firestore;
|
|
15
|
+
export declare function getFirebaseAdminFunctions(): Functions;
|
|
13
16
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/server/init.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/server/init.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IAEhB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;CAC7B;AAwDD,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAUxE;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC,CAMxD;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAM3C;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAMrD;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAMrD"}
|
|
@@ -105,13 +105,34 @@ export declare function updateSubscriptionStatus(subscriptionId: string, status:
|
|
|
105
105
|
*/
|
|
106
106
|
export declare function hasFeatureAccess(userId: string, featureKey: string, options?: SubscriptionOptions): Promise<boolean>;
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @
|
|
108
|
+
* Options for verifying and handling a Stripe webhook request.
|
|
109
|
+
*
|
|
110
|
+
* @version 0.0.1
|
|
111
|
+
* @since 0.0.1
|
|
112
|
+
* @author AMBROISE PARK Consulting
|
|
113
|
+
*/
|
|
114
|
+
export interface StripeWebhookOptions extends SubscriptionOptions {
|
|
115
|
+
/** Raw request body as string or Buffer (required for HMAC verification) */
|
|
116
|
+
rawBody: string | Buffer;
|
|
117
|
+
/** Value of the Stripe-Signature header */
|
|
118
|
+
signature: string;
|
|
119
|
+
/** Stripe webhook endpoint secret (whsec_...) */
|
|
120
|
+
webhookSecret: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Verifies the Stripe webhook HMAC signature and handles the event.
|
|
124
|
+
*
|
|
125
|
+
* NC2 fix: previously handleStripeWebhookEvent accepted a pre-parsed event with no
|
|
126
|
+
* signature verification — any caller could forge arbitrary Stripe events.
|
|
127
|
+
* This function must be used instead: it calls stripe.webhooks.constructEvent()
|
|
128
|
+
* before processing the payload.
|
|
129
|
+
*
|
|
130
|
+
* @param options - Webhook options including rawBody, signature, and webhookSecret
|
|
131
|
+
* @returns The verified Stripe event type that was processed
|
|
111
132
|
*
|
|
112
133
|
* @version 0.0.1
|
|
113
134
|
* @since 0.0.1
|
|
114
135
|
* @author AMBROISE PARK Consulting
|
|
115
136
|
*/
|
|
116
|
-
export declare function
|
|
137
|
+
export declare function verifyAndHandleStripeWebhook(options: StripeWebhookOptions): Promise<void>;
|
|
117
138
|
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/server/subscription.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/server/subscription.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA+BzD;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA8BlC;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAsB7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,gBAAgB,EAC9B,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAoC3B;AAED;;;;;;;;;GASG;AACH,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,OAAO,CAAC,CAgClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,4EAA4E;IAC5E,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA+Bf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as
|
|
1
|
+
import{handleError as d}from"@donotdev/core/server";import{getServerFirestore as u}from"./utils";import{prepareForFirestore as w,transformFirestoreData as h}from"../shared/transform";import{handleFirebaseError as l}from"../shared/utils";async function f(t,r={}){const{collection:o="subscriptions",userIdField:e="customerId"}=r;try{const s=await(await u()).collection(o).where(e,"==",t).where("status","==","active").limit(1).get();if(s.empty)return null;const n=s.docs[0];if(!n)return null;const i=n.data();return h({id:n.id,...i})}catch(a){throw l(a,"getActiveSubscription")}}async function k(t,r={}){const{collection:o="subscriptions",userIdField:e="customerId"}=r;try{return(await(await u()).collection(o).where(e,"==",t).orderBy("createdAt","desc").get()).docs.map(n=>h({id:n.id,...n.data()}))}catch(a){throw l(a,"getUserSubscriptions")}}async function m(t,r={}){const{collection:o="subscriptions"}=r;try{const e=await u(),a=new Date().toISOString(),c={...t,createdAt:t.createdAt||a,updatedAt:a},s=w(c),{id:n,...i}=s,p=n?e.collection(o).doc(n):e.collection(o).doc();return await p.set(i,{merge:!0}),{...c,id:p.id}}catch(e){throw l(e,"saveSubscription")}}async function y(t,r,o={}){const{collection:e="subscriptions"}=o;try{await(await u()).collection(e).doc(t).update({status:r,updatedAt:new Date().toISOString()})}catch(a){throw l(a,"updateSubscriptionStatus")}}async function F(t,r,o={}){try{const e=await f(t,o);return e?e.features&&Array.isArray(e.features)?e.features.includes(r):e.metadata&&e.metadata[r]?e.metadata[r]==="true":!1:!1}catch(e){throw d(e,{userMessage:"Failed to check feature access",severity:"error",context:{function:"hasFeatureAccess",userId:t,featureKey:r}})}}async function x(t){const{rawBody:r,signature:o,webhookSecret:e,...a}=t;let c;try{const n=await import("stripe"),i=n.default??n;c=new i("placeholder",{apiVersion:"2023-10-16"})}catch{throw d(new Error("stripe package is not installed"),{userMessage:"Stripe package missing \u2014 cannot verify webhook signature",severity:"error"})}let s;try{s=c.webhooks.constructEvent(r,o,e)}catch(n){throw d(n,{userMessage:"Stripe webhook signature verification failed",severity:"error",context:{function:"verifyAndHandleStripeWebhook"}})}await b(s,a)}async function b(t,r={}){const o=t.type,e=t.data.object;try{switch(o){case"customer.subscription.created":case"customer.subscription.updated":await g(e,r);break;case"customer.subscription.deleted":await y(e.id,"canceled",r);break;default:}}catch(a){throw d(a,{userMessage:`Failed to handle Stripe webhook event: ${o}`,severity:"error",context:{eventType:o,eventId:t.id}})}}async function g(t,r={}){if(!t.items.data.length)throw d(new Error("[subscription] Stripe subscription has no items"),{userMessage:"Stripe subscription has no items \u2014 cannot determine plan",severity:"error",context:{subscriptionId:t.id}});const o={id:t.id,customerId:t.customer,status:t.status,planId:t.items.data[0]?.plan.id||"",currentPeriodStart:new Date(t.current_period_start*1e3).toISOString(),currentPeriodEnd:new Date(t.current_period_end*1e3).toISOString(),cancelAtPeriodEnd:t.cancel_at_period_end,metadata:t.metadata||{},createdAt:new Date(t.created*1e3).toISOString(),updatedAt:new Date().toISOString()};t.canceled_at&&(o.canceledAt=new Date(t.canceled_at*1e3).toISOString()),await m(o,r)}export{f as getActiveSubscription,k as getUserSubscriptions,F as hasFeatureAccess,m as saveSubscription,y as updateSubscriptionStatus,x as verifyAndHandleStripeWebhook};
|
|
@@ -43,14 +43,21 @@ export declare function hasUniqueConstraintValidator(): boolean;
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function createFirestoreValidator(): Promise<UniqueConstraintValidator>;
|
|
45
45
|
/**
|
|
46
|
-
* Creates
|
|
47
|
-
*
|
|
46
|
+
* Creates an Admin SDK Firestore validator for server-side uniqueness checks.
|
|
47
|
+
* Renamed from createFirestoreClientValidator — C1 fix: the old name was misleading;
|
|
48
|
+
* this function exclusively uses the Firebase Admin SDK and must never run in a browser.
|
|
49
|
+
* @returns An Admin Firestore uniqueness constraint validator
|
|
48
50
|
*
|
|
49
51
|
* @version 0.0.1
|
|
50
52
|
* @since 0.0.1
|
|
51
53
|
* @author AMBROISE PARK Consulting
|
|
52
54
|
*/
|
|
53
|
-
export declare function
|
|
55
|
+
export declare function createAdminFirestoreValidator(): Promise<UniqueConstraintValidator>;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use createAdminFirestoreValidator instead.
|
|
58
|
+
* This alias is kept for backwards compatibility and will be removed in a future version.
|
|
59
|
+
*/
|
|
60
|
+
export declare const createFirestoreClientValidator: typeof createAdminFirestoreValidator;
|
|
54
61
|
/**
|
|
55
62
|
* Validates uniqueness constraints for a document
|
|
56
63
|
* @param collection Collection name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueness.d.ts","sourceRoot":"","sources":["../../src/server/uniqueness.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAYhE;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,yBAAyB,GACnC,IAAI,CAEN;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,IACxC,yBAAyB,GACzB,SAAS,CAEZ;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,IAAI,OAAO,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,yBAAyB,CAAC,
|
|
1
|
+
{"version":3,"file":"uniqueness.d.ts","sourceRoot":"","sources":["../../src/server/uniqueness.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAYhE;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,yBAAyB,GACnC,IAAI,CAEN;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,IACxC,yBAAyB,GACzB,SAAS,CAEZ;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,IAAI,OAAO,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAuCnF;AAED;;;;;;;;;GASG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAwCxF;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,sCAAgC,CAAC;AAE5E;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC,EACF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC,CAqDf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as l}from"@donotdev/core/server";import{getServerFirestore as
|
|
1
|
+
import{handleError as l}from"@donotdev/core/server";import{getServerFirestore as h}from"./utils";const d={};function f(n){d.uniqueConstraintValidator=n}function q(){return d.uniqueConstraintValidator}function V(){return!!d.uniqueConstraintValidator}async function y(){const n=await h(),o={checkDuplicate:async(a,r,t,i)=>{if(t==null)return!1;try{return(await n.collection(a).where(r,"==",t).get()).docs.some(e=>e.id!==i&&e.data()[r]===t)}catch(s){throw l(s,{userMessage:`Failed to check uniqueness for field "${r}"`,severity:"error",context:{collection:a,field:r,value:t}})}}};return f(o),o}async function w(){const n=await h(),o={checkDuplicate:async(a,r,t,i)=>{if(t==null)return!1;try{return(await n.collection(a).where(r,"==",t).get()).docs.some(e=>e.id!==i&&e.data()[r]===t)}catch(s){throw l(s,{userMessage:`Failed to check uniqueness for field "${r}"`,severity:"error",context:{collection:a,field:r,value:t}})}}};return f(o),o}const C=w;async function F(n,o,a,r){if(!o.length)return;let t=q();t||(t=await y());const i=[],c=(await Promise.allSettled(o.map(async({field:e,errorMessage:p})=>{const u=a[e];if(u==null)return;await t.checkDuplicate(n,e,u,r)&&i.push({field:e,message:p||`The ${e} must be unique`})}))).find(e=>e.status==="rejected");if(c&&c.status==="rejected")throw c.reason;if(i.length>0)throw l(new Error("Uniqueness validation failed"),{userMessage:"Uniqueness validation failed",severity:"error",context:{validationErrors:i,collection:n}})}export{w as createAdminFirestoreValidator,C as createFirestoreClientValidator,y as createFirestoreValidator,q as getUniqueConstraintValidator,V as hasUniqueConstraintValidator,f as registerUniqueConstraintValidator,F as validateUniqueness};
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
1
|
+
import type { App } from 'firebase-admin/app';
|
|
2
|
+
import type { Firestore } from 'firebase-admin/firestore';
|
|
3
3
|
/**
|
|
4
|
-
* Get Firebase Admin instance (server-only)
|
|
4
|
+
* Get Firebase Admin App instance (server-only)
|
|
5
5
|
*
|
|
6
6
|
* @version 0.0.1
|
|
7
7
|
* @since 0.0.1
|
|
8
8
|
* @author AMBROISE PARK Consulting
|
|
9
9
|
*/
|
|
10
|
-
export declare const getServerAdmin: () => Promise<
|
|
10
|
+
export declare const getServerAdmin: () => Promise<App>;
|
|
11
11
|
/**
|
|
12
12
|
* Get Firebase Admin Firestore instance (server-only)
|
|
13
13
|
*
|
|
@@ -15,7 +15,7 @@ export declare const getServerAdmin: () => Promise<FirebaseAdminType>;
|
|
|
15
15
|
* @since 0.0.1
|
|
16
16
|
* @author AMBROISE PARK Consulting
|
|
17
17
|
*/
|
|
18
|
-
export declare const getServerFirestore: () => Promise<
|
|
18
|
+
export declare const getServerFirestore: () => Promise<Firestore>;
|
|
19
19
|
/**
|
|
20
20
|
* Generate Firestore document ID (server-only)
|
|
21
21
|
*
|
|
@@ -24,5 +24,4 @@ export declare const getServerFirestore: () => Promise<FirestoreType>;
|
|
|
24
24
|
* @author AMBROISE PARK Consulting
|
|
25
25
|
*/
|
|
26
26
|
export declare const generateServerId: () => Promise<string>;
|
|
27
|
-
export {};
|
|
28
27
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AA4B1D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,OAAO,CAAC,GAAG,CAAwC,CAAC;AAEvF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,OAAO,CAAC,SAAS,CAA4C,CAAC;AAErG;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,QA/BD,OAAO,CAAC,MAAM,CA+B4B,CAAC"}
|
package/dist/server/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as t}from"@donotdev/core/server";const r={async getServerAdmin(){try{
|
|
1
|
+
import{handleError as t}from"@donotdev/core/server";import{getFirebaseAdminApp as o,getFirebaseAdminFirestore as n}from"./init";const r={async getServerAdmin(){try{return o()}catch(e){throw t(e,"Error getting Firebase Admin")}},async getServerFirestore(){try{return n()}catch(e){throw t(e,"Error getting Admin Firestore")}},async generateServerId(){return(await r.getServerFirestore()).collection("_").doc().id}},g=r.getServerAdmin,a=r.getServerFirestore,c=r.generateServerId;export{c as generateServerId,g as getServerAdmin,a as getServerFirestore};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import * as v from 'valibot';
|
|
9
9
|
import type { dndevSchema } from '@donotdev/core';
|
|
10
|
-
export { validateUniqueness, registerUniqueConstraintValidator, getUniqueConstraintValidator, hasUniqueConstraintValidator, createFirestoreValidator, createFirestoreClientValidator, } from './uniqueness';
|
|
10
|
+
export { validateUniqueness, registerUniqueConstraintValidator, getUniqueConstraintValidator, hasUniqueConstraintValidator, createFirestoreValidator, createAdminFirestoreValidator, createFirestoreClientValidator, } from './uniqueness';
|
|
11
11
|
/**
|
|
12
12
|
* Validates a Firestore document against its schema with enhanced checks
|
|
13
13
|
* @param schema - The Valibot schema to validate against
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/server/validation.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAA6B,MAAM,gBAAgB,CAAC;AAM7E,OAAO,EACL,kBAAkB,EAClB,iCAAiC,EACjC,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;GAWG;AAC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,CAAC,EACzB,SAAS,EAAE,QAAQ,GAAG,QAAQ,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,GACA,WAAW,CAAC,CAAC,CAAC,CAIhB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as i from"valibot";import{handleError as o}from"@donotdev/core/server";import{validateUniqueness as l}from"./uniqueness";import{validateUniqueness as v,registerUniqueConstraintValidator as V,getUniqueConstraintValidator as p,hasUniqueConstraintValidator as q,createFirestoreValidator as g,createAdminFirestoreValidator as w,createFirestoreClientValidator as F}from"./uniqueness";async function u(t,e,a,n){try{i.parse(t,e),t.metadata?.uniqueFields?.length&&await l(t.metadata.collection,t.metadata.uniqueFields,e,n),t.metadata?.customValidate&&await t.metadata.customValidate(e,a)}catch(r){throw i.isValiError(r)?o(r,{userMessage:"Document validation failed",context:{validationErrors:r.issues,data:e},severity:"warning"}):o(r,{userMessage:"Document validation failed",context:{collection:t.metadata?.collection||"unknown"},severity:"error"})}}function c(t,e){const a=t;return a.metadata=e,a}export{w as createAdminFirestoreValidator,F as createFirestoreClientValidator,g as createFirestoreValidator,c as enhanceSchema,p as getUniqueConstraintValidator,q as hasUniqueConstraintValidator,V as registerUniqueConstraintValidator,u as validateFirestoreDocument,v as validateUniqueness};
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -19,19 +19,7 @@ export interface FirebaseConfig {
|
|
|
19
19
|
storageBucket?: string;
|
|
20
20
|
messagingSenderId?: string;
|
|
21
21
|
appId?: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Firebase services interface
|
|
25
|
-
*
|
|
26
|
-
* @version 0.0.1
|
|
27
|
-
* @since 0.0.1
|
|
28
|
-
* @author AMBROISE PARK Consulting
|
|
29
|
-
*/
|
|
30
|
-
export interface FirebaseServices {
|
|
31
|
-
app: any | null;
|
|
32
|
-
auth: any | null;
|
|
33
|
-
firestore: any | null;
|
|
34
|
-
functions: any | null;
|
|
35
|
-
isDemoMode: boolean;
|
|
22
|
+
/** Firebase measurement ID for analytics (optional) */
|
|
23
|
+
measurementId?: string;
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
package/dist/shared/utils.d.ts
CHANGED
|
@@ -7,30 +7,6 @@
|
|
|
7
7
|
* @author AMBROISE PARK Consulting
|
|
8
8
|
*/
|
|
9
9
|
import type { FirebaseCallOptions } from '@donotdev/core';
|
|
10
|
-
/**
|
|
11
|
-
* Firebase Admin instance (not available in browser)
|
|
12
|
-
*
|
|
13
|
-
* @version 0.0.1
|
|
14
|
-
* @since 0.0.1
|
|
15
|
-
* @author AMBROISE PARK Consulting
|
|
16
|
-
*/
|
|
17
|
-
export declare const admin: (() => never) | null;
|
|
18
|
-
/**
|
|
19
|
-
* Get Firebase Admin Firestore instance (not available in browser)
|
|
20
|
-
*
|
|
21
|
-
* @version 0.0.1
|
|
22
|
-
* @since 0.0.1
|
|
23
|
-
* @author AMBROISE PARK Consulting
|
|
24
|
-
*/
|
|
25
|
-
export declare const getAdminFirestore: () => never;
|
|
26
|
-
/**
|
|
27
|
-
* Generate Firestore document ID (not available in browser)
|
|
28
|
-
*
|
|
29
|
-
* @version 0.0.1
|
|
30
|
-
* @since 0.0.1
|
|
31
|
-
* @author AMBROISE PARK Consulting
|
|
32
|
-
*/
|
|
33
|
-
export declare const generateId: () => never;
|
|
34
10
|
/**
|
|
35
11
|
* Creates an abort controller with timeout
|
|
36
12
|
* @param options Timeout and related options
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/shared/utils.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,eAAe,CA+BjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAKvE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAAC,CAAC,EAC9C,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CAChB,GACL,OAAO,CAAC,CAAC,CAAC,CA+BZ"}
|
package/dist/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as o}from"@donotdev/core";
|
|
1
|
+
import{handleError as o}from"@donotdev/core";function f(e){const t=new AbortController;let r;return e?.timeout&&(r=setTimeout(()=>{t.abort(o(new Error("Request timeout exceeded"),{userMessage:"The operation timed out",context:{timeoutMs:e.timeout,abortKey:e.abortKey}}))},e.timeout)),e?.externalSignal&&e.externalSignal.addEventListener("abort",()=>{t.abort(e.externalSignal?.reason||"External abort")}),t.signal.addEventListener("abort",()=>{r!==void 0&&clearTimeout(r)}),t}function y(e,t){return o(e,{userMessage:t?`Error during ${t}`:void 0,context:{operation:t}})}async function x(e,t,r={}){const{retry:n=!1,maxRetries:i=3,retryDelay:l=300}=r;let a=0;for(;;)try{return await t()}catch(u){if(a++,c(u)&&n&&a<=i){const s=l*Math.pow(2,a-1);await new Promise(d=>setTimeout(d,s));continue}throw o(u,{userMessage:`Firebase operation "${e}" failed`,context:{operation:e,attempt:a,maxRetries:i,options:r}})}}function c(e){const t=["permission-denied","invalid-argument","already-exists","not-found","unauthenticated"];return e&&e.name==="DoNotDevError"&&t.includes(e.code)?!1:e&&e.code?["unavailable","deadline","cancel","network","timeout","internal","resource","exhausted"].some(n=>e.code.toLowerCase().includes(n)):!0}export{f as createAbortController,x as executeFirebaseOperation,y as handleFirebaseError};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/firebase",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"valibot": "^1.2.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@donotdev/core": "^0.0.
|
|
33
|
-
"firebase": "^12.
|
|
32
|
+
"@donotdev/core": "^0.0.24",
|
|
33
|
+
"firebase": "^12.9.0",
|
|
34
34
|
"firebase-admin": "^13.6.0"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|