@stackframe/stack-shared 1.0.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/LICENSE +7 -0
- package/dist/helpers/fetch-token.d.ts +1 -0
- package/dist/helpers/fetch-token.d.ts.map +1 -0
- package/dist/helpers/fetch-token.js +1 -0
- package/dist/helpers/password.d.ts +1 -0
- package/dist/helpers/password.d.ts.map +1 -0
- package/dist/helpers/password.js +33 -0
- package/dist/hooks/use-async-external-store.d.ts +4 -0
- package/dist/hooks/use-async-external-store.d.ts.map +1 -0
- package/dist/hooks/use-async-external-store.js +20 -0
- package/dist/hooks/use-strict-memo.d.ts +6 -0
- package/dist/hooks/use-strict-memo.d.ts.map +1 -0
- package/dist/hooks/use-strict-memo.js +64 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/interface/adminInterface.d.ts +88 -0
- package/dist/interface/adminInterface.d.ts.map +1 -0
- package/dist/interface/adminInterface.js +109 -0
- package/dist/interface/clientInterface.d.ts +134 -0
- package/dist/interface/clientInterface.d.ts.map +1 -0
- package/dist/interface/clientInterface.js +444 -0
- package/dist/interface/serverInterface.d.ts +33 -0
- package/dist/interface/serverInterface.d.ts.map +1 -0
- package/dist/interface/serverInterface.js +70 -0
- package/dist/utils/arrays.d.ts +10 -0
- package/dist/utils/arrays.d.ts.map +1 -0
- package/dist/utils/arrays.js +54 -0
- package/dist/utils/caches.d.ts +76 -0
- package/dist/utils/caches.d.ts.map +1 -0
- package/dist/utils/caches.js +100 -0
- package/dist/utils/crypto.d.ts +1 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +5 -0
- package/dist/utils/dates.d.ts +12 -0
- package/dist/utils/dates.d.ts.map +1 -0
- package/dist/utils/dates.js +57 -0
- package/dist/utils/dom.d.ts +4 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/dom.js +11 -0
- package/dist/utils/env.d.ts +4 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +7 -0
- package/dist/utils/errors.d.ts +184 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +72 -0
- package/dist/utils/html.d.ts +2 -0
- package/dist/utils/html.d.ts.map +1 -0
- package/dist/utils/html.js +12 -0
- package/dist/utils/json.d.ts +10 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +26 -0
- package/dist/utils/jwt.d.ts +3 -0
- package/dist/utils/jwt.d.ts.map +1 -0
- package/dist/utils/jwt.js +16 -0
- package/dist/utils/math.d.ts +4 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +6 -0
- package/dist/utils/numbers.d.ts +2 -0
- package/dist/utils/numbers.d.ts.map +1 -0
- package/dist/utils/numbers.js +26 -0
- package/dist/utils/objects.d.ts +18 -0
- package/dist/utils/objects.d.ts.map +1 -0
- package/dist/utils/objects.js +63 -0
- package/dist/utils/password.d.ts +2 -0
- package/dist/utils/password.d.ts.map +1 -0
- package/dist/utils/password.js +8 -0
- package/dist/utils/promises.d.ts +49 -0
- package/dist/utils/promises.d.ts.map +1 -0
- package/dist/utils/promises.js +145 -0
- package/dist/utils/react.d.ts +12 -0
- package/dist/utils/react.d.ts.map +1 -0
- package/dist/utils/react.js +44 -0
- package/dist/utils/results.d.ts +73 -0
- package/dist/utils/results.d.ts.map +1 -0
- package/dist/utils/results.js +112 -0
- package/dist/utils/stores.d.ts +57 -0
- package/dist/utils/stores.d.ts.map +1 -0
- package/dist/utils/stores.js +122 -0
- package/dist/utils/strings.d.ts +40 -0
- package/dist/utils/strings.d.ts.map +1 -0
- package/dist/utils/strings.js +91 -0
- package/dist/utils/types.d.ts +33 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +61 -0
- package/dist/utils/uuids.d.ts +1 -0
- package/dist/utils/uuids.d.ts.map +1 -0
- package/dist/utils/uuids.js +4 -0
- package/package.json +40 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { AsyncResult } from "./results";
|
|
2
|
+
import { generateUuid } from "./uuids";
|
|
3
|
+
import { rejected, resolved } from "./promises";
|
|
4
|
+
export class AsyncStore {
|
|
5
|
+
_isAvailable;
|
|
6
|
+
_value = undefined;
|
|
7
|
+
_isRejected = false;
|
|
8
|
+
_rejectionError;
|
|
9
|
+
_waitingRejectFunctions = new Map();
|
|
10
|
+
_callbacks = new Map();
|
|
11
|
+
_updateCounter = 0;
|
|
12
|
+
_lastSuccessfulUpdate = -1;
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
if (args.length === 0) {
|
|
15
|
+
this._isAvailable = false;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this._isAvailable = true;
|
|
19
|
+
this._value = args[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
isAvailable() {
|
|
23
|
+
return this._isAvailable;
|
|
24
|
+
}
|
|
25
|
+
isRejected() {
|
|
26
|
+
return this._isRejected;
|
|
27
|
+
}
|
|
28
|
+
get() {
|
|
29
|
+
if (this.isRejected()) {
|
|
30
|
+
return AsyncResult.error(this._rejectionError);
|
|
31
|
+
}
|
|
32
|
+
else if (this.isAvailable()) {
|
|
33
|
+
return AsyncResult.ok(this._value);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return AsyncResult.pending();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
getOrWait() {
|
|
40
|
+
const uuid = generateUuid();
|
|
41
|
+
if (this.isRejected()) {
|
|
42
|
+
return rejected(this._rejectionError);
|
|
43
|
+
}
|
|
44
|
+
else if (this.isAvailable()) {
|
|
45
|
+
return resolved(this._value);
|
|
46
|
+
}
|
|
47
|
+
const promise = new Promise((resolve, reject) => {
|
|
48
|
+
this.onceChange((value) => {
|
|
49
|
+
resolve(value);
|
|
50
|
+
});
|
|
51
|
+
this._waitingRejectFunctions.set(uuid, reject);
|
|
52
|
+
});
|
|
53
|
+
const withFinally = promise.finally(() => {
|
|
54
|
+
this._waitingRejectFunctions.delete(uuid);
|
|
55
|
+
});
|
|
56
|
+
return Object.assign(withFinally, {
|
|
57
|
+
status: "pending",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
_setIfLatest(value, curCounter) {
|
|
61
|
+
if (!this._isAvailable || this._isRejected || this._value !== value) {
|
|
62
|
+
const oldValue = this._value;
|
|
63
|
+
if (curCounter > this._lastSuccessfulUpdate) {
|
|
64
|
+
this._lastSuccessfulUpdate = curCounter;
|
|
65
|
+
this._isAvailable = true;
|
|
66
|
+
this._isRejected = false;
|
|
67
|
+
this._value = value;
|
|
68
|
+
this._callbacks.forEach((callback) => callback(value, oldValue));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
set(value) {
|
|
76
|
+
this._setIfLatest(value, ++this._updateCounter);
|
|
77
|
+
}
|
|
78
|
+
update(updater) {
|
|
79
|
+
const value = updater(this._value);
|
|
80
|
+
this.set(value);
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
async setAsync(promise) {
|
|
84
|
+
const curCounter = ++this._updateCounter;
|
|
85
|
+
const value = await promise;
|
|
86
|
+
return this._setIfLatest(value, curCounter);
|
|
87
|
+
}
|
|
88
|
+
setUnavailable() {
|
|
89
|
+
this._isAvailable = false;
|
|
90
|
+
this._isRejected = false;
|
|
91
|
+
this._value = undefined;
|
|
92
|
+
}
|
|
93
|
+
setRejected(error) {
|
|
94
|
+
this._isRejected = true;
|
|
95
|
+
this._value = undefined;
|
|
96
|
+
this._rejectionError = error;
|
|
97
|
+
this._waitingRejectFunctions.forEach((reject) => reject(error));
|
|
98
|
+
}
|
|
99
|
+
map(mapper) {
|
|
100
|
+
const store = new AsyncStore();
|
|
101
|
+
this.onChange((value) => {
|
|
102
|
+
store.set(mapper(value));
|
|
103
|
+
});
|
|
104
|
+
return store;
|
|
105
|
+
}
|
|
106
|
+
onChange(callback) {
|
|
107
|
+
const uuid = generateUuid();
|
|
108
|
+
this._callbacks.set(uuid, callback);
|
|
109
|
+
return {
|
|
110
|
+
unsubscribe: () => {
|
|
111
|
+
this._callbacks.delete(uuid);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
onceChange(callback) {
|
|
116
|
+
const { unsubscribe } = this.onChange((...args) => {
|
|
117
|
+
unsubscribe();
|
|
118
|
+
callback(...args);
|
|
119
|
+
});
|
|
120
|
+
return { unsubscribe };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare function typedToLowercase<S extends string>(s: S): Lowercase<S>;
|
|
2
|
+
export declare function typedToUppercase<S extends string>(s: S): Uppercase<S>;
|
|
3
|
+
/**
|
|
4
|
+
* Returns all whitespace character at the start of the string.
|
|
5
|
+
*
|
|
6
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getWhitespacePrefix(s: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns all whitespace character at the end of the string.
|
|
11
|
+
*
|
|
12
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWhitespaceSuffix(s: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a string with all empty or whitespace-only lines at the start removed.
|
|
17
|
+
*
|
|
18
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function trimEmptyLinesStart(s: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a string with all empty or whitespace-only lines at the end removed.
|
|
23
|
+
*
|
|
24
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function trimEmptyLinesEnd(s: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a string with all empty or whitespace-only lines trimmed at the start and end.
|
|
29
|
+
*
|
|
30
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function trimLines(s: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* A template literal tag that returns the same string as the template literal without a tag.
|
|
35
|
+
*
|
|
36
|
+
* Useful for implementing your own template literal tags.
|
|
37
|
+
*/
|
|
38
|
+
export declare function templateIdentity(strings: TemplateStringsArray | readonly string[], ...values: any[]): string;
|
|
39
|
+
export declare function deindent(code: string): string;
|
|
40
|
+
export declare function deindent(strings: TemplateStringsArray | readonly string[], ...values: any[]): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.tsx"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAErE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAErE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAIrD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAK5G;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;AAC/C,wBAAgB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export function typedToLowercase(s) {
|
|
2
|
+
return s.toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
export function typedToUppercase(s) {
|
|
5
|
+
return s.toUpperCase();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns all whitespace character at the start of the string.
|
|
9
|
+
*
|
|
10
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
11
|
+
*/
|
|
12
|
+
export function getWhitespacePrefix(s) {
|
|
13
|
+
return s.substring(0, s.length - s.trimStart().length);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns all whitespace character at the end of the string.
|
|
17
|
+
*
|
|
18
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
19
|
+
*/
|
|
20
|
+
export function getWhitespaceSuffix(s) {
|
|
21
|
+
return s.substring(s.trimEnd().length);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns a string with all empty or whitespace-only lines at the start removed.
|
|
25
|
+
*
|
|
26
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
27
|
+
*/
|
|
28
|
+
export function trimEmptyLinesStart(s) {
|
|
29
|
+
const lines = s.split("\n");
|
|
30
|
+
const firstNonEmptyLineIndex = lines.findIndex((line) => line.trim() !== "");
|
|
31
|
+
return lines.slice(firstNonEmptyLineIndex).join("\n");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns a string with all empty or whitespace-only lines at the end removed.
|
|
35
|
+
*
|
|
36
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
37
|
+
*/
|
|
38
|
+
export function trimEmptyLinesEnd(s) {
|
|
39
|
+
const lines = s.split("\n");
|
|
40
|
+
const lastNonEmptyLineIndex = lines.findLastIndex((line) => line.trim() !== "");
|
|
41
|
+
return lines.slice(0, lastNonEmptyLineIndex + 1).join("\n");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns a string with all empty or whitespace-only lines trimmed at the start and end.
|
|
45
|
+
*
|
|
46
|
+
* Uses the same definition for whitespace as `String.prototype.trim()`.
|
|
47
|
+
*/
|
|
48
|
+
export function trimLines(s) {
|
|
49
|
+
return trimEmptyLinesEnd(trimEmptyLinesStart(s));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A template literal tag that returns the same string as the template literal without a tag.
|
|
53
|
+
*
|
|
54
|
+
* Useful for implementing your own template literal tags.
|
|
55
|
+
*/
|
|
56
|
+
export function templateIdentity(strings, ...values) {
|
|
57
|
+
if (strings.length === 0)
|
|
58
|
+
return "";
|
|
59
|
+
if (values.length !== strings.length - 1)
|
|
60
|
+
throw new Error("Invalid number of values; must be one less than strings");
|
|
61
|
+
return strings.slice(1).reduce((result, string, i) => `${result}${values[i] ?? "n/a"}${string}`, strings[0]);
|
|
62
|
+
}
|
|
63
|
+
export function deindent(strings, ...values) {
|
|
64
|
+
if (typeof strings === "string")
|
|
65
|
+
return deindent([strings]);
|
|
66
|
+
if (strings.length === 0)
|
|
67
|
+
return "";
|
|
68
|
+
if (values.length !== strings.length - 1)
|
|
69
|
+
throw new Error("Invalid number of values; must be one less than strings");
|
|
70
|
+
const trimmedStrings = [...strings];
|
|
71
|
+
trimmedStrings[0] = trimEmptyLinesStart(trimmedStrings[0]);
|
|
72
|
+
trimmedStrings[trimmedStrings.length - 1] = trimEmptyLinesEnd(trimmedStrings[trimmedStrings.length - 1]);
|
|
73
|
+
const indentation = trimmedStrings
|
|
74
|
+
.join("${SOME_VALUE}")
|
|
75
|
+
.split("\n")
|
|
76
|
+
.filter((line) => line.trim() !== "")
|
|
77
|
+
.map((line) => getWhitespacePrefix(line).length)
|
|
78
|
+
.reduce((min, current) => Math.min(min, current), Infinity);
|
|
79
|
+
const deindentedStrings = trimmedStrings
|
|
80
|
+
.map((string, stringIndex) => {
|
|
81
|
+
return string
|
|
82
|
+
.split("\n")
|
|
83
|
+
.map((line, lineIndex) => stringIndex !== 0 && lineIndex === 0 ? line : line.substring(indentation))
|
|
84
|
+
.join("\n");
|
|
85
|
+
});
|
|
86
|
+
const indentedValues = values.map((value, i) => {
|
|
87
|
+
const firstLineIndentation = getWhitespacePrefix(deindentedStrings[i].split("\n").at(-1));
|
|
88
|
+
return `${value}`.replaceAll("\n", `\n${firstLineIndentation}`);
|
|
89
|
+
});
|
|
90
|
+
return templateIdentity(deindentedStrings, ...indentedValues);
|
|
91
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { StatusError } from "./errors";
|
|
2
|
+
export type ReadonlyJson = null | boolean | number | string | readonly ReadonlyJson[] | {
|
|
3
|
+
readonly [key: string]: ReadonlyJson;
|
|
4
|
+
};
|
|
5
|
+
export declare const AccessTokenExpiredErrorCode = "ACCESS_TOKEN_EXPIRED";
|
|
6
|
+
export declare const GrantInvalidErrorCode = "GRANT_INVALID";
|
|
7
|
+
export declare const UserAlreadyExistErrorCode = "USER_ALREADY_EXIST";
|
|
8
|
+
export declare const UserNotExistErrorCode = "USER_NOT_EXIST";
|
|
9
|
+
export declare const UserNotVerifiedErrorCode = "USER_NOT_VERIFIED";
|
|
10
|
+
export declare const EmailPasswordMissMatchErrorCode = "EMAIL_PASSWORD_MISS_MATCH";
|
|
11
|
+
export declare const RedirectUrlInvalidErrorCode = "REDIRECT_URL_INVALID";
|
|
12
|
+
export declare const PasswordFormatInvalidErrorCode = "PASSWORD_FORMAT_INVALID";
|
|
13
|
+
export declare const ProjectIdOrKeyInvalidErrorCode = "PROJECT_ID_OR_KEY_INVALID";
|
|
14
|
+
export declare const EmailVerificationLinkInvalidErrorCode = "EMAIL_VERIFICATION_LINK_INVALID";
|
|
15
|
+
export declare const EmailVerificationLinkExpiredErrorCode = "EMAIL_VERIFICATION_LINK_EXPIRED";
|
|
16
|
+
export declare const EmailVerificationLinkUsedErrorCode = "EMAIL_VERIFICATION_LINK_USED";
|
|
17
|
+
export declare const PasswordResetLinkInvalidErrorCode = "PASSWORD_RESET_LINK_INVALID";
|
|
18
|
+
export declare const PasswordResetLinkExpiredErrorCode = "PASSWORD_RESET_LINK_EXPIRED";
|
|
19
|
+
export declare const PasswordResetLinkUsedErrorCode = "PASSWORD_RESET_LINK_USED";
|
|
20
|
+
export type KnownErrorCode = typeof GrantInvalidErrorCode | typeof AccessTokenExpiredErrorCode | typeof UserAlreadyExistErrorCode | typeof UserNotExistErrorCode | typeof UserNotVerifiedErrorCode | typeof EmailPasswordMissMatchErrorCode | typeof RedirectUrlInvalidErrorCode | typeof PasswordFormatInvalidErrorCode | typeof ProjectIdOrKeyInvalidErrorCode | typeof EmailVerificationLinkInvalidErrorCode | typeof EmailVerificationLinkExpiredErrorCode | typeof EmailVerificationLinkUsedErrorCode | typeof PasswordResetLinkInvalidErrorCode | typeof PasswordResetLinkExpiredErrorCode | typeof PasswordResetLinkUsedErrorCode;
|
|
21
|
+
export declare const KnownErrorCodes: string[];
|
|
22
|
+
export type SignUpErrorCode = typeof UserAlreadyExistErrorCode;
|
|
23
|
+
export declare const SignUpErrorCodes: string[];
|
|
24
|
+
export type SignInErrorCode = typeof EmailPasswordMissMatchErrorCode | typeof UserNotExistErrorCode;
|
|
25
|
+
export declare const SignInErrorCodes: string[];
|
|
26
|
+
export type EmailVerificationLinkErrorCode = typeof EmailVerificationLinkInvalidErrorCode | typeof EmailVerificationLinkExpiredErrorCode | typeof EmailVerificationLinkUsedErrorCode;
|
|
27
|
+
export declare const EmailVerificationLinkErrorCodes: string[];
|
|
28
|
+
export type PasswordResetLinkErrorCode = typeof PasswordResetLinkInvalidErrorCode | typeof PasswordResetLinkExpiredErrorCode | typeof PasswordResetLinkUsedErrorCode;
|
|
29
|
+
export declare const PasswordResetLinkErrorCodes: string[];
|
|
30
|
+
export declare class KnownError extends StatusError {
|
|
31
|
+
readonly errorCode: KnownErrorCode;
|
|
32
|
+
constructor(errorCode: KnownErrorCode);
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKvC,MAAM,MAAM,YAAY,GACpB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,YAAY,EAAE,GACvB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;CAAE,CAAC;AAE7C,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,MAAM,MAAM,cAAc,GACtB,OAAO,qBAAqB,GAC5B,OAAO,2BAA2B,GAClC,OAAO,yBAAyB,GAChC,OAAO,qBAAqB,GAC5B,OAAO,wBAAwB,GAC/B,OAAO,+BAA+B,GACtC,OAAO,2BAA2B,GAClC,OAAO,8BAA8B,GACrC,OAAO,8BAA8B,GACrC,OAAO,qCAAqC,GAC5C,OAAO,qCAAqC,GAC5C,OAAO,kCAAkC,GACzC,OAAO,iCAAiC,GACxC,OAAO,iCAAiC,GACxC,OAAO,8BAA8B,CAAA;AACzC,eAAO,MAAM,eAAe,UAgB3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,OAAO,yBAAyB,CAAA;AAC9D,eAAO,MAAM,gBAAgB,UAA8B,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG,OAAO,+BAA+B,GAChE,OAAO,qBAAqB,CAAA;AAChC,eAAO,MAAM,gBAAgB,UAG5B,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,OAAO,qCAAqC,GACrF,OAAO,qCAAqC,GAAG,OAAO,kCAAkC,CAAA;AAC5F,eAAO,MAAM,+BAA+B,UAI3C,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,OAAO,iCAAiC,GAC7E,OAAO,iCAAiC,GAAG,OAAO,8BAA8B,CAAA;AACpF,eAAO,MAAM,2BAA2B,UAIvC,CAAC;AAEF,qBAAa,UAAW,SAAQ,WAAW;aACb,SAAS,EAAE,cAAc;gBAAzB,SAAS,EAAE,cAAc;CAatD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateUuid(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuids.d.ts","sourceRoot":"","sources":["../../src/utils/uuids.tsx"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,WAE3B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackframe/stack-shared",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"react": "^18.2.0"
|
|
11
|
+
},
|
|
12
|
+
"peerDependenciesMeta": {
|
|
13
|
+
"react": {
|
|
14
|
+
"optional": true
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"bcrypt": "^5.1.1",
|
|
19
|
+
"jose": "^5.2.2",
|
|
20
|
+
"oauth4webapi": "^2.10.3",
|
|
21
|
+
"uuid": "^9.0.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/bcrypt": "^5.0.2",
|
|
25
|
+
"@types/react": "^18.2.60",
|
|
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
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "pnpm clean && tsc",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"clean": "rimraf dist",
|
|
37
|
+
"dev": "tsc -w --preserveWatchOutput --declarationMap",
|
|
38
|
+
"lint": "eslint --ext .tsx,.ts ."
|
|
39
|
+
}
|
|
40
|
+
}
|