griddo-sdk 1.0.14 → 1.1.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/api/index.js +15 -0
- package/index.js +8 -0
- package/models/alerts.js +10 -0
- package/models/structuredData.js +1 -1
- package/package.json +1 -1
package/api/index.js
CHANGED
|
@@ -6,6 +6,20 @@ const api = (env, method, endpoint, body = null, headers = {}) => {
|
|
|
6
6
|
token,
|
|
7
7
|
} = env;
|
|
8
8
|
if (!api) throw new Error('Class SDK should be initialized with connect method.');
|
|
9
|
+
return apiCall(api, token, method, endpoint, body = null, headers = {});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const publicApi = (env, method, endpoint, body = null, headers = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
publicApi,
|
|
15
|
+
token,
|
|
16
|
+
} = env;
|
|
17
|
+
if (!publicApi) throw new Error('Public API should be declared at initialization.');
|
|
18
|
+
return apiCall(api, token, method, endpoint, body = null, headers = {});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const apiCall = (api,token, method, endpoint, body = null, headers = {}) => {
|
|
22
|
+
|
|
9
23
|
const noBodyMethods = [
|
|
10
24
|
'get',
|
|
11
25
|
'delete',
|
|
@@ -22,4 +36,5 @@ const api = (env, method, endpoint, body = null, headers = {}) => {
|
|
|
22
36
|
|
|
23
37
|
module.exports={
|
|
24
38
|
api,
|
|
39
|
+
publicApi,
|
|
25
40
|
};
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const { getPages, getPage, savePage, deletePage, restorePage } = require('./mode
|
|
|
4
4
|
const { getStructuredData, saveStructuredData, deleteStructuredData } = require('./models/structuredData');
|
|
5
5
|
const { getLanguages } = require('./models/languages');
|
|
6
6
|
const { getStatus } = require('./models/liveStatus');
|
|
7
|
+
const { sendAlert } = require('./models/alerts');
|
|
7
8
|
|
|
8
9
|
class SDK {
|
|
9
10
|
constructor() {
|
|
@@ -23,6 +24,7 @@ class SDK {
|
|
|
23
24
|
this.mapStructuredData = this.mapStructuredData.bind(this);
|
|
24
25
|
this.getLanguage = this.getLanguage.bind(this);
|
|
25
26
|
this.getDefaultLanguage = this.getDefaultLanguage.bind(this);
|
|
27
|
+
this.sendAlert = this.sendAlert.bind(this);
|
|
26
28
|
this.languages = [];
|
|
27
29
|
this.liveStatus = {};
|
|
28
30
|
}
|
|
@@ -30,6 +32,7 @@ class SDK {
|
|
|
30
32
|
async connect(environment) {
|
|
31
33
|
const {
|
|
32
34
|
api,
|
|
35
|
+
publicApi,
|
|
33
36
|
user,
|
|
34
37
|
password,
|
|
35
38
|
verbose,
|
|
@@ -37,6 +40,7 @@ class SDK {
|
|
|
37
40
|
if (!api || !user || !password) throw new Error('Connection object must contain the keys api, user and password.');
|
|
38
41
|
this._env = {
|
|
39
42
|
api: api.endsWith('/') ? api.slice(0, -1) : api,
|
|
43
|
+
publicApi: publicApi && (publicApi.endsWith('/') ? publicApi.slice(0, -1) : publicApi),
|
|
40
44
|
token: await getToken(environment),
|
|
41
45
|
verbose,
|
|
42
46
|
};
|
|
@@ -159,6 +163,10 @@ class SDK {
|
|
|
159
163
|
showLog(...text) {
|
|
160
164
|
console.log(`\t${text.join(' ')} `);
|
|
161
165
|
};
|
|
166
|
+
|
|
167
|
+
async sendAlert(alert) {
|
|
168
|
+
return await sendAlert(this._env, alert);
|
|
169
|
+
};
|
|
162
170
|
};
|
|
163
171
|
|
|
164
172
|
module.exports = SDK;
|
package/models/alerts.js
ADDED
package/models/structuredData.js
CHANGED
|
@@ -4,7 +4,7 @@ const getStructuredData = async (env, contentType, site = null, language = null)
|
|
|
4
4
|
const headers = {
|
|
5
5
|
lang: language,
|
|
6
6
|
};
|
|
7
|
-
const items = await api(env, 'get', `${site ? `/site/${site}` : ''}/structured_data_contents/${contentType||''}?pagination=false&includeDraft=true`,
|
|
7
|
+
const items = await api(env, 'get', `${site ? `/site/${site}` : ''}/structured_data_contents/${contentType||''}?pagination=false&includeDraft=true`, null, headers)
|
|
8
8
|
.then(data => data.items);
|
|
9
9
|
if (env.verbose) console.log(`\tStructured data ${contentType} loaded.`);
|
|
10
10
|
return items;
|