gcf-common-lib 0.23.32 → 0.23.34
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 +32 -16
- package/src/index.ts +30 -14
- package/src/types.ts +4 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -93,7 +93,7 @@ class GcfCommon {
|
|
|
93
93
|
console.log('publish:', topic, appId, env, json, attributes);
|
|
94
94
|
return exports.pubSub.topic(topic).publishMessage({
|
|
95
95
|
json: json !== null && json !== void 0 ? json : {},
|
|
96
|
-
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, (v) => '' + v)), {
|
|
96
|
+
attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, (v) => '' + v)), { appId: appId !== null && appId !== void 0 ? appId : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '', env: env !== null && env !== void 0 ? env : '',
|
|
97
97
|
//
|
|
98
98
|
type: 'response', response: '1' }),
|
|
99
99
|
});
|
|
@@ -110,45 +110,61 @@ class GcfCommon {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
static getTopicAndQueue(event, context) {
|
|
113
|
-
var _a, _b;
|
|
113
|
+
var _a, _b, _c, _d;
|
|
114
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
let
|
|
116
|
-
if (!topic && !queue && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
115
|
+
let _meta = this.getMetadata(event, context);
|
|
116
|
+
if (!_meta.topic && !_meta.queue && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
117
117
|
if ((context === null || context === void 0 ? void 0 : context.eventType) === 'google.storage.object.finalize') {
|
|
118
118
|
const gsEvent = event;
|
|
119
119
|
const [meta] = yield exports.storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
120
|
-
(
|
|
120
|
+
(_meta = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {});
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
topic: _meta.topic,
|
|
125
|
+
queue: _meta.queue,
|
|
126
|
+
env: _meta.env,
|
|
127
|
+
appId: (_c = _meta.appId) !== null && _c !== void 0 ? _c : _meta['app-id'],
|
|
128
|
+
requestId: (_d = _meta.requestId) !== null && _d !== void 0 ? _d : _meta['request-id'],
|
|
129
|
+
};
|
|
124
130
|
});
|
|
125
131
|
}
|
|
126
132
|
static getQueue(event, context) {
|
|
127
|
-
var _a, _b;
|
|
133
|
+
var _a, _b, _c, _d;
|
|
128
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
let
|
|
130
|
-
if (!queue && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
135
|
+
let _meta = this.getMetadata(event, context);
|
|
136
|
+
if (!_meta.queue && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
131
137
|
if ((context === null || context === void 0 ? void 0 : context.eventType) === 'google.storage.object.finalize') {
|
|
132
138
|
const gsEvent = event;
|
|
133
139
|
const [meta] = yield exports.storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
134
|
-
(
|
|
140
|
+
(_meta = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {});
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
|
-
return {
|
|
143
|
+
return {
|
|
144
|
+
queue: _meta.queue,
|
|
145
|
+
env: _meta.env,
|
|
146
|
+
appId: (_c = _meta.appId) !== null && _c !== void 0 ? _c : _meta['app-id'],
|
|
147
|
+
requestId: (_d = _meta.requestId) !== null && _d !== void 0 ? _d : _meta['request-id'],
|
|
148
|
+
};
|
|
138
149
|
});
|
|
139
150
|
}
|
|
140
151
|
static getTopic(event, context) {
|
|
141
|
-
var _a, _b;
|
|
152
|
+
var _a, _b, _c, _d;
|
|
142
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
let
|
|
144
|
-
if (!topic && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
154
|
+
let _meta = this.getMetadata(event, context);
|
|
155
|
+
if (!_meta.topic && ((_a = context === null || context === void 0 ? void 0 : context.resource) === null || _a === void 0 ? void 0 : _a.type) === 'storage#object') {
|
|
145
156
|
if ((context === null || context === void 0 ? void 0 : context.eventType) === 'google.storage.object.finalize') {
|
|
146
157
|
const gsEvent = event;
|
|
147
158
|
const [meta] = yield exports.storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
148
|
-
(
|
|
159
|
+
(_meta = (_b = meta === null || meta === void 0 ? void 0 : meta.metadata) !== null && _b !== void 0 ? _b : {});
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
|
-
return {
|
|
162
|
+
return {
|
|
163
|
+
topic: _meta.topic,
|
|
164
|
+
env: _meta.env,
|
|
165
|
+
appId: (_c = _meta.appId) !== null && _c !== void 0 ? _c : _meta['app-id'],
|
|
166
|
+
requestId: (_d = _meta.requestId) !== null && _d !== void 0 ? _d : _meta['request-id'],
|
|
167
|
+
};
|
|
152
168
|
});
|
|
153
169
|
}
|
|
154
170
|
static getOptions(event, context) {
|
package/src/index.ts
CHANGED
|
@@ -72,9 +72,9 @@ export class GcfCommon {
|
|
|
72
72
|
json: json ?? {},
|
|
73
73
|
attributes: {
|
|
74
74
|
...mapValues(attributes ?? {}, (v) => '' + v),
|
|
75
|
+
appId: appId ?? '',
|
|
75
76
|
requestId: requestId ?? '',
|
|
76
77
|
env: env ?? '',
|
|
77
|
-
appId: appId ?? '',
|
|
78
78
|
//
|
|
79
79
|
type: 'response',
|
|
80
80
|
response: '1',
|
|
@@ -95,45 +95,61 @@ export class GcfCommon {
|
|
|
95
95
|
|
|
96
96
|
|
|
97
97
|
static async getTopicAndQueue(event: TEvent, context: TContext) {
|
|
98
|
-
let
|
|
98
|
+
let _meta = this.getMetadata(event, context);
|
|
99
99
|
|
|
100
|
-
if (!topic && !queue && context?.resource?.type === 'storage#object') {
|
|
100
|
+
if (!_meta.topic && !_meta.queue && context?.resource?.type === 'storage#object') {
|
|
101
101
|
if (context?.eventType === 'google.storage.object.finalize') {
|
|
102
102
|
const gsEvent = event as TGSEvent;
|
|
103
103
|
const [meta] = await storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
104
|
-
(
|
|
104
|
+
(_meta = meta?.metadata ?? {});
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
return {
|
|
108
|
+
return {
|
|
109
|
+
topic: _meta.topic,
|
|
110
|
+
queue: _meta.queue,
|
|
111
|
+
env: _meta.env,
|
|
112
|
+
appId: _meta.appId ?? _meta['app-id'],
|
|
113
|
+
requestId: _meta.requestId ?? _meta['request-id'],
|
|
114
|
+
};
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
static async getQueue(event: TEvent, context: TContext) {
|
|
112
|
-
let
|
|
118
|
+
let _meta = this.getMetadata(event, context);
|
|
113
119
|
|
|
114
|
-
if (!queue && context?.resource?.type === 'storage#object') {
|
|
120
|
+
if (!_meta.queue && context?.resource?.type === 'storage#object') {
|
|
115
121
|
if (context?.eventType === 'google.storage.object.finalize') {
|
|
116
122
|
const gsEvent = event as TGSEvent;
|
|
117
123
|
const [meta] = await storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
118
|
-
(
|
|
124
|
+
(_meta = meta?.metadata ?? {});
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
return {
|
|
128
|
+
return {
|
|
129
|
+
queue: _meta.queue,
|
|
130
|
+
env: _meta.env,
|
|
131
|
+
appId: _meta.appId ?? _meta['app-id'],
|
|
132
|
+
requestId: _meta.requestId ?? _meta['request-id'],
|
|
133
|
+
};
|
|
123
134
|
}
|
|
124
135
|
|
|
125
136
|
static async getTopic(event: TEvent, context: TContext) {
|
|
126
|
-
let
|
|
137
|
+
let _meta = this.getMetadata(event, context);
|
|
127
138
|
|
|
128
|
-
if (!topic && context?.resource?.type === 'storage#object') {
|
|
139
|
+
if (!_meta.topic && context?.resource?.type === 'storage#object') {
|
|
129
140
|
if (context?.eventType === 'google.storage.object.finalize') {
|
|
130
141
|
const gsEvent = event as TGSEvent;
|
|
131
142
|
const [meta] = await storage.bucket(gsEvent.bucket).file(gsEvent.name).getMetadata();
|
|
132
|
-
(
|
|
143
|
+
(_meta = meta?.metadata ?? {});
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
146
|
|
|
136
|
-
return {
|
|
147
|
+
return {
|
|
148
|
+
topic: _meta.topic,
|
|
149
|
+
env: _meta.env,
|
|
150
|
+
appId: _meta.appId ?? _meta['app-id'],
|
|
151
|
+
requestId: _meta.requestId ?? _meta['request-id'],
|
|
152
|
+
};
|
|
137
153
|
}
|
|
138
154
|
|
|
139
155
|
static async getOptions(event: TEvent, context: TContext): Promise<Dict<any>> {
|
|
@@ -180,4 +196,4 @@ export class GcfCommon {
|
|
|
180
196
|
static async getSecrets(names: string[], versions?: string[]) {
|
|
181
197
|
return Promise.all(names.map(async (name, idx) => this.getSecret(name, versions?.[idx]).catch()));
|
|
182
198
|
}
|
|
183
|
-
}
|
|
199
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -3,9 +3,11 @@ import Dict = NodeJS.Dict;
|
|
|
3
3
|
export type TMetadata = {
|
|
4
4
|
topic?: string; // response PubSub topic [t_{GUID}__{YYYY-MM-DD}]
|
|
5
5
|
queue?: string; // response amqp queue
|
|
6
|
-
requestId?: string; // for rpc response [GUID]
|
|
7
6
|
env?: string; // app environment
|
|
8
7
|
appId?: string; // app id
|
|
8
|
+
'app-id'?: string; // app id
|
|
9
|
+
requestId?: string; // for rpc response [GUID]
|
|
10
|
+
'request-id'?: string; // for rpc response [GUID]
|
|
9
11
|
options?: string;
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -56,4 +58,4 @@ export type TResponse = {
|
|
|
56
58
|
message: string;
|
|
57
59
|
stack?: string;
|
|
58
60
|
};
|
|
59
|
-
};
|
|
61
|
+
};
|