Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

1 change: 1 addition & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"lib/stack/release/items/index.js",
"lib/stack/label/index.js",
"lib/stack/locale/index.js",
"lib/stack/auditlog/index.js",
"lib/stack/environment/index.js",
"lib/stack/deliveryToken/index.js",
"lib/stack/roles/index.js",
Expand Down
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: 87a65198a53dfe59b81776d26882e419edaeb321003b2d03c06d396a8c673038
checksum: 71a070335979f3eed857a887e4bd36d9a1e14b08370c55117c55b45b77889b68
version: ""
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Install it via npm:
npm i @contentstack/management
```
To import the SDK, use the following command:
```
```javascript
import contentstack from ‘@contentstack/management’

contentstackClient = contentstack.client()
Expand All @@ -29,12 +29,12 @@ contentstackClient = contentstack.client()
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
### Authtoken
An [Authtoken](https://www.contentstack.com/docs/developers/create-tokens/types-of-tokens/#authentication-tokens-authtokens-) is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
```
```javascript
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
```
### Login
To Login to Contentstack by using credentials, you can use the following lines of code:
```
```javascript
contentstackClient.login({ email: 'EMAIL', password: 'PASSWORD'})
.then((response) => {
console.log(response.notice)
Expand All @@ -44,7 +44,7 @@ contentstackClient.login({ email: 'EMAIL', password: 'PASSWORD'})

### Management Token
[Management Tokens](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens/) are **stack-level** tokens, with no users attached to them.
```
```javascript
contentstackClient.stack({ api_key: 'API_KEY', management_token: 'MANAGEMENT_TOKEN' }).contentType('CONTENT_TYPE_UID')
.fetch()
.then((contenttype) => {
Expand All @@ -54,14 +54,14 @@ contentstackClient.stack({ api_key: 'API_KEY', management_token: 'MANAGEMENT_TOK
### Contentstack Management JavaScript SDK: 5-minute Quickstart
#### Initializing Your SDK:
To use the JavaScript CMA SDK, you need to first initialize it. To do this, use the following code:
```
```javascript
import contentstack from ‘@contentstack/management’

var contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
```
#### Fetch Stack Detail
Use the following lines of code to fetch your stack detail using this SDK:
```
```javascript
contentstackClient.stack({ api_key: 'API_KEY' })
.fetch()
.then((stack) => {
Expand All @@ -71,7 +71,7 @@ contentstackClient.stack({ api_key: 'API_KEY' })

#### Create Entry
To create an entry in a specific content type of a stack, use the following lines of code:
```
```javascript
var entry = {
title: 'Sample Entry',
url: '/sampleEntry'
Expand All @@ -85,7 +85,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).contentType('CONTENT_TYPE_UID')

#### Create Asset
The following lines of code can be used to upload assets to your stack:
```
```javascript
var asset = {
upload: 'path/to/file',
title: 'Asset Title'
Expand All @@ -104,7 +104,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset })
- [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)

### The MIT License (MIT)
Copyright © 2012-2022 [Contentstack](https://www.contentstack.com/). All Rights Reserved
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
26 changes: 19 additions & 7 deletions lib/core/concurrency-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ export function ConcurrencyQueue ({ axios, config }) {
}

if (this.paused && request.retryCount > 0) {
return new Promise(resolve => {
this.unshift({ request, resolve })
return new Promise((resolve, reject) => {
this.unshift({ request, resolve, reject })
})
} else if (request.retryCount > 0) {
return request
}

return new Promise(resolve => {
return new Promise((resolve, reject) => {
request.onComplete = () => {
this.running.pop({ request, resolve })
this.running.pop({ request, resolve, reject })
}
this.push({ request, resolve })
this.push({ request, resolve, reject })
})
}

Expand All @@ -131,6 +131,7 @@ export function ConcurrencyQueue ({ axios, config }) {
}, time))
}
}

const refreshToken = () => {
return config.refreshToken().then((token) => {
if (token.authorization) {
Expand All @@ -146,8 +147,19 @@ export function ConcurrencyQueue ({ axios, config }) {
axios.httpClientParams.headers.authtoken = token.authtoken
this.config.authtoken = token.authtoken
}
}).catch((error) => {
throw error
}).catch(() => {
this.queue.forEach(queueItem => {
queueItem.reject({
errorCode: '401',
errorMessage: 'Unable to refresh token',
code: 'Unauthorized',
message: 'Request failed with status code 401',
name: 'Token Error',
config: queueItem.request
})
})
this.queue = []
this.running = []
}).finally(() => {
this.queue.forEach((queueItem) => {
if (this.config.authorization) {
Expand Down
5 changes: 3 additions & 2 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ export const publishUnpublish = async (http, url, httpBody, headers, locale = nu
export const upload = async ({ http, urlPath, stackHeaders, formData, params, method = 'POST' }) => {
const headers = {
headers: {
...params,
...cloneDeep(stackHeaders)
},
params: {
...cloneDeep(params)
}
} || {}

if (method === 'POST') {
return http.post(urlPath, formData, headers)
} else {
Expand Down
7 changes: 4 additions & 3 deletions lib/stack/contentType/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,18 @@ export function ContentType (http, data = {}) {
* const data = {
* content_type: 'path/to/file.json',
* }
* client.stack({ api_key: 'api_key'}).contentType().import(data)
* client.stack({ api_key: 'api_key'}).contentType().import(data, { overwrite: true })
* .then((contentType) => console.log(contentType))
*
*/
this.import = async function (data) {
this.import = async function (data, params = {}) {
try {
const response = await upload({
http: http,
urlPath: `${this.urlPath}/import`,
stackHeaders: this.stackHeaders,
formData: createFormData(data)
formData: createFormData(data),
params: params
})
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders))
Expand Down
7 changes: 4 additions & 3 deletions lib/stack/globalField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,18 @@ export function GlobalField (http, data = {}) {
* const data = {
* global_field: 'path/to/file.json',
* }
* client.stack({ api_key: 'api_key'}).globalField().import(data)
* client.stack({ api_key: 'api_key'}).globalField().import(data, { overwrite: true })
* .then((globalField) => console.log(globalField))
*
*/
this.import = async function (data) {
this.import = async function (data, params = {}) {
try {
const response = await upload({
http: http,
urlPath: `${this.urlPath}/import`,
stackHeaders: this.stackHeaders,
formData: createFormData(data)
formData: createFormData(data),
params: params
})
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders))
Expand Down
5 changes: 2 additions & 3 deletions lib/stack/locale/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ export function Locale (http, data = {}) {
*
* client.stack({ api_key: 'api_key'}).locale('locale_code').fetch()
* .then((locale) => {
* locale.title = 'My New Content Type'
* locale.description = 'Content Type description'
* return locale.update()
* locale.fallback_locale = 'en-at'
* return locale.update()
* })
* .then((locale) => console.log(locale))
*
Expand Down
6 changes: 5 additions & 1 deletion lib/stack/workflow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ export function Workflow (http, data = {}) {
}

export function WorkflowCollection (http, data) {
const obj = cloneDeep(data.workflows) || []
let obj = cloneDeep(data.workflows) || []
if (!Array.isArray(obj)) {
obj = [obj]
}

return obj.map((userData) => {
return new Workflow(http, { workflow: userData, stackHeaders: data.stackHeaders })
})
Expand Down
Loading