kinde-testkit 0.7.0 → 0.8.0

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +97 -9
  3. package/dist/chunk-BPPG4G52.js +427 -0
  4. package/dist/chunk-BPPG4G52.js.map +1 -0
  5. package/dist/{chunk-JTAB2S44.js → chunk-CY75AADD.js} +175 -454
  6. package/dist/chunk-CY75AADD.js.map +1 -0
  7. package/dist/chunk-EZUKOKNO.js +48 -0
  8. package/dist/chunk-EZUKOKNO.js.map +1 -0
  9. package/dist/{chunk-2QJ7DTNL.js → chunk-YJPE5HAM.js} +5 -3
  10. package/dist/{chunk-2QJ7DTNL.js.map → chunk-YJPE5HAM.js.map} +1 -1
  11. package/dist/cli.js +8 -2
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cypress-support.d.ts +142 -0
  14. package/dist/cypress-support.js +21 -6
  15. package/dist/cypress-support.js.map +1 -1
  16. package/dist/cypress.cjs +142 -14
  17. package/dist/cypress.d.cts +1 -1
  18. package/dist/cypress.d.ts +3 -2
  19. package/dist/cypress.js +2 -1
  20. package/dist/cypress.js.map +1 -1
  21. package/dist/{handle-estfqypp.d.cts → handle-DRPxm36j.d.cts} +1 -1
  22. package/dist/{handle-E_BhdHx8.d.ts → handle-Pjt9fSUq.d.ts} +3 -2
  23. package/dist/index.cjs +145 -14
  24. package/dist/index.d.cts +17 -4
  25. package/dist/index.d.ts +8 -26
  26. package/dist/index.js +27 -51
  27. package/dist/index.js.map +1 -1
  28. package/dist/jest.cjs +142 -14
  29. package/dist/jest.d.cts +3 -3
  30. package/dist/jest.d.ts +5 -4
  31. package/dist/jest.js +3 -2
  32. package/dist/jest.js.map +1 -1
  33. package/dist/playwright.d.ts +12 -3
  34. package/dist/playwright.js +30 -0
  35. package/dist/playwright.js.map +1 -1
  36. package/dist/react.d.ts +43 -0
  37. package/dist/react.js +110 -0
  38. package/dist/react.js.map +1 -0
  39. package/dist/{server-CTBJXMac.d.cts → server-CLRn67qI.d.cts} +26 -0
  40. package/dist/{server-B9fBcnyQ.d.ts → server-CuHAHsaN.d.ts} +3 -56
  41. package/dist/sign-in-flow-DNrDXSLI.d.ts +35 -0
  42. package/dist/testkit-BvCAFsSj.d.ts +156 -0
  43. package/dist/vitest.d.ts +5 -4
  44. package/dist/vitest.js +3 -2
  45. package/dist/vitest.js.map +1 -1
  46. package/dist/{webhooks-DJyCsbdF.d.ts → webhooks-CiK9_pVw.d.ts} +82 -155
  47. package/package.json +30 -3
  48. package/dist/chunk-JTAB2S44.js.map +0 -1
