@drawbridge/drawbridge-utils 0.0.8 → 0.0.9

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.
@@ -1,7 +1,7 @@
1
1
  // Simple circuit breaker for wrapped async operations.
2
2
  //
3
- // const breaker = circuit({ name : 'kinde-auth', threshold : 5, timeout : 30000 });
4
- // const result = await breaker( () => validateToken( ... ) );
3
+ // const breaker = circuit({ name : 'google-auth', threshold : 5, timeout : 30000 });
4
+ // const result = await breaker( () => verifyIdToken( ... ) );
5
5
  //
6
6
  // States: CLOSED → OPEN (after `threshold` consecutive failures) → HALF_OPEN
7
7
  // (after `timeout` ms; next call probes recovery) → CLOSED (on success).
package/dist/circuit.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Simple circuit breaker for wrapped async operations.
2
2
  //
3
- // const breaker = circuit({ name : 'kinde-auth', threshold : 5, timeout : 30000 });
4
- // const result = await breaker( () => validateToken( ... ) );
3
+ // const breaker = circuit({ name : 'google-auth', threshold : 5, timeout : 30000 });
4
+ // const result = await breaker( () => verifyIdToken( ... ) );
5
5
  //
6
6
  // States: CLOSED → OPEN (after `threshold` consecutive failures) → HALF_OPEN
7
7
  // (after `timeout` ms; next call probes recovery) → CLOSED (on success).
package/package.json CHANGED
@@ -1,8 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
3
  "dependencies": {
4
- "@kinde/jwt-decoder": "0.2.1",
5
- "@kinde/jwt-validator": "0.4.1",
6
4
  "axios": "1.16.0",
7
5
  "currency-codes": "2.2.0",
8
6
  "nanoid": "3.3.8",
@@ -20,11 +18,6 @@
20
18
  "import": "./dist/encrypt.js",
21
19
  "require": "./dist/encrypt.cjs"
22
20
  },
23
- "./kinde": {
24
- "types": "./dist/kinde.d.ts",
25
- "import": "./dist/kinde.js",
26
- "require": "./dist/kinde.cjs"
27
- },
28
21
  "./axios": {
29
22
  "types": "./dist/axios.d.ts",
30
23
  "import": "./dist/axios.js",
@@ -60,5 +53,5 @@
60
53
  "build": "tsup && npm publish"
61
54
  },
62
55
  "types": "dist/index.d.ts",
63
- "version": "0.0.8"
56
+ "version": "0.0.9"
64
57
  }
