@logto/core-kit 1.0.0-beta.30 → 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 CHANGED
@@ -1,3 +1,9 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ * All content that resides under the "packages/cloud" directory of this repository, if that directory exists, is licensed under the license defined in "packages/cloud/LICENSE" (Elastic-2.0).
4
+ * All third party components incorporated into this software are licensed under the original license provided by the owner of the applicable component.
5
+ * Content outside of the above mentioned directories or restrictions above is available under the "MPL-2.0" license as defined below.
6
+
1
7
  Mozilla Public License Version 2.0
2
8
  ==================================
3
9
 
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './utilities/index.js';
1
+ export * from './utils/index.js';
2
2
  export * from './regex.js';
3
3
  export * from './scope.js';
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './utilities/index.js';
1
+ export * from './utils/index.js';
2
2
  export * from './regex.js';
3
3
  export * from './scope.js';
package/lib/regex.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export declare const emailRegEx: RegExp;
2
2
  export declare const phoneRegEx: RegExp;
3
+ export declare const phoneInputRegEx: RegExp;
3
4
  export declare const usernameRegEx: RegExp;
4
- export declare const passwordRegEx: RegExp;
5
5
  export declare const webRedirectUriProtocolRegEx: RegExp;
6
6
  export declare const mobileUriSchemeProtocolRegEx: RegExp;
7
7
  export declare const hexColorRegEx: RegExp;
8
8
  export declare const dateRegex: RegExp;
9
+ export declare const noSpaceRegEx: RegExp;
10
+ export declare const passwordRegEx: RegExp;
package/lib/regex.js CHANGED
@@ -1,8 +1,14 @@
1
1
  export const emailRegEx = /^\S+@\S+\.\S+$/;
2
2
  export const phoneRegEx = /^\d+$/;
3
+ export const phoneInputRegEx = /^\+?[\d-( )]+$/;
3
4
  export const usernameRegEx = /^[A-Z_a-z]\w*$/;
4
- export const passwordRegEx = /^.{6,}$/;
5
5
  export const webRedirectUriProtocolRegEx = /^https?:$/;
6
6
  export const mobileUriSchemeProtocolRegEx = /^[a-z][\d_a-z]*(\.[\d_a-z]+)+:$/;
7
7
  export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
8
8
  export const dateRegex = /^\d{4}(-\d{2}){2}/;
