griddo-sdk 1.0.6 → 1.0.7
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/index.js +10 -8
- package/models/auth.js +3 -2
- package/models/pages.js +4 -4
- package/models/structuredData.js +3 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,12 +28,14 @@ class SDK {
|
|
|
28
28
|
const {
|
|
29
29
|
api,
|
|
30
30
|
user,
|
|
31
|
-
password
|
|
31
|
+
password,
|
|
32
|
+
verbose,
|
|
32
33
|
} = environment;
|
|
33
34
|
if (!api || !user || !password) throw new Error('Environment JSON file should contain the keys api, user and password.');
|
|
34
35
|
this._env = {
|
|
35
36
|
api: api.endsWith('/') ? api.slice(0, -1) : api,
|
|
36
37
|
token: await getToken(environment),
|
|
38
|
+
verbose,
|
|
37
39
|
};
|
|
38
40
|
this.languages = await getLanguages(this._env);
|
|
39
41
|
|
|
@@ -50,15 +52,15 @@ class SDK {
|
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
async mapPages(callback, templateName) {
|
|
53
|
-
console.log(`\nMapping ${templateName || 'all'} pages with callback function ${callback.name}...`);
|
|
55
|
+
if (this._env.verbose) console.log(`\nMapping ${templateName || 'all'} pages with callback function ${callback.name}...`);
|
|
54
56
|
if (!callback || typeof (callback) !== 'function') throw new Error('Cannot map pages without a callback function.');
|
|
55
57
|
const pages = await getPages(this._env, templateName);
|
|
56
58
|
if (!pages?.length) {
|
|
57
|
-
console.log('- No pages found.');
|
|
59
|
+
if (this._env.verbose) console.log('- No pages found.');
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
62
|
for (const pageId of pages) {
|
|
61
|
-
console.log('- Mapping page', pageId);
|
|
63
|
+
if (this._env.verbose) console.log('- Mapping page', pageId);
|
|
62
64
|
const page = await getPage(this._env, pageId)
|
|
63
65
|
const pageProtected = JSON.parse(JSON.stringify(page));
|
|
64
66
|
const result = await callback(pageProtected);
|
|
@@ -69,7 +71,7 @@ class SDK {
|
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
async mapModulesFromPage(page, moduleName, callback) {
|
|
72
|
-
console.log(`\tMapping modules ${moduleName} with callback function ${callback.name}...`);
|
|
74
|
+
if (this._env.verbose) console.log(`\tMapping modules ${moduleName} with callback function ${callback.name}...`);
|
|
73
75
|
if (!callback || typeof (callback) !== 'function') throw new Error('Cannot map modules without a callback function.');
|
|
74
76
|
if (!moduleName) throw new Error('Cannot map modules in page without selecting the module to map.');
|
|
75
77
|
if (!page || typeof (page) !== 'object') throw new Error('Page to map modules not found.');
|
|
@@ -80,7 +82,7 @@ class SDK {
|
|
|
80
82
|
const module = modulePiece[key];
|
|
81
83
|
if (!module || typeof (module) !== 'object') continue;
|
|
82
84
|
if (module.component === moduleName) {
|
|
83
|
-
if (!found) console.log(`\tModule ${moduleName} found.`);
|
|
85
|
+
if (!found && this._env.verbose) console.log(`\tModule ${moduleName} found.`);
|
|
84
86
|
const newModule = await callback(JSON.parse(JSON.stringify(module)));
|
|
85
87
|
if (newModule) modulePiece[key] = newModule;
|
|
86
88
|
found = true;
|
|
@@ -89,12 +91,12 @@ class SDK {
|
|
|
89
91
|
}
|
|
90
92
|
};
|
|
91
93
|
await search(protectedPage);
|
|
92
|
-
if (!found) console.log(`\tModule ${moduleName} not found.`);
|
|
94
|
+
if (!found && this._env.verbose) console.log(`\tModule ${moduleName} not found.`);
|
|
93
95
|
return protectedPage;
|
|
94
96
|
};
|
|
95
97
|
|
|
96
98
|
async mapModules(callback, moduleName, template) {
|
|
97
|
-
console.log(`\nMapping modules ${moduleName} from ${template || 'all'} pages with callback function ${callback.name}...`);
|
|
99
|
+
if (this._env.verbose) console.log(`\nMapping modules ${moduleName} from ${template || 'all'} pages with callback function ${callback.name}...`);
|
|
98
100
|
if (!callback || typeof (callback) !== 'function') throw new Error('Cannot map modules without a callback function.');
|
|
99
101
|
if (!moduleName) throw new Error('Cannot map modules in page without selecting the module to map.');
|
|
100
102
|
const fixPage = (page) => this.mapModulesFromPage(page, moduleName, callback);
|
package/models/auth.js
CHANGED
|
@@ -5,11 +5,12 @@ const getToken = async (params) => {
|
|
|
5
5
|
api: apiKey,
|
|
6
6
|
user: email,
|
|
7
7
|
password,
|
|
8
|
+
verbose,
|
|
8
9
|
} = params;
|
|
9
|
-
console.log('Logging to api...');
|
|
10
|
+
if (verbose) console.log('Logging to api...');
|
|
10
11
|
const token = await api({ api: apiKey }, 'post', '/login_check', { email, password })
|
|
11
12
|
.then(data => data.token);
|
|
12
|
-
console.log('Authenticated.');
|
|
13
|
+
if (verbose) console.log('Authenticated.');
|
|
13
14
|
return token;
|
|
14
15
|
};
|
|
15
16
|
|
package/models/pages.js
CHANGED
|
@@ -4,7 +4,7 @@ const getPages = (env, template = null) => api(env, 'get', `/pages/all/id/${temp
|
|
|
4
4
|
|
|
5
5
|
const getPage = async (env, pageId) => {
|
|
6
6
|
const page = await api(env, 'get', `/page/${pageId}`)
|
|
7
|
-
console.log('\tLoaded page', page.title);
|
|
7
|
+
if (env.verbose) console.log('\tLoaded page', page.title);
|
|
8
8
|
return page;
|
|
9
9
|
};
|
|
10
10
|
|
|
@@ -27,17 +27,17 @@ const savePage = async (env, page) => {
|
|
|
27
27
|
actionName,
|
|
28
28
|
} = actions[page.id ? 'update' : 'new'];
|
|
29
29
|
const savedPage = await api(env, method, endpoint, page);
|
|
30
|
-
console.log(`\tPage ${actionName}.`);
|
|
30
|
+
if (env.verbose) console.log(`\tPage ${actionName}.`);
|
|
31
31
|
return savedPage;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const deletePage = (env, id) => {
|
|
35
|
-
console.log('\tDelete page', id);
|
|
35
|
+
if (env.verbose) console.log('\tDelete page', id);
|
|
36
36
|
return api(env, 'delete', `/page/${id}`);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const restorePage = (env, id) => {
|
|
40
|
-
console.log('\tRestore page', id);
|
|
40
|
+
if (env.verbose) console.log('\tRestore page', id);
|
|
41
41
|
return api(env, 'delete', `/page/${id}/undo`);
|
|
42
42
|
};
|
|
43
43
|
|
package/models/structuredData.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const { api } = require('../api');
|
|
2
2
|
|
|
3
|
-
const getStructuredData = async (env, id, site = null, language = null) => {
|
|
3
|
+
const getStructuredData = async (env, id, site = null, language = null, verbose) => {
|
|
4
4
|
const headers = {
|
|
5
5
|
lang: language,
|
|
6
6
|
};
|
|
7
7
|
const items = await api(env, 'get', `${site ? `/site/${site}` : ''}/structured_data_contents/${id}?pagination=false&includeDraft=true`, { headers })
|
|
8
8
|
.then(data => data.items);
|
|
9
|
-
console.log(`\tStructured data ${id} loaded.`);
|
|
9
|
+
if (env.verbose) console.log(`\tStructured data ${id} loaded.`);
|
|
10
10
|
return items;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ const saveStructuredData = async (env, structuredData) => {
|
|
|
29
29
|
actionName,
|
|
30
30
|
} = actions[structuredData.id ? 'update' : 'new'];
|
|
31
31
|
const savedItem = await api(env, method, endpoint, structuredData);
|
|
32
|
-
console.log(`\tStructured data ${structuredData?.content?.title || structuredData?.content?.label || 'untitled'} in ${structuredData.structuredData} ${actionName}.`);
|
|
32
|
+
if (env.verbose) console.log(`\tStructured data ${structuredData?.content?.title || structuredData?.content?.label || 'untitled'} in ${structuredData.structuredData} ${actionName}.`);
|
|
33
33
|
return savedItem;
|
|
34
34
|
};
|
|
35
35
|
|