mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Address TODO next-release comments
This commit is contained in:
parent
74ea96bfd9
commit
a183bcca07
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -17,6 +17,7 @@
|
||||
"ctsx",
|
||||
"datapoints",
|
||||
"deindent",
|
||||
"deindented",
|
||||
"EAUTH",
|
||||
"EDNS",
|
||||
"EMESSAGE",
|
||||
|
||||
@ -27,7 +27,7 @@ async function sendWebhooks(options: {
|
||||
} catch (e: any) {
|
||||
if (e.message.includes("409")) {
|
||||
// This is a Svix bug; they are working on fixing it
|
||||
// TODO next-release: remove this once it no longer appears on Sentry
|
||||
// TODO: remove this once it no longer appears on Sentry
|
||||
captureError("svix-409-hack", "Svix bug: 409 error when creating application. Remove this warning once Svix fixes this.");
|
||||
} else {
|
||||
throw e;
|
||||
|
||||
@ -33,10 +33,9 @@ const clientReadSchema = usersCrudServerReadSchema.pick([
|
||||
"passkey_auth_enabled",
|
||||
]).concat(yupObject({
|
||||
selected_team: teamsCrudClientReadSchema.nullable().defined(),
|
||||
})).nullable().defined(); // TODO: next-release: make required
|
||||
})).defined();
|
||||
|
||||
// TODO: next-release: make required
|
||||
const serverReadSchema = usersCrudServerReadSchema.nullable().defined();
|
||||
const serverReadSchema = usersCrudServerReadSchema.defined();
|
||||
|
||||
const clientDeleteSchema = usersCrudServerDeleteSchema;
|
||||
|
||||
|
||||
@ -211,53 +211,6 @@ const InvalidProjectAuthentication = createKnownErrorConstructor(
|
||||
"inherit",
|
||||
);
|
||||
|
||||
// TODO next-release: delete deprecated error type
|
||||
/**
|
||||
* @deprecated Use ProjectKeyWithoutAccessType instead
|
||||
*/
|
||||
const ProjectKeyWithoutRequestType = createKnownErrorConstructor(
|
||||
InvalidProjectAuthentication,
|
||||
"PROJECT_KEY_WITHOUT_REQUEST_TYPE",
|
||||
() => [
|
||||
400,
|
||||
"Either an API key or an admin access token was provided, but the x-stack-access-type header is missing. Set it to 'client', 'server', or 'admin' as appropriate.",
|
||||
] as const,
|
||||
() => [] as const,
|
||||
);
|
||||
|
||||
// TODO next-release: delete deprecated error type
|
||||
/**
|
||||
* @deprecated Use InvalidAccessType instead
|
||||
*/
|
||||
const InvalidRequestType = createKnownErrorConstructor(
|
||||
InvalidProjectAuthentication,
|
||||
"INVALID_REQUEST_TYPE",
|
||||
(requestType: string) => [
|
||||
400,
|
||||
`The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${requestType}'.`,
|
||||
] as const,
|
||||
(json) => [
|
||||
(json as any)?.requestType ?? throwErr("requestType not found in InvalidRequestType details"),
|
||||
] as const,
|
||||
);
|
||||
|
||||
// TODO next-release: delete deprecated error type
|
||||
/**
|
||||
* @deprecated Use AccessTypeWithoutProjectId instead
|
||||
*/
|
||||
const RequestTypeWithoutProjectId = createKnownErrorConstructor(
|
||||
InvalidProjectAuthentication,
|
||||
"REQUEST_TYPE_WITHOUT_PROJECT_ID",
|
||||
(requestType: "client" | "server" | "admin") => [
|
||||
400,
|
||||
`The x-stack-access-type header was '${requestType}', but the x-stack-project-id header was not provided.`,
|
||||
{
|
||||
request_type: requestType,
|
||||
},
|
||||
] as const,
|
||||
(json: any) => [json.request_type] as const,
|
||||
);
|
||||
|
||||
const ProjectKeyWithoutAccessType = createKnownErrorConstructor(
|
||||
InvalidProjectAuthentication,
|
||||
"PROJECT_KEY_WITHOUT_ACCESS_TYPE",
|
||||
@ -1208,9 +1161,6 @@ export const KnownErrors = {
|
||||
AllOverloadsFailed,
|
||||
ProjectAuthenticationError,
|
||||
InvalidProjectAuthentication,
|
||||
ProjectKeyWithoutRequestType,
|
||||
InvalidRequestType,
|
||||
RequestTypeWithoutProjectId,
|
||||
ProjectKeyWithoutAccessType,
|
||||
InvalidAccessType,
|
||||
AccessTypeWithoutProjectId,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { StackAssertionError } from "./errors";
|
||||
import { camelCaseToSnakeCase, snakeCaseToCamelCase } from "./strings";
|
||||
|
||||
export type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;
|
||||
|
||||
@ -54,20 +53,6 @@ export function deepPlainClone<T>(obj: T): T {
|
||||
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepPlainClone(v)])) as any;
|
||||
}
|
||||
|
||||
export function deepPlainSnakeCaseToCamelCase(snakeCaseObj: any): any {
|
||||
if (typeof snakeCaseObj === 'function') throw new StackAssertionError("deepPlainSnakeCaseToCamelCase does not support functions");
|
||||
if (typeof snakeCaseObj !== 'object' || !snakeCaseObj) return snakeCaseObj;
|
||||
if (Array.isArray(snakeCaseObj)) return snakeCaseObj.map(o => deepPlainSnakeCaseToCamelCase(o));
|
||||
return Object.fromEntries(Object.entries(snakeCaseObj).map(([k, v]) => [snakeCaseToCamelCase(k), deepPlainSnakeCaseToCamelCase(v)]));
|
||||
}
|
||||
|
||||
export function deepPlainCamelCaseToSnakeCase(camelCaseObj: any): any {
|
||||
if (typeof camelCaseObj === 'function') throw new StackAssertionError("deepPlainCamelCaseToSnakeCase does not support functions");
|
||||
if (typeof camelCaseObj !== 'object' || !camelCaseObj) return camelCaseObj;
|
||||
if (Array.isArray(camelCaseObj)) return camelCaseObj.map(o => deepPlainCamelCaseToSnakeCase(o));
|
||||
return Object.fromEntries(Object.entries(camelCaseObj).map(([k, v]) => [camelCaseToSnakeCase(k), deepPlainCamelCaseToSnakeCase(v)]));
|
||||
}
|
||||
|
||||
export function typedEntries<T extends {}>(obj: T): [keyof T, T[keyof T]][] {
|
||||
return Object.entries(obj) as any;
|
||||
}
|
||||
|
||||
@ -123,17 +123,6 @@ export function mergeScopeStrings(...scopes: string[]): string {
|
||||
}
|
||||
|
||||
|
||||
export function snakeCaseToCamelCase(snakeCase: string): string {
|
||||
if (snakeCase.match(/[A-Z]/)) return snakeCase; // TODO next-release: this is a hack for fixing the email templates, remove this after v2 migration
|
||||
return snakeCase.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
||||
}
|
||||
|
||||
export function camelCaseToSnakeCase(camelCase: string): string {
|
||||
if (camelCase.match(/_/)) return camelCase; // TODO next-release: this is a hack for fixing the email templates, remove this after v2 migration
|
||||
return camelCase.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Some classes have different constructor names in different environments (eg. `Headers` is sometimes called `_Headers`,
|
||||
* so we create an object of overrides to handle these cases.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user