@logto/core-kit 2.4.0 → 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.
@@ -0,0 +1,7 @@
1
+ export declare const buildErrorResponse: (error: unknown) => {
2
+ message: string;
3
+ stack: string | undefined;
4
+ } | {
5
+ message: string;
6
+ stack?: undefined;
7
+ };
@@ -0,0 +1,9 @@
1
+ import { types } from 'node:util';
2
+ export const buildErrorResponse = (error) =>
3
+ /**
4
+ * Use `isNativeError` to check if the error is an instance of `Error`.
5
+ * If the error comes from `node:vm` module, then it will not be an instance of `Error` but can be captured by `isNativeError`.
6
+ */
7
+ types.isNativeError(error)
8
+ ? { message: error.message, stack: error.stack }
9
+ : { message: String(error) };
@@ -0,0 +1,2 @@
1
+ export * from './script-execution.js';
2
+ export * from './error-handling.js';
@@ -0,0 +1,2 @@
1
+ export * from './script-execution.js';
2
+ export * from './error-handling.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This function is used to execute a named function in a customized code script in a local
3
+ * virtual machine with the given payload as input.
4
+ *
5
+ * @param script Custom code snippet.
6
+ * @param functionName The name of the function to be executed.
7
+ * @param payload The input payload for the function.
8
+ * @returns The result of the function execution.
9
+ */
10
+ export declare const runScriptFunctionInLocalVm: (script: string, functionName: string, payload: unknown) => Promise<unknown>;
@@ -0,0 +1,30 @@
1
+ import { runInNewContext } from 'node:vm';
2
+ /**
3
+ * This function is used to execute a named function in a customized code script in a local
4
+ * virtual machine with the given payload as input.
5
+ *
6
+ * @param script Custom code snippet.
7
+ * @param functionName The name of the function to be executed.
8
+ * @param payload The input payload for the function.
9
+ * @returns The result of the function execution.
10
+ */
11
+ export const runScriptFunctionInLocalVm = async (script, functionName, payload) => {
12
+ const globalContext = Object.freeze({
13
+ fetch: async (...args) => fetch(...args),
14
+ });
15
+ const customFunction = runInNewContext(script + `;${functionName};`, globalContext);
16
+ if (typeof customFunction !== 'function') {
17
+ throw new TypeError(`The script does not have a function named \`${functionName}\``);
18
+ }
19
+ /**
20
+ * We can not use top-level await in `vm`, use the following implementation instead.
21
+ *
22
+ * Ref:
23
+ * 1. https://github.com/nodejs/node/issues/40898
24
+ * 2. https://github.com/n-riesco/ijavascript/issues/173#issuecomment-693924098
25
+ */
26
+ const result = await runInNewContext('(async () => customFunction(payload))();', Object.freeze({ customFunction, payload }),
27
+ // Limit the execution time to 3 seconds, throws error if the script takes too long to execute.
28
+ { timeout: 3000 });
29
+ return result;
30
+ };
@@ -1,7 +1,7 @@
1
- export type TenantMetadata = {
1
+ export type TenantDatabaseMetadata = {
2
2
  id: string;
3
3
  parentRole: string;
4
4
  role: string;
5
5
  password: string;
6
6
  };
7
- export declare const createTenantMetadata: (databaseName: string, tenantId?: string) => TenantMetadata;
7
+ export declare const createTenantDatabaseMetadata: (databaseName: string, tenantId?: string) => TenantDatabaseMetadata;
@@ -1,7 +1,7 @@
1
1
  import { generateStandardId } from '@logto/shared/universal';
2
2
  // Use lowercase letters for tenant IDs to improve compatibility
3
3
  const generateTenantId = () => generateStandardId(6);
4
- export const createTenantMetadata = (databaseName, tenantId = generateTenantId()) => {
4
+ export const createTenantDatabaseMetadata = (databaseName, tenantId = generateTenantId()) => {
5
5
  const parentRole = `logto_tenant_${databaseName}`;
6
6
  const role = `logto_tenant_${databaseName}_${tenantId}`;
7
7
  const password = generateStandardId(32);
package/lib/openid.d.ts CHANGED
@@ -12,7 +12,7 @@ export declare enum ReservedResource {
12
12
  */
13
13
  Organization = "urn:logto:resource:organizations"
14
14
  }
15
- export type UserClaim = 'name' | 'given_name' | 'family_name' | 'middle_name' | 'nickname' | 'preferred_username' | 'profile' | 'picture' | 'website' | 'email' | 'email_verified' | 'gender' | 'birthdate' | 'zoneinfo' | 'locale' | 'phone_number' | 'phone_number_verified' | 'address' | 'updated_at' | 'username' | 'roles' | 'organizations' | 'organization_data' | 'organization_roles' | 'custom_data' | 'identities' | 'created_at';
15
+ export type UserClaim = 'name' | 'given_name' | 'family_name' | 'middle_name' | 'nickname' | 'preferred_username' | 'profile' | 'picture' | 'website' | 'email' | 'email_verified' | 'gender' | 'birthdate' | 'zoneinfo' | 'locale' | 'phone_number' | 'phone_number_verified' | 'address' | 'updated_at' | 'username' | 'roles' | 'organizations' | 'organization_data' | 'organization_roles' | 'custom_data' | 'identities' | 'sso_identities' | 'created_at';
16
16
  /**
17
17
  * Scopes for ID Token and Userinfo Endpoint.
18
18
  */
@@ -48,7 +48,7 @@ export declare enum UserScope {
48
48
  */
49
49
  CustomData = "custom_data",
50
50
  /**
51
- * Scope for user's social identity details.
51
+ * Scope for user's social and SSO identity details.
52
52
  *
53
53
  * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
54
54
  */
package/lib/openid.js CHANGED
@@ -50,7 +50,7 @@ export var UserScope;
50
50
  */
51
51
  UserScope["CustomData"] = "custom_data";
52
52
  /**
53
- * Scope for user's social identity details.
53
+ * Scope for user's social and SSO identity details.
54
54
  *
55
55
  * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
56
56
  */
@@ -121,7 +121,7 @@ export const userinfoClaims = Object.freeze({
121
121
  [UserScope.Organizations]: ['organization_data'],
122
122
  [UserScope.OrganizationRoles]: [],
123
123
  [UserScope.CustomData]: ['custom_data'],
124
- [UserScope.Identities]: ['identities'],
124
+ [UserScope.Identities]: ['identities', 'sso_identities'],
125
125
  });
126
126
  export const userClaims = Object.freeze(
127
127
  // Hard to infer type directly, use `as` for a workaround.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/core-kit",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
5
5
  "homepage": "https://github.com/logto-io/toolkit#readme",
6
6
  "repository": {
@@ -17,7 +17,11 @@
17
17
  "import": "./lib/index.js"
18
18
  },
19
19
  "./declaration": "./declaration/index.ts",
20
- "./scss/*": "./scss/*.scss"
20
+ "./scss/*": "./scss/*.scss",
21
+ "./custom-jwt": {
22
+ "node": "./lib/custom-jwt/index.js",
23
+ "types": "./lib/custom-jwt/index.d.ts"
24
+ }
21
25
  },
22
26
  "types": "./lib/index.d.ts",
23
27
  "files": [
@@ -31,21 +35,22 @@
31
35
  "dependencies": {
32
36
  "@logto/language-kit": "^1.1.0",
33
37
  "@logto/shared": "^3.1.0",
34
- "@silverhand/essentials": "^2.9.0",
38
+ "@silverhand/essentials": "^2.9.1",
35
39
  "color": "^4.2.3"
36
40
  },
37
41
  "optionalDependencies": {
38
42
  "zod": "^3.22.4"
39
43
  },
40
44
  "devDependencies": {
41
- "@silverhand/eslint-config": "5.0.0",
42
- "@silverhand/ts-config": "5.0.0",
43
- "@silverhand/ts-config-react": "5.0.0",
45
+ "@silverhand/eslint-config": "6.0.1",
46
+ "@silverhand/eslint-config-react": "6.0.2",
47
+ "@silverhand/ts-config": "6.0.0",
48
+ "@silverhand/ts-config-react": "6.0.0",
44
49
  "@types/color": "^3.0.3",
45
50
  "@types/node": "^20.9.5",
46
51
  "@types/react": "^18.0.31",
47
52
  "@vitest/coverage-v8": "^1.4.0",
48
- "eslint": "^8.44.0",
53
+ "eslint": "^8.56.0",
49
54
  "lint-staged": "^15.0.0",
50
55
  "postcss": "^8.4.31",
51
56
  "prettier": "^3.0.0",