kinde-testkit 0.2.2 → 0.4.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 +179 -7
- package/dist/cli.js +1014 -15
- package/dist/index.cjs +731 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +180 -2
- package/dist/index.d.ts +180 -2
- package/dist/index.js +723 -14
- package/dist/index.js.map +1 -1
- package/dist/playwright.d.ts +61 -1
- package/dist/playwright.js +36 -7
- package/dist/playwright.js.map +1 -1
- package/dist/vitest.d.ts +158 -0
- package/dist/vitest.js +553 -14
- package/dist/vitest.js.map +1 -1
- package/package.json +2 -1
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,10 +175,12 @@ 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>>;
|
|
159
182
|
principalFor(scenario: Scenario): KindePrincipal | null;
|
|
183
|
+
signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
|
|
160
184
|
private sign;
|
|
161
185
|
private stranger;
|
|
162
186
|
}
|
|
@@ -188,11 +212,29 @@ interface TestkitSeed {
|
|
|
188
212
|
roles?: string[];
|
|
189
213
|
permissions?: string[];
|
|
190
214
|
}>;
|
|
215
|
+
webhooks?: Array<{
|
|
216
|
+
url: string;
|
|
217
|
+
events?: string[];
|
|
218
|
+
}>;
|
|
219
|
+
applications?: Array<{
|
|
220
|
+
clientId: string;
|
|
221
|
+
clientSecret?: string;
|
|
222
|
+
name?: string;
|
|
223
|
+
organization?: string;
|
|
224
|
+
scopes?: string[];
|
|
225
|
+
permissions?: string[];
|
|
226
|
+
audience?: string | string[];
|
|
227
|
+
}>;
|
|
191
228
|
}
|
|
192
229
|
interface ResolvedSeed {
|
|
193
230
|
users: KindeUser[];
|
|
194
231
|
organizations: KindeOrganization[];
|
|
195
232
|
memberships: KindeMembership[];
|
|
233
|
+
applications: KindeApplication[];
|
|
234
|
+
webhooks: Array<{
|
|
235
|
+
url: string;
|
|
236
|
+
events?: string[];
|
|
237
|
+
}>;
|
|
196
238
|
}
|
|
197
239
|
declare function resolveSeed(input: unknown): ResolvedSeed;
|
|
198
240
|
declare function seedScenario(seed: ResolvedSeed, ref: {
|
|
@@ -200,6 +242,110 @@ declare function seedScenario(seed: ResolvedSeed, ref: {
|
|
|
200
242
|
organization?: string | null;
|
|
201
243
|
}): AuthenticatedScenario;
|
|
202
244
|
|
|
245
|
+
interface FailureRule {
|
|
246
|
+
path: string;
|
|
247
|
+
method?: string;
|
|
248
|
+
status?: number;
|
|
249
|
+
delayMs?: number;
|
|
250
|
+
hang?: boolean;
|
|
251
|
+
times?: number;
|
|
252
|
+
retryAfter?: number;
|
|
253
|
+
}
|
|
254
|
+
interface ActiveFailure {
|
|
255
|
+
id: string;
|
|
256
|
+
path: string;
|
|
257
|
+
method: string | null;
|
|
258
|
+
status: number | null;
|
|
259
|
+
delayMs: number;
|
|
260
|
+
hang: boolean;
|
|
261
|
+
remaining: number | null;
|
|
262
|
+
retryAfter: number;
|
|
263
|
+
hits: number;
|
|
264
|
+
}
|
|
265
|
+
declare class FailureInjector {
|
|
266
|
+
private rules;
|
|
267
|
+
private nextId;
|
|
268
|
+
add(rule: FailureRule): ActiveFailure;
|
|
269
|
+
remove(id: string): boolean;
|
|
270
|
+
clear(): void;
|
|
271
|
+
list(): ActiveFailure[];
|
|
272
|
+
take(method: string, path: string): ActiveFailure | null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
declare const WEBHOOK_EVENT_TYPES: readonly ["user.created", "user.updated", "user.deleted", "user.authenticated", "user.authentication_failed", "organization.created", "organization.updated", "organization.deleted", "role.created", "role.updated", "role.deleted", "permission.created", "permission.updated", "permission.deleted", "subscriber.created", "access_request.created"];
|
|
276
|
+
declare const BILLING_EVENT_TYPES: readonly ["customer.agreement_cancelled", "customer.agreement_created", "customer.invoice_overdue", "customer.meter_usage_updated", "customer.payment_failed", "customer.payment_succeeded", "customer.plan_assigned", "customer.plan_changed"];
|
|
277
|
+
type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
|
|
278
|
+
type WebhookSource = "admin" | "api" | "user";
|
|
279
|
+
interface WebhookEndpointInput {
|
|
280
|
+
url: string;
|
|
281
|
+
events?: string[];
|
|
282
|
+
}
|
|
283
|
+
interface WebhookEndpoint {
|
|
284
|
+
id: string;
|
|
285
|
+
url: string;
|
|
286
|
+
events: string[] | null;
|
|
287
|
+
}
|
|
288
|
+
interface SendWebhookOptions {
|
|
289
|
+
type: string;
|
|
290
|
+
data?: Record<string, unknown>;
|
|
291
|
+
user?: string;
|
|
292
|
+
organization?: string;
|
|
293
|
+
role?: string;
|
|
294
|
+
permission?: string;
|
|
295
|
+
source?: WebhookSource;
|
|
296
|
+
ipAddress?: string;
|
|
297
|
+
to?: string;
|
|
298
|
+
duplicate?: number;
|
|
299
|
+
delayMs?: number;
|
|
300
|
+
invalid?: WebhookInvalidKind;
|
|
301
|
+
}
|
|
302
|
+
interface WebhookAttempt {
|
|
303
|
+
attempt: number;
|
|
304
|
+
status: number | null;
|
|
305
|
+
error: string | null;
|
|
306
|
+
durationMs: number;
|
|
307
|
+
}
|
|
308
|
+
interface WebhookDelivery {
|
|
309
|
+
webhookId: string;
|
|
310
|
+
eventId: string;
|
|
311
|
+
type: string;
|
|
312
|
+
url: string;
|
|
313
|
+
copy: number;
|
|
314
|
+
delivered: boolean;
|
|
315
|
+
attempts: WebhookAttempt[];
|
|
316
|
+
payload: Record<string, unknown>;
|
|
317
|
+
}
|
|
318
|
+
interface WebhookOptions {
|
|
319
|
+
retryDelaysMs?: number[];
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
}
|
|
322
|
+
declare class WebhookDispatcher {
|
|
323
|
+
private readonly testkit;
|
|
324
|
+
private readonly seed;
|
|
325
|
+
private endpoints;
|
|
326
|
+
private seededEndpoints;
|
|
327
|
+
private log;
|
|
328
|
+
private nextEndpoint;
|
|
329
|
+
private readonly retryDelaysMs;
|
|
330
|
+
private readonly timeoutMs;
|
|
331
|
+
constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
|
|
332
|
+
addEndpoint(input: WebhookEndpointInput): WebhookEndpoint;
|
|
333
|
+
removeEndpoint(id: string): boolean;
|
|
334
|
+
listEndpoints(): WebhookEndpoint[];
|
|
335
|
+
deliveries(): WebhookDelivery[];
|
|
336
|
+
reset(): void;
|
|
337
|
+
buildEvent(options: SendWebhookOptions): Record<string, unknown>;
|
|
338
|
+
send(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
339
|
+
private deliver;
|
|
340
|
+
private buildData;
|
|
341
|
+
emitForUser(type: "user.created" | "user.authenticated", user: KindeUser): void;
|
|
342
|
+
private userData;
|
|
343
|
+
private userPayload;
|
|
344
|
+
private organizationData;
|
|
345
|
+
private namedData;
|
|
346
|
+
private requireUser;
|
|
347
|
+
}
|
|
348
|
+
|
|
203
349
|
interface StartKindeTestkitOptions {
|
|
204
350
|
port?: number;
|
|
205
351
|
host?: string;
|
|
@@ -208,6 +354,7 @@ interface StartKindeTestkitOptions {
|
|
|
208
354
|
clientId?: string;
|
|
209
355
|
seed?: TestkitSeed;
|
|
210
356
|
allowPublic?: boolean;
|
|
357
|
+
webhooks?: WebhookOptions;
|
|
211
358
|
}
|
|
212
359
|
interface RunningKindeTestkit {
|
|
213
360
|
url: string;
|
|
@@ -216,6 +363,9 @@ interface RunningKindeTestkit {
|
|
|
216
363
|
jwksUri: string;
|
|
217
364
|
testkit: KindeTestkit;
|
|
218
365
|
seed: ResolvedSeed;
|
|
366
|
+
failures: FailureInjector;
|
|
367
|
+
webhooks: WebhookDispatcher;
|
|
368
|
+
reset(): void;
|
|
219
369
|
close(): Promise<void>;
|
|
220
370
|
}
|
|
221
371
|
declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
|
|
@@ -228,4 +378,32 @@ declare class TestkitError extends Error {
|
|
|
228
378
|
toString(): string;
|
|
229
379
|
}
|
|
230
380
|
|
|
231
|
-
|
|
381
|
+
type CheckStatus = "pass" | "warn" | "fail";
|
|
382
|
+
interface Check {
|
|
383
|
+
name: string;
|
|
384
|
+
status: CheckStatus;
|
|
385
|
+
detail: string;
|
|
386
|
+
}
|
|
387
|
+
interface TokenInspection {
|
|
388
|
+
kind: "access" | "id" | "m2m" | "unknown";
|
|
389
|
+
header: ProtectedHeaderParameters | null;
|
|
390
|
+
payload: JWTPayload | null;
|
|
391
|
+
checks: Check[];
|
|
392
|
+
}
|
|
393
|
+
declare function inspectToken(token: string, options?: {
|
|
394
|
+
issuerUrl?: string;
|
|
395
|
+
now?: number;
|
|
396
|
+
}): Promise<TokenInspection>;
|
|
397
|
+
|
|
398
|
+
interface DoctorReport {
|
|
399
|
+
url: string;
|
|
400
|
+
checks: Check[];
|
|
401
|
+
ok: boolean;
|
|
402
|
+
}
|
|
403
|
+
declare function runDoctor(options: {
|
|
404
|
+
url: string;
|
|
405
|
+
env: Record<string, string | undefined>;
|
|
406
|
+
}): Promise<DoctorReport>;
|
|
407
|
+
declare function parseEnvFile(text: string): Record<string, string>;
|
|
408
|
+
|
|
409
|
+
export { type ActiveFailure, type AuthenticatedScenario, BILLING_EVENT_TYPES, 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 SendWebhookOptions, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type TokenInspection, type UnauthenticatedScenario, WEBHOOK_EVENT_TYPES, type WebhookAttempt, type WebhookDelivery, WebhookDispatcher, type WebhookEndpoint, type WebhookEndpointInput, type WebhookInvalidKind, type WebhookOptions, type WebhookSource, 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,10 +175,12 @@ 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>>;
|
|
159
182
|
principalFor(scenario: Scenario): KindePrincipal | null;
|
|
183
|
+
signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
|
|
160
184
|
private sign;
|
|
161
185
|
private stranger;
|
|
162
186
|
}
|
|
@@ -188,11 +212,29 @@ interface TestkitSeed {
|
|
|
188
212
|
roles?: string[];
|
|
189
213
|
permissions?: string[];
|
|
190
214
|
}>;
|
|
215
|
+
webhooks?: Array<{
|
|
216
|
+
url: string;
|
|
217
|
+
events?: string[];
|
|
218
|
+
}>;
|
|
219
|
+
applications?: Array<{
|
|
220
|
+
clientId: string;
|
|
221
|
+
clientSecret?: string;
|
|
222
|
+
name?: string;
|
|
223
|
+
organization?: string;
|
|
224
|
+
scopes?: string[];
|
|
225
|
+
permissions?: string[];
|
|
226
|
+
audience?: string | string[];
|
|
227
|
+
}>;
|
|
191
228
|
}
|
|
192
229
|
interface ResolvedSeed {
|
|
193
230
|
users: KindeUser[];
|
|
194
231
|
organizations: KindeOrganization[];
|
|
195
232
|
memberships: KindeMembership[];
|
|
233
|
+
applications: KindeApplication[];
|
|
234
|
+
webhooks: Array<{
|
|
235
|
+
url: string;
|
|
236
|
+
events?: string[];
|
|
237
|
+
}>;
|
|
196
238
|
}
|
|
197
239
|
declare function resolveSeed(input: unknown): ResolvedSeed;
|
|
198
240
|
declare function seedScenario(seed: ResolvedSeed, ref: {
|
|
@@ -200,6 +242,110 @@ declare function seedScenario(seed: ResolvedSeed, ref: {
|
|
|
200
242
|
organization?: string | null;
|
|
201
243
|
}): AuthenticatedScenario;
|
|
202
244
|
|
|
245
|
+
interface FailureRule {
|
|
246
|
+
path: string;
|
|
247
|
+
method?: string;
|
|
248
|
+
status?: number;
|
|
249
|
+
delayMs?: number;
|
|
250
|
+
hang?: boolean;
|
|
251
|
+
times?: number;
|
|
252
|
+
retryAfter?: number;
|
|
253
|
+
}
|
|
254
|
+
interface ActiveFailure {
|
|
255
|
+
id: string;
|
|
256
|
+
path: string;
|
|
257
|
+
method: string | null;
|
|
258
|
+
status: number | null;
|
|
259
|
+
delayMs: number;
|
|
260
|
+
hang: boolean;
|
|
261
|
+
remaining: number | null;
|
|
262
|
+
retryAfter: number;
|
|
263
|
+
hits: number;
|
|
264
|
+
}
|
|
265
|
+
declare class FailureInjector {
|
|
266
|
+
private rules;
|
|
267
|
+
private nextId;
|
|
268
|
+
add(rule: FailureRule): ActiveFailure;
|
|
269
|
+
remove(id: string): boolean;
|
|
270
|
+
clear(): void;
|
|
271
|
+
list(): ActiveFailure[];
|
|
272
|
+
take(method: string, path: string): ActiveFailure | null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
declare const WEBHOOK_EVENT_TYPES: readonly ["user.created", "user.updated", "user.deleted", "user.authenticated", "user.authentication_failed", "organization.created", "organization.updated", "organization.deleted", "role.created", "role.updated", "role.deleted", "permission.created", "permission.updated", "permission.deleted", "subscriber.created", "access_request.created"];
|
|
276
|
+
declare const BILLING_EVENT_TYPES: readonly ["customer.agreement_cancelled", "customer.agreement_created", "customer.invoice_overdue", "customer.meter_usage_updated", "customer.payment_failed", "customer.payment_succeeded", "customer.plan_assigned", "customer.plan_changed"];
|
|
277
|
+
type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
|
|
278
|
+
type WebhookSource = "admin" | "api" | "user";
|
|
279
|
+
interface WebhookEndpointInput {
|
|
280
|
+
url: string;
|
|
281
|
+
events?: string[];
|
|
282
|
+
}
|
|
283
|
+
interface WebhookEndpoint {
|
|
284
|
+
id: string;
|
|
285
|
+
url: string;
|
|
286
|
+
events: string[] | null;
|
|
287
|
+
}
|
|
288
|
+
interface SendWebhookOptions {
|
|
289
|
+
type: string;
|
|
290
|
+
data?: Record<string, unknown>;
|
|
291
|
+
user?: string;
|
|
292
|
+
organization?: string;
|
|
293
|
+
role?: string;
|
|
294
|
+
permission?: string;
|
|
295
|
+
source?: WebhookSource;
|
|
296
|
+
ipAddress?: string;
|
|
297
|
+
to?: string;
|
|
298
|
+
duplicate?: number;
|
|
299
|
+
delayMs?: number;
|
|
300
|
+
invalid?: WebhookInvalidKind;
|
|
301
|
+
}
|
|
302
|
+
interface WebhookAttempt {
|
|
303
|
+
attempt: number;
|
|
304
|
+
status: number | null;
|
|
305
|
+
error: string | null;
|
|
306
|
+
durationMs: number;
|
|
307
|
+
}
|
|
308
|
+
interface WebhookDelivery {
|
|
309
|
+
webhookId: string;
|
|
310
|
+
eventId: string;
|
|
311
|
+
type: string;
|
|
312
|
+
url: string;
|
|
313
|
+
copy: number;
|
|
314
|
+
delivered: boolean;
|
|
315
|
+
attempts: WebhookAttempt[];
|
|
316
|
+
payload: Record<string, unknown>;
|
|
317
|
+
}
|
|
318
|
+
interface WebhookOptions {
|
|
319
|
+
retryDelaysMs?: number[];
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
}
|
|
322
|
+
declare class WebhookDispatcher {
|
|
323
|
+
private readonly testkit;
|
|
324
|
+
private readonly seed;
|
|
325
|
+
private endpoints;
|
|
326
|
+
private seededEndpoints;
|
|
327
|
+
private log;
|
|
328
|
+
private nextEndpoint;
|
|
329
|
+
private readonly retryDelaysMs;
|
|
330
|
+
private readonly timeoutMs;
|
|
331
|
+
constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
|
|
332
|
+
addEndpoint(input: WebhookEndpointInput): WebhookEndpoint;
|
|
333
|
+
removeEndpoint(id: string): boolean;
|
|
334
|
+
listEndpoints(): WebhookEndpoint[];
|
|
335
|
+
deliveries(): WebhookDelivery[];
|
|
336
|
+
reset(): void;
|
|
337
|
+
buildEvent(options: SendWebhookOptions): Record<string, unknown>;
|
|
338
|
+
send(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
339
|
+
private deliver;
|
|
340
|
+
private buildData;
|
|
341
|
+
emitForUser(type: "user.created" | "user.authenticated", user: KindeUser): void;
|
|
342
|
+
private userData;
|
|
343
|
+
private userPayload;
|
|
344
|
+
private organizationData;
|
|
345
|
+
private namedData;
|
|
346
|
+
private requireUser;
|
|
347
|
+
}
|
|
348
|
+
|
|
203
349
|
interface StartKindeTestkitOptions {
|
|
204
350
|
port?: number;
|
|
205
351
|
host?: string;
|
|
@@ -208,6 +354,7 @@ interface StartKindeTestkitOptions {
|
|
|
208
354
|
clientId?: string;
|
|
209
355
|
seed?: TestkitSeed;
|
|
210
356
|
allowPublic?: boolean;
|
|
357
|
+
webhooks?: WebhookOptions;
|
|
211
358
|
}
|
|
212
359
|
interface RunningKindeTestkit {
|
|
213
360
|
url: string;
|
|
@@ -216,6 +363,9 @@ interface RunningKindeTestkit {
|
|
|
216
363
|
jwksUri: string;
|
|
217
364
|
testkit: KindeTestkit;
|
|
218
365
|
seed: ResolvedSeed;
|
|
366
|
+
failures: FailureInjector;
|
|
367
|
+
webhooks: WebhookDispatcher;
|
|
368
|
+
reset(): void;
|
|
219
369
|
close(): Promise<void>;
|
|
220
370
|
}
|
|
221
371
|
declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
|
|
@@ -228,4 +378,32 @@ declare class TestkitError extends Error {
|
|
|
228
378
|
toString(): string;
|
|
229
379
|
}
|
|
230
380
|
|
|
231
|
-
|
|
381
|
+
type CheckStatus = "pass" | "warn" | "fail";
|
|
382
|
+
interface Check {
|
|
383
|
+
name: string;
|
|
384
|
+
status: CheckStatus;
|
|
385
|
+
detail: string;
|
|
386
|
+
}
|
|
387
|
+
interface TokenInspection {
|
|
388
|
+
kind: "access" | "id" | "m2m" | "unknown";
|
|
389
|
+
header: ProtectedHeaderParameters | null;
|
|
390
|
+
payload: JWTPayload | null;
|
|
391
|
+
checks: Check[];
|
|
392
|
+
}
|
|
393
|
+
declare function inspectToken(token: string, options?: {
|
|
394
|
+
issuerUrl?: string;
|
|
395
|
+
now?: number;
|
|
396
|
+
}): Promise<TokenInspection>;
|
|
397
|
+
|
|
398
|
+
interface DoctorReport {
|
|
399
|
+
url: string;
|
|
400
|
+
checks: Check[];
|
|
401
|
+
ok: boolean;
|
|
402
|
+
}
|
|
403
|
+
declare function runDoctor(options: {
|
|
404
|
+
url: string;
|
|
405
|
+
env: Record<string, string | undefined>;
|
|
406
|
+
}): Promise<DoctorReport>;
|
|
407
|
+
declare function parseEnvFile(text: string): Record<string, string>;
|
|
408
|
+
|
|
409
|
+
export { type ActiveFailure, type AuthenticatedScenario, BILLING_EVENT_TYPES, 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 SendWebhookOptions, type StartKindeTestkitOptions, TestkitError, type TestkitErrorCode, type TestkitSeed, type TokenInspection, type UnauthenticatedScenario, WEBHOOK_EVENT_TYPES, type WebhookAttempt, type WebhookDelivery, WebhookDispatcher, type WebhookEndpoint, type WebhookEndpointInput, type WebhookInvalidKind, type WebhookOptions, type WebhookSource, createKindeOrganization, createKindeToken, createKindeUser, createMembership, getDefaultTestkit, inspectToken, isAuthenticated, parseEnvFile, principalFromClaims, resetFactories, resolveSeed, runDoctor, scenario, seedScenario, startKindeTestkit, toKindeRole };
|