@theholocron/holocron-plugin-clerk 5.0.0-alpha.51 → 5.0.0-alpha.510

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/README.md CHANGED
@@ -19,10 +19,10 @@ Token resolution order:
19
19
  2. `HOLOCRON_CLERK_SECRET_KEY` env var
20
20
  3. `CLERK_SECRET_KEY` env var (Clerk's own default; what their docs reference)
21
21
  4. Keyring `clerk.<org>` — tried first when an org is active via `--org`, `HOLOCRON_ORG`, or `org` in `holocron.config.ts`
22
- 5. Keyring `clerk` — unnamespaced fallback; set via `holocron auth set clerk <key>`
22
+ 5. Keyring `clerk` — unnamespaced fallback; set via `holocron new token clerk <key>`
23
23
 
24
24
  > **Why not the `clerk` CLI?** Rando's adapter shells out to `npx clerk@latest
25
- api …`, but the `clerk` CLI just wraps the same REST API holocron talks to.
25
+ api …`, but the `clerk` CLI only wraps the same REST API holocron talks to.
26
26
  > Direct REST drops a system-binary dependency and matches the uniform auth/REST
27
27
  > pattern across the other holocron plugins.
28
28
 
package/dist/index.d.mts CHANGED
@@ -1,13 +1,22 @@
1
- import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, ParseWebhookInput, ResolveTokenInput, WebhookDashboardInfo } from "@theholocron/cli";
1
+ /**
2
+ * `@theholocron/holocron-plugin-clerk` — entrypoint.
3
+ *
4
+ * Implements the `auth` capability against Clerk's Backend REST API.
5
+ * See README for auth + config docs.
6
+ */
7
+ import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, EnsureRelaySourceInput, EnsureRelaySourceResult, ParseWebhookInput, PluginToken, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess, WebhookDashboardInfo } from "@theholocron/cli";
2
8
  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
