kinde-testkit 0.4.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/CHANGELOG.md +18 -0
- package/README.md +235 -11
- package/dist/cli.js +2160 -267
- package/dist/cypress-support.d.ts +98 -0
- package/dist/cypress-support.js +119 -0
- package/dist/cypress-support.js.map +1 -0
- package/dist/cypress.cjs +4249 -0
- package/dist/cypress.cjs.map +1 -0
- package/dist/cypress.d.cts +118 -0
- package/dist/cypress.d.ts +118 -0
- package/dist/cypress.js +3324 -0
- package/dist/cypress.js.map +1 -0
- package/dist/index.cjs +3270 -314
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +326 -2
- package/dist/index.d.ts +326 -2
- package/dist/index.js +1954 -150
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +4318 -0
- package/dist/jest.cjs.map +1 -0
- package/dist/jest.d.cts +567 -0
- package/dist/jest.d.ts +567 -0
- package/dist/jest.js +3392 -0
- package/dist/jest.js.map +1 -0
- package/dist/vitest.d.ts +236 -1
- package/dist/vitest.js +1853 -155
- package/dist/vitest.js.map +1 -1
- package/package.json +36 -3
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;
|
|
@@ -146,6 +156,7 @@ interface TestkitSeed {
|
|
|
146
156
|
familyName?: string | null;
|
|
147
157
|
picture?: string | null;
|
|
148
158
|
claims?: Record<string, unknown>;
|
|
159
|
+
properties?: Record<string, string | number | boolean>;
|
|
149
160
|
}>;
|
|
150
161
|
organizations?: Array<{
|
|
151
162
|
code: string;
|
|
@@ -162,6 +173,39 @@ interface TestkitSeed {
|
|
|
162
173
|
url: string;
|
|
163
174
|
events?: string[];
|
|
164
175
|
}>;
|
|
176
|
+
roles?: Array<{
|
|
177
|
+
key: string;
|
|
178
|
+
name?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
permissions?: string[];
|
|
181
|
+
isDefault?: boolean;
|
|
182
|
+
}>;
|
|
183
|
+
featureFlags?: Array<{
|
|
184
|
+
key: string;
|
|
185
|
+
name?: string;
|
|
186
|
+
type?: "boolean" | "string" | "integer";
|
|
187
|
+
value: boolean | string | number;
|
|
188
|
+
organizations?: Record<string, boolean | string | number>;
|
|
189
|
+
}>;
|
|
190
|
+
plans?: Array<{
|
|
191
|
+
key: string;
|
|
192
|
+
name?: string;
|
|
193
|
+
subscribers?: string[];
|
|
194
|
+
entitlements?: Array<{
|
|
195
|
+
featureKey: string;
|
|
196
|
+
featureName?: string;
|
|
197
|
+
priceName?: string;
|
|
198
|
+
fixedCharge?: number | null;
|
|
199
|
+
unitAmount?: number | null;
|
|
200
|
+
limitMax?: number | null;
|
|
201
|
+
limitMin?: number | null;
|
|
202
|
+
}>;
|
|
203
|
+
}>;
|
|
204
|
+
permissions?: Array<{
|
|
205
|
+
key: string;
|
|
206
|
+
name?: string;
|
|
207
|
+
description?: string;
|
|
208
|
+
}>;
|
|
165
209
|
applications?: Array<{
|
|
166
210
|
clientId: string;
|
|
167
211
|
clientSecret?: string;
|
|
@@ -181,6 +225,103 @@ interface ResolvedSeed {
|
|
|
181
225
|
url: string;
|
|
182
226
|
events?: string[];
|
|
183
227
|
}>;
|
|
228
|
+
roles: SeedRole[];
|
|
229
|
+
permissions: SeedPermission[];
|
|
230
|
+
featureFlags: SeedFeatureFlag[];
|
|
231
|
+
plans: SeedPlan[];
|
|
232
|
+
userProperties: Record<string, Record<string, string | number | boolean>>;
|
|
233
|
+
}
|
|
234
|
+
interface SeedFeatureFlag {
|
|
235
|
+
id: string;
|
|
236
|
+
key: string;
|
|
237
|
+
name: string;
|
|
238
|
+
type: "boolean" | "string" | "integer";
|
|
239
|
+
value: boolean | string | number;
|
|
240
|
+
organizations: Record<string, boolean | string | number>;
|
|
241
|
+
}
|
|
242
|
+
interface SeedPlan {
|
|
243
|
+
key: string;
|
|
244
|
+
name: string;
|
|
245
|
+
subscribers: string[];
|
|
246
|
+
subscribedOn: string;
|
|
247
|
+
entitlements: Array<{
|
|
248
|
+
id: string;
|
|
249
|
+
featureKey: string;
|
|
250
|
+
featureName: string;
|
|
251
|
+
priceName: string;
|
|
252
|
+
fixedCharge: number | null;
|
|
253
|
+
unitAmount: number | null;
|
|
254
|
+
limitMax: number | null;
|
|
255
|
+
limitMin: number | null;
|
|
256
|
+
}>;
|
|
257
|
+
}
|
|
258
|
+
interface SeedRole {
|
|
259
|
+
id: string;
|
|
260
|
+
key: string;
|
|
261
|
+
name: string;
|
|
262
|
+
description: string | null;
|
|
263
|
+
isDefault: boolean;
|
|
264
|
+
permissions: string[];
|
|
265
|
+
}
|
|
266
|
+
interface SeedPermission {
|
|
267
|
+
id: string;
|
|
268
|
+
key: string;
|
|
269
|
+
name: string;
|
|
270
|
+
description: string | null;
|
|
271
|
+
}
|
|
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;
|
|
184
325
|
}
|
|
185
326
|
|
|
186
327
|
interface FailureRule {
|
|
@@ -267,8 +408,12 @@ declare class WebhookDispatcher {
|
|
|
267
408
|
private nextEndpoint;
|
|
268
409
|
private readonly retryDelaysMs;
|
|
269
410
|
private readonly timeoutMs;
|
|
411
|
+
/** Set by the server to record coverage. */
|
|
412
|
+
observe: (id: string) => void;
|
|
270
413
|
constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
|
|
271
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;
|
|
272
417
|
removeEndpoint(id: string): boolean;
|
|
273
418
|
listEndpoints(): WebhookEndpoint[];
|
|
274
419
|
deliveries(): WebhookDelivery[];
|
|
@@ -277,6 +422,8 @@ declare class WebhookDispatcher {
|
|
|
277
422
|
send(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
278
423
|
private deliver;
|
|
279
424
|
private buildData;
|
|
425
|
+
emit(type: string, data: Record<string, unknown>, source?: WebhookSource): void;
|
|
426
|
+
userEventData(user: KindeUser): Record<string, unknown>;
|
|
280
427
|
emitForUser(type: "user.created" | "user.authenticated", user: KindeUser): void;
|
|
281
428
|
private userData;
|
|
282
429
|
private userPayload;
|
|
@@ -285,15 +432,96 @@ declare class WebhookDispatcher {
|
|
|
285
432
|
private requireUser;
|
|
286
433
|
}
|
|
287
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
|
+
|
|
288
508
|
interface StartKindeTestkitOptions {
|
|
289
509
|
port?: number;
|
|
290
510
|
host?: string;
|
|
291
511
|
issuer?: string;
|
|
292
512
|
audience?: string | string[];
|
|
293
513
|
clientId?: string;
|
|
294
|
-
seed
|
|
514
|
+
/** A seed object, or the path of a JSON, YAML, JavaScript or TypeScript seed file. */
|
|
515
|
+
seed?: TestkitSeed | string;
|
|
295
516
|
allowPublic?: boolean;
|
|
517
|
+
/** Write this run's authentication coverage to a folder when the testkit closes. */
|
|
518
|
+
coverage?: boolean | {
|
|
519
|
+
directory?: string;
|
|
520
|
+
};
|
|
296
521
|
webhooks?: WebhookOptions;
|
|
522
|
+
https?: boolean | {
|
|
523
|
+
certDirectory?: string;
|
|
524
|
+
};
|
|
297
525
|
}
|
|
298
526
|
|
|
299
527
|
interface KindeTestAuth {
|
|
@@ -316,9 +544,16 @@ interface KindeTestkitHandle {
|
|
|
316
544
|
readonly testkit: KindeTestkit;
|
|
317
545
|
readonly failures: FailureInjector;
|
|
318
546
|
readonly webhooks: WebhookDispatcher;
|
|
547
|
+
readonly directory: Directory;
|
|
548
|
+
readonly coverage: CoverageRecorder;
|
|
549
|
+
readonly activity: ActivityLog;
|
|
550
|
+
readonly certificatePath: string | null;
|
|
319
551
|
auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
|
|
552
|
+
loadSeed(seed: TestkitSeed): void;
|
|
320
553
|
reset(): void;
|
|
321
554
|
}
|
|
555
|
+
|
|
556
|
+
/** Starts a testkit for the test file. Use the handle inside tests and hooks. */
|
|
322
557
|
declare function useKindeTestkit(options?: StartKindeTestkitOptions): KindeTestkitHandle;
|
|
323
558
|
|
|
324
559
|
export { type KindeTestAuth, type KindeTestkitHandle, kindeTest, useKindeTestkit };
|