@stackframe/stack-shared 2.1.0 → 2.2.1
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/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 +4 -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 +204 -0
- package/dist/known-errors.d.ts.map +1 -0
- package/dist/known-errors.js +318 -0
- 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 +5 -1
- package/dist/utils/errors.d.ts +15 -7
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +44 -3
- package/dist/utils/functions.d.ts +3 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/dist/utils/functions.js +6 -0
- package/dist/utils/jwt.d.ts.map +1 -1
- package/dist/utils/objects.d.ts +2 -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/package.json +1 -1
- package/dist/helpers/fetch-token.d.ts +0 -2
- package/dist/helpers/fetch-token.d.ts.map +0 -1
- package/dist/helpers/fetch-token.js +0 -1
- package/dist/utils/types.d.ts +0 -31
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/utils/types.js +0 -61
package/dist/utils/crypto.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import crypto from "
|
|
1
|
+
import crypto from "crypto";
|
|
2
2
|
import { encodeBase32 } from "./bytes";
|
|
3
|
+
/**
|
|
4
|
+
* Generates a secure alphanumeric string using the system's cryptographically secure
|
|
5
|
+
* random number generator.
|
|
6
|
+
*/
|
|
3
7
|
export function generateSecureRandomString(minBitsOfEntropy = 224) {
|
|
4
8
|
const base32CharactersCount = Math.ceil(minBitsOfEntropy / 5);
|
|
5
9
|
const bytesCount = Math.ceil(base32CharactersCount * 5 / 8);
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
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
|
+
name: string;
|
|
8
|
+
constructor(message: string, extraData?: Record<string, any> | undefined, options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
export declare function throwStackErr(message: string, extraData?: any): never;
|
|
11
|
+
export declare function registerErrorSink(sink: (location: string, error: unknown) => void): void;
|
|
12
|
+
export declare function captureError(location: string, error: unknown): void;
|
|
4
13
|
type Status = {
|
|
5
14
|
statusCode: number;
|
|
6
15
|
message: string;
|
|
7
16
|
};
|
|
8
17
|
type StatusErrorConstructorParameters = [
|
|
9
18
|
statusCode: number | Status,
|
|
10
|
-
message?: string
|
|
11
|
-
options?: {
|
|
12
|
-
headers: Record<string, string[]>;
|
|
13
|
-
}
|
|
19
|
+
message?: string
|
|
14
20
|
];
|
|
15
21
|
export declare class StatusError extends Error {
|
|
16
|
-
|
|
17
|
-
headers: Record<string, string[]>;
|
|
18
|
-
} | undefined;
|
|
22
|
+
name: string;
|
|
19
23
|
readonly statusCode: number;
|
|
20
24
|
static BadRequest: {
|
|
21
25
|
statusCode: number;
|
|
@@ -180,6 +184,10 @@ export declare class StatusError extends Error {
|
|
|
180
184
|
constructor(...args: StatusErrorConstructorParameters);
|
|
181
185
|
isClientError(): boolean;
|
|
182
186
|
isServerError(): boolean;
|
|
187
|
+
getStatusCode(): number;
|
|
188
|
+
getBody(): Uint8Array;
|
|
189
|
+
getHeaders(): Record<string, string[]>;
|
|
190
|
+
toHttpJson(): Json;
|
|
183
191
|
}
|
|
184
192
|
export {};
|
|
185
193
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -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;aAEC,SAAS,CAAC;IADhD,IAAI,SAAyB;gBACxB,OAAO,EAAE,MAAM,EAAkB,SAAS,CAAC,iCAAqB,EAAE,OAAO,CAAC,EAAE,YAAY;CAGrG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0C;IAC9D,OAAc,gBAAgB;;;MAAqD;IACnF,OAAc,QAAQ;;;MAA6C;IACnE,OAAc,eAAe;;;MAAoD;IACjF,OAAc,oBAAoB;;;MAAyD;IAC3F,OAAc,eAAe;;;MAAqD;IAClF,OAAc,2BAA2B;;;MAAmE;IAC5G,OAAc,0BAA0B;;;MAAiE;IAEzG,OAAc,mBAAmB;;;MAAyD;IAC1F,OAAc,cAAc;;;MAAmD;IAC/E,OAAc,UAAU;;;MAA+C;IACvE,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
|
+
name = "StackAssertionError";
|
|
16
|
+
constructor(message, extraData, options) {
|
|
17
|
+
super(`${message}\n\nThis is likely an error in Stack. Please report it.`, options);
|
|
18
|
+
this.extraData = extraData;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function throwStackErr(message, extraData) {
|
|
22
|
+
throw new StackAssertionError(message, extraData);
|
|
23
|
+
}
|
|
24
|
+
const errorSinks = new Set();
|
|
25
|
+
export function registerErrorSink(sink) {
|
|
26
|
+
if (errorSinks.has(sink)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
errorSinks.add(sink);
|
|
30
|
+
}
|
|
31
|
+
registerErrorSink((location, ...args) => console.error(`Error in ${location}:`, ...args));
|
|
32
|
+
export function captureError(location, error) {
|
|
33
|
+
for (const sink of errorSinks) {
|
|
34
|
+
sink(location, error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
13
37
|
export class StatusError extends Error {
|
|
14
|
-
|
|
38
|
+
name = "StatusError";
|
|
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/jwt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/utils/jwt.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/utils/jwt.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAM7B,wBAAsB,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,SAAO,mBAMnE;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,4BAK3C"}
|
package/dist/utils/objects.d.ts
CHANGED
|
@@ -19,4 +19,6 @@ export declare function typedAssign<T extends {}, U extends {}>(target: T, sourc
|
|
|
19
19
|
export declare function filterUndefined<T extends {}>(obj: T): {
|
|
20
20
|
[k in keyof T]+?: T[k] & ({} | null);
|
|
21
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>;
|
|
22
24
|
//# sourceMappingURL=objects.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objects.d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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,CAAC;AACxC,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,CA0BzG;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAKrD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAK5D;AAED,wBAAgB,YAAY,IAAI,YAAY,CAAC,KAAK,CAAC,CAElD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAA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,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,MA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CAAC,GAAG,SAAS,KAAK,CAAC,GAAG,CAAC;IAMzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAMrD,cAAc,IAAI,IAAI;IAQtB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAIjC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAQ9C,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;IAU5F,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;CAO/F"}
|
package/dist/utils/stores.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AsyncResult } from "./results";
|
|
1
|
+
import { AsyncResult, 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/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-token.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,iFAAiF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const fetchTokenPrefix = "#stack-auth--if-you-see-this-you-probably-forgot-to-add-an-auth-provider----";
|
package/dist/utils/types.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { StatusError } from "./errors";
|
|
2
|
-
export declare const AccessTokenExpiredErrorCode = "ACCESS_TOKEN_EXPIRED";
|
|
3
|
-
export declare const GrantInvalidErrorCode = "GRANT_INVALID";
|
|
4
|
-
export declare const UserAlreadyExistErrorCode = "USER_ALREADY_EXIST";
|
|
5
|
-
export declare const UserNotExistErrorCode = "USER_NOT_EXIST";
|
|
6
|
-
export declare const UserNotVerifiedErrorCode = "USER_NOT_VERIFIED";
|
|
7
|
-
export declare const EmailPasswordMissMatchErrorCode = "EMAIL_PASSWORD_MISS_MATCH";
|
|
8
|
-
export declare const RedirectUrlInvalidErrorCode = "REDIRECT_URL_INVALID";
|
|
9
|
-
export declare const PasswordFormatInvalidErrorCode = "PASSWORD_FORMAT_INVALID";
|
|
10
|
-
export declare const ProjectIdOrKeyInvalidErrorCode = "PROJECT_ID_OR_KEY_INVALID";
|
|
11
|
-
export declare const EmailVerificationLinkInvalidErrorCode = "EMAIL_VERIFICATION_LINK_INVALID";
|
|
12
|
-
export declare const EmailVerificationLinkExpiredErrorCode = "EMAIL_VERIFICATION_LINK_EXPIRED";
|
|
13
|
-
export declare const EmailVerificationLinkUsedErrorCode = "EMAIL_VERIFICATION_LINK_USED";
|
|
14
|
-
export declare const PasswordResetLinkInvalidErrorCode = "PASSWORD_RESET_LINK_INVALID";
|
|
15
|
-
export declare const PasswordResetLinkExpiredErrorCode = "PASSWORD_RESET_LINK_EXPIRED";
|
|
16
|
-
export declare const PasswordResetLinkUsedErrorCode = "PASSWORD_RESET_LINK_USED";
|
|
17
|
-
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"];
|
|
18
|
-
export type KnownErrorCode = typeof KnownErrorCodes[number];
|
|
19
|
-
export declare const SignUpErrorCodes: readonly ["USER_ALREADY_EXIST"];
|
|
20
|
-
export type SignUpErrorCode = typeof SignUpErrorCodes[number];
|
|
21
|
-
export declare const SignInErrorCodes: readonly ["EMAIL_PASSWORD_MISS_MATCH", "USER_NOT_EXIST"];
|
|
22
|
-
export type SignInErrorCode = typeof SignInErrorCodes[number];
|
|
23
|
-
export declare const EmailVerificationLinkErrorCodes: readonly ["EMAIL_VERIFICATION_LINK_INVALID", "EMAIL_VERIFICATION_LINK_EXPIRED", "EMAIL_VERIFICATION_LINK_USED"];
|
|
24
|
-
export type EmailVerificationLinkErrorCode = typeof EmailVerificationLinkErrorCodes[number];
|
|
25
|
-
export declare const PasswordResetLinkErrorCodes: readonly ["PASSWORD_RESET_LINK_INVALID", "PASSWORD_RESET_LINK_EXPIRED", "PASSWORD_RESET_LINK_USED"];
|
|
26
|
-
export type PasswordResetLinkErrorCode = typeof PasswordResetLinkErrorCodes[number];
|
|
27
|
-
export declare class KnownError extends StatusError {
|
|
28
|
-
readonly errorCode: KnownErrorCode;
|
|
29
|
-
constructor(errorCode: KnownErrorCode);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,qBAAqB,mBAAmB,CAAC;AACtD,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAC5D,eAAO,MAAM,+BAA+B,8BAA8B,CAAC;AAC3E,eAAO,MAAM,2BAA2B,yBAAyB,CAAC;AAClE,eAAO,MAAM,8BAA8B,4BAA4B,CAAC;AACxE,eAAO,MAAM,8BAA8B,8BAA8B,CAAC;AAC1E,eAAO,MAAM,qCAAqC,oCAAoC,CAAC;AACvF,eAAO,MAAM,qCAAqC,oCAAoC,CAAC;AACvF,eAAO,MAAM,kCAAkC,iCAAiC,CAAC;AACjF,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAC/E,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAC/E,eAAO,MAAM,8BAA8B,6BAA6B,CAAC;AAEzE,eAAO,MAAM,eAAe,8ZAgBlB,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,qBAAa,UAAW,SAAQ,WAAW;aACb,SAAS,EAAE,cAAc;gBAAzB,SAAS,EAAE,cAAc;CAatD"}
|
package/dist/utils/types.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { StatusError } from "./errors";
|
|
2
|
-
export const AccessTokenExpiredErrorCode = "ACCESS_TOKEN_EXPIRED";
|
|
3
|
-
export const GrantInvalidErrorCode = "GRANT_INVALID";
|
|
4
|
-
export const UserAlreadyExistErrorCode = "USER_ALREADY_EXIST";
|
|
5
|
-
export const UserNotExistErrorCode = "USER_NOT_EXIST";
|
|
6
|
-
export const UserNotVerifiedErrorCode = "USER_NOT_VERIFIED";
|
|
7
|
-
export const EmailPasswordMissMatchErrorCode = "EMAIL_PASSWORD_MISS_MATCH";
|
|
8
|
-
export const RedirectUrlInvalidErrorCode = "REDIRECT_URL_INVALID";
|
|
9
|
-
export const PasswordFormatInvalidErrorCode = "PASSWORD_FORMAT_INVALID";
|
|
10
|
-
export const ProjectIdOrKeyInvalidErrorCode = "PROJECT_ID_OR_KEY_INVALID";
|
|
11
|
-
export const EmailVerificationLinkInvalidErrorCode = "EMAIL_VERIFICATION_LINK_INVALID";
|
|
12
|
-
export const EmailVerificationLinkExpiredErrorCode = "EMAIL_VERIFICATION_LINK_EXPIRED";
|
|
13
|
-
export const EmailVerificationLinkUsedErrorCode = "EMAIL_VERIFICATION_LINK_USED";
|
|
14
|
-
export const PasswordResetLinkInvalidErrorCode = "PASSWORD_RESET_LINK_INVALID";
|
|
15
|
-
export const PasswordResetLinkExpiredErrorCode = "PASSWORD_RESET_LINK_EXPIRED";
|
|
16
|
-
export const PasswordResetLinkUsedErrorCode = "PASSWORD_RESET_LINK_USED";
|
|
17
|
-
export const KnownErrorCodes = [
|
|
18
|
-
AccessTokenExpiredErrorCode,
|
|
19
|
-
GrantInvalidErrorCode,
|
|
20
|
-
UserAlreadyExistErrorCode,
|
|
21
|
-
UserNotExistErrorCode,
|
|
22
|
-
UserNotVerifiedErrorCode,
|
|
23
|
-
EmailPasswordMissMatchErrorCode,
|
|
24
|
-
RedirectUrlInvalidErrorCode,
|
|
25
|
-
PasswordFormatInvalidErrorCode,
|
|
26
|
-
ProjectIdOrKeyInvalidErrorCode,
|
|
27
|
-
EmailVerificationLinkInvalidErrorCode,
|
|
28
|
-
EmailVerificationLinkExpiredErrorCode,
|
|
29
|
-
EmailVerificationLinkUsedErrorCode,
|
|
30
|
-
PasswordResetLinkInvalidErrorCode,
|
|
31
|
-
PasswordResetLinkExpiredErrorCode,
|
|
32
|
-
PasswordResetLinkUsedErrorCode,
|
|
33
|
-
];
|
|
34
|
-
export const SignUpErrorCodes = [UserAlreadyExistErrorCode];
|
|
35
|
-
export const SignInErrorCodes = [
|
|
36
|
-
EmailPasswordMissMatchErrorCode,
|
|
37
|
-
UserNotExistErrorCode
|
|
38
|
-
];
|
|
39
|
-
export const EmailVerificationLinkErrorCodes = [
|
|
40
|
-
EmailVerificationLinkInvalidErrorCode,
|
|
41
|
-
EmailVerificationLinkExpiredErrorCode,
|
|
42
|
-
EmailVerificationLinkUsedErrorCode
|
|
43
|
-
];
|
|
44
|
-
export const PasswordResetLinkErrorCodes = [
|
|
45
|
-
PasswordResetLinkInvalidErrorCode,
|
|
46
|
-
PasswordResetLinkExpiredErrorCode,
|
|
47
|
-
PasswordResetLinkUsedErrorCode
|
|
48
|
-
];
|
|
49
|
-
export class KnownError extends StatusError {
|
|
50
|
-
errorCode;
|
|
51
|
-
constructor(errorCode) {
|
|
52
|
-
super(401, JSON.stringify({
|
|
53
|
-
error_code: errorCode,
|
|
54
|
-
}), {
|
|
55
|
-
headers: {
|
|
56
|
-
"content-type": ["application/json"],
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
this.errorCode = errorCode;
|
|
60
|
-
}
|
|
61
|
-
}
|