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/playwright.d.ts
CHANGED
|
@@ -2,6 +2,60 @@ import * as playwright_test from 'playwright/test';
|
|
|
2
2
|
import { Page } from '@playwright/test';
|
|
3
3
|
export { expect } from '@playwright/test';
|
|
4
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
|
+
}
|
|
58
|
+
|
|
5
59
|
interface KindeFixtureOptions {
|
|
6
60
|
issuer: string;
|
|
7
61
|
loginPath: string;
|
|
@@ -16,13 +70,19 @@ interface KindeFixture {
|
|
|
16
70
|
signInAs(user: string, options?: SignInOptions): Promise<void>;
|
|
17
71
|
switchOrganization(org: string): Promise<void>;
|
|
18
72
|
signOut(): Promise<void>;
|
|
73
|
+
injectFailure(rule: FailureRule): Promise<ActiveFailure>;
|
|
74
|
+
clearFailures(): Promise<void>;
|
|
75
|
+
sendWebhook(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
76
|
+
}
|
|
77
|
+
interface ManagedKindeFixture extends KindeFixture {
|
|
78
|
+
dispose(): Promise<void>;
|
|
19
79
|
}
|
|
20
80
|
interface KindeTestOptions {
|
|
21
81
|
kindeIssuer: string;
|
|
22
82
|
kindeLoginPath: string;
|
|
23
83
|
kindeLogoutPath: string;
|
|
24
84
|
}
|
|
25
|
-
declare function createKindeFixture(page: Page, options: KindeFixtureOptions):
|
|
85
|
+
declare function createKindeFixture(page: Page, options: KindeFixtureOptions): ManagedKindeFixture;
|
|
26
86
|
declare const test: playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & KindeTestOptions & {
|
|
27
87
|
kinde: KindeFixture;
|
|
28
88
|
}, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
|
package/dist/playwright.js
CHANGED
|
@@ -4,6 +4,18 @@ function createKindeFixture(page, options) {
|
|
|
4
4
|
const issuer = new URL(options.issuer);
|
|
5
5
|
const onIssuer = (url) => url.origin === issuer.origin;
|
|
6
6
|
let currentUser = null;
|
|
7
|
+
const injected = /* @__PURE__ */ new Set();
|
|
8
|
+
async function control(path, init = {}) {
|
|
9
|
+
const response = await fetch(`${issuer.origin}${path}`, {
|
|
10
|
+
...init,
|
|
11
|
+
headers: { "content-type": "application/json", ...init.headers ?? {} }
|
|
12
|
+
});
|
|
13
|
+
if (!response.ok && response.status !== 404) {
|
|
14
|
+
const body = await response.json().catch(() => ({}));
|
|
15
|
+
throw new Error(body.error_description ?? `kinde-testkit answered ${response.status} for ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
7
19
|
async function signInAs(user, signIn = {}) {
|
|
8
20
|
const params = new URLSearchParams({ login_hint: user });
|
|
9
21
|
if (signIn.org) params.set("org_code", signIn.org);
|
|
@@ -43,6 +55,23 @@ function createKindeFixture(page, options) {
|
|
|
43
55
|
async signOut() {
|
|
44
56
|
await page.goto(options.logoutPath);
|
|
45
57
|
currentUser = null;
|
|
58
|
+
},
|
|
59
|
+
async injectFailure(rule) {
|
|
60
|
+
const response = await control("/testkit/failures", { method: "POST", body: JSON.stringify(rule) });
|
|
61
|
+
const failure = await response.json();
|
|
62
|
+
injected.add(failure.id);
|
|
63
|
+
return failure;
|
|
64
|
+
},
|
|
65
|
+
async clearFailures() {
|
|
66
|
+
await Promise.all([...injected].map((id) => control(`/testkit/failures/${id}`, { method: "DELETE" })));
|
|
67
|
+
injected.clear();
|
|
68
|
+
},
|
|
69
|
+
async sendWebhook(webhook) {
|
|
70
|
+
const response = await control("/testkit/webhooks", { method: "POST", body: JSON.stringify(webhook) });
|
|
71
|
+
return await response.json();
|
|
72
|
+
},
|
|
73
|
+
async dispose() {
|
|
74
|
+
if (injected.size > 0) await this.clearFailures();
|
|
46
75
|
}
|
|
47
76
|
};
|
|
48
77
|
}
|
|
@@ -51,13 +80,13 @@ var test = base.extend({
|
|
|
51
80
|
kindeLoginPath: ["/api/auth/login", { option: true }],
|
|
52
81
|
kindeLogoutPath: ["/api/auth/logout", { option: true }],
|
|
53
82
|
kinde: async ({ page, kindeIssuer, kindeLoginPath, kindeLogoutPath }, use) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
83
|
+
const fixture = createKindeFixture(page, {
|
|
84
|
+
issuer: kindeIssuer,
|
|
85
|
+
loginPath: kindeLoginPath,
|
|
86
|
+
logoutPath: kindeLogoutPath
|
|
87
|
+
});
|
|
88
|
+
await use(fixture);
|
|
89
|
+
await fixture.dispose();
|
|
61
90
|
}
|
|
62
91
|
});
|
|
63
92
|
export {
|
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\";\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}\n\nexport interface KindeTestOptions {\n kindeIssuer: string;\n kindeLoginPath: string;\n kindeLogoutPath: string;\n}\n\nexport function createKindeFixture(page: Page, options: KindeFixtureOptions):
|
|
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,WAAW,CAAC,QAAa,IAAI,WAAW,OAAO;AACrD,MAAI,cAA6B;AACjC,QAAM,WAAW,oBAAI,IAAY;AAEjC,iBAAe,QAAQ,MAAc,OAAoB,CAAC,GAAsB;AAC9E,UAAM,WAAW,MAAM,MAAM,GAAG,OAAO,MAAM,GAAG,IAAI,IAAI;AAAA,MACtD,GAAG;AAAA,MACH,SAAS,EAAE,gBAAgB,oBAAoB,GAAI,KAAK,WAAW,CAAC,EAAG;AAAA,IACzE,CAAC;AACD,QAAI,CAAC,SAAS,MAAM,SAAS,WAAW,KAAK;AAC3C,YAAM,OAAQ,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACpD,YAAM,IAAI,MAAM,KAAK,qBAAqB,0BAA0B,SAAS,MAAM,QAAQ,IAAI,GAAG;AAAA,IACpG;AACA,WAAO;AAAA,EACT;AAEA,iBAAe,SAAS,MAAc,SAAwB,CAAC,GAAkB;AAC/E,UAAM,SAAS,IAAI,gBAAgB,EAAE,YAAY,KAAK,CAAC;AACvD,QAAI,OAAO,IAAK,QAAO,IAAI,YAAY,OAAO,GAAG;AACjD,UAAM,KAAK,KAAK,GAAG,QAAQ,SAAS,IAAI,MAAM,EAAE;AAEhD,QAAI,EAAE,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,KAAK,IAAI,CAAC,EAAE,aAAa,iBAAiB;AACvF,YAAM,IAAI;AAAA,QACR,YAAY,QAAQ,SAAS,qDAAqD,OAAO,MAAM,2BAA2B,KAAK,IAAI,CAAC,8CAA8C,OAAO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
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;
|
|
@@ -32,6 +47,7 @@ interface UnauthenticatedScenario {
|
|
|
32
47
|
}
|
|
33
48
|
type Scenario = AuthenticatedScenario | UnauthenticatedScenario;
|
|
34
49
|
interface KindePrincipal {
|
|
50
|
+
type: "user" | "machine";
|
|
35
51
|
subject: string;
|
|
36
52
|
issuer: string;
|
|
37
53
|
organization: {
|
|
@@ -71,6 +87,17 @@ interface KindeTestkitOptions {
|
|
|
71
87
|
now?: () => number;
|
|
72
88
|
}
|
|
73
89
|
type ScenarioTokenOverrides = Pick<KindeTokenOptions, "expiresIn" | "invalid" | "scopes" | "featureFlags" | "claims" | "authMethods" | "authTime" | "clientId" | "audience">;
|
|
90
|
+
interface M2MTokenOptions {
|
|
91
|
+
clientId?: string;
|
|
92
|
+
organizationCode?: string | null;
|
|
93
|
+
scopes?: string[];
|
|
94
|
+
grantedScopes?: string[];
|
|
95
|
+
audience?: string[];
|
|
96
|
+
permissions?: string[];
|
|
97
|
+
claims?: Record<string, unknown>;
|
|
98
|
+
expiresIn?: Duration;
|
|
99
|
+
invalid?: InvalidTokenKind;
|
|
100
|
+
}
|
|
74
101
|
interface IdTokenOptions {
|
|
75
102
|
expiresIn?: Duration;
|
|
76
103
|
authMethods?: string[];
|
|
@@ -97,10 +124,12 @@ declare class KindeTestkit {
|
|
|
97
124
|
keys: JWK[];
|
|
98
125
|
};
|
|
99
126
|
token(options?: KindeTokenOptions): Promise<string>;
|
|
127
|
+
m2mToken(options?: M2MTokenOptions): Promise<string>;
|
|
100
128
|
tokenFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<string | null>;
|
|
101
129
|
idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
|
|
102
130
|
headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
|
|
103
131
|
principalFor(scenario: Scenario): KindePrincipal | null;
|
|
132
|
+
signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
|
|
104
133
|
private sign;
|
|
105
134
|
private stranger;
|
|
106
135
|
}
|
|
@@ -129,6 +158,131 @@ interface TestkitSeed {
|
|
|
129
158
|
roles?: string[];
|
|
130
159
|
permissions?: string[];
|
|
131
160
|
}>;
|
|
161
|
+
webhooks?: Array<{
|
|
162
|
+
url: string;
|
|
163
|
+
events?: string[];
|
|
164
|
+
}>;
|
|
165
|
+
applications?: Array<{
|
|
166
|
+
clientId: string;
|
|
167
|
+
clientSecret?: string;
|
|
168
|
+
name?: string;
|
|
169
|
+
organization?: string;
|
|
170
|
+
scopes?: string[];
|
|
171
|
+
permissions?: string[];
|
|
172
|
+
audience?: string | string[];
|
|
173
|
+
}>;
|
|
174
|
+
}
|
|
175
|
+
interface ResolvedSeed {
|
|
176
|
+
users: KindeUser[];
|
|
177
|
+
organizations: KindeOrganization[];
|
|
178
|
+
memberships: KindeMembership[];
|
|
179
|
+
applications: KindeApplication[];
|
|
180
|
+
webhooks: Array<{
|
|
181
|
+
url: string;
|
|
182
|
+
events?: string[];
|
|
183
|
+
}>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface FailureRule {
|
|
187
|
+
path: string;
|
|
188
|
+
method?: string;
|
|
189
|
+
status?: number;
|
|
190
|
+
delayMs?: number;
|
|
191
|
+
hang?: boolean;
|
|
192
|
+
times?: number;
|
|
193
|
+
retryAfter?: number;
|
|
194
|
+
}
|
|
195
|
+
interface ActiveFailure {
|
|
196
|
+
id: string;
|
|
197
|
+
path: string;
|
|
198
|
+
method: string | null;
|
|
199
|
+
status: number | null;
|
|
200
|
+
delayMs: number;
|
|
201
|
+
hang: boolean;
|
|
202
|
+
remaining: number | null;
|
|
203
|
+
retryAfter: number;
|
|
204
|
+
hits: number;
|
|
205
|
+
}
|
|
206
|
+
declare class FailureInjector {
|
|
207
|
+
private rules;
|
|
208
|
+
private nextId;
|
|
209
|
+
add(rule: FailureRule): ActiveFailure;
|
|
210
|
+
remove(id: string): boolean;
|
|
211
|
+
clear(): void;
|
|
212
|
+
list(): ActiveFailure[];
|
|
213
|
+
take(method: string, path: string): ActiveFailure | null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
type WebhookInvalidKind = "bad-signature" | "unknown-key" | "unsigned" | "stale";
|
|
217
|
+
type WebhookSource = "admin" | "api" | "user";
|
|
218
|
+
interface WebhookEndpointInput {
|
|
219
|
+
url: string;
|
|
220
|
+
events?: string[];
|
|
221
|
+
}
|
|
222
|
+
interface WebhookEndpoint {
|
|
223
|
+
id: string;
|
|
224
|
+
url: string;
|
|
225
|
+
events: string[] | null;
|
|
226
|
+
}
|
|
227
|
+
interface SendWebhookOptions {
|
|
228
|
+
type: string;
|
|
229
|
+
data?: Record<string, unknown>;
|
|
230
|
+
user?: string;
|
|
231
|
+
organization?: string;
|
|
232
|
+
role?: string;
|
|
233
|
+
permission?: string;
|
|
234
|
+
source?: WebhookSource;
|
|
235
|
+
ipAddress?: string;
|
|
236
|
+
to?: string;
|
|
237
|
+
duplicate?: number;
|
|
238
|
+
delayMs?: number;
|
|
239
|
+
invalid?: WebhookInvalidKind;
|
|
240
|
+
}
|
|
241
|
+
interface WebhookAttempt {
|
|
242
|
+
attempt: number;
|
|
243
|
+
status: number | null;
|
|
244
|
+
error: string | null;
|
|
245
|
+
durationMs: number;
|
|
246
|
+
}
|
|
247
|
+
interface WebhookDelivery {
|
|
248
|
+
webhookId: string;
|
|
249
|
+
eventId: string;
|
|
250
|
+
type: string;
|
|
251
|
+
url: string;
|
|
252
|
+
copy: number;
|
|
253
|
+
delivered: boolean;
|
|
254
|
+
attempts: WebhookAttempt[];
|
|
255
|
+
payload: Record<string, unknown>;
|
|
256
|
+
}
|
|
257
|
+
interface WebhookOptions {
|
|
258
|
+
retryDelaysMs?: number[];
|
|
259
|
+
timeoutMs?: number;
|
|
260
|
+
}
|
|
261
|
+
declare class WebhookDispatcher {
|
|
262
|
+
private readonly testkit;
|
|
263
|
+
private readonly seed;
|
|
264
|
+
private endpoints;
|
|
265
|
+
private seededEndpoints;
|
|
266
|
+
private log;
|
|
267
|
+
private nextEndpoint;
|
|
268
|
+
private readonly retryDelaysMs;
|
|
269
|
+
private readonly timeoutMs;
|
|
270
|
+
constructor(testkit: KindeTestkit, seed: ResolvedSeed, endpoints?: WebhookEndpointInput[], options?: WebhookOptions);
|
|
271
|
+
addEndpoint(input: WebhookEndpointInput): WebhookEndpoint;
|
|
272
|
+
removeEndpoint(id: string): boolean;
|
|
273
|
+
listEndpoints(): WebhookEndpoint[];
|
|
274
|
+
deliveries(): WebhookDelivery[];
|
|
275
|
+
reset(): void;
|
|
276
|
+
buildEvent(options: SendWebhookOptions): Record<string, unknown>;
|
|
277
|
+
send(options: SendWebhookOptions): Promise<WebhookDelivery[]>;
|
|
278
|
+
private deliver;
|
|
279
|
+
private buildData;
|
|
280
|
+
emitForUser(type: "user.created" | "user.authenticated", user: KindeUser): void;
|
|
281
|
+
private userData;
|
|
282
|
+
private userPayload;
|
|
283
|
+
private organizationData;
|
|
284
|
+
private namedData;
|
|
285
|
+
private requireUser;
|
|
132
286
|
}
|
|
133
287
|
|
|
134
288
|
interface StartKindeTestkitOptions {
|
|
@@ -139,6 +293,7 @@ interface StartKindeTestkitOptions {
|
|
|
139
293
|
clientId?: string;
|
|
140
294
|
seed?: TestkitSeed;
|
|
141
295
|
allowPublic?: boolean;
|
|
296
|
+
webhooks?: WebhookOptions;
|
|
142
297
|
}
|
|
143
298
|
|
|
144
299
|
interface KindeTestAuth {
|
|
@@ -159,7 +314,10 @@ interface KindeTestkitHandle {
|
|
|
159
314
|
readonly issuer: string;
|
|
160
315
|
readonly jwksUri: string;
|
|
161
316
|
readonly testkit: KindeTestkit;
|
|
317
|
+
readonly failures: FailureInjector;
|
|
318
|
+
readonly webhooks: WebhookDispatcher;
|
|
162
319
|
auth(scenario: Scenario, token?: ScenarioTokenOverrides): Promise<KindeTestAuth>;
|
|
320
|
+
reset(): void;
|
|
163
321
|
}
|
|
164
322
|
declare function useKindeTestkit(options?: StartKindeTestkitOptions): KindeTestkitHandle;
|
|
165
323
|
|