@shushed/helpers 0.0.233 → 0.0.235

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.
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "PriceChange", "additionalProperties": false, "allOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Price", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": ["string", "null"] }, "colour_id": { "type": ["string", "null"] }, "pricelist_code": { "type": "string" }, "price_changes": { "type": "array", "items": { "type": "object", "additionalProperties": false, "properties": { "price": { "type": "integer", "minimum": 0 }, "price_type": { "type": "string", "enum": ["rrp", "perm", "pos"] }, "effective_from": { "type": "string", "format": "date-time" }, "effective_until": { "type": "string", "format": "date-time" } }, "includes_vat": { "type": "boolean" }, "required": ["price", "includes_vat", "price_type", "effective_from", "effective_until"] } }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "channel": { "type": "string" } }, "required": ["style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"] }, { "type": "object", "additionalProperties": false, "required": ["style_id", "colour_id", "full_price", "markdown", "pos", "currency", "effective_from", "channel"] }], "$id": "https://shushed.example.com/messages/price-change.schema.json" };
3
+ const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "PriceChange", "additionalProperties": false, "allOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Price", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": ["string", "null"] }, "colour_id": { "type": ["string", "null"] }, "pricelist_code": { "type": "string" }, "sizes": { "type": "array", "items": { "type": "string" } }, "price_changes": { "type": "array", "items": { "type": "object", "additionalProperties": false, "properties": { "price": { "type": "integer", "minimum": 0 }, "price_type": { "type": "string", "enum": ["rrp", "perm", "pos"] }, "effective_from": { "type": "string", "format": "date-time" }, "effective_until": { "type": "string", "format": "date-time" } }, "includes_vat": { "type": "boolean" }, "required": ["price", "includes_vat", "price_type", "effective_from", "effective_until"] } }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "channel": { "type": "string" } }, "required": ["sizes", "style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"] }, { "type": "object", "additionalProperties": false, "required": ["style_id", "colour_id", "full_price", "markdown", "pos", "currency", "effective_from", "channel"] }], "$id": "https://shushed.example.com/messages/price-change.schema.json" };
4
4
  exports.default = schema;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Price", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": ["string", "null"] }, "colour_id": { "type": ["string", "null"] }, "pricelist_code": { "type": "string" }, "price_changes": { "type": "array", "items": { "type": "object", "additionalProperties": false, "properties": { "price": { "type": "integer", "minimum": 0 }, "price_type": { "type": "string", "enum": ["rrp", "perm", "pos"] }, "effective_from": { "type": "string", "format": "date-time" }, "effective_until": { "type": "string", "format": "date-time" } }, "includes_vat": { "type": "boolean" }, "required": ["price", "includes_vat", "price_type", "effective_from", "effective_until"] } }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "channel": { "type": "string" } }, "required": ["style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"], "$id": "https://shushed.example.com/price.schema.json" };
3
+ const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Price", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": ["string", "null"] }, "colour_id": { "type": ["string", "null"] }, "pricelist_code": { "type": "string" }, "sizes": { "type": "array", "items": { "type": "string" } }, "price_changes": { "type": "array", "items": { "type": "object", "additionalProperties": false, "properties": { "price": { "type": "integer", "minimum": 0 }, "price_type": { "type": "string", "enum": ["rrp", "perm", "pos"] }, "effective_from": { "type": "string", "format": "date-time" }, "effective_until": { "type": "string", "format": "date-time" } }, "includes_vat": { "type": "boolean" }, "required": ["price", "includes_vat", "price_type", "effective_from", "effective_until"] } }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "channel": { "type": "string" } }, "required": ["sizes", "style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"], "$id": "https://shushed.example.com/price.schema.json" };
4
4
  exports.default = schema;
@@ -50,7 +50,6 @@ class BigQueryHelper extends runtime_1.default {
50
50
  }
51
51
  }
52
52
  for (const sql of alterStatements) {
53
- console.log(`Executing SQL: ${sql}`);
54
53
  await this.bigQuery.query({ query: sql });
55
54
  }
56
55
  return fullTableId;
@@ -777,9 +777,6 @@ class EnvEngine extends runtime_1.default {
777
777
  projectId: pubSubProjectId
778
778
  });
779
779
  global.HUSH_PUBSUB_INSTANCE = pubSub;
780
- this.logging.log('getPubSubHelper', {
781
- serviceAccountEmail: serviceAccount,
782
- });
783
780
  return new pubsub_1.default(this, {
784
781
  serviceAccountEmail: serviceAccount
785
782
  }, pubSub);
@@ -64,15 +64,6 @@ class PubSubHelper extends runtime_1.default {
64
64
  return message;
65
65
  }
