kinde-testkit 0.6.0 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.1
4
+
5
+ - Cut the package from 923 kB to 321 kB. The ESM entry points now share one copy of the issuer instead of each bundling its own.
6
+ - With `--json`, CLI errors are one JSON object with `code`, `message` and `details`, so scripts and coding agents can read why a command failed. Error details no longer print twice.
7
+ - Add contract tests that compare discovery, JWKS, M2M token claims and Management API responses with a real Kinde business. Run them with `npm run test:contract`.
8
+ - Add a contents list and a section for coding agents to the README.
9
+ - Fix the Next.js example's Cypress outage test, which failed because the first visit landed on the testkit.
10
+
3
11
  ## 0.6.0
4
12
 
5
13
  - Add `kinde-testkit/jest` with the same `useKindeTestkit()` and `kindeTest()` as the Vitest helper, for CommonJS and ESM test files.
package/README.md CHANGED
@@ -11,6 +11,33 @@ There are two ways to use it:
11
11
 
12
12
  It also issues machine-to-machine tokens, answers the Management API and Account API calls your app makes, sends signed webhooks, and makes Kinde's endpoints fail or slow down on demand. A local dashboard shows what the testkit issued and answered, a coverage report shows which authentication cases your tests reached, and a `doctor` command checks your app's Kinde settings before a test run. It runs with Vitest, Jest, Playwright and Cypress, from the command line, or in Docker.
13
13
 
