@theholocron/holocron-plugin-clerk 5.0.0-alpha.26 → 5.0.0-alpha.261

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/index.d.mts CHANGED
@@ -1,11 +1,8 @@
1
- import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, ParseWebhookInput, ResolveTokenInput, WebhookDashboardInfo } from "@theholocron/cli";
1
+ import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, ParseWebhookInput, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, WebhookDashboardInfo } from "@theholocron/cli";
2
2
  import { ClerkClient, ClerkClientOptions, createClerkClient } from "@theholocron/clerk-client";
3
- //#region src/auth.d.ts
4
- declare const resolveToken: (input?: ResolveTokenInput) => string;
5
- //#endregion
6
- //#region src/capabilities/auth.d.ts
3
+ export declare const resolveToken: (input?: ResolveTokenInput) => string;
7
4
  type ClerkAuthOptions = Record<string, never>;
8
- declare class ClerkAuth implements Auth {
5
+ export declare class ClerkAuth implements Auth {
9
6
  private readonly client;
10
7
  readonly key: "auth";
11
8
  readonly providerName = "clerk";
@@ -18,51 +15,29 @@ declare class ClerkAuth implements Auth {
18
15
  getWebhookDashboardUrl(): Promise<WebhookDashboardInfo>;
19
16
  createUser(input: CreateAuthUserInput): Promise<AuthUser>;
20
17
  }
21
- //#endregion
22
- //#region src/parse-webhook.d.ts
23
- declare function parseWebhook(input: ParseWebhookInput): Promise<AuthEvent>;
24
- //#endregion
25
- //#region src/verify-token.d.ts
26
- /**
27
- * `verifyToken` — plugin-level export used by `holocron auth set` +
28
- * `holocron auth check`. Hits Clerk's `/v1/instance` endpoint, which
29
- * requires a valid secret key and returns instance metadata (id,
30
- * environment_type, etc.). Invalid keys → 401.
31
- *
32
- * Clerk doesn't have a traditional user-oriented whoami — the "authed
33
- * entity" is your Clerk INSTANCE, not a user. `/v1/instance` is the
34
- * canonical "is this secret key valid?" endpoint.
35
- */
36
- interface VerifyTokenSuccess {
37
- ok: true;
38
- subject: string;
39
- }
40
- interface VerifyTokenFailure {
41
- ok: false;
42
- message: string;
43
- }
44
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
18
+ export declare function parseWebhook(input: ParseWebhookInput): Promise<AuthEvent>;
45
19
  interface VerifyTokenOptions {
46
20
  baseUrl?: string;
47
21
  fetch?: typeof fetch;
48
22
  }
49
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
50
- //#endregion
51
- //#region src/index.d.ts
52
- interface ClerkPluginOptions extends ResolveTokenInput {
23
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
24
+ export interface ClerkPluginOptions extends ResolveTokenInput {
53
25
  /** Override base URL for tests. */
54
26
  baseUrl?: string;
55
27
  /** Override `fetch` for tests. */
56
28
  fetch?: typeof fetch;
57
29
  }
58
- interface PluginContext {
30
+ export interface PluginContext {
59
31
  options: ClerkPluginOptions;
60
32
  client: () => ClerkClient;
61
33
  }
62
- declare function createContext(options?: ClerkPluginOptions): PluginContext;
63
- declare function auth(ctx: PluginContext): Auth;
64
- declare function createPlugin(options?: ClerkPluginOptions): {
34
+ export declare function createContext(options?: ClerkPluginOptions): PluginContext;
35
+ export declare function auth(ctx: PluginContext): Auth;
36
+ export declare function createPlugin(options?: ClerkPluginOptions): {
65
37
  name: string;
38
+ probes: {
39
+ connection: import("@theholocron/cli").Probe;
40
+ };
66
41
  capabilities: {
67
42
  auth: () => Auth;
68
43
  };
@@ -73,6 +48,5 @@ declare function createPlugin(options?: ClerkPluginOptions): {
73
48
  * the Clerk dashboard's API Keys section — MUST be the SECRET key
74
49
  * (sk_test_* / sk_live_*), not the publishable key.
75
50
  */
76
- declare const AUTH_HINT: string;
77
- //#endregion
78
- export { AUTH_HINT, AuthError, ClerkAuth, type ClerkClientOptions, ClerkPluginOptions, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, auth, createClerkClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
51
+ export declare const AUTH_HINT: string;
52
+ export { AuthError, type ClerkClientOptions, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createClerkClient };
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- import { AuthError, ProviderApiError, WebhookVerificationError, createResolveToken } from "@theholocron/cli";
1
+ import { AuthError, ProviderApiError, WebhookVerificationError, connectionProbe, createResolveToken } from "@theholocron/cli";
2
2
  import { createClerkClient } from "@theholocron/clerk-client";
3
+ import { errorMessage } from "@theholocron/misc-utils";
3
4
  import { createHmac, timingSafeEqual } from "node:crypto";
4
- //#region src/auth.ts
5
+ // src/auth.ts
5
6
  const resolveToken = createResolveToken({
6
7
  envName: "HOLOCRON_CLERK_SECRET_KEY",
7
8
  vendorEnvName: "CLERK_SECRET_KEY",
8
9
  keyringService: "clerk",
9
10
  errorMessage: "no Clerk secret key found. Pass --token <KEY>, set HOLOCRON_CLERK_SECRET_KEY / CLERK_SECRET_KEY, or run: holocron auth set clerk <KEY>"
10
11
  });
11
- //#endregion
12
- //#region src/capabilities/auth.ts
12
+ // src/capabilities/auth.ts
13
13
  var ClerkAuth = class {
14
14
  client;
15
15
  key = "auth";
@@ -70,8 +70,27 @@ function isAlreadyExistsError(err) {
70
70
  }
71
71
  return false;
72
72
  }
73
- //#endregion
74
- //#region src/parse-webhook.ts
73
+ // src/verify-token.ts
74
+ async function verifyToken(token, opts = {}) {
75
+ const client = createClerkClient({
76
+ token,
77
+ baseUrl: opts.baseUrl,
78
+ fetch: opts.fetch
79
+ });
80
+ try {
81
+ const inst = await client.instance.get();
82
+ return {
83
+ ok: true,
84
+ subject: `${inst?.environment_type ?? "unknown"} instance ${inst?.id ?? "unknown"}`
85
+ };
86
+ } catch (err) {
87
+ return {
88
+ ok: false,
89
+ message: errorMessage(err)
90
+ };
91
+ }
92
+ }
93
+ // src/parse-webhook.ts
75
94
  /**
76
95
  * Translates a Clerk webhook delivery into the normalized `AuthEvent`
77
96
  * shape defined in `@theholocron/cli`, with full Svix HMAC-SHA256
@@ -98,7 +117,7 @@ async function parseWebhook(input) {
98
117
  try {
99
118
  payload = JSON.parse(bodyStr);
100
119
  } catch (err) {
101
- throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
120
+ throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${errorMessage(err)}`);
102
121
  }
103
122
  const normalizedType = CLERK_TO_NORMALIZED[payload.type];
104
123
  if (!normalizedType) throw new WebhookVerificationError(`Clerk webhook event type "${payload.type}" has no normalized mapping yet`);
@@ -141,46 +160,14 @@ async function verifySignature(input) {
141
160
  let sigBytes;
142
161
  try {
143
162
  sigBytes = Buffer.from(sig.slice(comma + 1), "base64");
144
- } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
163
+ } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
145
164
  return false;
146
165
  }
147
166
  if (sigBytes.length !== computed.length) return false;
148
167
  return timingSafeEqual(sigBytes, computed);
149
168
  })) throw new WebhookVerificationError("Svix signature verification failed");
150
169
  }
151
- //#endregion
152
- //#region src/verify-token.ts
153
- /**
154
- * `verifyToken` — plugin-level export used by `holocron auth set` +
155
- * `holocron auth check`. Hits Clerk's `/v1/instance` endpoint, which
156
- * requires a valid secret key and returns instance metadata (id,
157
- * environment_type, etc.). Invalid keys → 401.
158
- *
159
- * Clerk doesn't have a traditional user-oriented whoami — the "authed
160
- * entity" is your Clerk INSTANCE, not a user. `/v1/instance` is the
161
- * canonical "is this secret key valid?" endpoint.
162
- */
163
- async function verifyToken(token, opts = {}) {
164
- const client = createClerkClient({
165
- token,
166
- baseUrl: opts.baseUrl,
167
- fetch: opts.fetch
168
- });
169
- try {
170
- const inst = await client.instance.get();
171
- return {
172
- ok: true,
173
- subject: `${inst?.environment_type ?? "unknown"} instance ${inst?.id ?? "unknown"}`
174
- };
175
- } catch (err) {
176
- return {
177
- ok: false,
178
- message: err instanceof Error ? err.message : String(err)
179
- };
180
- }
181
- }
182
- //#endregion
183
- //#region src/index.ts
170
+ // src/index.ts
184
171
  function createContext(options = {}) {
185
172
  let client;
186
173
  return {
@@ -199,6 +186,16 @@ function createPlugin(options = {}) {
199
186
  const ctx = createContext(options);
200
187
  return {
201
188
  name: "@theholocron/holocron-plugin-clerk",
189
+ probes: { connection: connectionProbe({
190
+ provider: "Clerk",
191
+ url: options.baseUrl ?? "https://api.clerk.com",
192
+ fetch: options.fetch,
193
+ token: () => resolveToken(options),
194
+ verify: (token) => verifyToken(token, {
195
+ baseUrl: options.baseUrl,
196
+ fetch: options.fetch
197
+ })
198
+ }) },
202
199
  capabilities: { auth: () => auth(ctx) }
203
200
  };
204
201
  }
@@ -209,5 +206,4 @@ function createPlugin(options = {}) {
209
206
  * (sk_test_* / sk_live_*), not the publishable key.
210
207
  */
211
208
  const AUTH_HINT = "grab your SECRET key (sk_test_* / sk_live_*) at https://dashboard.clerk.com → API Keys, then run: holocron auth set clerk <KEY>. Do NOT use the publishable key.";
212
- //#endregion
213
209
  export { AUTH_HINT, AuthError, ClerkAuth, auth, createClerkClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-clerk",
3
- "version": "5.0.0-alpha.26",
3
+ "version": "5.0.0-alpha.261",
4
4
  "description": "Holocron plugin for Clerk. Implements the auth capability against Clerk's Backend REST API.",
5
5
  "keywords": [
6
6
  "auth",
@@ -8,12 +8,12 @@
8
8
  "holocron",
9
9
  "plugin"
10
10
  ],
11
- "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-clerk#readme",
11
+ "homepage": "https://github.com/theholocron/holocron/tree/main/plugins/holocron-plugin-clerk#readme",
12
12
  "bugs": "https://github.com/theholocron/holocron/issues",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/theholocron/holocron.git",
16
- "directory": "packages/holocron-plugin-clerk"
16
+ "directory": "plugins/holocron-plugin-clerk"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Newton Koumantzelis",
@@ -30,27 +30,29 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/clerk-client": "^1.22.0",
34
- "@theholocron/eslint-config": "^8.0.0",
35
- "@theholocron/http-client": "^1.22.0",
36
- "@theholocron/tsconfig": "^8.0.0",
37
- "@theholocron/tsdown-config": "^8.0.0",
38
- "@theholocron/vitest-config": "^8.0.0",
39
33
  "@types/node": "^26",
40
- "@vitest/coverage-v8": "^4.1.11",
34
+ "@vitest/coverage-v8": "^5.0.5",
41
35
  "@vitest/eslint-plugin": "^1.6.27",
42
36
  "eslint": "^10.8.1",
43
37
  "eslint-plugin-n": "^18.3.0",
44
38
  "globals": "^17.11.0",
45
- "tsdown": "^0.22.14",
46
- "tsx": "4.23.12",
39
+ "tsdown": "^0.23.3",
40
+ "tsx": "4.23.15",
47
41
  "typescript": "^5.9.3",
48
- "vitest": "^4.1.11",
49
- "@theholocron/cli": "5.0.0-alpha.26"
42
+ "vitest": "^5.0.5",
43
+ "@theholocron/clerk-client": "^1.57.1-alpha.2",
44
+ "@theholocron/cli": "5.0.0-alpha.261",
45
+ "@theholocron/http-client": "^1.57.1-alpha.2",
46
+ "@theholocron/misc-utils": "^1.16.1-alpha.1",
47
+ "@theholocron/tsconfig": "^8.9.0-alpha.3",
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.3",
49
+ "@theholocron/vitest-config": "^8.9.0-alpha.3",
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.3"
50
51
  },
51
52
  "peerDependencies": {
52
- "@theholocron/clerk-client": "^1.22.0",
53
- "@theholocron/cli": "5.0.0-alpha.26"
53
+ "@theholocron/clerk-client": "^1.43.1",
54
+ "@theholocron/misc-utils": "^1.16.0",
55
+ "@theholocron/cli": "5.0.0-alpha.261"
54
56
  },
55
57
  "engines": {
56
58
  "node": ">=22"
@@ -60,10 +62,10 @@
60
62
  },
61
63
  "scripts": {
62
64
  "delivery.build": "tsdown",
63
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
65
+ "sourceQuality.staticAnalysis": "eslint .",
64
66
  "test:watch": "vitest",
65
67
  "validate": "tsx scripts/validate.mjs",
66
- "verification.typeSafety": "holocron run verification.typeSafety --",
67
- "verification.unitTests": "holocron run verification.unitTests --"
68
+ "verification.typeSafety": "tsc --noEmit",
69
+ "verification.unitTests": "vitest run"
68
70
  }
69
71
  }