@stackframe/stack-shared 2.5.3 → 2.5.4
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 +8 -0
- package/dist/crud.d.ts +10 -3
- package/dist/helpers/production-mode.d.ts +6 -0
- package/dist/helpers/production-mode.js +43 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/interface/adminInterface.d.ts +28 -67
- package/dist/interface/adminInterface.js +63 -21
- package/dist/interface/clientInterface.d.ts +21 -133
- package/dist/interface/clientInterface.js +92 -118
- package/dist/interface/crud/api-keys.d.ts +134 -0
- package/dist/interface/crud/api-keys.js +61 -0
- package/dist/interface/crud/current-user.d.ts +47 -11
- package/dist/interface/crud/current-user.js +7 -3
- package/dist/interface/crud/email-templates.d.ts +53 -34
- package/dist/interface/crud/email-templates.js +37 -24
- package/dist/interface/crud/oauth.d.ts +8 -9
- package/dist/interface/crud/oauth.js +5 -5
- package/dist/interface/crud/projects.d.ts +446 -0
- package/dist/interface/crud/projects.js +110 -0
- package/dist/interface/crud/team-memberships.d.ts +22 -0
- package/dist/interface/crud/team-memberships.js +22 -0
- package/dist/interface/crud/team-permissions.d.ts +129 -0
- package/dist/interface/crud/team-permissions.js +83 -0
- package/dist/interface/crud/teams.d.ts +148 -0
- package/dist/interface/crud/teams.js +80 -0
- package/dist/interface/crud/users.d.ts +88 -33
- package/dist/interface/crud/users.js +22 -14
- package/dist/interface/crud-deprecated/api-keys.d.ts +134 -0
- package/dist/interface/crud-deprecated/api-keys.js +61 -0
- package/dist/interface/crud-deprecated/current-user.d.ts +127 -0
- package/dist/interface/crud-deprecated/current-user.js +49 -0
- package/dist/interface/crud-deprecated/email-templates.d.ts +75 -0
- package/dist/interface/crud-deprecated/email-templates.js +41 -0
- package/dist/interface/crud-deprecated/oauth.d.ts +24 -0
- package/dist/interface/crud-deprecated/oauth.js +12 -0
- package/dist/interface/crud-deprecated/projects.d.ts +440 -0
- package/dist/interface/crud-deprecated/projects.js +109 -0
- package/dist/interface/crud-deprecated/team-memberships.d.ts +22 -0
- package/dist/interface/crud-deprecated/team-memberships.js +22 -0
- package/dist/interface/crud-deprecated/team-permissions.d.ts +129 -0
- package/dist/interface/crud-deprecated/team-permissions.js +83 -0
- package/dist/interface/crud-deprecated/teams.d.ts +126 -0
- package/dist/interface/crud-deprecated/teams.js +78 -0
- package/dist/interface/crud-deprecated/users.d.ts +201 -0
- package/dist/interface/crud-deprecated/users.js +75 -0
- package/dist/interface/serverInterface.d.ts +33 -60
- package/dist/interface/serverInterface.js +74 -101
- package/dist/known-errors.d.ts +43 -26
- package/dist/known-errors.js +132 -85
- package/dist/schema-fields.d.ts +53 -4
- package/dist/schema-fields.js +156 -25
- package/dist/sessions.d.ts +1 -0
- package/dist/sessions.js +13 -3
- package/dist/utils/compile-time.d.ts +3 -1
- package/dist/utils/compile-time.js +3 -1
- package/dist/utils/errors.d.ts +8 -1
- package/dist/utils/errors.js +17 -4
- package/dist/utils/objects.d.ts +4 -1
- package/dist/utils/objects.js +16 -8
- package/dist/utils/promises.js +6 -1
- package/dist/utils/proxies.d.ts +1 -0
- package/dist/utils/proxies.js +65 -0
- package/dist/utils/react.d.ts +1 -1
- package/dist/utils/react.js +2 -2
- package/dist/utils/strings.js +3 -3
- package/dist/utils/urls.d.ts +1 -0
- package/dist/utils/urls.js +8 -0
- package/package.json +2 -2
- package/dist/utils/yup.d.ts +0 -3
- package/dist/utils/yup.js +0 -13
package/dist/known-errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StatusError, throwErr } from "./utils/errors";
|
|
1
|
+
import { StackAssertionError, StatusError, throwErr } from "./utils/errors";
|
|
2
2
|
import { identityArgs } from "./utils/functions";
|
|
3
3
|
import { deindent } from "./utils/strings";
|
|
4
4
|
export class KnownError extends StatusError {
|
|
@@ -10,11 +10,7 @@ export class KnownError extends StatusError {
|
|
|
10
10
|
this.name = "KnownError";
|
|
11
11
|
}
|
|
12
12
|
getBody() {
|
|
13
|
-
return new TextEncoder().encode(JSON.stringify(
|
|
14
|
-
code: this.errorCode,
|
|
15
|
-
details: this.details,
|
|
16
|
-
error: this.humanReadableMessage,
|
|
17
|
-
}, undefined, 2));
|
|
13
|
+
return new TextEncoder().encode(JSON.stringify(this.toDescriptiveJson(), undefined, 2));
|
|
18
14
|
}
|
|
19
15
|
getHeaders() {
|
|
20
16
|
return {
|
|
@@ -22,6 +18,13 @@ export class KnownError extends StatusError {
|
|
|
22
18
|
"X-Stack-Known-Error": [this.errorCode],
|
|
23
19
|
};
|
|
24
20
|
}
|
|
21
|
+
toDescriptiveJson() {
|
|
22
|
+
return {
|
|
23
|
+
code: this.errorCode,
|
|
24
|
+
...this.details ? { details: this.details } : {},
|
|
25
|
+
error: this.humanReadableMessage,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
25
28
|
get errorCode() {
|
|
26
29
|
return this.constructor.errorCode ?? throwErr(`Can't find error code for this KnownError. Is its constructor a KnownErrorConstructor? ${this}`);
|
|
27
30
|
}
|
|
@@ -29,18 +32,19 @@ export class KnownError extends StatusError {
|
|
|
29
32
|
return [
|
|
30
33
|
400,
|
|
31
34
|
json.message,
|
|
32
|
-
json
|
|
35
|
+
json,
|
|
33
36
|
];
|
|
34
37
|
}
|
|
35
38
|
static fromJson(json) {
|
|
36
39
|
for (const [_, KnownErrorType] of Object.entries(KnownErrors)) {
|
|
37
40
|
if (json.code === KnownErrorType.prototype.errorCode) {
|
|
41
|
+
const constructorArgs = KnownErrorType.constructorArgsFromJson(json);
|
|
38
42
|
return new KnownErrorType(
|
|
39
43
|
// @ts-expect-error
|
|
40
|
-
...
|
|
44
|
+
...constructorArgs);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
throw new Error(`Unknown KnownError code
|
|
47
|
+
throw new Error(`Unknown KnownError code. You may need to update your version of Stack to see more detailed information. ${json.code}: ${json.message}`);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
const knownErrorConstructorErrorCodeSentinel = Symbol("knownErrorConstructorErrorCodeSentinel");
|
|
@@ -56,7 +60,7 @@ function createKnownErrorConstructor(SuperClass, errorCode, create, constructorA
|
|
|
56
60
|
this.constructorArgs = args;
|
|
57
61
|
}
|
|
58
62
|
static constructorArgsFromJson(json) {
|
|
59
|
-
return constructorArgsFromJsonFn(json);
|
|
63
|
+
return constructorArgsFromJsonFn(json.details);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
KnownErrorImpl.errorCode = errorCode;
|
|
@@ -66,12 +70,12 @@ function createKnownErrorConstructor(SuperClass, errorCode, create, constructorA
|
|
|
66
70
|
}
|
|
67
71
|
const UnsupportedError = createKnownErrorConstructor(KnownError, "UNSUPPORTED_ERROR", (originalErrorCode) => [
|
|
68
72
|
500,
|
|
69
|
-
`An error
|
|
73
|
+
`An error occurred that is not currently supported (possibly because it was added in a version of Stack that is newer than this client). The original unsupported error code was: ${originalErrorCode}`,
|
|
70
74
|
{
|
|
71
75
|
originalErrorCode,
|
|
72
76
|
},
|
|
73
77
|
], (json) => [
|
|
74
|
-
json
|
|
78
|
+
json?.originalErrorCode ?? throwErr("originalErrorCode not found in UnsupportedError details"),
|
|
75
79
|
]);
|
|
76
80
|
const BodyParsingError = createKnownErrorConstructor(KnownError, "BODY_PARSING_ERROR", (message) => [
|
|
77
81
|
400,
|
|
@@ -79,7 +83,10 @@ const BodyParsingError = createKnownErrorConstructor(KnownError, "BODY_PARSING_E
|
|
|
79
83
|
], (json) => [json.message]);
|
|
80
84
|
const SchemaError = createKnownErrorConstructor(KnownError, "SCHEMA_ERROR", (message) => [
|
|
81
85
|
400,
|
|
82
|
-
message,
|
|
86
|
+
message || throwErr("SchemaError requires a message"),
|
|
87
|
+
{
|
|
88
|
+
message,
|
|
89
|
+
},
|
|
83
90
|
], (json) => [json.message]);
|
|
84
91
|
const AllOverloadsFailed = createKnownErrorConstructor(KnownError, "ALL_OVERLOADS_FAILED", (overloadErrors) => [
|
|
85
92
|
400,
|
|
@@ -94,58 +101,61 @@ const AllOverloadsFailed = createKnownErrorConstructor(KnownError, "ALL_OVERLOAD
|
|
|
94
101
|
overload_errors: overloadErrors,
|
|
95
102
|
},
|
|
96
103
|
], (json) => [
|
|
97
|
-
json
|
|
104
|
+
json?.overload_errors ?? throwErr("overload_errors not found in AllOverloadsFailed details"),
|
|
98
105
|
]);
|
|
99
106
|
const ProjectAuthenticationError = createKnownErrorConstructor(KnownError, "PROJECT_AUTHENTICATION_ERROR", "inherit", "inherit");
|
|
100
|
-
const
|
|
107
|
+
const InvalidProjectAuthentication = createKnownErrorConstructor(ProjectAuthenticationError, "INVALID_PROJECT_AUTHENTICATION", "inherit", "inherit");
|
|
108
|
+
// TODO next-release: delete deprecated error type
|
|
101
109
|
/**
|
|
102
110
|
* @deprecated Use ProjectKeyWithoutAccessType instead
|
|
103
111
|
*/
|
|
104
|
-
const ProjectKeyWithoutRequestType = createKnownErrorConstructor(
|
|
112
|
+
const ProjectKeyWithoutRequestType = createKnownErrorConstructor(InvalidProjectAuthentication, "PROJECT_KEY_WITHOUT_REQUEST_TYPE", () => [
|
|
105
113
|
400,
|
|
106
|
-
"Either an API key or an admin access token was provided, but the x-stack-
|
|
114
|
+
"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.",
|
|
107
115
|
], () => []);
|
|
116
|
+
// TODO next-release: delete deprecated error type
|
|
108
117
|
/**
|
|
109
118
|
* @deprecated Use InvalidAccessType instead
|
|
110
119
|
*/
|
|
111
|
-
const InvalidRequestType = createKnownErrorConstructor(
|
|
120
|
+
const InvalidRequestType = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_REQUEST_TYPE", (requestType) => [
|
|
112
121
|
400,
|
|
113
|
-
`The x-stack-
|
|
122
|
+
`The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${requestType}'.`,
|
|
114
123
|
], (json) => [
|
|
115
|
-
json
|
|
124
|
+
json?.requestType ?? throwErr("requestType not found in InvalidRequestType details"),
|
|
116
125
|
]);
|
|
126
|
+
// TODO next-release: delete deprecated error type
|
|
117
127
|
/**
|
|
118
128
|
* @deprecated Use AccessTypeWithoutProjectId instead
|
|
119
129
|
*/
|
|
120
|
-
const RequestTypeWithoutProjectId = createKnownErrorConstructor(
|
|
130
|
+
const RequestTypeWithoutProjectId = createKnownErrorConstructor(InvalidProjectAuthentication, "REQUEST_TYPE_WITHOUT_PROJECT_ID", (requestType) => [
|
|
121
131
|
400,
|
|
122
|
-
`The x-stack-
|
|
132
|
+
`The x-stack-access-type header was '${requestType}', but the x-stack-project-id header was not provided.`,
|
|
123
133
|
{
|
|
124
134
|
request_type: requestType,
|
|
125
135
|
},
|
|
126
136
|
], (json) => [json.request_type]);
|
|
127
|
-
const ProjectKeyWithoutAccessType = createKnownErrorConstructor(
|
|
137
|
+
const ProjectKeyWithoutAccessType = createKnownErrorConstructor(InvalidProjectAuthentication, "PROJECT_KEY_WITHOUT_ACCESS_TYPE", () => [
|
|
128
138
|
400,
|
|
129
139
|
"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.",
|
|
130
140
|
], () => []);
|
|
131
|
-
const InvalidAccessType = createKnownErrorConstructor(
|
|
141
|
+
const InvalidAccessType = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_ACCESS_TYPE", (accessType) => [
|
|
132
142
|
400,
|
|
133
|
-
`The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${
|
|
143
|
+
`The x-stack-access-type header must be 'client', 'server', or 'admin', but was '${accessType}'.`,
|
|
134
144
|
], (json) => [
|
|
135
|
-
json
|
|
145
|
+
json?.accessType ?? throwErr("accessType not found in InvalidAccessType details"),
|
|
136
146
|
]);
|
|
137
|
-
const AccessTypeWithoutProjectId = createKnownErrorConstructor(
|
|
147
|
+
const AccessTypeWithoutProjectId = createKnownErrorConstructor(InvalidProjectAuthentication, "ACCESS_TYPE_WITHOUT_PROJECT_ID", (accessType) => [
|
|
138
148
|
400,
|
|
139
|
-
`The x-stack-access-type header was '${
|
|
149
|
+
`The x-stack-access-type header was '${accessType}', but the x-stack-project-id header was not provided.`,
|
|
140
150
|
{
|
|
141
|
-
request_type:
|
|
151
|
+
request_type: accessType,
|
|
142
152
|
},
|
|
143
153
|
], (json) => [json.request_type]);
|
|
144
|
-
const AccessTypeRequired = createKnownErrorConstructor(
|
|
154
|
+
const AccessTypeRequired = createKnownErrorConstructor(InvalidProjectAuthentication, "ACCESS_TYPE_REQUIRED", () => [
|
|
145
155
|
400,
|
|
146
156
|
`You must specify an access level for this Stack project. Make sure project API keys are provided (eg. x-stack-publishable-client-key) and you set the x-stack-access-type header to 'client', 'server', or 'admin'.`,
|
|
147
157
|
], () => []);
|
|
148
|
-
const InsufficientAccessType = createKnownErrorConstructor(
|
|
158
|
+
const InsufficientAccessType = createKnownErrorConstructor(InvalidProjectAuthentication, "INSUFFICIENT_ACCESS_TYPE", (actualAccessType, allowedAccessTypes) => [
|
|
149
159
|
401,
|
|
150
160
|
`The x-stack-access-type header must be ${allowedAccessTypes.map(s => `'${s}'`).join(" or ")}, but was '${actualAccessType}'.`,
|
|
151
161
|
{
|
|
@@ -153,31 +163,31 @@ const InsufficientAccessType = createKnownErrorConstructor(InvalidProjectAccess,
|
|
|
153
163
|
allowed_access_types: allowedAccessTypes,
|
|
154
164
|
},
|
|
155
165
|
], (json) => [
|
|
156
|
-
json.
|
|
157
|
-
json.
|
|
166
|
+
json.actual_access_type,
|
|
167
|
+
json.allowed_access_types,
|
|
158
168
|
]);
|
|
159
|
-
const InvalidPublishableClientKey = createKnownErrorConstructor(
|
|
169
|
+
const InvalidPublishableClientKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_PUBLISHABLE_CLIENT_KEY", (projectId) => [
|
|
160
170
|
401,
|
|
161
171
|
`The publishable key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,
|
|
162
172
|
{
|
|
163
173
|
project_id: projectId,
|
|
164
174
|
},
|
|
165
175
|
], (json) => [json.project_id]);
|
|
166
|
-
const InvalidSecretServerKey = createKnownErrorConstructor(
|
|
176
|
+
const InvalidSecretServerKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_SECRET_SERVER_KEY", (projectId) => [
|
|
167
177
|
401,
|
|
168
178
|
`The secret server key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,
|
|
169
179
|
{
|
|
170
180
|
project_id: projectId,
|
|
171
181
|
},
|
|
172
182
|
], (json) => [json.project_id]);
|
|
173
|
-
const InvalidSuperSecretAdminKey = createKnownErrorConstructor(
|
|
183
|
+
const InvalidSuperSecretAdminKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_SUPER_SECRET_ADMIN_KEY", (projectId) => [
|
|
174
184
|
401,
|
|
175
185
|
`The super secret admin key is not valid for the project ${JSON.stringify(projectId)}. Does the project and/or the key exist?`,
|
|
176
186
|
{
|
|
177
187
|
project_id: projectId,
|
|
178
188
|
},
|
|
179
189
|
], (json) => [json.project_id]);
|
|
180
|
-
const InvalidAdminAccessToken = createKnownErrorConstructor(
|
|
190
|
+
const InvalidAdminAccessToken = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_ADMIN_ACCESS_TOKEN", "inherit", "inherit");
|
|
181
191
|
const UnparsableAdminAccessToken = createKnownErrorConstructor(InvalidAdminAccessToken, "UNPARSABLE_ADMIN_ACCESS_TOKEN", () => [
|
|
182
192
|
401,
|
|
183
193
|
"Admin access token is not parsable.",
|
|
@@ -259,22 +269,14 @@ const InvalidProjectForAccessToken = createKnownErrorConstructor(InvalidAccessTo
|
|
|
259
269
|
401,
|
|
260
270
|
"Access token not valid for this project.",
|
|
261
271
|
], () => []);
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
"User e-mail not verified, but is required by the project.",
|
|
265
|
-
], () => []);
|
|
266
|
-
const SessionAuthenticationRequired = createKnownErrorConstructor(SessionAuthenticationError, "SESSION_AUTHENTICATION_REQUIRED", () => [
|
|
272
|
+
const RefreshTokenError = createKnownErrorConstructor(KnownError, "REFRESH_TOKEN_ERROR", "inherit", "inherit");
|
|
273
|
+
const RefreshTokenNotFoundOrExpired = createKnownErrorConstructor(RefreshTokenError, "REFRESH_TOKEN_NOT_FOUND_OR_EXPIRED", () => [
|
|
267
274
|
401,
|
|
268
|
-
"
|
|
275
|
+
"Refresh token not found for this project, or the session has expired/been revoked.",
|
|
269
276
|
], () => []);
|
|
270
|
-
const RefreshTokenError = createKnownErrorConstructor(KnownError, "INVALID_REFRESH_TOKEN", "inherit", "inherit");
|
|
271
277
|
const ProviderRejected = createKnownErrorConstructor(RefreshTokenError, "PROVIDER_REJECTED", () => [
|
|
272
278
|
401,
|
|
273
|
-
"The provider refused to refresh their token.",
|
|
274
|
-
], () => []);
|
|
275
|
-
const InvalidRefreshToken = createKnownErrorConstructor(RefreshTokenError, "REFRESH_TOKEN_EXPIRED", () => [
|
|
276
|
-
401,
|
|
277
|
-
"Refresh token has expired. A new refresh token requires reauthentication.",
|
|
279
|
+
"The provider refused to refresh their token. This usually means that the provider used to authenticate the user no longer regards this session as valid, and the user must re-authenticate.",
|
|
278
280
|
], () => []);
|
|
279
281
|
const UserEmailAlreadyExists = createKnownErrorConstructor(KnownError, "USER_EMAIL_ALREADY_EXISTS", () => [
|
|
280
282
|
400,
|
|
@@ -292,9 +294,20 @@ const ApiKeyNotFound = createKnownErrorConstructor(KnownError, "API_KEY_NOT_FOUN
|
|
|
292
294
|
404,
|
|
293
295
|
"API key not found.",
|
|
294
296
|
], () => []);
|
|
295
|
-
const ProjectNotFound = createKnownErrorConstructor(KnownError, "PROJECT_NOT_FOUND", () =>
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
const ProjectNotFound = createKnownErrorConstructor(KnownError, "PROJECT_NOT_FOUND", (projectId) => {
|
|
298
|
+
if (typeof projectId !== "string")
|
|
299
|
+
throw new StackAssertionError("projectId of KnownErrors.ProjectNotFound must be a string");
|
|
300
|
+
return [
|
|
301
|
+
404,
|
|
302
|
+
`Project ${projectId} not found or is not accessible with the current user.`,
|
|
303
|
+
{
|
|
304
|
+
project_id: projectId,
|
|
305
|
+
},
|
|
306
|
+
];
|
|
307
|
+
}, (json) => [json.project_id]);
|
|
308
|
+
const PasswordAuthenticationNotEnabled = createKnownErrorConstructor(KnownError, "PASSWORD_AUTHENTICATION_NOT_ENABLED", () => [
|
|
309
|
+
400,
|
|
310
|
+
"Password authentication is not enabled for this project.",
|
|
298
311
|
], () => []);
|
|
299
312
|
const EmailPasswordMismatch = createKnownErrorConstructor(KnownError, "EMAIL_PASSWORD_MISMATCH", () => [
|
|
300
313
|
400,
|
|
@@ -309,10 +322,10 @@ const PasswordTooShort = createKnownErrorConstructor(PasswordRequirementsNotMet,
|
|
|
309
322
|
400,
|
|
310
323
|
`Password too short. Minimum length is ${minLength}.`,
|
|
311
324
|
{
|
|
312
|
-
minLength,
|
|
325
|
+
min_length: minLength,
|
|
313
326
|
},
|
|
314
327
|
], (json) => [
|
|
315
|
-
json
|
|
328
|
+
json?.min_length ?? throwErr("min_length not found in PasswordTooShort details"),
|
|
316
329
|
]);
|
|
317
330
|
const PasswordTooLong = createKnownErrorConstructor(PasswordRequirementsNotMet, "PASSWORD_TOO_LONG", (maxLength) => [
|
|
318
331
|
400,
|
|
@@ -321,8 +334,12 @@ const PasswordTooLong = createKnownErrorConstructor(PasswordRequirementsNotMet,
|
|
|
321
334
|
maxLength,
|
|
322
335
|
},
|
|
323
336
|
], (json) => [
|
|
324
|
-
json
|
|
337
|
+
json?.maxLength ?? throwErr("maxLength not found in PasswordTooLong details"),
|
|
325
338
|
]);
|
|
339
|
+
const UserDoesNotHavePassword = createKnownErrorConstructor(KnownError, "USER_DOES_NOT_HAVE_PASSWORD", () => [
|
|
340
|
+
400,
|
|
341
|
+
"This user does not have password authentication enabled.",
|
|
342
|
+
], () => []);
|
|
326
343
|
const VerificationCodeError = createKnownErrorConstructor(KnownError, "VERIFICATION_ERROR", "inherit", "inherit");
|
|
327
344
|
const VerificationCodeNotFound = createKnownErrorConstructor(VerificationCodeError, "VERIFICATION_CODE_NOT_FOUND", () => [
|
|
328
345
|
404,
|
|
@@ -336,7 +353,7 @@ const VerificationCodeAlreadyUsed = createKnownErrorConstructor(VerificationCode
|
|
|
336
353
|
400,
|
|
337
354
|
"The verification link has already been used.",
|
|
338
355
|
], () => []);
|
|
339
|
-
const
|
|
356
|
+
const PasswordConfirmationMismatch = createKnownErrorConstructor(KnownError, "PASSWORD_CONFIRMATION_MISMATCH", () => [
|
|
340
357
|
400,
|
|
341
358
|
"Passwords do not match.",
|
|
342
359
|
], () => []);
|
|
@@ -344,43 +361,47 @@ const EmailAlreadyVerified = createKnownErrorConstructor(KnownError, "EMAIL_ALRE
|
|
|
344
361
|
400,
|
|
345
362
|
"The e-mail is already verified.",
|
|
346
363
|
], () => []);
|
|
364
|
+
const EmailNotAssociatedWithUser = createKnownErrorConstructor(KnownError, "EMAIL_NOT_ASSOCIATED_WITH_USER", () => [
|
|
365
|
+
400,
|
|
366
|
+
"The e-mail is not associated with a user that could log in with that e-mail.",
|
|
367
|
+
], () => []);
|
|
368
|
+
const EmailIsNotPrimaryEmail = createKnownErrorConstructor(KnownError, "EMAIL_IS_NOT_PRIMARY_EMAIL", (email, primaryEmail) => [
|
|
369
|
+
400,
|
|
370
|
+
`The given e-mail (${email}) must equal the user's primary e-mail (${primaryEmail}).`,
|
|
371
|
+
{
|
|
372
|
+
email,
|
|
373
|
+
primary_email: primaryEmail,
|
|
374
|
+
},
|
|
375
|
+
], (json) => [json.email, json.primary_email]);
|
|
347
376
|
const PermissionNotFound = createKnownErrorConstructor(KnownError, "PERMISSION_NOT_FOUND", (permissionId) => [
|
|
348
377
|
404,
|
|
349
|
-
`Permission ${permissionId} not found. Make sure you created it on the dashboard.`,
|
|
378
|
+
`Permission "${permissionId}" not found. Make sure you created it on the dashboard.`,
|
|
350
379
|
{
|
|
351
380
|
permission_id: permissionId,
|
|
352
381
|
},
|
|
353
|
-
], (json) => [json.
|
|
354
|
-
const
|
|
355
|
-
return [
|
|
356
|
-
400,
|
|
357
|
-
`The scope of the permission with ID ${permissionId} is \`${permissionScope.type}\` but you tested against permissions of scope \`${testScope.type}\`. ${{
|
|
358
|
-
"global": `Please don't specify any teams when using global permissions. For example: \`user.hasPermission(${JSON.stringify(permissionId)})\`.`,
|
|
359
|
-
"any-team": `Please specify the team. For example: \`user.hasPermission(team, ${JSON.stringify(permissionId)})\`.`,
|
|
360
|
-
"specific-team": `Please specify the team. For example: \`user.hasPermission(team, ${JSON.stringify(permissionId)})\`.`,
|
|
361
|
-
}[permissionScope.type]}`,
|
|
362
|
-
{
|
|
363
|
-
permission_id: permissionId,
|
|
364
|
-
permission_scope: permissionScope,
|
|
365
|
-
test_scope: testScope,
|
|
366
|
-
},
|
|
367
|
-
];
|
|
368
|
-
}, (json) => [json.details.permission_id, json.details.permission_scope, json.details.test_scope]);
|
|
369
|
-
const UserNotInTeam = createKnownErrorConstructor(KnownError, "USER_NOT_IN_TEAM", (userId, teamId) => [
|
|
382
|
+
], (json) => [json.permission_id]);
|
|
383
|
+
const ContainedPermissionNotFound = createKnownErrorConstructor(KnownError, "CONTAINED_PERMISSION_NOT_FOUND", (permissionId) => [
|
|
370
384
|
400,
|
|
371
|
-
`
|
|
385
|
+
`Contained permission with ID "${permissionId}" not found. Make sure you created it on the dashboard.`,
|
|
372
386
|
{
|
|
373
|
-
|
|
374
|
-
team_id: teamId,
|
|
387
|
+
permission_id: permissionId,
|
|
375
388
|
},
|
|
376
|
-
], (json) => [json.
|
|
389
|
+
], (json) => [json.permission_id]);
|
|
377
390
|
const TeamNotFound = createKnownErrorConstructor(KnownError, "TEAM_NOT_FOUND", (teamId) => [
|
|
378
391
|
404,
|
|
379
392
|
`Team ${teamId} not found.`,
|
|
380
393
|
{
|
|
381
394
|
team_id: teamId,
|
|
382
395
|
},
|
|
383
|
-
], (json) => [json.
|
|
396
|
+
], (json) => [json.team_id]);
|
|
397
|
+
const TeamMembershipNotFound = createKnownErrorConstructor(KnownError, "TEAM_MEMBERSHIP_NOT_FOUND", (teamId, userId) => [
|
|
398
|
+
404,
|
|
399
|
+
`User ${userId} is not found in team ${teamId}.`,
|
|
400
|
+
{
|
|
401
|
+
team_id: teamId,
|
|
402
|
+
user_id: userId,
|
|
403
|
+
},
|
|
404
|
+
], (json) => [json.team_id, json.user_id]);
|
|
384
405
|
const EmailTemplateAlreadyExists = createKnownErrorConstructor(KnownError, "EMAIL_TEMPLATE_ALREADY_EXISTS", () => [
|
|
385
406
|
400,
|
|
386
407
|
"Email template already exists.",
|
|
@@ -405,6 +426,17 @@ const OAuthAccessTokenNotAvailableWithSharedOAuthKeys = createKnownErrorConstruc
|
|
|
405
426
|
400,
|
|
406
427
|
"Access tokens are not available with shared OAuth keys. Please add your own OAuth keys on the Stack dashboard to use access tokens.",
|
|
407
428
|
], () => []);
|
|
429
|
+
const InvalidOAuthClientIdOrSecret = createKnownErrorConstructor(KnownError, "INVALID_OAUTH_CLIENT_ID_OR_SECRET", (clientId) => [
|
|
430
|
+
400,
|
|
431
|
+
"The OAuth client ID or secret is invalid. The client ID must be equal to the project ID, and the client secret must be a publishable client key.",
|
|
432
|
+
{
|
|
433
|
+
client_id: clientId ?? null,
|
|
434
|
+
},
|
|
435
|
+
], (json) => [json.client_id ?? undefined]);
|
|
436
|
+
const InvalidScope = createKnownErrorConstructor(KnownError, "INVALID_SCOPE", (scope) => [
|
|
437
|
+
400,
|
|
438
|
+
`The scope "${scope}" is not a valid OAuth scope for Stack.`,
|
|
439
|
+
], (json) => [json.scope]);
|
|
408
440
|
const UserAlreadyConnectedToAnotherOAuthConnection = createKnownErrorConstructor(KnownError, "USER_ALREADY_CONNECTED_TO_ANOTHER_OAUTH_CONNECTION", () => [
|
|
409
441
|
400,
|
|
410
442
|
"The user is already connected to another OAuth account. Did you maybe selected the wrong account?",
|
|
@@ -413,13 +445,21 @@ const OuterOAuthTimeout = createKnownErrorConstructor(KnownError, "OUTER_OAUTH_T
|
|
|
413
445
|
408,
|
|
414
446
|
"The OAuth flow has timed out. Please sign in again.",
|
|
415
447
|
], () => []);
|
|
448
|
+
const OAuthProviderNotFoundOrNotEnabled = createKnownErrorConstructor(KnownError, "OAUTH_PROVIDER_NOT_FOUND_OR_NOT_ENABLED", () => [
|
|
449
|
+
400,
|
|
450
|
+
"The OAuth provider is not found or not enabled.",
|
|
451
|
+
], () => []);
|
|
452
|
+
const UserAuthenticationRequired = createKnownErrorConstructor(KnownError, "USER_AUTHENTICATION_REQUIRED", () => [
|
|
453
|
+
401,
|
|
454
|
+
"User authentication required for this endpoint.",
|
|
455
|
+
], () => []);
|
|
416
456
|
export const KnownErrors = {
|
|
417
457
|
UnsupportedError,
|
|
418
458
|
BodyParsingError,
|
|
419
459
|
SchemaError,
|
|
420
460
|
AllOverloadsFailed,
|
|
421
461
|
ProjectAuthenticationError,
|
|
422
|
-
InvalidProjectAuthentication
|
|
462
|
+
InvalidProjectAuthentication,
|
|
423
463
|
ProjectKeyWithoutRequestType,
|
|
424
464
|
InvalidRequestType,
|
|
425
465
|
RequestTypeWithoutProjectId,
|
|
@@ -451,37 +491,44 @@ export const KnownErrors = {
|
|
|
451
491
|
UnparsableAccessToken,
|
|
452
492
|
AccessTokenExpired,
|
|
453
493
|
InvalidProjectForAccessToken,
|
|
454
|
-
SessionUserEmailNotVerified,
|
|
455
|
-
SessionAuthenticationRequired,
|
|
456
494
|
RefreshTokenError,
|
|
457
495
|
ProviderRejected,
|
|
458
|
-
|
|
496
|
+
RefreshTokenNotFoundOrExpired,
|
|
459
497
|
UserEmailAlreadyExists,
|
|
460
498
|
UserNotFound,
|
|
461
499
|
ApiKeyNotFound,
|
|
462
500
|
ProjectNotFound,
|
|
501
|
+
PasswordAuthenticationNotEnabled,
|
|
463
502
|
EmailPasswordMismatch,
|
|
464
503
|
RedirectUrlNotWhitelisted,
|
|
465
504
|
PasswordRequirementsNotMet,
|
|
466
505
|
PasswordTooShort,
|
|
467
506
|
PasswordTooLong,
|
|
507
|
+
UserDoesNotHavePassword,
|
|
468
508
|
VerificationCodeError,
|
|
469
509
|
VerificationCodeNotFound,
|
|
470
510
|
VerificationCodeExpired,
|
|
471
511
|
VerificationCodeAlreadyUsed,
|
|
472
|
-
|
|
512
|
+
PasswordConfirmationMismatch,
|
|
473
513
|
EmailAlreadyVerified,
|
|
514
|
+
EmailNotAssociatedWithUser,
|
|
515
|
+
EmailIsNotPrimaryEmail,
|
|
474
516
|
PermissionNotFound,
|
|
475
|
-
|
|
517
|
+
ContainedPermissionNotFound,
|
|
476
518
|
TeamNotFound,
|
|
519
|
+
TeamMembershipNotFound,
|
|
477
520
|
EmailTemplateAlreadyExists,
|
|
478
521
|
OAuthConnectionNotConnectedToUser,
|
|
479
522
|
OAuthConnectionAlreadyConnectedToAnotherUser,
|
|
480
523
|
OAuthConnectionDoesNotHaveRequiredScope,
|
|
481
524
|
OAuthExtraScopeNotAvailableWithSharedOAuthKeys,
|
|
482
525
|
OAuthAccessTokenNotAvailableWithSharedOAuthKeys,
|
|
526
|
+
InvalidOAuthClientIdOrSecret,
|
|
527
|
+
InvalidScope,
|
|
483
528
|
UserAlreadyConnectedToAnotherOAuthConnection,
|
|
484
529
|
OuterOAuthTimeout,
|
|
530
|
+
OAuthProviderNotFoundOrNotEnabled,
|
|
531
|
+
UserAuthenticationRequired,
|
|
485
532
|
};
|
|
486
533
|
// ensure that all known error codes are unique
|
|
487
534
|
const knownErrorCodes = new Set();
|
package/dist/schema-fields.d.ts
CHANGED
|
@@ -1,22 +1,59 @@
|
|
|
1
1
|
import * as yup from "yup";
|
|
2
2
|
declare const StackAdaptSentinel: unique symbol;
|
|
3
3
|
export type StackAdaptSentinel = typeof StackAdaptSentinel;
|
|
4
|
+
export declare function yupString<A extends string, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.string<A, B>>): yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
5
|
+
export declare function yupNumber<A extends number, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.number<A, B>>): yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
|
|
6
|
+
export declare function yupBoolean<A extends boolean, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.boolean<A, B>>): yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated, use number of milliseconds since epoch instead
|
|
9
|
+
*/
|
|
10
|
+
export declare function yupDate<A extends Date, B extends yup.Maybe<yup.AnyObject> = yup.AnyObject>(...args: Parameters<typeof yup.date<A, B>>): yup.DateSchema<Date | undefined, yup.AnyObject, undefined, "">;
|
|
11
|
+
export declare function yupMixed<A extends {}>(...args: Parameters<typeof yup.mixed<A>>): yup.MixedSchema<A | undefined, yup.AnyObject, undefined, "">;
|
|
12
|
+
export declare function yupArray<A extends yup.Maybe<yup.AnyObject> = yup.AnyObject, B = any>(...args: Parameters<typeof yup.array<A, B>>): yup.ArraySchema<B[] | undefined, A, undefined, "">;
|
|
13
|
+
export declare function yupTuple<T extends [unknown, ...unknown[]]>(...args: Parameters<typeof yup.tuple<T>>): yup.TupleSchema<T | undefined, yup.AnyObject, undefined, "">;
|
|
14
|
+
export declare function yupObject<A extends yup.Maybe<yup.AnyObject>, B extends yup.ObjectShape>(...args: Parameters<typeof yup.object<A, B>>): yup.ObjectSchema<yup.TypeFromShape<B, yup.AnyObject> extends infer T ? T extends yup.TypeFromShape<B, yup.AnyObject> ? T extends {} ? { [k in keyof T]: T[k]; } : T : never : never, yup.AnyObject, yup.DefaultFromShape<B> extends infer T_1 ? T_1 extends yup.DefaultFromShape<B> ? T_1 extends {} ? { [k_1 in keyof T_1]: T_1[k_1]; } : T_1 : never : never, "">;
|
|
4
15
|
export declare const adaptSchema: yup.MixedSchema<typeof StackAdaptSentinel | undefined, yup.AnyObject, undefined, "">;
|
|
5
16
|
/**
|
|
6
17
|
* Yup's URL schema does not recognize some URLs (including `http://localhost`) as a valid URL. This schema is a workaround for that.
|
|
7
18
|
*/
|
|
8
19
|
export declare const urlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
20
|
+
export declare const jsonSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
|
|
21
|
+
export declare const jsonStringSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
22
|
+
export declare const emailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
9
23
|
export declare const clientOrHigherAuthTypeSchema: yup.StringSchema<"client" | "server" | "admin" | undefined, yup.AnyObject, undefined, "">;
|
|
10
24
|
export declare const serverOrHigherAuthTypeSchema: yup.StringSchema<"server" | "admin" | undefined, yup.AnyObject, undefined, "">;
|
|
11
25
|
export declare const adminAuthTypeSchema: yup.StringSchema<"admin" | undefined, yup.AnyObject, undefined, "">;
|
|
12
26
|
export declare const projectIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
13
|
-
export declare const
|
|
27
|
+
export declare const projectDisplayNameSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
28
|
+
export declare const projectDescriptionSchema: yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
|
|
29
|
+
export declare const projectCreatedAtMillisSchema: yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
|
|
30
|
+
export declare const projectUserCountSchema: yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
|
|
31
|
+
export declare const projectIsProductionModeSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
32
|
+
export declare const projectConfigIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
33
|
+
export declare const projectAllowLocalhostSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
34
|
+
export declare const projectCreateTeamOnSignUpSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
35
|
+
export declare const projectMagicLinkEnabledSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
36
|
+
export declare const projectCredentialEnabledSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
37
|
+
export declare const oauthIdSchema: yup.StringSchema<"google" | "github" | "facebook" | "microsoft" | "spotify" | undefined, yup.AnyObject, undefined, "">;
|
|
38
|
+
export declare const oauthEnabledSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
39
|
+
export declare const oauthTypeSchema: yup.StringSchema<"shared" | "standard" | undefined, yup.AnyObject, undefined, "">;
|
|
40
|
+
export declare const oauthClientIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
41
|
+
export declare const oauthClientSecretSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
42
|
+
export declare const emailTypeSchema: yup.StringSchema<"shared" | "standard" | undefined, yup.AnyObject, undefined, "">;
|
|
43
|
+
export declare const emailSenderNameSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
44
|
+
export declare const emailHostSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
45
|
+
export declare const emailPortSchema: yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
|
|
46
|
+
export declare const emailUsernameSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
47
|
+
export declare const emailSenderEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
48
|
+
export declare const emailPasswordSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
49
|
+
export declare const domainSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
50
|
+
export declare const handlerPathSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
14
51
|
export declare class ReplaceFieldWithOwnUserId extends Error {
|
|
15
52
|
readonly path: string;
|
|
16
53
|
constructor(path: string);
|
|
17
54
|
}
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
55
|
+
export declare const userIdOrMeSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
56
|
+
export declare const userIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
20
57
|
export declare const primaryEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
21
58
|
export declare const primaryEmailVerifiedSchema: yup.BooleanSchema<boolean | undefined, yup.AnyObject, undefined, "">;
|
|
22
59
|
export declare const userDisplayNameSchema: yup.StringSchema<string | null | undefined, yup.AnyObject, undefined, "">;
|
|
@@ -26,7 +63,8 @@ export declare const signedUpAtMillisSchema: yup.NumberSchema<number | undefined
|
|
|
26
63
|
export declare const userClientMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
|
|
27
64
|
export declare const userServerMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
|
|
28
65
|
export declare const signInEmailSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
29
|
-
export declare const
|
|
66
|
+
export declare const emailOtpSignInCallbackUrlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
67
|
+
export declare const emailVerificationCallbackUrlSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
30
68
|
export declare const accessTokenResponseSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
31
69
|
export declare const refreshTokenResponseSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
32
70
|
export declare const signInResponseSchema: yup.ObjectSchema<{
|
|
@@ -40,4 +78,15 @@ export declare const signInResponseSchema: yup.ObjectSchema<{
|
|
|
40
78
|
is_new_user: undefined;
|
|
41
79
|
user_id: undefined;
|
|
42
80
|
}, "">;
|
|
81
|
+
export declare const teamSystemPermissions: readonly ["$update_team", "$delete_team", "$read_members", "$remove_members", "$invite_members"];
|
|
82
|
+
export declare const teamPermissionIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
83
|
+
export declare const customTeamPermissionIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
84
|
+
export declare const teamPermissionDescriptionSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
85
|
+
export declare const containedPermissionIdsSchema: yup.ArraySchema<string[] | undefined, yup.AnyObject, undefined, "">;
|
|
86
|
+
export declare const teamIdSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
87
|
+
export declare const teamDisplayNameSchema: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
|
|
88
|
+
export declare const teamClientMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
|
|
89
|
+
export declare const teamServerMetadataSchema: yup.MixedSchema<{} | null, yup.AnyObject, undefined, "">;
|
|
90
|
+
export declare const teamCreatedAtMillisSchema: yup.NumberSchema<number | undefined, yup.AnyObject, undefined, "">;
|
|
91
|
+
export declare function yupRequiredWhen<S extends yup.AnyObject>(schema: S, triggerName: string, isValue: any): S;
|
|
43
92
|
export {};
|