@logto/core-kit 2.2.1 → 2.3.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.
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { type webcrypto } from 'node:crypto';
1
3
  import { type DeepPartial } from '@silverhand/essentials';
2
4
  import { z } from 'zod';
3
5
  /** Password policy configuration type. */
@@ -137,7 +139,7 @@ export type UserInfo = Partial<{
137
139
  */
138
140
  export declare class PasswordPolicyChecker {
139
141
  /** The Web Crypto API to use. By default, the global `crypto.subtle` will be used. */
140
- protected readonly subtle: SubtleCrypto;
142
+ protected readonly subtle: webcrypto.SubtleCrypto | SubtleCrypto;
141
143
  static symbols: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
142
144
  /** A set of characters that are considered as sequential. */
143
145
  static sequence: readonly ["0123456789", "abcdefghijklmnopqrstuvwxyz", "qwertyuiop", "asdfghjkl", "zxcvbnm", "1qaz", "2wsx", "3edc", "4rfv", "5tgb", "6yhn", "7ujm", "8ik", "9ol"];
@@ -153,7 +155,7 @@ export declare class PasswordPolicyChecker {
153
155
  readonly policy: PasswordPolicy;
154
156
  constructor(policy: DeepPartial<PasswordPolicy>,
155
157
  /** The Web Crypto API to use. By default, the global `crypto.subtle` will be used. */
156
- subtle?: SubtleCrypto);
158
+ subtle?: webcrypto.SubtleCrypto | SubtleCrypto);
157
159
  /**
158
160
  * Check if a password meets all the policy requirements.
159
161
  *
@@ -43,7 +43,7 @@ export const passwordPolicyGuard = z.object({
43
43
  * // ]
44
44
  * ```
45
45
  */
46
- class PasswordPolicyChecker {
46
+ export class PasswordPolicyChecker {
47
47
  static { this.symbols = Object.freeze('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '); }
48
48
  /** A set of characters that are considered as sequential. */
49
49
  static { this.sequence = Object.freeze([
@@ -356,4 +356,3 @@ class PasswordPolicyChecker {
356
356
  return false;
357
357
  }
358
358
  }
359
- export { PasswordPolicyChecker };
package/lib/regex.d.ts CHANGED
@@ -7,3 +7,5 @@ export declare const mobileUriSchemeProtocolRegEx: RegExp;
7
7
  export declare const hexColorRegEx: RegExp;
8
8
  export declare const dateRegex: RegExp;
9
9
  export declare const noSpaceRegEx: RegExp;
10
+ /** Full domain that consists of at least 3 parts, e.g. foo.bar.com */
11
+ export declare const domainRegEx: RegExp;
package/lib/regex.js CHANGED
@@ -7,3 +7,5 @@ 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
9
  export const noSpaceRegEx = /^\S+$/;
10
+ /** Full domain that consists of at least 3 parts, e.g. foo.bar.com */
11
+ export const domainRegEx = /^[\dA-Za-z]+(\.[\dA-Za-z]+){2,}$/;
@@ -1,2 +1,3 @@
1
1
  export * from './color.js';
2
+ export * from './regex.js';
2
3
  export * from './url.js';
@@ -1,2 +1,3 @@
1
1
  export * from './color.js';
2
+ export * from './regex.js';
2
3
  export * from './url.js';
@@ -0,0 +1 @@
1
+ export declare const isValidRegEx: (regEx?: string) => boolean;
@@ -0,0 +1,8 @@
1
+ export const isValidRegEx = (regEx) => {
2
+ try {
3
+ return Boolean(regEx && new RegExp(regEx));
4
+ }
5
+ catch {
6
+ return false;
7
+ }
8
+ };
@@ -1,2 +1,3 @@
1
1
  export declare const validateRedirectUrl: (url: string, type: 'web' | 'mobile') => boolean;
2
2
  export declare const validateUriOrigin: (url: string) => boolean;
3
+ export declare const isValidUrl: (url?: string) => boolean;
package/lib/utils/url.js CHANGED
@@ -17,3 +17,11 @@ export const validateUriOrigin = (url) => {
17
17
  return false;
18
18
  }
19
19
  };
20
+ export const isValidUrl = (url) => {
21
+ try {
22
+ return Boolean(url && new URL(url));
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/core-kit",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
5
5
  "homepage": "https://github.com/logto-io/toolkit#readme",
6
6
  "repository": {
@@ -26,11 +26,11 @@
26
26
  "scss"
27
27
  ],
28
28
  "engines": {
29
- "node": "^18.12.0"
29
+ "node": "^20.9.0"
30
30
  },
31
31
  "dependencies": {
32
- "@logto/language-kit": "^1.0.0",
33
- "@logto/shared": "^3.0.0",
32
+ "@logto/language-kit": "^1.1.0",
33
+ "@logto/shared": "^3.1.0",
34
34
  "color": "^4.2.3"
35
35
  },
36
36
  "optionalDependencies": {
@@ -38,22 +38,22 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@jest/types": "^29.0.3",
41
- "@silverhand/eslint-config": "4.0.1",
42
- "@silverhand/essentials": "^2.8.4",
43
- "@silverhand/ts-config": "4.0.0",
44
- "@silverhand/ts-config-react": "4.0.0",
41
+ "@silverhand/eslint-config": "5.0.0",
42
+ "@silverhand/essentials": "^2.9.0",
43
+ "@silverhand/ts-config": "5.0.0",
44
+ "@silverhand/ts-config-react": "5.0.0",
45
45
  "@types/color": "^3.0.3",
46
46
  "@types/jest": "^29.4.0",
47
- "@types/node": "^18.11.18",
47
+ "@types/node": "^20.9.5",
48
48
  "@types/react": "^18.0.31",
49
49
  "eslint": "^8.44.0",
50
- "jest": "^29.5.0",
50
+ "jest": "^29.7.0",
51
51
  "lint-staged": "^15.0.0",
52
52
  "postcss": "^8.4.31",
53
53
  "prettier": "^3.0.0",
54
54
  "stylelint": "^15.0.0",
55
55
  "tslib": "^2.4.1",
56
- "typescript": "^5.0.0"
56
+ "typescript": "^5.3.3"
57
57
  },
58
58
  "eslintConfig": {
59
59
  "extends": "@silverhand"
@@ -92,6 +92,7 @@
92
92
  --color-alert-99: #fff5eb;
93
93
 
94
94
  // color aliases
95
+ --color-static-white: #fff;
95
96
  --color-primary: var(--color-primary-40);
96
97
  --color-on-primary: var(--color-all-100);
97
98
  --color-primary-container: var(--color-primary-90);
@@ -160,6 +161,8 @@
160
161
  --color-env-tag-production: rgba(131, 218, 133, 35%);
161
162
  --color-specific-icon-bg: #f3effa;
162
163
  --color-specific-toggle-off-enable: var(--color-neutral-90);
164
+ --color-specific-unselected-disabled: var(--color-hover); // 8% Neutral-10
165
+ --color-function-n-overlay-primary-focused: rgba(93, 52, 242, 16%); // 16% Primary-40
163
166
 
164
167
  // Shadows
165
168
  --shadow-1: 0 4px 8px rgba(0, 0, 0, 8%);
@@ -187,7 +190,7 @@
187
190
  // Background
188
191
  --color-bg-body-base: var(--color-neutral-95);
189
192
  --color-bg-body: var(--color-neutral-100);
190
- --color-bg-layer-1: var(--color-static-white);
193
+ --color-bg-layer-1: var(--color-all-100);
191
194
  --color-bg-layer-2: var(--color-neutral-95);
192
195
  --color-bg-body-overlay: var(--color-neutral-100);
193
196
  --color-bg-float-base: var(--color-neutral-variant-90);
@@ -294,6 +297,7 @@
294
297
  --color-alert-99: #2b1700;
295
298
 
296
299
  // color aliases
300
+ --color-static-white: #fff;
297
301
  --color-primary: var(--color-primary-70);
298
302
  --color-on-primary: var(--color-all-0);
299
303
  --color-primary-container: var(--color-primary-30);
@@ -362,6 +366,8 @@
362
366
  --color-env-tag-production: rgba(104, 190, 108, 36%);
363
367
  --color-specific-icon-bg: rgba(247, 248, 248, 12%);
364
368
  --color-specific-toggle-off-enable: var(--color-neutral-90);
369
+ --color-specific-unselected-disabled: var(--color-hover); // 8% Neutral-10
370
+ --color-function-n-overlay-primary-focused: rgba(202, 190, 255, 16%); // 16% Primary-40
365
371
 
366
372
  // Shadows
367
373
  --shadow-1: 0 4px 8px rgba(0, 0, 0, 8%);