@sekyro/connect-firebase 0.1.0-rc.1 → 0.1.0-rc.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @sekyro/connect-firebase
2
2
 
3
+ ## 0.1.0-rc.3
4
+
5
+ ### Patch Changes
6
+
7
+ - c307b12: New `ConnectorOptions.onRevocationUnresolved(event)`: called when Sekyro revokes or deletes a subject and the connector finds no user to clear the claim on. The event (`RevocationUnresolvedEvent`) carries ids only: `subjectId`, `provider` and `reason` (`revoked` or `deleted`), never provider data. It runs after the `revocation_unresolved` log line and telemetry event, in the background; the webhook does not wait for it, and a throw or rejection is caught and reported to `logger` as the new `revocation_handler_failed` event. The provider packages' READMEs and examples show the option.
8
+ - 58359cc: Connector telemetry for the dashboard's Connectors page. `createConnector` sends an `x-sekyro-connector: <provider>/<version>` header on every API call and, after each claim write and each `revocation_unresolved`, posts an id-only event (type, provider, session id, subject id, time; never the claim, a token or user data) in the background with a 2-second timeout and no retry. `telemetry: false` turns both off; custom adapters send nothing. New: `ConnectorOptions.telemetry`, `ProviderAdapter.version`, `SekyroOptions.connector`. The six provider adapters report their package version.
9
+ - Updated dependencies [c307b12]
10
+ - Updated dependencies [58359cc]
11
+ - Updated dependencies [ff5cc35]
12
+ - @sekyro/node@0.1.0-rc.10
13
+
14
+ ## 0.1.0-rc.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 393b68e: First release built and published by the Sekyro release pipeline (npm Trusted Publishing), with the same tarball, licence and SBOM checks as the other Sekyro SDKs. No API change from 0.1.0-rc.1.
19
+
3
20
  ## 0.1.0-rc.1
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -150,6 +150,30 @@ there is no transport to verify. The handler takes the uid and runs `connector.u
150
150
  `bytes` and `budget` for a refused write. It never carries the Firebase message, which can contain an e-mail
151
151
  address. A missing user reads as `null`; a write to a missing user is `not_found`.
152
152
 
153
+ ## Telemetry
154
+
155
+ The connector tells Sekyro it is wired so the dashboard's Connectors page shows it as connected for this
156
+ environment. Every API call carries the `x-sekyro-connector` header (`firebase/<version>`), and after each claim write,
157
+ and each `revocation_unresolved`, the connector posts an event with ids only: the event type, the provider, the
158
+ session id, the subject id and the time. Never the claim, a token, a secret or user data. Events go in the
159
+ background with a 2-second timeout and no retry. Pass `telemetry: false` to `createConnector` to send neither.
160
+
161
+ ## Revocations it cannot resolve
162
+
163
+ When Sekyro revokes or deletes a person and the connector finds no Firebase user for the subject (no
164
+ `externalRefs` on the event or subject, and no entry in the `store`), no claim is cleared. Pass
165
+ `onRevocationUnresolved` to `createConnector` to act on it:
166
+
167
+ ```ts
168
+ onRevocationUnresolved: async ({ subjectId, provider, reason }) => {
169
+ // reason is "revoked" or "deleted". Find the user for subjectId and remove their access.
170
+ },
171
+ ```
172
+
173
+ The event carries ids only, never Firebase data. It runs after the `revocation_unresolved` log line and
174
+ telemetry event, in the background: the webhook does not wait for it, and a throw or rejection is caught and
175
+ reported to `logger` as `revocation_handler_failed`.
176
+
153
177
  ## Security
154
178
 
155
179
  - Secrets (Sekyro API key and webhook secret, the service account key) stay in server environment.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{FIREBASE_CLAIM_KEY:()=>FIREBASE_CLAIM_KEY,SekyroFirebaseError:()=>SekyroFirebaseError,claimsByteLength:()=>claimsByteLength,firebase:()=>firebase,firebaseUserDeleted:()=>firebaseUserDeleted,firestoreRefreshSignal:()=>firestoreRefreshSignal,rtdbRefreshSignal:()=>rtdbRefreshSignal});module.exports=__toCommonJS(src_exports);var import_connect=require("@sekyro/node/connect");var MESSAGES={config:"The Firebase connector is not configured",not_found:"The Firebase user does not exist",claims_budget_exceeded:"The custom claims would exceed the Firebase size budget",reserved_claim:"The user's custom claims use a name Firebase reserves",unauthorized:"Firebase refused the service account",unavailable:"Firebase Authentication is unavailable",upstream:"Firebase Authentication answered with an unexpected error"},SekyroFirebaseError=class extends Error{name="SekyroFirebaseError";code;firebaseCode;bytes;budget;constructor(code,opts={}){super(opts.message??MESSAGES[code]),this.code=code,opts.firebaseCode!==void 0&&(this.firebaseCode=opts.firebaseCode),opts.bytes!==void 0&&(this.bytes=opts.bytes),opts.budget!==void 0&&(this.budget=opts.budget)}},BY_CODE={"auth/user-not-found":"not_found","auth/claims-too-large":"claims_budget_exceeded","auth/reserved-claim":"reserved_claim","auth/reserved-claims":"reserved_claim","auth/insufficient-permission":"unauthorized","auth/invalid-credential":"unauthorized","app/invalid-credential":"unauthorized","auth/internal-error":"unavailable","app/internal-error":"unavailable","app/network-error":"unavailable","app/network-timeout":"unavailable","auth/quota-exceeded":"unavailable","auth/too-many-requests":"unavailable"};function codeOf(err){if(err===null||typeof err!="object")return;let code=err.code;return typeof code=="string"&&code.length>0?code:void 0}function fromFirebaseError(err){if(err instanceof SekyroFirebaseError)return err;let firebaseCode=codeOf(err);if(firebaseCode===void 0)return new SekyroFirebaseError("unavailable");let mapped=BY_CODE[firebaseCode]??(firebaseCode.startsWith("auth/")?"upstream":"unavailable");return new SekyroFirebaseError(mapped,{firebaseCode})}function isUserNotFound(err){return codeOf(err)==="auth/user-not-found"}function perKeyLock(){let tails=new Map;return(key,fn)=>{let run=(tails.get(key)??Promise.resolve()).then(fn,fn),tail=run.then(()=>{},()=>{});return tails.set(key,tail),tail.then(()=>{tails.get(key)===tail&&tails.delete(key)}),run}}var FIREBASE_CLAIM_KEY="sekyro",DEFAULT_MAX_CLAIMS_BYTES=1e3,encoder=new TextEncoder;function claimsByteLength(claims){return encoder.encode(JSON.stringify(claims)).byteLength}function firebase(opts){let auth=opts?.auth;if(auth===null||typeof auth!="object"||typeof auth.getUser!="function"||typeof auth.setCustomUserClaims!="function")throw new SekyroFirebaseError("config",{message:"`auth` must be a firebase-admin Auth instance"});let maxClaimsBytes=opts.maxClaimsBytes??DEFAULT_MAX_CLAIMS_BYTES;if(!Number.isInteger(maxClaimsBytes)||maxClaimsBytes<1)throw new SekyroFirebaseError("config",{message:"`maxClaimsBytes` must be a positive integer"});let{refreshSignal,onSignalError}=opts,revokeOnRevoked=opts.revokeRefreshTokensOnRevoked===!0;if(revokeOnRevoked&&typeof auth.revokeRefreshTokens!="function")throw new SekyroFirebaseError("config",{message:"`revokeRefreshTokensOnRevoked` needs an `auth` with revokeRefreshTokens"});let now=opts.now??Date.now,lock=perKeyLock(),revokedIn=value=>(0,import_connect.parseClaim)(value)?.flags?.includes("revoked")===!0;async function claimsOf(uid,missingOk){try{return(await auth.getUser(uid)).customClaims??{}}catch(err){if(missingOk&&isUserNotFound(err))return null;throw fromFirebaseError(err)}}async function commit(uid,existing,claim){let next={...existing,[FIREBASE_CLAIM_KEY]:claim},bytes=claimsByteLength(next);if(bytes>maxClaimsBytes)throw new SekyroFirebaseError("claims_budget_exceeded",{bytes,budget:maxClaimsBytes});if(revokeOnRevoked&&revokedIn(claim)&&!revokedIn(existing[FIREBASE_CLAIM_KEY]))try{await auth.revokeRefreshTokens(uid)}catch(err){throw fromFirebaseError(err)}try{await auth.setCustomUserClaims(uid,next)}catch(err){throw fromFirebaseError(err)}if(refreshSignal)try{await refreshSignal.set(uid,now())}catch(err){onSignalError?.(err,uid)}}return{name:"firebase",maxClaimsBytes,async readUser(uid){let user;try{user=await auth.getUser(uid)}catch(err){if(isUserNotFound(err))return null;throw fromFirebaseError(err)}return user.customClaims?.[FIREBASE_CLAIM_KEY]??null},writeUser(uid,claim){return lock(uid,async()=>{await commit(uid,await claimsOf(uid,!1),claim)})},update(uid,fn){return lock(uid,async()=>{let existing=await claimsOf(uid,!0),out=fn(existing?.[FIREBASE_CLAIM_KEY]??null);if(out.changed&&out.claim){if(existing===null)throw new SekyroFirebaseError("not_found",{firebaseCode:"auth/user-not-found"});await commit(uid,existing,out.claim)}return out})},readClaimFromToken(tokenClaims){return tokenClaims[FIREBASE_CLAIM_KEY]??null}}}var MAX_UID_LENGTH=128;function assertUid(uid,what){if(typeof uid!="string"||uid.length===0||uid.length>MAX_UID_LENGTH||uid.includes("/"))throw new SekyroFirebaseError("config",{message:`${what} needs a uid of 1 to ${MAX_UID_LENGTH} characters without "/"`})}function rtdbRefreshSignal(db,opts={}){let path=opts.path??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"rtdbRefreshSignal"),await db.ref(`${path}/${uid}`).set({refreshTime:refreshTimeMs})}}}function firestoreRefreshSignal(db,opts={}){let collection=opts.collection??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"firestoreRefreshSignal"),await db.doc(`${collection}/${uid}`).set({refreshTime:refreshTimeMs},{merge:!0})}}}function firebaseUserDeleted(connector){return async input=>{let uid=uidOf(input);if(uid===void 0)throw new SekyroFirebaseError("config",{message:"firebaseUserDeleted needs a uid, a user record or an onUserDeleted event"});let{policy,subjects}=await connector.userDeleted(uid);return{policy,subjects,uid}}}function uidOf(input){let uid;if(typeof input=="string")uid=input;else if(input!==null&&typeof input=="object"){let record=input;record.uid!==void 0?uid=record.uid:record.data!==null&&typeof record.data=="object"&&(uid=record.data.uid)}return typeof uid=="string"&&uid.length>0&&uid.length<=MAX_UID_LENGTH?uid:void 0}0&&(module.exports={FIREBASE_CLAIM_KEY,SekyroFirebaseError,claimsByteLength,firebase,firebaseUserDeleted,firestoreRefreshSignal,rtdbRefreshSignal});
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{FIREBASE_CLAIM_KEY:()=>FIREBASE_CLAIM_KEY,SekyroFirebaseError:()=>SekyroFirebaseError,claimsByteLength:()=>claimsByteLength,firebase:()=>firebase,firebaseUserDeleted:()=>firebaseUserDeleted,firestoreRefreshSignal:()=>firestoreRefreshSignal,rtdbRefreshSignal:()=>rtdbRefreshSignal});module.exports=__toCommonJS(src_exports);var import_connect=require("@sekyro/node/connect");var MESSAGES={config:"The Firebase connector is not configured",not_found:"The Firebase user does not exist",claims_budget_exceeded:"The custom claims would exceed the Firebase size budget",reserved_claim:"The user's custom claims use a name Firebase reserves",unauthorized:"Firebase refused the service account",unavailable:"Firebase Authentication is unavailable",upstream:"Firebase Authentication answered with an unexpected error"},SekyroFirebaseError=class extends Error{name="SekyroFirebaseError";code;firebaseCode;bytes;budget;constructor(code,opts={}){super(opts.message??MESSAGES[code]),this.code=code,opts.firebaseCode!==void 0&&(this.firebaseCode=opts.firebaseCode),opts.bytes!==void 0&&(this.bytes=opts.bytes),opts.budget!==void 0&&(this.budget=opts.budget)}},BY_CODE={"auth/user-not-found":"not_found","auth/claims-too-large":"claims_budget_exceeded","auth/reserved-claim":"reserved_claim","auth/reserved-claims":"reserved_claim","auth/insufficient-permission":"unauthorized","auth/invalid-credential":"unauthorized","app/invalid-credential":"unauthorized","auth/internal-error":"unavailable","app/internal-error":"unavailable","app/network-error":"unavailable","app/network-timeout":"unavailable","auth/quota-exceeded":"unavailable","auth/too-many-requests":"unavailable"};function codeOf(err){if(err===null||typeof err!="object")return;let code=err.code;return typeof code=="string"&&code.length>0?code:void 0}function fromFirebaseError(err){if(err instanceof SekyroFirebaseError)return err;let firebaseCode=codeOf(err);if(firebaseCode===void 0)return new SekyroFirebaseError("unavailable");let mapped=BY_CODE[firebaseCode]??(firebaseCode.startsWith("auth/")?"upstream":"unavailable");return new SekyroFirebaseError(mapped,{firebaseCode})}function isUserNotFound(err){return codeOf(err)==="auth/user-not-found"}function perKeyLock(){let tails=new Map;return(key,fn)=>{let run=(tails.get(key)??Promise.resolve()).then(fn,fn),tail=run.then(()=>{},()=>{});return tails.set(key,tail),tail.then(()=>{tails.get(key)===tail&&tails.delete(key)}),run}}var CONNECTOR_VERSION="0.1.0-rc.3";var FIREBASE_CLAIM_KEY="sekyro",DEFAULT_MAX_CLAIMS_BYTES=1e3,encoder=new TextEncoder;function claimsByteLength(claims){return encoder.encode(JSON.stringify(claims)).byteLength}function firebase(opts){let auth=opts?.auth;if(auth===null||typeof auth!="object"||typeof auth.getUser!="function"||typeof auth.setCustomUserClaims!="function")throw new SekyroFirebaseError("config",{message:"`auth` must be a firebase-admin Auth instance"});let maxClaimsBytes=opts.maxClaimsBytes??DEFAULT_MAX_CLAIMS_BYTES;if(!Number.isInteger(maxClaimsBytes)||maxClaimsBytes<1)throw new SekyroFirebaseError("config",{message:"`maxClaimsBytes` must be a positive integer"});let{refreshSignal,onSignalError}=opts,revokeOnRevoked=opts.revokeRefreshTokensOnRevoked===!0;if(revokeOnRevoked&&typeof auth.revokeRefreshTokens!="function")throw new SekyroFirebaseError("config",{message:"`revokeRefreshTokensOnRevoked` needs an `auth` with revokeRefreshTokens"});let now=opts.now??Date.now,lock=perKeyLock(),revokedIn=value=>(0,import_connect.parseClaim)(value)?.flags?.includes("revoked")===!0;async function claimsOf(uid,missingOk){try{return(await auth.getUser(uid)).customClaims??{}}catch(err){if(missingOk&&isUserNotFound(err))return null;throw fromFirebaseError(err)}}async function commit(uid,existing,claim){let next={...existing,[FIREBASE_CLAIM_KEY]:claim},bytes=claimsByteLength(next);if(bytes>maxClaimsBytes)throw new SekyroFirebaseError("claims_budget_exceeded",{bytes,budget:maxClaimsBytes});if(revokeOnRevoked&&revokedIn(claim)&&!revokedIn(existing[FIREBASE_CLAIM_KEY]))try{await auth.revokeRefreshTokens(uid)}catch(err){throw fromFirebaseError(err)}try{await auth.setCustomUserClaims(uid,next)}catch(err){throw fromFirebaseError(err)}if(refreshSignal)try{await refreshSignal.set(uid,now())}catch(err){onSignalError?.(err,uid)}}return{name:"firebase",version:CONNECTOR_VERSION,maxClaimsBytes,async readUser(uid){let user;try{user=await auth.getUser(uid)}catch(err){if(isUserNotFound(err))return null;throw fromFirebaseError(err)}return user.customClaims?.[FIREBASE_CLAIM_KEY]??null},writeUser(uid,claim){return lock(uid,async()=>{await commit(uid,await claimsOf(uid,!1),claim)})},update(uid,fn){return lock(uid,async()=>{let existing=await claimsOf(uid,!0),out=fn(existing?.[FIREBASE_CLAIM_KEY]??null);if(out.changed&&out.claim){if(existing===null)throw new SekyroFirebaseError("not_found",{firebaseCode:"auth/user-not-found"});await commit(uid,existing,out.claim)}return out})},readClaimFromToken(tokenClaims){return tokenClaims[FIREBASE_CLAIM_KEY]??null}}}var MAX_UID_LENGTH=128;function assertUid(uid,what){if(typeof uid!="string"||uid.length===0||uid.length>MAX_UID_LENGTH||uid.includes("/"))throw new SekyroFirebaseError("config",{message:`${what} needs a uid of 1 to ${MAX_UID_LENGTH} characters without "/"`})}function rtdbRefreshSignal(db,opts={}){let path=opts.path??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"rtdbRefreshSignal"),await db.ref(`${path}/${uid}`).set({refreshTime:refreshTimeMs})}}}function firestoreRefreshSignal(db,opts={}){let collection=opts.collection??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"firestoreRefreshSignal"),await db.doc(`${collection}/${uid}`).set({refreshTime:refreshTimeMs},{merge:!0})}}}function firebaseUserDeleted(connector){return async input=>{let uid=uidOf(input);if(uid===void 0)throw new SekyroFirebaseError("config",{message:"firebaseUserDeleted needs a uid, a user record or an onUserDeleted event"});let{policy,subjects}=await connector.userDeleted(uid);return{policy,subjects,uid}}}function uidOf(input){let uid;if(typeof input=="string")uid=input;else if(input!==null&&typeof input=="object"){let record=input;record.uid!==void 0?uid=record.uid:record.data!==null&&typeof record.data=="object"&&(uid=record.data.uid)}return typeof uid=="string"&&uid.length>0&&uid.length<=MAX_UID_LENGTH?uid:void 0}0&&(module.exports={FIREBASE_CLAIM_KEY,SekyroFirebaseError,claimsByteLength,firebase,firebaseUserDeleted,firestoreRefreshSignal,rtdbRefreshSignal});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{parseClaim}from"@sekyro/node/connect";var MESSAGES={config:"The Firebase connector is not configured",not_found:"The Firebase user does not exist",claims_budget_exceeded:"The custom claims would exceed the Firebase size budget",reserved_claim:"The user's custom claims use a name Firebase reserves",unauthorized:"Firebase refused the service account",unavailable:"Firebase Authentication is unavailable",upstream:"Firebase Authentication answered with an unexpected error"},SekyroFirebaseError=class extends Error{name="SekyroFirebaseError";code;firebaseCode;bytes;budget;constructor(code,opts={}){super(opts.message??MESSAGES[code]),this.code=code,opts.firebaseCode!==void 0&&(this.firebaseCode=opts.firebaseCode),opts.bytes!==void 0&&(this.bytes=opts.bytes),opts.budget!==void 0&&(this.budget=opts.budget)}},BY_CODE={"auth/user-not-found":"not_found","auth/claims-too-large":"claims_budget_exceeded","auth/reserved-claim":"reserved_claim","auth/reserved-claims":"reserved_claim","auth/insufficient-permission":"unauthorized","auth/invalid-credential":"unauthorized","app/invalid-credential":"unauthorized","auth/internal-error":"unavailable","app/internal-error":"unavailable","app/network-error":"unavailable","app/network-timeout":"unavailable","auth/quota-exceeded":"unavailable","auth/too-many-requests":"unavailable"};function codeOf(err){if(err===null||typeof err!="object")return;let code=err.code;return typeof code=="string"&&code.length>0?code:void 0}function fromFirebaseError(err){if(err instanceof SekyroFirebaseError)return err;let firebaseCode=codeOf(err);if(firebaseCode===void 0)return new SekyroFirebaseError("unavailable");let mapped=BY_CODE[firebaseCode]??(firebaseCode.startsWith("auth/")?"upstream":"unavailable");return new SekyroFirebaseError(mapped,{firebaseCode})}function isUserNotFound(err){return codeOf(err)==="auth/user-not-found"}function perKeyLock(){let tails=new Map;return(key,fn)=>{let run=(tails.get(key)??Promise.resolve()).then(fn,fn),tail=run.then(()=>{},()=>{});return tails.set(key,tail),tail.then(()=>{tails.get(key)===tail&&tails.delete(key)}),run}}var FIREBASE_CLAIM_KEY="sekyro",DEFAULT_MAX_CLAIMS_BYTES=1e3,encoder=new TextEncoder;function claimsByteLength(claims){return encoder.encode(JSON.stringify(claims)).byteLength}function firebase(opts){let auth=opts?.auth;if(auth===null||typeof auth!="object"||typeof auth.getUser!="function"||typeof auth.setCustomUserClaims!="function")throw new SekyroFirebaseError("config",{message:"`auth` must be a firebase-admin Auth instance"});let maxClaimsBytes=opts.maxClaimsBytes??DEFAULT_MAX_CLAIMS_BYTES;if(!Number.isInteger(maxClaimsBytes)||maxClaimsBytes<1)throw new SekyroFirebaseError("config",{message:"`maxClaimsBytes` must be a positive integer"});let{refreshSignal,onSignalError}=opts,revokeOnRevoked=opts.revokeRefreshTokensOnRevoked===!0;if(revokeOnRevoked&&typeof auth.revokeRefreshTokens!="function")throw new SekyroFirebaseError("config",{message:"`revokeRefreshTokensOnRevoked` needs an `auth` with revokeRefreshTokens"});let now=opts.now??Date.now,lock=perKeyLock(),revokedIn=value=>parseClaim(value)?.flags?.includes("revoked")===!0;async function claimsOf(uid,missingOk){try{return(await auth.getUser(uid)).customClaims??{}}catch(err){if(missingOk&&isUserNotFound(err))return null;throw fromFirebaseError(err)}}async function commit(uid,existing,claim){let next={...existing,[FIREBASE_CLAIM_KEY]:claim},bytes=claimsByteLength(next);if(bytes>maxClaimsBytes)throw new SekyroFirebaseError("claims_budget_exceeded",{bytes,budget:maxClaimsBytes});if(revokeOnRevoked&&revokedIn(claim)&&!revokedIn(existing[FIREBASE_CLAIM_KEY]))try{await auth.revokeRefreshTokens(uid)}catch(err){throw fromFirebaseError(err)}try{await auth.setCustomUserClaims(uid,next)}catch(err){throw fromFirebaseError(err)}if(refreshSignal)try{await refreshSignal.set(uid,now())}catch(err){onSignalError?.(err,uid)}}return{name:"firebase",maxClaimsBytes,async readUser(uid){let user;try{user=await auth.getUser(uid)}catch(err){if(isUserNotFound(err))return null;throw fromFirebaseError(err)}return user.customClaims?.[FIREBASE_CLAIM_KEY]??null},writeUser(uid,claim){return lock(uid,async()=>{await commit(uid,await claimsOf(uid,!1),claim)})},update(uid,fn){return lock(uid,async()=>{let existing=await claimsOf(uid,!0),out=fn(existing?.[FIREBASE_CLAIM_KEY]??null);if(out.changed&&out.claim){if(existing===null)throw new SekyroFirebaseError("not_found",{firebaseCode:"auth/user-not-found"});await commit(uid,existing,out.claim)}return out})},readClaimFromToken(tokenClaims){return tokenClaims[FIREBASE_CLAIM_KEY]??null}}}var MAX_UID_LENGTH=128;function assertUid(uid,what){if(typeof uid!="string"||uid.length===0||uid.length>MAX_UID_LENGTH||uid.includes("/"))throw new SekyroFirebaseError("config",{message:`${what} needs a uid of 1 to ${MAX_UID_LENGTH} characters without "/"`})}function rtdbRefreshSignal(db,opts={}){let path=opts.path??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"rtdbRefreshSignal"),await db.ref(`${path}/${uid}`).set({refreshTime:refreshTimeMs})}}}function firestoreRefreshSignal(db,opts={}){let collection=opts.collection??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"firestoreRefreshSignal"),await db.doc(`${collection}/${uid}`).set({refreshTime:refreshTimeMs},{merge:!0})}}}function firebaseUserDeleted(connector){return async input=>{let uid=uidOf(input);if(uid===void 0)throw new SekyroFirebaseError("config",{message:"firebaseUserDeleted needs a uid, a user record or an onUserDeleted event"});let{policy,subjects}=await connector.userDeleted(uid);return{policy,subjects,uid}}}function uidOf(input){let uid;if(typeof input=="string")uid=input;else if(input!==null&&typeof input=="object"){let record=input;record.uid!==void 0?uid=record.uid:record.data!==null&&typeof record.data=="object"&&(uid=record.data.uid)}return typeof uid=="string"&&uid.length>0&&uid.length<=MAX_UID_LENGTH?uid:void 0}export{FIREBASE_CLAIM_KEY,SekyroFirebaseError,claimsByteLength,firebase,firebaseUserDeleted,firestoreRefreshSignal,rtdbRefreshSignal};
1
+ import{parseClaim}from"@sekyro/node/connect";var MESSAGES={config:"The Firebase connector is not configured",not_found:"The Firebase user does not exist",claims_budget_exceeded:"The custom claims would exceed the Firebase size budget",reserved_claim:"The user's custom claims use a name Firebase reserves",unauthorized:"Firebase refused the service account",unavailable:"Firebase Authentication is unavailable",upstream:"Firebase Authentication answered with an unexpected error"},SekyroFirebaseError=class extends Error{name="SekyroFirebaseError";code;firebaseCode;bytes;budget;constructor(code,opts={}){super(opts.message??MESSAGES[code]),this.code=code,opts.firebaseCode!==void 0&&(this.firebaseCode=opts.firebaseCode),opts.bytes!==void 0&&(this.bytes=opts.bytes),opts.budget!==void 0&&(this.budget=opts.budget)}},BY_CODE={"auth/user-not-found":"not_found","auth/claims-too-large":"claims_budget_exceeded","auth/reserved-claim":"reserved_claim","auth/reserved-claims":"reserved_claim","auth/insufficient-permission":"unauthorized","auth/invalid-credential":"unauthorized","app/invalid-credential":"unauthorized","auth/internal-error":"unavailable","app/internal-error":"unavailable","app/network-error":"unavailable","app/network-timeout":"unavailable","auth/quota-exceeded":"unavailable","auth/too-many-requests":"unavailable"};function codeOf(err){if(err===null||typeof err!="object")return;let code=err.code;return typeof code=="string"&&code.length>0?code:void 0}function fromFirebaseError(err){if(err instanceof SekyroFirebaseError)return err;let firebaseCode=codeOf(err);if(firebaseCode===void 0)return new SekyroFirebaseError("unavailable");let mapped=BY_CODE[firebaseCode]??(firebaseCode.startsWith("auth/")?"upstream":"unavailable");return new SekyroFirebaseError(mapped,{firebaseCode})}function isUserNotFound(err){return codeOf(err)==="auth/user-not-found"}function perKeyLock(){let tails=new Map;return(key,fn)=>{let run=(tails.get(key)??Promise.resolve()).then(fn,fn),tail=run.then(()=>{},()=>{});return tails.set(key,tail),tail.then(()=>{tails.get(key)===tail&&tails.delete(key)}),run}}var CONNECTOR_VERSION="0.1.0-rc.3";var FIREBASE_CLAIM_KEY="sekyro",DEFAULT_MAX_CLAIMS_BYTES=1e3,encoder=new TextEncoder;function claimsByteLength(claims){return encoder.encode(JSON.stringify(claims)).byteLength}function firebase(opts){let auth=opts?.auth;if(auth===null||typeof auth!="object"||typeof auth.getUser!="function"||typeof auth.setCustomUserClaims!="function")throw new SekyroFirebaseError("config",{message:"`auth` must be a firebase-admin Auth instance"});let maxClaimsBytes=opts.maxClaimsBytes??DEFAULT_MAX_CLAIMS_BYTES;if(!Number.isInteger(maxClaimsBytes)||maxClaimsBytes<1)throw new SekyroFirebaseError("config",{message:"`maxClaimsBytes` must be a positive integer"});let{refreshSignal,onSignalError}=opts,revokeOnRevoked=opts.revokeRefreshTokensOnRevoked===!0;if(revokeOnRevoked&&typeof auth.revokeRefreshTokens!="function")throw new SekyroFirebaseError("config",{message:"`revokeRefreshTokensOnRevoked` needs an `auth` with revokeRefreshTokens"});let now=opts.now??Date.now,lock=perKeyLock(),revokedIn=value=>parseClaim(value)?.flags?.includes("revoked")===!0;async function claimsOf(uid,missingOk){try{return(await auth.getUser(uid)).customClaims??{}}catch(err){if(missingOk&&isUserNotFound(err))return null;throw fromFirebaseError(err)}}async function commit(uid,existing,claim){let next={...existing,[FIREBASE_CLAIM_KEY]:claim},bytes=claimsByteLength(next);if(bytes>maxClaimsBytes)throw new SekyroFirebaseError("claims_budget_exceeded",{bytes,budget:maxClaimsBytes});if(revokeOnRevoked&&revokedIn(claim)&&!revokedIn(existing[FIREBASE_CLAIM_KEY]))try{await auth.revokeRefreshTokens(uid)}catch(err){throw fromFirebaseError(err)}try{await auth.setCustomUserClaims(uid,next)}catch(err){throw fromFirebaseError(err)}if(refreshSignal)try{await refreshSignal.set(uid,now())}catch(err){onSignalError?.(err,uid)}}return{name:"firebase",version:CONNECTOR_VERSION,maxClaimsBytes,async readUser(uid){let user;try{user=await auth.getUser(uid)}catch(err){if(isUserNotFound(err))return null;throw fromFirebaseError(err)}return user.customClaims?.[FIREBASE_CLAIM_KEY]??null},writeUser(uid,claim){return lock(uid,async()=>{await commit(uid,await claimsOf(uid,!1),claim)})},update(uid,fn){return lock(uid,async()=>{let existing=await claimsOf(uid,!0),out=fn(existing?.[FIREBASE_CLAIM_KEY]??null);if(out.changed&&out.claim){if(existing===null)throw new SekyroFirebaseError("not_found",{firebaseCode:"auth/user-not-found"});await commit(uid,existing,out.claim)}return out})},readClaimFromToken(tokenClaims){return tokenClaims[FIREBASE_CLAIM_KEY]??null}}}var MAX_UID_LENGTH=128;function assertUid(uid,what){if(typeof uid!="string"||uid.length===0||uid.length>MAX_UID_LENGTH||uid.includes("/"))throw new SekyroFirebaseError("config",{message:`${what} needs a uid of 1 to ${MAX_UID_LENGTH} characters without "/"`})}function rtdbRefreshSignal(db,opts={}){let path=opts.path??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"rtdbRefreshSignal"),await db.ref(`${path}/${uid}`).set({refreshTime:refreshTimeMs})}}}function firestoreRefreshSignal(db,opts={}){let collection=opts.collection??"metadata";return{async set(uid,refreshTimeMs){assertUid(uid,"firestoreRefreshSignal"),await db.doc(`${collection}/${uid}`).set({refreshTime:refreshTimeMs},{merge:!0})}}}function firebaseUserDeleted(connector){return async input=>{let uid=uidOf(input);if(uid===void 0)throw new SekyroFirebaseError("config",{message:"firebaseUserDeleted needs a uid, a user record or an onUserDeleted event"});let{policy,subjects}=await connector.userDeleted(uid);return{policy,subjects,uid}}}function uidOf(input){let uid;if(typeof input=="string")uid=input;else if(input!==null&&typeof input=="object"){let record=input;record.uid!==void 0?uid=record.uid:record.data!==null&&typeof record.data=="object"&&(uid=record.data.uid)}return typeof uid=="string"&&uid.length>0&&uid.length<=MAX_UID_LENGTH?uid:void 0}export{FIREBASE_CLAIM_KEY,SekyroFirebaseError,claimsByteLength,firebase,firebaseUserDeleted,firestoreRefreshSignal,rtdbRefreshSignal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sekyro/connect-firebase",
3
- "version": "0.1.0-rc.1",
3
+ "version": "0.1.0-rc.3",
4
4
  "private": false,
5
5
  "description": "Sekyro AI connector for Firebase Authentication: writes the verified-human claim as the custom claim sekyro through the Admin SDK, within the 1000-byte budget, and turns onUserDeleted into the connector's deletion policy.",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -58,7 +58,7 @@
58
58
  "check:emulator": "node scripts/check-emulator.mjs"
59
59
  },
60
60
  "peerDependencies": {
61
- "@sekyro/node": "^0.1.0-rc.8 || ^0.2.0-rc.0",
61
+ "@sekyro/node": "^0.1.0-rc.10 || ^0.2.0-rc.0",
62
62
  "firebase-admin": "^12.0.0 || ^13.0.0 || ^14.0.0"
63
63
  },
64
64
  "peerDependenciesMeta": {
package/sbom.cdx.json CHANGED
@@ -97,8 +97,9 @@
97
97
  "type": "application",
98
98
  "name": "connect-firebase",
99
99
  "group": "@sekyro",
100
- "version": "0.1.0-rc.1",
101
- "bom-ref": "@sekyro/connect-firebase@0.1.0-rc.1",
100
+ "version": "0.1.0-rc.3",
101
+ "bom-ref": "@sekyro/connect-firebase@0.1.0-rc.3",
102
+ "description": "Sekyro AI connector for Firebase Authentication: writes the verified-human claim as the custom claim sekyro through the Admin SDK, within the 1000-byte budget, and turns onUserDeleted into the connector's deletion policy.",
102
103
  "licenses": [
103
104
  {
104
105
  "license": {
@@ -107,8 +108,29 @@
107
108
  }
108
109
  }
109
110
  ],
110
- "purl": "pkg:npm/%40sekyro/connect-firebase@0.1.0-rc.1",
111
+ "purl": "pkg:npm/%40sekyro/connect-firebase@0.1.0-rc.3?vcs_url=git%2Bhttps%3A%2F%2Fgithub.com%2FIBTIKAR-Technologies%2Fibtikar-identity.git%23packages%2Fsekyro-connect-firebase",
112
+ "externalReferences": [
113
+ {
114
+ "url": "https://github.com/IBTIKAR-Technologies/ibtikar-identity/issues",
115
+ "type": "issue-tracker",
116
+ "comment": "as detected from PackageJson property \"bugs.url\""
117
+ },
118
+ {
119
+ "url": "git+https://github.com/IBTIKAR-Technologies/ibtikar-identity.git#packages/sekyro-connect-firebase",
120
+ "type": "vcs",
121
+ "comment": "as detected from PackageJson property \"repository.url\" and \"repository.directory\""
122
+ },
123
+ {
124
+ "url": "https://github.com/IBTIKAR-Technologies/ibtikar-identity#readme",
125
+ "type": "website",
126
+ "comment": "as detected from PackageJson property \"homepage\""
127
+ }
128
+ ],
111
129
  "properties": [
130
+ {
131
+ "name": "cdx:npm:package:constraint:engine:node",
132
+ "value": ">=20"
133
+ },
112
134
  {
113
135
  "name": "cdx:npm:package:path",
114
136
  "value": ""
@@ -125,7 +147,7 @@
125
147
  "components": [],
126
148
  "dependencies": [
127
149
  {
128
- "ref": "@sekyro/connect-firebase@0.1.0-rc.1"
150
+ "ref": "@sekyro/connect-firebase@0.1.0-rc.3"
129
151
  }
130
152
  ]
131
153
  }