@cedarjs/auth-clerk-api 1.1.1-next.18 → 1.1.1-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/dist/decoder.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import type { Decoder } from '@cedarjs/api';
2
+ /**
3
+ * @deprecated This function will be removed; it uses a rate-limited API. Use `clerkAuthDecoder` instead.
4
+ */
5
+ export declare const authDecoder: Decoder;
2
6
  export declare const clerkAuthDecoder: Decoder;
3
7
  //# sourceMappingURL=decoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../src/decoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,eAAO,MAAM,gBAAgB,EAAE,OA6B9B,CAAA"}
1
+ {"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../src/decoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,OAiCzB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,OAkC9B,CAAA"}
package/dist/decoder.js CHANGED
@@ -28,18 +28,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var decoder_exports = {};
30
30
  __export(decoder_exports, {
31
+ authDecoder: () => authDecoder,
31
32
  clerkAuthDecoder: () => clerkAuthDecoder
32
33
  });
33
34
  module.exports = __toCommonJS(decoder_exports);
35
+ const authDecoder = async (token, type) => {
36
+ if (type !== "clerk") {
37
+ return null;
38
+ }
39
+ const { users, verifyToken } = await import("@clerk/clerk-sdk-node");
40
+ try {
41
+ const issuer = (iss) => iss.startsWith("https://clerk.") || iss.includes(".clerk.accounts");
42
+ const jwtPayload = await verifyToken(token, {
43
+ issuer,
44
+ apiUrl: process.env.CLERK_API_URL || "https://api.clerk.dev",
45
+ jwtKey: process.env.CLERK_JWT_KEY,
46
+ apiKey: process.env.CLERK_API_KEY,
47
+ secretKey: process.env.CLERK_SECRET_KEY
48
+ });
49
+ if (!jwtPayload.sub) {
50
+ return Promise.reject(new Error("Session invalid"));
51
+ }
52
+ const user = await users.getUser(jwtPayload.sub);
53
+ return {
54
+ ...user,
55
+ roles: user.publicMetadata["roles"] ?? []
56
+ };
57
+ } catch (error) {
58
+ console.error(error);
59
+ return Promise.reject(error);
60
+ }
61
+ };
34
62
  const clerkAuthDecoder = async (token, type) => {
35
63
  if (type !== "clerk") {
36
64
  return null;
37
65
  }
38
- const { verifyToken } = await import("@clerk/backend");
66
+ const { verifyToken } = await import("@clerk/clerk-sdk-node");
39
67
  try {
68
+ const issuer = (iss) => iss.startsWith("https://clerk.") || iss.includes(".clerk.accounts");
40
69
  const jwtPayload = await verifyToken(token, {
41
- apiUrl: process.env.CLERK_API_URL,
70
+ issuer,
71
+ apiUrl: process.env.CLERK_API_URL || "https://api.clerk.dev",
42
72
  jwtKey: process.env.CLERK_JWT_KEY,
73
+ apiKey: process.env.CLERK_API_KEY,
43
74
  secretKey: process.env.CLERK_SECRET_KEY
44
75
  });
45
76
  if (!jwtPayload.sub) {
@@ -56,5 +87,6 @@ const clerkAuthDecoder = async (token, type) => {
56
87
  };
57
88
  // Annotate the CommonJS export names for ESM import in node:
58
89
  0 && (module.exports = {
90
+ authDecoder,
59
91
  clerkAuthDecoder
60
92
  });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { clerkAuthDecoder } from './decoder';
1
+ export { authDecoder, clerkAuthDecoder } from './decoder';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -18,11 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
+ authDecoder: () => import_decoder.authDecoder,
21
22
  clerkAuthDecoder: () => import_decoder.clerkAuthDecoder
22
23
  });
23
24
  module.exports = __toCommonJS(index_exports);
24
25
  var import_decoder = require("./decoder");
25
26
  // Annotate the CommonJS export names for ESM import in node:
26
27
  0 && (module.exports = {
28
+ authDecoder,
27
29
  clerkAuthDecoder
28
30
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/auth-clerk-api",
3
- "version": "1.1.1-next.18+5ffd3124d",
3
+ "version": "1.1.1-rc.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -39,12 +39,12 @@
39
39
  "test:watch": "vitest watch"
40
40
  },
41
41
  "dependencies": {
42
- "@clerk/backend": "1.34.0"
42
+ "@clerk/clerk-sdk-node": "4.13.21"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@arethetypeswrong/cli": "0.18.2",
46
- "@cedarjs/api": "1.1.1-next.18+5ffd3124d",
47
- "@cedarjs/framework-tools": "1.1.1-next.18",
46
+ "@cedarjs/api": "1.1.1-rc.3",
47
+ "@cedarjs/framework-tools": "1.1.1-rc.3",
48
48
  "@types/aws-lambda": "8.10.152",
49
49
  "concurrently": "8.2.2",
50
50
  "publint": "0.3.12",
@@ -55,5 +55,5 @@
55
55
  "publishConfig": {
56
56
  "access": "public"
57
57
  },
58
- "gitHead": "5ffd3124d3d4ceb7843408264c96ecceff8542f5"
58
+ "gitHead": "1332c50070b0ab7f2cfc0d7bc802c60cd8a664a9"
59
59
  }