@@ -1,157 +1,4 @@
1
- import { JWTPayload, JWK } from 'jose';
2
-
3
- interface KindeUser {
4
- id: string;
5
- email: string | null;
6
- emailVerified: boolean;
7
- givenName: string | null;
8
- familyName: string | null;
9
- picture: string | null;
10
- claims: Record<string, unknown>;
11
- }
12
- interface KindeOrganization {
13
- code: string;
14
- name: string;
15
- metadata: Record<string, unknown>;
16
- }
17
- interface KindeRole {
18
- id: string;
19
- key: string;
20
- name: string;
21
- }
22
- interface KindeApplication {
23
- clientId: string;
24
- clientSecret: string | null;
25
- name: string;
26
- organizationCode: string | null;
27
- scopes: string[] | null;
28
- permissions: string[] | null;
29
- audience: string[] | null;
30
- }
31
- interface KindeMembership {
32
- userId: string;
33
- organizationCode: string;
34
- roles: string[];
35
- permissions: string[];
36
- }
37
- interface AuthenticatedScenario {
38
- kind: "authenticated";
39
- user: KindeUser;
40
- organization: KindeOrganization | null;
41
- roles: string[];
42
- permissions: string[];
43
- claims: Record<string, unknown>;
44
- }
45
- interface UnauthenticatedScenario {
46
- kind: "unauthenticated";
47
- }
48
- type Scenario = AuthenticatedScenario | UnauthenticatedScenario;
49
- interface KindePrincipal {
50
- type: "user" | "machine";
51
- subject: string;
52
- issuer: string;
53
- organization: {
54
- code: string;
55
- } | null;
56
- roles: string[];
57
- permissions: string[];
58
- claims: Record<string, unknown>;
59
- }
60
- type InvalidTokenKind = "expired" | "wrong-issuer" | "wrong-audience" | "missing-subject" | "missing-organization" | "missing-permissions" | "future-iat" | "bad-signature" | "unknown-key" | "unsigned";
61
- type Duration = number | `${number}${"s" | "m" | "h" | "d"}`;
62
- interface KindeTokenOptions {
63
- subject?: string;
64
- organizationCode?: string | null;
65
- permissions?: string[];
66
- roles?: Array<string | KindeRole>;
67
- scopes?: string[];
68
- featureFlags?: Record<string, {
69
- t: "b" | "s" | "i";
70
- v: boolean | string | number;
71
- }>;
72
- claims?: Record<string, unknown>;
73
- authMethods?: string[];
74
- authTime?: number;
75
- clientId?: string;
76
- audience?: string[];
77
- expiresIn?: Duration;
78
- invalid?: InvalidTokenKind;
79
- }
80
-
81
- declare const DEFAULT_ISSUER = "http://localhost:4400";
82
- declare const DEFAULT_CLIENT_ID = "kinde_testkit_client";
83
- declare const DEFAULT_M2M_CLIENT_ID = "kinde_testkit_m2m";
84
- declare const DEFAULT_SCOPES: string[];
85
- declare const DEFAULT_AUTH_METHODS: string[];
86
- declare const INVALID_TOKEN_KINDS: readonly InvalidTokenKind[];
87
- interface KindeTestkitOptions {
88
- issuer?: string;
89
- audience?: string | string[];
90
- clientId?: string;
91
- accessTokenExpiresIn?: Duration;
92
- idTokenExpiresIn?: Duration;
93
- now?: () => number;
94
- }
95
- type ScenarioTokenOverrides = Pick<KindeTokenOptions, "expiresIn" | "invalid" | "scopes" | "featureFlags" | "claims" | "authMethods" | "authTime" | "clientId" | "audience">;
96
- interface M2MTokenOptions {
97
- clientId?: string;
98
- organizationCode?: string | null;
99
- scopes?: string[];
100
- grantedScopes?: string[];
101
- audience?: string[];
102
- permissions?: string[];
103
- claims?: Record<string, unknown>;
104
- expiresIn?: Duration;
105
- invalid?: InvalidTokenKind;
106
- }
107
- interface IdTokenOptions {
108
- expiresIn?: Duration;
109
- authMethods?: string[];
110
- authTime?: number;
111
- clientId?: string;
112
- nonce?: string;
113
- }
114
- /** Receives every token the testkit signs, for coverage and the dashboard. */
115
- interface TokenObserver {
116
- accessToken?(payload: Record<string, unknown>, invalid: InvalidTokenKind | undefined, token: string): void;
117
- idToken?(payload: Record<string, unknown>, token: string): void;
118
- anonymous?(): void;
119
- }
120
- declare class KindeTestkit {
121
- private observers;
122
- /** Calls the observer for every token signed from now on. Returns a function that stops it. */
123
- observe(observer: TokenObserver): () => void;
124
- private signAccess;
125
- readonly issuer: string;
126
- readonly audience: string[];
127
- readonly clientId: string;
128
- private readonly accessTokenExpiresIn;
129
- private readonly idTokenExpiresIn;
130
- private readonly clock;
131
- private readonly signingKey;
132
- private strangerKey;
133
- static create(options?: KindeTestkitOptions): Promise<KindeTestkit>;
134
- private constructor();
135
- get jwksUri(): string;
136
- get keyId(): string;
137
- get accessTokenLifetime(): number;
138
- verify(token: string): Promise<JWTPayload>;
139
- jwks(): {
140
- keys: JWK[];
141
- };
142
- token(options?: KindeTokenOptions): Promise<string>;
143
- m2mToken(options?: M2MTokenOptions): Promise<string>;
144
- tokenFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<string | null>;
145
- idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
146
- headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
147
- principalFor(scenario: Scenario): KindePrincipal | null;
148
- signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
149
- private sign;
150
- private stranger;
151
- }
152
- declare function principalFromClaims(claims: Record<string, unknown>): KindePrincipal;
153
- declare function getDefaultTestkit(): Promise<KindeTestkit>;
154
- declare function createKindeToken(options?: KindeTokenOptions): Promise<string>;
1
+ import { a as KindeUser, K as KindeOrganization, b as KindeMembership, k as KindeApplication, A as AuthenticatedScenario, m as KindeTestkit } from './testkit-BvCAFsSj.js';
155
2
 
