@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.
- package/dist/helpers/fetch-token.d.ts +1 -0
- package/dist/helpers/password.d.ts +2 -1
- package/dist/helpers/password.d.ts.map +1 -1
- package/dist/helpers/password.js +8 -29
- package/dist/hooks/use-async-callback.d.ts +3 -0
- package/dist/hooks/use-async-callback.d.ts.map +1 -0
- package/dist/hooks/use-async-callback.js +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/interface/clientInterface.d.ts +21 -24
- package/dist/interface/clientInterface.d.ts.map +1 -1
- package/dist/interface/clientInterface.js +109 -67
- package/dist/interface/serverInterface.d.ts.map +1 -1
- package/dist/known-errors.d.ts +202 -0
- package/dist/known-errors.d.ts.map +1 -0
- package/dist/known-errors.js +316 -0
- package/dist/utils/arrays.d.ts +1 -1
- package/dist/utils/arrays.d.ts.map +1 -1
- package/dist/utils/caches.d.ts +3 -0
- package/dist/utils/caches.d.ts.map +1 -1
- package/dist/utils/caches.js +18 -14
- package/dist/utils/crypto.d.ts +4 -0
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +10 -6
- package/dist/utils/errors.d.ts +13 -7
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +44 -3
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/dist/utils/functions.js +6 -0
- package/dist/utils/objects.d.ts +5 -0
- package/dist/utils/objects.d.ts.map +1 -1
- package/dist/utils/objects.js +6 -0
- package/dist/utils/promises.d.ts +3 -1
- package/dist/utils/promises.d.ts.map +1 -1
- package/dist/utils/promises.js +24 -4
- package/dist/utils/stores.d.ts +2 -2
- package/dist/utils/stores.d.ts.map +1 -1
- package/dist/utils/stores.js +32 -19
- package/dist/utils/types.d.ts +5 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js +4 -1
- package/package.json +4 -15
package/dist/utils/caches.js
CHANGED
|
@@ -45,6 +45,7 @@ export class AsyncCache {
|
|
|
45
45
|
isCacheAvailable = this._createKeyed("isCacheAvailable");
|
|
46
46
|
getIfCached = this._createKeyed("getIfCached");
|
|
47
47
|
getOrWait = this._createKeyed("getOrWait");
|
|
48
|
+
forceSetCachedValue = this._createKeyed("forceSetCachedValue");
|
|
48
49
|
refresh = this._createKeyed("refresh");
|
|
49
50
|
invalidate = this._createKeyed("invalidate");
|
|
50
51
|
onChange = this._createKeyed("onChange");
|
|
@@ -52,6 +53,7 @@ export class AsyncCache {
|
|
|
52
53
|
class AsyncValueCache {
|
|
53
54
|
_options;
|
|
54
55
|
_store;
|
|
56
|
+
_pendingPromise;
|
|
55
57
|
_fetcher;
|
|
56
58
|
_rateLimitOptions;
|
|
57
59
|
_subscriptionsCount = 0;
|
|
@@ -61,7 +63,7 @@ class AsyncValueCache {
|
|
|
61
63
|
this._store = new AsyncStore();
|
|
62
64
|
this._rateLimitOptions = {
|
|
63
65
|
concurrency: 1,
|
|
64
|
-
|
|
66
|
+
throttleMs: 300,
|
|
65
67
|
...filterUndefined(_options.rateLimiter ?? {}),
|
|
66
68
|
};
|
|
67
69
|
this._fetcher = rateLimited(fetcher, {
|
|
@@ -80,32 +82,34 @@ class AsyncValueCache {
|
|
|
80
82
|
if (cacheStrategy === "read-write" && cached.status === "ok") {
|
|
81
83
|
return resolved(cached.data);
|
|
82
84
|
}
|
|
83
|
-
return
|
|
85
|
+
return this._refetch(cacheStrategy);
|
|
84
86
|
}
|
|
85
87
|
_set(value) {
|
|
86
88
|
this._store.set(value);
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
+
_setAsync(value) {
|
|
91
|
+
return pending(this._store.setAsync(value));
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (cacheStrategy === "write-only") {
|
|
95
|
-
await this._setAsync(res);
|
|
96
|
-
}
|
|
97
|
-
return await res;
|
|
93
|
+
_refetch(cacheStrategy) {
|
|
94
|
+
if (cacheStrategy === "read-write" && this._pendingPromise) {
|
|
95
|
+
return this._pendingPromise;
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
const promise = pending(this._fetcher());
|
|
98
|
+
if (cacheStrategy === "never") {
|
|
99
|
+
return promise;
|
|
102
100
|
}
|
|
101
|
+
this._pendingPromise = promise;
|
|
102
|
+
return pending(this._setAsync(promise).then(() => promise));
|
|
103
|
+
}
|
|
104
|
+
forceSetCachedValue(value) {
|
|
105
|
+
this._set(value);
|
|
103
106
|
}
|
|
104
107
|
async refresh() {
|
|
105
108
|
return await this.getOrWait("write-only");
|
|
106
109
|
}
|
|
107
110
|
async invalidate() {
|
|
108
111
|
this._store.setUnavailable();
|
|
112
|
+
this._pendingPromise = undefined;
|
|
109
113
|
return await this.refresh();
|
|
110
114
|
}
|
|
111
115
|
onChange(callback) {
|
package/dist/utils/crypto.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/utils/crypto.tsx"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,GAAE,MAAY,UAMxE"}
|
package/dist/utils/crypto.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import crypto from "
|
|
1
|
+
import crypto from "crypto";
|
|
2
2
|
import { encodeBase32 } from "./bytes";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Generates a secure alphanumeric string using the system's cryptographically secure
|
|
5
|
+
* random number generator.
|
|
6
|
+
*/
|
|
6
7
|
export function generateSecureRandomString(minBitsOfEntropy = 224) {
|
|
7
|
-
const
|
|
8
|
-
|
|
8
|
+
const base32CharactersCount = Math.ceil(minBitsOfEntropy / 5);
|
|
9
|
+
const bytesCount = Math.ceil(base32CharactersCount * 5 / 8);
|
|
10
|
+
const randomBytes = crypto.randomBytes(bytesCount);
|
|
11
|
+
const str = encodeBase32(randomBytes);
|
|
12
|
+
return str.slice(str.length - base32CharactersCount).toLowerCase();
|
|
9
13
|
}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { Json } from "./json";
|
|
1
2
|
export declare function throwErr(errorMessage: string): never;
|
|
2
3
|
export declare function throwErr(error: Error): never;
|
|
3
4
|
export declare function throwErr(...args: StatusErrorConstructorParameters): never;
|
|
5
|
+
export declare class StackAssertionError extends Error {
|
|
6
|
+
readonly extraData?: Record<string, any> | undefined;
|
|
7
|
+
constructor(message: string, extraData?: Record<string, any> | undefined, options?: ErrorOptions);
|
|
8
|
+
}
|
|
9
|
+
export declare function throwStackErr(message: string, extraData?: any): never;
|
|
10
|
+
export declare function registerErrorSink(sink: (location: string, error: unknown) => void): void;
|
|
11
|
+
export declare function captureError(location: string, error: unknown): void;
|
|
4
12
|
type Status = {
|
|
5
13
|
statusCode: number;
|
|
6
14
|
message: string;
|
|
7
15
|
};
|
|
8
16
|
type StatusErrorConstructorParameters = [
|
|
9
17
|
statusCode: number | Status,
|
|
10
|
-
message?: string
|
|
11
|
-
options?: {
|
|
12
|
-
headers: Record<string, string>;
|
|
13
|
-
}
|
|
18
|
+
message?: string
|
|
14
19
|
];
|
|
15
20
|
export declare class StatusError extends Error {
|
|
16
|
-
readonly options?: {
|
|
17
|
-
headers: Record<string, string>;
|
|
18
|
-
} | undefined;
|
|
19
21
|
readonly statusCode: number;
|
|
20
22
|
static BadRequest: {
|
|
21
23
|
statusCode: number;
|
|
@@ -180,5 +182,9 @@ export declare class StatusError extends Error {
|
|
|
180
182
|
constructor(...args: StatusErrorConstructorParameters);
|
|
181
183
|
isClientError(): boolean;
|
|
182
184
|
isServerError(): boolean;
|
|
185
|
+
getStatusCode(): number;
|
|
186
|
+
getBody(): Uint8Array;
|
|
187
|
+
getHeaders(): Record<string, string[]>;
|
|
188
|
+
toHttpJson(): Json;
|
|
183
189
|
}
|
|
184
190
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.tsx"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAAC;AACtD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;AAC9C,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,gCAAgC,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,wBAAgB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAAC;AACtD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC;AAC9C,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,gCAAgC,GAAG,KAAK,CAAC;AAa3E,qBAAa,mBAAoB,SAAQ,KAAK;aACC,SAAS,CAAC;gBAA3C,OAAO,EAAE,MAAM,EAAkB,SAAS,CAAC,iCAAqB,EAAE,OAAO,CAAC,EAAE,YAAY;CAGrG;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,KAAK,CAErE;AAID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAOxF;AAGD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAA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ACvE,OAAc,kBAAkB;;;MAAuD;IACvF,OAAc,cAAc;;;MAAmD;IAC/E,OAAc,uBAAuB;;;MAA8D;IACnG,OAAc,qBAAqB;;;MAA2D;IAC9F,OAAc,mBAAmB;;;MAAwD;IACzF,OAAc,YAAY;;;MAAiD;IAC3E,OAAc,WAAW;;;MAAgD;IACzE,OAAc,6BAA6B;;;MAAmE;gBAGlG,GAAG,IAAI,EAAE,gCAAgC;IAc9C,aAAa;IAIb,aAAa;IAIb,aAAa,IAAI,MAAM;IAIvB,OAAO,IAAI,UAAU;IAIrB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAMtC,UAAU,IAAI,IAAI;CAO1B"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -10,8 +10,32 @@ export function throwErr(...args) {
|
|
|
10
10
|
throw new StatusError(...args);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
export class StackAssertionError extends Error {
|
|
14
|
+
extraData;
|
|
15
|
+
constructor(message, extraData, options) {
|
|
16
|
+
super(`${message}\n\nThis is likely an error in Stack. Please report it.`, options);
|
|
17
|
+
this.extraData = extraData;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function throwStackErr(message, extraData) {
|
|
21
|
+
throw new StackAssertionError(message, extraData);
|
|
22
|
+
}
|
|
23
|
+
const errorSinks = new Set();
|
|
24
|
+
export function registerErrorSink(sink) {
|
|
25
|
+
if (errorSinks.has(sink)) {
|
|
26
|
+
console.log("Error sink already registered", sink);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
console.log("Registering error sink", sink);
|
|
30
|
+
errorSinks.add(sink);
|
|
31
|
+
}
|
|
32
|
+
registerErrorSink((location, ...args) => console.error(`Error in ${location}:`, ...args));
|
|
33
|
+
export function captureError(location, error) {
|
|
34
|
+
for (const sink of errorSinks) {
|
|
35
|
+
sink(location, error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
13
38
|
export class StatusError extends Error {
|
|
14
|
-
options;
|
|
15
39
|
statusCode;
|
|
16
40
|
static BadRequest = { statusCode: 400, message: "Bad Request" };
|
|
17
41
|
static Unauthorized = { statusCode: 401, message: "Unauthorized" };
|
|
@@ -53,14 +77,13 @@ export class StatusError extends Error {
|
|
|
53
77
|
static LoopDetected = { statusCode: 508, message: "Loop Detected" };
|
|
54
78
|
static NotExtended = { statusCode: 510, message: "Not Extended" };
|
|
55
79
|
static NetworkAuthenticationRequired = { statusCode: 511, message: "Network Authentication Required" };
|
|
56
|
-
constructor(status, message
|
|
80
|
+
constructor(status, message) {
|
|
57
81
|
if (typeof status === "object") {
|
|
58
82
|
message ??= status.message;
|
|
59
83
|
status = status.statusCode;
|
|
60
84
|
}
|
|
61
85
|
message ??= "Server Error";
|
|
62
86
|
super(message);
|
|
63
|
-
this.options = options;
|
|
64
87
|
this.statusCode = status;
|
|
65
88
|
}
|
|
66
89
|
isClientError() {
|
|
@@ -69,4 +92,22 @@ export class StatusError extends Error {
|
|
|
69
92
|
isServerError() {
|
|
70
93
|
return !this.isClientError();
|
|
71
94
|
}
|
|
95
|
+
getStatusCode() {
|
|
96
|
+
return this.statusCode;
|
|
97
|
+
}
|
|
98
|
+
getBody() {
|
|
99
|
+
return new TextEncoder().encode(this.message);
|
|
100
|
+
}
|
|
101
|
+
getHeaders() {
|
|
102
|
+
return {
|
|
103
|
+
"Content-Type": ["text/plain; charset=utf-8"],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
toHttpJson() {
|
|
107
|
+
return {
|
|
108
|
+
statusCode: this.statusCode,
|
|
109
|
+
body: this.message,
|
|
110
|
+
headers: this.getHeaders(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
72
113
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/utils/functions.tsx"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAEnC;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,CAE3D"}
|
package/dist/utils/objects.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type DeepPartial<T> = T extends object ? {
|
|
2
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
3
|
+
} : T;
|
|
1
4
|
/**
|
|
2
5
|
* Assumes both objects are primitives, arrays, or non-function plain objects, and compares them deeply.
|
|
3
6
|
*
|
|
@@ -16,3 +19,5 @@ export declare function typedAssign<T extends {}, U extends {}>(target: T, sourc
|
|
|
16
19
|
export declare function filterUndefined<T extends {}>(obj: T): {
|
|
17
20
|
[k in keyof T]+?: T[k] & ({} | null);
|
|
18
21
|
};
|
|
22
|
+
export declare function pick<T extends {}, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
23
|
+
export declare function omit<T extends {}, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../src/utils/objects.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,CAAC,CAgCpE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAE1E;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAE3F;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG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CAAC,CAAC,CAAC,CAE3F;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAE3D;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAE9D;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAErG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC;CAAE,CAE9F;AAGD,wBAAgB,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAEnF;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAEnF"}
|
package/dist/utils/objects.js
CHANGED
|
@@ -61,3 +61,9 @@ export function typedAssign(target, source) {
|
|
|
61
61
|
export function filterUndefined(obj) {
|
|
62
62
|
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
|
|
63
63
|
}
|
|
64
|
+
export function pick(obj, keys) {
|
|
65
|
+
return Object.fromEntries(Object.entries(obj).filter(([k]) => keys.includes(k)));
|
|
66
|
+
}
|
|
67
|
+
export function omit(obj, keys) {
|
|
68
|
+
return Object.fromEntries(Object.entries(obj).filter(([k]) => !keys.includes(k)));
|
|
69
|
+
}
|
package/dist/utils/promises.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ export declare function neverResolve(): ReactPromise<never>;
|
|
|
16
16
|
export declare function pending<T>(promise: Promise<T>): ReactPromise<T>;
|
|
17
17
|
export declare function wait(ms: number): Promise<void>;
|
|
18
18
|
export declare function waitUntil(date: Date): Promise<void>;
|
|
19
|
-
export declare function runAsynchronously(promiseOrFunc: Promise<unknown> | (() => Promise<unknown>) | undefined
|
|
19
|
+
export declare function runAsynchronously(promiseOrFunc: void | Promise<unknown> | (() => void | Promise<unknown>) | undefined, options?: {
|
|
20
|
+
ignoreErrors?: boolean;
|
|
21
|
+
}): void;
|
|
20
22
|
declare class TimeoutError extends Error {
|
|
21
23
|
readonly ms: number;
|
|
22
24
|
constructor(ms: number);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/utils/promises.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/utils/promises.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAElF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CACvC,gBAAgB,CAAC,CAAC,CAAC,GACnB,iBAAiB,CAAC,CAAC,CAAC,GACpB,eAAe,CAAC,CAAC,CAAC,CACrB,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACrC,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAA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,OAAO,CAAC,CAAC,CAAC,CAEjF;AAGD,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,WAAW,EAAE,CAAC,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,gBAAgB,GACxB,MAAM,OAAO,CAAC,CAAC,CAAC,CAoDlB;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAe3H"}
|
package/dist/utils/promises.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StackAssertionError, captureError } from "./errors";
|
|
1
2
|
import { Result } from "./results";
|
|
2
3
|
import { generateUuid } from "./uuids";
|
|
3
4
|
export function createPromise(callback) {
|
|
@@ -50,9 +51,17 @@ export function neverResolve() {
|
|
|
50
51
|
return pending(new Promise(() => { }));
|
|
51
52
|
}
|
|
52
53
|
export function pending(promise) {
|
|
53
|
-
|
|
54
|
+
const res = Object.assign(promise, {
|
|
54
55
|
status: "pending",
|
|
55
56
|
});
|
|
57
|
+
res.then(value => {
|
|
58
|
+
res.status = "fulfilled";
|
|
59
|
+
res.value = value;
|
|
60
|
+
}, reason => {
|
|
61
|
+
res.status = "rejected";
|
|
62
|
+
res.reason = reason;
|
|
63
|
+
});
|
|
64
|
+
return res;
|
|
56
65
|
}
|
|
57
66
|
export async function wait(ms) {
|
|
58
67
|
return await new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -60,15 +69,26 @@ export async function wait(ms) {
|
|
|
60
69
|
export async function waitUntil(date) {
|
|
61
70
|
return await wait(date.getTime() - Date.now());
|
|
62
71
|
}
|
|
63
|
-
|
|
72
|
+
class ErrorDuringRunAsynchronously extends Error {
|
|
73
|
+
constructor() {
|
|
74
|
+
super("The error above originated in a runAsynchronously() call. Here is the stacktrace associated with it.");
|
|
75
|
+
this.name = "ErrorDuringRunAsynchronously";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function runAsynchronously(promiseOrFunc, options = {}) {
|
|
64
79
|
if (typeof promiseOrFunc === "function") {
|
|
65
80
|
promiseOrFunc = promiseOrFunc();
|
|
66
81
|
}
|
|
82
|
+
const duringError = new ErrorDuringRunAsynchronously();
|
|
67
83
|
promiseOrFunc?.catch(error => {
|
|
68
|
-
const newError = new
|
|
84
|
+
const newError = new StackAssertionError("Uncaught error in asynchronous function: " + error.toString(), {
|
|
85
|
+
duringError,
|
|
86
|
+
}, {
|
|
69
87
|
cause: error,
|
|
70
88
|
});
|
|
71
|
-
|
|
89
|
+
if (!options.ignoreErrors) {
|
|
90
|
+
captureError("runAsynchronously", newError);
|
|
91
|
+
}
|
|
72
92
|
});
|
|
73
93
|
}
|
|
74
94
|
class TimeoutError extends Error {
|
package/dist/utils/stores.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncResult } from "./results";
|
|
1
|
+
import { AsyncResult, Result } from "./results";
|
|
2
2
|
import { ReactPromise } from "./promises";
|
|
3
3
|
export type ReadonlyAsyncStore<T> = {
|
|
4
4
|
isAvailable(): boolean;
|
|
@@ -41,7 +41,7 @@ export declare class AsyncStore<T> implements ReadonlyAsyncStore<T> {
|
|
|
41
41
|
status: "ok";
|
|
42
42
|
});
|
|
43
43
|
getOrWait(): ReactPromise<T>;
|
|
44
|
-
_setIfLatest(
|
|
44
|
+
_setIfLatest(result: Result<T>, curCounter: number): boolean;
|
|
45
45
|
set(value: T): void;
|
|
46
46
|
update(updater: (value: T | undefined) => T): T;
|
|
47
47
|
setAsync(promise: Promise<T>): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../../src/utils/stores.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../../src/utils/stores.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EAAE,YAAY,EAA+B,MAAM,YAAY,CAAC;AAEvE,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IAClC,WAAW,IAAI,OAAO,CAAC;IACvB,GAAG,IAAI,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACrC,SAAS,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;IAC7F,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CAChG,CAAC;AAEF,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,kBAAkB,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,MAAM,CAA4B;IAE1C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CA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yncResult, Result } from "./results";
|
|
2
2
|
import { generateUuid } from "./uuids";
|
|
3
3
|
import { pending, rejected, resolved } from "./promises";
|
|
4
4
|
export class AsyncStore {
|
|
@@ -55,23 +55,37 @@ export class AsyncStore {
|
|
|
55
55
|
});
|
|
56
56
|
return pending(withFinally);
|
|
57
57
|
}
|
|
58
|
-
_setIfLatest(
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
_setIfLatest(result, curCounter) {
|
|
59
|
+
if (curCounter > this._lastSuccessfulUpdate) {
|
|
60
|
+
switch (result.status) {
|
|
61
|
+
case "ok": {
|
|
62
|
+
if (!this._isAvailable || this._isRejected || this._value !== result.data) {
|
|
63
|
+
const oldValue = this._value;
|
|
64
|
+
this._lastSuccessfulUpdate = curCounter;
|
|
65
|
+
this._isAvailable = true;
|
|
66
|
+
this._isRejected = false;
|
|
67
|
+
this._value = result.data;
|
|
68
|
+
this._rejectionError = undefined;
|
|
69
|
+
this._callbacks.forEach((callback) => callback(result.data, oldValue));
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
case "error": {
|
|
75
|
+
this._lastSuccessfulUpdate = curCounter;
|
|
76
|
+
this._isAvailable = false;
|
|
77
|
+
this._isRejected = true;
|
|
78
|
+
this._value = undefined;
|
|
79
|
+
this._rejectionError = result.error;
|
|
80
|
+
this._waitingRejectFunctions.forEach((reject) => reject(result.error));
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
68
83
|
}
|
|
69
|
-
return false;
|
|
70
84
|
}
|
|
71
85
|
return false;
|
|
72
86
|
}
|
|
73
87
|
set(value) {
|
|
74
|
-
this._setIfLatest(value, ++this._updateCounter);
|
|
88
|
+
this._setIfLatest(Result.ok(value), ++this._updateCounter);
|
|
75
89
|
}
|
|
76
90
|
update(updater) {
|
|
77
91
|
const value = updater(this._value);
|
|
@@ -80,19 +94,18 @@ export class AsyncStore {
|
|
|
80
94
|
}
|
|
81
95
|
async setAsync(promise) {
|
|
82
96
|
const curCounter = ++this._updateCounter;
|
|
83
|
-
const
|
|
84
|
-
return this._setIfLatest(
|
|
97
|
+
const result = await Result.fromPromise(promise);
|
|
98
|
+
return this._setIfLatest(result, curCounter);
|
|
85
99
|
}
|
|
86
100
|
setUnavailable() {
|
|
101
|
+
this._lastSuccessfulUpdate = ++this._updateCounter;
|
|
87
102
|
this._isAvailable = false;
|
|
88
103
|
this._isRejected = false;
|
|
89
104
|
this._value = undefined;
|
|
105
|
+
this._rejectionError = undefined;
|
|
90
106
|
}
|
|
91
107
|
setRejected(error) {
|
|
92
|
-
this.
|
|
93
|
-
this._value = undefined;
|
|
94
|
-
this._rejectionError = error;
|
|
95
|
-
this._waitingRejectFunctions.forEach((reject) => reject(error));
|
|
108
|
+
this._setIfLatest(Result.error(error), ++this._updateCounter);
|
|
96
109
|
}
|
|
97
110
|
map(mapper) {
|
|
98
111
|
const store = new AsyncStore();
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export declare const EmailVerificationLinkUsedErrorCode = "EMAIL_VERIFICATION_LI
|
|
|
14
14
|
export declare const PasswordResetLinkInvalidErrorCode = "PASSWORD_RESET_LINK_INVALID";
|
|
15
15
|
export declare const PasswordResetLinkExpiredErrorCode = "PASSWORD_RESET_LINK_EXPIRED";
|
|
16
16
|
export declare const PasswordResetLinkUsedErrorCode = "PASSWORD_RESET_LINK_USED";
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const WrongPasswordErrorCode = "WRONG_PASSWORD";
|
|
18
|
+
export declare const KnownErrorCodes: readonly ["ACCESS_TOKEN_EXPIRED", "GRANT_INVALID", "USER_ALREADY_EXIST", "USER_NOT_EXIST", "USER_NOT_VERIFIED", "EMAIL_PASSWORD_MISS_MATCH", "REDIRECT_URL_INVALID", "PASSWORD_FORMAT_INVALID", "PROJECT_ID_OR_KEY_INVALID", "EMAIL_VERIFICATION_LINK_INVALID", "EMAIL_VERIFICATION_LINK_EXPIRED", "EMAIL_VERIFICATION_LINK_USED", "PASSWORD_RESET_LINK_INVALID", "PASSWORD_RESET_LINK_EXPIRED", "PASSWORD_RESET_LINK_USED", "WRONG_PASSWORD"];
|
|
18
19
|
export type KnownErrorCode = typeof KnownErrorCodes[number];
|
|
19
20
|
export declare const SignUpErrorCodes: readonly ["USER_ALREADY_EXIST"];
|
|
20
21
|
export type SignUpErrorCode = typeof SignUpErrorCodes[number];
|
|
@@ -24,7 +25,10 @@ export declare const EmailVerificationLinkErrorCodes: readonly ["EMAIL_VERIFICAT
|
|
|
24
25
|
export type EmailVerificationLinkErrorCode = typeof EmailVerificationLinkErrorCodes[number];
|
|
25
26
|
export declare const PasswordResetLinkErrorCodes: readonly ["PASSWORD_RESET_LINK_INVALID", "PASSWORD_RESET_LINK_EXPIRED", "PASSWORD_RESET_LINK_USED"];
|
|
26
27
|
export type PasswordResetLinkErrorCode = typeof PasswordResetLinkErrorCodes[number];
|
|
28
|
+
export declare const PasswordUpdateErrorCodes: readonly ["WRONG_PASSWORD", "PASSWORD_FORMAT_INVALID"];
|
|
29
|
+
export type PasswordUpdateErrorCode = typeof PasswordUpdateErrorCodes[number];
|
|
27
30
|
export declare class KnownError extends StatusError {
|
|
28
31
|
readonly errorCode: KnownErrorCode;
|
|
29
32
|
constructor(errorCode: KnownErrorCode);
|
|
30
33
|
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,2BAA2B,yBAAyB,CAAC;AAClE,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AACrD,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAC9D,eAAO,MAAM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E,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD,eAAO,MAAM,eAAe,gbAiBlB,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAE5D,eAAO,MAAM,gBAAgB,iCAAuC,CAAC;AACrE,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE9D,eAAO,MAAM,gBAAgB,0DAGnB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE9D,eAAO,MAAM,+BAA+B,iHAIlC,CAAC;AACX,MAAM,MAAM,8BAA8B,GAAG,OAAO,+BAA+B,CAAC,MAAM,CAAC,CAAA;AAE3F,eAAO,MAAM,2BAA2B,qGAI9B,CAAC;AACX,MAAM,MAAM,0BAA0B,GAAG,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAA;AAEnF,eAAO,MAAM,wBAAwB,wDAAoE,CAAC;AAC1G,MAAM,MAAM,uBAAuB,GAAG,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAE9E,qBAAa,UAAW,SAAQ,WAAW;aACb,SAAS,EAAE,cAAc;gBAAzB,SAAS,EAAE,cAAc;CAatD"}
|
package/dist/utils/types.js
CHANGED
|
@@ -14,6 +14,7 @@ export const EmailVerificationLinkUsedErrorCode = "EMAIL_VERIFICATION_LINK_USED"
|
|
|
14
14
|
export const PasswordResetLinkInvalidErrorCode = "PASSWORD_RESET_LINK_INVALID";
|
|
15
15
|
export const PasswordResetLinkExpiredErrorCode = "PASSWORD_RESET_LINK_EXPIRED";
|
|
16
16
|
export const PasswordResetLinkUsedErrorCode = "PASSWORD_RESET_LINK_USED";
|
|
17
|
+
export const WrongPasswordErrorCode = "WRONG_PASSWORD";
|
|
17
18
|
export const KnownErrorCodes = [
|
|
18
19
|
AccessTokenExpiredErrorCode,
|
|
19
20
|
GrantInvalidErrorCode,
|
|
@@ -30,6 +31,7 @@ export const KnownErrorCodes = [
|
|
|
30
31
|
PasswordResetLinkInvalidErrorCode,
|
|
31
32
|
PasswordResetLinkExpiredErrorCode,
|
|
32
33
|
PasswordResetLinkUsedErrorCode,
|
|
34
|
+
WrongPasswordErrorCode
|
|
33
35
|
];
|
|
34
36
|
export const SignUpErrorCodes = [UserAlreadyExistErrorCode];
|
|
35
37
|
export const SignInErrorCodes = [
|
|
@@ -46,6 +48,7 @@ export const PasswordResetLinkErrorCodes = [
|
|
|
46
48
|
PasswordResetLinkExpiredErrorCode,
|
|
47
49
|
PasswordResetLinkUsedErrorCode
|
|
48
50
|
];
|
|
51
|
+
export const PasswordUpdateErrorCodes = [WrongPasswordErrorCode, PasswordFormatInvalidErrorCode];
|
|
49
52
|
export class KnownError extends StatusError {
|
|
50
53
|
errorCode;
|
|
51
54
|
constructor(errorCode) {
|
|
@@ -53,7 +56,7 @@ export class KnownError extends StatusError {
|
|
|
53
56
|
error_code: errorCode,
|
|
54
57
|
}), {
|
|
55
58
|
headers: {
|
|
56
|
-
"content-type": "application/json",
|
|
59
|
+
"content-type": ["application/json"],
|
|
57
60
|
},
|
|
58
61
|
});
|
|
59
62
|
this.errorCode = errorCode;
|
package/package.json
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"peerDependencies": {
|
|
10
|
-
"react": "^18.2
|
|
11
|
-
},
|
|
12
|
-
"peerDependenciesMeta": {
|
|
13
|
-
"react": {
|
|
14
|
-
"optional": true
|
|
15
|
-
}
|
|
10
|
+
"react": "^18.2"
|
|
16
11
|
},
|
|
17
12
|
"dependencies": {
|
|
18
13
|
"bcrypt": "^5.1.1",
|
|
@@ -22,14 +17,8 @@
|
|
|
22
17
|
},
|
|
23
18
|
"devDependencies": {
|
|
24
19
|
"@types/bcrypt": "^5.0.2",
|
|
25
|
-
"@types/react": "^18.2.
|
|
26
|
-
"@types/uuid": "^9.0.8"
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^6",
|
|
28
|
-
"@typescript-eslint/parser": "^6.x",
|
|
29
|
-
"eslint": "^8",
|
|
30
|
-
"eslint-config-next": "^14",
|
|
31
|
-
"rimraf": "^5.0.5",
|
|
32
|
-
"react": "^18.2.0"
|
|
20
|
+
"@types/react": "^18.2.66",
|
|
21
|
+
"@types/uuid": "^9.0.8"
|
|
33
22
|
},
|
|
34
23
|
"scripts": {
|
|
35
24
|
"build": "tsc",
|