@shushed/helpers 0.0.198-v2-20251111082635 → 0.0.198-v2-20251113133839

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
- const topicName = opts.topicName;
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
- let mainTopic = topics.find(x => this.getNameFromFullyQualifiedName(x.name) === topicName);
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,
@@ -211,11 +211,14 @@ function minutesAgo(minutes) {
211
211
  return new Date(Date.now() - minutes * 60 * 1000).toISOString();
212
212
  }
213
213
  function setRetryAfterVariable(value, options) {
214
+ if (!options.root || !options.root.state) {
215
+ return null;
216
+ }
214
217
  let v = null;
215
218
  if (value instanceof Response) {
216
219
  v = value.headers.get('retry-after') || null;
217
220
  }
218
- else if (typeof v === 'object') {
221
+ else if (typeof value === 'object') {
219
222
  if (value instanceof Headers) {
220
223
  v = value.get('retry-after') || null;
221
224
  }
@@ -223,11 +226,36 @@ function setRetryAfterVariable(value, options) {
223
226
  v = value['retry-after'] || null;
224
227
  }
225
228
  }
226
- else if (typeof v !== 'string') {
227
- v = null;
229
+ else if (typeof value === 'string') {
230
+ v = value;
231
+ }
232
+ let normV = 0;
233
+ if (v) {
234
+ if (/^\d+$/.test(v)) {
235
+ normV = new Date(Date.now() + parseInt(v) * 1000).getTime();
236
+ }
237
+ else {
238
+ normV = new Date(v).getTime();
239
+ }
240
+ if (isNaN(normV)) {
241
+ normV = 0;
242
+ }
243
+ }
244
+ else {
245
+ normV = 0;
246
+ }
247
+ let existingV = 0;
248
+ if (options.root.state['_$hsRetryAfter_']) {
249
+ existingV = new Date(options.root.state['_$hsRetryAfter_']).getTime();
250
+ if (isNaN(existingV)) {
251
+ existingV = 0;
252
+ }
253
+ }
254
+ if (normV > existingV) {
255
+ options.root.state['_$hsRetryAfter_'] = new Date(normV).toISOString();
256
+ return new Date(normV).toISOString();
228
257
  }
229
- options.root.state['_$hsRetryAfter_'] = v;
230
- return v;
258
+ return options.root.state['_$hsRetryAfter_'] ?? null;
231
259
  }
232
260
  global.functionsCache = global.functionsCache || {};
233
261
  exports.FUNCTION_EXPR_ERROR = Symbol('function');
@@ -252,12 +280,7 @@ function onResponse(config, options, requiredFlag) {
252
280
  headersToSet = outputBody.headersToSet;
253
281
  }
254
282
  if (options.root?.state?.['_$hsRetryAfter_'] && !Object.keys(headersToSet).some(x => x.toLocaleLowerCase() === 'retry-after')) {
255
- let retryAfter = options.root.state['_$hsRetryAfter_'];
256
- if (retryAfter) {
257
- if (/^\d+$/.test(retryAfter ?? '')) {
258
- retryAfter = new Date(Date.now() + parseInt(retryAfter) * 1000).toString();
259
- }
260
- }
283
+ const retryAfter = options.root.state['_$hsRetryAfter_'];
261
284
  headersToSet['retry-after'] = retryAfter;
262
285
  }
263
286
  if (headersToSet) {
@@ -275,23 +298,39 @@ function onResponse(config, options, requiredFlag) {
275
298
  else {
276
299
  responsePayload = outputBody;
277
300
  }
301
+ const redactedResponse = {
302
+ message: `<Redacted Response>. Client does not have required permission flag: ${requiredFlag}`,
303
+ error: false,
304
+ };
278
305
  if (responsePayload && Array.isArray(responsePayload) && responsePayload.length === numberOfInputMessages) {
279
306
  return {
280
307
  status: headersToSet['retry-after'] ? 429 : (outputStatus ? outputStatus : ((responsePayload && responsePayload instanceof Error) ? 500 : 200)),
281
308
  value: responsePayload.map(x => {
282
309
  if (x && typeof x === 'object' && x.statusCode && x.body) {
310
+ if (requiredFlag && !flags?.includes(requiredFlag) && !(x.body instanceof Error)) {
311
+ return Object.assign({}, x, { body: redactedResponse });
312
+ }
313
+ if (x.body instanceof Error) {
314
+ return Object.assign({}, x, { message: x.body.message, error: true });
315
+ }
283
316
  return x;
284
317
  }
285
318
  return {
286
319
  statusCode: x instanceof Error ? (headersToSet['retry-after'] ? 429 : 500) : 200,
287
- body: x instanceof Error ? x.message : x,
320
+ body: x instanceof Error ? ({
321
+ message: x.message,
322
+ error: true
323
+ }) : (requiredFlag && flags?.includes(requiredFlag) ? x : redactedResponse),
288
324
  };
289
325
  })
290
326
  };
291
327
  }
292
328
  return {
293
329
  status: headersToSet['retry-after'] ? 429 : (outputStatus ? outputStatus : ((responsePayload && responsePayload instanceof Error) ? 500 : 200)),
294
- value: responsePayload,
330
+ value: responsePayload instanceof Error ? ({
331
+ message: responsePayload.message,
332
+ error: true
333
+ }) : (requiredFlag && flags?.includes(requiredFlag) ? responsePayload : redactedResponse),
295
334
  cacheMaxAge: 0,
296
335
  };
297
336
  }
@@ -78,7 +78,7 @@ declare class PubSubHelper extends Runtime {
78
78
  ackDeadline: number;
79
79
  };
80
80
  }): Promise<{
81
- mainTopic: Topic | undefined;
81
+ mainTopic: Topic;
82
82
  mainDlqTopic: Topic | undefined;
83
83
  tableDlqTopic: Topic | undefined;
84
84
  mainSubscription: Subscription | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.198-v2-20251111082635",
3
+ "version": "0.0.198-v2-20251113133839",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",