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
108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
import type { StackClientAppConstructorOptions, StackServerAppConstructorOptions } from '@hexclave/js';
|
|
import { AdminProjectCreateOptions, StackAdminApp, StackClientApp, StackServerApp } from '@hexclave/js';
|
|
import { throwErr } from '@hexclave/shared/dist/utils/errors';
|
|
import { Result } from '@hexclave/shared/dist/utils/results';
|
|
import { SDK_BASE_URL, STACK_INTERNAL_PROJECT_ADMIN_KEY, STACK_INTERNAL_PROJECT_CLIENT_KEY, STACK_INTERNAL_PROJECT_SERVER_KEY } from '../helpers';
|
|
|
|
const testExtraRequestHeaders = {
|
|
"x-stack-disable-artificial-development-delay": "yes",
|
|
};
|
|
|
|
const sdkBaseUrl = SDK_BASE_URL;
|
|
|
|
export async function scaffoldProject(body?: Omit<AdminProjectCreateOptions, 'displayName' | 'teamId'> & { displayName?: string }) {
|
|
const internalApp = new StackAdminApp({
|
|
projectId: 'internal',
|
|
baseUrl: sdkBaseUrl,
|
|
publishableClientKey: STACK_INTERNAL_PROJECT_CLIENT_KEY,
|
|
secretServerKey: STACK_INTERNAL_PROJECT_SERVER_KEY,
|
|
superSecretAdminKey: STACK_INTERNAL_PROJECT_ADMIN_KEY,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
extraRequestHeaders: testExtraRequestHeaders,
|
|
});
|
|
|
|
const fakeEmail = `${crypto.randomUUID()}@stack-js-test.example.com`;
|
|
|
|
Result.orThrow(await internalApp.signUpWithCredential({
|
|
email: fakeEmail,
|
|
password: "password",
|
|
verificationCallbackUrl: "http://localhost:3000",
|
|
}));
|
|
const adminUser = await internalApp.getUser({
|
|
or: 'throw',
|
|
});
|
|
const teamId = adminUser.selectedTeam?.id ?? throwErr("No team selected");
|
|
|
|
const project = await adminUser.createProject({
|
|
displayName: body?.displayName || 'New Project',
|
|
teamId,
|
|
...body,
|
|
});
|
|
|
|
return {
|
|
project,
|
|
adminUser,
|
|
};
|
|
}
|
|
|
|
export async function createApp(
|
|
body?: Parameters<typeof scaffoldProject>[0],
|
|
appOverrides?: {
|
|
client?: Partial<StackClientAppConstructorOptions<true, string>>,
|
|
server?: Partial<StackServerAppConstructorOptions<true, string>>,
|
|
},
|
|
) {
|
|
const { project, adminUser } = await scaffoldProject(body);
|
|
const adminApp = new StackAdminApp({
|
|
projectId: project.id,
|
|
baseUrl: sdkBaseUrl,
|
|
projectOwnerSession: adminUser._internalSession,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
extraRequestHeaders: testExtraRequestHeaders,
|
|
});
|
|
|
|
const apiKey = await adminApp.createInternalApiKey({
|
|
description: 'test',
|
|
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
|
|
hasPublishableClientKey: true,
|
|
hasSecretServerKey: true,
|
|
hasSuperSecretAdminKey: false,
|
|
});
|
|
if (!apiKey.secretServerKey) {
|
|
throw new Error("createInternalApiKey did not return a secretServerKey");
|
|
}
|
|
const secretServerKey = apiKey.secretServerKey;
|
|
|
|
const serverApp = new StackServerApp({
|
|
baseUrl: sdkBaseUrl,
|
|
projectId: project.id,
|
|
publishableClientKey: apiKey.publishableClientKey,
|
|
secretServerKey,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
extraRequestHeaders: testExtraRequestHeaders,
|
|
...(appOverrides?.server ?? {}),
|
|
});
|
|
|
|
const clientApp = new StackClientApp({
|
|
baseUrl: sdkBaseUrl,
|
|
projectId: project.id,
|
|
publishableClientKey: apiKey.publishableClientKey,
|
|
tokenStore: "memory",
|
|
redirectMethod: "none",
|
|
extraRequestHeaders: testExtraRequestHeaders,
|
|
...(appOverrides?.client ?? {}),
|
|
});
|
|
|
|
return {
|
|
serverApp,
|
|
clientApp,
|
|
adminApp,
|
|
apiKey,
|
|
project,
|
|
secretServerKey,
|
|
};
|
|
}
|