kinde-testkit 0.3.0 → 0.5.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 +113 -8
- package/dist/cli.js +1580 -118
- package/dist/index.cjs +1428 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -1
- package/dist/index.d.ts +235 -1
- package/dist/index.js +1421 -103
- package/dist/index.js.map +1 -1
- package/dist/playwright.d.ts +34 -0
- package/dist/playwright.js +4 -0
- package/dist/playwright.js.map +1 -1
- package/dist/vitest.d.ts +186 -0
- package/dist/vitest.js +1409 -103
- package/dist/vitest.js.map +1 -1
- package/package.json +4 -1
package/dist/playwright.d.ts
CHANGED
|
@@ -23,6 +23,39 @@ interface ActiveFailure {
|
|
|
23
23
|
hits: number;
|
|
24
24
|
}
|
|
25
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
|
+
}
|
|
58
|
+
|
|
26
59
|
interface KindeFixtureOptions {
|
|
27
60
|
issuer: string;
|
|
28
61
|
loginPath: string;
|
|
@@ -39,6 +72,7 @@ interface KindeFixture {
|
|
|
39
72
|
signOut(): Promise<void>;
|
|
40
73
|
injectFailure(rule: FailureRule): Promise<ActiveFailure>;
|
|
41
74
|
clearFailures(): Promise<void>;
|
|
75
|
+
sendWebhook(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
42
76
|
}
|
|
43
77
|
interface ManagedKindeFixture extends KindeFixture {
|
|
44
78
|
dispose(): Promise<void>;
|
package/dist/playwright.js
CHANGED
|
@@ -66,6 +66,10 @@ function createKindeFixture(page, options) {
|
|
|
66
66
|
await Promise.all([...injected].map((id) => control(`/testkit/failures/${id}`, { method: "DELETE" })));
|
|
67
67
|
injected.clear();
|
|
68
68
|
},
|
|
69
|
+
async sendWebhook(webhook) {
|
|
70
|
+
const response = await control("/testkit/webhooks", { method: "POST", body: JSON.stringify(webhook) });
|
|
71
|
+
return await response.json();
|
|
72
|
+
},
|
|
69
73
|
async dispose() {
|
|
70
74
|
if (injected.size > 0) await this.clearFailures();
|
|
71
75
|
}
|
package/dist/playwright.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/playwright.ts"],"sourcesContent":["import { test as base, expect, type Page } from \"@playwright/test\";\nimport type { ActiveFailure, FailureRule } from \"./failures.js\";\n\nexport interface KindeFixtureOptions {\n issuer: string;\n loginPath: string;\n logoutPath: string;\n}\n\nexport interface SignInOptions {\n org?: string;\n}\n\nexport interface KindeFixture {\n readonly issuer: string;\n readonly currentUser: string | null;\n signInAs(user: string, options?: SignInOptions): Promise<void>;\n switchOrganization(org: string): Promise<void>;\n signOut(): Promise<void>;\n injectFailure(rule: FailureRule): Promise<ActiveFailure>;\n clearFailures(): Promise<void>;\n}\n\ninterface ManagedKindeFixture extends KindeFixture {\n dispose(): Promise<void>;\n}\n\nexport interface KindeTestOptions {\n kindeIssuer: string;\n kindeLoginPath: string;\n kindeLogoutPath: string;\n}\n\nexport function createKindeFixture(page: Page, options: KindeFixtureOptions): ManagedKindeFixture {\n const issuer = new URL(options.issuer);\n const onIssuer = (url: URL) => url.origin === issuer.origin;\n let currentUser: string | null = null;\n const injected = new Set<string>();\n\n async function control(path: string, init: RequestInit = {}): Promise<Response> {\n const response = await fetch(`${issuer.origin}${path}`, {\n ...init,\n headers: { \"content-type\": \"application/json\", ...(init.headers ?? {}) },\n });\n if (!response.ok && response.status !== 404) {\n const body = (await response.json().catch(() => ({}))) as { error_description?: string };\n throw new Error(body.error_description ?? `kinde-testkit answered ${response.status} for ${path}.`);\n }\n return response;\n }\n\n async function signInAs(user: string, signIn: SignInOptions = {}): Promise<void> {\n const params = new URLSearchParams({ login_hint: user });\n if (signIn.org) params.set(\"org_code\", signIn.org);\n await page.goto(`${options.loginPath}?${params}`);\n\n if (!(onIssuer(new URL(page.url())) && new URL(page.url()).pathname === \"/oauth2/auth\")) {\n throw new Error(\n `Expected ${options.loginPath} to redirect to the kinde-testkit sign-in page at ${issuer.origin}, but the browser is at ${page.url()}. Check that the app's KINDE_ISSUER_URL is ${issuer.origin}.`,\n );\n }\n\n await page.getByLabel(\"Email\").fill(user);\n await page.getByRole(\"button\", { name: \"Continue\", exact: true }).click();\n await page.waitForURL((url) => !(onIssuer(url) && url.pathname === \"/oauth2/auth\"));\n\n const landed = new URL(page.url());\n if (onIssuer(landed)) {\n const alert = page.getByRole(\"alert\");\n if (await alert.count()) {\n throw new Error(`kinde-testkit refused the sign-in: ${(await alert.innerText()).trim()}`);\n }\n if (await page.getByRole(\"heading\", { name: \"Choose an organization\" }).count()) {\n throw new Error(`${user} belongs to more than one organization. Pass one with signInAs(\"${user}\", { org: \"org_...\" }).`);\n }\n throw new Error(`Sign-in stopped on ${page.url()}.`);\n }\n\n await page.waitForURL((url) => !onIssuer(url) && !url.pathname.endsWith(\"/kinde_callback\"));\n currentUser = user;\n }\n\n return {\n issuer: issuer.origin,\n get currentUser() {\n return currentUser;\n },\n signInAs,\n async switchOrganization(org: string) {\n if (!currentUser) throw new Error(\"Call signInAs() before switchOrganization().\");\n await signInAs(currentUser, { org });\n },\n async signOut() {\n await page.goto(options.logoutPath);\n currentUser = null;\n },\n async injectFailure(rule: FailureRule) {\n const response = await control(\"/testkit/failures\", { method: \"POST\", body: JSON.stringify(rule) });\n const failure = (await response.json()) as ActiveFailure;\n injected.add(failure.id);\n return failure;\n },\n async clearFailures() {\n await Promise.all([...injected].map((id) => control(`/testkit/failures/${id}`, { method: \"DELETE\" })));\n injected.clear();\n },\n async dispose() {\n if (injected.size > 0) await this.clearFailures();\n },\n };\n}\n\nexport const test = base.extend<KindeTestOptions & { kinde: KindeFixture }>({\n kindeIssuer: [process.env.KINDE_ISSUER_URL ?? \"http://localhost:4400\", { option: true }],\n kindeLoginPath: [\"/api/auth/login\", { option: true }],\n kindeLogoutPath: [\"/api/auth/logout\", { option: true }],\n kinde: async ({ page, kindeIssuer, kindeLoginPath, kindeLogoutPath }, use) => {\n const fixture = createKindeFixture(page, {\n issuer: kindeIssuer,\n loginPath: kindeLoginPath,\n logoutPath: kindeLogoutPath,\n });\n await use(fixture);\n await fixture.dispose();\n },\n});\n\nexport { expect };\n"],"mappings":";AAAA,SAAS,QAAQ,MAAM,cAAyB;
|
|
1
|
+
{"version":3,"sources":["../src/playwright.ts"],"sourcesContent":["import { test as base, expect, type Page } from \"@playwright/test\";\nimport type { ActiveFailure, FailureRule } from \"./failures.js\";\nimport type { SendWebhookOptions, WebhookDelivery } from \"./webhooks.js\";\n\nexport interface KindeFixtureOptions {\n issuer: string;\n loginPath: string;\n logoutPath: string;\n}\n\nexport interface SignInOptions {\n org?: string;\n}\n\nexport interface KindeFixture {\n readonly issuer: string;\n readonly currentUser: string | null;\n signInAs(user: string, options?: SignInOptions): Promise<void>;\n switchOrganization(org: string): Promise<void>;\n signOut(): Promise<void>;\n injectFailure(rule: FailureRule): Promise<ActiveFailure>;\n clearFailures(): Promise<void>;\n sendWebhook(options: SendWebhookOptions): Promise<WebhookDelivery[]>;\n}\n\ninterface ManagedKindeFixture extends KindeFixture {\n dispose(): Promise<void>;\n}\n\nexport interface KindeTestOptions {\n kindeIssuer: string;\n kindeLoginPath: string;\n kindeLogoutPath: string;\n}\n\nexport function createKindeFixture(page: Page, options: KindeFixtureOptions): ManagedKindeFixture {\n const issuer = new URL(options.issuer);\n const onIssuer = (url: URL) => url.origin === issuer.origin;\n let currentUser: string | null = null;\n const injected = new Set<string>();\n\n async function control(path: string, init: RequestInit = {}): Promise<Response> {\n const response = await fetch(`${issuer.origin}${path}`, {\n ...init,\n headers: { \"content-type\": \"application/json\", ...(init.headers ?? {}) },\n });\n if (!response.ok && response.status !== 404) {\n const body = (await response.json().catch(() => ({}))) as { error_description?: string };\n throw new Error(body.error_description ?? `kinde-testkit answered ${response.status} for ${path}.`);\n }\n return response;\n }\n\n async function signInAs(user: string, signIn: SignInOptions = {}): Promise<void> {\n const params = new URLSearchParams({ login_hint: user });\n if (signIn.org) params.set(\"org_code\", signIn.org);\n await page.goto(`${options.loginPath}?${params}`);\n\n if (!(onIssuer(new URL(page.url())) && new URL(page.url()).pathname === \"/oauth2/auth\")) {\n throw new Error(\n `Expected ${options.loginPath} to redirect to the kinde-testkit sign-in page at ${issuer.origin}, but the browser is at ${page.url()}. Check that the app's KINDE_ISSUER_URL is ${issuer.origin}.`,\n );\n }\n\n await page.getByLabel(\"Email\").fill(user);\n await page.getByRole(\"button\", { name: \"Continue\", exact: true }).click();\n await page.waitForURL((url) => !(onIssuer(url) && url.pathname === \"/oauth2/auth\"));\n\n const landed = new URL(page.url());\n if (onIssuer(landed)) {\n const alert = page.getByRole(\"alert\");\n if (await alert.count()) {\n throw new Error(`kinde-testkit refused the sign-in: ${(await alert.innerText()).trim()}`);\n }\n if (await page.getByRole(\"heading\", { name: \"Choose an organization\" }).count()) {\n throw new Error(`${user} belongs to more than one organization. Pass one with signInAs(\"${user}\", { org: \"org_...\" }).`);\n }\n throw new Error(`Sign-in stopped on ${page.url()}.`);\n }\n\n await page.waitForURL((url) => !onIssuer(url) && !url.pathname.endsWith(\"/kinde_callback\"));\n currentUser = user;\n }\n\n return {\n issuer: issuer.origin,\n get currentUser() {\n return currentUser;\n },\n signInAs,\n async switchOrganization(org: string) {\n if (!currentUser) throw new Error(\"Call signInAs() before switchOrganization().\");\n await signInAs(currentUser, { org });\n },\n async signOut() {\n await page.goto(options.logoutPath);\n currentUser = null;\n },\n async injectFailure(rule: FailureRule) {\n const response = await control(\"/testkit/failures\", { method: \"POST\", body: JSON.stringify(rule) });\n const failure = (await response.json()) as ActiveFailure;\n injected.add(failure.id);\n return failure;\n },\n async clearFailures() {\n await Promise.all([...injected].map((id) => control(`/testkit/failures/${id}`, { method: \"DELETE\" })));\n injected.clear();\n },\n async sendWebhook(webhook: SendWebhookOptions) {\n const response = await control(\"/testkit/webhooks\", { method: \"POST\", body: JSON.stringify(webhook) });\n return (await response.json()) as WebhookDelivery[];\n },\n async dispose() {\n if (injected.size > 0) await this.clearFailures();\n },\n };\n}\n\nexport const test = base.extend<KindeTestOptions & { kinde: KindeFixture }>({\n kindeIssuer: [process.env.KINDE_ISSUER_URL ?? \"http://localhost:4400\", { option: true }],\n kindeLoginPath: [\"/api/auth/login\", { option: true }],\n kindeLogoutPath: [\"/api/auth/logout\", { option: true }],\n kinde: async ({ page, kindeIssuer, kindeLoginPath, kindeLogoutPath }, use) => {\n const fixture = createKindeFixture(page, {\n issuer: kindeIssuer,\n loginPath: kindeLoginPath,\n logoutPath: kindeLogoutPath,\n });\n await use(fixture);\n await fixture.dispose();\n },\n});\n\nexport { expect };\n"],"mappings":";AAAA,SAAS,QAAQ,MAAM,cAAyB;AAmCzC,SAAS,mBAAmB,MAAY,SAAmD;AAChG,QAAM,SAAS,IAAI,IAAI,QAAQ,MAAM;AACrC,QAAM,WA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AAS,CAAC,CAAC,CAAC;AACrG,eAAS,MAAM;AAAA,IACjB;AAAA,IACA,MAAM,YAAY,SAA6B;AAC7C,YAAM,WAAW,MAAM,QAAQ,qBAAqB,EAAE,QAAQ,QAAQ,MAAM,KAAK,UAAU,OAAO,EAAE,CAAC;AACrG,aAAQ,MAAM,SAAS,KAAK;AAAA,IAC9B;AAAA,IACA,MAAM,UAAU;AACd,UAAI,SAAS,OAAO,EAAG,OAAM,KAAK,cAAc;AAAA,IAClD;AAAA,EACF;AACF;AAEO,IAAM,OAAO,KAAK,OAAmD;AAAA,EAC1E,aAAa,CAAC,QAAQ,IAAI,oBAAoB,yBAAyB,EAAE,QAAQ,KAAK,CAAC;AAAA,EACvF,gBAAgB,CAAC,mBAAmB,EAAE,QAAQ,KAAK,CAAC;AAAA,EACpD,iBAAiB,CAAC,oBAAoB,EAAE,QAAQ,KAAK,CAAC;AAAA,EACtD,OAAO,OAAO,EAAE,MAAM,aAAa,gBAAgB,gBAAgB,GAAG,QAAQ;AAC5E,UAAM,UAAU,mBAAmB,MAAM;AAAA,MACvC,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,YAAY;AAAA,IACd,CAAC;AACD,UAAM,IAAI,OAAO;AACjB,UAAM,QAAQ,QAAQ;AAAA,EACxB;AACF,CAAC;","names":[]}
|
package/dist/vitest.d.ts
CHANGED
|
@@ -19,6 +19,21 @@ 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
|
+
}
|
|
31
|
+
interface KindeMembership {
|
|
32
|
+
userId: string;
|
|
33
|
+
organizationCode: string;
|
|
34
|
+
roles: string[];
|
|
35
|
+
permissions: string[];
|
|
36
|
+
}
|
|
22
37
|
interface AuthenticatedScenario {
|
|
23
38
|
kind: "authenticated";
|
|
24
39
|
user: KindeUser;
|
|
@@ -114,6 +129,7 @@ declare class KindeTestkit {
|
|
|
114
129
|
idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
|
|
115
130
|
headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
|
|
116
131
|
principalFor(scenario: Scenario): KindePrincipal | null;
|
|
132
|
+
signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
|
|
117
133
|
private sign;
|
|
118
134
|
private stranger;
|
|
119
135
|
}
|
|
@@ -130,6 +146,7 @@ interface TestkitSeed {
|
|
|
130
146
|
familyName?: string | null;
|
|
131
147
|
picture?: string | null;
|
|
132
148
|
claims?: Record<string, unknown>;
|
|
149
|
+
properties?: Record<string, string | number | boolean>;
|
|
133
150
|
}>;
|
|
134
151
|
organizations?: Array<{
|
|
135
152
|
code: string;
|
|
@@ -142,6 +159,43 @@ interface TestkitSeed {
|
|
|
142
159
|
roles?: string[];
|
|
143
160
|
permissions?: string[];
|
|
144
161
|
}>;
|
|
162
|
+
webhooks?: Array<{
|
|
163
|
+
url: string;
|
|
164
|
+
events?: string[];
|
|
165
|
+
}>;
|
|
166
|
+
roles?: Array<{
|
|
167
|
+
key: string;
|
|
168
|
+
name?: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
permissions?: string[];
|
|
171
|
+
isDefault?: boolean;
|
|
172
|
+
}>;
|
|
173
|
+
featureFlags?: Array<{
|
|
174
|
+
key: string;
|
|
175
|
+
name?: string;
|
|
176
|
+
type?: "boolean" | "string" | "integer";
|
|
177
|
+
value: boolean | string | number;
|
|
178
|
+
organizations?: Record<string, boolean | string | number>;
|
|
179
|
+
}>;
|
|
180
|
+
plans?: Array<{
|
|
181
|
+
key: string;
|
|
182
|
+
name?: string;
|
|
183
|
+
subscribers?: string[];
|
|
184
|
+
entitlements?: Array<{
|
|
185
|
+
featureKey: string;
|
|
186
|
+
featureName?: string;
|
|
187
|
+
priceName?: string;
|
|
188
|
+
fixedCharge?: number | null;
|
|
189
|
+
unitAmount?: number | null;
|
|
190
|
+
limitMax?: number | null;
|
|
191
|
+
limitMin?: number | null;
|
|
192
|
+
}>;
|
|
193
|
+
}>;
|
|
194
|
+
permissions?: Array<{
|
|
195
|
+
key: string;
|
|
196
|
+
name?: string;
|
|
197
|
+
description?: string;
|
|
198
|
+
}>;
|
|
145
199
|
applications?: Array<{
|
|
146
200
|
clientId: string;
|
|
147
201
|
clientSecret?: string;
|
|
@@ -152,6 +206,59 @@ interface TestkitSeed {
|
|
|
152
206
|
audience?: string | string[];
|
|
153
207
|
}>;
|
|
154
208
|
}
|
|
209
|
+
interface ResolvedSeed {
|
|
210
|
+
users: KindeUser[];
|
|
211
|
+
organizations: KindeOrganization[];
|
|
212
|
+
memberships: KindeMembership[];
|
|
213
|
+
applications: KindeApplication[];
|
|
214
|
+
webhooks: Array<{
|
|
215
|
+
url: string;
|
|
216
|
+
events?: string[];
|
|
217
|
+
}>;
|
|
218
|
+
roles: SeedRole[];
|
|
219
|
+
permissions: SeedPermission[];
|
|
220
|
+
featureFlags: SeedFeatureFlag[];
|
|
221
|
+
plans: SeedPlan[];
|
|
222
|
+
userProperties: Record<string, Record<string, string | number | boolean>>;
|
|
223
|
+
}
|
|
224
|
+
interface SeedFeatureFlag {
|
|
225
|
+
id: string;
|
|
226
|
+
key: string;
|
|
227
|
+
name: string;
|
|
228
|
+
type: "boolean" | "string" | "integer";
|
|
229
|
+
value: boolean | string | number;
|
|
230
|
+
organizations: Record<string, boolean | string | number>;
|
|
231
|
+
}
|
|
232
|
+
interface SeedPlan {
|
|
233
|
+
key: string;
|
|
234
|
+
name: string;
|
|
235
|
+
subscribers: string[];
|
|
236
|
+
subscribedOn: string;
|
|
237
|
+
entitlements: Array<{
|
|
238
|
+
id: string;
|
|
239
|
+
featureKey: string;
|
|
240
|
+
featureName: string;
|
|
241
|
+
priceName: string;
|
|
242
|
+
fixedCharge: number | null;
|
|
243
|
+
unitAmount: number | null;
|
|
244
|
+
limitMax: number | null;
|
|
245
|
+
limitMin: number | null;
|
|
246
|
+
}>;
|
|
247
|
+
}
|
|
248
|
+
interface SeedRole {
|
|
249
|
+
id: string;
|
|
250
|
+
key: string;
|
|
251
|
+
name: string;
|
|
252
|
+
description: string | null;
|
|
253
|
+
isDefault: boolean;
|
|
254
|
+
permissions: string[];
|
|
255
|
+
}
|
|
256
|
+
interface SeedPermission {
|
|
257
|
+
id: string;
|
|
258
|
+
key: string;
|
|
259
|
+
name: string;
|
|
260
|
+
description: string | null;
|
|
261
|
+
}
|
|
155
262
|
|
|
156
263
|
interface FailureRule {
|
|
157
264
|
path: string;
|
|
@@ -183,6 +290,80 @@ declare class FailureInjector {
|
|
|
183
290
|
take(method: string, path: string): ActiveFailure | null;
|
|
184
291
|
}
|
|
185
292
|
|
|
293
|
+
type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
|
|
294
|
+
type WebhookSource = "admin" | "api" | "user";
|
|
295
|
+
interface WebhookEndpointInput {
|
|
296
|
+
url: string;
|
|
297
|
+
events?: string[];
|
|
298
|
+
}
|
|
299
|
+
interface WebhookEndpoint {
|
|
300
|
+
id: string;
|
|
301
|
+
url: string;
|
|
302
|
+
events: string[] | null;
|
|
303
|
+
}
|
|
304
|
+
interface SendWebhookOptions {
|
|
305
|
+
type: string;
|
|
306
|
+
data?: Record<string, unknown>;
|
|
307
|
+
user?: string;
|
|
308
|
+
organization?: string;
|
|
309
|
+
role?: string;
|
|
310
|
+
permission?: string;
|
|
311
|
+
source?: WebhookSource;
|
|
312
|
+
ipAddress?: string;
|
|
313
|
+
to?: string;
|
|
314
|
+
duplicate?: number;
|
|
315
|
+
delayMs?: number;
|
|
316
|
+
invalid?: WebhookInvalidKind;
|
|
317
|
+
}
|
|
318
|
+
interface WebhookAttempt {
|
|
319
|
+
attempt: number;
|
|
320
|
+
status: number | null;
|
|
321
|
+
error: string | null;
|
|
322
|
+
durationMs: number;
|
|
323
|
+
}
|
|
324
|
+
interface WebhookDelivery {
|
|
325
|
+
webhookId: string;
|
|
326
|
+
eventId: string;
|
|
327
|
+
type: string;
|
|
328
|
+
url: string;
|
|
329
|
+
copy: number;
|
|
330
|
+
delivered: boolean;
|
|
331
|
+
attempts: WebhookAttempt[];
|
|
332
|
+
payload: Record<string, unknown>;
|
|
333
|
+
}
|
|
334
|
+
interface WebhookOptions {
|
|
335
|
+
retryDelaysMs?: number[];
|
|
336
|
+
timeoutMs?: number;
|
|
337
|
+
}
|
|
338
|
+
declare class WebhookDispatcher {
|
|
339
|
+
private readonly testkit;
|
|
340
|
+
private readonly seed;
|
|
341
|
+
private endpoints;
|
|
342
|
+
private seededEndpoints;
|
|
343
|
+
private log;
|
|
344
|
+
private nextEndpoint;
|
|
345
|
+
private readonly retryDelaysMs;
|
|
346
|
+
private readonly timeoutMs;
|
|
347
|
+
constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
|
|
348
|
+
addEndpoint(input: WebhookEndpointInput): WebhookEndpoint;
|
|
349
|
+
removeEndpoint(id: string): boolean;
|
|
350
|
+
listEndpoints(): WebhookEndpoint[];
|
|
351
|
+
deliveries(): WebhookDelivery[];
|
|
352
|
+
reset(): void;
|
|
353
|
+
buildEvent(options: SendWebhookOptions): Record<string, unknown>;
|
|
354
|
+
send(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
355
|
+
private deliver;
|
|
356
|
+
private buildData;
|
|
357
|
+
emit(type: string, data: Record<string, unknown>, source?: WebhookSource): void;
|
|
358
|
+
userEventData(user: KindeUser): Record<string, unknown>;
|
|
359
|
+
emitForUser(type: "user.created" | "user.authenticated", user: KindeUser): void;
|
|
360
|
+
private userData;
|
|
361
|
+
private userPayload;
|
|
362
|
+
private organizationData;
|
|
363
|
+
private namedData;
|
|
364
|
+
private requireUser;
|
|
365
|
+
}
|
|
366
|
+
|
|
186
367
|
interface StartKindeTestkitOptions {
|
|
187
368
|
port?: number;
|
|
188
369
|
host?: string;
|
|
@@ -191,6 +372,10 @@ interface StartKindeTestkitOptions {
|
|
|
191
372
|
clientId?: string;
|
|
192
373
|
seed?: TestkitSeed;
|
|
193
374
|
allowPublic?: boolean;
|
|
375
|
+
webhooks?: WebhookOptions;
|
|
376
|
+
https?: boolean | {
|
|
377
|
+
certDirectory?: string;
|
|
378
|
+
};
|
|
194
379
|
}
|
|
195
380
|
|
|
196
381
|
interface KindeTestAuth {
|
|
@@ -212,6 +397,7 @@ interface KindeTestkitHandle {
|
|
|
212
397
|
readonly jwksUri: string;
|
|
213
398
|
readonly testkit: KindeTestkit;
|
|
214
399
|
readonly failures: FailureInjector;
|
|
400
|
+
readonly webhooks: WebhookDispatcher;
|
|
215
401
|
auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
|
|
216
402
|
reset(): void;
|
|
217
403
|
}
|