kinde-testkit 0.7.0 → 0.8.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 +15 -0
- package/README.md +97 -9
- package/dist/chunk-BPPG4G52.js +427 -0
- package/dist/chunk-BPPG4G52.js.map +1 -0
- package/dist/{chunk-JTAB2S44.js → chunk-CY75AADD.js} +175 -454
- package/dist/chunk-CY75AADD.js.map +1 -0
- package/dist/chunk-EZUKOKNO.js +48 -0
- package/dist/chunk-EZUKOKNO.js.map +1 -0
- package/dist/{chunk-2QJ7DTNL.js → chunk-YJPE5HAM.js} +5 -3
- package/dist/{chunk-2QJ7DTNL.js.map → chunk-YJPE5HAM.js.map} +1 -1
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/cypress-support.d.ts +142 -0
- package/dist/cypress-support.js +21 -6
- package/dist/cypress-support.js.map +1 -1
- package/dist/cypress.cjs +142 -14
- package/dist/cypress.d.cts +1 -1
- package/dist/cypress.d.ts +3 -2
- package/dist/cypress.js +2 -1
- package/dist/cypress.js.map +1 -1
- package/dist/{handle-estfqypp.d.cts → handle-DRPxm36j.d.cts} +1 -1
- package/dist/{handle-E_BhdHx8.d.ts → handle-Pjt9fSUq.d.ts} +3 -2
- package/dist/index.cjs +145 -14
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +8 -26
- package/dist/index.js +27 -51
- package/dist/index.js.map +1 -1
- package/dist/jest.cjs +142 -14
- package/dist/jest.d.cts +3 -3
- package/dist/jest.d.ts +5 -4
- package/dist/jest.js +3 -2
- package/dist/jest.js.map +1 -1
- package/dist/playwright.d.ts +12 -3
- package/dist/playwright.js +30 -0
- package/dist/playwright.js.map +1 -1
- package/dist/react.d.ts +43 -0
- package/dist/react.js +110 -0
- package/dist/react.js.map +1 -0
- package/dist/{server-CTBJXMac.d.cts → server-CLRn67qI.d.cts} +26 -0
- package/dist/{server-B9fBcnyQ.d.ts → server-CuHAHsaN.d.ts} +3 -56
- package/dist/sign-in-flow-DNrDXSLI.d.ts +35 -0
- package/dist/testkit-BvCAFsSj.d.ts +156 -0
- package/dist/vitest.d.ts +5 -4
- package/dist/vitest.js +3 -2
- package/dist/vitest.js.map +1 -1
- package/dist/{webhooks-DJyCsbdF.d.ts → webhooks-CiK9_pVw.d.ts} +82 -155
- package/package.json +30 -3
- package/dist/chunk-JTAB2S44.js.map +0 -1
package/dist/react.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDefaultTestkit
|
|
3
|
+
} from "./chunk-BPPG4G52.js";
|
|
4
|
+
|
|
5
|
+
// src/react.ts
|
|
6
|
+
import { KindeContext } from "@kinde-oss/kinde-auth-react";
|
|
7
|
+
import {
|
|
8
|
+
getClaim,
|
|
9
|
+
getClaims,
|
|
10
|
+
getCurrentOrganization,
|
|
11
|
+
getFlag,
|
|
12
|
+
getPermission,
|
|
13
|
+
getPermissions,
|
|
14
|
+
getRoles,
|
|
15
|
+
getUserOrganizations,
|
|
16
|
+
getUserProfile,
|
|
17
|
+
MemoryStorage,
|
|
18
|
+
setActiveStorage,
|
|
19
|
+
StorageKeys
|
|
20
|
+
} from "@kinde/js-utils";
|
|
21
|
+
import { existsSync } from "fs";
|
|
22
|
+
import { createRequire } from "module";
|
|
23
|
+
import { dirname, join } from "path";
|
|
24
|
+
import { pathToFileURL } from "url";
|
|
25
|
+
import { createElement } from "react";
|
|
26
|
+
var contextsPromise = null;
|
|
27
|
+
function kindeContexts() {
|
|
28
|
+
contextsPromise ??= (async () => {
|
|
29
|
+
const contexts = [KindeContext];
|
|
30
|
+
try {
|
|
31
|
+
const require2 = createRequire(import.meta.url);
|
|
32
|
+
let dir = dirname(require2.resolve("@kinde-oss/kinde-auth-nextjs"));
|
|
33
|
+
while (!existsSync(join(dir, "package.json"))) dir = dirname(dir);
|
|
34
|
+
const nested = join(dir, "node_modules", "@kinde-oss", "kinde-auth-react", "dist", "index.mjs");
|
|
35
|
+
if (existsSync(nested)) {
|
|
36
|
+
const module = await import(pathToFileURL(nested).href);
|
|
37
|
+
if (module.KindeContext !== KindeContext) contexts.push(module.KindeContext);
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
return contexts;
|
|
42
|
+
})();
|
|
43
|
+
return contextsPromise;
|
|
44
|
+
}
|
|
45
|
+
function flagClaims(flags) {
|
|
46
|
+
if (!flags) return void 0;
|
|
47
|
+
return Object.fromEntries(
|
|
48
|
+
Object.entries(flags).map(([key, v]) => [key, { t: typeof v === "boolean" ? "b" : typeof v === "number" ? "i" : "s", v }])
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
async function kindeAuth(scenario, options = {}) {
|
|
52
|
+
const testkit = options.testkit ?? await getDefaultTestkit();
|
|
53
|
+
const accessToken = await testkit.tokenFor(scenario, { ...options.token, featureFlags: flagClaims(options.featureFlags) ?? options.token?.featureFlags });
|
|
54
|
+
const idToken = await testkit.idTokenFor(scenario);
|
|
55
|
+
const storage = new MemoryStorage();
|
|
56
|
+
if (accessToken) await storage.setSessionItem(StorageKeys.accessToken, accessToken);
|
|
57
|
+
if (idToken) await storage.setSessionItem(StorageKeys.idToken, idToken);
|
|
58
|
+
const withStorage = (fn) => (...args) => {
|
|
59
|
+
setActiveStorage(storage);
|
|
60
|
+
return fn(...args);
|
|
61
|
+
};
|
|
62
|
+
const calls = [];
|
|
63
|
+
const record = (method) => async (...args) => {
|
|
64
|
+
calls.push({ method, args });
|
|
65
|
+
};
|
|
66
|
+
const authenticated = scenario.kind === "authenticated";
|
|
67
|
+
const user = authenticated ? await withStorage(getUserProfile)() : null;
|
|
68
|
+
const value = {
|
|
69
|
+
isAuthenticated: authenticated,
|
|
70
|
+
isLoading: false,
|
|
71
|
+
user: user ?? void 0,
|
|
72
|
+
error: void 0,
|
|
73
|
+
login: record("login"),
|
|
74
|
+
register: record("register"),
|
|
75
|
+
logout: record("logout"),
|
|
76
|
+
switchOrg: record("switchOrg"),
|
|
77
|
+
refreshToken: async (...args) => {
|
|
78
|
+
calls.push({ method: "refreshToken", args });
|
|
79
|
+
return { success: true, accessToken: accessToken ?? void 0, idToken: idToken ?? void 0 };
|
|
80
|
+
},
|
|
81
|
+
generatePortalUrl: async (...args) => {
|
|
82
|
+
calls.push({ method: "generatePortalUrl", args });
|
|
83
|
+
return { url: new URL(`${testkit.issuer}/testkit/portal`) };
|
|
84
|
+
},
|
|
85
|
+
getToken: async () => accessToken ?? void 0,
|
|
86
|
+
getAccessToken: async () => accessToken ?? void 0,
|
|
87
|
+
getIdToken: async () => idToken ?? void 0,
|
|
88
|
+
getClaims: withStorage(getClaims),
|
|
89
|
+
getClaim: withStorage(getClaim),
|
|
90
|
+
getOrganization: withStorage(getCurrentOrganization),
|
|
91
|
+
getCurrentOrganization: withStorage(getCurrentOrganization),
|
|
92
|
+
getFlag: withStorage(getFlag),
|
|
93
|
+
getUserProfile: withStorage(getUserProfile),
|
|
94
|
+
getPermission: withStorage(getPermission),
|
|
95
|
+
getPermissions: withStorage(getPermissions),
|
|
96
|
+
getUserOrganizations: withStorage(getUserOrganizations),
|
|
97
|
+
getRoles: withStorage(getRoles)
|
|
98
|
+
};
|
|
99
|
+
const contexts = await kindeContexts();
|
|
100
|
+
const wrapper = ({ children }) => contexts.reduce((inner, context) => createElement(context.Provider, { value }, inner), children ?? null);
|
|
101
|
+
return { wrapper, value, calls, accessToken, idToken };
|
|
102
|
+
}
|
|
103
|
+
function KindeTestProvider({ auth, children }) {
|
|
104
|
+
return auth.wrapper({ children });
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
KindeTestProvider,
|
|
108
|
+
kindeAuth
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["import { KindeContext, type KindeContextProps } from \"@kinde-oss/kinde-auth-react\";\nimport {\n getClaim,\n getClaims,\n getCurrentOrganization,\n getFlag,\n getPermission,\n getPermissions,\n getRoles,\n getUserOrganizations,\n getUserProfile,\n MemoryStorage,\n setActiveStorage,\n StorageKeys,\n} from \"@kinde/js-utils\";\nimport { existsSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { createElement, type Context, type ReactNode } from \"react\";\nimport { getDefaultTestkit, type KindeTestkit, type ScenarioTokenOverrides } from \"./testkit.js\";\nimport type { Scenario } from \"./types.js\";\n\nexport interface KindeTestAuthOptions {\n /** Signs the tokens. Defaults to the shared testkit whose issuer is http://localhost:4400. */\n testkit?: KindeTestkit;\n /** Feature flags in the access token, such as { new_editor: true }. */\n featureFlags?: Record<string, boolean | string | number>;\n /** Other token settings, the same as kindeTest() and tokenFor(). */\n token?: ScenarioTokenOverrides;\n}\n\n/** A call your component made to a Kinde action, such as login() or logout(). */\nexport interface KindeTestAuthCall {\n method: \"login\" | \"register\" | \"logout\" | \"switchOrg\" | \"refreshToken\" | \"generatePortalUrl\";\n args: unknown[];\n}\n\nexport interface KindeTestAuth {\n /** Pass to React Testing Library: render(<App />, { wrapper: auth.wrapper }). */\n wrapper: (props: { children?: ReactNode }) => ReactNode;\n /** The value the wrapper gives KindeContext. */\n value: KindeContextProps;\n /** Every login(), logout(), register() and switchOrg() call, in order. */\n calls: KindeTestAuthCall[];\n accessToken: string | null;\n idToken: string | null;\n}\n\nlet contextsPromise: Promise<Array<Context<KindeContextProps | null>>> | null = null;\n\n/**\n * The KindeContext objects the installed SDKs read. @kinde-oss/kinde-auth-nextjs pins its own\n * version of @kinde-oss/kinde-auth-react, so a project can have two copies, each with its own context.\n */\nfunction kindeContexts(): Promise<Array<Context<KindeContextProps | null>>> {\n contextsPromise ??= (async () => {\n const contexts = [KindeContext];\n try {\n const require = createRequire(import.meta.url);\n let dir = dirname(require.resolve(\"@kinde-oss/kinde-auth-nextjs\"));\n while (!existsSync(join(dir, \"package.json\"))) dir = dirname(dir);\n const nested = join(dir, \"node_modules\", \"@kinde-oss\", \"kinde-auth-react\", \"dist\", \"index.mjs\");\n if (existsSync(nested)) {\n const module = (await import(pathToFileURL(nested).href)) as { KindeContext: Context<KindeContextProps | null> };\n if (module.KindeContext !== KindeContext) contexts.push(module.KindeContext);\n }\n } catch {\n // The Next.js SDK is not installed.\n }\n return contexts;\n })();\n return contextsPromise;\n}\n\nfunction flagClaims(flags: Record<string, boolean | string | number> | undefined) {\n if (!flags) return undefined;\n return Object.fromEntries(\n Object.entries(flags).map(([key, v]) => [key, { t: typeof v === \"boolean\" ? \"b\" : typeof v === \"number\" ? \"i\" : \"s\", v }]),\n ) as Record<string, { t: \"b\" | \"s\" | \"i\"; v: boolean | string | number }>;\n}\n\n/**\n * Builds Kinde auth state for components under test. Components that call useKindeAuth() from\n * @kinde-oss/kinde-auth-react or useKindeBrowserClient() from @kinde-oss/kinde-auth-nextjs read\n * real tokens signed for the scenario, through the same @kinde/js-utils functions the SDKs use.\n */\nexport async function kindeAuth(scenario: Scenario, options: KindeTestAuthOptions = {}): Promise<KindeTestAuth> {\n const testkit = options.testkit ?? (await getDefaultTestkit());\n const accessToken = await testkit.tokenFor(scenario, { ...options.token, featureFlags: flagClaims(options.featureFlags) ?? options.token?.featureFlags });\n const idToken = await testkit.idTokenFor(scenario);\n const storage = new MemoryStorage();\n if (accessToken) await storage.setSessionItem(StorageKeys.accessToken, accessToken);\n if (idToken) await storage.setSessionItem(StorageKeys.idToken, idToken);\n\n // @kinde/js-utils reads one active storage, so each call points it at this scenario's tokens first.\n const withStorage =\n <A extends unknown[], R>(fn: (...args: A) => R) =>\n (...args: A): R => {\n setActiveStorage(storage);\n return fn(...args);\n };\n const calls: KindeTestAuthCall[] = [];\n const record =\n (method: KindeTestAuthCall[\"method\"]) =>\n async (...args: unknown[]) => {\n calls.push({ method, args });\n };\n\n const authenticated = scenario.kind === \"authenticated\";\n const user = authenticated ? await withStorage(getUserProfile)() : null;\n const value = {\n isAuthenticated: authenticated,\n isLoading: false,\n user: user ?? undefined,\n error: undefined,\n login: record(\"login\"),\n register: record(\"register\"),\n logout: record(\"logout\"),\n switchOrg: record(\"switchOrg\"),\n refreshToken: async (...args: unknown[]) => {\n calls.push({ method: \"refreshToken\", args });\n return { success: true, accessToken: accessToken ?? undefined, idToken: idToken ?? undefined };\n },\n generatePortalUrl: async (...args: unknown[]) => {\n calls.push({ method: \"generatePortalUrl\", args });\n return { url: new URL(`${testkit.issuer}/testkit/portal`) };\n },\n getToken: async () => accessToken ?? undefined,\n getAccessToken: async () => accessToken ?? undefined,\n getIdToken: async () => idToken ?? undefined,\n getClaims: withStorage(getClaims),\n getClaim: withStorage(getClaim),\n getOrganization: withStorage(getCurrentOrganization),\n getCurrentOrganization: withStorage(getCurrentOrganization),\n getFlag: withStorage(getFlag),\n getUserProfile: withStorage(getUserProfile),\n getPermission: withStorage(getPermission),\n getPermissions: withStorage(getPermissions),\n getUserOrganizations: withStorage(getUserOrganizations),\n getRoles: withStorage(getRoles),\n } as unknown as KindeContextProps;\n\n const contexts = await kindeContexts();\n const wrapper = ({ children }: { children?: ReactNode }) =>\n contexts.reduce<ReactNode>((inner, context) => createElement(context.Provider, { value }, inner), children ?? null);\n return { wrapper, value, calls, accessToken, idToken };\n}\n\n/** Wraps children in Kinde auth state built by kindeAuth(). */\nexport function KindeTestProvider({ auth, children }: { auth: KindeTestAuth; children?: ReactNode }) {\n return auth.wrapper({ children });\n}\n"],"mappings":";;;;;AAAA,SAAS,oBAA4C;AACrD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,qBAAmD;AA8B5D,IAAI,kBAA4E;AAMhF,SAAS,gB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IACtD,UAAU,YAAY,QAAQ;AAAA,EAChC;AAEA,QAAM,WAAW,MAAM,cAAc;AACrC,QAAM,UAAU,CAAC,EAAE,SAAS,MAC1B,SAAS,OAAkB,CAAC,OAAO,YAAY,cAAc,QAAQ,UAAU,EAAE,MAAM,GAAG,KAAK,GAAG,YAAY,IAAI;AACpH,SAAO,EAAE,SAAS,OAAO,OAAO,aAAa,QAAQ;AACvD;AAGO,SAAS,kBAAkB,EAAE,MAAM,SAAS,GAAkD;AACnG,SAAO,KAAK,QAAQ,EAAE,SAAS,CAAC;AAClC;","names":["require"]}
|
|
@@ -291,6 +291,19 @@ interface UserMeta {
|
|
|
291
291
|
createdOn: string;
|
|
292
292
|
totalSignIns: number;
|
|
293
293
|
lastSignedIn: string | null;
|
|
294
|
+
/** Last sign-in time per organization code. */
|
|
295
|
+
lastOrganizationSignIns: Record<string, string>;
|
|
296
|
+
}
|
|
297
|
+
/** An identity for authenticateAs(). */
|
|
298
|
+
interface Identity {
|
|
299
|
+
email: string;
|
|
300
|
+
givenName?: string | null;
|
|
301
|
+
familyName?: string | null;
|
|
302
|
+
/** The organization code. Created when it does not exist. */
|
|
303
|
+
organization?: string | null;
|
|
304
|
+
organizationName?: string;
|
|
305
|
+
roles?: string[];
|
|
306
|
+
permissions?: string[];
|
|
294
307
|
}
|
|
295
308
|
interface OrganizationMeta {
|
|
296
309
|
externalId: string | null;
|
|
@@ -329,6 +342,15 @@ declare class Directory {
|
|
|
329
342
|
deleteOrganization(code: string): boolean;
|
|
330
343
|
membership(userId: string, organizationCode: string): KindeMembership | undefined;
|
|
331
344
|
addMembership(userId: string, organizationCode: string, roles?: string[], permissions?: string[]): KindeMembership;
|
|
345
|
+
/**
|
|
346
|
+
* Makes sure a user exists with exactly these roles and permissions in the organization, creating
|
|
347
|
+
* the user, organization and membership when they are missing. Used by authenticateAs() in browser
|
|
348
|
+
* tests, so a test can sign in as any identity without adding it to the seed. reset() removes it.
|
|
349
|
+
*/
|
|
350
|
+
ensureIdentity(input: Identity): {
|
|
351
|
+
user: KindeUser;
|
|
352
|
+
organization: KindeOrganization | null;
|
|
353
|
+
};
|
|
332
354
|
removeMembership(userId: string, organizationCode: string): boolean;
|
|
333
355
|
role(idOrKey: string): SeedRole | undefined;
|
|
334
356
|
permission(idOrKey: string): SeedPermission | undefined;
|
|
@@ -353,7 +375,10 @@ interface FailureRule {
|
|
|
353
375
|
hang?: boolean;
|
|
354
376
|
times?: number;
|
|
355
377
|
retryAfter?: number;
|
|
378
|
+
/** Answer with a body your client cannot use. The status is 200 unless you set one. */
|
|
379
|
+
malformed?: MalformedKind;
|
|
356
380
|
}
|
|
381
|
+
type MalformedKind = "invalid-json" | "empty" | "html" | "unexpected-json";
|
|
357
382
|
interface ActiveFailure {
|
|
358
383
|
id: string;
|
|
359
384
|
path: string;
|
|
@@ -363,6 +388,7 @@ interface ActiveFailure {
|
|
|
363
388
|
hang: boolean;
|
|
364
389
|
remaining: number | null;
|
|
365
390
|
retryAfter: number;
|
|
391
|
+
malformed: MalformedKind | null;
|
|
366
392
|
hits: number;
|
|
367
393
|
}
|
|
368
394
|
declare class FailureInjector {
|
|
@@ -1,58 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import { j as InvalidTokenKind, m as KindeTestkit } from './testkit-BvCAFsSj.js';
|
|
2
|
+
import { T as TestkitSeed, h as WebhookOptions, R as ResolvedSeed, F as FailureInjector, d as WebhookDispatcher, D as Directory } from './webhooks-CiK9_pVw.js';
|
|
56
3
|
|
|
57
4
|
interface DeviceFlowOptions {
|
|
58
5
|
/** Seconds a client must wait between polls. Kinde uses 5. Set 0 in tests that poll in a loop. */
|
|
@@ -191,4 +138,4 @@ interface RunningKindeTestkit {
|
|
|
191
138
|
}
|
|
192
139
|
declare function startKindeTestkit(options?: StartKindeTestkitOptions): Promise<RunningKindeTestkit>;
|
|
193
140
|
|
|
194
|
-
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, type DeviceFlowOptions as g,
|
|
141
|
+
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, type DeviceFlowOptions as g, type RunningKindeTestkit as h, buildReport as i, clearCoverageDirectory as j, formatCoverageReport as k, mergeSnapshots as m, readCoverageDirectory as r, startKindeTestkit as s };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Steps for signing in through the testkit with plain HTTP requests instead of a browser page.
|
|
3
|
+
* The Cypress commands use these. No Node APIs here, because Cypress bundles this file for the browser.
|
|
4
|
+
*/
|
|
5
|
+
/** What the social provider does when the user picks it on the sign-in page. */
|
|
6
|
+
type ProviderResult = "success" | "cancelled" | "error";
|
|
7
|
+
/** What happens at the multi-factor authentication step. */
|
|
8
|
+
type MfaOutcome = "none" | "passed" | "failed" | "cancelled";
|
|
9
|
+
/** How the user signs in on the testkit page. */
|
|
10
|
+
interface SignInMethodOptions {
|
|
11
|
+
/** "email" (the default), or a social provider such as "google", "github" or "microsoft". */
|
|
12
|
+
connection?: string;
|
|
13
|
+
/** For a social provider: "success" (the default), "cancelled" by the user, or a provider "error". */
|
|
14
|
+
providerResult?: ProviderResult;
|
|
15
|
+
/** Multi-factor authentication: "none" (the default), "passed", "failed" with a wrong code, or "cancelled". */
|
|
16
|
+
mfa?: MfaOutcome;
|
|
17
|
+
}
|
|
18
|
+
interface RequestSignInOptions extends SignInMethodOptions {
|
|
19
|
+
/** Email address or ID of the user. */
|
|
20
|
+
user: string;
|
|
21
|
+
/** Active organization, for users in more than one. */
|
|
22
|
+
org?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The app's login route, with the hints the testkit sign-in page reads. */
|
|
25
|
+
declare function appLoginUrl(loginPath: string, options: RequestSignInOptions): string;
|
|
26
|
+
/** Reads the hidden request field from the testkit sign-in page. */
|
|
27
|
+
declare function readSignInRequest(html: string): string;
|
|
28
|
+
/** The form the sign-in page posts to /oauth2/auth/login. */
|
|
29
|
+
declare function signInForm(request: string, options: RequestSignInOptions): Record<string, string>;
|
|
30
|
+
/** Explains why the testkit did not redirect back to the app after the form was posted. */
|
|
31
|
+
declare function signInFailure(status: number, html: string, options: RequestSignInOptions): Error;
|
|
32
|
+
/** Resolves a Location header, which can be relative, against the URL that sent it. */
|
|
33
|
+
declare function resolveLocation(location: string, from: string): string;
|
|
34
|
+
|
|
35
|
+
export { type RequestSignInOptions as R, type SignInMethodOptions as S, appLoginUrl as a, resolveLocation as b, signInForm as c, readSignInRequest as r, signInFailure as s };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { JWTPayload, JWK } from 'jose';
|
|
2
|
+
|
|
3
|
+
interface KindeUser {
|
|
4
|
+
id: string;
|
|
5
|
+
email: string | null;
|
|
6
|
+
emailVerified: boolean;
|
|
7
|
+
givenName: string | null;
|
|
8
|
+
familyName: string | null;
|
|
9
|
+
picture: string | null;
|
|
10
|
+
claims: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
interface KindeOrganization {
|
|
13
|
+
code: string;
|
|
14
|
+
name: string;
|
|
15
|
+
metadata: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
interface KindeRole {
|
|
18
|
+
id: string;
|
|
19
|
+
key: string;
|
|
20
|
+
name: string;
|
|
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
|
+
}
|
|
37
|
+
interface AuthenticatedScenario {
|
|
38
|
+
kind: "authenticated";
|
|
39
|
+
user: KindeUser;
|
|
40
|
+
organization: KindeOrganization | null;
|
|
41
|
+
roles: string[];
|
|
42
|
+
permissions: string[];
|
|
43
|
+
claims: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface UnauthenticatedScenario {
|
|
46
|
+
kind: "unauthenticated";
|
|
47
|
+
}
|
|
48
|
+
type Scenario = AuthenticatedScenario | UnauthenticatedScenario;
|
|
49
|
+
interface KindePrincipal {
|
|
50
|
+
type: "user" | "machine";
|
|
51
|
+
subject: string;
|
|
52
|
+
issuer: string;
|
|
53
|
+
organization: {
|
|
54
|
+
code: string;
|
|
55
|
+
} | null;
|
|
56
|
+
roles: string[];
|
|
57
|
+
permissions: string[];
|
|
58
|
+
claims: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
type InvalidTokenKind = "expired" | "wrong-issuer" | "wrong-audience" | "missing-subject" | "missing-organization" | "missing-permissions" | "future-iat" | "bad-signature" | "unknown-key" | "unsigned";
|
|
61
|
+
type Duration = number | `${number}${"s" | "m" | "h" | "d"}`;
|
|
62
|
+
interface KindeTokenOptions {
|
|
63
|
+
subject?: string;
|
|
64
|
+
organizationCode?: string | null;
|
|
65
|
+
permissions?: string[];
|
|
66
|
+
roles?: Array<string | KindeRole>;
|
|
67
|
+
scopes?: string[];
|
|
68
|
+
featureFlags?: Record<string, {
|
|
69
|
+
t: "b" | "s" | "i";
|
|
70
|
+
v: boolean | string | number;
|
|
71
|
+
}>;
|
|
72
|
+
claims?: Record<string, unknown>;
|
|
73
|
+
authMethods?: string[];
|
|
74
|
+
authTime?: number;
|
|
75
|
+
clientId?: string;
|
|
76
|
+
audience?: string[];
|
|
77
|
+
expiresIn?: Duration;
|
|
78
|
+
invalid?: InvalidTokenKind;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
declare const DEFAULT_ISSUER = "http://localhost:4400";
|
|
82
|
+
declare const DEFAULT_CLIENT_ID = "kinde_testkit_client";
|
|
83
|
+
declare const DEFAULT_M2M_CLIENT_ID = "kinde_testkit_m2m";
|
|
84
|
+
declare const DEFAULT_SCOPES: string[];
|
|
85
|
+
declare const DEFAULT_AUTH_METHODS: string[];
|
|
86
|
+
declare const INVALID_TOKEN_KINDS: readonly InvalidTokenKind[];
|
|
87
|
+
interface KindeTestkitOptions {
|
|
88
|
+
issuer?: string;
|
|
89
|
+
audience?: string | string[];
|
|
90
|
+
clientId?: string;
|
|
91
|
+
accessTokenExpiresIn?: Duration;
|
|
92
|
+
idTokenExpiresIn?: Duration;
|
|
93
|
+
now?: () => number;
|
|
94
|
+
}
|
|
95
|
+
type ScenarioTokenOverrides = Pick<KindeTokenOptions, "expiresIn" | "invalid" | "scopes" | "featureFlags" | "claims" | "authMethods" | "authTime" | "clientId" | "audience">;
|
|
96
|
+
interface M2MTokenOptions {
|
|
97
|
+
clientId?: string;
|
|
98
|
+
organizationCode?: string | null;
|
|
99
|
+
scopes?: string[];
|
|
100
|
+
grantedScopes?: string[];
|
|
101
|
+
audience?: string[];
|
|
102
|
+
permissions?: string[];
|
|
103
|
+
claims?: Record<string, unknown>;
|
|
104
|
+
expiresIn?: Duration;
|
|
105
|
+
invalid?: InvalidTokenKind;
|
|
106
|
+
}
|
|
107
|
+
interface IdTokenOptions {
|
|
108
|
+
expiresIn?: Duration;
|
|
109
|
+
authMethods?: string[];
|
|
110
|
+
authTime?: number;
|
|
111
|
+
clientId?: string;
|
|
112
|
+
nonce?: string;
|
|
113
|
+
}
|
|
114
|
+
/** Receives every token the testkit signs, for coverage and the dashboard. */
|
|
115
|
+
interface TokenObserver {
|
|
116
|
+
accessToken?(payload: Record<string, unknown>, invalid: InvalidTokenKind | undefined, token: string): void;
|
|
117
|
+
idToken?(payload: Record<string, unknown>, token: string): void;
|
|
118
|
+
anonymous?(): void;
|
|
119
|
+
}
|
|
120
|
+
declare class KindeTestkit {
|
|
121
|
+
private observers;
|
|
122
|
+
/** Calls the observer for every token signed from now on. Returns a function that stops it. */
|
|
123
|
+
observe(observer: TokenObserver): () => void;
|
|
124
|
+
private signAccess;
|
|
125
|
+
readonly issuer: string;
|
|
126
|
+
readonly audience: string[];
|
|
127
|
+
readonly clientId: string;
|
|
128
|
+
private readonly accessTokenExpiresIn;
|
|
129
|
+
private readonly idTokenExpiresIn;
|
|
130
|
+
private readonly clock;
|
|
131
|
+
private readonly signingKey;
|
|
132
|
+
private strangerKey;
|
|
133
|
+
static create(options?: KindeTestkitOptions): Promise<KindeTestkit>;
|
|
134
|
+
private constructor();
|
|
135
|
+
get jwksUri(): string;
|
|
136
|
+
get keyId(): string;
|
|
137
|
+
get accessTokenLifetime(): number;
|
|
138
|
+
verify(token: string): Promise<JWTPayload>;
|
|
139
|
+
jwks(): {
|
|
140
|
+
keys: JWK[];
|
|
141
|
+
};
|
|
142
|
+
token(options?: KindeTokenOptions): Promise<string>;
|
|
143
|
+
m2mToken(options?: M2MTokenOptions): Promise<string>;
|
|
144
|
+
tokenFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<string | null>;
|
|
145
|
+
idTokenFor(scenario: Scenario, options?: IdTokenOptions): Promise<string | null>;
|
|
146
|
+
headersFor(scenario: Scenario, overrides?: ScenarioTokenOverrides): Promise<Record<string, string>>;
|
|
147
|
+
principalFor(scenario: Scenario): KindePrincipal | null;
|
|
148
|
+
signPayload(payload: Record<string, unknown>, invalid?: "bad-signature" | "unknown-key" | "unsigned"): Promise<string>;
|
|
149
|
+
private sign;
|
|
150
|
+
private stranger;
|
|
151
|
+
}
|
|
152
|
+
declare function principalFromClaims(claims: Record<string, unknown>): KindePrincipal;
|
|
153
|
+
declare function getDefaultTestkit(): Promise<KindeTestkit>;
|
|
154
|
+
declare function createKindeToken(options?: KindeTokenOptions): Promise<string>;
|
|
155
|
+
|
|
156
|
+
export { type AuthenticatedScenario as A, DEFAULT_AUTH_METHODS as D, INVALID_TOKEN_KINDS as I, type KindeOrganization as K, type M2MTokenOptions as M, type Scenario as S, type TokenObserver as T, type UnauthenticatedScenario as U, type KindeUser as a, type KindeMembership as b, type KindeRole as c, DEFAULT_CLIENT_ID as d, DEFAULT_ISSUER as e, DEFAULT_M2M_CLIENT_ID as f, DEFAULT_SCOPES as g, type Duration as h, type IdTokenOptions as i, type InvalidTokenKind as j, type KindeApplication as k, type KindePrincipal as l, KindeTestkit as m, type KindeTestkitOptions as n, type KindeTokenOptions as o, type ScenarioTokenOverrides as p, createKindeToken as q, getDefaultTestkit as r, principalFromClaims as s };
|
package/dist/vitest.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { a as KindeTestkitHandle } from './handle-
|
|
2
|
-
export { K as KindeTestAuth, k as kindeTest } from './handle-
|
|
3
|
-
import { S as StartKindeTestkitOptions } from './server-
|
|
4
|
-
import './
|
|
1
|
+
import { a as KindeTestkitHandle } from './handle-Pjt9fSUq.js';
|
|
2
|
+
export { K as KindeTestAuth, k as kindeTest } from './handle-Pjt9fSUq.js';
|
|
3
|
+
import { S as StartKindeTestkitOptions } from './server-CuHAHsaN.js';
|
|
4
|
+
import './testkit-BvCAFsSj.js';
|
|
5
5
|
import 'jose';
|
|
6
|
+
import './webhooks-CiK9_pVw.js';
|
|
6
7
|
|
|
7
8
|
/** Starts a testkit for the test file. Use the handle inside tests and hooks. */
|
|
8
9
|
declare function useKindeTestkit(options?: StartKindeTestkitOptions): KindeTestkitHandle;
|
package/dist/vitest.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createKindeTestkitHandle,
|
|
3
3
|
kindeTest
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-YJPE5HAM.js";
|
|
5
|
+
import "./chunk-CY75AADD.js";
|
|
6
|
+
import "./chunk-BPPG4G52.js";
|
|
6
7
|
|
|
7
8
|
// src/vitest.ts
|
|
8
9
|
import { afterAll, beforeAll } from "vitest";
|
package/dist/vitest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vitest.ts"],"sourcesContent":["import { afterAll, beforeAll } from \"vitest\";\nimport { createKindeTestkitHandle, type KindeTestkitHandle } from \"./handle.js\";\nimport type { StartKindeTestkitOptions } from \"./server.js\";\n\nexport { kindeTest, type KindeTestAuth, type KindeTestkitHandle } from \"./handle.js\";\n\n/** Starts a testkit for the test file. Use the handle inside tests and hooks. */\nexport function useKindeTestkit(options: StartKindeTestkitOptions = {}): KindeTestkitHandle {\n return createKindeTestkitHandle({ beforeAll, afterAll }, options, \"useKindeTestkit\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/vitest.ts"],"sourcesContent":["import { afterAll, beforeAll } from \"vitest\";\nimport { createKindeTestkitHandle, type KindeTestkitHandle } from \"./handle.js\";\nimport type { StartKindeTestkitOptions } from \"./server.js\";\n\nexport { kindeTest, type KindeTestAuth, type KindeTestkitHandle } from \"./handle.js\";\n\n/** Starts a testkit for the test file. Use the handle inside tests and hooks. */\nexport function useKindeTestkit(options: StartKindeTestkitOptions = {}): KindeTestkitHandle {\n return createKindeTestkitHandle({ beforeAll, afterAll }, options, \"useKindeTestkit\");\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,UAAU,iBAAiB;AAO7B,SAAS,gBAAgB,UAAoC,CAAC,GAAuB;AAC1F,SAAO,yBAAyB,EAAE,WAAW,SAAS,GAAG,SAAS,iBAAiB;AACrF;","names":[]}
|