gcf-common-lib 0.25.53 → 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.53",
4
+ "version": "0.25.54",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
package/src/index.js CHANGED
@@ -90,36 +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)), { '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 : '' }),
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 : '' }),
102
102
  });
103
103
  }
104
104
  if (exchange && !(0, isEmpty_1.default)(exchange)) {
105
- console.log('send:', exchange, queue, appId, env, json, attributes);
105
+ console.log('send:', exchange, queue, app_id, env, json, attributes);
106
106
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
107
107
  yield ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
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 }));
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 }));
109
109
  }), this.amqpOptions.url);
110
110
  }
111
111
  else if (queue && !(0, isEmpty_1.default)(queue)) {
112
- console.log('send:', queue, appId, env, json, attributes);
112
+ console.log('send:', queue, app_id, env, json, attributes);
113
113
  yield (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
114
114
  yield ch.assertQueue(queue, this.amqpOptions.assertOptions);
115
- yield (0, utils_1.publishAmqp)(ch, undefined, queue, json !== null && json !== void 0 ? json : {}, Object.assign(Object.assign({}, this.amqpOptions.publishOptions), { correlationId: requestId }));
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 }));
116
116
  }), this.amqpOptions.url);
117
117
  }
118
118
  console.timeEnd('publish');
119
119
  });
120
120
  }
121
121
  static safeGetAttributes(event, context, props) {
122
- var _a, _b, _c, _d, _e, _f;
122
+ var _a, _b;
123
123
  return __awaiter(this, void 0, void 0, function* () {
124
124
  let metaOrAttr = this.getMetadataOrAttribute(event, context);
125
125
  // const everyPropIsNil = props.map(prop => get(metaOrAttr, prop)).every(v => isNil(v));
@@ -133,7 +133,7 @@ class GcfCommon {
133
133
  metaOrAttr = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {};
134
134
  }
135
135
  }
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 });
136
+ return Object.assign(Object.assign({}, metaOrAttr), { app_id: metaOrAttr.app_id, request_id: metaOrAttr.request_id });
137
137
  });
138
138
  }
139
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,36 +83,35 @@ 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
- 'request-id': requestId ?? '',
95
- requestId: requestId ?? '',
96
- 'app-id': appId ?? '',
97
- appId: appId ?? '',
91
+ consumer_id: consumer_id ?? '',
92
+ request_id: request_id ?? '',
93
+ app_id: app_id ?? '',
98
94
  env: env ?? '',
99
95
  } as TMetadataOrAttributes,
100
96
  });
101
97
  }
102
98
 
103
99
  if (exchange && !isEmpty(exchange)) {
104
- console.log('send:', exchange, queue, appId, env, json, attributes);
100
+ console.log('send:', exchange, queue, app_id, env, json, attributes);
105
101
  await withAmqpCh(async ch => {
106
102
  await ch.assertExchange(exchange, 'direct', this.amqpOptions.assertExchange);
107
103
  await publishAmqp(ch, exchange, queue ?? '', json ?? {}, {
108
104
  ...this.amqpOptions.publishOptions,
109
- correlationId: requestId,
105
+ correlationId: request_id,
110
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
112
  await publishAmqp(ch, undefined, queue, json ?? {}, {
117
113
  ...this.amqpOptions.publishOptions,
118
- correlationId: requestId,
114
+ correlationId: request_id,
119
115
  });
120
116
  }, this.amqpOptions.url as string);
121
117
  }
@@ -140,10 +136,8 @@ export class GcfCommon {
140
136
 
141
137
  return {
142
138
  ...metaOrAttr,
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,
139
+ app_id: metaOrAttr.app_id,
140
+ request_id: metaOrAttr.request_id,
147
141
  } as TMetadataOrAttributes;
148
142
  }
149
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]
34
+ request_id?: string; // for rpc response [GUID]
35
+ consumer_id?: string; // for rpc response [GUID]
35
36
  topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
36
37
  exchange?: string; // response amqp exchange
37
38
  queue?: string; // response amqp queue
38
39
  //
39
40
  filename?: string;
40
41
  referer?: string;
41
- 'remote-address'?: string;
42
- 'upload-id'?: string;
43
- 'user-agent'?: string;
42
+ remote_address?: string;
43
+ upload_id?: string;
44
+ user_agent?: string;
44
45
  timestamp?: string;
45
46
  //
46
47
  action?: string;
47
48
  pipeline?: string;
48
49
  options?: string;
49
- 'job-uid'?: string;
50
- 'user-id'?: string;
51
- 'tenant-id'?: string;
50
+ job_uid?: string;
51
+ user_id?: string;
52
+ tenant_id?: string;
52
53
  //
53
- 'app-id'?: string; // app id
54
+ app_id?: string; // app id
54
55
  env?: string; // app environment
55
56
  };
56
57