storyblok-js-client
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -32,3 +32,4 @@ declare global { | ||
interface StoryblokConfig { | ||
accessToken: string | ||
accessToken?: string | ||
oauthToken?: string | ||
cache?: StoryblokCache | ||
@@ -51,2 +52,7 @@ timeout?: number | ||
export interface StoryblokManagmentApiResult { | ||
data: any | ||
headers: any | ||
} | ||
export interface StoryData { | ||
@@ -127,2 +133,5 @@ alternates: string[] | ||
get(slug: string, params?: any): Promise<StoryblokResult> | ||
post(slug: string, params?: any): Promise<StoryblokManagmentApiResult> | ||
put(slug: string, params?: any): Promise<StoryblokManagmentApiResult> | ||
delete(slug: string, params?: any): Promise<StoryblokManagmentApiResult> | ||
getStories(params?: StoriesParams): Promise<Stories> | ||
@@ -129,0 +138,0 @@ getStory(slug: string, params?: StoryParams): Promise<Story> |
@@ -25,2 +25,6 @@ 'use strict'; | ||
if (typeof config.oauthToken != 'undefined') { | ||
headers['Authorization'] = config.oauthToken; | ||
} | ||
this.throttle = throttledQueue(5, 1000); | ||
@@ -32,3 +36,3 @@ this.cacheVersion = this.cacheVersion || this.newVersion(); | ||
baseURL: endpoint, | ||
timeout: config.timeout || 5000, | ||
timeout: config.timeout || 0, | ||
headers: headers | ||
@@ -61,2 +65,20 @@ }); | ||
}, { | ||
key: 'post', | ||
value: function post(slug, params) { | ||
var url = '/' + slug; | ||
return this.throttledRequest('post', url, params); | ||
} | ||
}, { | ||
key: 'put', | ||
value: function put(slug, params) { | ||
var url = '/' + slug; | ||
return this.throttledRequest('put', url, params); | ||
} | ||
}, { | ||
key: 'delete', | ||
value: function _delete(slug, params) { | ||
var url = '/' + slug; | ||
return this.throttledRequest('delete', url, params); | ||
} | ||
}, { | ||
key: 'getStories', | ||
@@ -98,29 +120,27 @@ value: function getStories(params) { | ||
} else { | ||
_this.throttle(function () { | ||
_this.client.get(url, { | ||
params: params, | ||
paramsSerializer: function paramsSerializer(params) { | ||
return qs.stringify(params, { arrayFormat: 'brackets' }); | ||
} | ||
}).then(function (res) { | ||
var response = { data: res.data, headers: res.headers }; | ||
_this.throttledRequest('get', url, { | ||
params: params, | ||
paramsSerializer: function paramsSerializer(params) { | ||
return qs.stringify(params, { arrayFormat: 'brackets' }); | ||
} | ||
}).then(function (res) { | ||
var response = { data: res.data, headers: res.headers }; | ||
if (res.headers['per-page']) { | ||
response = _extends({}, response, { | ||
perPage: parseInt(res.headers['per-page']), | ||
total: parseInt(res.headers['total']) | ||
}); | ||
} | ||
if (res.headers['per-page']) { | ||
response = _extends({}, response, { | ||
perPage: parseInt(res.headers['per-page']), | ||
total: parseInt(res.headers['total']) | ||
}); | ||
} | ||
if (res.status != 200) { | ||
return reject(res); | ||
} | ||
if (res.status != 200) { | ||
return reject(res); | ||
} | ||
if (params.version === 'published') { | ||
provider.set(cacheKey, response); | ||
} | ||
resolve(response); | ||
}).catch(function (response) { | ||
reject(response); | ||
}); | ||
if (params.version === 'published') { | ||
provider.set(cacheKey, response); | ||
} | ||
resolve(response); | ||
}).catch(function (response) { | ||
reject(response); | ||
}); | ||
@@ -131,2 +151,17 @@ } | ||
}, { | ||
key: 'throttledRequest', | ||
value: function throttledRequest(type, url, params) { | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this2.throttle(function () { | ||
_this2.client[type](url, params).then(function (response) { | ||
resolve(response); | ||
}).catch(function (response) { | ||
reject(response); | ||
}); | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'newVersion', | ||
@@ -133,0 +168,0 @@ value: function newVersion() { |
{ | ||
"name": "storyblok-js-client", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "Universal JavaScript SDK for Storyblok's API", | ||
@@ -26,3 +26,4 @@ "main": "./dist/index.js", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1" | ||
"babel-preset-es2015": "^6.24.1", | ||
"lodash": "~>4.17.5" | ||
}, | ||
@@ -29,0 +30,0 @@ "dependencies": { |
@@ -18,2 +18,6 @@ 'use strict' | ||
if (typeof config.oauthToken != 'undefined') { | ||
headers['Authorization'] = config.oauthToken | ||
} | ||
this.throttle = throttledQueue(5, 1000) | ||
@@ -25,3 +29,3 @@ this.cacheVersion = (this.cacheVersion || this.newVersion()) | ||
baseURL: endpoint, | ||
timeout: (config.timeout || 5000), | ||
timeout: (config.timeout || 0), | ||
headers: headers | ||
@@ -52,2 +56,17 @@ }) | ||
post(slug, params) { | ||
let url = `/${slug}` | ||
return this.throttledRequest('post', url, params) | ||
} | ||
put(slug, params) { | ||
let url = `/${slug}` | ||
return this.throttledRequest('put', url, params) | ||
} | ||
delete(slug, params) { | ||
let url = `/${slug}` | ||
return this.throttledRequest('delete', url, params) | ||
} | ||
getStories(params) { | ||
@@ -82,30 +101,29 @@ return this.get('cdn/stories', params) | ||
} else { | ||
this.throttle(() => { | ||
this.client.get(url, { | ||
params: params, | ||
paramsSerializer: params => qs.stringify(params, {arrayFormat: 'brackets'}) | ||
}) | ||
.then((res) => { | ||
let response = {data: res.data, headers: res.headers} | ||
this.throttledRequest('get', url, { | ||
params: params, | ||
paramsSerializer: params => qs.stringify(params, {arrayFormat: 'brackets'}) | ||
}) | ||
.then((res) => { | ||
let response = {data: res.data, headers: res.headers} | ||
if (res.headers['per-page']) { | ||
response = Object.assign({}, response, { | ||
perPage: parseInt(res.headers['per-page']), | ||
total: parseInt(res.headers['total']) | ||
}) | ||
} | ||
if (res.headers['per-page']) { | ||
response = Object.assign({}, response, { | ||
perPage: parseInt(res.headers['per-page']), | ||
total: parseInt(res.headers['total']) | ||
}) | ||
} | ||
if (res.status != 200) { | ||
return reject(res) | ||
} | ||
if (res.status != 200) { | ||
return reject(res) | ||
} | ||
if (params.version === 'published') { | ||
provider.set(cacheKey, response) | ||
} | ||
resolve(response) | ||
}) | ||
.catch((response) => { | ||
reject(response) | ||
}) | ||
}) | ||
if (params.version === 'published') { | ||
provider.set(cacheKey, response) | ||
} | ||
resolve(response) | ||
}) | ||
.catch((response) => { | ||
reject(response) | ||
}) | ||
} | ||
@@ -115,2 +133,16 @@ }) | ||
throttledRequest(type, url, params) { | ||
return new Promise((resolve, reject) => { | ||
this.throttle(() => { | ||
this.client[type](url, params) | ||
.then((response) => { | ||
resolve(response) | ||
}) | ||
.catch((response) => { | ||
reject(response) | ||
}) | ||
}) | ||
}) | ||
} | ||
newVersion() { | ||
@@ -117,0 +149,0 @@ return new Date().getTime() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18457
468
4
5