gcf-common-lib 0.25.52 → 0.25.54

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.52",
4
+ "version": "0.25.54",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
@@ -21,9 +21,9 @@
21
21
  "url": "https://github.com/TopTechnologies/gcf-common.git"
22
22
  },
23
23
  "dependencies": {
24
- "@google-cloud/pubsub": "^4.0.3",
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",
@@ -33,10 +33,10 @@
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.198",
39
- "@types/node": "^14.18.58"
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,38 +90,36 @@ 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, 'app-id': appId, env, 'request-id': requestId, } = yield this.safeGetAttributes(event, context, ['topic', 'exchange', 'queue']);
93
+ const { topic, exchange, queue, consumer_id, request_id, app_id, env } = yield this.safeGetAttributes(event, context, ['consumer_id', 'topic', 'exchange', 'queue']);
94
94
  console.timeEnd('safeGetAttributes');
95
95
  //
96
96
  console.time('publish');
97
97
  if (topic && !(0, isEmpty_1.default)(topic)) {
98
- console.log('send:', topic, appId, env, json, attributes);
98
+ console.log('send:', topic, app_id, env, json, attributes);
99
99
  yield exports.pubSub.topic(topic).publishMessage({
100
100
  json: json !== null && json !== void 0 ? json : {},
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 : '',
102
- //
103
- type: 'response', response: '1' }),
101
+ attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, v => '' + v)), { consumer_id: consumer_id !== null && consumer_id !== void 0 ? consumer_id : '', request_id: request_id !== null && request_id !== void 0 ? request_id : '', app_id: app_id !== null && app_id !== void 0 ? app_id : '', env: env !== null && env !== void 0 ? env : '' }),
104
102
  });
105
103
  }
106
104
  if (exchange && !(0, isEmpty_1.default)(exchange)) {
107
- console.log('send:', exchange, queue, appId, env, json, attributes);
105
+ console.log('send:', exchange, queue, app_id, env, json, attributes);
108
106
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
109
107
  yield ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
110
- 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: request_id }));
111
109
  }), this.amqpOptions.url);
112
110
  }
113
111
  else if (queue && !(0, isEmpty_1.default)(queue)) {
114
- console.log('send:', queue, appId, env, json, attributes);
112
+ console.log('send:', queue, app_id, env, json, attributes);
115
113
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
116
114
  yield ch.assertQueue(queue, this.amqpOptions.assertOptions);
117
- 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: request_id }));
118
116
  }), this.amqpOptions.url);
119
117
  }
120
118
  console.timeEnd('publish');
121
119
  });
122
120
  }
123
121
  static safeGetAttributes(event, context, props) {
124
- var _a, _b, _c, _d, _e, _f;
122
+ var _a, _b;
125
123
  return __awaiter(this, void 0, void 0, function* () {
126
124
  let metaOrAttr = this.getMetadataOrAttribute(event, context);
127
125
  // const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
@@ -135,7 +133,7 @@ class GcfCommon {
135
133
  metaOrAttr = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {};
136
134
  }
137
135
  }
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 });
136
+ return Object.assign(Object.assign({}, metaOrAttr), { app_id: metaOrAttr.app_id, request_id: metaOrAttr.request_id });
139
137
  });
140
138
  }
141
139
  static getOptions(event, context) {
package/src/index.ts CHANGED
@@ -70,14 +70,11 @@ 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
- topic,
75
- exchange,
76
- queue,
77
- 'app-id': appId,
78
- env,
79
- 'request-id': requestId,
80
- } = await this.safeGetAttributes(event, context, ['topic', 'exchange', 'queue']);
73
+ const { topic, exchange, queue, consumer_id, request_id, app_id, env } = await this.safeGetAttributes(
74
+ event,
75
+ context,
76
+ ['consumer_id', 'topic', 'exchange', 'queue'],
77
+ );
81
78
 
82
79
  console.timeEnd('safeGetAttributes');
