@sekyro/connect-firebase 0.1.0-rc.7 → 0.1.0
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 +138 -0
- package/README.md +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/sbom.cdx.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,143 @@
|
|
|
1
1
|
# @sekyro/connect-firebase
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1b32db0: Breaking: works with the `@sekyro/node` release candidate of levels v2 (1 Contact, 2 Human, 3 Identity), which reads and writes claim version 2 only: a stored version 1 claim is no claim, so the person reads as not verified until a new verification or re-check writes a version 2 claim. Move every gate that means identity from `level: 2` to `level: 3`, and every gate that means a real person from `level: 1` to `level: 2`; left alone they accept weaker results. To require a registry match, add `assurance: ["registry_biometric"]`. Rules written in your provider (Firebase security rules, Supabase policies) read the raw claim: check `sekyro.v == 2 && sekyro.level >= 3`. The Auth0 post-login Action copies version 2 claims only.
|
|
8
|
+
- 202fe34: Breaking: works with the `@sekyro/node` 1.0.0 release candidate that brings the session outcome model. Subscribe the connector's webhook endpoint to `session.verified`, `session.not_verified`, `person.updated` and `person.deleted`. A `session.verified` writes the claim from its result token; a `session.not_verified` (any `reason`: rejected, inconclusive, unavailable, abandoned, not opened, policy, cancelled or superseded) never writes a level and, when the session was rejected because the face belongs to another person, adds the `face_mismatch` flag. The return-URL sync writes nothing for a `not_verified` session. The merge rule for a result that proves no level is `not_verified`. The claim and the adapters are otherwise the same.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- bb24ac2: First release candidate of the Firebase connector: `firebase({ auth })` stores the Sekyro claim as the custom claim `sekyro` through any `firebase-admin` `Auth` (project or tenant), reading the user's other claims first, serialising writes per user and refusing a write over the 1000-byte budget before it reaches Firebase; the opt-in `revokeRefreshTokensOnRevoked` revokes the user's refresh tokens before a write that newly carries `revoked`; `rtdbRefreshSignal` and `firestoreRefreshSignal` write the `metadata/{uid}` refresh signal; `firebaseUserDeleted` turns `onUserDeleted` (2nd or 1st gen) into the connector's deletion policy; `SekyroFirebaseError` carries a code and never a provider message. Proven against the Firebase Auth emulator; Next.js and Cloud Functions samples ship in the repository.
|
|
13
|
+
- 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.
|
|
14
|
+
- 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.
|
|
15
|
+
- 7b411d4: Setup docs and examples use the partner API's person vocabulary: the API key scopes are `people:read` and `people:write` (the older `subjects:read` and `subjects:write` still work), the webhook endpoint subscribes to `person.updated` and `person.deleted` (the `subject.*` events are deprecated), and `onRevocationUnresolved` reads `personId`. With `@sekyro/node` from this release the connector handles both event families. No option changes.
|
|
16
|
+
- af06c1c: The connector's API key needs `sessions:manage` next to `sessions:create`, `sessions:read` and `people:read`, and `people:manage` (was `people:write`) when `onUserDeleted` is `revoke` or `delete`. Keys minted from the dashboard carry both.
|
|
17
|
+
- 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.
|
|
18
|
+
- c285d1b: The connector reads the webhooks in their new shape (`data.id` for the session and the person, `completedAt`). Use it with the `@sekyro/node` release of the same date, and upgrade before version 2 events reach your production endpoint: an older connector answers them `200` without applying them, revocations included. A payload it cannot read is refused (`unsupported_payload`), not ignored.
|
|
19
|
+
- ffb87d8: The connectors move to the `@sekyro/node` major prerelease of the partner API removal release; the release sets their peer range to it. Nothing else changes: the claim and the adapters are the same.
|
|
20
|
+
- 5a643ec: Works with the `@sekyro/node` major prerelease that brings signals: the connect core reads the duplicate flag from a `duplicate_identity` signal. Nothing else changes: the claim and the adapters are the same.
|
|
21
|
+
- Updated dependencies [05c0319]
|
|
22
|
+
- Updated dependencies [22acfcf]
|
|
23
|
+
- Updated dependencies [82c4898]
|
|
24
|
+
- Updated dependencies [d8f24f3]
|
|
25
|
+
- Updated dependencies [49044a2]
|
|
26
|
+
- Updated dependencies [4e7a4a3]
|
|
27
|
+
- Updated dependencies [6108158]
|
|
28
|
+
- Updated dependencies [d291557]
|
|
29
|
+
- Updated dependencies [c491b0b]
|
|
30
|
+
- Updated dependencies [a43e198]
|
|
31
|
+
- Updated dependencies [1e450dc]
|
|
32
|
+
- Updated dependencies [c307b12]
|
|
33
|
+
- Updated dependencies [58359cc]
|
|
34
|
+
- Updated dependencies [ffb87d8]
|
|
35
|
+
- Updated dependencies [d28443c]
|
|
36
|
+
- Updated dependencies [0a8e356]
|
|
37
|
+
- Updated dependencies [d7f1e23]
|
|
38
|
+
- Updated dependencies [30c5345]
|
|
39
|
+
- Updated dependencies [9f106d5]
|
|
40
|
+
- Updated dependencies [466d3e1]
|
|
41
|
+
- Updated dependencies [4c1aa5b]
|
|
42
|
+
- Updated dependencies [21d94d7]
|
|
43
|
+
- Updated dependencies [cc5fcbf]
|
|
44
|
+
- Updated dependencies [46905f2]
|
|
45
|
+
- Updated dependencies [1b8395d]
|
|
46
|
+
- Updated dependencies [9acafe1]
|
|
47
|
+
- Updated dependencies [5988b08]
|
|
48
|
+
- Updated dependencies [fcba7e9]
|
|
49
|
+
- Updated dependencies [96a3b2b]
|
|
50
|
+
- Updated dependencies [4323262]
|
|
51
|
+
- Updated dependencies [dfe2f1e]
|
|
52
|
+
- Updated dependencies [c7b8031]
|
|
53
|
+
- Updated dependencies [4899a37]
|
|
54
|
+
- Updated dependencies [09efd58]
|
|
55
|
+
- Updated dependencies [6a58d80]
|
|
56
|
+
- Updated dependencies [b45092b]
|
|
57
|
+
- Updated dependencies [95d5af8]
|
|
58
|
+
- Updated dependencies [3ecb077]
|
|
59
|
+
- Updated dependencies [0206561]
|
|
60
|
+
- Updated dependencies
|
|
61
|
+
- Updated dependencies [3ea3d33]
|
|
62
|
+
- Updated dependencies [6bad03d]
|
|
63
|
+
- Updated dependencies [67e81a2]
|
|
64
|
+
- Updated dependencies [9464f3d]
|
|
65
|
+
- Updated dependencies [71ab282]
|
|
66
|
+
- Updated dependencies [c429120]
|
|
67
|
+
- Updated dependencies [a30cf7a]
|
|
68
|
+
- Updated dependencies [655cf14]
|
|
69
|
+
- Updated dependencies [e229ab3]
|
|
70
|
+
- Updated dependencies [c3c8f3e]
|
|
71
|
+
- Updated dependencies [db1d4d4]
|
|
72
|
+
- Updated dependencies [af06c1c]
|
|
73
|
+
- Updated dependencies [4729aa6]
|
|
74
|
+
- Updated dependencies [c3699fd]
|
|
75
|
+
- Updated dependencies [ef4be5d]
|
|
76
|
+
- Updated dependencies [4489e83]
|
|
77
|
+
- Updated dependencies [ee0a55c]
|
|
78
|
+
- Updated dependencies [8425e95]
|
|
79
|
+
- Updated dependencies [b6df220]
|
|
80
|
+
- Updated dependencies [5eeebad]
|
|
81
|
+
- Updated dependencies [c285d1b]
|
|
82
|
+
- Updated dependencies [7a3f935]
|
|
83
|
+
- Updated dependencies [62987ea]
|
|
84
|
+
- Updated dependencies [f7c6d79]
|
|
85
|
+
- Updated dependencies [dcdbeab]
|
|
86
|
+
- Updated dependencies [5883be5]
|
|
87
|
+
- Updated dependencies [471d833]
|
|
88
|
+
- Updated dependencies [f4840d7]
|
|
89
|
+
- Updated dependencies [8425e95]
|
|
90
|
+
- Updated dependencies [6b9a2f9]
|
|
91
|
+
- Updated dependencies [1b6bef2]
|
|
92
|
+
- Updated dependencies [1b6bef2]
|
|
93
|
+
- Updated dependencies [13d512f]
|
|
94
|
+
- Updated dependencies [acbf409]
|
|
95
|
+
- Updated dependencies [ba01f52]
|
|
96
|
+
- Updated dependencies [a21b05c]
|
|
97
|
+
- Updated dependencies [0dd0208]
|
|
98
|
+
- Updated dependencies [f91053f]
|
|
99
|
+
- Updated dependencies [886756a]
|
|
100
|
+
- Updated dependencies [14faf9e]
|
|
101
|
+
- Updated dependencies [0311ef4]
|
|
102
|
+
- Updated dependencies [45f639f]
|
|
103
|
+
- Updated dependencies [82d0799]
|
|
104
|
+
- Updated dependencies [d0dce5e]
|
|
105
|
+
- Updated dependencies [880bde9]
|
|
106
|
+
- Updated dependencies [3ee9ae7]
|
|
107
|
+
- Updated dependencies [745caf9]
|
|
108
|
+
- Updated dependencies [202fe34]
|
|
109
|
+
- Updated dependencies [6d7d1a2]
|
|
110
|
+
- Updated dependencies [5a643ec]
|
|
111
|
+
- Updated dependencies [96f3e69]
|
|
112
|
+
- Updated dependencies [58e220c]
|
|
113
|
+
- Updated dependencies [8bc8320]
|
|
114
|
+
- Updated dependencies [ff5cc35]
|
|
115
|
+
- Updated dependencies [1e0236f]
|
|
116
|
+
- Updated dependencies [24a22a4]
|
|
117
|
+
- Updated dependencies [757f31d]
|
|
118
|
+
- @sekyro/node@1.0.0
|
|
119
|
+
|
|
120
|
+
## 0.1.0-rc.8
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- af06c1c: The connector's API key needs `sessions:manage` next to `sessions:create`, `sessions:read` and `people:read`, and `people:manage` (was `people:write`) when `onUserDeleted` is `revoke` or `delete`. Keys minted from the dashboard carry both.
|
|
125
|
+
- c285d1b: The connector reads the webhooks in their new shape (`data.id` for the session and the person, `completedAt`). Use it with the `@sekyro/node` release of the same date, and upgrade before version 2 events reach your production endpoint: an older connector answers them `200` without applying them, revocations included. A payload it cannot read is refused (`unsupported_payload`), not ignored.
|
|
126
|
+
- Updated dependencies [49044a2]
|
|
127
|
+
- Updated dependencies [09efd58]
|
|
128
|
+
- Updated dependencies [b45092b]
|
|
129
|
+
- Updated dependencies [3ecb077]
|
|
130
|
+
- Updated dependencies [0206561]
|
|
131
|
+
- Updated dependencies
|
|
132
|
+
- Updated dependencies [67e81a2]
|
|
133
|
+
- Updated dependencies [9464f3d]
|
|
134
|
+
- Updated dependencies [a30cf7a]
|
|
135
|
+
- Updated dependencies [af06c1c]
|
|
136
|
+
- Updated dependencies [5eeebad]
|
|
137
|
+
- Updated dependencies [c285d1b]
|
|
138
|
+
- Updated dependencies [0311ef4]
|
|
139
|
+
- @sekyro/node@1.0.0-rc.36
|
|
140
|
+
|
|
3
141
|
## 0.1.0-rc.7
|
|
4
142
|
|
|
5
143
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ itself has no runtime dependency and runs on Node.js 20.
|
|
|
52
52
|
|
|
53
53
|
## Configure Sekyro
|
|
54
54
|
|
|
55
|
-
An app, its API key (`sessions:create`, `sessions:read`, `people:read`, plus `people:
|
|
55
|
+
An app, its API key (`sessions:create`, `sessions:read`, `sessions:manage`, `people:read`, plus `people:manage` when
|
|
56
56
|
`onUserDeleted` is `revoke` or `delete`) and a webhook endpoint for `session.verified`, `session.not_verified`,
|
|
57
57
|
`person.updated` and `person.deleted`, limited to the app's id (`appIds`).
|
|
58
58
|
|
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 CONNECTOR_VERSION="0.1.0
|
|
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";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 CONNECTOR_VERSION="0.1.0
|
|
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";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
|
|
3
|
+
"version": "0.1.0",
|
|
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": "^1.0.0
|
|
61
|
+
"@sekyro/node": "^1.0.0 || ^1.1.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,8 @@
|
|
|
97
97
|
"type": "application",
|
|
98
98
|
"name": "connect-firebase",
|
|
99
99
|
"group": "@sekyro",
|
|
100
|
-
"version": "0.1.0
|
|
101
|
-
"bom-ref": "@sekyro/connect-firebase@0.1.0
|
|
100
|
+
"version": "0.1.0",
|
|
101
|
+
"bom-ref": "@sekyro/connect-firebase@0.1.0",
|
|
102
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.",
|
|
103
103
|
"licenses": [
|
|
104
104
|
{
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
],
|
|
111
|
-
"purl": "pkg:npm/%40sekyro/connect-firebase@0.1.0
|
|
111
|
+
"purl": "pkg:npm/%40sekyro/connect-firebase@0.1.0?vcs_url=git%2Bhttps%3A%2F%2Fgithub.com%2FIBTIKAR-Technologies%2Fibtikar-identity.git%23packages%2Fsekyro-connect-firebase",
|
|
112
112
|
"externalReferences": [
|
|
113
113
|
{
|
|
114
114
|
"url": "https://github.com/IBTIKAR-Technologies/ibtikar-identity/issues",
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"components": [],
|
|
148
148
|
"dependencies": [
|
|
149
149
|
{
|
|
150
|
-
"ref": "@sekyro/connect-firebase@0.1.0
|
|
150
|
+
"ref": "@sekyro/connect-firebase@0.1.0"
|
|
151
151
|
}
|
|
152
152
|
]
|
|
153
153
|
}
|