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