@stackframe/stack-shared 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/interface/adminInterface.js +0 -1
- package/dist/interface/clientInterface.js +0 -1
- package/dist/interface/serverInterface.js +0 -1
- package/dist/known-errors.js +3 -7
- package/dist/schema-fields.js +0 -1
- package/dist/sessions.js +7 -23
- package/dist/utils/arrays.d.ts +4 -0
- package/dist/utils/arrays.js +10 -0
- package/dist/utils/caches.js +11 -18
- package/dist/utils/errors.js +41 -43
- package/dist/utils/globals.js +3 -0
- package/dist/utils/maps.js +8 -5
- package/dist/utils/numbers.js +5 -5
- package/dist/utils/promises.js +0 -1
- package/dist/utils/results.js +0 -1
- package/dist/utils/stores.js +7 -10
- package/dist/utils/strings.js +6 -1
- package/dist/utils/uuids.d.ts +1 -1
- package/dist/utils/uuids.js +2 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,6 @@ import { StackClientInterface, } from "./clientInterface";
|
|
|
2
2
|
import { Result } from "../utils/results";
|
|
3
3
|
export const emailTemplateTypes = ['EMAIL_VERIFICATION', 'PASSWORD_RESET', 'MAGIC_LINK'];
|
|
4
4
|
export class StackServerInterface extends StackClientInterface {
|
|
5
|
-
options;
|
|
6
5
|
constructor(options) {
|
|
7
6
|
super(options);
|
|
8
7
|
this.options = options;
|
package/dist/known-errors.js
CHANGED
|
@@ -2,15 +2,12 @@ import { StatusError, throwErr } from "./utils/errors";
|
|
|
2
2
|
import { identityArgs } from "./utils/functions";
|
|
3
3
|
import { deindent } from "./utils/strings";
|
|
4
4
|
export class KnownError extends StatusError {
|
|
5
|
-
statusCode;
|
|
6
|
-
humanReadableMessage;
|
|
7
|
-
details;
|
|
8
|
-
name = "KnownError";
|
|
9
5
|
constructor(statusCode, humanReadableMessage, details) {
|
|
10
6
|
super(statusCode, humanReadableMessage);
|
|
11
7
|
this.statusCode = statusCode;
|
|
12
8
|
this.humanReadableMessage = humanReadableMessage;
|
|
13
9
|
this.details = details;
|
|
10
|
+
this.name = "KnownError";
|
|
14
11
|
}
|
|
15
12
|
getBody() {
|
|
16
13
|
return new TextEncoder().encode(JSON.stringify({
|
|
@@ -52,18 +49,17 @@ function createKnownErrorConstructor(SuperClass, errorCode, create, constructorA
|
|
|
52
49
|
const constructorArgsFromJsonFn = constructorArgsFromJson === "inherit" ? SuperClass.constructorArgsFromJson : constructorArgsFromJson;
|
|
53
50
|
// @ts-expect-error this is not a mixin, but TS detects it as one
|
|
54
51
|
class KnownErrorImpl extends SuperClass {
|
|
55
|
-
static errorCode = errorCode;
|
|
56
|
-
name = `KnownError<${errorCode}>`;
|
|
57
|
-
constructorArgs;
|
|
58
52
|
constructor(...args) {
|
|
59
53
|
// @ts-expect-error
|
|
60
54
|
super(...createFn(...args));
|
|
55
|
+
this.name = `KnownError<${errorCode}>`;
|
|
61
56
|
this.constructorArgs = args;
|
|
62
57
|
}
|
|
63
58
|
static constructorArgsFromJson(json) {
|
|
64
59
|
return constructorArgsFromJsonFn(json);
|
|
65
60
|
}
|
|
66
61
|
}
|
|
62
|
+
KnownErrorImpl.errorCode = errorCode;
|
|
67
63
|
;
|
|
68
64
|
// @ts-expect-error
|
|
69
65
|
return KnownErrorImpl;
|
package/dist/schema-fields.js
CHANGED
|
@@ -29,7 +29,6 @@ export const projectIdSchema = yup.string().meta({ openapiField: { description:
|
|
|
29
29
|
// Users
|
|
30
30
|
export const userIdRequestSchema = yup.string().uuid().meta({ openapiField: { description: 'The ID of the user', exampleValue: '3241a285-8329-4d69-8f3d-316e08cf140c' } });
|
|
31
31
|
export class ReplaceFieldWithOwnUserId extends Error {
|
|
32
|
-
path;
|
|
33
32
|
constructor(path) {
|
|
34
33
|
super(`This error should be caught by whoever validated the schema, and the field in the path '${path}' should be replaced with the current user's id. This is a workaround to yup not providing access to the context inside the transform function.`);
|
|
35
34
|
this.path = path;
|
package/dist/sessions.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Store } from "./utils/stores";
|
|
2
2
|
export class AccessToken {
|
|
3
|
-
token;
|
|
4
3
|
constructor(token) {
|
|
5
4
|
this.token = token;
|
|
6
5
|
}
|
|
7
6
|
}
|
|
8
7
|
export class RefreshToken {
|
|
9
|
-
token;
|
|
10
8
|
constructor(token) {
|
|
11
9
|
this.token = token;
|
|
12
10
|
}
|
|
@@ -17,29 +15,15 @@ export class RefreshToken {
|
|
|
17
15
|
* A session never changes which user or session it belongs to, but the tokens in it may change over time.
|
|
18
16
|
*/
|
|
19
17
|
export class InternalSession {
|
|
20
|
-
_options;
|
|
21
|
-
/**
|
|
22
|
-
* Each session has a session key that depends on the tokens inside. If the session has a refresh token, the session key depends only on the refresh token. If the session does not have a refresh token, the session key depends only on the access token.
|
|
23
|
-
*
|
|
24
|
-
* Multiple Session objects may have the same session key, which implies that they represent the same session by the same user. Furthermore, a session's key never changes over the lifetime of a session object.
|
|
25
|
-
*
|
|
26
|
-
* This is useful for caching and indexing sessions.
|
|
27
|
-
*/
|
|
28
|
-
sessionKey;
|
|
29
|
-
/**
|
|
30
|
-
* An access token that is not known to be invalid (ie. may be valid, but may have expired).
|
|
31
|
-
*/
|
|
32
|
-
_accessToken;
|
|
33
|
-
_refreshToken;
|
|
34
|
-
/**
|
|
35
|
-
* Whether the session as a whole is known to be invalid. Used as a cache to avoid making multiple requests to the server (sessions never go back to being valid after being invalidated).
|
|
36
|
-
*
|
|
37
|
-
* Applies to both the access token and the refresh token (it is possible for the access token to be invalid but the refresh token to be valid, in which case the session is still valid).
|
|
38
|
-
*/
|
|
39
|
-
_knownToBeInvalid = new Store(false);
|
|
40
|
-
_refreshPromise = null;
|
|
41
18
|
constructor(_options) {
|
|
42
19
|
this._options = _options;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the session as a whole is known to be invalid. Used as a cache to avoid making multiple requests to the server (sessions never go back to being valid after being invalidated).
|
|
22
|
+
*
|
|
23
|
+
* Applies to both the access token and the refresh token (it is possible for the access token to be invalid but the refresh token to be valid, in which case the session is still valid).
|
|
24
|
+
*/
|
|
25
|
+
this._knownToBeInvalid = new Store(false);
|
|
26
|
+
this._refreshPromise = null;
|
|
43
27
|
this._accessToken = new Store(_options.accessToken ? new AccessToken(_options.accessToken) : null);
|
|
44
28
|
this._refreshToken = _options.refreshToken ? new RefreshToken(_options.refreshToken) : null;
|
|
45
29
|
this.sessionKey = InternalSession.calculateSessionKey({ accessToken: _options.accessToken ?? null, refreshToken: _options.refreshToken });
|
package/dist/utils/arrays.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Ponyfill for ES2023's findLastIndex.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findLastIndex<T>(arr: readonly T[], predicate: (item: T) => boolean): number;
|
|
4
8
|
export declare function groupBy<T extends any, K>(arr: Iterable<T>, key: (item: T) => K): Map<K, T[]>;
|
|
5
9
|
export declare function range(endExclusive: number): number[];
|
|
6
10
|
export declare function range(startInclusive: number, endExclusive: number): number[];
|
package/dist/utils/arrays.js
CHANGED
|
@@ -14,6 +14,16 @@ export function isShallowEqual(a, b) {
|
|
|
14
14
|
}
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Ponyfill for ES2023's findLastIndex.
|
|
19
|
+
*/
|
|
20
|
+
export function findLastIndex(arr, predicate) {
|
|
21
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
22
|
+
if (predicate(arr[i]))
|
|
23
|
+
return i;
|
|
24
|
+
}
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
17
27
|
export function groupBy(arr, key) {
|
|
18
28
|
const result = new Map;
|
|
19
29
|
for (const item of arr) {
|
package/dist/utils/caches.js
CHANGED
|
@@ -17,12 +17,18 @@ export function cacheFunction(f) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
export class AsyncCache {
|
|
20
|
-
_fetcher;
|
|
21
|
-
_options;
|
|
22
|
-
_map = new DependenciesMap();
|
|
23
20
|
constructor(_fetcher, _options = {}) {
|
|
24
21
|
this._fetcher = _fetcher;
|
|
25
22
|
this._options = _options;
|
|
23
|
+
this._map = new DependenciesMap();
|
|
24
|
+
this.isCacheAvailable = this._createKeyed("isCacheAvailable");
|
|
25
|
+
this.getIfCached = this._createKeyed("getIfCached");
|
|
26
|
+
this.getOrWait = this._createKeyed("getOrWait");
|
|
27
|
+
this.forceSetCachedValue = this._createKeyed("forceSetCachedValue");
|
|
28
|
+
this.forceSetCachedValueAsync = this._createKeyed("forceSetCachedValueAsync");
|
|
29
|
+
this.refresh = this._createKeyed("refresh");
|
|
30
|
+
this.invalidate = this._createKeyed("invalidate");
|
|
31
|
+
this.onStateChange = this._createKeyed("onStateChange");
|
|
26
32
|
// nothing here yet
|
|
27
33
|
}
|
|
28
34
|
_createKeyed(functionName) {
|
|
@@ -42,25 +48,12 @@ export class AsyncCache {
|
|
|
42
48
|
}
|
|
43
49
|
return cache;
|
|
44
50
|
}
|
|
45
|
-
isCacheAvailable = this._createKeyed("isCacheAvailable");
|
|
46
|
-
getIfCached = this._createKeyed("getIfCached");
|
|
47
|
-
getOrWait = this._createKeyed("getOrWait");
|
|
48
|
-
forceSetCachedValue = this._createKeyed("forceSetCachedValue");
|
|
49
|
-
forceSetCachedValueAsync = this._createKeyed("forceSetCachedValueAsync");
|
|
50
|
-
refresh = this._createKeyed("refresh");
|
|
51
|
-
invalidate = this._createKeyed("invalidate");
|
|
52
|
-
onStateChange = this._createKeyed("onStateChange");
|
|
53
51
|
}
|
|
54
52
|
class AsyncValueCache {
|
|
55
|
-
_options;
|
|
56
|
-
_store;
|
|
57
|
-
_pendingPromise;
|
|
58
|
-
_fetcher;
|
|
59
|
-
_rateLimitOptions;
|
|
60
|
-
_subscriptionsCount = 0;
|
|
61
|
-
_unsubscribers = [];
|
|
62
53
|
constructor(fetcher, _options = {}) {
|
|
63
54
|
this._options = _options;
|
|
55
|
+
this._subscriptionsCount = 0;
|
|
56
|
+
this._unsubscribers = [];
|
|
64
57
|
this._store = new AsyncStore();
|
|
65
58
|
this._rateLimitOptions = {
|
|
66
59
|
concurrency: 1,
|
package/dist/utils/errors.js
CHANGED
|
@@ -12,7 +12,6 @@ export function throwErr(...args) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export class StackAssertionError extends Error {
|
|
15
|
-
extraData;
|
|
16
15
|
constructor(message, extraData, options) {
|
|
17
16
|
const disclaimer = `\n\nThis is likely an error in Stack. Please report it.`;
|
|
18
17
|
super(`${message}${message.endsWith(disclaimer) ? "" : disclaimer}`, options);
|
|
@@ -40,48 +39,6 @@ export function captureError(location, error) {
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
export class StatusError extends Error {
|
|
43
|
-
name = "StatusError";
|
|
44
|
-
statusCode;
|
|
45
|
-
static BadRequest = { statusCode: 400, message: "Bad Request" };
|
|
46
|
-
static Unauthorized = { statusCode: 401, message: "Unauthorized" };
|
|
47
|
-
static PaymentRequired = { statusCode: 402, message: "Payment Required" };
|
|
48
|
-
static Forbidden = { statusCode: 403, message: "Forbidden" };
|
|
49
|
-
static NotFound = { statusCode: 404, message: "Not Found" };
|
|
50
|
-
static MethodNotAllowed = { statusCode: 405, message: "Method Not Allowed" };
|
|
51
|
-
static NotAcceptable = { statusCode: 406, message: "Not Acceptable" };
|
|
52
|
-
static ProxyAuthenticationRequired = { statusCode: 407, message: "Proxy Authentication Required" };
|
|
53
|
-
static RequestTimeout = { statusCode: 408, message: "Request Timeout" };
|
|
54
|
-
static Conflict = { statusCode: 409, message: "Conflict" };
|
|
55
|
-
static Gone = { statusCode: 410, message: "Gone" };
|
|
56
|
-
static LengthRequired = { statusCode: 411, message: "Length Required" };
|
|
57
|
-
static PreconditionFailed = { statusCode: 412, message: "Precondition Failed" };
|
|
58
|
-
static PayloadTooLarge = { statusCode: 413, message: "Payload Too Large" };
|
|
59
|
-
static URITooLong = { statusCode: 414, message: "URI Too Long" };
|
|
60
|
-
static UnsupportedMediaType = { statusCode: 415, message: "Unsupported Media Type" };
|
|
61
|
-
static RangeNotSatisfiable = { statusCode: 416, message: "Range Not Satisfiable" };
|
|
62
|
-
static ExpectationFailed = { statusCode: 417, message: "Expectation Failed" };
|
|
63
|
-
static ImATeapot = { statusCode: 418, message: "I'm a teapot" };
|
|
64
|
-
static MisdirectedRequest = { statusCode: 421, message: "Misdirected Request" };
|
|
65
|
-
static UnprocessableEntity = { statusCode: 422, message: "Unprocessable Entity" };
|
|
66
|
-
static Locked = { statusCode: 423, message: "Locked" };
|
|
67
|
-
static FailedDependency = { statusCode: 424, message: "Failed Dependency" };
|
|
68
|
-
static TooEarly = { statusCode: 425, message: "Too Early" };
|
|
69
|
-
static UpgradeRequired = { statusCode: 426, message: "Upgrade Required" };
|
|
70
|
-
static PreconditionRequired = { statusCode: 428, message: "Precondition Required" };
|
|
71
|
-
static TooManyRequests = { statusCode: 429, message: "Too Many Requests" };
|
|
72
|
-
static RequestHeaderFieldsTooLarge = { statusCode: 431, message: "Request Header Fields Too Large" };
|
|
73
|
-
static UnavailableForLegalReasons = { statusCode: 451, message: "Unavailable For Legal Reasons" };
|
|
74
|
-
static InternalServerError = { statusCode: 500, message: "Internal Server Error" };
|
|
75
|
-
static NotImplemented = { statusCode: 501, message: "Not Implemented" };
|
|
76
|
-
static BadGateway = { statusCode: 502, message: "Bad Gateway" };
|
|
77
|
-
static ServiceUnavailable = { statusCode: 503, message: "Service Unavailable" };
|
|
78
|
-
static GatewayTimeout = { statusCode: 504, message: "Gateway Timeout" };
|
|
79
|
-
static HTTPVersionNotSupported = { statusCode: 505, message: "HTTP Version Not Supported" };
|
|
80
|
-
static VariantAlsoNegotiates = { statusCode: 506, message: "Variant Also Negotiates" };
|
|
81
|
-
static InsufficientStorage = { statusCode: 507, message: "Insufficient Storage" };
|
|
82
|
-
static LoopDetected = { statusCode: 508, message: "Loop Detected" };
|
|
83
|
-
static NotExtended = { statusCode: 510, message: "Not Extended" };
|
|
84
|
-
static NetworkAuthenticationRequired = { statusCode: 511, message: "Network Authentication Required" };
|
|
85
42
|
constructor(status, message) {
|
|
86
43
|
if (typeof status === "object") {
|
|
87
44
|
message ??= status.message;
|
|
@@ -89,6 +46,7 @@ export class StatusError extends Error {
|
|
|
89
46
|
}
|
|
90
47
|
message ??= "Server Error";
|
|
91
48
|
super(message);
|
|
49
|
+
this.name = "StatusError";
|
|
92
50
|
this.statusCode = status;
|
|
93
51
|
}
|
|
94
52
|
isClientError() {
|
|
@@ -116,3 +74,43 @@ export class StatusError extends Error {
|
|
|
116
74
|
};
|
|
117
75
|
}
|
|
118
76
|
}
|
|
77
|
+
StatusError.BadRequest = { statusCode: 400, message: "Bad Request" };
|
|
78
|
+
StatusError.Unauthorized = { statusCode: 401, message: "Unauthorized" };
|
|
79
|
+
StatusError.PaymentRequired = { statusCode: 402, message: "Payment Required" };
|
|
80
|
+
StatusError.Forbidden = { statusCode: 403, message: "Forbidden" };
|
|
81
|
+
StatusError.NotFound = { statusCode: 404, message: "Not Found" };
|
|
82
|
+
StatusError.MethodNotAllowed = { statusCode: 405, message: "Method Not Allowed" };
|
|
83
|
+
StatusError.NotAcceptable = { statusCode: 406, message: "Not Acceptable" };
|
|
84
|
+
StatusError.ProxyAuthenticationRequired = { statusCode: 407, message: "Proxy Authentication Required" };
|
|
85
|
+
StatusError.RequestTimeout = { statusCode: 408, message: "Request Timeout" };
|
|
86
|
+
StatusError.Conflict = { statusCode: 409, message: "Conflict" };
|
|
87
|
+
StatusError.Gone = { statusCode: 410, message: "Gone" };
|
|
88
|
+
StatusError.LengthRequired = { statusCode: 411, message: "Length Required" };
|
|
89
|
+
StatusError.PreconditionFailed = { statusCode: 412, message: "Precondition Failed" };
|
|
90
|
+
StatusError.PayloadTooLarge = { statusCode: 413, message: "Payload Too Large" };
|
|
91
|
+
StatusError.URITooLong = { statusCode: 414, message: "URI Too Long" };
|
|
92
|
+
StatusError.UnsupportedMediaType = { statusCode: 415, message: "Unsupported Media Type" };
|
|
93
|
+
StatusError.RangeNotSatisfiable = { statusCode: 416, message: "Range Not Satisfiable" };
|
|
94
|
+
StatusError.ExpectationFailed = { statusCode: 417, message: "Expectation Failed" };
|
|
95
|
+
StatusError.ImATeapot = { statusCode: 418, message: "I'm a teapot" };
|
|
96
|
+
StatusError.MisdirectedRequest = { statusCode: 421, message: "Misdirected Request" };
|
|
97
|
+
StatusError.UnprocessableEntity = { statusCode: 422, message: "Unprocessable Entity" };
|
|
98
|
+
StatusError.Locked = { statusCode: 423, message: "Locked" };
|
|
99
|
+
StatusError.FailedDependency = { statusCode: 424, message: "Failed Dependency" };
|
|
100
|
+
StatusError.TooEarly = { statusCode: 425, message: "Too Early" };
|
|
101
|
+
StatusError.UpgradeRequired = { statusCode: 426, message: "Upgrade Required" };
|
|
102
|
+
StatusError.PreconditionRequired = { statusCode: 428, message: "Precondition Required" };
|
|
103
|
+
StatusError.TooManyRequests = { statusCode: 429, message: "Too Many Requests" };
|
|
104
|
+
StatusError.RequestHeaderFieldsTooLarge = { statusCode: 431, message: "Request Header Fields Too Large" };
|
|
105
|
+
StatusError.UnavailableForLegalReasons = { statusCode: 451, message: "Unavailable For Legal Reasons" };
|
|
106
|
+
StatusError.InternalServerError = { statusCode: 500, message: "Internal Server Error" };
|
|
107
|
+
StatusError.NotImplemented = { statusCode: 501, message: "Not Implemented" };
|
|
108
|
+
StatusError.BadGateway = { statusCode: 502, message: "Bad Gateway" };
|
|
109
|
+
StatusError.ServiceUnavailable = { statusCode: 503, message: "Service Unavailable" };
|
|
110
|
+
StatusError.GatewayTimeout = { statusCode: 504, message: "Gateway Timeout" };
|
|
111
|
+
StatusError.HTTPVersionNotSupported = { statusCode: 505, message: "HTTP Version Not Supported" };
|
|
112
|
+
StatusError.VariantAlsoNegotiates = { statusCode: 506, message: "Variant Also Negotiates" };
|
|
113
|
+
StatusError.InsufficientStorage = { statusCode: 507, message: "Insufficient Storage" };
|
|
114
|
+
StatusError.LoopDetected = { statusCode: 508, message: "Loop Detected" };
|
|
115
|
+
StatusError.NotExtended = { statusCode: 510, message: "Not Extended" };
|
|
116
|
+
StatusError.NetworkAuthenticationRequired = { statusCode: 511, message: "Network Authentication Required" };
|
package/dist/utils/globals.js
CHANGED
|
@@ -4,6 +4,9 @@ const globalVar = typeof globalThis !== 'undefined' ? globalThis :
|
|
|
4
4
|
typeof self !== 'undefined' ? self :
|
|
5
5
|
{};
|
|
6
6
|
export { globalVar, };
|
|
7
|
+
if (typeof globalThis === 'undefined') {
|
|
8
|
+
globalVar.globalThis = globalVar;
|
|
9
|
+
}
|
|
7
10
|
const stackGlobalsSymbol = Symbol.for('__stack-globals');
|
|
8
11
|
globalVar[stackGlobalsSymbol] ??= {};
|
|
9
12
|
export function createGlobal(key, init) {
|
package/dist/utils/maps.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
var _a, _b;
|
|
1
2
|
import { Result } from "./results";
|
|
2
3
|
export class MaybeWeakMap {
|
|
3
|
-
_primitiveMap;
|
|
4
|
-
_weakMap;
|
|
5
4
|
constructor(entries) {
|
|
5
|
+
this[_a] = "MaybeWeakMap";
|
|
6
6
|
const entriesArray = [...entries ?? []];
|
|
7
7
|
this._primitiveMap = new Map(entriesArray.filter((e) => !this._isAllowedInWeakMap(e[0])));
|
|
8
8
|
this._weakMap = new WeakMap(entriesArray.filter((e) => this._isAllowedInWeakMap(e[0])));
|
|
@@ -43,10 +43,13 @@ export class MaybeWeakMap {
|
|
|
43
43
|
return this._primitiveMap.has(key);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
[Symbol.toStringTag] = "MaybeWeakMap";
|
|
47
46
|
}
|
|
47
|
+
_a = Symbol.toStringTag;
|
|
48
48
|
export class DependenciesMap {
|
|
49
|
-
|
|
49
|
+
constructor() {
|
|
50
|
+
this._inner = { map: new MaybeWeakMap(), hasValue: false, value: undefined };
|
|
51
|
+
this[_b] = "DependenciesMap";
|
|
52
|
+
}
|
|
50
53
|
_valueToResult(inner) {
|
|
51
54
|
if (inner.hasValue) {
|
|
52
55
|
return Result.ok(inner.value);
|
|
@@ -106,5 +109,5 @@ export class DependenciesMap {
|
|
|
106
109
|
clear() {
|
|
107
110
|
this._inner = { map: new MaybeWeakMap(), hasValue: false, value: undefined };
|
|
108
111
|
}
|
|
109
|
-
[Symbol.toStringTag] = "DependenciesMap";
|
|
110
112
|
}
|
|
113
|
+
_b = Symbol.toStringTag;
|
package/dist/utils/numbers.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const magnitudes = [
|
|
2
|
-
[
|
|
3
|
-
[
|
|
4
|
-
[
|
|
5
|
-
[
|
|
6
|
-
[
|
|
2
|
+
[1000000000000000, "trln"],
|
|
3
|
+
[1000000000000, "bln"],
|
|
4
|
+
[1000000000, "bn"],
|
|
5
|
+
[1000000, "M"],
|
|
6
|
+
[1000, "k"],
|
|
7
7
|
];
|
|
8
8
|
export function prettyPrintWithMagnitudes(num) {
|
|
9
9
|
if (typeof num !== "number")
|
package/dist/utils/promises.js
CHANGED
package/dist/utils/results.js
CHANGED
package/dist/utils/stores.js
CHANGED
|
@@ -2,10 +2,9 @@ import { AsyncResult, Result } from "./results";
|
|
|
2
2
|
import { generateUuid } from "./uuids";
|
|
3
3
|
import { pending, rejected, resolved } from "./promises";
|
|
4
4
|
export class Store {
|
|
5
|
-
_value;
|
|
6
|
-
_callbacks = new Map();
|
|
7
5
|
constructor(_value) {
|
|
8
6
|
this._value = _value;
|
|
7
|
+
this._callbacks = new Map();
|
|
9
8
|
}
|
|
10
9
|
get() {
|
|
11
10
|
return this._value;
|
|
@@ -38,15 +37,13 @@ export class Store {
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
export class AsyncStore {
|
|
41
|
-
_isAvailable;
|
|
42
|
-
_mostRecentOkValue = undefined;
|
|
43
|
-
_isRejected = false;
|
|
44
|
-
_rejectionError;
|
|
45
|
-
_waitingRejectFunctions = new Map();
|
|
46
|
-
_callbacks = new Map();
|
|
47
|
-
_updateCounter = 0;
|
|
48
|
-
_lastSuccessfulUpdate = -1;
|
|
49
40
|
constructor(...args) {
|
|
41
|
+
this._mostRecentOkValue = undefined;
|
|
42
|
+
this._isRejected = false;
|
|
43
|
+
this._waitingRejectFunctions = new Map();
|
|
44
|
+
this._callbacks = new Map();
|
|
45
|
+
this._updateCounter = 0;
|
|
46
|
+
this._lastSuccessfulUpdate = -1;
|
|
50
47
|
if (args.length === 0) {
|
|
51
48
|
this._isAvailable = false;
|
|
52
49
|
}
|
package/dist/utils/strings.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { findLastIndex } from "./arrays";
|
|
1
2
|
import { StackAssertionError } from "./errors";
|
|
2
3
|
import { filterUndefined } from "./objects";
|
|
3
4
|
export function typedToLowercase(s) {
|
|
@@ -42,7 +43,7 @@ export function trimEmptyLinesStart(s) {
|
|
|
42
43
|
*/
|
|
43
44
|
export function trimEmptyLinesEnd(s) {
|
|
44
45
|
const lines = s.split("\n");
|
|
45
|
-
const lastNonEmptyLineIndex =
|
|
46
|
+
const lastNonEmptyLineIndex = findLastIndex(lines, (line) => line.trim() !== "");
|
|
46
47
|
return lines.slice(0, lastNonEmptyLineIndex + 1).join("\n");
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
@@ -105,9 +106,13 @@ export function mergeScopeStrings(...scopes) {
|
|
|
105
106
|
return extractScopes(allScope).join(" ");
|
|
106
107
|
}
|
|
107
108
|
export function snakeCaseToCamelCase(snakeCase) {
|
|
109
|
+
if (snakeCase.match(/[A-Z]/))
|
|
110
|
+
return snakeCase; // TODO: this is a hack for fixing the email templates, remove this after v2 migration
|
|
108
111
|
return snakeCase.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
109
112
|
}
|
|
110
113
|
export function camelCaseToSnakeCase(camelCase) {
|
|
114
|
+
if (camelCase.match(/_/))
|
|
115
|
+
return camelCase; // TODO: this is a hack for fixing the email templates, remove this after v2 migration
|
|
111
116
|
return camelCase.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
112
117
|
}
|
|
113
118
|
/**
|
package/dist/utils/uuids.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function generateUuid():
|
|
1
|
+
export declare function generateUuid(): string;
|
package/dist/utils/uuids.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { globalVar } from "./globals";
|
|
2
2
|
export function generateUuid() {
|
|
3
|
-
|
|
3
|
+
// crypto.randomUuid is not supported in all browsers, so this is a polyfill
|
|
4
|
+
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => (+c ^ globalVar.crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16));
|
|
4
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"jose": "^5.2.2",
|
|
37
37
|
"oauth4webapi": "^2.10.3",
|
|
38
38
|
"uuid": "^9.0.1",
|
|
39
|
-
"@stackframe/stack-sc": "2.5.
|
|
39
|
+
"@stackframe/stack-sc": "2.5.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"rimraf": "^5.0.5",
|