2.0.8 • Published 3 years ago

ctvault v2.0.8

Weekly downloads
4
License
ISC
Repository
-
Last release
3 years ago

ctvault

Motivation

ctvault is a wrapper library around the commercetools JavaScript SDK that aims to reduce boilerplate code and provide consolidated credential management for multiple commercetools projects.

Configuration

There are multiple methods for configuring the type of data store that ctvault uses. Set the CT_VAULT_CONFIG environment variable to point to the location of the JSON configuration file.

commercetools project

This configuration will point ctvault at a commercetools project, specifying a namespace and key for a custom object to store the managed credentials.

keyvalue
type"ctp"
namespacethe custom object namespace
keythe custom object key
credentialsthe commercetools project credentials

Google Firebase

You can also use a Google Firebase store to serve as the credentials vault.

keyvalue
type"firebase"
credentialspath to a JSON file with GCP service account credentials (see https://cloud.google.com/iam/docs/service-accounts)
collectionname of the firebase collection that holds the managed credentials

Local file

Alternatively you can store them in a file on the local file system.

keyvalue
type"file"
credentialsan array of commercetools project credentials

commercetools Credentials

Here is the structure for the commercetools credentials objects. These are both to specify the project (if you are pointing at a commercetools project) and to specify the set of managed credentials.

keyvalue
oauth_urlURL to the commercetools auth server
api_urlURL to the commercetools API gateway
projectproject key
client_idAPI client ID
client_secretAPI client secret

Usage

ctvault acts as a simple broker. You can query it by using two methods:

getClient(projectKey)

This will return a CTP client configured to talk to the project specified in projectKey if the credentials exist in the vault. If they are not, an exception is thrown to that effect.

If projectKey is empty, ctvault will attempt to find it in the command line argument --project.

getClients

This will return an array of CTP clients for which the vault contains credentials.

Both of these methods are asynchronous, so be sure to use await.

Using a ctvault CTP client (ctclient)

ctclient uses a syntax based on api-request-builder (https://commercetools.github.io/nodejs/sdk/api/apiRequestBuilder.html), specifically the Declarative Usage section (https://commercetools.github.io/nodejs/sdk/api/apiRequestBuilder.html#declarative-usage).

Largely syntactic sugar, it provides an interface for you to use standard CRUD operations (create, get, update, remove), but also adds the following verbs:

process: This will use the processRequest method from api-request-builder to page through objects.

ensure: Given a source object, will try to find an object with the matching key. If it is not found, it will be created with the source object as the template. Use when building data models.

Examples

Query for a tax category with a key of standard:

const argv = require('yargs').argv
let ct = await require('ctvault').getClient(argv.project)

let standardTaxCategory = await ct.taxCategories.get({ key: 'standard' })

Make sure order type foo is defined:

const argv = require('yargs').argv
let ct = await require('ctvault').getClient(argv.project)

let fooOrderType = {
    key: 'FooOrderType',
    name: { 
        en: 'Foo'
    },
    resourceTypeIds: ['order'],
    description: { 
        en: 'Foo'
    },
    fieldDefinitions: [{
        name: 'bar',
        type: { name: 'String' },
        required: false,
        label: { 
            en: 'Bar'
        }
    }]
}

let foo = await ct.types.ensure(fooOrderType)
2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

1.0.39

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago