@logto/core-kit 1.0.0-beta.30 → 1.0.0-rc.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/lib/regex.d.ts +1 -0
- package/lib/regex.js +1 -0
- package/lib/scope.d.ts +1 -1
- package/lib/scope.js +1 -1
- package/package.json +8 -10
- package/scss/_fonts.scss +14 -17
- package/lib/index.cjs +0 -38
- package/lib/regex.cjs +0 -19
- package/lib/scope.cjs +0 -74
- package/lib/utilities/color.cjs +0 -18
- package/lib/utilities/id.cjs +0 -10
- package/lib/utilities/url.cjs +0 -25
- package/lib/utilities/zod.cjs +0 -19
package/lib/regex.d.ts
CHANGED
package/lib/regex.js
CHANGED
|
@@ -6,3 +6,4 @@ 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+$/;
|
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' | '
|
|
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'
|
|
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]: [],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/core-kit",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc.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.
|
|
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,26 +22,25 @@
|
|
|
22
22
|
"scss"
|
|
23
23
|
],
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": "^
|
|
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-
|
|
30
|
+
"@logto/language-kit": "1.0.0-rc.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
37
|
"@silverhand/eslint-config": "1.3.0",
|
|
39
38
|
"@silverhand/eslint-config-react": "1.3.0",
|
|
40
39
|
"@silverhand/essentials": "2.1.0",
|
|
41
40
|
"@silverhand/ts-config": "1.2.1",
|
|
42
41
|
"@types/color": "^3.0.3",
|
|
43
42
|
"@types/jest": "^29.0.3",
|
|
44
|
-
"@types/node": "^
|
|
43
|
+
"@types/node": "^18.11.18",
|
|
45
44
|
"@types/react": "^18.0.20",
|
|
46
45
|
"eslint": "^8.21.0",
|
|
47
46
|
"jest": "^29.0.3",
|
|
@@ -49,7 +48,6 @@
|
|
|
49
48
|
"lint-staged": "^13.0.0",
|
|
50
49
|
"postcss": "^8.4.6",
|
|
51
50
|
"prettier": "^2.8.1",
|
|
52
|
-
"rollup": "^3.6.0",
|
|
53
51
|
"stylelint": "^14.9.1",
|
|
54
52
|
"tslib": "^2.4.1",
|
|
55
53
|
"typescript": "^4.9.4"
|
|
@@ -67,7 +65,7 @@
|
|
|
67
65
|
"scripts": {
|
|
68
66
|
"precommit": "lint-staged",
|
|
69
67
|
"dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
|
|
70
|
-
"build": "rm -rf lib/ &&
|
|
68
|
+
"build": "rm -rf lib/ && tsc -p tsconfig.build.json",
|
|
71
69
|
"build:test": "pnpm build -p tsconfig.test.json --sourcemap",
|
|
72
70
|
"lint": "eslint --ext .ts src",
|
|
73
71
|
"lint:report": "pnpm lint --format json --output-file report.json",
|
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-
|
|
16
|
-
--font-headline-
|
|
17
|
-
--font-headline-
|
|
18
|
-
--font-title-
|
|
19
|
-
--font-title-
|
|
20
|
-
--font-title-
|
|
21
|
-
--font-label-
|
|
22
|
-
--font-label-
|
|
23
|
-
--font-label-
|
|
24
|
-
--font-body-
|
|
25
|
-
--font-body-
|
|
26
|
-
--font-body-
|
|
27
|
-
--font-
|
|
28
|
-
--font-
|
|
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;
|
package/lib/utilities/color.cjs
DELETED
|
@@ -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;
|
package/lib/utilities/id.cjs
DELETED
|
@@ -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;
|
package/lib/utilities/url.cjs
DELETED
|
@@ -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;
|
package/lib/utilities/zod.cjs
DELETED
|
@@ -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;
|