@cryptexlabs/codex-nodejs-common 0.16.0 → 0.16.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/lib/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function ApiMetaHeaders(): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
1
|
+
export declare function ApiMetaHeaders(required?: boolean): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -4,18 +4,22 @@ exports.ApiMetaHeaders = ApiMetaHeaders;
|
|
|
4
4
|
const swagger_1 = require("@nestjs/swagger");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
|
-
function ApiMetaHeaders() {
|
|
7
|
+
function ApiMetaHeaders(required = undefined) {
|
|
8
8
|
return (0, common_1.applyDecorators)(...[
|
|
9
9
|
(0, swagger_1.ApiHeader)({
|
|
10
10
|
name: "X-Correlation-Id",
|
|
11
|
-
required:
|
|
11
|
+
required: required !== undefined
|
|
12
|
+
? required
|
|
13
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
12
14
|
schema: {
|
|
13
15
|
example: (0, uuid_1.v4)(),
|
|
14
16
|
},
|
|
15
17
|
}),
|
|
16
18
|
(0, swagger_1.ApiHeader)({
|
|
17
19
|
name: "Accept-Language",
|
|
18
|
-
required:
|
|
20
|
+
required: required !== undefined
|
|
21
|
+
? required
|
|
22
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
19
23
|
schema: {
|
|
20
24
|
example: "en-US",
|
|
21
25
|
},
|
|
@@ -23,7 +27,9 @@ function ApiMetaHeaders() {
|
|
|
23
27
|
(0, swagger_1.ApiHeader)({
|
|
24
28
|
name: "X-Started",
|
|
25
29
|
description: "The time that the very first user initiated or time initiated event that eventually lead to this api being called was created",
|
|
26
|
-
required:
|
|
30
|
+
required: required !== undefined
|
|
31
|
+
? required
|
|
32
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
27
33
|
schema: {
|
|
28
34
|
example: new Date().toISOString(),
|
|
29
35
|
},
|
|
@@ -31,7 +37,9 @@ function ApiMetaHeaders() {
|
|
|
31
37
|
(0, swagger_1.ApiHeader)({
|
|
32
38
|
name: "X-Context-Category",
|
|
33
39
|
description: "A category for the context of the request. For example 'test' or 'performance test'",
|
|
34
|
-
required:
|
|
40
|
+
required: required !== undefined
|
|
41
|
+
? required
|
|
42
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
35
43
|
schema: {
|
|
36
44
|
example: "default",
|
|
37
45
|
},
|
|
@@ -39,7 +47,9 @@ function ApiMetaHeaders() {
|
|
|
39
47
|
(0, swagger_1.ApiHeader)({
|
|
40
48
|
name: "X-Context-Id",
|
|
41
49
|
description: "A unique context identifier used for correlating logs and metrics usually for performance or experimental testing",
|
|
42
|
-
required:
|
|
50
|
+
required: required !== undefined
|
|
51
|
+
? required
|
|
52
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
43
53
|
schema: {
|
|
44
54
|
example: "none",
|
|
45
55
|
},
|
|
@@ -47,7 +57,9 @@ function ApiMetaHeaders() {
|
|
|
47
57
|
(0, swagger_1.ApiHeader)({
|
|
48
58
|
name: "X-Client-Id",
|
|
49
59
|
description: "A unique identifier for the client to help identify exactly which application or third party is making the requests",
|
|
50
|
-
required:
|
|
60
|
+
required: required !== undefined
|
|
61
|
+
? required
|
|
62
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
51
63
|
schema: {},
|
|
52
64
|
examples: {
|
|
53
65
|
UUIDV4: {
|
|
@@ -61,7 +73,9 @@ function ApiMetaHeaders() {
|
|
|
61
73
|
(0, swagger_1.ApiHeader)({
|
|
62
74
|
name: "X-Client-Name",
|
|
63
75
|
description: "The name of the client",
|
|
64
|
-
required:
|
|
76
|
+
required: required !== undefined
|
|
77
|
+
? required
|
|
78
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
65
79
|
schema: {
|
|
66
80
|
example: "swagger",
|
|
67
81
|
},
|
|
@@ -70,7 +84,9 @@ function ApiMetaHeaders() {
|
|
|
70
84
|
name: "X-Client-Version",
|
|
71
85
|
description: "The version of the client. If the client is making bad requests this helps " +
|
|
72
86
|
"identify which version of the client is making the bad requests",
|
|
73
|
-
required:
|
|
87
|
+
required: required !== undefined
|
|
88
|
+
? required
|
|
89
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
74
90
|
schema: {
|
|
75
91
|
example: "0.3.6",
|
|
76
92
|
},
|
|
@@ -78,7 +94,9 @@ function ApiMetaHeaders() {
|
|
|
78
94
|
(0, swagger_1.ApiHeader)({
|
|
79
95
|
name: "X-Client-Variant",
|
|
80
96
|
description: "Usually an environment or build type such as dev, test, or prod",
|
|
81
|
-
required:
|
|
97
|
+
required: required !== undefined
|
|
98
|
+
? required
|
|
99
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
82
100
|
schema: {
|
|
83
101
|
example: "dev",
|
|
84
102
|
},
|
|
@@ -86,7 +104,9 @@ function ApiMetaHeaders() {
|
|
|
86
104
|
(0, swagger_1.ApiHeader)({
|
|
87
105
|
name: "X-Created",
|
|
88
106
|
description: "The time the client initiated the http request",
|
|
89
|
-
required:
|
|
107
|
+
required: required !== undefined
|
|
108
|
+
? required
|
|
109
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
90
110
|
schema: {
|
|
91
111
|
example: new Date().toISOString(),
|
|
92
112
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-meta-headers.js","sourceRoot":"","sources":["../../../src/decorator/api-meta-headers.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"api-meta-headers.js","sourceRoot":"","sources":["../../../src/decorator/api-meta-headers.ts"],"names":[],"mappings":";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CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,OAAO;YACrD,MAAM,EAAE;gBACN,OAAO,EAAE,KAAK;aACf;SACF,CAAC;QACF,IAAA,mBAAS,EAAC;YACR,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EACN,QAAQ,KAAK,SAAS;gBACpB,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,OAAO;YACrD,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aAClC;SACF,CAAC;QACF,IAAA,mBAAS,EAAC;YACR,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE;gBACN,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aAClC;SACF,CAAC;QACF,IAAA,mBAAS,EAAC;YACR,IAAI,EAAE,YAAY;YAClB,WAAW,EACT,yEAAyE;YAC3E,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE;gBACN,OAAO,EAAE,iBAAiB;aAC3B;SACF,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,19 +2,25 @@ import { ApiHeader } from "@nestjs/swagger";
|
|
|
2
2
|
import { applyDecorators } from "@nestjs/common";
|
|
3
3
|
import { v4 as uuidV4 } from "uuid";
|
|
4
4
|
|
|
5
|
-
export function ApiMetaHeaders() {
|
|
5
|
+
export function ApiMetaHeaders(required: boolean = undefined) {
|
|
6
6
|
return applyDecorators(
|
|
7
7
|
...[
|
|
8
8
|
ApiHeader({
|
|
9
9
|
name: "X-Correlation-Id",
|
|
10
|
-
required:
|
|
10
|
+
required:
|
|
11
|
+
required !== undefined
|
|
12
|
+
? required
|
|
13
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
11
14
|
schema: {
|
|
12
15
|
example: uuidV4(),
|
|
13
16
|
},
|
|
14
17
|
}),
|
|
15
18
|
ApiHeader({
|
|
16
19
|
name: "Accept-Language",
|
|
17
|
-
required:
|
|
20
|
+
required:
|
|
21
|
+
required !== undefined
|
|
22
|
+
? required
|
|
23
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
18
24
|
schema: {
|
|
19
25
|
example: "en-US",
|
|
20
26
|
},
|
|
@@ -23,7 +29,10 @@ export function ApiMetaHeaders() {
|
|
|
23
29
|
name: "X-Started",
|
|
24
30
|
description:
|
|
25
31
|
"The time that the very first user initiated or time initiated event that eventually lead to this api being called was created",
|
|
26
|
-
required:
|
|
32
|
+
required:
|
|
33
|
+
required !== undefined
|
|
34
|
+
? required
|
|
35
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
27
36
|
schema: {
|
|
28
37
|
example: new Date().toISOString(),
|
|
29
38
|
},
|
|
@@ -32,7 +41,10 @@ export function ApiMetaHeaders() {
|
|
|
32
41
|
name: "X-Context-Category",
|
|
33
42
|
description:
|
|
34
43
|
"A category for the context of the request. For example 'test' or 'performance test'",
|
|
35
|
-
required:
|
|
44
|
+
required:
|
|
45
|
+
required !== undefined
|
|
46
|
+
? required
|
|
47
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
36
48
|
schema: {
|
|
37
49
|
example: "default",
|
|
38
50
|
},
|
|
@@ -41,7 +53,10 @@ export function ApiMetaHeaders() {
|
|
|
41
53
|
name: "X-Context-Id",
|
|
42
54
|
description:
|
|
43
55
|
"A unique context identifier used for correlating logs and metrics usually for performance or experimental testing",
|
|
44
|
-
required:
|
|
56
|
+
required:
|
|
57
|
+
required !== undefined
|
|
58
|
+
? required
|
|
59
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
45
60
|
schema: {
|
|
46
61
|
example: "none",
|
|
47
62
|
},
|
|
@@ -50,7 +65,10 @@ export function ApiMetaHeaders() {
|
|
|
50
65
|
name: "X-Client-Id",
|
|
51
66
|
description:
|
|
52
67
|
"A unique identifier for the client to help identify exactly which application or third party is making the requests",
|
|
53
|
-
required:
|
|
68
|
+
required:
|
|
69
|
+
required !== undefined
|
|
70
|
+
? required
|
|
71
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
54
72
|
schema: {},
|
|
55
73
|
examples: {
|
|
56
74
|
UUIDV4: {
|
|
@@ -64,7 +82,10 @@ export function ApiMetaHeaders() {
|
|
|
64
82
|
ApiHeader({
|
|
65
83
|
name: "X-Client-Name",
|
|
66
84
|
description: "The name of the client",
|
|
67
|
-
required:
|
|
85
|
+
required:
|
|
86
|
+
required !== undefined
|
|
87
|
+
? required
|
|
88
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
68
89
|
schema: {
|
|
69
90
|
example: "swagger",
|
|
70
91
|
},
|
|
@@ -74,7 +95,10 @@ export function ApiMetaHeaders() {
|
|
|
74
95
|
description:
|
|
75
96
|
"The version of the client. If the client is making bad requests this helps " +
|
|
76
97
|
"identify which version of the client is making the bad requests",
|
|
77
|
-
required:
|
|
98
|
+
required:
|
|
99
|
+
required !== undefined
|
|
100
|
+
? required
|
|
101
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
78
102
|
schema: {
|
|
79
103
|
example: "0.3.6",
|
|
80
104
|
},
|
|
@@ -83,7 +107,10 @@ export function ApiMetaHeaders() {
|
|
|
83
107
|
name: "X-Client-Variant",
|
|
84
108
|
description:
|
|
85
109
|
"Usually an environment or build type such as dev, test, or prod",
|
|
86
|
-
required:
|
|
110
|
+
required:
|
|
111
|
+
required !== undefined
|
|
112
|
+
? required
|
|
113
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
87
114
|
schema: {
|
|
88
115
|
example: "dev",
|
|
89
116
|
},
|
|
@@ -91,7 +118,10 @@ export function ApiMetaHeaders() {
|
|
|
91
118
|
ApiHeader({
|
|
92
119
|
name: "X-Created",
|
|
93
120
|
description: "The time the client initiated the http request",
|
|
94
|
-
required:
|
|
121
|
+
required:
|
|
122
|
+
required !== undefined
|
|
123
|
+
? required
|
|
124
|
+
: process.env.X_META_HEADERS_REQUIRED !== "false",
|
|
95
125
|
schema: {
|
|
96
126
|
example: new Date().toISOString(),
|
|
97
127
|
},
|