@theholocron/holocron-plugin-clerk 5.0.0-alpha.25 → 5.0.0-alpha.251
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 +15 -41
- package/dist/index.mjs +38 -42
- package/package.json +18 -16
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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: ${
|
|
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
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "5.0.0-alpha.251",
|
|
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/
|
|
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": "
|
|
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.
|
|
34
|
-
"@theholocron/eslint-config": "^8.
|
|
35
|
-
"@theholocron/http-client": "^1.
|
|
36
|
-
"@theholocron/
|
|
37
|
-
"@theholocron/
|
|
38
|
-
"@theholocron/
|
|
33
|
+
"@theholocron/clerk-client": "^1.43.1",
|
|
34
|
+
"@theholocron/eslint-config": "^8.8.2",
|
|
35
|
+
"@theholocron/http-client": "^1.57.0",
|
|
36
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
37
|
+
"@theholocron/tsconfig": "^8.8.2",
|
|
38
|
+
"@theholocron/tsdown-config": "^8.8.2",
|
|
39
|
+
"@theholocron/vitest-config": "^8.8.2",
|
|
39
40
|
"@types/node": "^26",
|
|
40
|
-
"@vitest/coverage-v8": "^
|
|
41
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
41
42
|
"@vitest/eslint-plugin": "^1.6.27",
|
|
42
43
|
"eslint": "^10.8.1",
|
|
43
44
|
"eslint-plugin-n": "^18.3.0",
|
|
44
45
|
"globals": "^17.11.0",
|
|
45
|
-
"tsdown": "^0.
|
|
46
|
-
"tsx": "4.23.
|
|
46
|
+
"tsdown": "^0.23.3",
|
|
47
|
+
"tsx": "4.23.15",
|
|
47
48
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^
|
|
49
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
49
|
+
"vitest": "^5.0.5",
|
|
50
|
+
"@theholocron/cli": "5.0.0-alpha.251"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@theholocron/clerk-client": "^1.
|
|
53
|
-
"@theholocron/
|
|
53
|
+
"@theholocron/clerk-client": "^1.43.1",
|
|
54
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
55
|
+
"@theholocron/cli": "5.0.0-alpha.251"
|
|
54
56
|
},
|
|
55
57
|
"engines": {
|
|
56
58
|
"node": ">=22"
|