kinde-testkit 0.5.0 → 0.6.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/vitest.d.ts CHANGED
@@ -105,7 +105,17 @@ interface IdTokenOptions {
105
105
  clientId?: string;
106
106
  nonce?: string;
107
107
  }
108
+ /** Receives every token the testkit signs, for coverage and the dashboard. */
109
+ interface TokenObserver {
110
+ accessToken?(payload: Record<string, unknown>, invalid: InvalidTokenKind | undefined, token: string): void;
111
+ idToken?(payload: Record<string, unknown>, token: string): void;
112
+ anonymous?(): void;
113
+ }
108
114
  declare class KindeTestkit {
115
+ private observers;
116
+ /** Calls the observer for every token signed from now on. Returns a function that stops it. */
117
+ observe(observer: TokenObserver): () => void;
118
+ private signAccess;
109
119
  readonly issuer: string;
110
120
  readonly audience: string[];
111
121
  readonly clientId: string;
@@ -260,6 +270,60 @@ interface SeedPermission {
260
270
  description: string | null;
261
271
  }
262
272
 
273
+ interface UserMeta {
274
+ providedId: string | null;
275
+ isSuspended: boolean;
276
+ isPasswordResetRequested: boolean;
277
+ createdOn: string;
278
+ totalSignIns: number;
279
+ lastSignedIn: string | null;
280
+ }
281
+ interface OrganizationMeta {
282
+ externalId: string | null;
283
+ handle: string;
284
+ createdOn: string;
285
+ isAllowRegistrations: boolean;
286
+ }
287
+ declare class Directory {
288
+ readonly seed: ResolvedSeed;
289
+ private readonly userMeta;
290
+ private readonly orgMeta;
291
+ private snapshot;
292
+ constructor(seed: ResolvedSeed);
293
+ restore(): void;
294
+ /** Replaces the whole seed with another resolved seed, and makes it the state reset() returns to. */
295
+ load(next: ResolvedSeed): void;
296
+ user(id: string): KindeUser | undefined;
297
+ meta(user: KindeUser): UserMeta;
298
+ isSuspended(userId: string): boolean;
299
+ recordSignIn(user: KindeUser, organizationCode: string | null): void;
300
+ createUser(input: {
301
+ email?: string | null;
302
+ givenName?: string | null;
303
+ familyName?: string | null;
304
+ picture?: string | null;
305
+ providedId?: string | null;
306
+ }): KindeUser;
307
+ deleteUser(id: string): boolean;
308
+ organization(code: string): KindeOrganization | undefined;
309
+ orgInfo(org: KindeOrganization): OrganizationMeta;
310
+ createOrganization(input: {
311
+ name: string;
312
+ externalId?: string | null;
313
+ handle?: string | null;
314
+ }): KindeOrganization;
315
+ deleteOrganization(code: string): boolean;
316
+ membership(userId: string, organizationCode: string): KindeMembership | undefined;
317
+ addMembership(userId: string, organizationCode: string, roles?: string[], permissions?: string[]): KindeMembership;
318
+ removeMembership(userId: string, organizationCode: string): boolean;
319
+ role(idOrKey: string): SeedRole | undefined;
320
+ permission(idOrKey: string): SeedPermission | undefined;
321
+ ensureRole(key: string, extra?: Partial<Omit<SeedRole, "id" | "key">>): SeedRole;
322
+ ensurePermission(key: string, extra?: Partial<Omit<SeedPermission, "id" | "key">>): SeedPermission;
323
+ deleteRole(id: string): SeedRole | undefined;
324
+ deletePermission(id: string): SeedPermission | undefined;
325
+ }
326
+
263
327
  interface FailureRule {
264
328
  path: string;
265
329
  method?: string;
@@ -344,8 +408,12 @@ declare class WebhookDispatcher {
344
408
  private nextEndpoint;
345
409
  private readonly retryDelaysMs;
346
410
  private readonly timeoutMs;
411
+ /** Set by the server to record coverage. */
412
+ observe: (id: string) => void;
347
413
  constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
348
414
  addEndpoint(input: WebhookEndpointInput): WebhookEndpoint;
415
+ /** Replaces the endpoints that came from the seed, as when a new seed is loaded. */
416
+ replaceSeededEndpoints(endpoints: WebhookEndpointInput[]): void;
349
417
  removeEndpoint(id: string): boolean;
350
418
  listEndpoints(): WebhookEndpoint[];
351
419
  deliveries(): WebhookDelivery[];
@@ -364,14 +432,92 @@ declare class WebhookDispatcher {
364
432
  private requireUser;
365
433
  }
366
434
 
435
+ interface RequestEntry {
436
+ at: string;
437
+ method: string;
438
+ path: string;
439
+ status: number;
440
+ durationMs: number;
441
+ injected: boolean;
442
+ }
443
+ interface TokenEntry {
444
+ at: string;
445
+ kind: "access" | "m2m" | "id";
446
+ subject: string | null;
447
+ organization: string | null;
448
+ permissions: string[];
449
+ roles: string[];
450
+ invalid: InvalidTokenKind | null;
451
+ expiresAt: string | null;
452
+ claims: Record<string, unknown>;
453
+ token: string;
454
+ }
455
+ /** Keeps the latest requests and tokens for the dashboard and `kinde-testkit inspect --requests`. */
456
+ declare class ActivityLog {
457
+ private requestLog;
458
+ private tokenLog;
459
+ request(entry: Omit<RequestEntry, "at" | "path"> & {
460
+ path: string;
461
+ query: URLSearchParams;
462
+ }): void;
463
+ token(kind: TokenEntry["kind"], claims: Record<string, unknown>, invalid: InvalidTokenKind | undefined, token: string): void;
464
+ requests(): RequestEntry[];
465
+ tokens(): TokenEntry[];
466
+ reset(): void;
467
+ }
468
+
469
+ interface CoverageItem {
470
+ id: string;
471
+ label: string;
472
+ hint: string;
473
+ }
474
+ interface CoverageGroupResult {
475
+ name: string;
476
+ covered: number;
477
+ total: number;
478
+ items: Array<CoverageItem & {
479
+ covered: boolean;
480
+ count: number;
481
+ }>;
482
+ }
483
+ interface CoverageReport {
484
+ covered: number;
485
+ total: number;
486
+ groups: CoverageGroupResult[];
487
+ }
488
+ interface CoverageSnapshot {
489
+ version: 1;
490
+ hits: Record<string, number>;
491
+ }
492
+ /** Records which authentication scenarios the testkit produced during a test run. */
493
+ declare class CoverageRecorder {
494
+ private hits;
495
+ private userOrganizations;
496
+ private organizationUsers;
497
+ private organizationPermissionSets;
498
+ hit(id: string): void;
499
+ /** Called for every access token the testkit signs. */
500
+ observeAccessToken(payload: Record<string, unknown>, invalid: InvalidTokenKind | undefined): void;
501
+ report(): CoverageReport;
502
+ snapshot(): CoverageSnapshot;
503
+ reset(): void;
504
+ /** Writes this run's snapshot to the coverage folder, so separate test files can be merged. */
505
+ write(directory?: string): string;
506
+ }
507
+
367
508
  interface StartKindeTestkitOptions {
368
509
  port?: number;
369
510
  host?: string;
370
511
  issuer?: string;
371
512
  audience?: string | string[];
372
513
  clientId?: string;
373
- seed?: TestkitSeed;
514
+ /** A seed object, or the path of a JSON, YAML, JavaScript or TypeScript seed file. */
515
+ seed?: TestkitSeed | string;
374
516
  allowPublic?: boolean;
517
+ /** Write this run's authentication coverage to a folder when the testkit closes. */
518
+ coverage?: boolean | {
519
+ directory?: string;
520
+ };
375
521
  webhooks?: WebhookOptions;
376
522
  https?: boolean | {
377
523
  certDirectory?: string;
@@ -398,9 +544,16 @@ interface KindeTestkitHandle {
398
544
  readonly testkit: KindeTestkit;
399
545
  readonly failures: FailureInjector;
400
546
  readonly webhooks: WebhookDispatcher;
547
+ readonly directory: Directory;
548
+ readonly coverage: CoverageRecorder;
549
+ readonly activity: ActivityLog;
550
+ readonly certificatePath: string | null;
401
551
  auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
552
+ loadSeed(seed: TestkitSeed): void;
402
553
  reset(): void;
403
554
  }
555
+
556
+ /** Starts a testkit for the test file. Use the handle inside tests and hooks. */
404
557
  declare function useKindeTestkit(options?: StartKindeTestkitOptions): KindeTestkitHandle;
405
558
 
406
559
  export { type KindeTestAuth, type KindeTestkitHandle, kindeTest, useKindeTestkit };