@constructor-io/constructorio-node 4.12.2 → 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/README.md +0 -1
- package/package.json +1 -1
- package/src/constructorio.js +4 -1
- package/src/types/autocomplete.d.ts +1 -0
- package/src/types/index.d.ts +5 -0
- package/src/types/tracker.d.ts +2 -2
- package/src/utils/helpers.js +20 -0
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@constructor-io/constructorio-node)
|
|
4
4
|
[](https://github.com/Constructor-io/constructorio-node/blob/master/LICENSE)
|
|
5
|
-
[](https://bundlephobia.com/result?p=@constructor-io/constructorio-node)
|
|
6
5
|
|
|
7
6
|
A Node.js client for [Constructor.io](http://constructor.io/). [Constructor.io](http://constructor.io/) provides search as a service that optimizes results using artificial intelligence (including natural language processing, re-ranking to optimize for conversions, and user personalization).
|
|
8
7
|
|
package/package.json
CHANGED
package/src/constructorio.js
CHANGED
|
@@ -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:
|
|
61
|
+
serviceUrl: utils.addHTTPSToString(normalizedServiceUrl) || 'https://ac.cnstrc.com',
|
|
59
62
|
fetch: fetch || nodeFetch,
|
|
60
63
|
networkParameters: networkParameters || {},
|
|
61
64
|
};
|
package/src/types/index.d.ts
CHANGED
package/src/types/tracker.d.ts
CHANGED
|
@@ -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:
|
|
119
|
+
items: ItemTrackedPurchased[];
|
|
120
120
|
revenue: number;
|
|
121
121
|
orderId?: string;
|
|
122
122
|
section?: string;
|
package/src/utils/helpers.js
CHANGED
|
@@ -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;
|