@chanzor/nest-leaf 0.0.1
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/dist/index.d.ts +16 -0
- package/dist/index.js +71 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +44 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ConfigService } from '../../node_modules/@nestjs/config';
|
|
2
|
+
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
3
|
+
|
|
4
|
+
export declare function buildConfigCorsOption(envAllowedCrossOrigin: string[]): CorsOptions;
|
|
5
|
+
|
|
6
|
+
export declare function isConfigProd(envMode: 'dev' | 'prod'): boolean;
|
|
7
|
+
|
|
8
|
+
export declare function optionalEnvAccessToken(configService: ConfigService, key: string): string | undefined;
|
|
9
|
+
|
|
10
|
+
export declare function optionalEnvAllowedCrossOrigin(configService: ConfigService<Record<string, unknown>, false>, key: string): string[] | undefined;
|
|
11
|
+
|
|
12
|
+
export declare function requireEnvMode(configService: ConfigService, key: string): 'dev' | 'prod';
|
|
13
|
+
|
|
14
|
+
export declare function requireEnvPort(configService: ConfigService, key: string): number;
|
|
15
|
+
|
|
16
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ForbiddenException as i } from "@nestjs/common";
|
|
2
|
+
function f(t) {
|
|
3
|
+
let n;
|
|
4
|
+
return t.length > 0 && (n = (e, r) => {
|
|
5
|
+
if (e === void 0) {
|
|
6
|
+
r(null, !0);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (typeof e != "string")
|
|
10
|
+
throw new i("Not allowed by CORS");
|
|
11
|
+
for (const o of t) {
|
|
12
|
+
if (o.includes("*") && new RegExp(`^${o.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`).test(e)) {
|
|
13
|
+
r(null, !0);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (o === e) {
|
|
17
|
+
r(null, !0);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw new i("Not allowed by CORS");
|
|
22
|
+
}), { origin: n, methods: ["GET"], credentials: !0, allowedHeaders: ["Content-Type", "x-access-token"] };
|
|
23
|
+
}
|
|
24
|
+
function d(t) {
|
|
25
|
+
switch (t) {
|
|
26
|
+
case "dev":
|
|
27
|
+
return !1;
|
|
28
|
+
case "prod":
|
|
29
|
+
return !0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function c(t, n) {
|
|
33
|
+
const e = t.get(n);
|
|
34
|
+
if (typeof e != "string") return;
|
|
35
|
+
const r = e.trim();
|
|
36
|
+
if (r.length)
|
|
37
|
+
return r;
|
|
38
|
+
}
|
|
39
|
+
function l(t, n) {
|
|
40
|
+
const e = t.get(n);
|
|
41
|
+
if (typeof e == "string")
|
|
42
|
+
return e.split(",").map((r) => r.trim());
|
|
43
|
+
}
|
|
44
|
+
function p(t, n) {
|
|
45
|
+
switch (t.get(n)) {
|
|
46
|
+
case "dev":
|
|
47
|
+
return "dev";
|
|
48
|
+
case "prod":
|
|
49
|
+
return "prod";
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`${n} is not defined`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function a(t, n) {
|
|
55
|
+
const e = t.get(n);
|
|
56
|
+
if (typeof e == "number") return e;
|
|
57
|
+
if (typeof e == "string") {
|
|
58
|
+
const r = parseInt(e);
|
|
59
|
+
if (!isNaN(r))
|
|
60
|
+
return r;
|
|
61
|
+
}
|
|
62
|
+
throw new Error(`${n} is not defined`);
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
f as buildConfigCorsOption,
|
|
66
|
+
d as isConfigProd,
|
|
67
|
+
c as optionalEnvAccessToken,
|
|
68
|
+
l as optionalEnvAllowedCrossOrigin,
|
|
69
|
+
p as requireEnvMode,
|
|
70
|
+
a as requireEnvPort
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@nestjs/common")):typeof define=="function"&&define.amd?define(["exports","@nestjs/common"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n["@chanzor/nest-leaf"]={},n.NestjsCommon))})(this,function(n,i){"use strict";function d(o){let t;return o.length>0&&(t=(e,r)=>{if(e===void 0){r(null,!0);return}if(typeof e!="string")throw new i.ForbiddenException("Not allowed by CORS");for(const s of o){if(s.includes("*")&&new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(e)){r(null,!0);return}if(s===e){r(null,!0);return}}throw new i.ForbiddenException("Not allowed by CORS")}),{origin:t,methods:["GET"],credentials:!0,allowedHeaders:["Content-Type","x-access-token"]}}function f(o){switch(o){case"dev":return!1;case"prod":return!0}}function u(o,t){const e=o.get(t);if(typeof e!="string")return;const r=e.trim();if(r.length)return r}function c(o,t){const e=o.get(t);if(typeof e=="string")return e.split(",").map(r=>r.trim())}function l(o,t){switch(o.get(t)){case"dev":return"dev";case"prod":return"prod";default:throw new Error(`${t} is not defined`)}}function p(o,t){const e=o.get(t);if(typeof e=="number")return e;if(typeof e=="string"){const r=parseInt(e);if(!isNaN(r))return r}throw new Error(`${t} is not defined`)}n.buildConfigCorsOption=d,n.isConfigProd=f,n.optionalEnvAccessToken=u,n.optionalEnvAllowedCrossOrigin=c,n.requireEnvMode=l,n.requireEnvPort=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chanzor/nest-leaf",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite build --watch",
|
|
7
|
+
"type-check": "tsc --noEmit",
|
|
8
|
+
"build": "npm run type-check && vite build",
|
|
9
|
+
"build-only": "vite build",
|
|
10
|
+
"format": "prettier --write src/"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.umd.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.umd.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@nestjs/common": "^11.1.11",
|
|
30
|
+
"@nestjs/config": "^4.0.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@chanzor/utils": "^0.1.6",
|
|
34
|
+
"@nestjs/common": "^11.1.11",
|
|
35
|
+
"@nestjs/config": "^4.0.2",
|
|
36
|
+
"@types/node": "^22.14.0",
|
|
37
|
+
"cors": "^2.8.5",
|
|
38
|
+
"prettier": "^3.5.3",
|
|
39
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
40
|
+
"typescript": "^5.8.3",
|
|
41
|
+
"vite": "^6.2.6",
|
|
42
|
+
"vite-plugin-dts": "^4.5.3"
|
|
43
|
+
}
|
|
44
|
+
}
|