@stackframe/stack-shared 2.4.28 → 2.5.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/CHANGELOG.md +10 -0
- package/dist/known-errors.d.ts +0 -3
- package/dist/known-errors.js +0 -9
- package/dist/utils/jwt.js +3 -3
- package/dist/utils/strings.d.ts +1 -0
- package/dist/utils/strings.js +3 -0
- package/dist/utils/yup.d.ts +1 -0
- package/dist/utils/yup.js +11 -0
- package/package.json +2 -2
- package/dist/hooks/use-trigger.d.ts +0 -1
- package/dist/hooks/use-trigger.js +0 -10
package/CHANGELOG.md
CHANGED
package/dist/known-errors.d.ts
CHANGED
|
@@ -236,9 +236,6 @@ export declare const KnownErrors: {
|
|
|
236
236
|
PermissionScopeMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"PERMISSION_SCOPE_MISMATCH">, [permissionId: string, permissionScope: PermissionDefinitionScopeJson, testScope: PermissionDefinitionScopeJson]> & {
|
|
237
237
|
errorCode: "PERMISSION_SCOPE_MISMATCH";
|
|
238
238
|
};
|
|
239
|
-
UserNotInTeam: KnownErrorConstructor<KnownError & KnownErrorBrand<"USER_NOT_IN_TEAM">, [userId: string, teamId: string]> & {
|
|
240
|
-
errorCode: "USER_NOT_IN_TEAM";
|
|
241
|
-
};
|
|
242
239
|
TeamNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"TEAM_NOT_FOUND">, [teamId: string]> & {
|
|
243
240
|
errorCode: "TEAM_NOT_FOUND";
|
|
244
241
|
};
|
package/dist/known-errors.js
CHANGED
|
@@ -332,14 +332,6 @@ const PermissionScopeMismatch = createKnownErrorConstructor(KnownError, "PERMISS
|
|
|
332
332
|
},
|
|
333
333
|
];
|
|
334
334
|
}, (json) => [json.details.permissionId, json.details.permissionScope, json.details.testScope]);
|
|
335
|
-
const UserNotInTeam = createKnownErrorConstructor(KnownError, "USER_NOT_IN_TEAM", (userId, teamId) => [
|
|
336
|
-
400,
|
|
337
|
-
`User ${userId} is not in team ${teamId}.`,
|
|
338
|
-
{
|
|
339
|
-
userId,
|
|
340
|
-
teamId,
|
|
341
|
-
},
|
|
342
|
-
], (json) => [json.details.userId, json.details.teamId]);
|
|
343
335
|
const TeamNotFound = createKnownErrorConstructor(KnownError, "TEAM_NOT_FOUND", (teamId) => [
|
|
344
336
|
404,
|
|
345
337
|
`Team ${teamId} not found.`,
|
|
@@ -444,7 +436,6 @@ export const KnownErrors = {
|
|
|
444
436
|
EmailAlreadyVerified,
|
|
445
437
|
PermissionNotFound,
|
|
446
438
|
PermissionScopeMismatch,
|
|
447
|
-
UserNotInTeam,
|
|
448
439
|
TeamNotFound,
|
|
449
440
|
EmailTemplateAlreadyExists,
|
|
450
441
|
OAuthConnectionNotConnectedToUser,
|
package/dist/utils/jwt.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as jose from "jose";
|
|
2
2
|
import { getEnvVariable } from "./env";
|
|
3
|
-
const
|
|
3
|
+
const STACK_SERVER_SECRET = jose.base64url.decode(getEnvVariable("STACK_SERVER_SECRET"));
|
|
4
4
|
export async function encryptJWT(payload, expirationTime = "5m") {
|
|
5
5
|
return await new jose.EncryptJWT(payload)
|
|
6
6
|
.setProtectedHeader({ alg: "dir", enc: "A128CBC-HS256" })
|
|
7
7
|
.setIssuedAt()
|
|
8
8
|
.setExpirationTime(expirationTime)
|
|
9
|
-
.encrypt(
|
|
9
|
+
.encrypt(STACK_SERVER_SECRET);
|
|
10
10
|
}
|
|
11
11
|
export async function decryptJWT(jwt) {
|
|
12
12
|
if (!jwt) {
|
|
13
13
|
throw new Error("Provided JWT is empty");
|
|
14
14
|
}
|
|
15
|
-
return (await jose.jwtDecrypt(jwt,
|
|
15
|
+
return (await jose.jwtDecrypt(jwt, STACK_SERVER_SECRET)).payload;
|
|
16
16
|
}
|
package/dist/utils/strings.d.ts
CHANGED
|
@@ -60,3 +60,4 @@ export type NicifyOptions = {
|
|
|
60
60
|
overrides: (...args: Parameters<typeof nicify>) => ["result", string] | ["replace", unknown] | null;
|
|
61
61
|
};
|
|
62
62
|
export declare function nicify(value: unknown, options?: Partial<NicifyOptions>): string;
|
|
63
|
+
export declare function replaceAll(input: string, searchValue: string, replaceValue: string): string;
|
package/dist/utils/strings.js
CHANGED
|
@@ -233,6 +233,9 @@ export function nicify(value, options = {}) {
|
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
+
export function replaceAll(input, searchValue, replaceValue) {
|
|
237
|
+
return input.split(searchValue).join(replaceValue);
|
|
238
|
+
}
|
|
236
239
|
function nicifyPropertyString(str) {
|
|
237
240
|
if (/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(str))
|
|
238
241
|
return str;
|
package/dist/utils/yup.d.ts
CHANGED
package/dist/utils/yup.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import * as yup from "yup";
|
|
2
2
|
export const yupJson = yup.mixed().nullable().defined().transform((value) => JSON.parse(JSON.stringify(value)));
|
|
3
|
+
export const yupJsonValidator = yup.string().test("json", "Invalid JSON format", (value) => {
|
|
4
|
+
if (!value)
|
|
5
|
+
return true;
|
|
6
|
+
try {
|
|
7
|
+
JSON.parse(value);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackframe/stack-shared",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
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.
|
|
39
|
+
"@stackframe/stack-sc": "2.5.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"rimraf": "^5.0.5",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useTrigger(callback: () => void): () => void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export function useTrigger(callback) {
|
|
3
|
-
const [hasTriggered, setHasTriggered] = React.useState(false);
|
|
4
|
-
React.useEffect(() => {
|
|
5
|
-
if (hasTriggered) {
|
|
6
|
-
callback();
|
|
7
|
-
}
|
|
8
|
-
}, [hasTriggered]);
|
|
9
|
-
return () => setHasTriggered(true);
|
|
10
|
-
}
|