Git Product home page Git Product logo

bynder-js-sdk's Introduction

Bynder JavaScript SDK

Tests Publish

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.

Requirements

To use this SDK, you will need:

Node installation will include NPM, which is responsible for dependency management.

Installation

Node.js

npm install @bynder/bynder-js-sdk

import Bynder from '@bynder/bynder-js-sdk';

Usage

This SDK relies heavily on Promises, making it easier to handle the asynchronous requests made to the API. The SDK provides a Bynder object containing several methods which map to the calls and parameters described in Bynder's API documentation.

The following snippet is a generic example of how to use the SDK. If you need details for a specific module, refer to the samples folder.

Before executing any request, you need to authorize the calls to the API:

Using a permanent token

const bynder = new Bynder({
  baseURL: "https//portal.getbynder.com/api/",
  permanentToken: "<token>",
});

Using OAuth2

  1. Call the constructor with your configuration
const bynder = new Bynder({
  baseURL: "https://portal.getbynder.com/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>",
  redirectUri: "<url where user will be redirected after authenticating>"
});
  1. Create an authorization URL, login and get one-time authorization code
const authorizationURL = bynder.makeAuthorizationURL();
  1. Exchange code for an access token
bynder.getToken(code);

If you already have an access token, you can also initialize Bynder with the token directly:

const bynder = new Bynder({
  baseURL: "http://api-url.bynder.io/api/",
  clientId: "<your OAuth2 client id>",
  clientSecret: "<your OAuth2 client secret>",
  redirectUri: "<url where user will be redirected after authenticating>",
  token: "<OAuth2 access token>"
});

Making requests

You can now use the various methods from the SDK to fetch media, metaproperties and other data. Following the Promises notation, you should use .then()/.catch() to handle the successful and failed requests, respectively.

Most of the calls take an object as the only parameter but please refer to the API documentation to tune the query as intended.

bynder
  .getMediaList({
    type: "image",
    limit: 9,
    page: 1
  })
  .then(data => {
    // TODO Handle data
  })
  .catch(error => {
    // TODO Handle the error
  });

Available methods

Authentication

  • makeAuthorizationURL()
  • getToken()

Media

  • getMediaList(queryObject)
  • getMediaInfo(queryObject)
  • getAllMediaItems(queryObject)
  • getMediaTotal(queryObject)
  • editMedia(object)
  • deleteMedia(id)

Media usage

  • getAssetUsage(queryObject)
  • saveNewAssetUsage(queryObject)
  • deleteAssetUsage(queryObject)

Metaproperties

  • getMetaproperties(queryObject)
  • getMetaproperty(queryObject)
  • saveNewMetaproperty(object)
  • editMetaproperty(object)
  • deleteMetaproperty(object)
  • saveNewMetapropertyOption(object)
  • editMetapropertyOption(object)
  • deleteMetapropertyOption(object)

Collections

  • getCollections(queryObject)
  • getCollection(queryObject)
  • saveNewCollection(queryObject)
  • shareCollection(queryObject)
  • addMediaToCollection(queryObject)
  • deleteMediaFromCollection(queryObject)

Tags

  • getTags(queryObject)

Smartfilters

  • getSmartfilters(queryObject)

Brands

  • getBrands()

Upload

  • uploadFile(fileObject)

Contribute to the SDK

If you wish to contribute to this repository and further extend the API coverage in the SDK, here are the steps necessary to prepare your environment:

  1. Clone the repository
  2. In the root folder, run yarn install to install all of the dependencies.
  3. Create a secret.json file with the following structure:
{
  "baseURL": "http://api-url.bynder.io/api/",
  "clientId": "<your OAuth2 client id>",
  "clientSecret": "<your OAuth2 client secret>",
  "redirectUri": "<url where user will be redirected after authenticating>"
}
  1. The following gulp tasks are available:
  • gulp lint - Run ESlint and check the code.
  • gulp build - Run webpack to bundle the code in order to run in a browser.
  • gulp babel - Run Babel to create a folder 'dist' with ES2015 compatible code.
  • gulp doc - Run JSDoc to create a 'doc' folder with automatically generated documentation for the source code.
  • gulp webserver - Deploy a web server from the root folder at localhost:8080 to run the html samples (in order to avoid CORS problems).

bynder-js-sdk's People

Contributors

anttiviljami avatar aprilsnows avatar arpit-sharma-usc avatar bchengwfd avatar betacar avatar bynder-snyk avatar codynova avatar danielsequeira avatar dependabot[bot] avatar elseee avatar enbochen avatar guilhermescp avatar jordanrastrick avatar ozanmakes avatar rcuisnier avatar sarah-vanderlaan avatar sashaqred avatar snyk-bot avatar woutertoering avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bynder-js-sdk's Issues

Upgrade to axios 0.19.0

Hi - we've been using a resolution to force bynder-js-sdk to use [email protected] for a while (as we need it to enable tunnelling through our internal http proxy for https requests). Now that [email protected] has been released, would it be possible to bump the version officially in the SDK? Cheers.

Page scroll block breaks Bynder scroll

Hi there, question about the Bynder compact-view. Didn't know which repo to post this. I open the Bynder modal in a sidebar which blocks the scroll of the page itself on mount. Doing this also completely breaks the scroll in the Bynder modal giving lots of errors. So, blocking the scroll on the page breaks the scroll of Bynder.
Schermafbeelding 2022-12-20 om 10 04 05

