@logto/core-kit 1.0.0-beta.21 → 1.0.0-beta.24
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/declaration/index.ts +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -20
- package/lib/language.js +8 -13
- package/lib/regex.js +8 -11
- package/lib/scope.js +8 -11
- package/lib/utilities/color.js +6 -15
- package/lib/utilities/index.d.ts +4 -4
- package/lib/utilities/index.js +4 -20
- package/lib/utilities/string.js +2 -6
- package/lib/utilities/url.js +4 -9
- package/lib/utilities/zod.js +3 -7
- package/package.json +11 -7
package/declaration/index.ts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './utilities';
|
|
2
|
-
export * from './regex';
|
|
3
|
-
export * from './language';
|
|
4
|
-
export * from './scope';
|
|
1
|
+
export * from './utilities/index.js';
|
|
2
|
+
export * from './regex.js';
|
|
3
|
+
export * from './language.js';
|
|
4
|
+
export * from './scope.js';
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./utilities"), exports);
|
|
18
|
-
__exportStar(require("./regex"), exports);
|
|
19
|
-
__exportStar(require("./language"), exports);
|
|
20
|
-
__exportStar(require("./scope"), exports);
|
|
1
|
+
export * from './utilities/index.js';
|
|
2
|
+
export * from './regex.js';
|
|
3
|
+
export * from './language.js';
|
|
4
|
+
export * from './scope.js';
|
package/lib/language.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const utilities_1 = require("./utilities");
|
|
7
|
-
const getDefaultLanguageTag = (language) => language_kit_1.languageTagGuard.or((0, utilities_1.fallback)('en')).parse(language);
|
|
8
|
-
exports.getDefaultLanguageTag = getDefaultLanguageTag;
|
|
1
|
+
import { languageTagGuard } from '@logto/language-kit';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { fallback } from './utilities/index.js';
|
|
4
|
+
export const getDefaultLanguageTag = (language) => languageTagGuard.or(fallback('en')).parse(language);
|
|
9
5
|
/** @deprecated */
|
|
10
|
-
|
|
6
|
+
export const languageKeys = ['en', 'fr', 'pt-PT', 'zh-CN', 'tr-TR', 'ko-KR'];
|
|
11
7
|
/** @deprecated */
|
|
12
|
-
|
|
8
|
+
export const languageKeyGuard = z.enum(languageKeys);
|
|
13
9
|
/** @deprecated */
|
|
14
|
-
const getDefaultLanguage = (language) => {
|
|
15
|
-
return
|
|
10
|
+
export const getDefaultLanguage = (language) => {
|
|
11
|
+
return languageKeyGuard.or(fallback('en')).parse(language);
|
|
16
12
|
};
|
|
17
|
-
exports.getDefaultLanguage = getDefaultLanguage;
|
package/lib/regex.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.mobileUriSchemeProtocolRegEx = /^[a-z][\d_a-z]*(\.[\d_a-z]+)+:$/;
|
|
10
|
-
exports.hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
|
|
11
|
-
exports.dateRegex = /^\d{4}(-\d{2}){2}/;
|
|
1
|
+
export const emailRegEx = /^\S+@\S+\.\S+$/;
|
|
2
|
+
export const phoneRegEx = /^\d+$/;
|
|
3
|
+
export const usernameRegEx = /^[A-Z_a-z]\w*$/;
|
|
4
|
+
export const passwordRegEx = /^.{6,}$/;
|
|
5
|
+
export const webRedirectUriProtocolRegEx = /^https?:$/;
|
|
6
|
+
export const mobileUriSchemeProtocolRegEx = /^[a-z][\d_a-z]*(\.[\d_a-z]+)+:$/;
|
|
7
|
+
export const hexColorRegEx = /^#[\da-f]{3}([\da-f]{3})?$/i;
|
|
8
|
+
export const dateRegex = /^\d{4}(-\d{2}){2}/;
|
package/lib/scope.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userClaims = exports.userinfoClaims = exports.idTokenClaims = exports.UserScope = exports.ReservedScope = void 0;
|
|
4
|
-
var ReservedScope;
|
|
1
|
+
export var ReservedScope;
|
|
5
2
|
(function (ReservedScope) {
|
|
6
3
|
ReservedScope["OpenId"] = "openid";
|
|
7
4
|
ReservedScope["OfflineAccess"] = "offline_access";
|
|
8
|
-
})(ReservedScope
|
|
5
|
+
})(ReservedScope || (ReservedScope = {}));
|
|
9
6
|
/**
|
|
10
7
|
* Scopes for ID Token and Userinfo Endpoint.
|
|
11
8
|
*/
|
|
12
|
-
var UserScope;
|
|
9
|
+
export var UserScope;
|
|
13
10
|
(function (UserScope) {
|
|
14
11
|
/**
|
|
15
12
|
* Scope for basic user info.
|
|
@@ -41,11 +38,11 @@ var UserScope;
|
|
|
41
38
|
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
42
39
|
*/
|
|
43
40
|
UserScope["Identities"] = "identities";
|
|
44
|
-
})(UserScope
|
|
41
|
+
})(UserScope || (UserScope = {}));
|
|
45
42
|
/**
|
|
46
43
|
* Mapped claims that ID Token includes.
|
|
47
44
|
*/
|
|
48
|
-
|
|
45
|
+
export const idTokenClaims = Object.freeze({
|
|
49
46
|
[UserScope.Profile]: ['name', 'picture', 'username', 'role_names'],
|
|
50
47
|
[UserScope.Email]: ['email', 'email_verified'],
|
|
51
48
|
[UserScope.Phone]: ['phone_number', 'phone_number_verified'],
|
|
@@ -55,17 +52,17 @@ exports.idTokenClaims = Object.freeze({
|
|
|
55
52
|
/**
|
|
56
53
|
* Additional claims that Userinfo Endpoint returns.
|
|
57
54
|
*/
|
|
58
|
-
|
|
55
|
+
export const userinfoClaims = Object.freeze({
|
|
59
56
|
[UserScope.Profile]: [],
|
|
60
57
|
[UserScope.Email]: [],
|
|
61
58
|
[UserScope.Phone]: [],
|
|
62
59
|
[UserScope.CustomData]: ['custom_data'],
|
|
63
60
|
[UserScope.Identities]: ['identities'],
|
|
64
61
|
});
|
|
65
|
-
|
|
62
|
+
export const userClaims = Object.freeze(
|
|
66
63
|
// Hard to infer type directly, use `as` for a workaround.
|
|
67
64
|
// eslint-disable-next-line no-restricted-syntax
|
|
68
65
|
Object.fromEntries(Object.values(UserScope).map((current) => [
|
|
69
66
|
current,
|
|
70
|
-
[...
|
|
67
|
+
[...idTokenClaims[current], ...userinfoClaims[current]],
|
|
71
68
|
])));
|
package/lib/utilities/color.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateDarkColor = exports.absoluteDarken = exports.absoluteLighten = void 0;
|
|
7
|
-
const color_1 = __importDefault(require("color"));
|
|
1
|
+
import color from 'color';
|
|
8
2
|
// Color hsl lighten/darken takes percentage value only, need to implement absolute value update
|
|
9
|
-
const absoluteLighten = (baseColor, delta) => {
|
|
3
|
+
export const absoluteLighten = (baseColor, delta) => {
|
|
10
4
|
const hslArray = baseColor.hsl().round().array();
|
|
11
|
-
return (
|
|
5
|
+
return color([hslArray[0] ?? 0, hslArray[1] ?? 0, (hslArray[2] ?? 0) + delta], 'hsl');
|
|
12
6
|
};
|
|
13
|
-
|
|
14
|
-
const absoluteDarken = (baseColor, delta) => {
|
|
7
|
+
export const absoluteDarken = (baseColor, delta) => {
|
|
15
8
|
const hslArray = baseColor.hsl().round().array();
|
|
16
|
-
return (
|
|
9
|
+
return color([hslArray[0] ?? 0, hslArray[1] ?? 0, (hslArray[2] ?? 0) - delta], 'hsl');
|
|
17
10
|
};
|
|
18
|
-
|
|
19
|
-
const generateDarkColor = (lightColor) => (0, exports.absoluteLighten)((0, color_1.default)(lightColor), 10).hex();
|
|
20
|
-
exports.generateDarkColor = generateDarkColor;
|
|
11
|
+
export const generateDarkColor = (lightColor) => absoluteLighten(color(lightColor), 10).hex();
|
package/lib/utilities/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './color';
|
|
2
|
-
export * from './string';
|
|
3
|
-
export * from './zod';
|
|
4
|
-
export * from './url';
|
|
1
|
+
export * from './color.js';
|
|
2
|
+
export * from './string.js';
|
|
3
|
+
export * from './zod.js';
|
|
4
|
+
export * from './url.js';
|
package/lib/utilities/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./color"), exports);
|
|
18
|
-
__exportStar(require("./string"), exports);
|
|
19
|
-
__exportStar(require("./zod"), exports);
|
|
20
|
-
__exportStar(require("./url"), exports);
|
|
1
|
+
export * from './color.js';
|
|
2
|
+
export * from './string.js';
|
|
3
|
+
export * from './zod.js';
|
|
4
|
+
export * from './url.js';
|
package/lib/utilities/string.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.generateRandomString = void 0;
|
|
4
|
-
const nanoid_1 = require("nanoid");
|
|
5
|
-
const generateRandomString = (size, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') => (0, nanoid_1.customAlphabet)(alphabet, size)();
|
|
6
|
-
exports.generateRandomString = generateRandomString;
|
|
1
|
+
import { customAlphabet } from 'nanoid';
|
|
2
|
+
export const generateRandomString = (size, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') => customAlphabet(alphabet, size)();
|
package/lib/utilities/url.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.validateUriOrigin = exports.validateRedirectUrl = void 0;
|
|
4
|
-
const regex_1 = require("../regex");
|
|
5
|
-
const validateRedirectUrl = (url, type) => {
|
|
1
|
+
import { mobileUriSchemeProtocolRegEx, webRedirectUriProtocolRegEx } from '../regex.js';
|
|
2
|
+
export const validateRedirectUrl = (url, type) => {
|
|
6
3
|
try {
|
|
7
4
|
const { protocol } = new URL(url);
|
|
8
|
-
const protocolRegEx = type === 'mobile' ?
|
|
5
|
+
const protocolRegEx = type === 'mobile' ? mobileUriSchemeProtocolRegEx : webRedirectUriProtocolRegEx;
|
|
9
6
|
return protocolRegEx.test(protocol);
|
|
10
7
|
}
|
|
11
8
|
catch {
|
|
12
9
|
return false;
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
const validateUriOrigin = (url) => {
|
|
12
|
+
export const validateUriOrigin = (url) => {
|
|
17
13
|
try {
|
|
18
14
|
return new URL(url).origin === url;
|
|
19
15
|
}
|
|
@@ -21,4 +17,3 @@ const validateUriOrigin = (url) => {
|
|
|
21
17
|
return false;
|
|
22
18
|
}
|
|
23
19
|
};
|
|
24
|
-
exports.validateUriOrigin = validateUriOrigin;
|
package/lib/utilities/zod.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fallback = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
1
|
+
import { any } from 'zod';
|
|
5
2
|
/**
|
|
6
3
|
* https://github.com/colinhacks/zod/issues/316#issuecomment-850906479
|
|
7
4
|
* Create a schema matches anything and returns a value. Use it with `or`:
|
|
@@ -12,7 +9,6 @@ const zod_1 = require("zod");
|
|
|
12
9
|
* schema.parse('foo') // => ZodError
|
|
13
10
|
* tolerant.parse('foo') // -1
|
|
14
11
|
*/
|
|
15
|
-
function fallback(value) {
|
|
16
|
-
return
|
|
12
|
+
export function fallback(value) {
|
|
13
|
+
return any().transform(() => value);
|
|
17
14
|
}
|
|
18
|
-
exports.fallback = fallback;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/core-kit",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.24",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
6
6
|
"homepage": "https://github.com/logto-io/toolkit#readme",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"url": "git+https://github.com/logto-io/toolkit.git"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
12
13
|
"files": [
|
|
13
14
|
"declaration",
|
|
14
15
|
"lib",
|
|
@@ -26,13 +27,15 @@
|
|
|
26
27
|
"test:coverage": "jest --silent --coverage"
|
|
27
28
|
},
|
|
28
29
|
"engines": {
|
|
29
|
-
"node": "^16.0.0"
|
|
30
|
+
"node": "^16.13.0 || ^18.12.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"zod": "^3.19.1"
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@logto/language-kit": "^1.0.0-beta.
|
|
36
|
+
"@logto/language-kit": "^1.0.0-beta.24",
|
|
33
37
|
"color": "^4.2.3",
|
|
34
|
-
"nanoid": "^3.1.23"
|
|
35
|
-
"zod": "^3.18.0"
|
|
38
|
+
"nanoid": "^3.1.23"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
41
|
"@jest/types": "^29.0.3",
|
|
@@ -52,7 +55,8 @@
|
|
|
52
55
|
"prettier": "^2.7.1",
|
|
53
56
|
"stylelint": "^14.9.1",
|
|
54
57
|
"ts-jest": "^29.0.1",
|
|
55
|
-
"typescript": "^4.7.4"
|
|
58
|
+
"typescript": "^4.7.4",
|
|
59
|
+
"zod": "^3.19.1"
|
|
56
60
|
},
|
|
57
61
|
"eslintConfig": {
|
|
58
62
|
"extends": "@silverhand"
|
|
@@ -64,5 +68,5 @@
|
|
|
64
68
|
"publishConfig": {
|
|
65
69
|
"access": "public"
|
|
66
70
|
},
|
|
67
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "ba97b1c838f8af3a178d6271d08d239e68f0456e"
|
|
68
72
|
}
|