@constructor-io/constructorio-node 4.12.3 → 4.13.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-node",
3
- "version": "4.12.3",
3
+ "version": "4.13.0",
4
4
  "description": "Constructor.io Node.js client",
5
5
  "main": "src/constructorio.js",
6
6
  "types": "src/types/constructorio.d.ts",
@@ -11,6 +11,7 @@ const Catalog = require('./modules/catalog');
11
11
  const Tasks = require('./modules/tasks');
12
12
  const Quizzes = require('./modules/quizzes');
13
13
  const { version: packageVersion } = require('../package.json');
14
+ const utils = require('./utils/helpers');
14
15
 
15
16
  /**
16
17
  * Class to instantiate the ConstructorIO client.
@@ -50,12 +51,14 @@ class ConstructorIO {
50
51
  throw new Error('API key is a required parameter of type string');
51
52
  }
52
53
 
54
+ const normalizedServiceUrl = serviceUrl && serviceUrl.replace(/\/$/, '');
55
+
53
56
  this.options = {
54
57
  apiKey,
55
58
  apiToken: apiToken || '',
56
59
  securityToken: securityToken || '',
57
60
  version: version || global.CLIENT_VERSION || `cio-node-${packageVersion}`,
58
- serviceUrl: (serviceUrl && serviceUrl.replace(/\/$/, '')) || 'https://ac.cnstrc.com',
61
+ serviceUrl: utils.addHTTPSToString(normalizedServiceUrl) || 'https://ac.cnstrc.com',
59
62
  fetch: fetch || nodeFetch,
60
63
  networkParameters: networkParameters || {},
61
64
  };
@@ -5,6 +5,7 @@ import {
5
5
  RequestFeatureVariant,
6
6
  UserParameters,
7
7
  VariationsMap,
8
+ FilterExpression,
8
9
  } from '.';
9
10
 
10
11
  export default Autocomplete;
@@ -338,3 +338,8 @@ export interface ItemTracked {
338
338
  itemId?: string;
339
339
  variationId?: string;
340
340
  }
341
+
342
+ export interface ItemTrackedPurchased extends ItemTracked {
343
+ price: number,
344
+ count: number
345
+ }
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import { ConstructorClientOptions, NetworkParameters, ItemTracked } from '.';
2
+ import { ConstructorClientOptions, NetworkParameters, ItemTracked, ItemTrackedPurchased } from '.';
3
3
 
4
4
  export default Tracker;
5
5
 
@@ -116,7 +116,7 @@ declare class Tracker {
116
116
 
117
117
  trackPurchase(
118
118
  parameters: {
119
- items: ItemTracked & {quantity: number}[];
119
+ items: ItemTrackedPurchased[];
120
120
  revenue: number;
121
121
  orderId?: string;
122
122
  section?: string;
@@ -114,6 +114,26 @@ const utils = {
114
114
 
115
115
  return false;
116
116
  },
117
+ addHTTPSToString(url) {
118
+ if (typeof url !== 'string') {
119
+ return null;
120
+ }
121
+
122
+ const doesUrlIncludeHTTPS = url.startsWith('https://');
123
+ const doesUrlStartWithHTTP = url.startsWith('http://');
124
+
125
+ if (!doesUrlIncludeHTTPS && doesUrlStartWithHTTP) {
126
+ return url.replace('http', 'https');
127
+ }
128
+
129
+ if (!doesUrlStartWithHTTP && !doesUrlIncludeHTTPS) {
130
+ const urlWithHttps = `https://${url}`;
131
+
132
+ return urlWithHttps;
133
+ }
134
+
135
+ return url;
136
+ },
117
137
  };
118
138
 
119
139
  module.exports = utils;