9
+ export const noSpaceRegEx = /^\S+$/;
10
+ const atLeastOneDigitAndOneLetters = /(?=.*\d)(?=.*[A-Za-z])/;
11
+ const atLeastOneDigitAndOneSpecialChar = /(?=.*\d)(?=.*[!"#$%&'()*+,./:;<=>?@[\]^_`{|}~-])/;
12
+ const atLeastOneLetterAndOneSpecialChar = /(?=.*[A-Za-z])(?=.*[!"#$%&'()*+,./:;<=>?@[\]^_`{|}~-])/;
13
+ const allowedChars = /[\w!"#$%&'()*+,./:;<=>?@[\]^`{|}~-]{8,}/;
14
+ export const passwordRegEx = new RegExp(`^(${atLeastOneDigitAndOneLetters.source}|${atLeastOneDigitAndOneSpecialChar.source}|${atLeastOneLetterAndOneSpecialChar.source})${allowedChars.source}$`);
package/lib/scope.d.ts CHANGED
@@ -2,7 +2,7 @@ export declare enum ReservedScope {
2
2
  OpenId = "openid",
3
3
  OfflineAccess = "offline_access"
4
4
  }
5
- export type UserClaim = 'name' | 'picture' | 'username' | 'role_names' | 'email' | 'email_verified' | 'phone_number' | 'phone_number_verified' | 'custom_data' | 'identities';
5
+ export type UserClaim = 'name' | 'picture' | 'username' | 'email' | 'email_verified' | 'phone_number' | 'phone_number_verified' | 'custom_data' | 'identities';
6
6
  /**
7
7
  * Scopes for ID Token and Userinfo Endpoint.
8
8
  */
package/lib/scope.js CHANGED
@@ -43,7 +43,7 @@ export var UserScope;
43
43
  * Mapped claims that ID Token includes.
44
44
  */
45
45
  export const idTokenClaims = Object.freeze({
46
- [UserScope.Profile]: ['name', 'picture', 'username', 'role_names'],
46
+ [UserScope.Profile]: ['name', 'picture', 'username'],
47
47
  [UserScope.Email]: ['email', 'email_verified'],
48
48
  [UserScope.Phone]: ['phone_number', 'phone_number_verified'],
49
49
  [UserScope.CustomData]: [],
@@ -1,4 +1,3 @@
1
1
  export * from './color.js';
2
2
  export * from './id.js';
3
- export * from './zod.js';
4
3
  export * from './url.js';
@@ -1,4 +1,3 @@
1
1
  export * from './color.js';
2
2
  export * from './id.js';
3
- export * from './zod.js';
4
3
  export * from './url.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/core-kit",
3
- "version": "1.0.0-beta.30",
3
+ "version": "1.0.0",
4
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
5
5
  "homepage": "https://github.com/logto-io/toolkit#readme",
6
6
  "repository": {
@@ -9,11 +9,11 @@
9
9
  },
10
10
  "license": "MPL-2.0",
11
11
  "type": "module",
12
- "main": "./lib/index.cjs",
12
+ "main": "./lib/index.js",
13
13
  "exports": {
14
+ "default": "./lib/index.js",
14
15
  "types": "./lib/index.d.ts",
15
- "import": "./lib/index.js",
16
- "require": "./lib/index.cjs"
16
+ "import": "./lib/index.js"
17
17
  },
18
18
  "types": "./lib/index.d.ts",
19
19
  "files": [
@@ -22,35 +22,32 @@
22
22
  "scss"
23
23
  ],
24
24
  "engines": {
25
- "node": "^16.13.0 || ^18.12.0"
25
+ "node": "^18.12.0"
26
26
  },
27
27
  "dependencies": {
28
28
  "color": "^4.2.3",
29
29
  "nanoid": "^4.0.0",
30
- "@logto/language-kit": "1.0.0-beta.30"
30
+ "@logto/language-kit": "1.0.0"
31
31
  },
32
32
  "optionalDependencies": {
33
33
  "zod": "^3.20.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@jest/types": "^29.0.3",
37
- "@rollup/plugin-typescript": "^10.0.1",
38
- "@silverhand/eslint-config": "1.3.0",
39
- "@silverhand/eslint-config-react": "1.3.0",
40
- "@silverhand/essentials": "2.1.0",
41
- "@silverhand/ts-config": "1.2.1",
37
+ "@silverhand/eslint-config": "2.0.1",
38
+ "@silverhand/eslint-config-react": "2.0.1",
39
+ "@silverhand/essentials": "^2.5.0",
40
+ "@silverhand/ts-config": "2.0.3",
42
41
  "@types/color": "^3.0.3",
43
- "@types/jest": "^29.0.3",
44
- "@types/node": "^16.3.1",
42
+ "@types/jest": "^29.4.0",
43
+ "@types/node": "^18.11.18",
45
44
  "@types/react": "^18.0.20",
46
- "eslint": "^8.21.0",
47
- "jest": "^29.0.3",
48
- "jest-matcher-specific-error": "^1.0.0",
45
+ "eslint": "^8.34.0",
46
+ "jest": "^29.5.0",
49
47
  "lint-staged": "^13.0.0",
50
48
  "postcss": "^8.4.6",
51
- "prettier": "^2.8.1",
52
- "rollup": "^3.6.0",
53
- "stylelint": "^14.9.1",
49
+ "prettier": "^2.8.2",
50
+ "stylelint": "^15.0.0",
54
51
  "tslib": "^2.4.1",
55
52
  "typescript": "^4.9.4"
56
53
  },
@@ -67,7 +64,7 @@
67
64
  "scripts": {
68
65
  "precommit": "lint-staged",
69
66
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
70
- "build": "rm -rf lib/ && rollup -c && tsc -p tsconfig.build.json",
67
+ "build": "rm -rf lib/ && tsc -p tsconfig.build.json",
71
68
  "build:test": "pnpm build -p tsconfig.test.json --sourcemap",
72
69
  "lint": "eslint --ext .ts src",
73
70
  "lint:report": "pnpm lint --format json --output-file report.json",
@@ -108,6 +108,7 @@
108
108
  --color-on-error: var(--color-all-100);
109
109
  --color-error-container: var(--color-error-90);
110
110
  --color-on-error-container: var(--color-error-10);
111
+ --color-alert-container: var(--color-alert-99);
111
112
  --color-background: var(--color-neutral-99);
112
113
  --color-on-background: var(--color-neutral-10);
113
114
  --color-surface: var(--color-neutral-99);
@@ -280,6 +281,7 @@
280
281
  --color-on-error: var(--color-all-0);
281
282
  --color-error-container: var(--color-error-90);
282
283
  --color-on-error-container: var(--color-error-30);
284
+ --color-alert-container: var(--color-alert-90);
283
285
  --color-background: var(--color-neutral-99);
284
286
  --color-on-background: var(--color-neutral-10);
285
287
  --color-surface: var(--color-neutral-99);
package/scss/_fonts.scss CHANGED
@@ -12,21 +12,18 @@ $font-family:
12
12
 
13
13
  :root {
14
14
  --font-family: #{$font-family};
15
- --font-headline-large: 600 32px/40px #{$font-family};
16
- --font-headline-medium: 600 28px/36px #{$font-family};
17
- --font-headline-small: 600 24px/32px #{$font-family};
18
- --font-title-large: 600 20px/28px #{$font-family};
19
- --font-title-medium: 600 16px/24px #{$font-family};
20
- --font-title-small: 600 14px/20px #{$font-family};
21
- --font-label-large: 500 14px/20px #{$font-family};
22
- --font-label-medium: 500 12px/16px #{$font-family};
23
- --font-label-small: 500 11px/16px #{$font-family};
24
- --font-body-large: 400 16px/24px #{$font-family};
25
- --font-body-medium: 400 14px/20px #{$font-family};
26
- --font-body-small: 400 12px/16px #{$font-family};
27
- --font-subhead-1: 500 16px/24px #{$font-family};
28
- --font-subhead-2: 500 14px/20px #{$font-family};
29
- --font-subhead-cap: 700 12px/16px #{$font-family};
30
- --font-subhead-cap-small: 700 10px/16px #{$font-family};
31
- --font-button: 500 14px/20px #{$font-family};
15
+ --font-headline-1: 600 32px/40px #{$font-family};
16
+ --font-headline-2: 600 28px/36px #{$font-family};
17
+ --font-headline-3: 600 24px/32px #{$font-family};
18
+ --font-title-1: 600 20px/28px #{$font-family};
19
+ --font-title-2: 600 16px/24px #{$font-family};
20
+ --font-title-3: 600 14px/20px #{$font-family};
21
+ --font-label-1: 500 16px/24px #{$font-family};
22
+ --font-label-2: 500 14px/20px #{$font-family};
23
+ --font-label-3: 500 12px/16px #{$font-family};
24
+ --font-body-1: 400 16px/24px #{$font-family};
25
+ --font-body-2: 400 14px/20px #{$font-family};
26
+ --font-body-3: 400 12px/16px #{$font-family};
27
+ --font-section-head-1: 700 12px/16px #{$font-family};
28
+ --font-section-head-2: 700 10px/16px #{$font-family};
32
29
  }
package/lib/index.cjs DELETED
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var color = require('./utilities/color.cjs');
4
- var id = require('./utilities/id.cjs');
5
- var zod = require('./utilities/zod.cjs');
6
- var url = require('./utilities/url.cjs');
7
- var regex = require('./regex.cjs');
8
- var scope = require('./scope.cjs');
9
-
10
-
11
-
12
- exports.absoluteDarken = color.absoluteDarken;
13
- exports.absoluteLighten = color.absoluteLighten;
14
- exports.generateDarkColor = color.generateDarkColor;
15
- exports.buildIdGenerator = id.buildIdGenerator;
16
- exports.generateStandardId = id.generateStandardId;
17
- exports.fallback = zod.fallback;
18
- exports.validateRedirectUrl = url.validateRedirectUrl;
19
- exports.validateUriOrigin = url.validateUriOrigin;
20
- exports.dateRegex = regex.dateRegex;
21
- exports.emailRegEx = regex.emailRegEx;
22
- exports.hexColorRegEx = regex.hexColorRegEx;
23
- exports.mobileUriSchemeProtocolRegEx = regex.mobileUriSchemeProtocolRegEx;
24
- exports.passwordRegEx = regex.passwordRegEx;
25
- exports.phoneRegEx = regex.phoneRegEx;
26
- exports.usernameRegEx = regex.usernameRegEx;
27
- exports.webRedirectUriProtocolRegEx = regex.webRedirectUriProtocolRegEx;
28
- Object.defineProperty(exports, 'ReservedScope', {
29
- enumerable: true,
30
- get: function () { return scope.ReservedScope; }
31
- });
32
- Object.defineProperty(exports, 'UserScope', {
33
- enumerable: true,
34
- get: function () { return scope.UserScope; }
35
- });
36
- exports.idTokenClaims = scope.idTokenClaims;
37
- exports.userClaims = scope.userClaims;
38
- exports.userinfoClaims = scope.userinfoClaims;
package/lib/regex.cjs DELETED
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- const emailRegEx = /^\S+@\S+\.\S+$/;
4
- const phoneRegEx = /^\d+$/;
5
- const usernameRegEx = /^[A-Z_a-z]\w*$/;
6
- const passwordRegEx = /^.{6,}$/;
7
- const webRedirectUriProtocolRegEx = /^https?:$/;
8
- const mobileUriSchemeProtocolRegEx = /^[a-z][\d_a-z]*(\.[\d_a-z]+)+:$/;
9
- const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
10
- const dateRegex = /^\d{4}(-\d{2}){2}/;
11
-
12
- exports.dateRegex = dateRegex;
13
- exports.emailRegEx = emailRegEx;
14
- exports.hexColorRegEx = hexColorRegEx;
15
- exports.mobileUriSchemeProtocolRegEx = mobileUriSchemeProtocolRegEx;
16
- exports.passwordRegEx = passwordRegEx;
17
- exports.phoneRegEx = phoneRegEx;
18
- exports.usernameRegEx = usernameRegEx;
19
- exports.webRedirectUriProtocolRegEx = webRedirectUriProtocolRegEx;
package/lib/scope.cjs DELETED
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- exports.ReservedScope = void 0;
4
- (function (ReservedScope) {
5
- ReservedScope["OpenId"] = "openid";
6
- ReservedScope["OfflineAccess"] = "offline_access";
7
- })(exports.ReservedScope || (exports.ReservedScope = {}));
8
- /**
9
- * Scopes for ID Token and Userinfo Endpoint.
10
- */
11
- exports.UserScope = void 0;
12
- (function (UserScope) {
13
- /**
14
- * Scope for basic user info.
15
- *
16
- * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
17
- */
18
- UserScope["Profile"] = "profile";
19
- /**
20
- * Scope for user email address.
21
- *
22
- * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
23
- */
24
- UserScope["Email"] = "email";
25
- /**
26
- * Scope for user phone number.
27
- *
28
- * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
29
- */
30
- UserScope["Phone"] = "phone";
31
- /**
32
- * Scope for user's custom data.
33
- *
34
- * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
35
- */
36
- UserScope["CustomData"] = "custom_data";
37
- /**
38
- * Scope for user's social identity details.
39
- *
40
- * See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
41
- */
42
- UserScope["Identities"] = "identities";
43
- })(exports.UserScope || (exports.UserScope = {}));
44
- /**
45
- * Mapped claims that ID Token includes.
46
- */
47
- const idTokenClaims = Object.freeze({
48
- [exports.UserScope.Profile]: ['name', 'picture', 'username', 'role_names'],
49
- [exports.UserScope.Email]: ['email', 'email_verified'],
50
- [exports.UserScope.Phone]: ['phone_number', 'phone_number_verified'],
51
- [exports.UserScope.CustomData]: [],
52
- [exports.UserScope.Identities]: [],
53
- });
54
- /**
55
- * Additional claims that Userinfo Endpoint returns.
56
- */
57
- const userinfoClaims = Object.freeze({
58
- [exports.UserScope.Profile]: [],
59
- [exports.UserScope.Email]: [],
60
- [exports.UserScope.Phone]: [],
61
- [exports.UserScope.CustomData]: ['custom_data'],
62
- [exports.UserScope.Identities]: ['identities'],
63
- });
64
- const userClaims = Object.freeze(
65
- // Hard to infer type directly, use `as` for a workaround.
66
- // eslint-disable-next-line no-restricted-syntax
67
- Object.fromEntries(Object.values(exports.UserScope).map((current) => [
68
- current,
69
- [...idTokenClaims[current], ...userinfoClaims[current]],
70
- ])));
71
-
72
- exports.idTokenClaims = idTokenClaims;
73
- exports.userClaims = userClaims;
74
- exports.userinfoClaims = userinfoClaims;
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- var color = require('color');
4
-
5
- // Color hsl lighten/darken takes percentage value only, need to implement absolute value update
6
- const absoluteLighten = (baseColor, delta) => {
7
- const hslArray = baseColor.hsl().round().array();
8
- return color([hslArray[0] ?? 0, hslArray[1] ?? 0, (hslArray[2] ?? 0) + delta], 'hsl');
9
- };
10
- const absoluteDarken = (baseColor, delta) => {
11
- const hslArray = baseColor.hsl().round().array();
12
- return color([hslArray[0] ?? 0, hslArray[1] ?? 0, (hslArray[2] ?? 0) - delta], 'hsl');
13
- };
14
- const generateDarkColor = (lightColor) => absoluteLighten(color(lightColor), 10).hex();
15
-
16
- exports.absoluteDarken = absoluteDarken;
17
- exports.absoluteLighten = absoluteLighten;
18
- exports.generateDarkColor = generateDarkColor;
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var nanoid = require('nanoid');
4
-
5
- const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
6
- const buildIdGenerator = (size) => nanoid.customAlphabet(alphabet, size);
7
- const generateStandardId = buildIdGenerator(21);
8
-
9
- exports.buildIdGenerator = buildIdGenerator;
10
- exports.generateStandardId = generateStandardId;
@@ -1,25 +0,0 @@
1
- 'use strict';
2
-
3
- var regex = require('../regex.cjs');
4
-
5
- const validateRedirectUrl = (url, type) => {
6
- try {
7
- const { protocol } = new URL(url);
8
- const protocolRegEx = type === 'mobile' ? regex.mobileUriSchemeProtocolRegEx : regex.webRedirectUriProtocolRegEx;
9
- return protocolRegEx.test(protocol);
10
- }
11
- catch {
12
- return false;
13
- }
14
- };
15
- const validateUriOrigin = (url) => {
16
- try {
17
- return new URL(url).origin === url;
18
- }
19
- catch {
20
- return false;
21
- }
22
- };
23
-
24
- exports.validateRedirectUrl = validateRedirectUrl;
25
- exports.validateUriOrigin = validateUriOrigin;
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var zod = require('zod');
4
-
5
- /**
6
- * https://github.com/colinhacks/zod/issues/316#issuecomment-850906479
7
- * Create a schema matches anything and returns a value. Use it with `or`:
8
- *
9
- * const schema = zod.number();
10
- * const tolerant = schema.or(fallback(-1));
11
- *
12
- * schema.parse('foo') // => ZodError
13
- * tolerant.parse('foo') // -1
14
- */
15
- function fallback(value) {
16
- return zod.any().transform(() => value);
17
- }
18
-
19
- exports.fallback = fallback;
@@ -1,11 +0,0 @@
1
- /**
2
- * https://github.com/colinhacks/zod/issues/316#issuecomment-850906479
3
- * Create a schema matches anything and returns a value. Use it with `or`:
4
- *
5
- * const schema = zod.number();
6
- * const tolerant = schema.or(fallback(-1));
7
- *
8
- * schema.parse('foo') // => ZodError
9
- * tolerant.parse('foo') // -1
10
- */
11
- export declare function fallback<T>(value: T): import("zod").ZodEffects<import("zod").ZodAny, T, any>;
@@ -1,14 +0,0 @@
1
- import { any } from 'zod';
2
- /**
3
- * https://github.com/colinhacks/zod/issues/316#issuecomment-850906479
4
- * Create a schema matches anything and returns a value. Use it with `or`:
5
- *
6
- * const schema = zod.number();
7
- * const tolerant = schema.or(fallback(-1));
8
- *
9
- * schema.parse('foo') // => ZodError
10
- * tolerant.parse('foo') // -1
11
- */
12
- export function fallback(value) {
13
- return any().transform(() => value);
14
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes