Skip to content

Commit

Permalink
chore(README.md): update package README.md (#156)
Browse files Browse the repository at this point in the history
- update all package README.md file to use sdk-client-v2
- include usage examples and documentations
- remove links related to old (nodejs) sdk-client
  • Loading branch information
ajimae authored Jan 4, 2022
1 parent 604567f commit 827c0ed
Show file tree
Hide file tree
Showing 6 changed files with 650 additions and 79 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

This repository contains several SDK packages generated from the commercetools platform API reference.

## Documentation

The full documentation and usage example for the TypeScript SDK can be found [here](https://commercetools.github.io/nodejs/sdk/api/typescriptSdk.html#typescript-sdk-client-v2)

## Support

If you have any urgent issues regarding this repository please create a support request over our [official support channel](http://support.commercetools.com).
Expand All @@ -27,13 +31,13 @@ If you have any urgent issues regarding this repository please create a support

### SDK

| Package | Version | |
| ------------------------------------------ | --------------------------------------------------------------------- | ---- |
| [`platform-sdk`](/packages/platform-sdk) | [![platform-sdk Version][platform-sdk-icon]][platform-sdk-version] | |
| [`importapi-sdk`](/packages/importapi-sdk) | [![importapi-sdk Version][importapi-sdk-icon]][importapi-sdk-version] | |
| [`ml-sdk`](/packages/ml-sdk) | [![ml-sdk Version][ml-sdk-icon]][ml-sdk-version] | |
| [`history-sdk`](/packages/history-sdk) | [![history-sdk Version][history-sdk-icon]][history-sdk-version] | |
| [`sdk-client`](/packages/sdk-client) | [![client-sdk Version][sdk-client-icon]][sdk-client-version] | Beta |
| Package | Version |
| ------------------------------------------ | --------------------------------------------------------------------- |
| [`platform-sdk`](/packages/platform-sdk) | [![platform-sdk Version][platform-sdk-icon]][platform-sdk-version] |
| [`importapi-sdk`](/packages/importapi-sdk) | [![importapi-sdk Version][importapi-sdk-icon]][importapi-sdk-version] |
| [`ml-sdk`](/packages/ml-sdk) | [![ml-sdk Version][ml-sdk-icon]][ml-sdk-version] |
| [`history-sdk`](/packages/history-sdk) | [![history-sdk Version][history-sdk-icon]][history-sdk-version] |
| [`sdk-client-v2`](/packages/sdk-client) | [![client-sdk Version][sdk-client-icon]][sdk-client-version] |

[platform-sdk-version]: https://www.npmjs.com/package/@commercetools/platform-sdk
[platform-sdk-icon]: https://img.shields.io/npm/v/@commercetools/platform-sdk.svg?style=flat-square
Expand Down
130 changes: 110 additions & 20 deletions packages/history-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,126 @@
# Typescript SDK for commercetools Audit log APIs.
# Typescript SDK for commercetools Audit log (history) APIs.

## Install
## Usage examples

```bash
npm install --save @commercetools/history-sdk
```
### Browser environment

### Browser
```html
<script src="https://unpkg.com/@commercetools/sdk-client-v2@latest/dist/commercetools-sdk-client-v2.umd.js"></script>
<script src="https://unpkg.com/@commercetools/history-sdk@latest/dist/commercetools-history-sdk.umd.js"></script>
```

```html
<script src="https://unpkg.com/browse/@commercetools/history-sdk/dist/history-sdk.umd.js"></script>
<script>
// global: historySdk
// global: @commercetools/sdk-client-v2
// global: @commercetools/history-sdk
;(function () {
// We can now access the sdk-client-v2 and history-sdk object as:
// const { ClientBuilder } = this['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = this['@commercetools/history-sdk']
// or
// const { ClientBuilder } = window['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = window['@commercetools/history-sdk']
})()
</script>
```

### Usage example
### Node environment

```bash
npm install --save @commercetools/sdk-client-v2
npm install --save @commercetools/history-sdk
```

```ts
import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import { createClient } from '@commercetools/sdk-client'
const {
ClientBuilder,
createAuthForClientCredentialsFlow,
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/history-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'mc-client-id',
clientSecret: 'mc-client-secrets',
},
oauthUri: 'https://auth.europe-west1.gcp.commercetools.com',
scopes: [`manage_project:${projectKey}`],
fetch,
}

const httpMiddlewareOptions = {
host: 'https://history.europe-west1.gcp.commercetools.com',
fetch,
}

const client = new ClientBuilder()
.withProjectKey(projectKey)
.withMiddleware(createAuthForClientCredentialsFlow(authMiddlewareOptions))
.withMiddleware(createHttpClient(httpMiddlewareOptions))
.withUserAgentMiddleware()
.build()

// or
const client = new ClientBuilder()
.withProjectKey(projectKey)
.withClientCredentialsFlow(authMiddlewareOptions)
.withHttpMiddleware(httpMiddlewareOptions)
.withUserAgentMiddleware()
.build()

const apiRoot = createApiBuilderFromCtpClient(client)

// calling the history-sdk functions
// get project details
apiRoot
.withProjectKey({ projectKey })
.recommendations()
.projectCategories()
.withProductId({
productId: product.id,
})
.get()
.execute()
.then((x) => {
/*...*/
})

apiRoot
.withProjectKey({ projectKey })
.imageSearch()
.post({
queryArgs: {
limit: 20,
},
body: image,
headers: {
'Content-Type': 'image/jpeg',
},
})
.execute()
.then((x) => {
/*...*/
})

// -----------------------------------------------------------------------
// The sdk-client-v2 also has support for the old syntax
import {
createApiBuilderFromCtpClient,
ApiRoot,
} from '@commercetools/history-sdk'
createClient,
createHttpClient,
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/history-sdk'
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
host: 'https://auth.europe-west1.gcp.commercetools.com/',
const authMiddleware = createAuthForClientCredentialsFlow({
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'some_id',
Expand All @@ -39,7 +129,7 @@ const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
fetch,
})

const httpMiddleware = createHttpMiddleware({
const httpMiddleware = createHttpClient({
host: 'https://history.europe-west1.gcp.commercetools.com',
fetch,
})
Expand All @@ -48,10 +138,10 @@ const ctpClient = createClient({
middlewares: [authMiddleware, httpMiddleware],
})

const apiRoot: ApiRoot = createApiBuilderFromCtpClient(ctpClient)
const apiRoot = createApiBuilderFromCtpClient(ctpClient)

apiRoot
.withProjectKeyValue({ projectKey })
.withProjectKey({ projectKey })
.recommendations()
.projectCategories()
.withProductId({
Expand Down
118 changes: 100 additions & 18 deletions packages/importapi-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,108 @@
# Typescript SDK for commercetools import API

## Install
## Usage examples

```bash
npm install --save @commercetools/importapi-sdk
```
### Browser environment

### Browser
```html
<script src="https://unpkg.com/@commercetools/sdk-client-v2@latest/dist/commercetools-sdk-client-v2.umd.js"></script>
<script src="https://unpkg.com/@commercetools/importapi-sdk@latest/dist/commercetools-importapi-sdk.umd.js"></script>
```

```html
<script src="https://unpkg.com/browse/@commercetools/importapi-sdk/dist/importapi-sdk.umd.js"></script>
<script>
// global: importApiSdk
// global: @commercetools/sdk-client-v2
// global: @commercetools/importapi-sdk
;(function () {
// We can now access the sdk-client-v2 and importapi-sdk object as:
// const { ClientBuilder } = this['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = this['@commercetools/importapi-sdk']
// or
// const { ClientBuilder } = window['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = window['@commercetools/importapi-sdk']
})()
</script>
```

### Usage example
### Node environment

```bash
npm install --save @commercetools/sdk-client-v2
npm install --save @commercetools/importapi-sdk
```

```ts
import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth'
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http'
import { createClient } from '@commercetools/sdk-client'
const {
ClientBuilder,
createAuthForClientCredentialsFlow,
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/importapi-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'mc-client-id',
clientSecret: 'mc-client-secrets',
},
oauthUri: 'https://auth.europe-west1.gcp.commercetools.com',
scopes: [`manage_project:${projectKey}`],
fetch,
}

const httpMiddlewareOptions = {
host: 'https://api.europe-west1.gcp.commercetools.com',
fetch,
}

const client = new ClientBuilder()
.withProjectKey(projectKey)
.withMiddleware(createAuthForClientCredentialsFlow(authMiddlewareOptions))
.withMiddleware(createHttpClient(httpMiddlewareOptions))
.withUserAgentMiddleware()
.build()

// or
const client = new ClientBuilder()
.withProjectKey(projectKey)
.withClientCredentialsFlow(authMiddlewareOptions)
.withHttpMiddleware(httpMiddlewareOptions)
.withUserAgentMiddleware()
.build()


const apiRoot = createApiBuilderFromCtpClient(client)

// calling the importapi functions
// get project details
apiRoot
.withProjectKey({
projectKey,
})
.get()
.execute()
.then((x) => {
/*...*/
})


// -----------------------------------------------------------------------
// The sdk-client-v2 also has support for the old syntax
import {
createApiBuilderFromCtpClient,
ApiRoot,
} from '@commercetools/importapi-sdk'
createClient,
createHttpClient,
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/importapi-sdk')
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
host: 'https://auth.europe-west1.gcp.commercetools.com/',
const authMiddleware = createAuthForClientCredentialsFlow({
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'some_id',
Expand All @@ -39,7 +111,7 @@ const authMiddleware = createAuthMiddlewareForClientCredentialsFlow({
fetch,
})

const httpMiddleware = createHttpMiddleware({
const httpMiddleware = createHttpClient({
host: 'https://import.europe-west1.gcp.commercetools.com',
fetch,
})
Expand All @@ -48,5 +120,15 @@ const ctpClient = createClient({
middlewares: [authMiddleware, httpMiddleware],
})

const apiRoot: ApiRoot = createApiBuilderFromCtpClient(ctpClient)
const apiRoot = createApiBuilderFromCtpClient(ctpClient)

apiRoot
.withProjectKey({
projectKey,
})
.get()
.execute()
.then((x) => {
/*...*/
})
```
Loading

0 comments on commit 827c0ed

Please sign in to comment.