mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
DB migration compat / Check if migrations changed (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Build and Run / docker (push) Has been cancelled
Runs E2E API Tests (Local Emulator) / E2E Tests (Local Emulator, Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (mock, 22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (prod, 22.x) (push) Has been cancelled
Runs E2E API Tests with custom port prefix / build (22.x) (push) Has been cancelled
Runs E2E Fallback Tests / E2E Fallback Tests (Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Lint & build / lint_and_build (24) (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
DB migration compat / Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code (push) Has been cancelled
DB migration compat / Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations (push) Has been cancelled
DB migration compat / No migration changes (skipped) (push) Has been cancelled
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import { StackAdminApp, StackClientApp, StackServerApp } from "@hexclave/js";
|
|
import { throwErr } from "@hexclave/shared/dist/utils/errors";
|
|
import { isUuid } from "@hexclave/shared/dist/utils/uuids";
|
|
import { SDK_BASE_URL, it } from "../helpers";
|
|
import { scaffoldProject } from "./js-helpers";
|
|
|
|
const sdkBaseUrl = SDK_BASE_URL;
|
|
|
|
it("StackServerApp can inherit configuration from StackClientApp", async ({ expect }) => {
|
|
const { project, adminUser } = await scaffoldProject();
|
|
const adminApp = new StackAdminApp({
|
|
projectId: project.id,
|
|
baseUrl: sdkBaseUrl,
|
|
projectOwnerSession: adminUser._internalSession,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
});
|
|
|
|
const key = await adminApp.createInternalApiKey({
|
|
description: "inheritance test key",
|
|
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
hasPublishableClientKey: true,
|
|
hasSecretServerKey: true,
|
|
hasSuperSecretAdminKey: true,
|
|
});
|
|
|
|
const clientApp = new StackClientApp({
|
|
baseUrl: sdkBaseUrl,
|
|
projectId: project.id,
|
|
publishableClientKey: key.publishableClientKey,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
});
|
|
|
|
const serverApp = new StackServerApp({
|
|
inheritsFrom: clientApp,
|
|
secretServerKey: key.secretServerKey,
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const createdUser = await serverApp.createUser({
|
|
primaryEmail: `${crypto.randomUUID()}@inheritance-test.example.com`,
|
|
password: "password",
|
|
primaryEmailAuthEnabled: true,
|
|
});
|
|
|
|
expect(isUuid(createdUser.id)).toBe(true);
|
|
const fetchedUser = await serverApp.getUser(createdUser.id);
|
|
expect(fetchedUser?.id).toBe(createdUser.id);
|
|
});
|
|
|
|
it("StackAdminApp can inherit configuration from StackServerApp", async ({ expect }) => {
|
|
const { project, adminUser } = await scaffoldProject();
|
|
const adminApp = new StackAdminApp({
|
|
projectId: project.id,
|
|
baseUrl: sdkBaseUrl,
|
|
projectOwnerSession: adminUser._internalSession,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
});
|
|
|
|
const key = await adminApp.createInternalApiKey({
|
|
description: "admin inheritance key",
|
|
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
hasPublishableClientKey: true,
|
|
hasSecretServerKey: true,
|
|
hasSuperSecretAdminKey: true,
|
|
});
|
|
|
|
const clientApp = new StackClientApp({
|
|
baseUrl: sdkBaseUrl,
|
|
projectId: project.id,
|
|
publishableClientKey: key.publishableClientKey,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
});
|
|
|
|
const serverApp = new StackServerApp({
|
|
inheritsFrom: clientApp,
|
|
secretServerKey: key.secretServerKey ?? throwErr("secret server key missing"),
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const adminInherited = new StackAdminApp({
|
|
inheritsFrom: serverApp,
|
|
superSecretAdminKey: key.superSecretAdminKey ?? throwErr("super secret admin key missing"),
|
|
tokenStore: "memory",
|
|
});
|
|
|
|
const keys = await adminInherited.listInternalApiKeys();
|
|
expect(Array.isArray(keys)).toBe(true);
|
|
expect(adminInherited.projectId).toBe(project.id);
|
|
});
|