@theholocron/holocron-plugin-clerk 5.0.0-alpha.27 → 5.0.0-alpha.271

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,10 @@
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, PluginToken, 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: import("@theholocron/cli").TokenResolver;
4
+ /** Every token this plugin takes, for `holocron doctor tokens`. */
5
+ export declare const tokens: PluginToken[];
7
6
  type ClerkAuthOptions = Record<string, never>;
8
- declare class ClerkAuth implements Auth {
7
+ export declare class ClerkAuth implements Auth {
9
8
  private readonly client;
10
9
  readonly key: "auth";
11
10
  readonly providerName = "clerk";
@@ -18,51 +17,29 @@ declare class ClerkAuth implements Auth {
18
17
  getWebhookDashboardUrl(): Promise<WebhookDashboardInfo>;
19
18
  createUser(input: CreateAuthUserInput): Promise<AuthUser>;
20
19
  }
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;
20
+ export declare function parseWebhook(input: ParseWebhookInput): Promise<AuthEvent>;
45
21
  interface VerifyTokenOptions {
46
22
  baseUrl?: string;
47
23
  fetch?: typeof fetch;
48
24
  }
49
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
50
- //#endregion
51
- //#region src/index.d.ts
52
- interface ClerkPluginOptions extends ResolveTokenInput {
25
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
26
+ export interface ClerkPluginOptions extends ResolveTokenInput {
53
27
  /** Override base URL for tests. */
54
28
  baseUrl?: string;
55
29
  /** Override `fetch` for tests. */
56
30
  fetch?: typeof fetch;
57
31
  }
58
- interface PluginContext {
32
+ export interface PluginContext {
59
33
  options: ClerkPluginOptions;
60
34
  client: () => ClerkClient;
61
35
  }
62
- declare function createContext(options?: ClerkPluginOptions): PluginContext;
63
- declare function auth(ctx: PluginContext): Auth;
64
- declare function createPlugin(options?: ClerkPluginOptions): {
36
+ export declare function createContext(options?: ClerkPluginOptions): PluginContext;
37
+ export declare function auth(ctx: PluginContext): Auth;
38
+ export declare function createPlugin(options?: ClerkPluginOptions): {
65
39
  name: string;
40
+ probes: {
41
+ connection: import("@theholocron/cli").Probe;
42
+ };
66
43
  capabilities: {
67
44
  auth: () => Auth;
68
45
  };
@@ -73,6 +50,5 @@ declare function createPlugin(options?: ClerkPluginOptions): {
73
50
  * the Clerk dashboard's API Keys section — MUST be the SECRET key
74
51
  * (sk_test_* / sk_live_*), not the publishable key.
75
52
  */
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 };
53
+ export declare const AUTH_HINT: string;
54
+ export { AuthError, type ClerkClientOptions, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createClerkClient };
package/dist/index.mjs CHANGED
@@ -1,15 +1,17 @@
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
+ /** Every token this plugin takes, for `holocron doctor tokens`. */
13
+ const tokens = [resolveToken.token];
14
+ // src/capabilities/auth.ts
13
15
  var ClerkAuth = class {
14
16
  client;
15
17
  key = "auth";
@@ -70,8 +72,27 @@ function isAlreadyExistsError(err) {
70
72
  }
71
73
  return false;
72
74
  }
73
- //#endregion
74
- //#region src/parse-webhook.ts
75
+ // src/verify-token.ts
76
+ async function verifyToken(token, opts = {}) {
77
+ const client = createClerkClient({
78
+ token,
79
+ baseUrl: opts.baseUrl,
80
+ fetch: opts.fetch
81
+ });
82
+ try {
83
+ const inst = await client.instance.get();
84
+ return {
85
+ ok: true,
86
+ subject: `${inst?.environment_type ?? "unknown"} instance ${inst?.id ?? "unknown"}`
87
+ };
88
+ } catch (err) {
89
+ return {
90
+ ok: false,
91
+ message: errorMessage(err)
92
+ };
93
+ }
94
+ }
95
+ // src/parse-webhook.ts
75
96
  /**
76
97
  * Translates a Clerk webhook delivery into the normalized `AuthEvent`
77
98
  * shape defined in `@theholocron/cli`, with full Svix HMAC-SHA256
@@ -98,7 +119,7 @@ async function parseWebhook(input) {
98
119
  try {
99
120
  payload = JSON.parse(bodyStr);
100
121
  } catch (err) {
101
- throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
122
+ throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${errorMessage(err)}`);
102
123
  }
103
124
  const normalizedType = CLERK_TO_NORMALIZED[payload.type];
104
125
  if (!normalizedType) throw new WebhookVerificationError(`Clerk webhook event type "${payload.type}" has no normalized mapping yet`);
@@ -141,46 +162,14 @@ async function verifySignature(input) {
141
162
  let sigBytes;
142
163
  try {
143
164
  sigBytes = Buffer.from(sig.slice(comma + 1), "base64");
144
- } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
165
+ } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
145
166
  return false;
146
167
  }
147
168
  if (sigBytes.length !== computed.length) return false;
148
169
  return timingSafeEqual(sigBytes, computed);
149
170
  })) throw new WebhookVerificationError("Svix signature verification failed");
150
171
  }
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
172
+ // src/index.ts
184
173
  function createContext(options = {}) {
185
174
  let client;
186
175
  return {
@@ -199,6 +188,16 @@ function createPlugin(options = {}) {
199
188
  const ctx = createContext(options);
200
189
  return {
201
190
  name: "@theholocron/holocron-plugin-clerk",
191
+ probes: { connection: connectionProbe({
192
+ provider: "Clerk",
193
+ url: options.baseUrl ?? "https://api.clerk.com",
194
+ fetch: options.fetch,
195
+ token: () => resolveToken(options),
196
+ verify: (token) => verifyToken(token, {
197
+ baseUrl: options.baseUrl,
198
+ fetch: options.fetch
199
+ })
200
+ }) },
202
201
  capabilities: { auth: () => auth(ctx) }
203
202
  };
204
203
  }
@@ -209,5 +208,4 @@ function createPlugin(options = {}) {
209
208
  * (sk_test_* / sk_live_*), not the publishable key.
210
209
  */
211
210
  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
- export { AUTH_HINT, AuthError, ClerkAuth, auth, createClerkClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
211
+ export { AUTH_HINT, AuthError, ClerkAuth, auth, createClerkClient, createContext, createPlugin, parseWebhook, resolveToken, tokens, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-clerk",
3
- "version": "5.0.0-alpha.27",
3
+ "version": "5.0.0-alpha.271",
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://docs.theholocron.dev/holocron/plugins/clerk/",
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.23.0",
34
- "@theholocron/eslint-config": "^8.0.0",
35
- "@theholocron/http-client": "^1.23.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.27"
42
+ "vitest": "^5.0.5",
43
+ "@theholocron/clerk-client": "^1.58.0-alpha.2",
44
+ "@theholocron/eslint-config": "^8.9.0-alpha.3",
45
+ "@theholocron/cli": "5.0.0-alpha.271",
46
+ "@theholocron/http-client": "^1.58.0-alpha.2",
47
+ "@theholocron/misc-utils": "^1.16.1-alpha.1",
48
+ "@theholocron/tsconfig": "^8.9.0-alpha.3",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.3",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.3"
50
51
  },
51
52
  "peerDependencies": {
52
- "@theholocron/clerk-client": "^1.23.0",
53
- "@theholocron/cli": "5.0.0-alpha.27"
53
+ "@theholocron/clerk-client": "^1.43.1",
54
+ "@theholocron/misc-utils": "^1.16.0",
55
+ "@theholocron/cli": "5.0.0-alpha.271"
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
  }