@commercetools/sdk-client-v2 0.1.2 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +196 -1
- package/dist/commercetools-sdk-client-v2.browser.cjs.js +789 -1155
- package/dist/commercetools-sdk-client-v2.browser.esm.js +789 -1155
- package/dist/commercetools-sdk-client-v2.cjs.dev.js +789 -1155
- package/dist/commercetools-sdk-client-v2.cjs.prod.js +789 -1155
- package/dist/commercetools-sdk-client-v2.esm.js +789 -1155
- package/dist/commercetools-sdk-client-v2.umd.js +1 -1
- package/dist/declarations/src/client-builder/ClientBuilder.d.ts +26 -26
- package/dist/declarations/src/http-user-agent/create-user-agent.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +14 -14
- package/dist/declarations/src/sdk-client/allowed-methods.d.ts +2 -2
- package/dist/declarations/src/sdk-client/client.d.ts +2 -2
- package/dist/declarations/src/sdk-client/errors.d.ts +10 -10
- package/dist/declarations/src/sdk-client/validate.d.ts +7 -7
- package/dist/declarations/src/sdk-middleware-auth/anonymous-session-flow.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/base-auth-flow.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/build-requests.d.ts +11 -11
- package/dist/declarations/src/sdk-middleware-auth/build-token-cache-key.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/client-credentials-flow.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/existing-token.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/index.d.ts +5 -5
- package/dist/declarations/src/sdk-middleware-auth/password-flow.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/refresh-token-flow.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-auth/utils.d.ts +4 -4
- package/dist/declarations/src/sdk-middleware-correlation-id/correlation-id.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-http/http.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-http/parse-headers.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-logger/logger.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-queue/queue.d.ts +2 -2
- package/dist/declarations/src/sdk-middleware-user-agent/user-agent.d.ts +2 -2
- package/package.json +5 -4
- package/dist/declarations/package.d.ts +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @commercetools/sdk-client-v2
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#167](https://github.com/commercetools/commercetools-sdk-typescript/pull/167) [`b31612d`](https://github.com/commercetools/commercetools-sdk-typescript/commit/b31612dbcc3d644847cb42cf67bce407ab202cb0) Thanks [@ajimae](https://github.com/ajimae)! - Add Buffer Dependency
|
|
8
|
+
|
|
9
|
+
## 1.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#163](https://github.com/commercetools/commercetools-sdk-typescript/pull/163) [`fcd35a0`](https://github.com/commercetools/commercetools-sdk-typescript/commit/fcd35a0f26b2780d0004c4e9d7b48233a86c2453) Thanks [@ajimae](https://github.com/ajimae)! - Fix issues with Buffer and node process
|
|
14
|
+
|
|
15
|
+
## 1.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- [#154](https://github.com/commercetools/commercetools-sdk-typescript/pull/154) [`25f1dea`](https://github.com/commercetools/commercetools-sdk-typescript/commit/25f1dea23eccdfdda01e9144ec2afe968ead58f2) Thanks [@jherey](https://github.com/jherey)! - This is the first major release of the sdk client
|
|
20
|
+
|
|
21
|
+
## 0.2.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [#146](https://github.com/commercetools/commercetools-sdk-typescript/pull/146) [`1f6f830`](https://github.com/commercetools/commercetools-sdk-typescript/commit/1f6f830bb25d98c15ac96e06635c5e2aa07fe1e8) Thanks [@ajimae](https://github.com/ajimae)! - release a new version of typescript
|
|
26
|
+
|
|
3
27
|
## 0.1.2
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1 +1,196 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Commercetools TypeScript SDK client.
|
|
2
|
+
|
|
3
|
+
## Usage examples
|
|
4
|
+
|
|
5
|
+
### Browser environment
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script src="https://unpkg.com/@commercetools/sdk-client-v2@latest/dist/commercetools-sdk-client-v2.umd.js"></script>
|
|
9
|
+
<script src="https://unpkg.com/@commercetools/platform-sdk@latest/dist/commercetools-platform-sdk.umd.js"></script>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<script>
|
|
14
|
+
// global: @commercetools/sdk-client-v2
|
|
15
|
+
// global: @commercetools/platform-sdk
|
|
16
|
+
;(function () {
|
|
17
|
+
// We can now access the sdk-client-v2 and platform-sdk object as:
|
|
18
|
+
// const { ClientBuilder } = this['@commercetools/sdk-client-v2']
|
|
19
|
+
// const { createApiBuilderFromCtpClient } = this['@commercetools/platform-sdk']
|
|
20
|
+
// or
|
|
21
|
+
// const { ClientBuilder } = window['@commercetools/sdk-client-v2']
|
|
22
|
+
// const { createApiBuilderFromCtpClient } = window['@commercetools/platform-sdk']
|
|
23
|
+
})()
|
|
24
|
+
</script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
See full usage example [here](https://github.com/commercetools/commercetools-sdk-typescript/blob/master/examples/browser/browser.html)
|
|
28
|
+
|
|
29
|
+
### Node environment
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install --save @commercetools/sdk-client-v2
|
|
33
|
+
npm install --save @commercetools/platform-sdk
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const {
|
|
38
|
+
ClientBuilder,
|
|
39
|
+
createAuthForClientCredentialsFlow,
|
|
40
|
+
createHttpClient,
|
|
41
|
+
} = require('@commercetools/sdk-client-v2')
|
|
42
|
+
const { createApiBuilderFromCtpClient } = require('@commercetools/platform-sdk')
|
|
43
|
+
const fetch = require('node-fetch')
|
|
44
|
+
|
|
45
|
+
const projectKey = 'mc-project-key'
|
|
46
|
+
const authMiddlewareOptions = {
|
|
47
|
+
host: 'https://auth.europe-west1.gcp.commercetools.com',
|
|
48
|
+
projectKey,
|
|
49
|
+
credentials: {
|
|
50
|
+
clientId: 'mc-client-id',
|
|
51
|
+
clientSecret: 'mc-client-secrets',
|
|
52
|
+
},
|
|
53
|
+
oauthUri: 'https://auth.europe-west1.gcp.commercetools.com',
|
|
54
|
+
scopes: [`manage_project:${projectKey}`],
|
|
55
|
+
fetch,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const httpMiddlewareOptions = {
|
|
59
|
+
host: 'https://api.europe-west1.gcp.commercetools.com',
|
|
60
|
+
fetch,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const client = new ClientBuilder()
|
|
64
|
+
.withProjectKey(projectKey)
|
|
65
|
+
.withMiddleware(createAuthForClientCredentialsFlow(authMiddlewareOptions))
|
|
66
|
+
.withMiddleware(createHttpClient(httpMiddlewareOptions))
|
|
67
|
+
.withUserAgentMiddleware()
|
|
68
|
+
.build()
|
|
69
|
+
|
|
70
|
+
// or
|
|
71
|
+
const client = new ClientBuilder()
|
|
72
|
+
.withProjectKey(projectKey)
|
|
73
|
+
.withClientCredentialsFlow(authMiddlewareOptions)
|
|
74
|
+
.withHttpMiddleware(httpMiddlewareOptions)
|
|
75
|
+
.withUserAgentMiddleware()
|
|
76
|
+
.build()
|
|
77
|
+
|
|
78
|
+
const apiRoot = createApiBuilderFromCtpClient(client)
|
|
79
|
+
|
|
80
|
+
// calling the platform functions
|
|
81
|
+
// get project details
|
|
82
|
+
apiRoot
|
|
83
|
+
.withProjectKey({
|
|
84
|
+
projectKey,
|
|
85
|
+
})
|
|
86
|
+
.get()
|
|
87
|
+
.execute()
|
|
88
|
+
.then((x) => {
|
|
89
|
+
/*...*/
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// create a productType
|
|
93
|
+
apiRoot
|
|
94
|
+
.withProjectKey({ projectKey })
|
|
95
|
+
.productTypes()
|
|
96
|
+
.post({
|
|
97
|
+
body: { name: 'product-type-name', description: 'some description' },
|
|
98
|
+
})
|
|
99
|
+
.execute()
|
|
100
|
+
.then((x) => {
|
|
101
|
+
/*...*/
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// create a product
|
|
105
|
+
apiRoot
|
|
106
|
+
.withProjectKey({ projectKey })
|
|
107
|
+
.products()
|
|
108
|
+
.post({
|
|
109
|
+
body: {
|
|
110
|
+
name: { en: 'our-great-product-name' },
|
|
111
|
+
productType: {
|
|
112
|
+
typeId: 'product-type',
|
|
113
|
+
id: 'some-product-type-id',
|
|
114
|
+
},
|
|
115
|
+
slug: { en: 'some-slug' },
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
.execute()
|
|
119
|
+
.then((x) => {
|
|
120
|
+
/*...*/
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// -----------------------------------------------------------------------
|
|
124
|
+
// The sdk-client-v2 also has support for the old syntax
|
|
125
|
+
import {
|
|
126
|
+
createClient,
|
|
127
|
+
createHttpClient,
|
|
128
|
+
createAuthForClientCredentialsFlow,
|
|
129
|
+
} from '@commercetools/sdk-client-v2'
|
|
130
|
+
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
|
|
131
|
+
import fetch from 'node-fetch'
|
|
132
|
+
|
|
133
|
+
const projectKey = 'some_project_key'
|
|
134
|
+
|
|
135
|
+
const authMiddleware = createAuthForClientCredentialsFlow({
|
|
136
|
+
host: 'https://auth.europe-west1.gcp.commercetools.com',
|
|
137
|
+
projectKey,
|
|
138
|
+
credentials: {
|
|
139
|
+
clientId: 'some_id',
|
|
140
|
+
clientSecret: 'some_secret',
|
|
141
|
+
},
|
|
142
|
+
fetch,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const httpMiddleware = createHttpClient({
|
|
146
|
+
host: 'https://api.europe-west1.gcp.commercetools.com',
|
|
147
|
+
fetch,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const ctpClient = createClient({
|
|
151
|
+
middlewares: [authMiddleware, httpMiddleware],
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const apiRoot = createApiBuilderFromCtpClient(ctpClient)
|
|
155
|
+
|
|
156
|
+
apiRoot
|
|
157
|
+
.withProjectKey({
|
|
158
|
+
projectKey,
|
|
159
|
+
})
|
|
160
|
+
.get()
|
|
161
|
+
.execute()
|
|
162
|
+
.then((x) => {
|
|
163
|
+
/*...*/
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
apiRoot
|
|
167
|
+
.withProjectKey({ projectKey })
|
|
168
|
+
.productTypes()
|
|
169
|
+
.post({
|
|
170
|
+
body: { name: 'product-type-name', description: 'some description' },
|
|
171
|
+
})
|
|
172
|
+
.execute()
|
|
173
|
+
.then((x) => {
|
|
174
|
+
/*...*/
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
apiRoot
|
|
178
|
+
.withProjectKey({ projectKey })
|
|
179
|
+
.products()
|
|
180
|
+
.post({
|
|
181
|
+
body: {
|
|
182
|
+
name: { en: 'our-great-product-name' },
|
|
183
|
+
productType: {
|
|
184
|
+
typeId: 'product-type',
|
|
185
|
+
id: 'some-product-type-id',
|
|
186
|
+
},
|
|
187
|
+
slug: { en: 'some-slug' },
|
|
188
|
+
},
|
|
189
|
+
})
|
|
190
|
+
.execute()
|
|
191
|
+
.then((x) => {
|
|
192
|
+
/*...*/
|
|
193
|
+
})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
See full usage example [here](https://github.com/commercetools/commercetools-sdk-typescript/blob/master/examples/node/node.js)
|