kinde-testkit 0.5.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.
@@ -0,0 +1,17 @@
1
+ import { a as KindeTestkitHandle } from './handle-BERQZCyH.cjs';
2
+ export { K as KindeTestAuth, k as kindeTest } from './handle-BERQZCyH.cjs';
3
+ import { S as StartKindeTestkitOptions } from './server-ciWIscoQ.cjs';
4
+ import 'jose';
5
+
6
+ type Hook = (fn: () => Promise<void>, timeout?: number) => void;
7
+ /**
8
+ * Starts a testkit for the test file. Use the handle inside tests and hooks.
9
+ * Uses Jest's global beforeAll and afterAll. With injectGlobals: false, pass them in:
10
+ * useKindeTestkit(options, { beforeAll, afterAll }) with the functions from @jest/globals.
11
+ */
12
+ declare function useKindeTestkit(options?: StartKindeTestkitOptions, hooks?: {
13
+ beforeAll: Hook;
14
+ afterAll: Hook;
15
+ }): KindeTestkitHandle;
16
+
17
+ export { KindeTestkitHandle, useKindeTestkit };
package/dist/jest.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { a as KindeTestkitHandle } from './handle-Dh0UpIzG.js';
2
+ export { K as KindeTestAuth, k as kindeTest } from './handle-Dh0UpIzG.js';
3
+ import { S as StartKindeTestkitOptions } from './server-BiODgeoB.js';
4
+ import './webhooks-DJyCsbdF.js';
5
+ import 'jose';
6
+
7
+ type Hook = (fn: () => Promise<void>, timeout?: number) => void;
8
+ /**
9
+ * Starts a testkit for the test file. Use the handle inside tests and hooks.
10
+ * Uses Jest's global beforeAll and afterAll. With injectGlobals: false, pass them in:
11
+ * useKindeTestkit(options, { beforeAll, afterAll }) with the functions from @jest/globals.
12
+ */
13
+ declare function useKindeTestkit(options?: StartKindeTestkitOptions, hooks?: {
14
+ beforeAll: Hook;
15
+ afterAll: Hook;
16
+ }): KindeTestkitHandle;
17
+
18
+ export { KindeTestkitHandle, useKindeTestkit };
package/dist/jest.js ADDED
@@ -0,0 +1,23 @@
1
+ import {
2
+ createKindeTestkitHandle,
3
+ kindeTest
4
+ } from "./chunk-U2D47SCY.js";
5
+ import "./chunk-GCOZVCZY.js";
6
+
7
+ // src/jest.ts
8
+ function useKindeTestkit(options = {}, hooks) {
9
+ const globals = globalThis;
10
+ const beforeAll = hooks?.beforeAll ?? globals.beforeAll;
11
+ const afterAll = hooks?.afterAll ?? globals.afterAll;
12
+ if (typeof beforeAll !== "function" || typeof afterAll !== "function") {
13
+ throw new Error(
14
+ "useKindeTestkit() from kinde-testkit/jest needs Jest's beforeAll and afterAll. Call it at the top of a test file, or pass them from @jest/globals."
15
+ );
16
+ }
17
+ return createKindeTestkitHandle({ beforeAll, afterAll }, options, "useKindeTestkit");
18
+ }
19
+ export {
20
+ kindeTest,
21
+ useKindeTestkit
22
+ };
23
+ //# sourceMappingURL=jest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/jest.ts"],"sourcesContent":["import { createKindeTestkitHandle, type KindeTestkitHandle } from \"./handle.js\";\nimport type { StartKindeTestkitOptions } from \"./server.js\";\n\nexport { kindeTest, type KindeTestAuth, type KindeTestkitHandle } from \"./handle.js\";\n\ntype Hook = (fn: () => Promise<void>, timeout?: number) => void;\n\n/**\n * Starts a testkit for the test file. Use the handle inside tests and hooks.\n * Uses Jest's global beforeAll and afterAll. With injectGlobals: false, pass them in:\n * useKindeTestkit(options, { beforeAll, afterAll }) with the functions from @jest/globals.\n */\nexport function useKindeTestkit(\n options: StartKindeTestkitOptions = {},\n hooks?: { beforeAll: Hook; afterAll: Hook },\n): KindeTestkitHandle {\n const globals = globalThis as unknown as { beforeAll?: Hook; afterAll?: Hook };\n const beforeAll = hooks?.beforeAll ?? globals.beforeAll;\n const afterAll = hooks?.afterAll ?? globals.afterAll;\n if (typeof beforeAll !== \"function\" || typeof afterAll !== \"function\") {\n throw new Error(\n \"useKindeTestkit() from kinde-testkit/jest needs Jest's beforeAll and afterAll. Call it at the top of a test file, or pass them from @jest/globals.\",\n );\n }\n return createKindeTestkitHandle({ beforeAll, afterAll }, options, \"useKindeTestkit\");\n}\n"],"mappings":";;;;;;;AAYO,SAAS,gBACd,UAAoC,CAAC,GACrC,OACoB;AACpB,QAAM,UAAU;AAChB,QAAM,YAAY,OAAO,aAAa,QAAQ;AAC9C,QAAM,WAAW,OAAO,YAAY,QAAQ;AAC5C,MAAI,OAAO,cAAc,cAAc,OAAO,aAAa,YAAY;AACrE,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,yBAAyB,EAAE,WAAW,SAAS,GAAG,SAAS,iBAAiB;AACrF;","names":[]}
@@ -1,60 +1,8 @@
1
1
  import * as playwright_test from 'playwright/test';