package/dist/kinde.cjs DELETED
@@ -1,56 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // kinde.js
20
- var kinde_exports = {};
21
- __export(kinde_exports, {
22
- verifyToken: () => verifyToken
23
- });
24
- module.exports = __toCommonJS(kinde_exports);
25
- var import_jwt_decoder = require("@kinde/jwt-decoder");
26
- var import_jwt_validator = require("@kinde/jwt-validator");
27
- var normalizeDomain = (raw) => {
28
- const trimmed = (raw || "").trim().replace(/\/+$/, "");
29
- if (!trimmed) return trimmed;
30
- return /^https?:\/\//.test(trimmed) ? trimmed : "https://" + trimmed;
31
- };
32
- var verifyToken = async (rawToken, { domain } = {}) => {
33
- if (!rawToken) {
34
- throw new Error("No token");
35
- }
36
- ;
37
- const token = rawToken.startsWith("Bearer ") ? rawToken.slice(7) : rawToken;
38
- const validation = await (0, import_jwt_validator.validateToken)({
39
- domain: normalizeDomain(domain),
40
- token
41
- });
42
- if (!(validation == null ? void 0 : validation.valid)) {
43
- throw new Error((validation == null ? void 0 : validation.message) || "Invalid token");
44
- }
45
- ;
46
- const decoded = (0, import_jwt_decoder.jwtDecoder)(token);
47
- if (!(decoded == null ? void 0 : decoded.sub)) {
48
- throw new Error("Invalid token payload");
49
- }
50
- ;
51
- return decoded;
52
- };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- verifyToken
56
- });
package/dist/kinde.d.cts DELETED
@@ -1,52 +0,0 @@
1
- import { jwtDecoder } from '@kinde/jwt-decoder';
2
- import { validateToken } from '@kinde/jwt-validator';
3
-
4
- const normalizeDomain = ( raw ) => {
5
-
6
- const trimmed = ( raw || '' ).trim().replace( /\/+$/, '' );
7
-
8
- if( ! trimmed ) return trimmed;
9
-
10
- return /^https?:\/\//.test( trimmed ) ? trimmed : 'https://' + trimmed;
11
-
12
- };
13
-
14
- // Verifies a Kinde access token cryptographically via JWKS and returns the decoded
15
- // payload. Throws on any failure (missing/invalid signature, missing sub claim, etc.).
16
- // Caller does user lookup + service-specific glue around this.
17
- //
18
- // const decoded = await verifyToken( token, { domain : process.env.KINDE_DOMAIN } );
19
- // decoded.sub // Kinde user id
20
- // decoded.org_code // org code
21
- // decoded.permissions // permissions array
22
- const verifyToken = async ( rawToken, { domain } = {} ) => {
23
-
24
- if( ! rawToken ){
25
-
26
- throw new Error( 'No token' );
27
-
28
- }
29
- const token = rawToken.startsWith( 'Bearer ' ) ? rawToken.slice( 7 ) : rawToken;
30
-
31
- const validation = await validateToken({
32
- domain : normalizeDomain( domain ),
33
- token
34
- });
35
-
36
- if( ! validation?.valid ){
37
-
38
- throw new Error( validation?.message || 'Invalid token' );
39
-
40
- }
41
- const decoded = jwtDecoder( token );
42
-
43
- if( ! decoded?.sub ){
44
-
45
- throw new Error( 'Invalid token payload' );
46
-
47
- }
48
- return decoded;
49
-
50
- };
51
-
52
- export { verifyToken };
package/dist/kinde.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { jwtDecoder } from '@kinde/jwt-decoder';
2
- import { validateToken } from '@kinde/jwt-validator';
3
-
4
- const normalizeDomain = ( raw ) => {
5
-
6
- const trimmed = ( raw || '' ).trim().replace( /\/+$/, '' );
7
-
8
- if( ! trimmed ) return trimmed;
9
-
10
- return /^https?:\/\//.test( trimmed ) ? trimmed : 'https://' + trimmed;
11
-
12
- };
13
-
14
- // Verifies a Kinde access token cryptographically via JWKS and returns the decoded
15
- // payload. Throws on any failure (missing/invalid signature, missing sub claim, etc.).
16
- // Caller does user lookup + service-specific glue around this.
17
- //
18
- // const decoded = await verifyToken( token, { domain : process.env.KINDE_DOMAIN } );
19
- // decoded.sub // Kinde user id
20
- // decoded.org_code // org code
21
- // decoded.permissions // permissions array
22
- const verifyToken = async ( rawToken, { domain } = {} ) => {
23
-
24
- if( ! rawToken ){
25
-
26
- throw new Error( 'No token' );
27
-
28
- }
29
- const token = rawToken.startsWith( 'Bearer ' ) ? rawToken.slice( 7 ) : rawToken;
30
-
31
- const validation = await validateToken({
32
- domain : normalizeDomain( domain ),
33
- token
34
- });
35
-
36
- if( ! validation?.valid ){
37
-
38
- throw new Error( validation?.message || 'Invalid token' );
39
-
40
- }
41
- const decoded = jwtDecoder( token );
42
-
43
- if( ! decoded?.sub ){
44
-
45
- throw new Error( 'Invalid token payload' );
46
-
47
- }
48
- return decoded;
49
-
50
- };
51
-
52
- export { verifyToken };
package/dist/kinde.js DELETED
@@ -1,32 +0,0 @@
1
- // kinde.js
2
- import { jwtDecoder } from "@kinde/jwt-decoder";
3
- import { validateToken } from "@kinde/jwt-validator";
4
- var normalizeDomain = (raw) => {
5
- const trimmed = (raw || "").trim().replace(/\/+$/, "");
6
- if (!trimmed) return trimmed;
7
- return /^https?:\/\//.test(trimmed) ? trimmed : "https://" + trimmed;
8
- };
9
- var verifyToken = async (rawToken, { domain } = {}) => {
10
- if (!rawToken) {
11
- throw new Error("No token");
12
- }
13
- ;
14
- const token = rawToken.startsWith("Bearer ") ? rawToken.slice(7) : rawToken;
15
- const validation = await validateToken({
16
- domain: normalizeDomain(domain),
17
- token
18
- });
19
- if (!(validation == null ? void 0 : validation.valid)) {
20
- throw new Error((validation == null ? void 0 : validation.message) || "Invalid token");
21
- }
22
- ;
23
- const decoded = jwtDecoder(token);
24
- if (!(decoded == null ? void 0 : decoded.sub)) {
25
- throw new Error("Invalid token payload");
26
- }
27
- ;
28
- return decoded;
29
- };
30
- export {
31
- verifyToken
32
- };