gcf-common-lib 0.46.0 → 0.48.0
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 +1 -1
- package/src/index.js +20 -27
- package/src/index.ts +2 -2
- package/src/mongo-helper.js +2 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-common-lib",
|
|
3
3
|
"description": "Common helpers for Google Cloud Functions: Pub/Sub publishing, Mongo helpers, and utilities for Node 20+ (TypeScript).",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.48.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"branches": [
|
package/src/index.js
CHANGED
|
@@ -44,8 +44,6 @@ const pubsub_1 = require("@google-cloud/pubsub");
|
|
|
44
44
|
const storage_1 = require("@google-cloud/storage");
|
|
45
45
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
46
46
|
const mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
47
|
-
const noop_1 = __importDefault(require("lodash/noop"));
|
|
48
|
-
const utils_1 = require("./utils");
|
|
49
47
|
exports.Storage = __importStar(require("@google-cloud/storage"));
|
|
50
48
|
exports.PubSub = __importStar(require("@google-cloud/pubsub"));
|
|
51
49
|
exports.RxJs = __importStar(require("rxjs"));
|
|
@@ -53,7 +51,6 @@ exports.MongoDb = __importStar(require("mongodb"));
|
|
|
53
51
|
__exportStar(require("./types"), exports);
|
|
54
52
|
__exportStar(require("./utils"), exports);
|
|
55
53
|
__exportStar(require("./mongo-helper"), exports);
|
|
56
|
-
// export * from './amqp-helper.ts';
|
|
57
54
|
exports.pubSub = new pubsub_1.PubSub();
|
|
58
55
|
exports.storage = new storage_1.Storage();
|
|
59
56
|
exports.GcfCommon = {
|
|
@@ -68,22 +65,17 @@ exports.GcfCommon = {
|
|
|
68
65
|
// publishOptions?: Options.Publish;
|
|
69
66
|
// },
|
|
70
67
|
async process(payload, handler) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// )
|
|
75
|
-
return asyncHandler({ ...payload })
|
|
76
|
-
.then(async (res) => {
|
|
77
|
-
// console.log('res:', res);
|
|
78
|
-
await exports.GcfCommon.response({ ...payload }, res).catch(noop_1.default);
|
|
68
|
+
try {
|
|
69
|
+
const res = await handler({ ...payload });
|
|
70
|
+
await exports.GcfCommon.response({ ...payload }, res).catch(console.log);
|
|
79
71
|
return res;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
await exports.GcfCommon.response({ ...payload }, exports.GcfCommon.
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
await exports.GcfCommon.response({ ...payload }, exports.GcfCommon.buildErrorResponse(error), { error: '1' }).catch(console.log);
|
|
83
75
|
throw error;
|
|
84
|
-
}
|
|
76
|
+
}
|
|
85
77
|
},
|
|
86
|
-
|
|
78
|
+
buildErrorResponse(error) {
|
|
87
79
|
return {
|
|
88
80
|
error: {
|
|
89
81
|
name: error.name,
|
|
@@ -158,14 +150,18 @@ exports.GcfCommon = {
|
|
|
158
150
|
// request_id: metaOrAttr.request_id,
|
|
159
151
|
// } as TMetadataOrAttributes;
|
|
160
152
|
// },
|
|
161
|
-
async getOptions(payload) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
},
|
|
153
|
+
// async getOptions(payload: TPayload): Promise<Dict<any>> {
|
|
154
|
+
// // const { options } = await GcfCommon.safeGetAttributes(event, context, ['options']);
|
|
155
|
+
// const { options } = GcfCommon.getMetadataOrAttribute(payload);
|
|
156
|
+
// return safeJsonParse(options as any, {} as any);
|
|
157
|
+
// },
|
|
166
158
|
getMetadataOrAttribute(payload) {
|
|
167
159
|
let metadataOrAttribute;
|
|
168
|
-
|
|
160
|
+
// console.log('getMetadataOrAttribute:', payload);
|
|
161
|
+
if (payload?.request) {
|
|
162
|
+
metadataOrAttribute = exports.GcfCommon.getRequestAttributes(payload.request);
|
|
163
|
+
}
|
|
164
|
+
else if (payload?.context) {
|
|
169
165
|
switch (payload?.context?.eventType) {
|
|
170
166
|
case 'google.storage.object.finalize': {
|
|
171
167
|
const gsEvent = payload?.event;
|
|
@@ -179,13 +175,10 @@ exports.GcfCommon = {
|
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
177
|
}
|
|
182
|
-
else if (payload?.request) {
|
|
183
|
-
metadataOrAttribute = exports.GcfCommon.getRequestMessage(payload.request)?.attributes;
|
|
184
|
-
}
|
|
185
178
|
// console.log('metadataOrAttribute:', metadataOrAttribute);
|
|
186
179
|
return metadataOrAttribute ?? {};
|
|
187
180
|
},
|
|
188
|
-
|
|
189
|
-
return request
|
|
181
|
+
getRequestAttributes(request) {
|
|
182
|
+
return { ...request?.body?.message?.attributes, ...request?.headers };
|
|
190
183
|
},
|
|
191
184
|
};
|
package/src/index.ts
CHANGED
|
@@ -134,7 +134,7 @@ export const GcfCommon = {
|
|
|
134
134
|
getMetadataOrAttribute<E = TEvent>(payload: TPayload<E>) {
|
|
135
135
|
let metadataOrAttribute: TMetadataOrAttributes | undefined;
|
|
136
136
|
|
|
137
|
-
console.log('getMetadataOrAttribute:', payload);
|
|
137
|
+
// console.log('getMetadataOrAttribute:', payload);
|
|
138
138
|
|
|
139
139
|
if (payload?.request) {
|
|
140
140
|
metadataOrAttribute = GcfCommon.getRequestAttributes(payload.request);
|
|
@@ -153,7 +153,7 @@ export const GcfCommon = {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
console.log('metadataOrAttribute:', metadataOrAttribute);
|
|
156
|
+
// console.log('metadataOrAttribute:', metadataOrAttribute);
|
|
157
157
|
|
|
158
158
|
return metadataOrAttribute ?? {};
|
|
159
159
|
},
|