2
2
  import { Page } from '@playwright/test';
3
3
  export { expect } from '@playwright/test';
4
-
5
- interface FailureRule {
6
- path: string;
7
- method?: string;
8
- status?: number;
9
- delayMs?: number;
10
- hang?: boolean;
11
- times?: number;
12
- retryAfter?: number;
13
- }
14
- interface ActiveFailure {
15
- id: string;
16
- path: string;
17
- method: string | null;
18
- status: number | null;
19
- delayMs: number;
20
- hang: boolean;
21
- remaining: number | null;
22
- retryAfter: number;
23
- hits: number;
24
- }
25
-
26
- type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
27
- type WebhookSource = "admin" | "api" | "user";
28
- interface SendWebhookOptions {
29
- type: string;
30
- data?: Record<string, unknown>;
31
- user?: string;
32
- organization?: string;
33
- role?: string;
34
- permission?: string;
35
- source?: WebhookSource;
36
- ipAddress?: string;
37
- to?: string;
38
- duplicate?: number;
39
- delayMs?: number;
40
- invalid?: WebhookInvalidKind;
41
- }
42
- interface WebhookAttempt {
43
- attempt: number;
44
- status: number | null;
45
- error: string | null;
46
- durationMs: number;
47
- }
48
- interface WebhookDelivery {
49
- webhookId: string;
50
- eventId: string;
51
- type: string;
52
- url: string;
53
- copy: number;
54
- delivered: boolean;
55
- attempts: WebhookAttempt[];
56
- payload: Record<string, unknown>;
57
- }
4
+ import { j as FailureRule, d as ActiveFailure, s as SendWebhookOptions, v as WebhookDelivery } from './webhooks-DJyCsbdF.js';
5
+ import 'jose';
58
6
 
