gcf-common-lib 0.25.51 → 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 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.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.1",
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.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
36
  "@types/amqplib": "^0.10.1",
37
37
  "@types/bluebird": "^3.5.38",
38
- "@types/lodash": "^4.14.197",
39
- "@types/node": "^14.18.54"
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 : '', env: env !== null && env !== void 0 ? env : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '',
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), { appId: (_c = metaOrAttr.appId) !== null && _c !== void 0 ? _c : metaOrAttr['app-id'], requestId: (_d = metaOrAttr.requestId) !== null && _d !== void 0 ? _d : metaOrAttr['request-id'] });
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 { 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,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
- env: env ?? '',
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
- appId: metaOrAttr.appId ?? metaOrAttr['app-id'],
136
- requestId: metaOrAttr.requestId ?? metaOrAttr['request-id'],
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
@@ -49,11 +49,9 @@ export type TMetadataOrAttributes = {
49
49
  'user-id'?: string;
50
50
  'tenant-id'?: string;
51
51
  //
52
- env?: string; // app environment
53
- appId?: string; // app id
54
52
  'app-id'?: string; // app id
55
- requestId?: string; // for rpc response [GUID]
56
53
  'request-id'?: string; // for rpc response [GUID]
54
+ env?: string; // app environment
57
55
  };
58
56
 
59
57
  export type TContext = {