gcf-common-lib 0.25.51 → 0.25.53

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.25.51",
4
+ "version": "0.25.53",
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.1",
25
- "@google-cloud/secret-manager": "^5.0.0",
26
- "@google-cloud/storage": "^7.0.1",
24
+ "@google-cloud/pubsub": "^4.0.6",
25
+ "@google-cloud/secret-manager": "^5.0.1",
26
+ "@google-cloud/storage": "^7.3.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.16.0",
31
+ "mongodb": "^4.17.1",
32
32
  "rxjs": "^7.8.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@tsconfig/node14": "^14.1.0",
36
- "@types/amqplib": "^0.10.1",
37
- "@types/bluebird": "^3.5.38",
38
- "@types/lodash": "^4.14.197",
39
- "@types/node": "^14.18.54"
36
+ "@types/amqplib": "^0.10.3",
37
+ "@types/bluebird": "^3.5.41",
38
+ "@types/lodash": "^4.14.200",
39
+ "@types/node": "^14.18.63"
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,30 +98,28 @@ 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 : '', env: env !== null && env !== void 0 ? env : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '',
106
- //
107
- type: 'response', response: '1' }),
101
+ attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), { 'request-id': requestId !== null && requestId !== void 0 ? requestId : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '', 'app-id': appId !== null && appId !== void 0 ? appId : '', appId: appId !== null && appId !== void 0 ? appId : '', env: env !== null && env !== void 0 ? env : '' }),
108
102
  });
109
103
  }
110
104
  if (exchange && !(0, isEmpty_1.default)(exchange)) {
111
105
  console.log('send:', exchange, queue, appId, env, json, attributes);
112
106
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
113
107
  yield ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
114
- yield (0, utils_1.publishAmqp)(ch, exchange, queue !== null && queue !== void 0 ? queue : '', json !== null && json !== void 0 ? json : {}, this.amqpOptions.publishOptions);
108
+ yield (0, utils_1.publishAmqp)(ch, exchange, queue !== null && queue !== void 0 ? queue : '', json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId: requestId }));
115
109
  }), this.amqpOptions.url);
116
110
  }
117
111
  else if (queue && !(0, isEmpty_1.default)(queue)) {
118
112
  console.log('send:', queue, appId, env, json, attributes);
119
113
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
120
114
  yield ch.assertQueue(queue, this.amqpOptions.assertOptions);
121
- yield (0, utils_1.publishAmqp)(ch, undefined, queue, json !== null && json !== void 0 ? json : {}, this.amqpOptions.publishOptions);
115
+ yield (0, utils_1.publishAmqp)(ch, undefined, queue, json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId: requestId }));
122
116
  }), this.amqpOptions.url);
123
117
  }
124
118
  console.timeEnd('publish');
125
119
  });
126
120
  }
127
121
  static safeGetAttributes(event, context, props) {
128
- var _a, _b, _c, _d;
122
+ var _a, _b, _c, _d, _e, _f;
129
123
  return __awaiter(this, void 0, void 0, function* () {
130
124
  let metaOrAttr = this.getMetadataOrAttribute(event, context);
131
125
  // const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
@@ -139,7 +133,7 @@ class GcfCommon {
139
133
  metaOrAttr = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {};
140
134
  }
141
135
  }
142
- return Object.assign(Object.assign({}, metaOrAttr), { appId: (_c = metaOrAttr.appId) !== null && _c !== void 0 ? _c : metaOrAttr['app-id'], requestId: (_d = metaOrAttr.requestId) !== null && _d !== void 0 ? _d : metaOrAttr['request-id'] });
136
+ 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
137
  });
144
138
  }
145
139
  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 { topic, exchange, queue, appId, env, requestId } = await this.safeGetAttributes(event, context, [
74
- 'topic',
75
- 'exchange',
76
- 'queue',
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,12 @@ export class GcfCommon {
88
91
  json: json ?? {},
89
92
  attributes: {
90
93
  ...mapValues(attributes ?? {}, v => '' + v),
94
+ 'request-id': requestId ?? '',
95
+ requestId: requestId ?? '',
96
+ 'app-id': appId ?? '',
91
97
  appId: appId ?? '',
92
98
  env: env ?? '',
93
- requestId: requestId ?? '',
94
- //
95
- type: 'response',
96
- response: '1',
97
- },
99
+ } as TMetadataOrAttributes,
98
100
  });
99
101
  }
100
102
 
@@ -102,13 +104,19 @@ export class GcfCommon {
102
104
  console.log('send:', exchange, queue, appId, env, json, attributes);
103
105
  await withAmqpCh(async ch => {
104
106
  await ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
105
- await publishAmqp(ch, exchange, queue ?? '', json ?? {}, this.amqpOptions.publishOptions);
107
+ await publishAmqp(ch, exchange, queue ?? '', json ?? {}, {
108
+ ...this.amqpOptions.publishOptions,
109
+ correlationId: requestId,
110
+ });
106
111
  }, this.amqpOptions.url as string);
107
112
  } else if (queue && !isEmpty(queue)) {
108
113
  console.log('send:', queue, appId, env, json, attributes);
109
114
  await withAmqpCh(async ch => {
110
115
  await ch.assertQueue(queue, this.amqpOptions.assertOptions);
111
- await publishAmqp(ch, undefined, queue, json ?? {}, this.amqpOptions.publishOptions);
116
+ await publishAmqp(ch, undefined, queue, json ?? {}, {
117
+ ...this.amqpOptions.publishOptions,
118
+ correlationId: requestId,
119
+ });
112
120
  }, this.amqpOptions.url as string);
113
121
  }
114
122
 
@@ -132,8 +140,10 @@ export class GcfCommon {
132
140
 
133
141
  return {
134
142
  ...metaOrAttr,
135
- appId: metaOrAttr.appId ?? metaOrAttr['app-id'],
136
- requestId: metaOrAttr.requestId ?? metaOrAttr['request-id'],
143
+ 'app-id': metaOrAttr['app-id'] ?? (metaOrAttr as any).appId,
144
+ appId: metaOrAttr['app-id'] ?? (metaOrAttr as any).appId,
145
+ 'request-id': metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
146
+ requestId: metaOrAttr['request-id'] ?? (metaOrAttr as any).requestId,
137
147
  } as TMetadataOrAttributes;
138
148
  }
139
149
 
package/src/types.ts CHANGED
@@ -31,6 +31,7 @@ export type TPSEvent<A = TMetadataOrAttributes> = {
31
31
  export type TEvent = TGSEvent | TPSEvent;
32
32
 
33
33
  export type TMetadataOrAttributes = {
34
+ 'request-id'?: string; // for rpc response [GUID]
34
35
  topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
35
36
  exchange?: string; // response amqp exchange
36
37
  queue?: string; // response amqp queue
@@ -49,11 +50,8 @@ export type TMetadataOrAttributes = {
49
50
  'user-id'?: string;
50
51
  'tenant-id'?: string;
51
52
  //
52
- env?: string; // app environment
53
- appId?: string; // app id
54
53
  'app-id'?: string; // app id
55
- requestId?: string; // for rpc response [GUID]
56
- 'request-id'?: string; // for rpc response [GUID]
54
+ env?: string; // app environment
57
55
  };
58
56
 
59
57
  export type TContext = {