@shushed/helpers 0.0.198-v2-20251111082635 → 0.0.198-v2-20251113133158
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.
|
@@ -692,7 +692,7 @@ class EnvEngine extends runtime_1.default {
|
|
|
692
692
|
bodyTxt: messageBodyRaw,
|
|
693
693
|
exportableToBigQuery: !!requestBody?.message?.attributes?.bigquery,
|
|
694
694
|
extraAttributes: Object.assign({}, request.query, (0, lodash_omit_1.default)(requestBody?.message?.attributes || {}, ['source_system', 'target_system', 'buildship_id', 'bigquery'])),
|
|
695
|
-
subscriptionName: requestBody?.subscription?.split('/')?.pop() || request.query.subscriptionName,
|
|
695
|
+
subscriptionName: (requestBody?.subscription?.split('/')?.pop() || request.query.subscriptionName)?.replace(/^rn\./, ''),
|
|
696
696
|
};
|
|
697
697
|
messages.push(message);
|
|
698
698
|
}
|
|
@@ -108,14 +108,17 @@ class PubSubHelper extends runtime_1.default {
|
|
|
108
108
|
}
|
|
109
109
|
async createOrUpdate(opts) {
|
|
110
110
|
const [topics] = await this.pubSub.getTopics();
|
|
111
|
-
|
|
111
|
+
let topicName = opts.topicName;
|
|
112
|
+
if (topicName.indexOf('rn.') !== 0 && /^\d/.test(topicName)) {
|
|
113
|
+
topicName = `rn.${topicName}`;
|
|
114
|
+
}
|
|
112
115
|
const mainSubscriptionName = opts.subscriptionName || topicName;
|
|
113
116
|
const tableSubscriptionName = `${mainSubscriptionName}.bq`;
|
|
114
117
|
const mainDlqTopicName = `${mainSubscriptionName}.dlq`;
|
|
115
118
|
const mainDlqSubscriptionName = `${mainSubscriptionName}.dlq`;
|
|
116
119
|
const tableDlqTopicName = `${mainSubscriptionName}.bq.dlq`;
|
|
117
120
|
const tableDlqSubscriptionName = `${mainSubscriptionName}.bq.dlq`;
|
|
118
|
-
|
|
121
|
+
const mainTopic = topics.find(x => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
119
122
|
let mainDlqTopic = topics.find(x => this.getNameFromFullyQualifiedName(x.name) === mainDlqTopicName);
|
|
120
123
|
let tableDlqTopic = topics.find(x => this.getNameFromFullyQualifiedName(x.name) === tableDlqTopicName);
|
|
121
124
|
let mainTopicSubscriptions = null;
|
|
@@ -135,9 +138,6 @@ class PubSubHelper extends runtime_1.default {
|
|
|
135
138
|
let tableSubscription = mainTopicSubscriptions?.find(x => this.getNameFromFullyQualifiedName(x.name) === tableSubscriptionName) || null;
|
|
136
139
|
let tableDlqSubscription = tableDlqTopicSubscriptions?.find(x => this.getNameFromFullyQualifiedName(x.name) === tableDlqSubscriptionName) || null;
|
|
137
140
|
const topic = await this.ensureTopicExists(opts.topicName);
|
|
138
|
-
if (opts.table || opts.pull) {
|
|
139
|
-
mainTopic = await this.ensureTopicExists(opts.topicName);
|
|
140
|
-
}
|
|
141
141
|
if (!opts.table) {
|
|
142
142
|
if (tableSubscription) {
|
|
143
143
|
await tableSubscription.delete();
|
|
@@ -212,7 +212,7 @@ class PubSubHelper extends runtime_1.default {
|
|
|
212
212
|
await mainDlqTopic.delete();
|
|
213
213
|
}
|
|
214
214
|
return {
|
|
215
|
-
mainTopic,
|
|
215
|
+
mainTopic: topic,
|
|
216
216
|
mainDlqTopic,
|
|
217
217
|
tableDlqTopic,
|
|
218
218
|
mainSubscription,
|
|
@@ -215,7 +215,7 @@ function setRetryAfterVariable(value, options) {
|
|
|
215
215
|
if (value instanceof Response) {
|
|
216
216
|
v = value.headers.get('retry-after') || null;
|
|
217
217
|
}
|
|
218
|
-
else if (typeof
|
|
218
|
+
else if (typeof value === 'object') {
|
|
219
219
|
if (value instanceof Headers) {
|
|
220
220
|
v = value.get('retry-after') || null;
|
|
221
221
|
}
|
|
@@ -223,11 +223,36 @@ function setRetryAfterVariable(value, options) {
|
|
|
223
223
|
v = value['retry-after'] || null;
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
-
else if (typeof
|
|
227
|
-
v =
|
|
226
|
+
else if (typeof value === 'string') {
|
|
227
|
+
v = value;
|
|
228
228
|
}
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
let normV = 0;
|
|
230
|
+
if (v) {
|
|
231
|
+
if (/^\d+$/.test(v)) {
|
|
232
|
+
normV = new Date(Date.now() + parseInt(v) * 1000).getTime();
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
normV = new Date(v).getTime();
|
|
236
|
+
}
|
|
237
|
+
if (isNaN(normV)) {
|
|
238
|
+
normV = 0;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
normV = 0;
|
|
243
|
+
}
|
|
244
|
+
let existingV = 0;
|
|
245
|
+
if (options.root.state['_$hsRetryAfter_']) {
|
|
246
|
+
existingV = new Date(options.root.state['_$hsRetryAfter_']).getTime();
|
|
247
|
+
if (isNaN(existingV)) {
|
|
248
|
+
existingV = 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (normV > existingV) {
|
|
252
|
+
options.root.state['_$hsRetryAfter_'] = new Date(normV).toISOString();
|
|
253
|
+
return new Date(normV).toISOString();
|
|
254
|
+
}
|
|
255
|
+
return options.root.state['_$hsRetryAfter_'] ?? null;
|
|
231
256
|
}
|
|
232
257
|
global.functionsCache = global.functionsCache || {};
|
|
233
258
|
exports.FUNCTION_EXPR_ERROR = Symbol('function');
|
|
@@ -252,12 +277,7 @@ function onResponse(config, options, requiredFlag) {
|
|
|
252
277
|
headersToSet = outputBody.headersToSet;
|
|
253
278
|
}
|
|
254
279
|
if (options.root?.state?.['_$hsRetryAfter_'] && !Object.keys(headersToSet).some(x => x.toLocaleLowerCase() === 'retry-after')) {
|
|
255
|
-
|
|
256
|
-
if (retryAfter) {
|
|
257
|
-
if (/^\d+$/.test(retryAfter ?? '')) {
|
|
258
|
-
retryAfter = new Date(Date.now() + parseInt(retryAfter) * 1000).toString();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
280
|
+
const retryAfter = options.root.state['_$hsRetryAfter_'];
|
|
261
281
|
headersToSet['retry-after'] = retryAfter;
|
|
262
282
|
}
|
|
263
283
|
if (headersToSet) {
|
|
@@ -275,23 +295,39 @@ function onResponse(config, options, requiredFlag) {
|
|
|
275
295
|
else {
|
|
276
296
|
responsePayload = outputBody;
|
|
277
297
|
}
|
|
298
|
+
const redactedResponse = {
|
|
299
|
+
message: `<Redacted Response>. Client does not have required permission flag: ${requiredFlag}`,
|
|
300
|
+
error: false,
|
|
301
|
+
};
|
|
278
302
|
if (responsePayload && Array.isArray(responsePayload) && responsePayload.length === numberOfInputMessages) {
|
|
279
303
|
return {
|
|
280
304
|
status: headersToSet['retry-after'] ? 429 : (outputStatus ? outputStatus : ((responsePayload && responsePayload instanceof Error) ? 500 : 200)),
|
|
281
305
|
value: responsePayload.map(x => {
|
|
282
306
|
if (x && typeof x === 'object' && x.statusCode && x.body) {
|
|
307
|
+
if (requiredFlag && !flags?.includes(requiredFlag) && !(x.body instanceof Error)) {
|
|
308
|
+
return Object.assign({}, x, { body: redactedResponse });
|
|
309
|
+
}
|
|
310
|
+
if (x.body instanceof Error) {
|
|
311
|
+
return Object.assign({}, x, { message: x.body.message, error: true });
|
|
312
|
+
}
|
|
283
313
|
return x;
|
|
284
314
|
}
|
|
285
315
|
return {
|
|
286
316
|
statusCode: x instanceof Error ? (headersToSet['retry-after'] ? 429 : 500) : 200,
|
|
287
|
-
body: x instanceof Error ?
|
|
317
|
+
body: x instanceof Error ? ({
|
|
318
|
+
message: x.message,
|
|
319
|
+
error: true
|
|
320
|
+
}) : (requiredFlag && flags?.includes(requiredFlag) ? x : redactedResponse),
|
|
288
321
|
};
|
|
289
322
|
})
|
|
290
323
|
};
|
|
291
324
|
}
|
|
292
325
|
return {
|
|
293
326
|
status: headersToSet['retry-after'] ? 429 : (outputStatus ? outputStatus : ((responsePayload && responsePayload instanceof Error) ? 500 : 200)),
|
|
294
|
-
value: responsePayload
|
|
327
|
+
value: responsePayload instanceof Error ? ({
|
|
328
|
+
message: responsePayload.message,
|
|
329
|
+
error: true
|
|
330
|
+
}) : (requiredFlag && flags?.includes(requiredFlag) ? responsePayload : redactedResponse),
|
|
295
331
|
cacheMaxAge: 0,
|
|
296
332
|
};
|
|
297
333
|
}
|
|
@@ -78,7 +78,7 @@ declare class PubSubHelper extends Runtime {
|
|
|
78
78
|
ackDeadline: number;
|
|
79
79
|
};
|
|
80
80
|
}): Promise<{
|
|
81
|
-
mainTopic: Topic
|
|
81
|
+
mainTopic: Topic;
|
|
82
82
|
mainDlqTopic: Topic | undefined;
|
|
83
83
|
tableDlqTopic: Topic | undefined;
|
|
84
84
|
mainSubscription: Subscription | null;
|