59
7
  interface KindeFixtureOptions {
60
8
  issuer: string;
@@ -0,0 +1,185 @@
1
+ import { R as ResolvedSeed, a as KindeUser, K as KindeOrganization, b as KindeMembership, O as SeedRole, P as SeedPermission, l as InvalidTokenKind, T as TestkitSeed, C as WebhookOptions, o as KindeTestkit, F as FailureInjector, w as WebhookDispatcher } from './webhooks-DJyCsbdF.js';
2
+
3
+ interface UserMeta {
4
+ providedId: string | null;
5
+ isSuspended: boolean;
6
+ isPasswordResetRequested: boolean;
7
+ createdOn: string;
8
+ totalSignIns: number;
9
+ lastSignedIn: string | null;
10
+ }
11
+ interface OrganizationMeta {
12
+ externalId: string | null;
13
+ handle: string;
14
+ createdOn: string;
15
+ isAllowRegistrations: boolean;
16
+ }
17
+ declare class Directory {
18
+ readonly seed: ResolvedSeed;
19
+ private readonly userMeta;
20
+ private readonly orgMeta;
21
+ private snapshot;
22
+ constructor(seed: ResolvedSeed);
23
+ restore(): void;
24
+ /** Replaces the whole seed with another resolved seed, and makes it the state reset() returns to. */
25
+ load(next: ResolvedSeed): void;
26
+ user(id: string): KindeUser | undefined;
27
+ meta(user: KindeUser): UserMeta;
28
+ isSuspended(userId: string): boolean;
29
+ recordSignIn(user: KindeUser, organizationCode: string | null): void;
30
+ createUser(input: {
31
+ email?: string | null;
32
+ givenName?: string | null;
33
+ familyName?: string | null;
34
+ picture?: string | null;
35
+ providedId?: string | null;
36
+ }): KindeUser;
37
+ deleteUser(id: string): boolean;
38
+ organization(code: string): KindeOrganization | undefined;
39
+ orgInfo(org: KindeOrganization): OrganizationMeta;
40
+ createOrganization(input: {
41
+ name: string;
42
+ externalId?: string | null;
43
+ handle?: string | null;
44
+ }): KindeOrganization;
45
+ deleteOrganization(code: string): boolean;
46
+ membership(userId: string, organizationCode: string): KindeMembership | undefined;
47
+ addMembership(userId: string, organizationCode: string, roles?: string[], permissions?: string[]): KindeMembership;
48
+ removeMembership(userId: string, organizationCode: string): boolean;
49
+ role(idOrKey: string): SeedRole | undefined;
50
+ permission(idOrKey: string): SeedPermission | undefined;
51
+ ensureRole(key: string, extra?: Partial<Omit<SeedRole, "id" | "key">>): SeedRole;
52
+ ensurePermission(key: string, extra?: Partial<Omit<SeedPermission, "id" | "key">>): SeedPermission;
53
+ deleteRole(id: string): SeedRole | undefined;
54
+ deletePermission(id: string): SeedPermission | undefined;
55
+ }
56
+
57
+ interface RequestEntry {
58
+ at: string;
59
+ method: string;
60
+ path: string;
61
+ status: number;
62
+ durationMs: number;
63
+ injected: boolean;
64
+ }
65
+ interface TokenEntry {
66
+ at: string;
67
+ kind: "access" | "m2m" | "id";
68
+ subject: string | null;
69
+ organization: string | null;
70
+ permissions: string[];
71
+ roles: string[];
72
+ invalid: InvalidTokenKind | null;
73
+ expiresAt: string | null;
74
+ claims: Record<string, unknown>;
75
+ token: string;
76
+ }
77
+ /** Keeps the latest requests and tokens for the dashboard and `kinde-testkit inspect --requests`. */
78
+ declare class ActivityLog {
79
+ private requestLog;
80
+ private tokenLog;
81
+ request(entry: Omit<RequestEntry, "at" | "path"> & {
82
+ path: string;
83
+ query: URLSearchParams;
84
+ }): void;
85
+ token(kind: TokenEntry["kind"], claims: Record<string, unknown>, invalid: InvalidTokenKind | undefined, token: string): void;
86
+ requests(): RequestEntry[];
87
+ tokens(): TokenEntry[];
88
+ reset(): void;
89
+ }
90
+
91
+ interface CoverageItem {
92
+ id: string;
93
+ label: string;
94
+ hint: string;
95
+ }
96
+ interface CoverageGroup {
97
+ name: string;
98
+ items: CoverageItem[];
99
+ }
100
+ declare const COVERAGE_GROUPS: CoverageGroup[];
101
+ interface CoverageGroupResult {
102
+ name: string;
103
+ covered: number;
104
+ total: number;
105
+ items: Array<CoverageItem & {
106
+ covered: boolean;
107
+ count: number;
108
+ }>;
109
+ }
110
+ interface CoverageReport {
111
+ covered: number;
112
+ total: number;
113
+ groups: CoverageGroupResult[];
114
+ }
115
+ interface CoverageSnapshot {
116
+ version: 1;
117
+ hits: Record<string, number>;
118
+ }
119
+ /** Records which authentication scenarios the testkit produced during a test run. */
120
+ declare class CoverageRecorder {
121
+ private hits;
122
+ private userOrganizations;
123
+ private organizationUsers;
124
+ private organizationPermissionSets;
125
+ hit(id: string): void;
126
+ /** Called for every access token the testkit signs. */
127
+ observeAccessToken(payload: Record<string, unknown>, invalid: InvalidTokenKind | undefined): void;
128
+ report(): CoverageReport;
129
+ snapshot(): CoverageSnapshot;
130
+ reset(): void;
131
+ /** Writes this run's snapshot to the coverage folder, so separate test files can be merged. */
132
+ write(directory?: string): string;
133
+ }
134
+ declare const DEFAULT_COVERAGE_DIRECTORY: string;
135
+ declare function buildReport(hits: Record<string, number>): CoverageReport;
136
+ declare function mergeSnapshots(snapshots: CoverageSnapshot[]): Record<string, number>;
137
+ /** Reads and merges every snapshot in the coverage folder. */
138
+ declare function readCoverageDirectory(directory?: string): {
139
+ files: number;
140
+ report: CoverageReport;
141
+ };
142
+ declare function clearCoverageDirectory(directory?: string): void;
143
+ declare function formatCoverageReport(report: CoverageReport, options?: {
144
+ missing?: boolean;
145
+ }): string;
146
+
147
+ interface StartKindeTestkitOptions {
148
+ port?: number;
149
+ host?: string;
150
+ issuer?: string;
151
+ audience?: string | string[];
152
+ clientId?: string;
153
+ /** A seed object, or the path of a JSON, YAML, JavaScript or TypeScript seed file. */
154
+ seed?: TestkitSeed | string;
155
+ allowPublic?: boolean;
156
+ /** Write this run's authentication coverage to a folder when the testkit closes. */
157
+ coverage?: boolean | {
158
+ directory?: string;
159
+ };
160
+ webhooks?: WebhookOptions;
161
+ https?: boolean | {
162
+ certDirectory?: string;
163
+ };
164
+ }
165
+ interface RunningKindeTestkit {
166
+ url: string;
167
+ issuer: string;
168
+ discoveryUrl: string;
169
+ jwksUri: string;
170
+ testkit: KindeTestkit;
171
+ seed: ResolvedSeed;
172
+ failures: FailureInjector;
173
+ webhooks: WebhookDispatcher;
174
+ directory: Directory;
175
+ certificatePath: string | null;
176
+ coverage: CoverageRecorder;
177
+ activity: ActivityLog;
178
+ /** Replaces the seed while the issuer runs. reset() returns to the new seed. */
179
+ loadSeed(seed: TestkitSeed): void;
180
+ reset(): void;
181
+ close(): Promise<void>;
182
+ }
183
+ declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
184
+
185
+ export { ActivityLog as A, COVERAGE_GROUPS as C, DEFAULT_COVERAGE_DIRECTORY as D, type RequestEntry as R, type StartKindeTestkitOptions as S, type TokenEntry as T, type CoverageGroup as a, type CoverageGroupResult as b, type CoverageItem as c, CoverageRecorder as d, type CoverageReport as e, type CoverageSnapshot as f, Directory as g, type RunningKindeTestkit as h, buildReport as i, clearCoverageDirectory as j, formatCoverageReport as k, mergeSnapshots as m, readCoverageDirectory as r, startKindeTestkit as s };