Skip to content

Commit 7383e6a

Browse files
committed
fix: added api_version support and test
1 parent a4c6e82 commit 7383e6a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/stack/api/asset/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,19 @@ class Asset extends Base {
205205
});
206206
* @return {external:Promise}
207207
*/
208-
publish(payload) {
208+
publish(payload: { [key: string]: any }, api_version: string = "") {
209209
if (
210210
!payload ||
211211
typeof payload !== "object" ||
212212
payload instanceof Array
213213
) {
214214
return Promise.reject(new Error("Kindly provide valid parameters"));
215215
}
216+
217+
if (api_version !== "") {
218+
payload = { ...payload, headers: { api_version } };
219+
}
220+
216221
return this.fetch("publishAsset", payload);
217222
}
218223

src/stack/api/base.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class Base {
6161
}
6262

6363
fetch(action: string, payload?: { [key: string]: any }) {
64+
console.log('fetch------->', action, payload);
6465
const options = {
6566
payload,
6667
content_type_uid: this.constructor.contentTypeUid,
@@ -69,6 +70,12 @@ export default class Base {
6970
action: action || `get${this.constructor.module()}`
7071
};
7172

73+
if ((action === 'publishEntry' || action === 'publishAsset') && payload?.headers && Object.keys(payload.headers).length > 0) {
74+
options.headers = payload.headers;
75+
}
76+
77+
console.log('options before cleanup------->', options);
78+
7279
if (!payload) { delete options.payload; }
7380
if (!this.constructor.contentTypeUid) { delete options.content_type_uid; }
7481
return this.constructor.connection.sendToParent('stackQuery', options)

src/stack/api/content-type/entry.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,19 @@ class Entry extends Base {
269269
}).then(...).catch(...);
270270
* @return {external:Promise}
271271
*/
272-
publish(payload: { [key: string]: any }) {
272+
publish(payload: { [key: string]: any }, api_version: string = "") {
273273
if (
274274
!payload ||
275275
typeof payload !== "object" ||
276276
payload instanceof Array
277277
) {
278278
return Promise.reject(new Error("Kindly provide valid parameters"));
279279
}
280+
281+
if (api_version !== "") {
282+
payload = { ...payload, headers: { api_version } };
283+
}
284+
280285
this._query = {};
281286
return this.fetch("publishEntry", payload);
282287
}

0 commit comments

Comments
 (0)