66
66
  async publish(options, payloads) {
67
- if (!pubSubPublishTopics[options.topicName]) {
68
- pubSubPublishTopics[options.topicName] = this.pubSub.topic(options.topicName, {
69
- batching: {
70
- maxMessages: 10,
71
- maxMilliseconds: 15
72
- },
73
- });
74
- }
75
- const topic = pubSubPublishTopics[options.topicName];
76
67
  const batches = payloads.length > 5 ? (0, lodash_chunk_1.default)(payloads, 10) : [payloads];
77
68
  let nextAttributes = {};
78
69
  const messageIds = [];
@@ -112,6 +103,25 @@ class PubSubHelper extends runtime_1.default {
112
103
  };
113
104
  let messageId = null;
114
105
  if (!options.dryRun) {
106
+ let topicName = '';
107
+ if (typeof options.topicName === 'function') {
108
+ options.topicName = options.topicName(message.data);
109
+ }
110
+ else if (typeof options.topicName === 'string') {
111
+ topicName = options.topicName;
112
+ }
113
+ else {
114
+ throw new Error('topicName must be a string or a function');
115
+ }
116
+ if (!pubSubPublishTopics[topicName]) {
117
+ pubSubPublishTopics[topicName] = this.pubSub.topic(topicName, {
118
+ batching: {
119
+ maxMessages: 10,
120
+ maxMilliseconds: 15
121
+ },
122
+ });
123
+ }
124
+ const topic = pubSubPublishTopics[topicName];
115
125
  messageId = await topic.publishMessage({
116
126
  data: Buffer.from(JSON.stringify(message.data)),
117
127
  attributes: message.attributes,
@@ -98,7 +98,7 @@ class Runtime {
98
98
  if (opts.trigger?.label) {
99
99
  this.triggerId = opts.trigger.id || '00000000-0000-0000-0000-000000000000';
100
100
  this.triggerName = opts.trigger?.label?.split(/\sv\d/)[0]?.trim() || this.workflowId;
101
- this.triggerVersion = buildSemver((opts.trigger.label.split(/\sv\d/)[1]?.trim() || 'v0').replace(/^v/, ''));
101
+ this.triggerVersion = buildSemver((opts.trigger?.label?.split(/\sv/)?.find(x => /^\d/.test(x))?.trim() || '0'));
102
102
  this.triggerDataProperties = opts.trigger.data?.properties;
103
103
  this.triggerConfigProperties = opts.trigger.config?.properties;
104
104
  }
@@ -182,7 +182,7 @@ class Runtime {
182
182
  exports.default = Runtime;
183
183
  ;
184
184
  function buildSemver(version) {
185
- const parts = version.split(/\./).map(x => parseInt(x, 10));
185
+ const parts = version.split('.').map(x => parseInt(x, 10)).filter(x => !isNaN(x));
186
186
  for (let i = parts.length; i < 3; i++) {
187
187
  parts.push(0);
188
188
  }
@@ -17,6 +17,12 @@ declare const schema: {
17
17
  readonly pricelist_code: {
18
18
  readonly type: "string";
19
19
  };
20
+ readonly sizes: {
21
+ readonly type: "array";
22
+ readonly items: {
23
+ readonly type: "string";
24
+ };
25
+ };
20
26
  readonly price_changes: {
21
27
  readonly type: "array";
22
28
  readonly items: {
@@ -56,7 +62,7 @@ declare const schema: {
56
62
  readonly type: "string";
57
63
  };
58
64
  };
59
- readonly required: readonly ["style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"];
65
+ readonly required: readonly ["sizes", "style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"];
60
66
  }, {
61
67
  readonly type: "object";
62
68
  readonly additionalProperties: false;
@@ -13,6 +13,12 @@ declare const schema: {
13
13
  readonly pricelist_code: {
14
14
  readonly type: "string";
15
15
  };
16
+ readonly sizes: {
17
+ readonly type: "array";
18
+ readonly items: {
19
+ readonly type: "string";
20
+ };
21
+ };
16
22
  readonly price_changes: {
17
23
  readonly type: "array";
18
24
  readonly items: {
@@ -52,7 +58,7 @@ declare const schema: {
52
58
  readonly type: "string";
53
59
  };
54
60
  };
55
- readonly required: readonly ["style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"];
61
+ readonly required: readonly ["sizes", "style_id", "colour_id", "pricelist_code", "markdown", "currency", "channel"];
56
62
  readonly $id: "https://shushed.example.com/price.schema.json";
57
63
  };
58
64
  export default schema;
@@ -4,6 +4,7 @@ export interface Price {
4
4
  style_id: (string | null);
5
5
  colour_id: (string | null);
6
6
  pricelist_code: string;
7
+ sizes: string[];
7
8
  price_changes?: {
8
9
  price: number;
9
10
  price_type: ("rrp" | "perm" | "pos");
@@ -3,6 +3,7 @@ export interface __MainSchema {
3
3
  style_id: (string | null);
4
4
  colour_id: (string | null);
5
5
  pricelist_code: string;
6
+ sizes: string[];
6
7
  price_changes?: {
7
8
  price: number;
8
9
  price_type: ("rrp" | "perm" | "pos");
@@ -52,7 +52,7 @@ declare class PubSubHelper extends Runtime {
52
52
  static decodeMessageFromRequest(req: PubSubMessage): Promise<ReceivedMessage>;
53
53
  static decodeMessageFromRequest(req: Context): Promise<ReceivedMessage>;
54
54
  publish(options: Partial<Message> & {
55
- topicName: string;
55
+ topicName: string | ((payload: any) => string);
56
56
  extraAttributes?: PublishAttributes;
57
57
  attributesGenerator?: PublishAttributesGenerator<Record<string, string>>;
58
58
  dryRun?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.233",
3
+ "version": "0.0.235",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",