@stackframe/stack-shared 2.0.0 → 2.2.0

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.
Files changed (44) hide show
  1. package/dist/helpers/fetch-token.d.ts +1 -0
  2. package/dist/helpers/password.d.ts +2 -1
  3. package/dist/helpers/password.d.ts.map +1 -1
  4. package/dist/helpers/password.js +8 -29
  5. package/dist/hooks/use-async-callback.d.ts +3 -0
  6. package/dist/hooks/use-async-callback.d.ts.map +1 -0
  7. package/dist/hooks/use-async-callback.js +32 -0
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/interface/clientInterface.d.ts +21 -24
  12. package/dist/interface/clientInterface.d.ts.map +1 -1
  13. package/dist/interface/clientInterface.js +109 -67
  14. package/dist/interface/serverInterface.d.ts.map +1 -1
  15. package/dist/known-errors.d.ts +202 -0
  16. package/dist/known-errors.d.ts.map +1 -0
  17. package/dist/known-errors.js +316 -0
  18. package/dist/utils/arrays.d.ts +1 -1
  19. package/dist/utils/arrays.d.ts.map +1 -1
  20. package/dist/utils/caches.d.ts +3 -0
  21. package/dist/utils/caches.d.ts.map +1 -1
  22. package/dist/utils/caches.js +18 -14
  23. package/dist/utils/crypto.d.ts +4 -0
  24. package/dist/utils/crypto.d.ts.map +1 -1
  25. package/dist/utils/crypto.js +10 -6
  26. package/dist/utils/errors.d.ts +13 -7
  27. package/dist/utils/errors.d.ts.map +1 -1
  28. package/dist/utils/errors.js +44 -3
  29. package/dist/utils/functions.d.ts +2 -0
  30. package/dist/utils/functions.d.ts.map +1 -0
  31. package/dist/utils/functions.js +6 -0
  32. package/dist/utils/objects.d.ts +5 -0
  33. package/dist/utils/objects.d.ts.map +1 -1
  34. package/dist/utils/objects.js +6 -0
  35. package/dist/utils/promises.d.ts +3 -1
  36. package/dist/utils/promises.d.ts.map +1 -1
  37. package/dist/utils/promises.js +24 -4
  38. package/dist/utils/stores.d.ts +2 -2
  39. package/dist/utils/stores.d.ts.map +1 -1
  40. package/dist/utils/stores.js +32 -19
  41. package/dist/utils/types.d.ts +5 -1
  42. package/dist/utils/types.d.ts.map +1 -1
  43. package/dist/utils/types.js +4 -1
  44. package/package.json +4 -15