156
3
  interface TestkitSeed {
157
4
  issuer?: string;
@@ -284,6 +131,82 @@ declare function seedScenario(seed: ResolvedSeed, ref: {
284
131
  organization?: string | null;
285
132
  }): AuthenticatedScenario;
286
133
 
134
+ interface UserMeta {
135
+ providedId: string | null;
136
+ isSuspended: boolean;
137
+ isPasswordResetRequested: boolean;
138
+ createdOn: string;
139
+ totalSignIns: number;
140
+ lastSignedIn: string | null;
141
+ /** Last sign-in time per organization code. */
142
+ lastOrganizationSignIns: Record<string, string>;
143
+ }
144
+ /** An identity for authenticateAs(). */
145
+ interface Identity {
146
+ email: string;
147
+ givenName?: string | null;
148
+ familyName?: string | null;
149
+ /** The organization code. Created when it does not exist. */
150
+ organization?: string | null;
151
+ organizationName?: string;
152
+ roles?: string[];
153
+ permissions?: string[];
154
+ }
155
+ interface OrganizationMeta {
156
+ externalId: string | null;
157
+ handle: string;
158
+ createdOn: string;
159
+ isAllowRegistrations: boolean;
160
+ }
161
+ declare class Directory {
162
+ readonly seed: ResolvedSeed;
163
+ private readonly userMeta;
164
+ private readonly orgMeta;
165
+ private snapshot;
166
+ constructor(seed: ResolvedSeed);
167
+ restore(): void;
168
+ /** Replaces the whole seed with another resolved seed, and makes it the state reset() returns to. */
169
+ load(next: ResolvedSeed): void;
170
+ user(id: string): KindeUser | undefined;
171
+ meta(user: KindeUser): UserMeta;
172
+ isSuspended(userId: string): boolean;
173
+ recordSignIn(user: KindeUser, organizationCode: string | null): void;
174
+ createUser(input: {
175
+ email?: string | null;
176
+ givenName?: string | null;
177
+ familyName?: string | null;
178
+ picture?: string | null;
179
+ providedId?: string | null;
180
+ }): KindeUser;
181
+ deleteUser(id: string): boolean;
182
+ organization(code: string): KindeOrganization | undefined;
183
+ orgInfo(org: KindeOrganization): OrganizationMeta;
184
+ createOrganization(input: {
185
+ name: string;
186
+ externalId?: string | null;
187
+ handle?: string | null;
188
+ }): KindeOrganization;
189
+ deleteOrganization(code: string): boolean;
190
+ membership(userId: string, organizationCode: string): KindeMembership | undefined;
191
+ addMembership(userId: string, organizationCode: string, roles?: string[], permissions?: string[]): KindeMembership;
192
+ /**
193
+ * Makes sure a user exists with exactly these roles and permissions in the organization, creating
194
+ * the user, organization and membership when they are missing. Used by authenticateAs() in browser
195
+ * tests, so a test can sign in as any identity without adding it to the seed. reset() removes it.
196
+ */
197
+ ensureIdentity(input: Identity): {
198
+ user: KindeUser;
199
+ organization: KindeOrganization | null;
200
+ };
201
+ removeMembership(userId: string, organizationCode: string): boolean;
202
+ role(idOrKey: string): SeedRole | undefined;
203
+ permission(idOrKey: string): SeedPermission | undefined;
204
+ ensureRole(key: string, extra?: Partial<Omit<SeedRole, "id" | "key">>): SeedRole;
205
+ ensurePermission(key: string, extra?: Partial<Omit<SeedPermission, "id" | "key">>): SeedPermission;
206
+ deleteRole(id: string): SeedRole | undefined;
207
+ deletePermission(id: string): SeedPermission | undefined;
208
+ }
209
+
287
210
  interface FailureRule {
288
211
  path: string;
289
212
  method?: string;
@@ -292,7 +215,10 @@ interface FailureRule {
292
215
  hang?: boolean;
293
216
  times?: number;
294
217
  retryAfter?: number;
218
+ /** Answer with a body your client cannot use. The status is 200 unless you set one. */
219
+ malformed?: MalformedKind;
295
220
  }
221
+ type MalformedKind = "invalid-json" | "empty" | "html" | "unexpected-json";
296
222
  interface ActiveFailure {
297
223
  id: string;
298
224
  path: string;
@@ -302,6 +228,7 @@ interface ActiveFailure {
302
228
  hang: boolean;
303
229
  remaining: number | null;
304
230
  retryAfter: number;
231
+ malformed: MalformedKind | null;
305
232
  hits: number;
306
233
  }
307
234
  declare class FailureInjector {
@@ -394,4 +321,4 @@ declare class WebhookDispatcher {
394
321
  private requireUser;
395
322
  }
396
323
 
397
- export { type AuthenticatedScenario as A, BILLING_EVENT_TYPES as B, type WebhookOptions as C, DEFAULT_AUTH_METHODS as D, type WebhookSource as E, FailureInjector as F, createKindeToken as G, getDefaultTestkit as H, INVALID_TOKEN_KINDS as I, principalFromClaims as J, type KindeOrganization as K, resolveSeed as L, type M2MTokenOptions as M, seedScenario as N, type SeedRole as O, type SeedPermission as P, type ResolvedSeed as R, type Scenario as S, type TestkitSeed as T, type UnauthenticatedScenario as U, WEBHOOK_EVENT_TYPES as W, type KindeUser as a, type KindeMembership as b, type KindeRole as c, type ActiveFailure as d, DEFAULT_CLIENT_ID as e, DEFAULT_ISSUER as f, DEFAULT_M2M_CLIENT_ID as g, DEFAULT_SCOPES as h, type Duration as i, type FailureRule as j, type IdTokenOptions as k, type InvalidTokenKind as l, type KindeApplication as m, type KindePrincipal as n, KindeTestkit as o, type KindeTestkitOptions as p, type KindeTokenOptions as q, type ScenarioTokenOverrides as r, type SendWebhookOptions as s, type TokenObserver as t, type WebhookAttempt as u, type WebhookDelivery as v, WebhookDispatcher as w, type WebhookEndpoint as x, type WebhookEndpointInput as y, type WebhookInvalidKind as z };
324
+ export { type ActiveFailure as A, BILLING_EVENT_TYPES as B, Directory as D, FailureInjector as F, type Identity as I, type ResolvedSeed as R, type SendWebhookOptions as S, type TestkitSeed as T, WEBHOOK_EVENT_TYPES as W, type FailureRule as a, type WebhookAttempt as b, type WebhookDelivery as c, WebhookDispatcher as d, type WebhookEndpoint as e, type WebhookEndpointInput as f, type WebhookInvalidKind as g, type WebhookOptions as h, type WebhookSource as i, resolveSeed as r, seedScenario as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kinde-testkit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Test Kinde-authenticated apps offline: a local issuer with a real sign-in flow, Kinde-shaped tokens, reusable auth scenarios, and Vitest and Playwright helpers.",
5
5
  "license": "MIT",
6
6
  "author": "Shola Jegede <jegedeshola@gmail.com>",
@@ -20,7 +20,8 @@
20
20
  "oauth",
21
21
  "jest",
22
22
  "cypress",
23
- "emulator"
23
+ "emulator",
24
+ "react-testing-library"
24
25
  ],
25
26
  "type": "module",
26
27
  "engines": {
@@ -71,6 +72,12 @@
71
72
  "default": "./dist/playwright.js"
72
73
  }
73
74
  },
75
+ "./react": {
76
+ "import": {
77
+ "types": "./dist/react.d.ts",
78
+ "default": "./dist/react.js"
79
+ }
80
+ },
74
81
  "./cypress": {
75
82
  "import": {
76
83
  "types": "./dist/cypress.d.ts",
@@ -90,7 +97,7 @@
90
97
  "./package.json": "./package.json"
91
98
  },
92
99
  "scripts": {
93
- "build": "tsup",
100
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsup && node test/check-exports.mjs",
94
101
  "typecheck": "tsc --noEmit",
95
102
  "test": "vitest run",
96
103
  "test:watch": "vitest",
@@ -102,7 +109,10 @@
102
109
  "yaml": "^2.9.1"
103
110
  },
104
111
  "peerDependencies": {
112
+ "@kinde-oss/kinde-auth-react": ">=5",
113
+ "@kinde/js-utils": ">=0.30",
105
114
  "@playwright/test": ">=1.40",
115
+ "react": ">=18",
106
116
  "vitest": ">=2"
107
117
  },
108
118
  "peerDependenciesMeta": {
@@ -111,16 +121,33 @@
111
121
  },
112
122
  "@playwright/test": {
113
123
  "optional": true
124
+ },
125
+ "react": {
126
+ "optional": true
127
+ },
128
+ "@kinde-oss/kinde-auth-react": {
129
+ "optional": true
130
+ },
131
+ "@kinde/js-utils": {
132
+ "optional": true
114
133
  }
115
134
  },
116
135
  "devDependencies": {
136
+ "@kinde-oss/kinde-auth-nextjs": "^2.13.2",
137
+ "@kinde-oss/kinde-auth-react": "^5.13.2",
117
138
  "@kinde/js-utils": "^0.32.2",
118
139
  "@kinde/jwt-validator": "^0.5.0",
119
140
  "@kinde/management-api-js": "^0.20.0",
120
141
  "@kinde/webhooks": "^1.3.3",
121
142
  "@playwright/test": "^1.65.1",
143
+ "@testing-library/react": "^16.3.3",
122
144
  "@types/node": "^22.10.0",
145
+ "@types/react": "^19.3.0",
123
146
  "jest": "^30.5.2",
147
+ "jsdom": "^26.1.0",
148
+ "next": "^16.4.6",
149
+ "react": "^19.3.1",
150
+ "react-dom": "^19.3.1",
124
151
  "tsup": "^8.3.5",
125
152
  "typescript": "^5.7.0",
126
153
  "vitest": "^5.1.0"