@nocobase/utils 2.2.0-beta.13 → 2.2.0-beta.15
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/auth-cookie-name.d.ts +10 -0
- package/lib/auth-cookie-name.js +46 -0
- package/lib/auth-cookie.d.ts +21 -0
- package/lib/auth-cookie.js +62 -0
- package/lib/client.d.ts +1 -0
- package/lib/client.js +2 -0
- package/lib/cors.d.ts +19 -0
- package/lib/cors.js +89 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export type AuthCookieType = 'authToken' | 'authenticator' | 'role' | 'csrfToken';
|
|
10
|
+
export declare function getAuthCookieName(type: AuthCookieType, appName?: string): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var auth_cookie_name_exports = {};
|
|
29
|
+
__export(auth_cookie_name_exports, {
|
|
30
|
+
getAuthCookieName: () => getAuthCookieName
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(auth_cookie_name_exports);
|
|
33
|
+
const cookieNamePrefixes = {
|
|
34
|
+
authToken: "nb_auth_token",
|
|
35
|
+
authenticator: "nb_authenticator",
|
|
36
|
+
role: "nb_role",
|
|
37
|
+
csrfToken: "nb_csrf_token"
|
|
38
|
+
};
|
|
39
|
+
function getAuthCookieName(type, appName) {
|
|
40
|
+
return `${cookieNamePrefixes[type]}_${appName || "main"}`;
|
|
41
|
+
}
|
|
42
|
+
__name(getAuthCookieName, "getAuthCookieName");
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
getAuthCookieName
|
|
46
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export type { AuthCookieType } from './auth-cookie-name';
|
|
10
|
+
export { getAuthCookieName } from './auth-cookie-name';
|
|
11
|
+
export declare function getAuthCookieOptions(ctx: {
|
|
12
|
+
protocol?: string;
|
|
13
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
14
|
+
}, httpOnly?: boolean, maxAge?: number): {
|
|
15
|
+
maxAge?: number;
|
|
16
|
+
secureProxy?: boolean;
|
|
17
|
+
httpOnly: boolean;
|
|
18
|
+
sameSite: "lax";
|
|
19
|
+
secure: boolean;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var auth_cookie_exports = {};
|
|
29
|
+
__export(auth_cookie_exports, {
|
|
30
|
+
getAuthCookieName: () => import_auth_cookie_name.getAuthCookieName,
|
|
31
|
+
getAuthCookieOptions: () => getAuthCookieOptions
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(auth_cookie_exports);
|
|
34
|
+
var import_auth_cookie_name = require("./auth-cookie-name");
|
|
35
|
+
function getFirstHeaderValue(value) {
|
|
36
|
+
var _a;
|
|
37
|
+
const header = Array.isArray(value) ? value[0] : value;
|
|
38
|
+
return (_a = header == null ? void 0 : header.split(",")[0]) == null ? void 0 : _a.trim().toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
__name(getFirstHeaderValue, "getFirstHeaderValue");
|
|
41
|
+
function getAuthCookieOptions(ctx, httpOnly = true, maxAge) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const forwardedProto = (_a = ctx.headers) == null ? void 0 : _a["x-forwarded-proto"];
|
|
44
|
+
const forwardedProtocol = getFirstHeaderValue(forwardedProto);
|
|
45
|
+
const protocol = forwardedProtocol || ctx.protocol;
|
|
46
|
+
const publicPath = ((_b = process.env.APP_PUBLIC_PATH) == null ? void 0 : _b.replace(/\/+$/g, "")) || "/";
|
|
47
|
+
const secure = protocol === "https";
|
|
48
|
+
return {
|
|
49
|
+
httpOnly,
|
|
50
|
+
sameSite: "lax",
|
|
51
|
+
secure: secure && !forwardedProtocol,
|
|
52
|
+
path: publicPath || "/",
|
|
53
|
+
...secure && forwardedProtocol ? { secureProxy: true } : {},
|
|
54
|
+
...maxAge ? { maxAge } : {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
__name(getAuthCookieOptions, "getAuthCookieOptions");
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
getAuthCookieName,
|
|
61
|
+
getAuthCookieOptions
|
|
62
|
+
});
|
package/lib/client.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { dayjs } from './dayjs';
|
|
|
11
11
|
import { getDayRangeByParams, getOffsetRangeByParams } from './dateRangeUtils';
|
|
12
12
|
export * from './collections-graph';
|
|
13
13
|
export * from './common';
|
|
14
|
+
export * from './auth-cookie-name';
|
|
14
15
|
export * from './date';
|
|
15
16
|
export * from './forEach';
|
|
16
17
|
export * from './getValuesByPath';
|
package/lib/client.js
CHANGED
|
@@ -48,6 +48,7 @@ var import_dayjs = require("./dayjs");
|
|
|
48
48
|
var import_dateRangeUtils = require("./dateRangeUtils");
|
|
49
49
|
__reExport(client_exports, require("./collections-graph"), module.exports);
|
|
50
50
|
__reExport(client_exports, require("./common"), module.exports);
|
|
51
|
+
__reExport(client_exports, require("./auth-cookie-name"), module.exports);
|
|
51
52
|
__reExport(client_exports, require("./date"), module.exports);
|
|
52
53
|
__reExport(client_exports, require("./forEach"), module.exports);
|
|
53
54
|
__reExport(client_exports, require("./getValuesByPath"), module.exports);
|
|
@@ -79,6 +80,7 @@ __reExport(client_exports, require("./liquidjs"), module.exports);
|
|
|
79
80
|
lodash,
|
|
80
81
|
...require("./collections-graph"),
|
|
81
82
|
...require("./common"),
|
|
83
|
+
...require("./auth-cookie-name"),
|
|
82
84
|
...require("./date"),
|
|
83
85
|
...require("./forEach"),
|
|
84
86
|
...require("./getValuesByPath"),
|
package/lib/cors.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export interface OriginContext {
|
|
10
|
+
protocol?: string;
|
|
11
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
12
|
+
get(name: string): string;
|
|
13
|
+
}
|
|
14
|
+
export declare function getFirstHeaderValue(value: string | string[] | undefined): string;
|
|
15
|
+
export declare function getCorsWhitelist(): Set<string>;
|
|
16
|
+
export declare function getRequestOrigin(ctx: OriginContext): string;
|
|
17
|
+
export declare function getOrigin(value: string): string;
|
|
18
|
+
export declare function isSameOrigin(ctx: OriginContext, origin: string): boolean;
|
|
19
|
+
export declare function isTrustedOrigin(ctx: OriginContext, origin: string): boolean;
|
package/lib/cors.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var cors_exports = {};
|
|
29
|
+
__export(cors_exports, {
|
|
30
|
+
getCorsWhitelist: () => getCorsWhitelist,
|
|
31
|
+
getFirstHeaderValue: () => getFirstHeaderValue,
|
|
32
|
+
getOrigin: () => getOrigin,
|
|
33
|
+
getRequestOrigin: () => getRequestOrigin,
|
|
34
|
+
isSameOrigin: () => isSameOrigin,
|
|
35
|
+
isTrustedOrigin: () => isTrustedOrigin
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(cors_exports);
|
|
38
|
+
function getFirstHeaderValue(value) {
|
|
39
|
+
var _a;
|
|
40
|
+
const header = Array.isArray(value) ? value[0] : value;
|
|
41
|
+
return (_a = header == null ? void 0 : header.split(",")[0]) == null ? void 0 : _a.trim();
|
|
42
|
+
}
|
|
43
|
+
__name(getFirstHeaderValue, "getFirstHeaderValue");
|
|
44
|
+
function getCorsWhitelist() {
|
|
45
|
+
const whitelistString = process.env.CORS_ORIGIN_WHITELIST;
|
|
46
|
+
if (!whitelistString) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return new Set(
|
|
50
|
+
whitelistString.split(",").map((item) => item.trim()).filter(Boolean)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
__name(getCorsWhitelist, "getCorsWhitelist");
|
|
54
|
+
function getRequestOrigin(ctx) {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
const protocol = (_b = getFirstHeaderValue((_a = ctx.headers) == null ? void 0 : _a["x-forwarded-proto"]) || ctx.protocol) == null ? void 0 : _b.toLowerCase();
|
|
57
|
+
const host = getFirstHeaderValue((_c = ctx.headers) == null ? void 0 : _c["x-forwarded-host"]) || ctx.get("host");
|
|
58
|
+
return host ? `${protocol}://${host}` : void 0;
|
|
59
|
+
}
|
|
60
|
+
__name(getRequestOrigin, "getRequestOrigin");
|
|
61
|
+
function getOrigin(value) {
|
|
62
|
+
try {
|
|
63
|
+
return new URL(value).origin;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
__name(getOrigin, "getOrigin");
|
|
69
|
+
function isSameOrigin(ctx, origin) {
|
|
70
|
+
return origin === getRequestOrigin(ctx);
|
|
71
|
+
}
|
|
72
|
+
__name(isSameOrigin, "isSameOrigin");
|
|
73
|
+
function isTrustedOrigin(ctx, origin) {
|
|
74
|
+
var _a;
|
|
75
|
+
if (isSameOrigin(ctx, origin)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return ((_a = getCorsWhitelist()) == null ? void 0 : _a.has(origin)) || false;
|
|
79
|
+
}
|
|
80
|
+
__name(isTrustedOrigin, "isTrustedOrigin");
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
getCorsWhitelist,
|
|
84
|
+
getFirstHeaderValue,
|
|
85
|
+
getOrigin,
|
|
86
|
+
getRequestOrigin,
|
|
87
|
+
isSameOrigin,
|
|
88
|
+
isTrustedOrigin
|
|
89
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
import lodash from 'lodash';
|
|
10
10
|
export { Schema } from '@formily/json-schema';
|
|
11
11
|
export * from './assign';
|
|
12
|
+
export * from './auth-cookie';
|
|
12
13
|
export * from './collections-graph';
|
|
13
14
|
export * from './common';
|
|
15
|
+
export * from './cors';
|
|
14
16
|
export * from './crypto';
|
|
15
17
|
export * from './date';
|
|
16
18
|
export * from './dateRangeUtils';
|
package/lib/index.js
CHANGED
|
@@ -45,8 +45,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
45
45
|
var import_lodash = __toESM(require("lodash"));
|
|
46
46
|
var import_json_schema = require("@formily/json-schema");
|
|
47
47
|
__reExport(src_exports, require("./assign"), module.exports);
|
|
48
|
+
__reExport(src_exports, require("./auth-cookie"), module.exports);
|
|
48
49
|
__reExport(src_exports, require("./collections-graph"), module.exports);
|
|
49
50
|
__reExport(src_exports, require("./common"), module.exports);
|
|
51
|
+
__reExport(src_exports, require("./cors"), module.exports);
|
|
50
52
|
__reExport(src_exports, require("./crypto"), module.exports);
|
|
51
53
|
__reExport(src_exports, require("./date"), module.exports);
|
|
52
54
|
__reExport(src_exports, require("./dateRangeUtils"), module.exports);
|
|
@@ -88,8 +90,10 @@ __reExport(src_exports, require("./storage-path"), module.exports);
|
|
|
88
90
|
dayjs,
|
|
89
91
|
lodash,
|
|
90
92
|
...require("./assign"),
|
|
93
|
+
...require("./auth-cookie"),
|
|
91
94
|
...require("./collections-graph"),
|
|
92
95
|
...require("./common"),
|
|
96
|
+
...require("./cors"),
|
|
93
97
|
...require("./crypto"),
|
|
94
98
|
...require("./date"),
|
|
95
99
|
...require("./dateRangeUtils"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "2.2.0-beta.
|
|
3
|
+
"version": "2.2.0-beta.15",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"object-path": "^0.11.8",
|
|
22
22
|
"ses": "^1.14.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "4c471f6b7d26adc412b2cc1d91264572296ca873"
|
|
25
25
|
}
|