9
+ /** Resolves the Clerk secret key from `--token`, `HOLOCRON_CLERK_SECRET_KEY`, `CLERK_SECRET_KEY` or the keyring entry for `clerk`, and throws `AuthError` when none is set. */
10
+ export declare const resolveToken: import("@theholocron/cli").TokenResolver;
11
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`. */
12
+ export declare const tokens: PluginToken[];
7
13
  type ClerkAuthOptions = Record<string, never>;
8
- declare class ClerkAuth implements Auth {
14
+ /** `auth` capability for Clerk, backed by Clerk's Backend REST API. */
15
+ export declare class ClerkAuth implements Auth {
9
16
  private readonly client;
17
+ /** Capability key; always `"auth"`. */
10
18
  readonly key: "auth";
19
+ /** Provider name; always `"clerk"`. */
11
20
  readonly providerName = "clerk";
12
21
  constructor(client: () => ClerkClient, _opts?: ClerkAuthOptions);
13
22
  describe(): Promise<AuthDescription>;
@@ -16,63 +25,58 @@ declare class ClerkAuth implements Auth {
16
25
  alreadyExists: boolean;
17
26
  }>;
18
27
  getWebhookDashboardUrl(): Promise<WebhookDashboardInfo>;
28
+ /**
29
+ * Clerk is the one relay source with a manual step (spec `tech-relay-sources`). Clerk delivers through Svix and
30
+ * neither the Backend API nor the Platform API has a route that makes an endpoint, lists them or returns a `whsec_`
31
+ * signing secret (checked 2026-11-19: `POST`/`DELETE /webhooks/svix` and `POST /webhooks/svix_url` are the only
32
+ * webhook routes). So this makes sure the instance's Svix app exists (idempotent) and returns a `todo` naming the
33
+ * dashboard steps; it never returns a secret and never creates an endpoint. Once the endpoint is made and
34
+ * `COMLINK_CLERK_SECRET` is synced, set `options.confirmed: true` on the source in the layout to stop the `todo`.
35
+ */
36
+ ensureRelaySource(input: EnsureRelaySourceInput): Promise<EnsureRelaySourceResult>;
19
37
  createUser(input: CreateAuthUserInput): Promise<AuthUser>;
20
38
  }
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;
39
+ /** Verifies a Clerk webhook's signature and replay window, then turns it into a normalized `AuthEvent`; throws `WebhookVerificationError` on a bad signature, invalid JSON or an unmapped event type. */
40
+ export declare function parseWebhook(input: ParseWebhookInput): Promise<AuthEvent>;
45
41
  interface VerifyTokenOptions {
46
42
  baseUrl?: string;
47
43
  fetch?: typeof fetch;
48
44
  }
49
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
50
- //#endregion
51
- //#region src/index.d.ts
52
- interface ClerkPluginOptions extends ResolveTokenInput {
45
+ /** Checks a Clerk secret key by fetching the instance and reports its environment type and id, or why it was rejected. */
46
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
47
+ /** Options for the Clerk plugin: the token lookup inputs plus test overrides. */
48
+ export interface ClerkPluginOptions extends ResolveTokenInput {
53
49
  /** Override base URL for tests. */
54
50
  baseUrl?: string;
55
51
  /** Override `fetch` for tests. */
56
52
  fetch?: typeof fetch;
57
53
  }
58
- interface PluginContext {
54
+ /** Shared state for one Clerk plugin instance: its options and a lazily created client. */
55
+ export interface PluginContext {
56
+ /** The options the plugin was created with. */
59
57
  options: ClerkPluginOptions;
58
+ /** Returns the memoized Clerk client; the token is resolved on the first call, not at plugin load. */
60
59
  client: () => ClerkClient;
61
60
  }
62
- declare function createContext(options?: ClerkPluginOptions): PluginContext;
63
- declare function auth(ctx: PluginContext): Auth;
64
- declare function createPlugin(options?: ClerkPluginOptions): {
61
+ /** Builds the plugin context from its options. */
62
+ export declare function createContext(options?: ClerkPluginOptions): PluginContext;
63
+ /** Builds the `auth` capability for the context. */
64
+ export declare function auth(ctx: PluginContext): Auth;
65
+ /** Creates the Clerk plugin: its `connection` probe and the `auth` capability. */
66
+ export declare function createPlugin(options?: ClerkPluginOptions): {
65
67
  name: string;
68
+ probes: {
69
+ connection: import("@theholocron/cli").Probe;
70
+ };
66
71
  capabilities: {
67
72
  auth: () => Auth;
68
73
  };
69
74
  };
70
75
  /**
71
- * One-line hint printed by `holocron auth set clerk` when no token
76
+ * One-line hint printed by `holocron new token clerk` when no token
72
77
  * is supplied or the supplied token is rejected. Points operators at
73
78
  * the Clerk dashboard's API Keys section — MUST be the SECRET key
74
79
  * (sk_test_* / sk_live_*), not the publishable key.
75
80
  */
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 };
81
+ export declare const AUTH_HINT: string;
82
+ export { AuthError, type ClerkClientOptions, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createClerkClient };
package/dist/index.mjs CHANGED
@@ -1,18 +1,24 @@
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
6
+ /** Resolves the Clerk secret key from `--token`, `HOLOCRON_CLERK_SECRET_KEY`, `CLERK_SECRET_KEY` or the keyring entry for `clerk`, and throws `AuthError` when none is set. */
5
7
  const resolveToken = createResolveToken({
6
8
  envName: "HOLOCRON_CLERK_SECRET_KEY",
7
9
  vendorEnvName: "CLERK_SECRET_KEY",
8
10
  keyringService: "clerk",
9
- errorMessage: "no Clerk secret key found. Pass --token <KEY>, set HOLOCRON_CLERK_SECRET_KEY / CLERK_SECRET_KEY, or run: holocron auth set clerk <KEY>"
11
+ errorMessage: "no Clerk secret key found. Pass --token <KEY>, set HOLOCRON_CLERK_SECRET_KEY / CLERK_SECRET_KEY, or run: holocron new token clerk <KEY>"
10
12
  });
11
- //#endregion
12
- //#region src/capabilities/auth.ts
13
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`. */
14
+ const tokens = [resolveToken.token];
15
+ // src/capabilities/auth.ts
16
+ /** `auth` capability for Clerk, backed by Clerk's Backend REST API. */
13
17
  var ClerkAuth = class {
14
18
  client;
19
+ /** Capability key; always `"auth"`. */
15
20
  key = "auth";
21
+ /** Provider name; always `"clerk"`. */
16
22
  providerName = "clerk";
17
23
  constructor(client, _opts = {}) {
18
24
  this.client = client;
@@ -44,6 +50,28 @@ var ClerkAuth = class {
44
50
  if (!url) throw new ProviderApiError("Clerk POST /webhooks/svix_url returned 200 but no `url` field", 500, void 0);
45
51
  return { url };
46
52
  }
53
+ /**
54
+ * Clerk is the one relay source with a manual step (spec `tech-relay-sources`). Clerk delivers through Svix and
55
+ * neither the Backend API nor the Platform API has a route that makes an endpoint, lists them or returns a `whsec_`
56
+ * signing secret (checked 2026-11-19: `POST`/`DELETE /webhooks/svix` and `POST /webhooks/svix_url` are the only
57
+ * webhook routes). So this makes sure the instance's Svix app exists (idempotent) and returns a `todo` naming the
58
+ * dashboard steps; it never returns a secret and never creates an endpoint. Once the endpoint is made and
59
+ * `COMLINK_CLERK_SECRET` is synced, set `options.confirmed: true` on the source in the layout to stop the `todo`.
60
+ */
61
+ async ensureRelaySource(input) {
62
+ await this.ensureWebhookApp();
63
+ if (input.options?.["confirmed"] === true) return {
64
+ created: false,
65
+ updated: []
66
+ };
67
+ const events = input.events?.length ? input.events.join(", ") : "the events the Comlink clerk source carries";
68
+ const binding = `COMLINK_${input.source.toUpperCase()}_SECRET`;
69
+ return {
70
+ created: false,
71
+ updated: [],
72
+ todo: [`Clerk has no API to make a webhook endpoint: in the Clerk Dashboard open Configure, Webhooks, Add Endpoint, set the URL to ${input.url}, tick ${events}, and save.`, `Copy the endpoint's Signing Secret (whsec_...) from its page into the prod 1Password Environment as ${binding}, run \`holocron sync secrets --env prod --cwd apps/comlink --worker comlink\`, then set \`options: { confirmed: true }\` on the \`${input.source}\` relay source to clear this step.`]
73
+ };
74
+ }
47
75
  async createUser(input) {
48
76
  const user = await this.client().users.create({
49
77
  email_address: [input.email],
@@ -70,8 +98,28 @@ function isAlreadyExistsError(err) {
70
98
  }
71
99
  return false;
72
100
  }
73
- //#endregion
74
- //#region src/parse-webhook.ts
101
+ // src/verify-token.ts
102
+ /** Checks a Clerk secret key by fetching the instance and reports its environment type and id, or why it was rejected. */
103
+ async function verifyToken(token, opts = {}) {
104
+ const client = createClerkClient({
105
+ token,
106
+ baseUrl: opts.baseUrl,
107
+ fetch: opts.fetch
108
+ });
109
+ try {
110
+ const inst = await client.instance.get();
111
+ return {
112
+ ok: true,
113
+ subject: `${inst?.environment_type ?? "unknown"} instance ${inst?.id ?? "unknown"}`
114
+ };
115
+ } catch (err) {
116
+ return {
117
+ ok: false,
118
+ message: errorMessage(err)
119
+ };
120
+ }
121
+ }
122
+ // src/parse-webhook.ts
75
123
  /**
76
124
  * Translates a Clerk webhook delivery into the normalized `AuthEvent`
77
125
  * shape defined in `@theholocron/cli`, with full Svix HMAC-SHA256
@@ -91,6 +139,7 @@ const CLERK_TO_NORMALIZED = {
91
139
  "user.deleted": "user.deleted"
92
140
  };
93
141
  const REPLAY_WINDOW_SECONDS = 300;
142
+ /** Verifies a Clerk webhook's signature and replay window, then turns it into a normalized `AuthEvent`; throws `WebhookVerificationError` on a bad signature, invalid JSON or an unmapped event type. */
94
143
  async function parseWebhook(input) {
95
144
  await verifySignature(input);
96
145
  const bodyStr = typeof input.body === "string" ? input.body : input.body.toString("utf8");
@@ -98,7 +147,7 @@ async function parseWebhook(input) {
98
147
  try {
99
148
  payload = JSON.parse(bodyStr);
100
149
  } catch (err) {
101
- throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
150
+ throw new WebhookVerificationError(`Clerk webhook body is not valid JSON: ${errorMessage(err)}`);
102
151
  }
103
152
  const normalizedType = CLERK_TO_NORMALIZED[payload.type];
104
153
  if (!normalizedType) throw new WebhookVerificationError(`Clerk webhook event type "${payload.type}" has no normalized mapping yet`);
@@ -141,46 +190,15 @@ async function verifySignature(input) {
141
190
  let sigBytes;
142
191
  try {
143
192
  sigBytes = Buffer.from(sig.slice(comma + 1), "base64");
144
- } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
193
+ } catch /* istanbul ignore next -- Buffer.from('base64') never throws in Node.js */ {
145
194
  return false;
146
195
  }
147
196
  if (sigBytes.length !== computed.length) return false;
148
197
  return timingSafeEqual(sigBytes, computed);
149
198
  })) throw new WebhookVerificationError("Svix signature verification failed");
150
199
  }
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
200
+ // src/index.ts
201
+ /** Builds the plugin context from its options. */
184
202
  function createContext(options = {}) {
185
203
  let client;
186
204
  return {
@@ -192,22 +210,33 @@ function createContext(options = {}) {
192
210
  })
193
211
  };
194
212
  }
213
+ /** Builds the `auth` capability for the context. */
195
214
  function auth(ctx) {
196
215
  return new ClerkAuth(ctx.client);
197
216
  }
217
+ /** Creates the Clerk plugin: its `connection` probe and the `auth` capability. */
198
218
  function createPlugin(options = {}) {
199
219
  const ctx = createContext(options);
200
220
  return {
201
221
  name: "@theholocron/holocron-plugin-clerk",
222
+ probes: { connection: connectionProbe({
223
+ provider: "Clerk",
224
+ url: options.baseUrl ?? "https://api.clerk.com",
225
+ fetch: options.fetch,
226
+ token: () => resolveToken(options),
227
+ verify: (token) => verifyToken(token, {
228
+ baseUrl: options.baseUrl,
229
+ fetch: options.fetch
230
+ })
231
+ }) },
202
232
  capabilities: { auth: () => auth(ctx) }
203
233
  };
204
234
  }
205
235
  /**
206
- * One-line hint printed by `holocron auth set clerk` when no token
236
+ * One-line hint printed by `holocron new token clerk` when no token
207
237
  * is supplied or the supplied token is rejected. Points operators at
208
238
  * the Clerk dashboard's API Keys section — MUST be the SECRET key
209
239
  * (sk_test_* / sk_live_*), not the publishable key.
210
240
  */
211
- 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 };
241
+ const AUTH_HINT = "grab your SECRET key (sk_test_* / sk_live_*) at https://dashboard.clerk.com → API Keys, then run: holocron new token clerk <KEY>. Do NOT use the publishable key.";
242
+ 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.51",
3
+ "version": "5.0.0-alpha.510",
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.25.0",
34
- "@theholocron/eslint-config": "^8.4.5",
35
- "@theholocron/http-client": "^1.25.0",
36
- "@theholocron/tsconfig": "^8.4.5",
37
- "@theholocron/tsdown-config": "^8.4.5",
38
- "@theholocron/vitest-config": "^8.4.5",
39
33
  "@types/node": "^26",
