gcf-common-lib 0.21.0 → 0.21.2

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.21.0",
4
+ "version": "0.21.2",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
package/src/index.js CHANGED
@@ -96,15 +96,24 @@ class GcfCommon {
96
96
  });
97
97
  }
98
98
  static getOptions(event, context) {
99
- var _a, _b, _c, _d, _e;
99
+ var _a, _b, _c, _d, _e, _f, _g;
100
100
  return __awaiter(this, void 0, void 0, function* () {
101
- if ((_a = event === null || event === void 0 ? void 0 : event.metadata) === null || _a === void 0 ? void 0 : _a.options) {
102
- return JSON.parse((_c = (_b = event === null || event === void 0 ? void 0 : event.metadata) === null || _b === void 0 ? void 0 : _b.options) !== null && _c !== void 0 ? _c : '{}');
103
- }
104
- else {
105
- const file = exports.storage.bucket(event.bucket).file(event.name);
106
- const [meta] = yield file.getMetadata();
107
- return JSON.parse((_e = (_d = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _d === void 0 ? void 0 : _d.options) !== null && _e !== void 0 ? _e : '{}');
101
+ switch (context === null || context === void 0 ? void 0 : context.eventType) {
102
+ case 'google.storage.object.finalize': {
103
+ const gsEvent = event;
104
+ if ((_a = gsEvent === null || gsEvent === void 0 ? void 0 : gsEvent.metadata) === null || _a === void 0 ? void 0 : _a.options) {
105
+ return JSON.parse((_c = (_b = gsEvent === null || gsEvent === void 0 ? void 0 : gsEvent.metadata) === null || _b === void 0 ? void 0 : _b.options) !== null && _c !== void 0 ? _c : '{}');
106
+ }
107
+ else {
108
+ const file = exports.storage.bucket(gsEvent.bucket).file(gsEvent.name);
109
+ const [meta] = yield file.getMetadata();
110
+ return JSON.parse((_e = (_d = meta === null || meta === void 0 ? void 0 : meta.metadata) === null || _d === void 0 ? void 0 : _d.options) !== null && _e !== void 0 ? _e : '{}');
111
+ }
112
+ }
113
+ case 'google.pubsub.topic.publish': {
114
+ const psEvent = event;
115
+ return JSON.parse((_g = (_f = psEvent === null || psEvent === void 0 ? void 0 : psEvent.attributes) === null || _f === void 0 ? void 0 : _f.options) !== null && _g !== void 0 ? _g : '{}');
116
+ }
108
117
  }
109
118
  });
110
119
  }
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ export type TPSEvent = {
41
41
  topic: string,
42
42
  requestId: string,
43
43
  env: string,
44
+ options?: any,
44
45
  };
45
46
  data?: string | Dict<any>;
46
47
  }
@@ -156,13 +157,22 @@ export class GcfCommon {
156
157
  return {topic, requestId, env};
157
158
  }
158
159
 
159
- static async getOptions(event: TGSEvent, context: TContext) {
160
- if (event?.metadata?.options) {
161
- return JSON.parse(event?.metadata?.options ?? '{}');
162
- } else {
163
- const file: File = storage.bucket(event.bucket).file(event.name);
164
- const [meta] = await file.getMetadata();
165
- return JSON.parse(meta?.metadata?.options ?? '{}');
160
+ static async getOptions(event: TEvent, context: TContext): Promise<Dict<any>> {
161
+ switch (context?.eventType) {
162
+ case 'google.storage.object.finalize': {
163
+ const gsEvent = event as TGSEvent;
164
+ if (gsEvent?.metadata?.options) {
165
+ return JSON.parse(gsEvent?.metadata?.options ?? '{}');
166
+ } else {
167
+ const file: File = storage.bucket(gsEvent.bucket).file(gsEvent.name);
168
+ const [meta] = await file.getMetadata();
169
+ return JSON.parse(meta?.metadata?.options ?? '{}');
170
+ }
171
+ }
172
+ case 'google.pubsub.topic.publish' : {
173
+ const psEvent = event as TPSEvent;
174
+ return JSON.parse(psEvent?.attributes?.options ?? '{}');
175
+ }
166
176
  }
167
177
  }
168
178