83
80
 
@@ -86,34 +83,36 @@ export class GcfCommon {
86
83
  console.time('publish');
87
84
 
88
85
  if (topic && !isEmpty(topic)) {
89
- console.log('send:', topic, appId, env, json, attributes);
86
+ console.log('send:', topic, app_id, env, json, attributes);
90
87
  await pubSub.topic(topic).publishMessage({
91
88
  json: json ?? {},
92
89
  attributes: {
93
90
  ...mapValues(attributes ?? {}, v => '' + v),
94
- 'app-id': appId ?? '',
95
- appId: appId ?? '',
96
- 'request-id': requestId ?? '',
97
- requestId: requestId ?? '',
91
+ consumer_id: consumer_id ?? '',
92
+ request_id: request_id ?? '',
93
+ app_id: app_id ?? '',
98
94
  env: env ?? '',
99
- //
100
- type: 'response',
101
- response: '1',
102
95
  } as TMetadataOrAttributes,
103
96
  });
104
97
  }
105
98
 
106
99
  if (exchange && !isEmpty(exchange)) {
107
- console.log('send:', exchange, queue, appId, env, json, attributes);
100
+ console.log('send:', exchange, queue, app_id, env, json, attributes);
108
101
  await withAmqpCh(async ch => {
109
102
  await ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
110
- await publishAmqp(ch, exchange, queue ?? '', json ?? {}, this.amqpOptions.publishOptions);
103
+ await publishAmqp(ch, exchange, queue ?? '', json ?? {}, {
104
+ ...this.amqpOptions.publishOptions,
105
+ correlationId: request_id,
106
+ });
111
107
  }, this.amqpOptions.url as string);
112
108
  } else if (queue && !isEmpty(queue)) {
113
- console.log('send:', queue, appId, env, json, attributes);
109
+ console.log('send:', queue, app_id, env, json, attributes);
114
110
  await withAmqpCh(async ch => {
115
111
  await ch.assertQueue(queue, this.amqpOptions.assertOptions);
116
- await publishAmqp(ch, undefined, queue, json ?? {}, this.amqpOptions.publishOptions);
112
+ await publishAmqp(ch, undefined, queue, json ?? {}, {
113
+ ...this.amqpOptions.publishOptions,
114
+ correlationId: request_id,
115
+ });
117
116
  }, this.amqpOptions.url as string);
118
117
  }
119
118
 
@@ -137,10 +136,8 @@ export class GcfCommon {
137
136
 
138
137
  return {
139
138
  ...metaOrAttr,
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,
139
+ app_id: metaOrAttr.app_id,
140
+ request_id: metaOrAttr.request_id,
144
141
  } as TMetadataOrAttributes;
145
142
  }
146
143
 
package/src/types.ts CHANGED
@@ -31,26 +31,27 @@ 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]
35
+ consumer_id?: string; // for rpc response [GUID]
34
36
  topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
35
37
  exchange?: string; // response amqp exchange
36
38
  queue?: string; // response amqp queue
37
39
  //
38
40
  filename?: string;
39
41
  referer?: string;
40
- 'remote-address'?: string;
41
- 'upload-id'?: string;
42
- 'user-agent'?: string;
42
+ remote_address?: string;
43
+ upload_id?: string;
44
+ user_agent?: string;
43
45
  timestamp?: string;
44
46
  //
45
47
  action?: string;
46
48
  pipeline?: string;
47
49
  options?: string;
48
- 'job-uid'?: string;
49
- 'user-id'?: string;
50
- 'tenant-id'?: string;
50
+ job_uid?: string;
51
+ user_id?: string;
52
+ tenant_id?: string;
51
53
  //
52
- 'app-id'?: string; // app id
53
- 'request-id'?: string; // for rpc response [GUID]
54
+ app_id?: string; // app id
54
55
  env?: string; // app environment
55
56
  };
56
57