@theholocron/holocron-plugin-clerk 2.0.0-alpha.46 → 2.0.0-alpha.48

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,22 +1,16 @@
1
- import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, ParseWebhookInput, ResolveTokenInput, RestClient, RestClient as RestClient$1, WebhookDashboardInfo } from "@theholocron/cli";
1
+ import { Auth, AuthDescription, AuthError, AuthEvent, AuthIdentity, AuthUser, CreateAuthUserInput, ParseWebhookInput, ResolveTokenInput, WebhookDashboardInfo } from "@theholocron/cli";
2
+ import { ClerkClient, createClerkClient } from "@theholocron/clerk-client";
2
3
 
3
4
  //#region src/auth.d.ts
4
5
  declare const resolveToken: (input?: import("@theholocron/http-client").ResolveTokenInput) => string;
5
6
  //#endregion
6
- //#region src/rest.d.ts
7
- declare function createClerkRestClient(opts: {
8
- token: string;
9
- baseUrl?: string;
10
- fetch?: typeof fetch;
11
- }): RestClient$1;
12
- //#endregion
13
7
  //#region src/capabilities/auth.d.ts
14
8
  type ClerkAuthOptions = Record<string, never>;
15
9
  declare class ClerkAuth implements Auth {
16
- private readonly rest;
10
+ private readonly client;
17
11
  readonly key: "auth";
18
12
  readonly providerName = "clerk";
19
- constructor(rest: RestClient, _opts?: ClerkAuthOptions);
13
+ constructor(client: ClerkClient, _opts?: ClerkAuthOptions);
20
14
  describe(): Promise<AuthDescription>;
21
15
  whoami(): Promise<AuthIdentity>;
22
16
  ensureWebhookApp(): Promise<{
@@ -64,7 +58,7 @@ interface ClerkPluginOptions extends ResolveTokenInput {
64
58
  }
65
59
  interface PluginContext {
66
60
  options: ClerkPluginOptions;
67
- rest: RestClient;
61
+ client: ClerkClient;
68
62
  }
69
63
  declare function createContext(options?: ClerkPluginOptions): PluginContext;
70
64
  declare function auth(ctx: PluginContext): Auth;
@@ -82,4 +76,4 @@ declare function createPlugin(options?: ClerkPluginOptions): {
82
76
  */
83
77
  declare const AUTH_HINT: string;
84
78
  //#endregion
85
- export { AUTH_HINT, AuthError, ClerkAuth, ClerkPluginOptions, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, auth, createClerkRestClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
79
+ export { AUTH_HINT, AuthError, ClerkAuth, ClerkPluginOptions, PluginContext, type ResolveTokenInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, auth, createClerkClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { AuthError, ProviderApiError, WebhookVerificationError, createResolveToken, createRestClient } from "@theholocron/cli";
1
+ import { AuthError, ProviderApiError, WebhookVerificationError, createResolveToken } from "@theholocron/cli";
2
+ import { createClerkClient } from "@theholocron/clerk-client";
2
3
  //#region src/auth.ts
3
4
  const resolveToken = createResolveToken({
4
5
  envName: "HOLOCRON_CLERK_SECRET_KEY",
@@ -34,11 +35,11 @@ const resolveToken = createResolveToken({
34
35
  * no per-call instance switch.
35
36
  */
36
37
  var ClerkAuth = class {
37
- rest;
38
+ client;
38
39
  key = "auth";
39
40
  providerName = "clerk";
40
- constructor(rest, _opts = {}) {
41
- this.rest = rest;
41
+ constructor(client, _opts = {}) {
42
+ this.client = client;
42
43
  }
43
44
  async describe() {
44
45
  return {
@@ -49,12 +50,12 @@ var ClerkAuth = class {
49
50
  async whoami() {
50
51
  return {
51
52
  provider: "clerk",
52
- details: { userCount: (await this.rest.request("/users/count")).total_count }
53
+ details: { userCount: (await this.client.users.count()).total_count }
53
54
  };
54
55
  }
55
56
  async ensureWebhookApp() {
56
57
  try {
57
- await this.rest.request("/webhooks/svix", { method: "POST" });
58
+ await this.client.webhooks.ensureSvixApp();
58
59
  return { alreadyExists: false };
59
60
  } catch (err) {
60
61
  if (err instanceof ProviderApiError && isAlreadyExistsError(err)) return { alreadyExists: true };
@@ -62,24 +63,21 @@ var ClerkAuth = class {
62
63
  }
63
64
  }
64
65
  async getWebhookDashboardUrl() {
65
- const body = await this.rest.request("/webhooks/svix_url", { method: "POST" });
66
+ const body = await this.client.webhooks.getSvixUrl();
66
67
  const url = body.url ?? body.svix_url;
67
68
  if (!url) throw new ProviderApiError("Clerk POST /webhooks/svix_url returned 200 but no `url` field", 500, void 0);
68
69
  return { url };
69
70
  }
70
71
  async createUser(input) {
71
- const body = await this.rest.request("/users", {
72
- method: "POST",
73
- body: {
74
- email_address: [input.email],
75
- password: input.password,
76
- ...input.firstName ? { first_name: input.firstName } : {},
77
- ...input.lastName ? { last_name: input.lastName } : {}
78
- }
72
+ const user = await this.client.users.create({
73
+ email_address: [input.email],
74
+ password: input.password,
75
+ ...input.firstName ? { first_name: input.firstName } : {},
76
+ ...input.lastName ? { last_name: input.lastName } : {}
79
77
  });
80
- const email = body.email_addresses[0]?.email_address ?? input.email;
78
+ const email = user.email_addresses[0]?.email_address ?? input.email;
81
79
  return {
82
- id: body.id,
80
+ id: user.id,
83
81
  email
84
82
  };
85
83
  }
@@ -97,16 +95,6 @@ function isAlreadyExistsError(err) {
97
95
  return false;
98
96
  }
99
97
  //#endregion
100
- //#region src/rest.ts
101
- function createClerkRestClient(opts) {
102
- return createRestClient({
103
- baseUrl: opts.baseUrl ?? "https://api.clerk.com/v1",
104
- token: opts.token,
105
- vendor: "Clerk",
106
- fetch: opts.fetch
107
- });
108
- }
109
- //#endregion
110
98
  //#region src/parse-webhook.ts
111
99
  /**
112
100
  * Translates a Clerk webhook delivery into the normalized `AuthEvent`
@@ -186,16 +174,16 @@ async function verifySignature(input) {
186
174
  * canonical "is this secret key valid?" endpoint.
187
175
  */
188
176
  async function verifyToken(token, opts = {}) {
189
- const rest = createClerkRestClient({
177
+ const client = createClerkClient({
190
178
  token,
191
179
  baseUrl: opts.baseUrl,
192
180
  fetch: opts.fetch
193
181
  });
194
182
  try {
195
- const instance = await rest.request("/instance");
183
+ const inst = await client.instance.get();
196
184
  return {
197
185
  ok: true,
198
- subject: `${instance?.environment_type ?? "unknown"} instance ${instance?.id ?? "unknown"}`
186
+ subject: `${inst?.environment_type ?? "unknown"} instance ${inst?.id ?? "unknown"}`
199
187
  };
200
188
  } catch (err) {
201
189
  return {
@@ -209,7 +197,7 @@ async function verifyToken(token, opts = {}) {
209
197
  function createContext(options = {}) {
210
198
  return {
211
199
  options,
212
- rest: createClerkRestClient({
200
+ client: createClerkClient({
213
201
  token: resolveToken(options),
214
202
  baseUrl: options.baseUrl,
215
203
  fetch: options.fetch
@@ -217,7 +205,7 @@ function createContext(options = {}) {
217
205
  };
218
206
  }
219
207
  function auth(ctx) {
220
- return new ClerkAuth(ctx.rest);
208
+ return new ClerkAuth(ctx.client);
221
209
  }
222
210
  function createPlugin(options = {}) {
223
211
  const ctx = createContext(options);
@@ -234,4 +222,4 @@ function createPlugin(options = {}) {
234
222
  */
235
223
  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.";
236
224
  //#endregion
237
- export { AUTH_HINT, AuthError, ClerkAuth, auth, createClerkRestClient, createContext, createPlugin, parseWebhook, resolveToken, verifyToken };
225
+ 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": "2.0.0-alpha.46",
3
+ "version": "2.0.0-alpha.48",
4
4
  "description": "Holocron plugin for Clerk. Implements the auth capability against Clerk's Backend REST API.",
5
5
  "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-clerk#readme",
6
6
  "bugs": "https://github.com/theholocron/holocron/issues",
@@ -21,9 +21,11 @@
21
21
  }
22
22
  },
23
23
  "peerDependencies": {
24
- "@theholocron/cli": "2.0.0-alpha.46"
24
+ "@theholocron/clerk-client": "^0.6.2",
25
+ "@theholocron/cli": "2.0.0-alpha.48"
25
26
  },
26
27
  "devDependencies": {
28
+ "@theholocron/clerk-client": "^0.6.2",
27
29
  "@types/node": "^26",
28
30
  "@theholocron/eslint-config": "^5.2.0",
29
31
  "@theholocron/tsconfig": "^6.0.0",
@@ -37,7 +39,7 @@
37
39
  "tsx": "^4.22.4",
38
40
  "typescript": "^5.9.3",
39
41
  "vitest": "^4.1.10",
40
- "@theholocron/cli": "2.0.0-alpha.46"
42
+ "@theholocron/cli": "2.0.0-alpha.48"
41
43
  },
42
44
  "publishConfig": {
43
45
  "access": "public"