14
+ ## Contents
15
+
16
+ - [Why it exists](#why-it-exists)
17
+ - [How it works](#how-it-works)
18
+ - [Install](#install)
19
+ - [Quick start with Vitest](#quick-start-with-vitest)
20
+ - [Browser tests with Playwright](#browser-tests-with-playwright)
21
+ - [Browser tests with Cypress](#browser-tests-with-cypress)
22
+ - [Machine-to-machine tokens](#machine-to-machine-tokens)
23
+ - [Webhooks](#webhooks)
24
+ - [Management API and Account API](#management-api-and-account-api)
25
+ - [Testing outages](#testing-outages)
26
+ - [Check your setup](#check-your-setup)
27
+ - [With Kinde's SDKs](#with-kindes-sdks)
28
+ - [Use with a coding agent](#use-with-a-coding-agent)
29
+ - [Checked against real Kinde](#checked-against-real-kinde)
30
+ - [Run the issuer from the command line](#run-the-issuer-from-the-command-line)
31
+ - [Dashboard](#dashboard)
32
+ - [Authentication coverage](#authentication-coverage)
33
+ - [Docker](#docker)
34
+ - [Invalid tokens](#invalid-tokens)
35
+ - [API](#api)
36
+ - [Endpoints](#endpoints)
37
+ - [Token shape](#token-shape)
38
+ - [What this release covers](#what-this-release-covers)
39
+ - [Safety](#safety)
40
+
14
41
  ## Why it exists
15
42
 
16
43
  Kinde's testing guides start with a test environment, a test user with a password, and a client ID and secret in `.env`. Every test then goes through a real sign-in. That works for a few smoke tests. It gets slow and hard to run in CI once you want to test what your app does with each kind of user, such as:
@@ -424,6 +451,31 @@ KINDE_ISSUER_URL=http://localhost:4400
424
451
 
425
452
  The SDK accepts a plain `http://localhost` issuer. Its login, callback, refresh, logout and session-ending routes all work against the testkit. Its `validateToken` accepts kinde-testkit tokens and rejects the wrong-issuer, tampered, unknown-key and unsigned kinds. It does not reject expired tokens, because the SDK handles expiry by refreshing the session.
426
453
 
454
+ ## Use with a coding agent
455
+
456
+ Every command takes `--json` and exits with code 1 when something fails. With `--json`, errors are one JSON object, `{ "error": { "code", "message", "details" } }`, so an agent can read the result and the reason without parsing text. A typical loop:
457
+
458
+ ```bash
459
+ npx kinde-testkit start --json & # prints the issuer URL and seed counts as JSON
460
+ npx kinde-testkit doctor --json # checks the app's .env against the issuer
461
+ npx kinde-testkit token --user admin@example.test --json
462
+ npx kinde-testkit inspect "$TOKEN" --json # explains why a token was rejected
463
+ npx kinde-testkit coverage --url http://localhost:4400 --json # lists the auth cases not tested yet
464
+ ```
465
+
466
+ Point the agent at three facts: the app's `KINDE_ISSUER_URL` must be the testkit's URL during tests, users and organizations come from `kinde-testkit.json` or `kinde-testkit.yaml`, and `kinde-testkit coverage` names the missing cases with the one-line change that tests each of them.
467
+
468
+ ## Checked against real Kinde
469
+
470
+ `test/contract` sends the same requests to a real Kinde business and to the testkit and fails on any field Kinde returns that the testkit does not: discovery endpoints, JWKS keys, M2M token claims, the Management API's error for a missing token, and the fields of users, organizations, roles and permissions. It only reads. Run it with an M2M app that has the `read:users`, `read:organizations`, `read:roles` and `read:permissions` scopes in a test business:
471
+
472
+ ```bash
473
+ KINDE_CONTRACT_DOMAIN=https://<your-business>.kinde.com \
474
+ KINDE_CONTRACT_CLIENT_ID=<client ID> \
475
+ KINDE_CONTRACT_CLIENT_SECRET=<client secret> \
476
+ npm run test:contract
477
+ ```
478
+
427
479
  ## Run the issuer from the command line
428
480
 
429
481
  ```bash
@@ -0,0 +1,183 @@
1
+ // src/inspect.ts
2
+ import { createRemoteJWKSet, decodeJwt, decodeProtectedHeader, jwtVerify } from "jose";
3
+ async function inspectToken(token, options = {}) {
4
+ const checks = [];
5
+ const trimmed = token.trim();
6
+ let header = null;
7
+ let payload = null;
8
+ if (trimmed.split(".").length !== 3) {
9
+ checks.push({ name: "Format", status: "fail", detail: "A JWT has three parts separated by dots." });
10
+ return { kind: "unknown", header, payload, checks };
11
+ }
12
+ try {
13
+ header = decodeProtectedHeader(trimmed);
14
+ payload = decodeJwt(trimmed);
15
+ } catch {
16
+ checks.push({ name: "Format", status: "fail", detail: "The header or payload is not valid base64url JSON." });
17
+ return { kind: "unknown", header, payload, checks };
18
+ }
19
+ checks.push({ name: "Format", status: "pass", detail: "Three base64url parts with JSON header and payload." });
20
+ checks.push(
21
+ header.alg === "RS256" ? { name: "Algorithm", status: "pass", detail: "RS256, the algorithm Kinde signs with." } : { name: "Algorithm", status: "fail", detail: `${String(header.alg)} is not RS256. Kinde tokens are always RS256.` }
22
+ );
23
+ const signer = typeof header.kid === "string" && header.kid.startsWith("kinde-testkit") ? "kinde-testkit" : "another issuer";
24
+ checks.push({ name: "Key", status: "pass", detail: `kid ${String(header.kid ?? "missing")} (${signer}).` });
25
+ const now = options.now ?? Math.floor(Date.now() / 1e3);
26
+ if (typeof payload.exp !== "number") {
27
+ checks.push({ name: "Expiry", status: "fail", detail: "No exp claim." });
28
+ } else if (payload.exp <= now) {
29
+ checks.push({ name: "Expiry", status: "fail", detail: `Expired ${formatSpan(now - payload.exp)} ago.` });
30
+ } else {
31
+ checks.push({ name: "Expiry", status: "pass", detail: `Expires in ${formatSpan(payload.exp - now)}.` });
32
+ }
33
+ if (typeof payload.iat === "number" && payload.iat > now + 60) {
34
+ checks.push({ name: "Issued at", status: "fail", detail: `iat is ${formatSpan(payload.iat - now)} in the future.` });
35
+ }
36
+ if (options.issuerUrl) {
37
+ const issuer = options.issuerUrl.replace(/\/+$/, "");
38
+ if (payload.iss !== issuer) {
39
+ checks.push({ name: "Issuer", status: "fail", detail: `iss is ${String(payload.iss)}, not ${issuer}.` });
40
+ } else {
41
+ checks.push({ name: "Issuer", status: "pass", detail: `Issued by ${issuer}.` });
42
+ }
43
+ try {
44
+ await jwtVerify(trimmed, createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`)), { algorithms: ["RS256"] });
45
+ checks.push({ name: "Signature", status: "pass", detail: `Verified against ${issuer}/.well-known/jwks.json.` });
46
+ } catch (error) {
47
+ const code = error.code ?? "";
48
+ if (code === "ERR_JWT_EXPIRED" || code === "ERR_JWT_CLAIM_VALIDATION_FAILED") {
49
+ checks.push({ name: "Signature", status: "pass", detail: `Verified against ${issuer}/.well-known/jwks.json.` });
50
+ } else {
51
+ checks.push({ name: "Signature", status: "fail", detail: describeVerifyError(code, issuer) });
52
+ }
53
+ }
54
+ } else {
55
+ checks.push({ name: "Signature", status: "warn", detail: "Not checked. Pass --url to verify against a running issuer." });
56
+ }
57
+ return { kind: kindOf(payload), header, payload, checks };
58
+ }
59
+ function kindOf(payload) {
60
+ if (Array.isArray(payload.gty) && payload.gty.includes("client_credentials")) return "m2m";
61
+ if ("email" in payload || "org_codes" in payload || "at_hash" in payload || "nonce" in payload) return "id";
62
+ if ("scp" in payload || "permissions" in payload || "org_code" in payload) return "access";
63
+ return "unknown";
64
+ }
65
+ function describeVerifyError(code, issuer) {
66
+ if (code === "ERR_JWKS_NO_MATCHING_KEY") return `No key in ${issuer}'s JWKS matches this token's kid.`;
67
+ if (code === "ERR_JWS_SIGNATURE_VERIFICATION_FAILED") return "The signature does not match the token. It was changed after signing.";
68
+ if (code === "ERR_JOSE_ALG_NOT_ALLOWED" || code === "ERR_JOSE_NOT_SUPPORTED") return "The token is not signed with RS256.";
69
+ if (code === "ERR_JWKS_TIMEOUT" || code === "ERR_JOSE_GENERIC") return `Could not fetch keys from ${issuer}.`;
70
+ return `Verification failed (${code || "unknown error"}).`;
71
+ }
72
+ function formatSpan(seconds) {
73
+ const s = Math.max(0, Math.round(seconds));
74
+ if (s < 60) return `${s}s`;
75
+ if (s < 3600) return `${Math.floor(s / 60)}m ${s % 60}s`;
76
+ if (s < 86400) return `${Math.floor(s / 3600)}h ${Math.floor(s % 3600 / 60)}m`;
77
+ return `${Math.floor(s / 86400)}d ${Math.floor(s % 86400 / 3600)}h`;
78
+ }
79
+
80
+ // src/doctor.ts
81
+ var SECRET_FORMAT = /^[a-zA-Z0-9]{40,60}$/;
82
+ async function runDoctor(options) {
83
+ const url = options.url.replace(/\/+$/, "");
84
+ const checks = [];
85
+ let issuer = null;
86
+ try {
87
+ const health = await (await fetch(`${url}/testkit/health`)).json();
88
+ issuer = health.issuer ?? null;
89
+ checks.push({ name: "Issuer running", status: "pass", detail: `${url} answers, issuer ${issuer}.` });
90
+ } catch {
91
+ checks.push({ name: "Issuer running", status: "fail", detail: `Nothing answers at ${url}. Start it with "kinde-testkit start".` });
92
+ }
93
+ if (issuer) {
94
+ try {
95
+ const discovery = await (await fetch(`${url}/.well-known/openid-configuration`)).json();
96
+ checks.push(
97
+ discovery.issuer === issuer ? { name: "Discovery", status: "pass", detail: "The discovery document names the same issuer." } : { name: "Discovery", status: "fail", detail: `Discovery says ${String(discovery.issuer)}, health says ${issuer}.` }
98
+ );
99
+ } catch {
100
+ checks.push({ name: "Discovery", status: "fail", detail: "Could not read /.well-known/openid-configuration." });
101
+ }
102
+ try {
103
+ const jwks = await (await fetch(`${url}/.well-known/jwks.json`)).json();
104
+ const usable = (jwks.keys ?? []).filter((key) => key.kty === "RSA" && key.use === "sig");
105
+ checks.push(
106
+ usable.length > 0 ? { name: "JWKS", status: "pass", detail: `${usable.length} RS256 signing key at /.well-known/jwks.json.` } : { name: "JWKS", status: "fail", detail: "No RSA signing key at /.well-known/jwks.json." }
107
+ );
108
+ } catch {
109
+ checks.push({ name: "JWKS", status: "fail", detail: "Could not read /.well-known/jwks.json." });
110
+ }
111
+ try {
112
+ const users = await (await fetch(`${url}/testkit/users`)).json();
113
+ checks.push(
114
+ users.length > 0 ? { name: "Seed", status: "pass", detail: `${users.length} seeded ${users.length === 1 ? "user" : "users"}.` } : { name: "Seed", status: "warn", detail: "No seeded users. The sign-in page still accepts any email, but those users have no organization." }
115
+ );
116
+ } catch {
117
+ checks.push({ name: "Seed", status: "warn", detail: "Could not read /testkit/users." });
118
+ }
119
+ }
120
+ const env = options.env;
121
+ const configured = env.KINDE_ISSUER_URL?.trim().replace(/\/+$/, "");
122
+ if (!configured) {
123
+ checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: "Not set. Set it to the testkit's issuer for test runs." });
124
+ } else if (/\.kinde\.com$/i.test(new URL(configured, "http://x").hostname)) {
125
+ checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: `${configured} is a real Kinde domain. Tests would sign in against Kinde, not the testkit.` });
126
+ } else if (issuer && configured !== issuer) {
127
+ checks.push({ name: "KINDE_ISSUER_URL", status: "fail", detail: `${configured} does not match the testkit issuer ${issuer}. Token checks compare iss exactly.` });
128
+ } else {
129
+ checks.push({ name: "KINDE_ISSUER_URL", status: "pass", detail: `${configured}.` });
130
+ }
131
+ checks.push(
132
+ env.KINDE_CLIENT_ID ? { name: "KINDE_CLIENT_ID", status: "pass", detail: "Set. The testkit accepts any client ID." } : { name: "KINDE_CLIENT_ID", status: "fail", detail: "Not set. Kinde's SDKs refuse to start without it." }
133
+ );
134
+ const secret = env.KINDE_CLIENT_SECRET;
135
+ if (!secret) {
136
+ checks.push({ name: "KINDE_CLIENT_SECRET", status: "warn", detail: "Not set. Server-side SDKs, such as the Next.js SDK, need it." });
137
+ } else if (!SECRET_FORMAT.test(secret)) {
138
+ checks.push({ name: "KINDE_CLIENT_SECRET", status: "fail", detail: "The Next.js SDK only accepts 40 to 60 letters and digits." });
139
+ } else {
140
+ checks.push({ name: "KINDE_CLIENT_SECRET", status: "pass", detail: "Set, in the format Kinde's SDKs accept." });
141
+ }
142
+ if (issuer?.startsWith("https://")) {
143
+ checks.push(
144
+ env.NODE_EXTRA_CA_CERTS ? { name: "NODE_EXTRA_CA_CERTS", status: "pass", detail: `${env.NODE_EXTRA_CA_CERTS}.` } : {
145
+ name: "NODE_EXTRA_CA_CERTS",
146
+ status: "warn",
147
+ detail: "The testkit serves HTTPS with a local certificate. Start your app with NODE_EXTRA_CA_CERTS set to it, or Node will refuse the connection."
148
+ }
149
+ );
150
+ }
151
+ const site = env.KINDE_SITE_URL;
152
+ if (!site) {
153
+ checks.push({ name: "KINDE_SITE_URL", status: "warn", detail: "Not set. The Next.js SDK builds its callback URL from it." });
154
+ } else if (!/^https?:\/\//.test(site)) {
155
+ checks.push({ name: "KINDE_SITE_URL", status: "fail", detail: `${site} is not an http or https URL.` });
156
+ } else {
157
+ checks.push({ name: "KINDE_SITE_URL", status: "pass", detail: `${site}.` });
158
+ }
159
+ return { url, checks, ok: checks.every((check) => check.status !== "fail") };
160
+ }
161
+ function parseEnvFile(text) {
162
+ const values = {};
163
+ for (const line of text.split(/\r?\n/)) {
164
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/.exec(line);
165
+ if (!match) continue;
166
+ let value = match[2];
167
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
168
+ value = value.slice(1, -1);
169
+ } else {
170
+ value = value.replace(/\s+#.*$/, "");
171
+ }
172
+ values[match[1]] = value;
173
+ }
174
+ return values;
175
+ }
176
+
177
+ export {
178
+ inspectToken,
179
+ formatSpan,
180
+ runDoctor,
181
+ parseEnvFile
182
+ };
183
+ //# sourceMappingURL=chunk-33AHOLUN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/inspect.ts","../src/doctor.ts"],"sourcesContent":["import { createRemoteJWKSet, decodeJwt, decodeProtectedHeader, jwtVerify, type JWTPayload, type ProtectedHeaderParameters } from \"jose\";\n\nexport type CheckStatus = \"pass\" | \"warn\" | \"fail\";\n\nexport interface Check {\n name: string;\n status: CheckStatus;\n detail: string;\n}\n\nexport interface TokenInspection {\n kind: \"access\" | \"id\" | \"m2m\" | \"unknown\";\n header: ProtectedHeaderParameters | null;\n payload: JWTPayload | null;\n checks: Check[];\n}\n\nexport async function inspectToken(\n token: string,\n options: { issuerUrl?: string; now?: number } = {},\n): Promise<TokenInspection> {\n const checks: Check[] = [];\n const trimmed = token.trim();\n let header: ProtectedHeaderParameters | null = null;\n let payload: JWTPayload | null = null;\n\n if (trimmed.split(\".\").length !== 3) {\n checks.push({ name: \"Format\", status: \"fail\", detail: \"A JWT has three parts separated by dots.\" });\n return { kind: \"unknown\", header, payload, checks };\n }\n try {\n header = decodeProtectedHeader(trimmed);\n payload = decodeJwt(trimmed);\n } catch {\n checks.push({ name: \"Format\", status: \"fail\", detail: \"The header or payload is not valid base64url JSON.\" });\n return { kind: \"unknown\", header, payload, checks };\n }\n checks.push({ name: \"Format\", status: \"pass\", detail: \"Three base64url parts with JSON header and payload.\" });\n\n checks.push(\n header.alg === \"RS256\"\n ? { name: \"Algorithm\", status: \"pass\", detail: \"RS256, the algorithm Kinde signs with.\" }\n : { name: \"Algorithm\", status: \"fail\", detail: `${String(header.alg)} is not RS256. Kinde tokens are always RS256.` },\n );\n\n const signer = typeof header.kid === \"string\" && header.kid.startsWith(\"kinde-testkit\") ? \"kinde-testkit\" : \"another issuer\";\n checks.push({ name: \"Key\", status: \"pass\", detail: `kid ${String(header.kid ?? \"missing\")} (${signer}).` });\n\n const now = options.now ?? Math.floor(Date.now() / 1000);\n if (typeof payload.exp !== \"number\") {\n checks.push({ name: \"Expiry\", status: \"fail\", detail: \"No exp claim.\" });\n } else if (payload.exp <= now) {\n checks.push({ name: \"Expiry\", status: \"fail\", detail: `Expired ${formatSpan(now - payload.exp)} ago.` });\n } else {\n checks.push({ name: \"Expiry\", status: \"pass\", detail: `Expires in ${formatSpan(payload.exp - now)}.` });\n }\n if (typeof payload.iat === \"number\" && payload.iat > now + 60) {\n checks.push({ name: \"Issued at\", status: \"fail\", detail: `iat is ${formatSpan(payload.iat - now)} in the future.` });\n }\n\n if (options.issuerUrl) {\n const issuer = options.issuerUrl.replace(/\\/+$/, \"\");\n if (payload.iss !== issuer) {\n checks.push({ name: \"Issuer\", status: \"fail\", detail: `iss is ${String(payload.iss)}, not ${issuer}.` });\n } else {\n checks.push({ name: \"Issuer\", status: \"pass\", detail: `Issued by ${issuer}.` });\n }\n try {\n await jwtVerify(trimmed, createRemoteJWKSet(new URL(`${issuer}/.well-known/jwks.json`)), { algorithms: [\"RS256\"] });\n checks.push({ name: \"Signature\", status: \"pass\", detail: `Verified against ${issuer}/.well-known/jwks.json.` });\n } catch (error) {\n const code = (error as { code?: string }).code ?? \"\";\n if (code === \"ERR_JWT_EXPIRED\" || code === \"ERR_JWT_CLAIM_VALIDATION_FAILED\") {\n checks.push({ name: \"Signature\", status: \"pass\", detail: `Verified against ${issuer}/.well-known/jwks.json.` });\n } else {\n checks.push({ name: \"Signature\", status: \"fail\", detail: describeVerifyError(code, issuer) });\n }\n }\n } else {\n checks.push({ name: \"Signature\", status: \"warn\", detail: \"Not checked. Pass --url to verify against a running issuer.\" });\n }\n\n return { kind: kindOf(payload), header, payload, checks };\n}\n\nfunction kindOf(payload: JWTPayload): TokenInspection[\"kind\"] {\n if (Array.isArray(payload.gty) && payload.gty.includes(\"client_credentials\")) return \"m2m\";\n if (\"email\" in payload || \"org_codes\" in payload || \"at_hash\" in payload || \"nonce\" in payload) return \"id\";\n if (\"scp\" in payload || \"permissions\" in payload || \"org_code\" in payload) return \"access\";\n return \"unknown\";\n}\n\nfunction describeVerifyError(code: string, issuer: string): string {\n if (code === \"ERR_JWKS_NO_MATCHING_KEY\") return `No key in ${issuer}'s JWKS matches this token's kid.`;\n if (code === \"ERR_JWS_SIGNATURE_VERIFICATION_FAILED\") return \"The signature does not match the token. It was changed after signing.\";\n if (code === \"ERR_JOSE_ALG_NOT_ALLOWED\" || code === \"ERR_JOSE_NOT_SUPPORTED\") return \"The token is not signed with RS256.\";\n if (code === \"ERR_JWKS_TIMEOUT\" || code === \"ERR_JOSE_GENERIC\") return `Could not fetch keys from ${issuer}.`;\n return `Verification failed (${code || \"unknown error\"}).`;\n}\n\nexport function formatSpan(seconds: number): string {\n const s = Math.max(0, Math.round(seconds));\n if (s < 60) return `${s}s`;\n if (s < 3600) return `${Math.floor(s / 60)}m ${s % 60}s`;\n if (s < 86400) return `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m`;\n return `${Math.floor(s / 86400)}d ${Math.floor((s % 86400) / 3600)}h`;\n}\n","import type { Check } from \"./inspect.js\";\n\nconst SECRET_FORMAT = /^[a-zA-Z0-9]{40,60}$/;\n\nexport interface DoctorReport {\n url: string;\n checks: Check[];\n ok: boolean;\n}\n\nexport async function runDoctor(options: { url: string; env: Record<string, string | undefined> }): Promise<DoctorReport> {\n const url = options.url.replace(/\\/+$/, \"\");\n const checks: Check[] = [];\n let issuer: string | null = null;\n\n try {\n const health = (await (await fetch(`${url}/testkit/health`)).json()) as { issuer?: string };\n issuer = health.issuer ?? null;\n checks.push({ name: \"Issuer running\", status: \"pass\", detail: `${url} answers, issuer ${issuer}.` });\n } catch {\n checks.push({ name: \"Issuer running\", status: \"fail\", detail: `Nothing answers at ${url}. Start it with \"kinde-testkit start\".` });\n }\n\n if (issuer) {\n try {\n const discovery = (await (await fetch(`${url}/.well-known/openid-configuration`)).json()) as { issuer?: string };\n checks.push(\n discovery.issuer === issuer\n ? { name: \"Discovery\", status: \"pass\", detail: \"The discovery document names the same issuer.\" }\n : { name: \"Discovery\", status: \"fail\", detail: `Discovery says ${String(discovery.issuer)}, health says ${issuer}.` },\n );\n } catch {\n checks.push({ name: \"Discovery\", status: \"fail\", detail: \"Could not read /.well-known/openid-configuration.\" });\n }\n try {\n const jwks = (await (await fetch(`${url}/.well-known/jwks.json`)).json()) as { keys?: Array<{ kty?: string; use?: string }> };\n const usable = (jwks.keys ?? []).filter((key) => key.kty === \"RSA\" && key.use === \"sig\");\n checks.push(\n usable.length > 0\n ? { name: \"JWKS\", status: \"pass\", detail: `${usable.length} RS256 signing key at /.well-known/jwks.json.` }\n : { name: \"JWKS\", status: \"fail\", detail: \"No RSA signing key at /.well-known/jwks.json.\" },\n );\n } catch {\n checks.push({ name: \"JWKS\", status: \"fail\", detail: \"Could not read /.well-known/jwks.json.\" });\n }\n try {\n const users = (await (await fetch(`${url}/testkit/users`)).json()) as unknown[];\n checks.push(\n users.length > 0\n ? { name: \"Seed\", status: \"pass\", detail: `${users.length} seeded ${users.length === 1 ? \"user\" : \"users\"}.` }\n : { name: \"Seed\", status: \"warn\", detail: \"No seeded users. The sign-in page still accepts any email, but those users have no organization.\" },\n );\n } catch {\n checks.push({ name: \"Seed\", status: \"warn\", detail: \"Could not read /testkit/users.\" });\n }\n }\n\n const env = options.env;\n const configured = env.KINDE_ISSUER_URL?.trim().replace(/\\/+$/, \"\");\n if (!configured) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: \"Not set. Set it to the testkit's issuer for test runs.\" });\n } else if (/\\.kinde\\.com$/i.test(new URL(configured, \"http://x\").hostname)) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: `${configured} is a real Kinde domain. Tests would sign in against Kinde, not the testkit.` });\n } else if (issuer && configured !== issuer) {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"fail\", detail: `${configured} does not match the testkit issuer ${issuer}. Token checks compare iss exactly.` });\n } else {\n checks.push({ name: \"KINDE_ISSUER_URL\", status: \"pass\", detail: `${configured}.` });\n }\n\n checks.push(\n env.KINDE_CLIENT_ID\n ? { name: \"KINDE_CLIENT_ID\", status: \"pass\", detail: \"Set. The testkit accepts any client ID.\" }\n : { name: \"KINDE_CLIENT_ID\", status: \"fail\", detail: \"Not set. Kinde's SDKs refuse to start without it.\" },\n );\n\n const secret = env.KINDE_CLIENT_SECRET;\n if (!secret) {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"warn\", detail: \"Not set. Server-side SDKs, such as the Next.js SDK, need it.\" });\n } else if (!SECRET_FORMAT.test(secret)) {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"fail\", detail: \"The Next.js SDK only accepts 40 to 60 letters and digits.\" });\n } else {\n checks.push({ name: \"KINDE_CLIENT_SECRET\", status: \"pass\", detail: \"Set, in the format Kinde's SDKs accept.\" });\n }\n\n if (issuer?.startsWith(\"https://\")) {\n checks.push(\n env.NODE_EXTRA_CA_CERTS\n ? { name: \"NODE_EXTRA_CA_CERTS\", status: \"pass\", detail: `${env.NODE_EXTRA_CA_CERTS}.` }\n : {\n name: \"NODE_EXTRA_CA_CERTS\",\n status: \"warn\",\n detail: \"The testkit serves HTTPS with a local certificate. Start your app with NODE_EXTRA_CA_CERTS set to it, or Node will refuse the connection.\",\n },\n );\n }\n\n const site = env.KINDE_SITE_URL;\n if (!site) {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"warn\", detail: \"Not set. The Next.js SDK builds its callback URL from it.\" });\n } else if (!/^https?:\\/\\//.test(site)) {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"fail\", detail: `${site} is not an http or https URL.` });\n } else {\n checks.push({ name: \"KINDE_SITE_URL\", status: \"pass\", detail: `${site}.` });\n }\n\n return { url, checks, ok: checks.every((check) => check.status !== \"fail\") };\n}\n\nexport function parseEnvFile(text: string): Record<string, string> {\n const values: Record<string, string> = {};\n for (const line of text.split(/\\r?\\n/)) {\n const match = /^\\s*(?:export\\s+)?([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*(.*)\\s*$/.exec(line);\n if (!match) continue;\n let value = match[2]!;\n if ((value.startsWith('\"') && value.endsWith('\"')) || (value.startsWith(\"'\") && value.endsWith(\"'\"))) {\n value = value.slice(1, -1);\n } else {\n value = value.replace(/\\s+#.*$/, \"\");\n }\n values[match[1]!] = value;\n }\n return values;\n}\n"],"mappings":";AAAA,SAAS,oBAAoB,WAAW,uBAAuB,iBAAkE;AAiBjI,eAAsB,aACpB,OACA,UAAgD,CAAC,GACvB;AAC1B,QAAM,SAAkB,CAAC;AACzB,QAAM,UAAU,MAAM,KAAK;AAC3B,MAAI,SAA2C;AAC/C,MAAI,UAA6B;AAEjC,MAAI,QAAQ,MAAM,GAAG,EAAE,WAAW,GAAG;AACnC,WAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,2CAA2C,CAAC;AAClG,WAAO,EAAE,MAAM,WAAW,QAAQ,SAAS,OAAO;AAAA,EACpD;AACA,MAAI;AACF,aAAS,sBAAsB,OAAO;AACtC,cAAU,UAAU,OAAO;AAAA,EAC7B,QAAQ;AACN,WAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,qDAAqD,CAAC;AAC5G,WAAO,EAAE,MAAM,WAAW,QAAQ,SAAS,OAAO;AAAA,EACpD;AACA,SAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,QAAQ,QAAQ,sDAAsD,CAAC;AAE7G,SAAO;AAAA,IACL,OAAO,QAAQ,UACX,EAAE,MAAM,aAAa,QAAQ,QAAQ,QAAQ,yCAAyC,IACtF,EAAE,MAAM,aAAa,QAAQ,QAAQ,QAAQ,GAAG,OAAO,OAAO,GAAG,CAAC,gDAAgD;AAAA,EACxH;AAEA,QAAM,SAAS,OAAO,OAAO,QAAQ,YAAY,OAAO,IAAI,WAAW,eAAe,IAAI,kBAAkB;AAC5G,SAAO,KAAK,EAAE,MAAM,OA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