@@ -0,0 +1,202 @@
1
+ import { StatusError } from "./utils/errors";
2
+ import { Json } from "./utils/json";
3
+ export type KnownErrorJson = {
4
+ code: string;
5
+ message: string;
6
+ details?: Json;
7
+ };
8
+ export type AbstractKnownErrorConstructor<Args extends any[]> = (abstract new (...args: Args) => KnownError) & {
9
+ constructorArgsFromJson: (json: KnownErrorJson) => Args;
10
+ };
11
+ export type KnownErrorConstructor<Instance extends KnownError, Args extends any[]> = {
12
+ new (...args: Args): Instance;
13
+ errorCode: string;
14
+ constructorArgsFromJson: (json: KnownErrorJson) => Args;
15
+ };
16
+ export declare abstract class KnownError extends StatusError {
17
+ readonly statusCode: number;
18
+ readonly humanReadableMessage: string;
19
+ readonly details?: Json | undefined;
20
+ constructor(statusCode: number, humanReadableMessage: string, details?: Json | undefined);
21
+ getBody(): Uint8Array;
22
+ getHeaders(): Record<string, string[]>;
23
+ get errorCode(): string;
24
+ static constructorArgsFromJson(json: KnownErrorJson): ConstructorParameters<typeof KnownError>;
25
+ static fromJson(json: KnownErrorJson): KnownError;
26
+ }
27
+ declare const knownErrorConstructorErrorCodeSentinel: unique symbol;
28
+ /**
29
+ * Exists solely so that known errors are nominative types (ie. two KnownErrors with the same interface are not the same type)
30
+ */
31
+ type KnownErrorBrand<ErrorCode extends string> = {
32
+ /**
33
+ * Does not exist at runtime
34
+ *
35
+ * Must be an object because it may be true for multiple error codes (it's true for all parents)
36
+ */
37
+ [knownErrorConstructorErrorCodeSentinel]: {
38
+ [K in ErrorCode]: true;
39
+ };
40
+ };
41
+ export type KnownErrors = {
42
+ [K in keyof typeof KnownErrors]: InstanceType<typeof KnownErrors[K]>;
43
+ };
44
+ export declare const KnownErrors: {
45
+ UnsupportedError: KnownErrorConstructor<KnownError & KnownErrorBrand<"UNSUPPORTED_ERROR">, [originalErrorCode: string]> & {
46
+ errorCode: "UNSUPPORTED_ERROR";
47
+ };
48
+ SchemaError: KnownErrorConstructor<KnownError & KnownErrorBrand<"SCHEMA_ERROR">, [string]> & {
49
+ errorCode: "SCHEMA_ERROR";
50
+ };
51
+ AllOverloadsFailed: KnownErrorConstructor<KnownError & KnownErrorBrand<"ALL_OVERLOADS_FAILED">, [overloadErrors: Json[]]> & {
52
+ errorCode: "ALL_OVERLOADS_FAILED";
53
+ };
54
+ ProjectAuthenticationError: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
55
+ errorCode: "PROJECT_AUTHENTICATION_ERROR";
56
+ };
57
+ InvalidProjectAuthentication: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
58
+ errorCode: "INVALID_PROJECT_AUTHENTICATION";
59
+ };
60
+ InvalidPublishableClientKey: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_PUBLISHABLE_CLIENT_KEY">, []> & {
61
+ errorCode: "INVALID_PUBLISHABLE_CLIENT_KEY";
62
+ };
63
+ InvalidSecretServerKey: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_SECRET_SERVER_KEY">, []> & {
64
+ errorCode: "INVALID_SECRET_SERVER_KEY";
65
+ };
66
+ InvalidSuperSecretAdminKey: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_SUPER_SECRET_ADMIN_KEY">, []> & {
67
+ errorCode: "INVALID_SUPER_SECRET_ADMIN_KEY";
68
+ };
69
+ InvalidAdminAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ADMIN_ACCESS_TOKEN">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
70
+ errorCode: "INVALID_ADMIN_ACCESS_TOKEN";
71
+ };
72
+ UnparsableAdminAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ADMIN_ACCESS_TOKEN"> & KnownErrorBrand<"UNPARSABLE_ADMIN_ACCESS_TOKEN">, []> & {
73
+ errorCode: "UNPARSABLE_ADMIN_ACCESS_TOKEN";
74
+ };
75
+ AdminAccessTokenExpired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ADMIN_ACCESS_TOKEN"> & KnownErrorBrand<"ADMIN_ACCESS_TOKEN_EXPIRED">, []> & {
76
+ errorCode: "ADMIN_ACCESS_TOKEN_EXPIRED";
77
+ };
78
+ InvalidProjectForAdminAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_PROJECT_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ADMIN_ACCESS_TOKEN"> & KnownErrorBrand<"INVALID_PROJECT_FOR_ADMIN_ACCESS_TOKEN">, []> & {
79
+ errorCode: "INVALID_PROJECT_FOR_ADMIN_ACCESS_TOKEN";
80
+ };
81
+ ProjectAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
82
+ errorCode: "PROJECT_AUTHENTICATION_REQUIRED";
83
+ };
84
+ ClientAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"CLIENT_AUTHENTICATION_REQUIRED">, []> & {
85
+ errorCode: "CLIENT_AUTHENTICATION_REQUIRED";
86
+ };
87
+ ServerAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"SERVER_AUTHENTICATION_REQUIRED">, []> & {
88
+ errorCode: "SERVER_AUTHENTICATION_REQUIRED";
89
+ };
90
+ ClientOrServerAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"CLIENT_OR_SERVER_AUTHENTICATION_REQUIRED">, []> & {
91
+ errorCode: "CLIENT_OR_SERVER_AUTHENTICATION_REQUIRED";
92
+ };
93
+ ClientOrAdminAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"CLIENT_OR_ADMIN_AUTHENTICATION_REQUIRED">, []> & {
94
+ errorCode: "CLIENT_OR_ADMIN_AUTHENTICATION_REQUIRED";
95
+ };
96
+ ClientOrServerOrAdminAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"CLIENT_OR_SERVER_OR_ADMIN_AUTHENTICATION_REQUIRED">, []> & {
97
+ errorCode: "CLIENT_OR_SERVER_OR_ADMIN_AUTHENTICATION_REQUIRED";
98
+ };
99
+ AdminAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"PROJECT_AUTHENTICATION_REQUIRED"> & KnownErrorBrand<"ADMIN_AUTHENTICATION_REQUIRED">, []> & {
100
+ errorCode: "ADMIN_AUTHENTICATION_REQUIRED";
101
+ };
102
+ ExpectedInternalProject: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_AUTHENTICATION_ERROR"> & KnownErrorBrand<"EXPECTED_INTERNAL_PROJECT">, []> & {
103
+ errorCode: "EXPECTED_INTERNAL_PROJECT";
104
+ };
105
+ SessionAuthenticationError: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
106
+ errorCode: "SESSION_AUTHENTICATION_ERROR";
107
+ };
108
+ InvalidSessionAuthentication: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
109
+ errorCode: "INVALID_SESSION_AUTHENTICATION";
110
+ };
111
+ InvalidAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TOKEN">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
112
+ errorCode: "INVALID_ACCESS_TOKEN";
113
+ };
114
+ UnparsableAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TOKEN"> & KnownErrorBrand<"UNPARSABLE_ACCESS_TOKEN">, []> & {
115
+ errorCode: "UNPARSABLE_ACCESS_TOKEN";
116
+ };
117
+ AccessTokenExpired: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TOKEN"> & KnownErrorBrand<"ACCESS_TOKEN_EXPIRED">, []> & {
118
+ errorCode: "ACCESS_TOKEN_EXPIRED";
119
+ };
120
+ InvalidProjectForAccessToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"INVALID_ACCESS_TOKEN"> & KnownErrorBrand<"INVALID_PROJECT_FOR_ACCESS_TOKEN">, []> & {
121
+ errorCode: "INVALID_PROJECT_FOR_ACCESS_TOKEN";
122
+ };
123
+ SessionUserEmailNotVerified: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"INVALID_SESSION_AUTHENTICATION"> & KnownErrorBrand<"SESSION_USER_EMAIL_NOT_VERIFIED">, []> & {
124
+ errorCode: "SESSION_USER_EMAIL_NOT_VERIFIED";
125
+ };
126
+ SessionAuthenticationRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"SESSION_AUTHENTICATION_ERROR"> & KnownErrorBrand<"SESSION_AUTHENTICATION_REQUIRED">, []> & {
127
+ errorCode: "SESSION_AUTHENTICATION_REQUIRED";
128
+ };
129
+ RefreshTokenError: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_REFRESH_TOKEN">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
130
+ errorCode: "INVALID_REFRESH_TOKEN";
131
+ };
132
+ ProviderRejected: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_REFRESH_TOKEN"> & KnownErrorBrand<"PROVIDER_REJECTED">, []> & {
133
+ errorCode: "PROVIDER_REJECTED";
134
+ };
135
+ InvalidRefreshToken: KnownErrorConstructor<KnownError & KnownErrorBrand<"INVALID_REFRESH_TOKEN"> & KnownErrorBrand<"REFRESH_TOKEN_EXPIRED">, []> & {
136
+ errorCode: "REFRESH_TOKEN_EXPIRED";
137
+ };
138
+ UserEmailAlreadyExists: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_EMAIL_ALREADY_EXISTS">, []> & {
139
+ errorCode: "USER_EMAIL_ALREADY_EXISTS";
140
+ };
141
+ UserNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_NOT_FOUND">, []> & {
142
+ errorCode: "USER_NOT_FOUND";
143
+ };
144
+ ApiKeyNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"API_KEY_NOT_FOUND">, []> & {
145
+ errorCode: "API_KEY_NOT_FOUND";
146
+ };
147
+ ProjectNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PROJECT_NOT_FOUND">, []> & {
148
+ errorCode: "PROJECT_NOT_FOUND";
149
+ };
150
+ EmailPasswordMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_PASSWORD_MISMATCH">, []> & {
151
+ errorCode: "EMAIL_PASSWORD_MISMATCH";
152
+ };
153
+ RedirectUrlNotWhitelisted: KnownErrorConstructor<KnownError & KnownErrorBrand<"REDIRECT_URL_NOT_WHITELISTED">, []> & {
154
+ errorCode: "REDIRECT_URL_NOT_WHITELISTED";
155
+ };
156
+ PasswordRequirementsNotMet: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_REQUIREMENTS_NOT_MET">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
157
+ errorCode: "PASSWORD_REQUIREMENTS_NOT_MET";
158
+ };
159
+ PasswordTooShort: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_REQUIREMENTS_NOT_MET"> & KnownErrorBrand<"PASSWORD_TOO_SHORT">, [minLength: number]> & {
160
+ errorCode: "PASSWORD_TOO_SHORT";
161
+ };
162
+ PasswordTooLong: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_REQUIREMENTS_NOT_MET"> & KnownErrorBrand<"PASSWORD_TOO_LONG">, [maxLength: number]> & {
163
+ errorCode: "PASSWORD_TOO_LONG";
164
+ };
165
+ EmailVerificationError: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_VERIFICATION_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
166
+ errorCode: "EMAIL_VERIFICATION_ERROR";
167
+ };
168
+ EmailVerificationCodeError: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_VERIFICATION_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
169
+ errorCode: "EMAIL_VERIFICATION_CODE_ERROR";
170
+ };
171
+ EmailVerificationCodeNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_VERIFICATION_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_NOT_FOUND">, []> & {
172
+ errorCode: "EMAIL_VERIFICATION_CODE_NOT_FOUND";
173
+ };
174
+ EmailVerificationCodeExpired: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_VERIFICATION_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_EXPIRED">, []> & {
175
+ errorCode: "EMAIL_VERIFICATION_CODE_EXPIRED";
176
+ };
177
+ EmailVerificationCodeAlreadyUsed: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_VERIFICATION_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_ERROR"> & KnownErrorBrand<"EMAIL_VERIFICATION_CODE_ALREADY_USED">, []> & {
178
+ errorCode: "EMAIL_VERIFICATION_CODE_ALREADY_USED";
179
+ };
180
+ PasswordResetError: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_RESET_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
181
+ errorCode: "PASSWORD_RESET_ERROR";
182
+ };
183
+ PasswordResetCodeError: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_RESET_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_ERROR">, [statusCode: number, humanReadableMessage: string, details?: Json | undefined]> & {
184
+ errorCode: "PASSWORD_RESET_CODE_ERROR";
185
+ };
186
+ PasswordResetCodeNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_RESET_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_NOT_FOUND">, []> & {
187
+ errorCode: "PASSWORD_RESET_CODE_NOT_FOUND";
188
+ };
189
+ PasswordResetCodeExpired: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_RESET_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_EXPIRED">, []> & {
190
+ errorCode: "PASSWORD_RESET_CODE_EXPIRED";
191
+ };
192
+ PasswordResetCodeAlreadyUsed: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_RESET_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_ERROR"> & KnownErrorBrand<"PASSWORD_RESET_CODE_ALREADY_USED">, []> & {
193
+ errorCode: "PASSWORD_RESET_CODE_ALREADY_USED";
194
+ };
195
+ PasswordMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"PASSWORD_MISMATCH">, []> & {
196
+ errorCode: "PASSWORD_MISMATCH";
197
+ };
198
+ EmailAlreadyVerified: KnownErrorConstructor<KnownError & KnownErrorBrand<"EMAIL_ALREADY_VERIFIED">, []> & {
199
+ errorCode: "EMAIL_ALREADY_VERIFIED";
200
+ };
201
+ };
202
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"known-errors.d.ts","sourceRoot":"","sources":["../src/known-errors.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA2B,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,6BAA6B,CAAC,IAAI,SAAS,GAAG,EAAE,IACxD,CAAC,QAAQ,MAAM,GAAG,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,GAC5C;IACA,uBAAuB,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CACzD,CAAC;AAEJ,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,UAAU,EAAE,IAAI,SAAS,GAAG,EAAE,IAAI;IACnF,KAAK,GAAG,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CACzD,CAAC;AAEF,8BAAsB,UAAW,SAAQ,WAAW;aAEhC,UAAU,EAAE,MAAM;aAClB,oBAAoB,EAAE,MAAM;aAC5B,OAAO,CAAC;gBAFR,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,MAAM,EAC5B,OAAO,CAAC,kBAAM;IAQhB,OAAO,IAAI,UAAU;IAQrB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAOtD,IAAI,SAAS,IAAI,MAAM,CAEtB;WAEa,uBAAuB,CAAC,IAAI,EAAE,cAAc,GAAG,qBAAqB,CAAC,OAAO,UAAU,CAAC;WAQvF,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU;CAYzD;AAED,QAAA,MAAM,sCAAsC,eAAmD,CAAC;AAChG;;GAEG;AACH,KAAK,eAAe,CAAC,SAAS,SAAS,MAAM,IAAI;IAC/C;;;;OAIG;IACH,CAAC,sCAAsC,CAAC,EAAE;SACvC,CAAC,IAAI,SAAS,GAAG,IAAI;KACvB,CAAC;CACH,CAAC;AA8hBF,MAAM,MAAM,WAAW,GAAG;KACvB,CAAC,IAAI,MAAM,OAAO,WAAW,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;CACrE,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDmC,CAAC"}
@@ -0,0 +1,316 @@
1
+ import { StatusError, throwErr, throwStackErr } from "./utils/errors";
2
+ import { identityArgs } from "./utils/functions";
3
+ export class KnownError extends StatusError {
4
+ statusCode;
5
+ humanReadableMessage;
6
+ details;
7
+ constructor(statusCode, humanReadableMessage, details) {
8
+ super(statusCode, humanReadableMessage);
9
+ this.statusCode = statusCode;
10
+ this.humanReadableMessage = humanReadableMessage;
11
+ this.details = details;
12
+ }
13
+ getBody() {
14
+ return new TextEncoder().encode(JSON.stringify({
15
+ code: this.errorCode,
16
+ message: this.humanReadableMessage,
17
+ details: this.details,
18
+ }, undefined, 2));
19
+ }
20
+ getHeaders() {
21
+ return {
22
+ "Content-Type": ["application/json; charset=utf-8"],
23
+ "X-Stack-Known-Error": [this.errorCode],
24
+ };
25
+ }
26
+ get errorCode() {
27
+ return this.constructor.errorCode ?? throwStackErr(`Can't find error code for this KnownError. Is its constructor a KnownErrorConstructor? ${this}`);
28
+ }
29
+ static constructorArgsFromJson(json) {
30
+ return [
31
+ 400,
32
+ json.message,
33
+ json.details,
34
+ ];
35
+ }
36
+ static fromJson(json) {
37
+ for (const [_, KnownErrorType] of Object.entries(KnownErrors)) {
38
+ if (json.code === KnownErrorType.prototype.errorCode) {
39
+ return new KnownErrorType(
40
+ // @ts-expect-error
41
+ ...KnownErrorType.constructorArgsFromJson(json));
42
+ }
43
+ }
44
+ throw new Error(`Unknown KnownError code: ${json.code}`);
45
+ }
46
+ }
47
+ const knownErrorConstructorErrorCodeSentinel = Symbol("knownErrorConstructorErrorCodeSentinel");
48
+ function createKnownErrorConstructor(SuperClass, errorCode, create, constructorArgsFromJson) {
49
+ const createFn = create === "inherit" ? identityArgs : create;
50
+ const constructorArgsFromJsonFn = constructorArgsFromJson === "inherit" ? SuperClass.constructorArgsFromJson : constructorArgsFromJson;
51
+ // @ts-expect-error this is not a mixin, but TS detects it as one
52
+ class KnownErrorImpl extends SuperClass {
53
+ static errorCode = errorCode;
54
+ constructor(...args) {
55
+ // @ts-expect-error
56
+ super(...createFn(...args));
57
+ }
58
+ static constructorArgsFromJson(json) {
59
+ return constructorArgsFromJsonFn(json);
60
+ }
61
+ }
62
+ ;
63
+ // @ts-expect-error
64
+ return KnownErrorImpl;
65
+ }
66
+ const UnsupportedError = createKnownErrorConstructor(KnownError, "UNSUPPORTED_ERROR", (originalErrorCode) => [
67
+ 500,
68
+ `An error occured 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}`,
69
+ {
70
+ originalErrorCode,
71
+ },
72
+ ], (json) => [
73
+ json.details?.originalErrorCode ?? throwErr("originalErrorCode not found in UnsupportedError details"),
74
+ ]);
75
+ const SchemaError = createKnownErrorConstructor(KnownError, "SCHEMA_ERROR", (message) => [
76
+ 400,
77
+ message,
78
+ ], (json) => [json.message]);
79
+ const AllOverloadsFailed = createKnownErrorConstructor(KnownError, "ALL_OVERLOADS_FAILED", (overloadErrors) => [
80
+ 400,
81
+ "This endpoint has multiple overloads, but they all failed to process the request.",
82
+ {
83
+ overloads: overloadErrors,
84
+ },
85
+ ], (json) => [
86
+ json.details?.overloadErrors ?? throwErr("overloadErrors not found in AllOverloadsFailed details"),
87
+ ]);
88
+ const ProjectAuthenticationError = createKnownErrorConstructor(KnownError, "PROJECT_AUTHENTICATION_ERROR", "inherit", "inherit");
89
+ const InvalidProjectAuthentication = createKnownErrorConstructor(ProjectAuthenticationError, "INVALID_PROJECT_AUTHENTICATION", "inherit", "inherit");
90
+ const InvalidPublishableClientKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_PUBLISHABLE_CLIENT_KEY", () => [
91
+ 401,
92
+ "The publishable key is not valid for the given project. Does the project and/or the key exist?",
93
+ ], () => []);
94
+ const InvalidSecretServerKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_SECRET_SERVER_KEY", () => [
95
+ 401,
96
+ "The secret server key is not valid for the given project. Does the project and/or the key exist?",
97
+ ], () => []);
98
+ const InvalidSuperSecretAdminKey = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_SUPER_SECRET_ADMIN_KEY", () => [
99
+ 401,
100
+ "The super secret admin key is not valid for the given project. Does the project and/or the key exist?",
101
+ ], () => []);
102
+ const InvalidAdminAccessToken = createKnownErrorConstructor(InvalidProjectAuthentication, "INVALID_ADMIN_ACCESS_TOKEN", "inherit", "inherit");
103
+ const UnparsableAdminAccessToken = createKnownErrorConstructor(InvalidAdminAccessToken, "UNPARSABLE_ADMIN_ACCESS_TOKEN", () => [
104
+ 401,
105
+ "Admin access token is not parsable.",
106
+ ], () => []);
107
+ const AdminAccessTokenExpired = createKnownErrorConstructor(InvalidAdminAccessToken, "ADMIN_ACCESS_TOKEN_EXPIRED", () => [
108
+ 401,
109
+ "Admin access token has expired. Please refresh it and try again.",
110
+ ], () => []);
111
+ const InvalidProjectForAdminAccessToken = createKnownErrorConstructor(InvalidAdminAccessToken, "INVALID_PROJECT_FOR_ADMIN_ACCESS_TOKEN", () => [
112
+ 401,
113
+ "Admin access token not valid for this project.",
114
+ ], () => []);
115
+ const ProjectAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationError, "PROJECT_AUTHENTICATION_REQUIRED", "inherit", "inherit");
116
+ const ClientAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "CLIENT_AUTHENTICATION_REQUIRED", () => [
117
+ 401,
118
+ "The publishable client key must be provided.",
119
+ ], () => []);
120
+ const ServerAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "SERVER_AUTHENTICATION_REQUIRED", () => [
121
+ 401,
122
+ "The secret server key must be provided.",
123
+ ], () => []);
124
+ const ClientOrServerAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "CLIENT_OR_SERVER_AUTHENTICATION_REQUIRED", () => [
125
+ 401,
126
+ "Either the publishable client key or the secret server key must be provided.",
127
+ ], () => []);
128
+ const ClientOrAdminAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "CLIENT_OR_ADMIN_AUTHENTICATION_REQUIRED", () => [
129
+ 401,
130
+ "Either the publishable client key or the super secret admin key must be provided.",
131
+ ], () => []);
132
+ const ClientOrServerOrAdminAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "CLIENT_OR_SERVER_OR_ADMIN_AUTHENTICATION_REQUIRED", () => [
133
+ 401,
134
+ "Either the publishable client key, the secret server key, or the super secret admin key must be provided.",
135
+ ], () => []);
136
+ const AdminAuthenticationRequired = createKnownErrorConstructor(ProjectAuthenticationRequired, "ADMIN_AUTHENTICATION_REQUIRED", () => [
137
+ 401,
138
+ "The super secret admin key must be provided.",
139
+ ], () => []);
140
+ const ExpectedInternalProject = createKnownErrorConstructor(ProjectAuthenticationError, "EXPECTED_INTERNAL_PROJECT", () => [
141
+ 401,
142
+ "The project ID is expected to be internal.",
143
+ ], () => []);
144
+ const SessionAuthenticationError = createKnownErrorConstructor(KnownError, "SESSION_AUTHENTICATION_ERROR", "inherit", "inherit");
145
+ const InvalidSessionAuthentication = createKnownErrorConstructor(SessionAuthenticationError, "INVALID_SESSION_AUTHENTICATION", "inherit", "inherit");
146
+ const InvalidAccessToken = createKnownErrorConstructor(InvalidSessionAuthentication, "INVALID_ACCESS_TOKEN", "inherit", "inherit");
147
+ const UnparsableAccessToken = createKnownErrorConstructor(InvalidAccessToken, "UNPARSABLE_ACCESS_TOKEN", () => [
148
+ 401,
149
+ "Access token is not parsable.",
150
+ ], () => []);
151
+ const AccessTokenExpired = createKnownErrorConstructor(InvalidAccessToken, "ACCESS_TOKEN_EXPIRED", () => [
152
+ 401,
153
+ "Access token has expired. Please refresh it and try again.",
154
+ ], () => []);
155
+ const InvalidProjectForAccessToken = createKnownErrorConstructor(InvalidAccessToken, "INVALID_PROJECT_FOR_ACCESS_TOKEN", () => [
156
+ 401,
157
+ "Access token not valid for this project.",
158
+ ], () => []);
159
+ const SessionUserEmailNotVerified = createKnownErrorConstructor(InvalidSessionAuthentication, "SESSION_USER_EMAIL_NOT_VERIFIED", () => [
160
+ 401,
161
+ "User e-mail not verified, but is required by the project.",
162
+ ], () => []);
163
+ const SessionAuthenticationRequired = createKnownErrorConstructor(SessionAuthenticationError, "SESSION_AUTHENTICATION_REQUIRED", () => [
164
+ 401,
165
+ "Session required for this request.",
166
+ ], () => []);
167
+ const RefreshTokenError = createKnownErrorConstructor(KnownError, "INVALID_REFRESH_TOKEN", "inherit", "inherit");
168
+ const ProviderRejected = createKnownErrorConstructor(RefreshTokenError, "PROVIDER_REJECTED", () => [
169
+ 401,
170
+ "The provider refused to refresh their token.",
171
+ ], () => []);
172
+ const InvalidRefreshToken = createKnownErrorConstructor(RefreshTokenError, "REFRESH_TOKEN_EXPIRED", () => [
173
+ 401,
174
+ "Refresh token has expired. A new refresh token requires reauthentication.",
175
+ ], () => []);
176
+ const UserEmailAlreadyExists = createKnownErrorConstructor(KnownError, "USER_EMAIL_ALREADY_EXISTS", () => [
177
+ 400,
178
+ "User already exists.",
179
+ ], () => []);
180
+ const UserNotFound = createKnownErrorConstructor(KnownError, "USER_NOT_FOUND", () => [
181
+ 404,
182
+ "User not found.",
183
+ ], () => []);
184
+ const ApiKeyNotFound = createKnownErrorConstructor(KnownError, "API_KEY_NOT_FOUND", () => [
185
+ 404,
186
+ "API key not found.",
187
+ ], () => []);
188
+ const ProjectNotFound = createKnownErrorConstructor(KnownError, "PROJECT_NOT_FOUND", () => [
189
+ 404,
190
+ "Project not found or is not accessible with the current user.",
191
+ ], () => []);
192
+ const EmailPasswordMismatch = createKnownErrorConstructor(KnownError, "EMAIL_PASSWORD_MISMATCH", () => [
193
+ 400,
194
+ "Wrong e-mail or password.",
195
+ ], () => []);
196
+ const RedirectUrlNotWhitelisted = createKnownErrorConstructor(KnownError, "REDIRECT_URL_NOT_WHITELISTED", () => [
197
+ 400,
198
+ "Redirect URL not whitelisted.",
199
+ ], () => []);
200
+ const PasswordRequirementsNotMet = createKnownErrorConstructor(KnownError, "PASSWORD_REQUIREMENTS_NOT_MET", "inherit", "inherit");
201
+ const PasswordTooShort = createKnownErrorConstructor(PasswordRequirementsNotMet, "PASSWORD_TOO_SHORT", (minLength) => [
202
+ 400,
203
+ `Password too short. Minimum length is ${minLength}.`,
204
+ {
205
+ minLength,
206
+ },
207
+ ], (json) => [
208
+ json.details?.minLength ?? throwErr("minLength not found in PasswordTooShort details"),
209
+ ]);
210
+ const PasswordTooLong = createKnownErrorConstructor(PasswordRequirementsNotMet, "PASSWORD_TOO_LONG", (maxLength) => [
211
+ 400,
212
+ `Password too long. Maximum length is ${maxLength}.`,
213
+ {
214
+ maxLength,
215
+ },
216
+ ], (json) => [
217
+ json.details?.maxLength ?? throwErr("maxLength not found in PasswordTooLong details"),
218
+ ]);
219
+ const EmailVerificationError = createKnownErrorConstructor(KnownError, "EMAIL_VERIFICATION_ERROR", "inherit", "inherit");
220
+ const EmailVerificationCodeError = createKnownErrorConstructor(EmailVerificationError, "EMAIL_VERIFICATION_CODE_ERROR", "inherit", "inherit");
221
+ const EmailVerificationCodeNotFound = createKnownErrorConstructor(EmailVerificationCodeError, "EMAIL_VERIFICATION_CODE_NOT_FOUND", () => [
222
+ 404,
223
+ "The e-mail verification code does not exist for this project.",
224
+ ], () => []);
225
+ const EmailVerificationCodeExpired = createKnownErrorConstructor(EmailVerificationCodeError, "EMAIL_VERIFICATION_CODE_EXPIRED", () => [
226
+ 400,
227
+ "The e-mail verification code has expired.",
228
+ ], () => []);
229
+ const EmailVerificationCodeAlreadyUsed = createKnownErrorConstructor(EmailVerificationCodeError, "EMAIL_VERIFICATION_CODE_ALREADY_USED", () => [
230
+ 400,
231
+ "The e-mail verification link has already been used.",
232
+ ], () => []);
233
+ const PasswordMismatch = createKnownErrorConstructor(KnownError, "PASSWORD_MISMATCH", () => [
234
+ 400,
235
+ "Passwords do not match.",
236
+ ], () => []);
237
+ const PasswordResetError = createKnownErrorConstructor(KnownError, "PASSWORD_RESET_ERROR", "inherit", "inherit");
238
+ const PasswordResetCodeError = createKnownErrorConstructor(PasswordResetError, "PASSWORD_RESET_CODE_ERROR", "inherit", "inherit");
239
+ const PasswordResetCodeNotFound = createKnownErrorConstructor(PasswordResetCodeError, "PASSWORD_RESET_CODE_NOT_FOUND", () => [
240
+ 404,
241
+ "The password reset code does not exist for this project.",
242
+ ], () => []);
243
+ const PasswordResetCodeExpired = createKnownErrorConstructor(PasswordResetCodeError, "PASSWORD_RESET_CODE_EXPIRED", () => [
244
+ 400,
245
+ "The password reset code has expired.",
246
+ ], () => []);
247
+ const PasswordResetCodeAlreadyUsed = createKnownErrorConstructor(PasswordResetCodeError, "PASSWORD_RESET_CODE_ALREADY_USED", () => [
248
+ 400,
249
+ "The password reset code has already been used.",
250
+ ], () => []);
251
+ const EmailAlreadyVerified = createKnownErrorConstructor(KnownError, "EMAIL_ALREADY_VERIFIED", () => [
252
+ 400,
253
+ "The e-mail is already verified.",
254
+ ], () => []);
255
+ export const KnownErrors = {
256
+ UnsupportedError,
257
+ SchemaError,
258
+ AllOverloadsFailed,
259
+ ProjectAuthenticationError,
260
+ InvalidProjectAuthentication,
261
+ InvalidPublishableClientKey,
262
+ InvalidSecretServerKey,
263
+ InvalidSuperSecretAdminKey,
264
+ InvalidAdminAccessToken,
265
+ UnparsableAdminAccessToken,
266
+ AdminAccessTokenExpired,
267
+ InvalidProjectForAdminAccessToken,
268
+ ProjectAuthenticationRequired,
269
+ ClientAuthenticationRequired,
270
+ ServerAuthenticationRequired,
271
+ ClientOrServerAuthenticationRequired,
272
+ ClientOrAdminAuthenticationRequired,
273
+ ClientOrServerOrAdminAuthenticationRequired,
274
+ AdminAuthenticationRequired,
275
+ ExpectedInternalProject,
276
+ SessionAuthenticationError,
277
+ InvalidSessionAuthentication,
278
+ InvalidAccessToken,
279
+ UnparsableAccessToken,
280
+ AccessTokenExpired,
281
+ InvalidProjectForAccessToken,
282
+ SessionUserEmailNotVerified,
283
+ SessionAuthenticationRequired,
284
+ RefreshTokenError,
285
+ ProviderRejected,
286
+ InvalidRefreshToken,
287
+ UserEmailAlreadyExists,
288
+ UserNotFound,
289
+ ApiKeyNotFound,
290
+ ProjectNotFound,
291
+ EmailPasswordMismatch,
292
+ RedirectUrlNotWhitelisted,
293
+ PasswordRequirementsNotMet,
294
+ PasswordTooShort,
295
+ PasswordTooLong,
296
+ EmailVerificationError,
297
+ EmailVerificationCodeError,
298
+ EmailVerificationCodeNotFound,
299
+ EmailVerificationCodeExpired,
300
+ EmailVerificationCodeAlreadyUsed,
301
+ PasswordResetError,
302
+ PasswordResetCodeError,
303
+ PasswordResetCodeNotFound,
304
+ PasswordResetCodeExpired,
305
+ PasswordResetCodeAlreadyUsed,
306
+ PasswordMismatch,
307
+ EmailAlreadyVerified,
308
+ };
309
+ // ensure that all known error codes are unique
310
+ const knownErrorCodes = new Set();
311
+ for (const [_, KnownError] of Object.entries(KnownErrors)) {
312
+ if (knownErrorCodes.has(KnownError.errorCode)) {
313
+ throw new Error(`Duplicate known error code: ${KnownError.errorCode}`);
314
+ }
315
+ knownErrorCodes.add(KnownError.errorCode);
316
+ }
@@ -1,7 +1,7 @@
1
1
  export declare function typedIncludes<T extends readonly any[]>(arr: T, item: unknown): item is T[number];
