-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnode.js
41 lines (36 loc) · 1.13 KB
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const {
ClientBuilder,
createAuthForClientCredentialsFlow,
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/platform-sdk')
const fetch = require('node-fetch')
const projectKey = process.env.CTP_PROJECT_KEY
const authMiddlewareOptions = {
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: process.env.CTP_CLIENT_ID || '',
clientSecret: process.env.CTP_CLIENT_SECRET || '',
},
oauthUri: process.env.adminAuthUrl || '',
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()
const apiRoot = createApiBuilderFromCtpClient(client)
function getProjectDetails() {
return apiRoot.withProjectKey({ projectKey }).get().execute()
}
module.exports = {
getProjectDetails,
}