Typescript support

Type definitions would be much appreciated for those of us working on Typescript. For now we have to laboriously define our own types, or opt to lose compiler typechecking help on offer.

Return Chunk Upload and Number of Chunk

I want to create a progress bar since I'll be uploading big files.
Is there a way to have access to the number of chunk created.
After that, is there a way to catch every response for each chunk to make my progress bar progress. I can't find a way at the moment. Thanks

Permanent tokens doesn't seem to work.

Hi, I'm trying to follow guide from readme but permanent token doesn't seem to work.

const Bynder = require('@bynder/bynder-js-sdk');

const bynder = new Bynder({
  baseURL: 'https://company.getbynder.com/api/',
  permanentToken: 'token',
});

bynder
  .getMediaList({
    type: 'image',
    limit: 9,
    page: 1,
  })
  .then(console.log, console.error);

bynder-js-sdk node upgrade

Hi, bynder-js-sdk is using an outdated version of many libraries, is it possible to bring bynder-js-sdk on the latest node?

This package has too many security issues because of the outdated libraries.

Issues with no direct upgrade or patch:
✗ Cross-site Request Forgery (CSRF) [High Severity][https://security.snyk.io/vuln/SNYK-JS-AXIOS-6032459] in [email protected]
introduced by @bynder/[email protected] > [email protected]
This issue was fixed in versions: 0.28.0, 1.6.0
✗ Regular Expression Denial of Service (ReDoS) [Medium Severity][https://security.snyk.io/vuln/SNYK-JS-AXIOS-6124857] in [email protected]
introduced by @bynder/[email protected] > [email protected]
This issue was fixed in versions: 1.6.3
✗ Prototype Pollution [High Severity][https://security.snyk.io/vuln/SNYK-JS-AXIOS-6144788] in [email protected]
introduced by @bynder/[email protected] > [email protected]
This issue was fixed in versions: 1.6.4

FYI... @elseee @erikvanbrakel

uploadFile seems to be too slow

Hello there,
i'm trying to upload some assets saved in a mongodb collection to bynder using the js-sdk.
For some reason each and every successful call takes 15 seconds to conclude which seems to be very strange. Is this expected?

I have the following code:

uploadFile({
            filename: `SMCR_UGC_${submission.fileId}`,
            length: submission.fileSizeInBytes,
            body: fileStream,
            data: {
              brandId: submission.brandId,
              name: `SMCR_UGC_${submission.fileId}`,
              description: submission.description,
              ...languageMetaProperty,
              ...destinationMetaProperty,
              ...fileTypeMetaProperty,
              ...subFileTypeMetaProperty,
            },
})```

API calls fail when payload contains values with ampersands in them

Whenever I try to send any payload with a value with the letter "&" in it, I always get a 401 error saying my oauth signature is incorrect.

Error: Request failed with status code 401                                                                                                          
    at createError (/Users/akuo/bynder-js-sdk/node_modules/axios/lib/core/createError.js:16:15)                                                                                                                          
    at settle (/Users/akuo/bynder-js-sdk/node_modules/axios/lib/core/settle.js:18:12)                                                                                                                                    
    at IncomingMessage.handleStreamEnd (/Users/akuo/bynder-js-sdk/node_modules/axios/lib/adapters/http.js:201:11)                                                                                                        
    at emitNone (events.js:91:20)                                                                                                                                                                                        
    at IncomingMessage.emit (events.js:185:7)                                                                                                                                                                            
    at endReadableNT (_stream_readable.js:974:12)                                                                                                                                                                        
    at _combinedTickCallback (internal/process/next_tick.js:80:11)                                                                                                                                                       
    at process._tickCallback (internal/process/next_tick.js:104:9)                                                                                                                                                       message=Invalid signature, 
signatureBaseString=..., statuscode=401                        

Upload stream

Is it possible to use a stream as parameter of uploadFile ?
Trying to stream files from AWS S3 (using AWS SDK) to a Bynder instance.

Missing OAuth Client Credentials

Hi,

I´ve tried the samples but was not able to login via OAuth. I didn´t provide a token in the secure.json file as it is optional but nevertheless the SDK isn´t retrieving a token from the backend.

I also cannot find any OAuth Client Credentials Support in the coding of the SDK.

Regards,
Andy

Stalling asset uploads

I'm uploading asset files using the SDKs uploadFile -function and some assets seem to be stalling in their upload. In my code I download a file from another provider as a stream using Axios and pass it to the bynder-js-sdk upload function. This way of uploading assets work for 95% of assets but some fail with an exception thrown from here.

Any idea what might be causing this?

Run tests and linter in CI

It would be great if the linter and tests would be automatically run in a CI service like Travis for master branch and when a PR is submitted.

OAuth2 permanent token not working

Hey,

I was using OAuth1 and was working fine, but it seems like this library has been updated to OAuth2-only support. If I try to use my permanent OAuth2 token in the new way:

const bynder = new Bynder({
    baseURL: 'https://MY_ORGANIZATION.getbynder.com/api/',
    clientId: 'MY_CLIENT_ID',
    clientSecret: 'MY_CLIENT_SECRET',
    token: {
      access_token:
        'MY_PERMANENT_ACCESS_TOKEN',
    },
  });

i receive an error message with code 401. Could you please provide guidance on how to authenticate with my permanent access token?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.