gcf-common-lib 0.25.50 → 0.25.52
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/package.json +5 -5
- package/src/index.js +4 -8
- package/src/index.ts +16 -9
- package/src/types.ts +28 -30
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-common-lib",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.52",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"branches": [
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
"url": "https://github.com/TopTechnologies/gcf-common.git"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@google-cloud/pubsub": "^4.0.
|
|
24
|
+
"@google-cloud/pubsub": "^4.0.3",
|
|
25
25
|
"@google-cloud/secret-manager": "^5.0.0",
|
|
26
26
|
"@google-cloud/storage": "^7.0.1",
|
|
27
27
|
"amqplib": "^0.10.3",
|
|
28
28
|
"bluebird": "^3.7.2",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
30
|
"moment": "^2.29.4",
|
|
31
|
-
"mongodb": "^4.
|
|
31
|
+
"mongodb": "^4.17.1",
|
|
32
32
|
"rxjs": "^7.8.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@tsconfig/node14": "^14.1.0",
|
|
36
36
|
"@types/amqplib": "^0.10.1",
|
|
37
37
|
"@types/bluebird": "^3.5.38",
|
|
38
|
-
"@types/lodash": "^4.14.
|
|
39
|
-
"@types/node": "^14.18.
|
|
38
|
+
"@types/lodash": "^4.14.198",
|
|
39
|
+
"@types/node": "^14.18.58"
|
|
40
40
|
},
|
|
41
41
|
"author": "alert83@gmail.com",
|
|
42
42
|
"license": ""
|
package/src/index.js
CHANGED
|
@@ -90,11 +90,7 @@ class GcfCommon {
|
|
|
90
90
|
static publish(event, context, json, attributes) {
|
|
91
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
92
|
console.time('safeGetAttributes');
|
|
93
|
-
const { topic, exchange, queue, appId, env, requestId } = yield this.safeGetAttributes(event, context, [
|
|
94
|
-
'topic',
|
|
95
|
-
'exchange',
|
|
96
|
-
'queue',
|
|
97
|
-
]);
|
|
93
|
+
const { topic, exchange, queue, 'app-id': appId, env, 'request-id': requestId, } = yield this.safeGetAttributes(event, context, ['topic', 'exchange', 'queue']);
|
|
98
94
|
console.timeEnd('safeGetAttributes');
|
|
99
95
|
//
|
|
100
96
|
console.time('publish');
|
|
@@ -102,7 +98,7 @@ class GcfCommon {
|
|
|
102
98
|
console.log('send:', topic, appId, env, json, attributes);
|
|
103
99
|
yield exports.pubSub.topic(topic).publishMessage({
|
|
104
100
|
json: json !== null && json !== void 0 ? json : {},
|
|
105
|
-
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), { appId: appId !== null && appId !== void 0 ? appId : '',
|
|
101
|
+
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), { 'app-id': appId !== null && appId !== void 0 ? appId : '', appId: appId !== null && appId !== void 0 ? appId : '', 'request-id': requestId !== null && requestId !== void 0 ? requestId : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '', env: env !== null && env !== void 0 ? env : '',
|
|
106
102
|
//
|
|
107
103
|
type: 'response', response: '1' }),
|
|
108
104
|
});
|
|
@@ -125,7 +121,7 @@ class GcfCommon {
|
|
|
125
121
|
});
|
|
126
122
|
}
|
|
127
123
|
static safeGetAttributes(event, context, props) {
|
|
128
|
-
var _a, _b, _c, _d;
|
|
124
|
+
var _a, _b, _c, _d, _e, _f;
|
|
129
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
126
|
let metaOrAttr = this.getMetadataOrAttribute(event, context);
|
|
131
127
|
// const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
|
|
@@ -139,7 +135,7 @@ class GcfCommon {
|
|
|
139
135
|
metaOrAttr = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {};
|
|
140
136
|
}
|
|
141
137
|
}
|
|
142
|
-
return Object.assign(Object.assign({}, metaOrAttr), {
|
|
138
|
+
return Object.assign(Object.assign({}, metaOrAttr), { 'app-id': (_c = metaOrAttr['app-id']) !== null && _c !== void 0 ? _c : metaOrAttr.appId, appId: (_d = metaOrAttr['app-id']) !== null && _d !== void 0 ? _d : metaOrAttr.appId, 'request-id': (_e = metaOrAttr['request-id']) !== null && _e !== void 0 ? _e : metaOrAttr.requestId, requestId: (_f = metaOrAttr['request-id']) !== null && _f !== void 0 ? _f : metaOrAttr.requestId });
|
|
143
139
|
});
|
|
144
140
|
}
|
|
145
141
|
static getOptions(event, context) {
|
package/src/index.ts
CHANGED
|
@@ -70,11 +70,14 @@ export class GcfCommon {
|
|
|
70
70
|
static async publish<E = TEvent>(event: E, context: TContext, json?: TResponse, attributes?: Dict<any>) {
|
|
71
71
|
console.time('safeGetAttributes');
|
|
72
72
|
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const {
|
|
74
|
+
topic,
|
|
75
|
+
exchange,
|
|
76
|
+
queue,
|
|
77
|
+
'app-id': appId,
|
|
78
|
+
env,
|
|
79
|
+
'request-id': requestId,
|
|
80
|
+
} = await this.safeGetAttributes(event, context, ['topic', 'exchange', 'queue']);
|
|
78
81
|
|
|
79
82
|
console.timeEnd('safeGetAttributes');
|
|
80
83
|
|
|
@@ -88,13 +91,15 @@ export class GcfCommon {
|
|
|
88
91
|
json: json ?? {},
|
|
89
92
|
attributes: {
|
|
90
93
|
...mapValues(attributes ?? {}, v => '' + v),
|
|
94
|
+
'app-id': appId ?? '',
|
|
91
95
|
appId: appId ?? '',
|
|
92
|
-
|
|
96
|
+
'request-id': requestId ?? '',
|
|
93
97
|
requestId: requestId ?? '',
|
|
98
|
+
env: env ?? '',
|
|
94
99
|
//
|
|
95
100
|
type: 'response',
|
|
96
101
|
response: '1',
|
|
97
|
-
},
|
|
102
|
+
} as TMetadataOrAttributes,
|
|
98
103
|
});
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -132,8 +137,10 @@ export class GcfCommon {
|
|
|
132
137
|
|
|
133
138
|
return {
|
|
134
139
|
...metaOrAttr,
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
'app-id': metaOrAttr['app-id'] ?? (metaOrAttr as any).appId,
|
|
141
|
+
appId: metaOrAttr['app-id'] ?? (metaOrAttr as any).appId,
|
|
142
|
+
'request-id': metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
|
|
143
|
+
requestId: metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
|
|
137
144
|
} as TMetadataOrAttributes;
|
|
138
145
|
}
|
|
139
146
|
|
package/src/types.ts
CHANGED
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
import Dict = NodeJS.Dict;
|
|
2
2
|
|
|
3
|
-
export type TMetadataOrAttributes = {
|
|
4
|
-
topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
|
|
5
|
-
exchange?: string; // response amqp exchange
|
|
6
|
-
queue?: string; // response amqp queue
|
|
7
|
-
//
|
|
8
|
-
filename?: string;
|
|
9
|
-
referer?: string;
|
|
10
|
-
'remote-address'?: string;
|
|
11
|
-
'upload-id'?: string;
|
|
12
|
-
'user-agent'?: string;
|
|
13
|
-
timestamp?: string;
|
|
14
|
-
//
|
|
15
|
-
action?: string;
|
|
16
|
-
pipeline?: string;
|
|
17
|
-
options?: string;
|
|
18
|
-
'job-uid'?: string;
|
|
19
|
-
'user-id'?: string;
|
|
20
|
-
'tenant-id'?: string;
|
|
21
|
-
//
|
|
22
|
-
env?: string; // app environment
|
|
23
|
-
appId?: string; // app id
|
|
24
|
-
'app-id'?: string; // app id
|
|
25
|
-
requestId?: string; // for rpc response [GUID]
|
|
26
|
-
'request-id'?: string; // for rpc response [GUID]
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type TGSEvent = {
|
|
3
|
+
export type TGSEvent<M = TMetadataOrAttributes> = {
|
|
30
4
|
bucket: string;
|
|
31
5
|
contentType: string;
|
|
32
6
|
crc32c: string;
|
|
@@ -36,7 +10,7 @@ export type TGSEvent = {
|
|
|
36
10
|
kind: string; // 'storage#object'
|
|
37
11
|
md5Hash: string;
|
|
38
12
|
mediaLink: string;
|
|
39
|
-
metadata:
|
|
13
|
+
metadata: M;
|
|
40
14
|
metageneration: string;
|
|
41
15
|
name: string;
|
|
42
16
|
selfLink: string;
|
|
@@ -47,15 +21,39 @@ export type TGSEvent = {
|
|
|
47
21
|
updated: string;
|
|
48
22
|
};
|
|
49
23
|
|
|
50
|
-
export type TPSEvent = {
|
|
24
|
+
export type TPSEvent<A = TMetadataOrAttributes> = {
|
|
51
25
|
'@type': string; // 'type.googleapis.com/google.pubsub.v1.PubsubMessage'
|
|
52
|
-
attributes?:
|
|
26
|
+
attributes?: A;
|
|
53
27
|
data?: string;
|
|
54
28
|
json?: Dict<any>;
|
|
55
29
|
};
|
|
56
30
|
|
|
57
31
|
export type TEvent = TGSEvent | TPSEvent;
|
|
58
32
|
|
|
33
|
+
export type TMetadataOrAttributes = {
|
|
34
|
+
topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
|
|
35
|
+
exchange?: string; // response amqp exchange
|
|
36
|
+
queue?: string; // response amqp queue
|
|
37
|
+
//
|
|
38
|
+
filename?: string;
|
|
39
|
+
referer?: string;
|
|
40
|
+
'remote-address'?: string;
|
|
41
|
+
'upload-id'?: string;
|
|
42
|
+
'user-agent'?: string;
|
|
43
|
+
timestamp?: string;
|
|
44
|
+
//
|
|
45
|
+
action?: string;
|
|
46
|
+
pipeline?: string;
|
|
47
|
+
options?: string;
|
|
48
|
+
'job-uid'?: string;
|
|
49
|
+
'user-id'?: string;
|
|
50
|
+
'tenant-id'?: string;
|
|
51
|
+
//
|
|
52
|
+
'app-id'?: string; // app id
|
|
53
|
+
'request-id'?: string; // for rpc response [GUID]
|
|
54
|
+
env?: string; // app environment
|
|
55
|
+
};
|
|
56
|
+
|
|
59
57
|
export type TContext = {
|
|
60
58
|
eventId: string;
|
|
61
59
|
timestamp: string;
|