40
- "@vitest/coverage-v8": "^4.1.11",
41
- "@vitest/eslint-plugin": "^1.6.27",
42
- "eslint": "^10.8.1",
43
- "eslint-plugin-n": "^18.3.0",
44
- "globals": "^17.11.0",
45
- "tsdown": "^0.22.14",
46
- "tsx": "4.23.12",
34
+ "@vitest/coverage-v8": "^5.1.0",
35
+ "@vitest/eslint-plugin": "^1.6.28",
36
+ "eslint": "^10.15.0",
37
+ "eslint-plugin-n": "^18.5.0",
38
+ "globals": "^17.14.0",
39
+ "tsdown": "^0.23.7",
40
+ "tsx": "4.23.15",
47
41
  "typescript": "^5.9.3",
48
- "vitest": "^4.1.11",
49
- "@theholocron/cli": "5.0.0-alpha.51"
42
+ "vitest": "^5.1.0",
43
+ "@theholocron/cli": "5.0.0-alpha.510",
44
+ "@theholocron/eslint-config": "^8.9.0-alpha.21",
45
+ "@theholocron/misc-utils": "^1.17.0-alpha.5",
46
+ "@theholocron/clerk-client": "^1.58.0-alpha.48",
47
+ "@theholocron/http-client": "^1.58.0-alpha.48",
48
+ "@theholocron/tsconfig": "^8.9.0-alpha.21",
49
+ "@theholocron/tsdown-config": "^8.9.0-alpha.21",
50
+ "@theholocron/vitest-config": "^8.9.0-alpha.21"
50
51
  },
51
52
  "peerDependencies": {
52
- "@theholocron/clerk-client": "^1.25.0",
53
- "@theholocron/cli": "5.0.0-alpha.51"
53
+ "@theholocron/clerk-client": "^1.43.1",
54
+ "@theholocron/misc-utils": "^1.16.0",
55
+ "@theholocron/cli": "5.0.0-alpha.510"
54
56
  },
55
57
  "engines": {
56
58
  "node": ">=22"
@@ -59,11 +61,11 @@
59
61
  "access": "public"
60
62
  },
61
63
  "scripts": {
62
- "delivery.build": "tsdown",
63
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
64
+ "build": "tsdown",
65
+ "lint:code": "eslint .",
66
+ "test:unit": "vitest run --coverage",
64
67
  "test:watch": "vitest",
65
- "validate": "tsx scripts/validate.mjs",
66
- "verification.typeSafety": "holocron run verification.typeSafety --",
67
- "verification.unitTests": "holocron run verification.unitTests --"
68
+ "typecheck": "tsc --noEmit",
69
+ "validate:plugin": "tsx scripts/validate.mjs"
68
70
  }
69
71
  }