@logto/core-kit 1.0.0-beta.25 → 1.0.0-beta.28

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 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
1
  export * from './utilities/index.js';
2
2
  export * from './regex.js';
3
- export * from './language.js';
4
3
  export * from './scope.js';
package/lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './utilities/index.js';
2
2
  export * from './regex.js';
3
- export * from './language.js';
4
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/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;
@@ -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;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var nanoid = require('nanoid');
4
+
5
+ const generateRandomString = (size, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') => nanoid.customAlphabet(alphabet, size)();
6
+
7
+ exports.generateRandomString = generateRandomString;
@@ -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;
@@ -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/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@logto/core-kit",
3
- "version": "1.0.0-beta.25",
4
- "main": "lib/index.js",
3
+ "version": "1.0.0-beta.28",
5
4
  "author": "Silverhand Inc. <contact@silverhand.io>",
6
5
  "homepage": "https://github.com/logto-io/toolkit#readme",
7
6
  "repository": {
@@ -10,6 +9,10 @@
10
9
  },
11
10
  "license": "MIT",
12
11
  "type": "module",
12
+ "source": "./src/index.ts",
13
+ "main": "./lib/index.cjs",
14
+ "exports": "./lib/index.js",
15
+ "types": "./lib/index.d.ts",
13
16
  "files": [
14
17
  "declaration",
15
18
  "lib",
@@ -17,8 +20,8 @@
17
20
  ],
18
21
  "scripts": {
19
22
  "precommit": "lint-staged",
20
- "build": "rm -rf lib/ && tsc -p tsconfig.build.json",
21
23
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput --incremental",
24
+ "build": "rm -rf lib/ && rollup -c && tsc -p tsconfig.build.json",
22
25
  "lint": "eslint --ext .ts src",
23
26
  "lint:report": "pnpm lint --format json --output-file report.json",
24
27
  "prepack": "pnpm build",
@@ -33,12 +36,13 @@
33
36
  "zod": "^3.19.1"
34
37
  },
35
38
  "dependencies": {
36
- "@logto/language-kit": "^1.0.0-beta.24",
39
+ "@logto/language-kit": "^1.0.0-beta.28",
37
40
  "color": "^4.2.3",
38
41
  "nanoid": "^3.1.23"
39
42
  },
40
43
  "devDependencies": {
41
44
  "@jest/types": "^29.0.3",
45
+ "@rollup/plugin-typescript": "^10.0.1",
42
46
  "@silverhand/eslint-config": "1.3.0",
43
47
  "@silverhand/eslint-config-react": "1.3.0",
44
48
  "@silverhand/essentials": "^1.2.1",
@@ -53,8 +57,10 @@
53
57
  "lint-staged": "^13.0.0",
54
58
  "postcss": "^8.4.6",
55
59
  "prettier": "^2.7.1",
60
+ "rollup": "^3.6.0",
56
61
  "stylelint": "^14.9.1",
57
62
  "ts-jest": "^29.0.1",
63
+ "tslib": "^2.4.1",
58
64
  "typescript": "^4.7.4",
59
65
  "zod": "^3.19.1"
60
66
  },
@@ -68,5 +74,5 @@
68
74
  "publishConfig": {
69
75
  "access": "public"
70
76
  },
71
- "gitHead": "99e4e13ee0ca5ae4420fa05f24f65c3ef19389f6"
77
+ "gitHead": "86d65c492079ff1209324355cdc2cf5de638cbc5"
72
78
  }
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,12 +0,0 @@
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);
5
- /** @deprecated */
6
- export const languageKeys = ['en', 'fr', 'pt-PT', 'zh-CN', 'tr-TR', 'ko-KR'];
7
- /** @deprecated */
8
- export const languageKeyGuard = z.enum(languageKeys);
9
- /** @deprecated */
10
- export const getDefaultLanguage = (language) => {
11
- return languageKeyGuard.or(fallback('en')).parse(language);
12
- };