kinde-testkit 0.2.2 → 0.3.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.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { JWTPayload, JWK } from 'jose';
1
+ import { JWTPayload, JWK, ProtectedHeaderParameters } from 'jose';
2
2
 
3
3
  interface KindeUser {
4
4
  id: string;
@@ -19,6 +19,15 @@ interface KindeRole {
19
19
  key: string;
20
20
  name: string;
21
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
+ }
22
31
  interface KindeMembership {
23
32
  userId: string;
24
33
  organizationCode: string;
@@ -38,6 +47,7 @@ interface UnauthenticatedScenario {
38
47
  }
39
48
  type Scenario = AuthenticatedScenario | UnauthenticatedScenario;
40
49
  interface KindePrincipal {
50
+ type: "user" | "machine";
41
51
  subject: string;
42
52
  issuer: string;
43
53
  organization: {
@@ -115,6 +125,7 @@ declare function isAuthenticated(value: Scenario): value is AuthenticatedScenari
115
125
 
116
126
  declare const DEFAULT_ISSUER = "http://localhost:4400";
117
127
  declare const DEFAULT_CLIENT_ID = "kinde_testkit_client";
128
+ declare const DEFAULT_M2M_CLIENT_ID = "kinde_testkit_m2m";
118
129
  declare const DEFAULT_SCOPES: string[];
119
130
  declare const DEFAULT_AUTH_METHODS: string[];
120
131
  declare const INVALID_TOKEN_KINDS: readonly InvalidTokenKind[];
@@ -127,6 +138,17 @@ interface KindeTestkitOptions {
127
138
  now?: () => number;
128
139
  }
129
140
  type ScenarioTokenOverrides = Pick<KindeTokenOptions, "expiresIn" | "invalid" | "scopes" | "featureFlags" | "claims" | "authMethods" | "authTime" | "clientId" | "audience">;
141
+ interface M2MTokenOptions {
142
+ clientId?: string;
143
+ organizationCode?: string | null;
144
+ scopes?: string[];
145
+ grantedScopes?: string[];
146
+ audience?: string[];
147
+ permissions?: string[];
148
+ claims?: Record<string, unknown>;
149
+ expiresIn?: Duration;
150
+ invalid?: InvalidTokenKind;
151
+ }
130
152
  interface IdTokenOptions {
131
153
  expiresIn?: Duration;
132
154
  authMethods?: string[];
@@ -153,6 +175,7 @@ declare class KindeTestkit {
153
175
  keys: JWK[];
154
176
  };
155
177
  token(options?: KindeTokenOptions): Promise<string>;
178
+ m2mToken(options?: M2MTokenOptions): Promise<string>;
156
179
  tokenFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<string | null>;
157
180
  idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
158
181
  headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
@@ -188,11 +211,21 @@ interface TestkitSeed {
188
211
  roles?: string[];
189
212
  permissions?: string[];
190
213
  }>;
214
+ applications?: Array<{
215
+ clientId: string;
216
+ clientSecret?: string;
217
+ name?: string;
218
+ organization?: string;
219
+ scopes?: string[];
220
+ permissions?: string[];
221
+ audience?: string | string[];
222
+ }>;
191
223
  }
192
224
  interface ResolvedSeed {
193
225
  users: KindeUser[];
194
226
  organizations: KindeOrganization[];
195
227
  memberships: KindeMembership[];
228
+ applications: KindeApplication[];
196
229
  }
197
230
  declare function resolveSeed(input: unknown): ResolvedSeed;
198
231
  declare function seedScenario(seed: ResolvedSeed, ref: {
@@ -200,6 +233,36 @@ declare function seedScenario(seed: ResolvedSeed, ref: {
200
233
  organization?: string | null;
201
234
  }): AuthenticatedScenario;
202
235
 
236
+ interface FailureRule {
237
+ path: string;
238
+ method?: string;
239
+ status?: number;
240
+ delayMs?: number;
241
+ hang?: boolean;
242
+ times?: number;
243
+ retryAfter?: number;
244
+ }
245
+ interface ActiveFailure {
246
+ id: string;
247
+ path: string;
248
+ method: string | null;
249
+ status: number | null;
250
+ delayMs: number;
251
+ hang: boolean;
252
+ remaining: number | null;
253
+ retryAfter: number;
254
+ hits: number;
255
+ }
256
+ declare class FailureInjector {
257
+ private rules;
258
+ private nextId;
259
+ add(rule: FailureRule): ActiveFailure;
260
+ remove(id: string): boolean;
261
+ clear(): void;
262
+ list(): ActiveFailure[];
263
+ take(method: string, path: string): ActiveFailure | null;
264
+ }
265
+
203
266
  interface StartKindeTestkitOptions {
204
267
  port?: number;
205
268
  host?: string;
@@ -216,6 +279,8 @@ interface RunningKindeTestkit {
216
279
  jwksUri: string;
217
280
  testkit: KindeTestkit;
218
281
  seed: ResolvedSeed;
282
+ failures: FailureInjector;
283
+ reset(): void;
219
284
  close(): Promise<void>;
220
285
  }
221
286
  declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
@@ -228,4 +293,32 @@ declare class TestkitError extends Error {
228
293
  toString(): string;
229
294
  }
230
295
 
231
- export { type AuthenticatedScenario, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_AUTH_METHODS, DEFAULT_CLIENT_ID, DEFAULT_ISSUER, DEFAULT_SCOPES, type Duration, INVALID_TOKEN_KINDS, type IdTokenOptions, type InvalidTokenKind, type KindeMembership, type KindeOrganization, type KindePrincipal, type KindeRole, KindeTestkit, type KindeTestkitOptions, type KindeTokenOptions, type KindeUser, type ResolvedSeed, type RunningKindeTestkit, type Scenario, ScenarioBuilder, type ScenarioTokenOverrides, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type UnauthenticatedScenario, createKindeOrganization, createKindeToken, createKindeUser, createMembership, getDefaultTestkit, isAuthenticated, principalFromClaims, resetFactories, resolveSeed, scenario, seedScenario, startKindeTestkit, toKindeRole };
296
+ type CheckStatus = "pass" | "warn" | "fail";
297
+ interface Check {
298
+ name: string;
299
+ status: CheckStatus;
300
+ detail: string;
301
+ }
302
+ interface TokenInspection {
303
+ kind: "access" | "id" | "m2m" | "unknown";
304
+ header: ProtectedHeaderParameters | null;
305
+ payload: JWTPayload | null;
306
+ checks: Check[];
307
+ }
308
+ declare function inspectToken(token: string, options?: {
309
+ issuerUrl?: string;
310
+ now?: number;
311
+ }): Promise<TokenInspection>;
312
+
313
+ interface DoctorReport {
314
+ url: string;
315
+ checks: Check[];
316
+ ok: boolean;
317
+ }
318
+ declare function runDoctor(options: {
319
+ url: string;
320
+ env: Record<string, string | undefined>;
321
+ }): Promise<DoctorReport>;
322
+ declare function parseEnvFile(text: string): Record<string, string>;
323
+
324
+ export { type ActiveFailure, type AuthenticatedScenario, type Check, type CheckStatus, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_AUTH_METHODS, DEFAULT_CLIENT_ID, DEFAULT_ISSUER, DEFAULT_M2M_CLIENT_ID, DEFAULT_SCOPES, type DoctorReport, type Duration, FailureInjector, type FailureRule, INVALID_TOKEN_KINDS, type IdTokenOptions, type InvalidTokenKind, type KindeApplication, type KindeMembership, type KindeOrganization, type KindePrincipal, type KindeRole, KindeTestkit, type KindeTestkitOptions, type KindeTokenOptions, type KindeUser, type M2MTokenOptions, type ResolvedSeed, type RunningKindeTestkit, type Scenario, ScenarioBuilder, type ScenarioTokenOverrides, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type TokenInspection, type UnauthenticatedScenario, createKindeOrganization, createKindeToken, createKindeUser, createMembership, getDefaultTestkit, inspectToken, isAuthenticated, parseEnvFile, principalFromClaims, resetFactories, resolveSeed, runDoctor, scenario, seedScenario, startKindeTestkit, toKindeRole };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JWTPayload, JWK } from 'jose';
1
+ import { JWTPayload, JWK, ProtectedHeaderParameters } from 'jose';
2
2
 
3
3
  interface KindeUser {
4
4
  id: string;
@@ -19,6 +19,15 @@ interface KindeRole {
19
19
  key: string;
20
20
  name: string;
21
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
+ }
22
31
  interface KindeMembership {
23
32
  userId: string;
24
33
  organizationCode: string;
@@ -38,6 +47,7 @@ interface UnauthenticatedScenario {
38
47
  }
39
48
  type Scenario = AuthenticatedScenario | UnauthenticatedScenario;
40
49
  interface KindePrincipal {
50
+ type: "user" | "machine";
41
51
  subject: string;
42
52
  issuer: string;
43
53
  organization: {
@@ -115,6 +125,7 @@ declare function isAuthenticated(value: Scenario): value is AuthenticatedScenari
115
125
 
116
126
  declare const DEFAULT_ISSUER = "http://localhost:4400";
117
127
  declare const DEFAULT_CLIENT_ID = "kinde_testkit_client";
128
+ declare const DEFAULT_M2M_CLIENT_ID = "kinde_testkit_m2m";
118
129
  declare const DEFAULT_SCOPES: string[];
119
130
  declare const DEFAULT_AUTH_METHODS: string[];
120
131
  declare const INVALID_TOKEN_KINDS: readonly InvalidTokenKind[];
@@ -127,6 +138,17 @@ interface KindeTestkitOptions {
127
138
  now?: () => number;
128
139
  }
129
140
  type ScenarioTokenOverrides = Pick<KindeTokenOptions, "expiresIn" | "invalid" | "scopes" | "featureFlags" | "claims" | "authMethods" | "authTime" | "clientId" | "audience">;
141
+ interface M2MTokenOptions {
142
+ clientId?: string;
143
+ organizationCode?: string | null;
144
+ scopes?: string[];
145
+ grantedScopes?: string[];
146
+ audience?: string[];
147
+ permissions?: string[];
148
+ claims?: Record<string, unknown>;
149
+ expiresIn?: Duration;
150
+ invalid?: InvalidTokenKind;
151
+ }
130
152
  interface IdTokenOptions {
131
153
  expiresIn?: Duration;
132
154
  authMethods?: string[];
@@ -153,6 +175,7 @@ declare class KindeTestkit {
153
175
  keys: JWK[];
154
176
  };
155
177
  token(options?: KindeTokenOptions): Promise<string>;
178
+ m2mToken(options?: M2MTokenOptions): Promise<string>;
156
179
  tokenFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<string | null>;
157
180
  idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
158
181
  headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
@@ -188,11 +211,21 @@ interface TestkitSeed {
188
211
  roles?: string[];
189
212
  permissions?: string[];
190
213
  }>;
214
+ applications?: Array<{
215
+ clientId: string;
216
+ clientSecret?: string;
217
+ name?: string;
218
+ organization?: string;
219
+ scopes?: string[];
220
+ permissions?: string[];
221
+ audience?: string | string[];
222
+ }>;
191
223
  }
192
224
  interface ResolvedSeed {
193
225
  users: KindeUser[];
194
226
  organizations: KindeOrganization[];
195
227
  memberships: KindeMembership[];
228
+ applications: KindeApplication[];
196
229
  }
197
230
  declare function resolveSeed(input: unknown): ResolvedSeed;
198
231
  declare function seedScenario(seed: ResolvedSeed, ref: {
@@ -200,6 +233,36 @@ declare function seedScenario(seed: ResolvedSeed, ref: {
200
233
  organization?: string | null;
201
234
  }): AuthenticatedScenario;
202
235
 
236
+ interface FailureRule {
237
+ path: string;
238
+ method?: string;
239
+ status?: number;
240
+ delayMs?: number;
241
+ hang?: boolean;
242
+ times?: number;
243
+ retryAfter?: number;
244
+ }
245
+ interface ActiveFailure {
246
+ id: string;
247
+ path: string;
248
+ method: string | null;
249
+ status: number | null;
250
+ delayMs: number;
251
+ hang: boolean;
252
+ remaining: number | null;
253
+ retryAfter: number;
254
+ hits: number;
255
+ }
256
+ declare class FailureInjector {
257
+ private rules;
258
+ private nextId;
259
+ add(rule: FailureRule): ActiveFailure;
260
+ remove(id: string): boolean;
261
+ clear(): void;
262
+ list(): ActiveFailure[];
263
+ take(method: string, path: string): ActiveFailure | null;
264
+ }
265
+
203
266
  interface StartKindeTestkitOptions {
204
267
  port?: number;
205
268
  host?: string;
@@ -216,6 +279,8 @@ interface RunningKindeTestkit {
216
279
  jwksUri: string;
217
280
  testkit: KindeTestkit;
218
281
  seed: ResolvedSeed;
282
+ failures: FailureInjector;
283
+ reset(): void;
219
284
  close(): Promise<void>;
220
285
  }
221
286
  declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
@@ -228,4 +293,32 @@ declare class TestkitError extends Error {
228
293
  toString(): string;
229
294
  }
230
295
 
231
- export { type AuthenticatedScenario, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_AUTH_METHODS, DEFAULT_CLIENT_ID, DEFAULT_ISSUER, DEFAULT_SCOPES, type Duration, INVALID_TOKEN_KINDS, type IdTokenOptions, type InvalidTokenKind, type KindeMembership, type KindeOrganization, type KindePrincipal, type KindeRole, KindeTestkit, type KindeTestkitOptions, type KindeTokenOptions, type KindeUser, type ResolvedSeed, type RunningKindeTestkit, type Scenario, ScenarioBuilder, type ScenarioTokenOverrides, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type UnauthenticatedScenario, createKindeOrganization, createKindeToken, createKindeUser, createMembership, getDefaultTestkit, isAuthenticated, principalFromClaims, resetFactories, resolveSeed, scenario, seedScenario, startKindeTestkit, toKindeRole };
296
+ type CheckStatus = "pass" | "warn" | "fail";
297
+ interface Check {
298
+ name: string;
299
+ status: CheckStatus;
300
+ detail: string;
301
+ }
302
+ interface TokenInspection {
303
+ kind: "access" | "id" | "m2m" | "unknown";
304
+ header: ProtectedHeaderParameters | null;
305
+ payload: JWTPayload | null;
306
+ checks: Check[];
307
+ }
308
+ declare function inspectToken(token: string, options?: {
309
+ issuerUrl?: string;
310
+ now?: number;
311
+ }): Promise<TokenInspection>;
312
+
313
+ interface DoctorReport {
314
+ url: string;
315
+ checks: Check[];
316
+ ok: boolean;
317
+ }
318
+ declare function runDoctor(options: {
319
+ url: string;
320
+ env: Record<string, string | undefined>;
321
+ }): Promise<DoctorReport>;
322
+ declare function parseEnvFile(text: string): Record<string, string>;
323
+
324
+ export { type ActiveFailure, type AuthenticatedScenario, type Check, type CheckStatus, type CreateKindeOrganizationOptions, type CreateKindeUserOptions, type CreateMembershipOptions, DEFAULT_AUTH_METHODS, DEFAULT_CLIENT_ID, DEFAULT_ISSUER, DEFAULT_M2M_CLIENT_ID, DEFAULT_SCOPES, type DoctorReport, type Duration, FailureInjector, type FailureRule, INVALID_TOKEN_KINDS, type IdTokenOptions, type InvalidTokenKind, type KindeApplication, type KindeMembership, type KindeOrganization, type KindePrincipal, type KindeRole, KindeTestkit, type KindeTestkitOptions, type KindeTokenOptions, type KindeUser, type M2MTokenOptions, type ResolvedSeed, type RunningKindeTestkit, type Scenario, ScenarioBuilder, type ScenarioTokenOverrides, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type TokenInspection, type UnauthenticatedScenario, createKindeOrganization, createKindeToken, createKindeUser, createMembership, getDefaultTestkit, inspectToken, isAuthenticated, parseEnvFile, principalFromClaims, resetFactories, resolveSeed, runDoctor, scenario, seedScenario, startKindeTestkit, toKindeRole };