2
2
  export declare function enumerate<T extends readonly any[]>(arr: T): [number, T[number]][];
3
3
  export declare function isShallowEqual(a: readonly any[], b: readonly any[]): boolean;
4
- export declare function groupBy<T extends readonly any[], K>(arr: T, key: (item: T[number]) => K): Map<K, T[number][]>;
4
+ export declare function groupBy<T extends any, K>(arr: Iterable<T>, key: (item: T) => K): Map<K, T[]>;
5
5
  export declare function range(endExclusive: number): number[];
6
6
  export declare function range(startInclusive: number, endExclusive: number): number[];
7
7
  export declare function range(startInclusive: number, endExclusive: number, step: number): number[];
@@ -1 +1 @@
1
- {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../../src/utils/arrays.tsx"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,CAEhG;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAEjF;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,SAAS,GAAG,EAAE,GAAG,OAAO,CAM5E;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,EAAE,CAAC,EACjD,GAAG,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAC1B,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAQrB;AAGD,wBAAgB,KAAK,CAAC,YAAY,EAAE,MAAM,GA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Qb;AAGD,wBAAgB,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AACtD,wBAAgB,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAC9E,wBAAgB,KAAK,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAgB5F,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,CAGhE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,GAAG,EAAE,CAEjE;AAGD,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAOjD"}
@@ -33,6 +33,7 @@ export declare class AsyncCache<D extends any[], T> {
33
33
  status: "ok";
34
34
  });
35
35
  readonly getOrWait: (key: D, cacheStrategy: CacheStrategy) => ReactPromise<T>;
36
+ readonly forceSetCachedValue: (key: D, value: T) => void;
36
37
  readonly refresh: (key: D) => Promise<T>;
37
38
  readonly invalidate: (key: D) => Promise<T>;
38
39
  readonly onChange: (key: D, callback: (value: T, oldValue: T | undefined) => void) => {
@@ -42,6 +43,7 @@ export declare class AsyncCache<D extends any[], T> {
42
43
  declare class AsyncValueCache<T> {
43
44
  private readonly _options;
44
45
  private _store;
46
+ private _pendingPromise;
45
47
  private _fetcher;
46
48
  private readonly _rateLimitOptions;
47
49
  private _subscriptionsCount;
@@ -72,6 +74,7 @@ declare class AsyncValueCache<T> {
72
74
  private _set;
73
75
  private _setAsync;
74
76
  private _refetch;
77
+ forceSetCachedValue(value: T): void;
75
78
  refresh(): Promise<T>;
76
79
  invalidate(): Promise<T>;
77
80
  onChange(callback: (value: T, oldValue: T | undefined) => void): {
@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