@logto/core-kit 1.0.0-beta.26 → 1.0.0-beta.29
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/lib/index.cjs +37 -0
- package/lib/index.d.ts +3 -4
- package/lib/index.js +3 -20
- package/lib/regex.cjs +19 -0
- package/lib/regex.js +8 -11
- package/lib/scope.cjs +74 -0
- package/lib/scope.js +8 -11
- package/lib/utilities/color.cjs +18 -0
- 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.cjs +7 -0
- package/lib/utilities/string.js +2 -6
- package/lib/utilities/url.cjs +25 -0
- package/lib/utilities/url.js +4 -9
- package/lib/utilities/zod.cjs +19 -0
- package/lib/utilities/zod.js +3 -7
- package/package.json +13 -6
- package/lib/language.d.ts +0 -11
- package/lib/language.js +0 -17
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var color = require('./utilities/color.cjs');
|
|
4
|
+
var string = require('./utilities/string.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.generateRandomString = string.generateRandomString;
|
|
16
|
+
exports.fallback = zod.fallback;
|
|
17
|
+
exports.validateRedirectUrl = url.validateRedirectUrl;
|
|
18
|
+
exports.validateUriOrigin = url.validateUriOrigin;
|
|
19
|
+
exports.dateRegex = regex.dateRegex;
|
|
20
|
+
exports.emailRegEx = regex.emailRegEx;
|
|
21
|
+
exports.hexColorRegEx = regex.hexColorRegEx;
|
|
22
|
+
exports.mobileUriSchemeProtocolRegEx = regex.mobileUriSchemeProtocolRegEx;
|
|
23
|
+
exports.passwordRegEx = regex.passwordRegEx;
|
|
24
|
+
exports.phoneRegEx = regex.phoneRegEx;
|
|
25
|
+
exports.usernameRegEx = regex.usernameRegEx;
|
|
26
|
+
exports.webRedirectUriProtocolRegEx = regex.webRedirectUriProtocolRegEx;
|
|
27
|
+
Object.defineProperty(exports, 'ReservedScope', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return scope.ReservedScope; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, 'UserScope', {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return scope.UserScope; }
|
|
34
|
+
});
|
|
35
|
+
exports.idTokenClaims = scope.idTokenClaims;
|
|
36
|
+
exports.userClaims = scope.userClaims;
|
|
37
|
+
exports.userinfoClaims = scope.userinfoClaims;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './utilities/index';
|
|
2
|
-
export * from './regex';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './scope';
|
|
1
|
+
export * from './utilities/index.js';
|
|
2
|
+
export * from './regex.js';
|
|
3
|
+
export * from './scope.js';
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
1
|
+
export * from './utilities/index.js';
|
|
2
|
+
export * from './regex.js';
|
|
3
|
+
export * from './scope.js';
|
package/lib/regex.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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/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.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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;
|
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
|
])));
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
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)();
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
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.29",
|
|
4
4
|
"author": "Silverhand Inc. <contact@silverhand.io>",
|
|
5
5
|
"homepage": "https://github.com/logto-io/toolkit#readme",
|
|
6
6
|
"repository": {
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
"url": "git+https://github.com/logto-io/toolkit.git"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
11
12
|
"source": "./src/index.ts",
|
|
12
|
-
"main": "./lib/index.
|
|
13
|
-
"exports":
|
|
13
|
+
"main": "./lib/index.cjs",
|
|
14
|
+
"exports": {
|
|
15
|
+
"import": "./lib/index.js",
|
|
16
|
+
"require": "./lib/index.cjs"
|
|
17
|
+
},
|
|
14
18
|
"types": "./lib/index.d.ts",
|
|
15
19
|
"files": [
|
|
16
20
|
"declaration",
|
|
@@ -20,7 +24,7 @@
|
|
|
20
24
|
"scripts": {
|
|
21
25
|
"precommit": "lint-staged",
|
|
22
26
|
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
|
|
23
|
-
"build": "rm -rf lib/ && tsc -p tsconfig.build.json",
|
|
27
|
+
"build": "rm -rf lib/ && rollup -c && tsc -p tsconfig.build.json",
|
|
24
28
|
"lint": "eslint --ext .ts src",
|
|
25
29
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
|
26
30
|
"prepack": "pnpm build",
|
|
@@ -35,12 +39,13 @@
|
|
|
35
39
|
"zod": "^3.19.1"
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
|
-
"@logto/language-kit": "^1.0.0-beta.
|
|
42
|
+
"@logto/language-kit": "^1.0.0-beta.29",
|
|
39
43
|
"color": "^4.2.3",
|
|
40
44
|
"nanoid": "^3.1.23"
|
|
41
45
|
},
|
|
42
46
|
"devDependencies": {
|
|
43
47
|
"@jest/types": "^29.0.3",
|
|
48
|
+
"@rollup/plugin-typescript": "^10.0.1",
|
|
44
49
|
"@silverhand/eslint-config": "1.3.0",
|
|
45
50
|
"@silverhand/eslint-config-react": "1.3.0",
|
|
46
51
|
"@silverhand/essentials": "^1.2.1",
|
|
@@ -55,8 +60,10 @@
|
|
|
55
60
|
"lint-staged": "^13.0.0",
|
|
56
61
|
"postcss": "^8.4.6",
|
|
57
62
|
"prettier": "^2.7.1",
|
|
63
|
+
"rollup": "^3.6.0",
|
|
58
64
|
"stylelint": "^14.9.1",
|
|
59
65
|
"ts-jest": "^29.0.1",
|
|
66
|
+
"tslib": "^2.4.1",
|
|
60
67
|
"typescript": "^4.7.4",
|
|
61
68
|
"zod": "^3.19.1"
|
|
62
69
|
},
|
|
@@ -70,5 +77,5 @@
|
|
|
70
77
|
"publishConfig": {
|
|
71
78
|
"access": "public"
|
|
72
79
|
},
|
|
73
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "6d7b4b80b6dfdfc57780f00adf60d9c488951ce6"
|
|
74
81
|
}
|
package/lib/language.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { LanguageTag } from '@logto/language-kit';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export declare const getDefaultLanguageTag: (language: string) => LanguageTag;
|
|
4
|
-
/** @deprecated */
|
|
5
|
-
export declare const languageKeys: readonly ["en", "fr", "pt-PT", "zh-CN", "tr-TR", "ko-KR"];
|
|
6
|
-
/** @deprecated */
|
|
7
|
-
export declare const languageKeyGuard: z.ZodEnum<["en", "fr", "pt-PT", "zh-CN", "tr-TR", "ko-KR"]>;
|
|
8
|
-
/** @deprecated */
|
|
9
|
-
export declare type LanguageKey = z.infer<typeof languageKeyGuard>;
|
|
10
|
-
/** @deprecated */
|
|
11
|
-
export declare const getDefaultLanguage: (language: string) => LanguageKey;
|
package/lib/language.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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;
|
|
9
|
-
/** @deprecated */
|
|
10
|
-
exports.languageKeys = ['en', 'fr', 'pt-PT', 'zh-CN', 'tr-TR', 'ko-KR'];
|
|
11
|
-
/** @deprecated */
|
|
12
|
-
exports.languageKeyGuard = zod_1.z.enum(exports.languageKeys);
|
|
13
|
-
/** @deprecated */
|
|
14
|
-
const getDefaultLanguage = (language) => {
|
|
15
|
-
return exports.languageKeyGuard.or((0, index_1.fallback)('en')).parse(language);
|
|
16
|
-
};
|
|
17
|
-
exports.getDefaultLanguage = getDefaultLanguage;
|