mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Stack initialization now sends completion callbacks (success/failure) to a configured notification service. * Backend endpoint added to receive and forward initialization completion notifications. * **Chores** * Added configuration entries for Telegram callback integration. * Local init tooling updated to respect a configurable API base URL for callback delivery. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
32 lines
846 B
TypeScript
32 lines
846 B
TypeScript
type TelegramErrorInfo = {
|
|
name?: string,
|
|
message: string,
|
|
stack?: string,
|
|
};
|
|
|
|
export type TelegramCompletionPayload = {
|
|
success: boolean,
|
|
distinctId?: string,
|
|
options: Record<string, unknown>,
|
|
args: string[],
|
|
isNonInteractive: boolean,
|
|
timestamp: string,
|
|
projectPath?: string,
|
|
error?: TelegramErrorInfo,
|
|
};
|
|
|
|
const API_BASE_ENV = "STACK_INIT_API_BASE_URL";
|
|
const DEFAULT_API_BASE_URL = "https://api.stack-auth.com";
|
|
const CALLBACK_ENDPOINT = "/api/latest/internal/init-script-callback";
|
|
|
|
export async function invokeCallback(payload: TelegramCompletionPayload): Promise<void> {
|
|
const baseUrl = process.env[API_BASE_ENV] ?? DEFAULT_API_BASE_URL;
|
|
await fetch(`${baseUrl}${CALLBACK_ENDPOINT}`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|