@bynder/bynder-js-sdk
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -7,4 +7,8 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
require('isomorphic-form-data'); | ||
var _oauth = require('oauth-1.0a'); | ||
@@ -18,2 +22,4 @@ | ||
var _path = require('path'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -116,3 +122,3 @@ | ||
} else { | ||
requestBody += encodeURI(key) + '=' + encodeURI(value) + '&'; | ||
requestBody += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&'; | ||
} | ||
@@ -172,3 +178,3 @@ } | ||
} | ||
if (response.status === 200) { | ||
if (response.status >= 200 && response.status <= 202) { | ||
return response.data; | ||
@@ -527,2 +533,25 @@ } | ||
/** | ||
* Modify new metaproperty with the information provided. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/metaproperties/specific-metaproperty-operations/modify-metaproperty|API Call} | ||
* @param {Object} object={} - An object containing the data of the metaproperty. | ||
* @param {String} queryObject.id - The id of the desired metaproperty. | ||
* @return {Promise} Object - Returns a Promise that, when fulfilled, will either return an empty Object in | ||
* case it's successful or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'editMetaproperty', | ||
value: function editMetaproperty(object) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!object.id) { | ||
return rejectValidation('metaproperty', 'id'); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/metaproperties/' + object.id + '/', 'POST', this.consumerToken, this.accessToken, { data: JSON.stringify(object) } // The API requires an object with the query content stringified inside | ||
); | ||
return request.send(); | ||
} | ||
/** | ||
* Delete the metaproperty with the provided id. | ||
@@ -550,2 +579,77 @@ * @see {@link http://docs.bynder.apiary.io/#reference/metaproperties/delete-metaproperty|API Call} | ||
/** | ||
* Add an option of metaproperty | ||
* @see {@link http://docs.bynder.apiary.io/#reference/metaproperties/specific-metaproperty-operations/create-metaproperty-option|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired metaproperty. | ||
* @param {String} queryObject.id - The id of the desired metaproperty. | ||
* @param {String} queryObject.name - The name of the desired metaproperty. | ||
* @return {Promise} Response - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* response or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'saveNewMetapropertyOption', | ||
value: function saveNewMetapropertyOption(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.id || !queryObject.name) { | ||
return rejectValidation('metaproperty option', 'id or name'); | ||
} | ||
var queryBody = Object.assign({}, queryObject); | ||
delete queryBody.id; | ||
var request = new APICall(this.baseURL, 'v4/metaproperties/' + queryObject.id + '/options/', 'POST', this.consumerToken, this.accessToken, { data: JSON.stringify(queryBody) }); | ||
return request.send(); | ||
} | ||
/** | ||
* modify an option of metaproperty | ||
* @see {@link http://docs.bynder.apiary.io/#reference/metaproperties/specific-metaproperty-operations/modify-metaproperty-option|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired metaproperty. | ||
* @param {String} queryObject.id - The id of the desired metaproperty. | ||
* @param {String} queryObject.optionId - The id of the desired option. | ||
* @param {String} queryObject.name - The id of the desired metaproperty. | ||
* @return {Promise} Response - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* response or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'editMetapropertyOption', | ||
value: function editMetapropertyOption(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.id || !queryObject.optionId) { | ||
return rejectValidation('metaproperty option', 'id or optionId'); | ||
} | ||
var queryBody = Object.assign({}, queryObject); | ||
delete queryBody.id; | ||
var request = new APICall(this.baseURL, 'v4/metaproperties/' + queryObject.id + '/options/' + queryObject.optionId + '/', 'POST', this.consumerToken, this.accessToken, { data: JSON.stringify(queryBody) }); | ||
return request.send(); | ||
} | ||
/** | ||
* delete an option of metaproperty | ||
* @see {@link http://docs.bynder.apiary.io/#reference/metaproperties/specific-metaproperty-operations/delete-metaproperty-option|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired metaproperty. | ||
* @param {String} queryObject.id - The id of the desired metaproperty. | ||
* @param {String} queryObject.optionId - The id of the desired option. | ||
* @param {String} queryObject.name - The id of the desired metaproperty. | ||
* @return {Promise} Response - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* response or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'deleteMetapropertyOption', | ||
value: function deleteMetapropertyOption(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.id || !queryObject.optionId) { | ||
return rejectValidation('metaproperty option', 'id or optionId'); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/metaproperties/' + queryObject.id + '/options/' + queryObject.optionId + '/', 'DELETE', this.consumerToken, this.accessToken); | ||
return request.send(); | ||
} | ||
/** | ||
* Get all the tags | ||
@@ -609,2 +713,418 @@ * @see {@link http://docs.bynder.apiary.io/#reference/tags/tags-access/retrieve-entry-point|API Call} | ||
} | ||
/** | ||
* Create the collection information according to the name provided. | ||
* @see {@link http://docs.bynder.apiary.io/#reference/collections/specific-collection-operations/create-collection|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired collection. | ||
* @param {String} queryObject.name - The name of the desired collection. | ||
* @param {String} queryObject.description - The description of the desired collection. | ||
* @return {Promise} Response - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* response or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'saveNewCollection', | ||
value: function saveNewCollection(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.name) { | ||
return rejectValidation('collection', 'name'); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/collections/', 'POST', this.consumerToken, this.accessToken, queryObject); | ||
return request.send(); | ||
} | ||
/** | ||
* Add assets to the desired collection. | ||
* @see {@link http://docs.bynder.apiary.io/#reference/collections/specific-collection-operations/add-asset-to-a-collection|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired collection. | ||
* @param {String} queryObject.id - The id of the shared collection. | ||
* @param {String} queryObject.data - JSON-serialised list of asset ids to add. | ||
* @return {Promise} Response - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* response or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'addMediaToCollection', | ||
value: function addMediaToCollection(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.id) { | ||
return rejectValidation('collection', 'id'); | ||
} | ||
if (!queryObject.data) { | ||
return rejectValidation('collection', 'data'); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/collections/' + queryObject.id + '/media/', 'POST', this.consumerToken, this.accessToken, { data: JSON.stringify(queryObject.data) }); | ||
return request.send(); | ||
} | ||
/** | ||
* Share the collection to the recipients provided. | ||
* @see {@link http://docs.bynder.apiary.io/#reference/collections/specific-collection-operations/share-collection|API Call} | ||
* @param {Object} queryObject={} - An object containing the id of the desired collection. | ||
* @param {String} queryObject.id - The id of the shared collection. | ||
* @param {String} queryObject.recipients - The email addressed of the recipients. | ||
* @param {String} queryObject.collectionOptions - The recipent right of the shared collection: view, edit | ||
* @return {Promise} Collection - Returns a Promise that, when fulfilled, will either return an Object with the | ||
* collection or an Error with the problem. | ||
*/ | ||
}, { | ||
key: 'shareCollection', | ||
value: function shareCollection(queryObject) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!queryObject.id) { | ||
return rejectValidation('collection', 'id'); | ||
} | ||
if (!queryObject.recipients) { | ||
return rejectValidation('collection', 'recipients'); | ||
} | ||
if (!queryObject.collectionOptions) { | ||
return rejectValidation('collection', 'collectionOptions'); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/collections/' + queryObject.id + '/share/', 'POST', this.consumerToken, this.accessToken, queryObject); | ||
return request.send(); | ||
} | ||
/** | ||
* Get a list of brands and subbrands | ||
* @see {@link https://bynder.docs.apiary.io/#reference/security-roles/specific-security-profile/retrieve-brands-and-subbrands} | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'getBrands', | ||
value: function getBrands() { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/brands/', 'GET', this.consumerToken, this.accessToken); | ||
return request.send(); | ||
} | ||
/** | ||
* Gets the closest Amazon S3 bucket location to upload to. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/1-get-closest-amazons3-upload-endpoint/get-closest-amazons3-upload-endpoint} | ||
* @return {Promise} Amazon S3 location url string. | ||
*/ | ||
}, { | ||
key: 'getClosestUploadEndpoint', | ||
value: function getClosestUploadEndpoint() { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var request = new APICall(this.baseURL, 'upload/endpoint', 'GET', this.consumerToken, this.accessToken); | ||
return request.send(); | ||
} | ||
/** | ||
* Starts the upload process. Registers a file upload with Bynder and returns authorisation information to allow | ||
* uploading to the Amazon S3 bucket-endpoint. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/2-initialise-upload/initialise-upload} | ||
* @param {String} filename - filename | ||
* @return {Promise} Relevant S3 file information, necessary for the file upload. | ||
*/ | ||
}, { | ||
key: 'initUpload', | ||
value: function initUpload(filename) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!filename) { | ||
return rejectValidation('upload', 'filename'); | ||
} | ||
var request = new APICall(this.baseURL, 'upload/init', 'POST', this.consumerToken, this.accessToken, { filename: filename }); | ||
return request.send(); | ||
} | ||
/** | ||
* Registers a temporary chunk in Bynder. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/3-upload-file-in-chunks-and-register-every-uploaded-chunk/register-uploaded-chunk} | ||
* @param {Object} init - result from init upload | ||
* @param {Number} chunkNumber - chunk number | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'registerChunk', | ||
value: function registerChunk(init, chunkNumber) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var s3file = init.s3file, | ||
filename = init.s3_filename; | ||
var uploadid = s3file.uploadid, | ||
targetid = s3file.targetid; | ||
var request = new APICall(this.baseURL, 'v4/upload/', 'POST', this.consumerToken, this.accessToken, { | ||
id: uploadid, | ||
targetid: targetid, | ||
filename: filename + '/p' + chunkNumber, | ||
chunkNumber: chunkNumber | ||
}); | ||
return request.send(); | ||
} | ||
/** | ||
* Finalises the file upload when all chunks finished uploading and registers it in Bynder. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/4-finalise-a-completely-uploaded-file/finalise-a-completely-uploaded-file} | ||
* @param {Object} init - Result from init upload | ||
* @param {String} fileName - Original file name | ||
* @param {Number} chunks - Number of chunks | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'finaliseUpload', | ||
value: function finaliseUpload(init, filename, chunks) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var s3file = init.s3file, | ||
s3filename = init.s3_filename; | ||
var uploadid = s3file.uploadid, | ||
targetid = s3file.targetid; | ||
var request = new APICall(this.baseURL, 'v4/upload/' + uploadid + '/', 'POST', this.consumerToken, this.accessToken, { | ||
targetid: targetid, | ||
s3_filename: s3filename + '/p' + chunks, | ||
original_filename: filename, | ||
chunks: chunks | ||
}); | ||
return request.send(); | ||
} | ||
/** | ||
* Checks if the files have finished uploading. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/5-poll-processing-state-of-finalised-files/retrieve-entry-point} | ||
* @param {String[]} importIds - The import IDs of the files to be checked. | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'pollUploadStatus', | ||
value: function pollUploadStatus(importIds) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var request = new APICall(this.baseURL, 'v4/upload/poll/', 'GET', this.consumerToken, this.accessToken, { items: importIds.join(',') }); | ||
return request.send(); | ||
} | ||
/** | ||
* Resolves once assets are uploaded, or rejects after 60 attempts with 2000ms between them | ||
* @param {String[]} importIds - The import IDs of the files to be checked. | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'waitForUploadDone', | ||
value: function waitForUploadDone(importIds) { | ||
var POLLING_INTERVAL = 2000; | ||
var MAX_POLLING_ATTEMPTS = 60; | ||
var pollUploadStatus = this.pollUploadStatus.bind(this); | ||
return new Promise(function (resolve, reject) { | ||
var attempt = 0; | ||
(function checkStatus() { | ||
pollUploadStatus(importIds).then(function (pollStatus) { | ||
if (pollStatus !== null) { | ||
var itemsDone = pollStatus.itemsDone, | ||
itemsFailed = pollStatus.itemsFailed; | ||
if (itemsDone.length === importIds.length) { | ||
// done ! | ||
return resolve({ itemsDone: itemsDone }); | ||
} | ||
if (itemsFailed.length > 0) { | ||
// failed | ||
return reject({ itemsFailed: itemsFailed }); | ||
} | ||
} | ||
if (++attempt > MAX_POLLING_ATTEMPTS) { | ||
// timed out | ||
return reject(new Error('Stopped polling after ' + attempt + ' attempts')); | ||
} | ||
return setTimeout(checkStatus, POLLING_INTERVAL); | ||
}).catch(reject); | ||
})(); | ||
}); | ||
} | ||
/** | ||
* Saves a media asset in Bynder. If media id is specified in the data a new version of the asset will be saved. | ||
* Otherwise a new asset will be saved. | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets/4-finalise-a-completely-uploaded-file/save-as-a-new-asset} | ||
* @param {Object} data - Asset data | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'saveAsset', | ||
value: function saveAsset(data) { | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
var brandId = data.brandId, | ||
mediaId = data.mediaId; | ||
if (!brandId) { | ||
return rejectValidation('upload', 'brandId'); | ||
} | ||
var saveURL = mediaId ? 'v4/media/' + mediaId + '/save/' : 'v4/media/save/'; | ||
var request = new APICall(this.baseURL, saveURL, 'POST', this.consumerToken, this.accessToken, data); | ||
return request.send(); | ||
} | ||
/** | ||
* Uploads arbirtrarily sized buffer or stream file to provided S3 endpoint in chunks and registers each chunk to Bynder. | ||
* Resolves the passed init result and final chunk number. | ||
* @param {Object} file ={} - An object containing the id of the desired collection. | ||
* @param {String} file.filename - The file name of the file to be saved | ||
* @param {Buffer|Readable} file.body - The file to be uploaded. Can be either buffer or a read stream. | ||
* @param {Number} file.length - The length of the file to be uploaded | ||
* @param {string} endpoint - S3 endpoint url | ||
* @param {Object} init - Result from init upload | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'uploadFileInChunks', | ||
value: function uploadFileInChunks(file, endpoint, init) { | ||
var body = file.body; | ||
var isBuffer = Buffer.isBuffer(body); | ||
var length = isBuffer ? body.length : file.length; | ||
var CHUNK_SIZE = 1024 * 1024 * 5; | ||
var chunks = Math.ceil(length / CHUNK_SIZE); | ||
var registerChunk = this.registerChunk.bind(this); | ||
var uploadPath = init.multipart_params.key; | ||
var uploadChunkToS3 = function uploadChunkToS3(chunkData, chunkNumber) { | ||
var form = new FormData(); | ||
var params = Object.assign(init.multipart_params, { | ||
name: (0, _path.basename)(uploadPath) + '/p' + chunkNumber, | ||
chunk: chunkNumber, | ||
chunks: chunks, | ||
Filename: uploadPath + '/p' + chunkNumber, | ||
key: uploadPath + '/p' + chunkNumber | ||
}); | ||
Object.keys(params).forEach(function (key) { | ||
form.append(key, params[key]); | ||
}); | ||
form.append('file', chunkData); | ||
var headers = Object.assign(form.getHeaders(), { | ||
'content-length': form.getLengthSync() | ||
}); | ||
return _axios2.default.post(endpoint, form, { headers: headers }); | ||
}; | ||
// sequentially upload chunks to AWS, then register them | ||
return new Promise(function (resolve, reject) { | ||
var chunkNumber = 0; | ||
(function nextChunk() { | ||
if (chunkNumber >= chunks) { | ||
// we are finished, pass init and chunk number to be finalised | ||
return resolve({ init: init, chunkNumber: chunkNumber }); | ||
} | ||
// upload next chunk | ||
var chunkData = void 0; | ||
if (isBuffer) { | ||
// handle buffer data | ||
var start = chunkNumber * CHUNK_SIZE; | ||
var end = Math.min(start + CHUNK_SIZE, length); | ||
chunkData = body.slice(start, end); | ||
} else { | ||
// handle stream data | ||
chunkData = body.read(CHUNK_SIZE); | ||
if (chunkData === null) { | ||
// our read stream is not done yet reading | ||
// let's wait for a while... | ||
return setTimeout(nextChunk, 50); | ||
} | ||
} | ||
return uploadChunkToS3(chunkData, ++chunkNumber).then(function () { | ||
// register uploaded chunk to Bynder | ||
return registerChunk(init, chunkNumber); | ||
}).then(nextChunk).catch(reject); | ||
})(); | ||
}); | ||
} | ||
/** | ||
* Uploads an arbitrarily sized buffer or stream file and returns the uploaded asset information | ||
* @see {@link https://bynder.docs.apiary.io/#reference/upload-assets} | ||
* @param {Object} file={} - An object containing the id of the desired collection. | ||
* @param {String} file.filename - The file name of the file to be saved | ||
* @param {Buffer|Readable} file.body - The file to be uploaded. Can be either buffer or a read stream. | ||
* @param {Number} file.length - The length of the file to be uploaded | ||
* @param {Object} file.data={} - An object containing the assets' attributes | ||
* @return {Promise} The information of the uploaded file, including IDs and all final file urls. | ||
*/ | ||
}, { | ||
key: 'uploadFile', | ||
value: function uploadFile(file) { | ||
var body = file.body, | ||
filename = file.filename, | ||
data = file.data; | ||
var brandId = data.brandId; | ||
var isBuffer = Buffer.isBuffer(body); | ||
var isStream = typeof body.read === 'function'; | ||
var length = isBuffer ? body.length : file.length; | ||
if (!this.validURL()) { | ||
return rejectURL(); | ||
} | ||
if (!brandId) { | ||
return rejectValidation('upload', 'brandId'); | ||
} | ||
if (!filename) { | ||
return rejectValidation('upload', 'filename'); | ||
} | ||
if (!body || !isStream && !isBuffer) { | ||
return rejectValidation('upload', 'body'); | ||
} | ||
if (!length || typeof length !== 'number') { | ||
return rejectValidation('upload', 'length'); | ||
} | ||
var getClosestUploadEndpoint = this.getClosestUploadEndpoint.bind(this); | ||
var initUpload = this.initUpload.bind(this); | ||
var uploadFileInChunks = this.uploadFileInChunks.bind(this); | ||
var finaliseUpload = this.finaliseUpload.bind(this); | ||
var saveAsset = this.saveAsset.bind(this); | ||
var waitForUploadDone = this.waitForUploadDone.bind(this); | ||
return Promise.all([getClosestUploadEndpoint(), initUpload(filename)]).then(function (res) { | ||
var _res = _slicedToArray(res, 2), | ||
endpoint = _res[0], | ||
init = _res[1]; | ||
return uploadFileInChunks(file, endpoint, init); | ||
}).then(function (uploadResponse) { | ||
var init = uploadResponse.init, | ||
chunkNumber = uploadResponse.chunkNumber; | ||
return finaliseUpload(init, filename, chunkNumber); | ||
}).then(function (finalizeResponse) { | ||
var importId = finalizeResponse.importId; | ||
return waitForUploadDone([importId]); | ||
}).then(function (doneResponse) { | ||
var itemsDone = doneResponse.itemsDone; | ||
var importId = itemsDone[0]; | ||
return saveAsset(Object.assign(data, { importId: importId })); | ||
}); | ||
} | ||
}]); | ||
@@ -611,0 +1131,0 @@ |
{ | ||
"name": "@bynder/bynder-js-sdk", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Bynder Javascript SDK", | ||
@@ -37,3 +37,4 @@ "main": "./dist/bynder-js-sdk.js", | ||
"dependencies": { | ||
"axios": "^0.15.3", | ||
"axios": "^0.18.0", | ||
"isomorphic-form-data": "^1.0.0", | ||
"node-fetch": "^1.6.0", | ||
@@ -40,0 +41,0 @@ "oauth-1.0a": "^1.0.1" |
# Bynder JavaScript SDK | ||
This SDK aims to help the development of integrations with Bynder that use JavaScript, providing an easy interface to communicate with Bynder's REST API and request the information required. | ||
This SDK aims to help the development of integrations with [Bynder](https://www.bynder.com/en/) that use JavaScript, providing an easy interface to communicate with [Bynder's REST API](https://developer-docs.bynder.com/API/) and request the information required. | ||
For that purpose, many ES2015 features were used, as well as Promises notation to help dealing with asynchronous code. | ||
## Requirements | ||
In order to use this SDK, the only thing needed is an updated version of Node.js: | ||
* [Node.js v6.3.0 or above](https://nodejs.org/) | ||
In order to use this SDK, you'll need the following tools: | ||
* [Node.js **v6.3.0 or above**](https://nodejs.org/) | ||
* [Yarn](https://yarnpkg.com/) | ||
Node installation will include NPM, which is responsible for the dependencies management. | ||
Node installation will include [NPM](https://www.npmjs.com/), which is responsible for the dependencies management. | ||
@@ -32,5 +33,5 @@ ## Installation | ||
As said before, this SDK relies heavily on [Promises](https://developers.google.com/web/fundamentals/getting-started/primers/promises), making it easier to handle the asynchronous requests made to the API. | ||
Besides that, it provides a `Bynder` object containing several methods corresponding to the calls to be performed, which accept the parameters exactly according [Bynder's API documentation](http://docs.bynder.apiary.io/). | ||
Besides that, it provides a `Bynder` object containing several methods corresponding to the calls to be performed, which accept the parameters exactly according [Bynder's API documentation](http://docs.bynder.apiary.io/). | ||
This is a generic example of how to use the SDK, if you need specific details for a specific module, refer to [samples folder](https://github.com/Bynder/bynder-js-sdk-private/tree/develop/samples). | ||
This is a generic example of how to use the SDK, if you need specific details for a specific module, refer to [samples folder](https://github.com/Bynder/bynder-js-sdk/tree/master/samples). | ||
@@ -53,3 +54,4 @@ Before executing any request, you need to call the constructor passing your credentials as parameters, making it possible to authorize the calls to the API: | ||
From this point on, you just need to call the methods made available to call the API and retrieve the data your looking for. Following the Promises notation, you should use `.then()/.catch()` to handle respectively the successful and failed requests. | ||
From this point on, you just need to call the methods made available to call the API and retrieve the data you're looking for. Following the Promises notation, you should use `.then()`/`.catch()` to handle respectively the successful and failed requests. | ||
Except for some special cases, most of the calls only take an object as parameter. After that, you'll need to refer to the API to tune the query as intended. | ||
@@ -91,3 +93,7 @@ | ||
* `saveNewMetaproperty(object)` | ||
* `editMetaproperty(object)` | ||
* `deleteMetaproperty(object)` | ||
* `saveNewMetapropertyOption(object)` | ||
* `editMetapropertyOption(object)` | ||
* `deleteMetapropertyOption(object)` | ||
@@ -97,2 +103,5 @@ ### Collections | ||
* `getCollection(queryObject)` | ||
* `saveNewCollection(queryObject)` | ||
* `shareCollection(queryObject)` | ||
* `addMediaToCollection(queryObject)` | ||
@@ -106,2 +115,8 @@ ### Tags | ||
### Brands | ||
* `getBrands()` | ||
### Upload | ||
* `uploadFile(fileObject)` | ||
## Contribute to the SDK | ||
@@ -112,5 +127,5 @@ If you wish to contribute to this repository and further extend the API coverage of the SDK, here are the steps necessary to prepare your environment: | ||
2. In the root folder, run `npm install` to install all the dependencies. | ||
3. Use the file named 'secret.json' for the tokens with this structure: | ||
3. Create the file named `secret.json` to provide API tokens following this structure: | ||
```json | ||
{ | ||
{ | ||
"consumer": { | ||
@@ -133,2 +148,2 @@ "public": "<public_consumer_key>", | ||
5. `gulp doc` - Run JSDoc to create a 'doc' folder with automatically generated documentation for the source code. | ||
6. `gulp webserver` - Deploy a web server from the root folder at `localhost:8080` to run the html samples (in order to avoid CORS problems). | ||
6. `gulp webserver` - Deploy a web server from the root folder at `localhost:8080` to run the html samples (in order to avoid CORS problems). |
@@ -1,15 +0,11 @@ | ||
{ "consumer": { | ||
"public": "4B5A0DD6-BA7B-4AB8-BDFBCB9EC2EA256D", | ||
"secret": "bf6b660c572cc9c19b89ca7261dfcfd1" | ||
}, | ||
"accessToken": { | ||
"public": "07121B18-F5C4-4861-9C2E22BD53FCF4AA", | ||
"secret": "a63950b9d6f459d26fffa256cf930315" | ||
}, | ||
"baseURL": "https://integrations.getbynder.com/api/", | ||
"login": { | ||
"consumerId": "DF0578B0-CDDB-44E6-A5E1E40AC7D2727B", | ||
"password": "Integrations@Bynder2017!", | ||
"username": "integrations@bynder.com" | ||
} | ||
} | ||
{ | ||
"consumer": { | ||
"public": "4B5A0DD6-BA7B-4AB8-BDFBCB9EC2EA256D", | ||
"secret": "bf6b660c572cc9c19b89ca7261dfcfd1" | ||
}, | ||
"accessToken": { | ||
"public": "07121B18-F5C4-4861-9C2E22BD53FCF4AA", | ||
"secret": "a63950b9d6f459d26fffa256cf930315" | ||
}, | ||
"baseURL": "https://integrations.getbynder.com/api/" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
1
143
2
1134470
4
12
26815
+ Addedisomorphic-form-data@^1.0.0
+ Addedasync@2.6.4(transitive)
+ Addedaxios@0.18.1(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedisomorphic-form-data@1.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
- Removedaxios@0.15.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removedfollow-redirects@1.0.0(transitive)
- Removedms@2.0.0(transitive)
Updatedaxios@^0.18.0