griddo-sdk 1.0.9 → 1.0.12
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 +20 -2
- package/models/structuredData.js +3 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -121,8 +121,8 @@ class SDK {
|
|
|
121
121
|
return await restorePage(this._env, id);
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
-
async getStructuredData(
|
|
125
|
-
return await getStructuredData(this._env,
|
|
124
|
+
async getStructuredData(contentType, site = null, language = null) {
|
|
125
|
+
return await getStructuredData(this._env, contentType, site, language);
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
async saveStructuredData(structuredData) {
|
|
@@ -133,6 +133,24 @@ class SDK {
|
|
|
133
133
|
return await deleteStructuredData(this._env, id);
|
|
134
134
|
};
|
|
135
135
|
|
|
136
|
+
async mapStructuredData(callback, contentType) {
|
|
137
|
+
if (this._env.verbose) console.log(`\nMapping ${contentType || 'all'} structured data with callback function ${callback.name}...`);
|
|
138
|
+
if (!callback || typeof (callback) !== 'function') throw new Error('Cannot map structured data without a callback function.');
|
|
139
|
+
const content = await getStructuredData(this._env, contentType);
|
|
140
|
+
if (!content?.length) {
|
|
141
|
+
if (this._env.verbose) console.log('- No structured data found.');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
for (const structuredData of content) {
|
|
145
|
+
if (this._env.verbose) console.log('- Mapping structured data', structuredData.id);
|
|
146
|
+
const dataProtected = JSON.parse(JSON.stringify(structuredData));
|
|
147
|
+
const result = await callback(dataProtected);
|
|
148
|
+
if (result && JSON.stringify(structuredData) !== JSON.stringify(result)) {
|
|
149
|
+
await saveStructuredData(this._env, result)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
136
154
|
async api(...params) {
|
|
137
155
|
return await api(this._env, ...params);
|
|
138
156
|
};
|
package/models/structuredData.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const { api } = require('../api');
|
|
2
2
|
|
|
3
|
-
const getStructuredData = async (env,
|
|
3
|
+
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/${
|
|
7
|
+
const items = await api(env, 'get', `${site ? `/site/${site}` : ''}/structured_data_contents/${contentType||''}?pagination=false&includeDraft=true`, { headers })
|
|
8
8
|
.then(data => data.items);
|
|
9
|
-
if (env.verbose) console.log(`\tStructured data ${
|
|
9
|
+
if (env.verbose) console.log(`\tStructured data ${contentType} loaded.`);
|
|
10
10
|
return items;
|
|
11
11
|
};
|
|
12
12
|
|