@shushed/helpers 0.0.198-v2-20251107134609 → 0.0.198-v2-20251107153925
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/dist/cjs/src-public/env.js +1 -0
- package/dist/cjs/src-public/pubsub.js +5 -12
- package/dist/cjs/src-public/utils.js +28 -17
- package/dist/types/src-public/pubsub.d.ts +2 -15
- package/dist/types/src-public/types.d.ts +1 -0
- package/dist/types/src-public/utils.d.ts +18 -2
- package/package.json +1 -1
|
@@ -550,6 +550,7 @@ class EnvEngine extends runtime_1.default {
|
|
|
550
550
|
error429Threshold: 0.30,
|
|
551
551
|
pauseOnErrorThresholdExceededSeconds: 60 * 10,
|
|
552
552
|
pauseOnError429ThresholdExceededSeconds: 60 * 10,
|
|
553
|
+
pauseBeforeProcessingMessagesSeconds: 0,
|
|
553
554
|
maxOutstandingMessages: 5,
|
|
554
555
|
ackDeadline: 10,
|
|
555
556
|
retryMinDelay: 60,
|
|
@@ -68,26 +68,19 @@ class PubSubHelper extends runtime_1.default {
|
|
|
68
68
|
};
|
|
69
69
|
return message;
|
|
70
70
|
}
|
|
71
|
-
async publish(options,
|
|
71
|
+
async publish(options, payloads) {
|
|
72
72
|
if (!pubSubPublishTopics[options.topicName]) {
|
|
73
73
|
pubSubPublishTopics[options.topicName] = this.pubSub.topic(options.topicName, {
|
|
74
74
|
batching: {
|
|
75
|
-
maxMessages:
|
|
76
|
-
maxMilliseconds:
|
|
75
|
+
maxMessages: 10,
|
|
76
|
+
maxMilliseconds: 15
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
const topic = pubSubPublishTopics[options.topicName];
|
|
81
|
-
|
|
82
|
-
if (!Array.isArray(payload)) {
|
|
83
|
-
normPayloads = [payload];
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
normPayloads = payload;
|
|
87
|
-
}
|
|
88
|
-
const batches = normPayloads.length > 5 ? (0, lodash_chunk_1.default)(normPayloads, 10) : [normPayloads];
|
|
81
|
+
const batches = payloads.length > 5 ? (0, lodash_chunk_1.default)(payloads, 10) : [payloads];
|
|
89
82
|
const attributes = {
|
|
90
|
-
...
|
|
83
|
+
...options.extraAttributes,
|
|
91
84
|
source_system: options.sourceSystem,
|
|
92
85
|
target_system: options.targetSystem,
|
|
93
86
|
buildship_id: this.systemEnvName + '-' + this.workflowId + '-' + this.triggerId,
|
|
@@ -14,6 +14,7 @@ exports.splitTimeToArr = splitTimeToArr;
|
|
|
14
14
|
exports.minutesAgo = minutesAgo;
|
|
15
15
|
exports.setRetryAfterVariable = setRetryAfterVariable;
|
|
16
16
|
exports.createFunction = createFunction;
|
|
17
|
+
exports.createOnResponse = createOnResponse;
|
|
17
18
|
exports.onResponse = onResponse;
|
|
18
19
|
const crypto_1 = __importDefault(require("crypto"));
|
|
19
20
|
const firestore_1 = require("@google-cloud/firestore");
|
|
@@ -236,21 +237,20 @@ function createFunction(expression) {
|
|
|
236
237
|
}
|
|
237
238
|
return (payload) => global.functionsCache[expression](exports.FUNCTION_EXPR_ERROR, payload);
|
|
238
239
|
}
|
|
239
|
-
function
|
|
240
|
+
function createOnResponse(opts) {
|
|
241
|
+
return (config, options) => onResponse(config, options, opts.requiredFlag);
|
|
242
|
+
}
|
|
243
|
+
function onResponse(config, options, requiredFlag) {
|
|
240
244
|
options.logging.log('onResponse', config);
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
|
|
245
|
+
const triggerOutput = options.root[options.triggerId || options.trigger?.id];
|
|
246
|
+
const flags = triggerOutput?.flags;
|
|
247
|
+
const numberOfInputMessages = triggerOutput?.body?.length ?? 0;
|
|
248
|
+
const outputBody = config.outputs?.body;
|
|
249
|
+
const outputStatus = config.outputs?.status;
|
|
246
250
|
let headersToSet = {};
|
|
247
|
-
if (outputBody
|
|
248
|
-
responsePayload = outputBody.body;
|
|
251
|
+
if (outputBody?.headersToSet) {
|
|
249
252
|
headersToSet = outputBody.headersToSet;
|
|
250
253
|
}
|
|
251
|
-
else {
|
|
252
|
-
responsePayload = outputBody;
|
|
253
|
-
}
|
|
254
254
|
if (options.root?.state?.['_$hsRetryAfter_'] && !Object.keys(headersToSet).some(x => x.toLocaleLowerCase() === 'retry-after')) {
|
|
255
255
|
let retryAfter = options.root.state['_$hsRetryAfter_'];
|
|
256
256
|
if (retryAfter) {
|
|
@@ -260,6 +260,22 @@ function onResponse(config, options) {
|
|
|
260
260
|
}
|
|
261
261
|
headersToSet['retry-after'] = retryAfter;
|
|
262
262
|
}
|
|
263
|
+
if (headersToSet) {
|
|
264
|
+
for (const [key, value] of Object.entries(headersToSet)) {
|
|
265
|
+
options.request.headers[key] = value;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (!triggerOutput) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
let responsePayload;
|
|
272
|
+
if (outputBody.headersToSet && outputBody.body) {
|
|
273
|
+
responsePayload = outputBody.body;
|
|
274
|
+
headersToSet = outputBody.headersToSet;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
responsePayload = outputBody;
|
|
278
|
+
}
|
|
263
279
|
if (Array.isArray(responsePayload) && responsePayload.length === numberOfInputMessages) {
|
|
264
280
|
return {
|
|
265
281
|
status: (responsePayload.every(x => x instanceof Error) ? 500 : (outputStatus ? outputStatus : 200)),
|
|
@@ -269,16 +285,11 @@ function onResponse(config, options) {
|
|
|
269
285
|
}
|
|
270
286
|
return {
|
|
271
287
|
status: x instanceof Error ? (headersToSet['retry-after'] ? 429 : 500) : 200,
|
|
272
|
-
body: x instanceof Error ? x.message : (flags.includes('product-data') ? x : '<Redacted>. No product-data permissions>')
|
|
288
|
+
body: x instanceof Error ? x.message : (flags.includes(requiredFlag || 'product-data') ? x : '<Redacted>. No product-data permissions>')
|
|
273
289
|
};
|
|
274
290
|
})
|
|
275
291
|
};
|
|
276
292
|
}
|
|
277
|
-
if (headersToSet) {
|
|
278
|
-
for (const [key, value] of Object.entries(headersToSet)) {
|
|
279
|
-
options.request.headers[key] = value;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
293
|
return {
|
|
283
294
|
status: headersToSet['retry-after'] ? 429 : (outputStatus ? outputStatus : (responsePayload instanceof Error ? 500 : 200)),
|
|
284
295
|
value: responsePayload,
|
|
@@ -22,15 +22,7 @@ export type ReceivedMessage = Message & {
|
|
|
22
22
|
body: any;
|
|
23
23
|
bodyTxt: string;
|
|
24
24
|
};
|
|
25
|
-
type
|
|
26
|
-
type AtLeastOne<T, Keys extends keyof T = keyof T> = Partial<T> & {
|
|
27
|
-
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, never>>;
|
|
28
|
-
}[Keys];
|
|
29
|
-
type MessageBody = {
|
|
30
|
-
[K in LastModifiedKeys]?: Date | string;
|
|
31
|
-
} & {
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
};
|
|
25
|
+
type MessageBody = Record<string, any>;
|
|
34
26
|
type SubscriptionOptionsPull = {
|
|
35
27
|
topic: Topic;
|
|
36
28
|
exactlyOnceDelivery?: boolean;
|
|
@@ -66,12 +58,7 @@ declare class PubSubHelper extends Runtime {
|
|
|
66
58
|
topicName: string;
|
|
67
59
|
sourceSystem: string;
|
|
68
60
|
attributesGenerator?: (payload: any) => Record<string, string>;
|
|
69
|
-
},
|
|
70
|
-
publish(options: Partial<Message> & {
|
|
71
|
-
topicName: string;
|
|
72
|
-
sourceSystem: string;
|
|
73
|
-
attributesGenerator?: (payload: any) => Record<string, string>;
|
|
74
|
-
}, payload: AtLeastOne<MessageBody, LastModifiedKeys>): Promise<Array<string | null>>;
|
|
61
|
+
}, payloads: Array<MessageBody>): Promise<Array<string | null>>;
|
|
75
62
|
createOrUpdate(opts: {
|
|
76
63
|
topicName: string;
|
|
77
64
|
subscriptionName?: string;
|
|
@@ -241,6 +241,7 @@ export type RNConfiguration = {
|
|
|
241
241
|
error429Threshold: number;
|
|
242
242
|
pauseOnError429ThresholdExceededSeconds: number;
|
|
243
243
|
pauseOnErrorThresholdExceededSeconds: number;
|
|
244
|
+
pauseBeforeProcessingMessagesSeconds: number;
|
|
244
245
|
maxOutstandingMessages: number;
|
|
245
246
|
ackDeadline: number;
|
|
246
247
|
tableName: string;
|
|
@@ -35,12 +35,28 @@ declare global {
|
|
|
35
35
|
}
|
|
36
36
|
export declare const FUNCTION_EXPR_ERROR: unique symbol;
|
|
37
37
|
export declare function createFunction(expression: string): (payload: any) => any;
|
|
38
|
+
export declare function createOnResponse(opts: {
|
|
39
|
+
requiredFlag: string;
|
|
40
|
+
}): (config: any & {
|
|
41
|
+
outputs: {
|
|
42
|
+
status: number;
|
|
43
|
+
body: any;
|
|
44
|
+
};
|
|
45
|
+
}, options: TriggerOnResponseOptions) => {
|
|
46
|
+
status: any;
|
|
47
|
+
value: any[];
|
|
48
|
+
cacheMaxAge?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
status: any;
|
|
51
|
+
value: any;
|
|
52
|
+
cacheMaxAge: number;
|
|
53
|
+
} | undefined;
|
|
38
54
|
export declare function onResponse(config: any & {
|
|
39
55
|
outputs: {
|
|
40
56
|
status: number;
|
|
41
57
|
body: any;
|
|
42
58
|
};
|
|
43
|
-
}, options: TriggerOnResponseOptions): {
|
|
59
|
+
}, options: TriggerOnResponseOptions, requiredFlag?: string): {
|
|
44
60
|
status: any;
|
|
45
61
|
value: any[];
|
|
46
62
|
cacheMaxAge?: undefined;
|
|
@@ -48,4 +64,4 @@ export declare function onResponse(config: any & {
|
|
|
48
64
|
status: any;
|
|
49
65
|
value: any;
|
|
50
66
|
cacheMaxAge: number;
|
|
51
|
-
};
|
|
67
|
+
} | undefined;
|