@contentstack/marketplace-sdk 1.0.0
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/CODEOWNERS +1 -0
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/SECURITY.md +27 -0
- package/dist/es-modules/contentstack.js +184 -0
- package/dist/es-modules/contentstackClient.js +116 -0
- package/dist/es-modules/contentstackCollection.js +30 -0
- package/dist/es-modules/core/Util.js +89 -0
- package/dist/es-modules/core/concurrency-queue.js +297 -0
- package/dist/es-modules/core/contentstackError.js +36 -0
- package/dist/es-modules/core/contentstackHTTPClient.js +87 -0
- package/dist/es-modules/entity.js +433 -0
- package/dist/es-modules/marketplace/app/hosting/deployment.js +307 -0
- package/dist/es-modules/marketplace/app/hosting/index.js +284 -0
- package/dist/es-modules/marketplace/app/index.js +456 -0
- package/dist/es-modules/marketplace/app/oauth/index.js +190 -0
- package/dist/es-modules/marketplace/apprequest/index.js +188 -0
- package/dist/es-modules/marketplace/authorization/index.js +175 -0
- package/dist/es-modules/marketplace/index.js +177 -0
- package/dist/es-modules/marketplace/installation/index.js +581 -0
- package/dist/es-modules/marketplace/installation/webhooks/index.js +185 -0
- package/dist/es5/contentstack.js +196 -0
- package/dist/es5/contentstackClient.js +126 -0
- package/dist/es5/contentstackCollection.js +41 -0
- package/dist/es5/core/Util.js +98 -0
- package/dist/es5/core/concurrency-queue.js +307 -0
- package/dist/es5/core/contentstackError.js +43 -0
- package/dist/es5/core/contentstackHTTPClient.js +101 -0
- package/dist/es5/entity.js +449 -0
- package/dist/es5/marketplace/app/hosting/deployment.js +321 -0
- package/dist/es5/marketplace/app/hosting/index.js +296 -0
- package/dist/es5/marketplace/app/index.js +469 -0
- package/dist/es5/marketplace/app/oauth/index.js +202 -0
- package/dist/es5/marketplace/apprequest/index.js +200 -0
- package/dist/es5/marketplace/authorization/index.js +187 -0
- package/dist/es5/marketplace/index.js +190 -0
- package/dist/es5/marketplace/installation/index.js +594 -0
- package/dist/es5/marketplace/installation/webhooks/index.js +197 -0
- package/dist/nativescript/contentstack-marketplace.js +2 -0
- package/dist/node/contentstack-marketplace.js +2 -0
- package/dist/react-native/contentstack-marketplace.js +2 -0
- package/dist/web/contentstack-marketplace.js +2 -0
- package/jest.config.js +11 -0
- package/package.json +95 -0
- package/types/contentstackClient.d.ts +56 -0
- package/types/contentstackCollection.d.ts +18 -0
- package/types/marketplace/app/hosting.d.ts +39 -0
- package/types/marketplace/app/index.d.ts +89 -0
- package/types/marketplace/app/oath.d.ts +8 -0
- package/types/marketplace/apprequest.d.ts +7 -0
- package/types/marketplace/authorization.d.ts +7 -0
- package/types/marketplace/index.d.ts +17 -0
- package/types/marketplace/installation.d.ts +22 -0
- package/types/marketplace/webhooks.d.ts +7 -0
- package/types/utility/fields.d.ts +9 -0
- package/types/utility/operations.d.ts +11 -0
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @contentstack/security-admin
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012-2023 Contentstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
[](https://www.contentstack.com/)
|
|
2
|
+
|
|
3
|
+
## Contentstack Marketplace SDK
|
|
4
|
+
|
|
5
|
+
Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
|
|
6
|
+
|
|
7
|
+
The new Contentstack Marketplace serves as a one-stop shop for all of your integration requirements. It's where you'll find pre-built apps, starters, tutorials, and everything you'll need to create a fully customized digital experience stack. This SDK helps in managing marketplace related operations.
|
|
8
|
+
### Prerequisite
|
|
9
|
+
|
|
10
|
+
You need Node.js version 10 or above installed on your machine to use the Contentstack Marketplace SDK.
|
|
11
|
+
|
|
12
|
+
### Installation
|
|
13
|
+
#### Node
|
|
14
|
+
Install it via npm:
|
|
15
|
+
```bash
|
|
16
|
+
npm i @contentstack/marketplace-sdk
|
|
17
|
+
```
|
|
18
|
+
To import the SDK, use the following command:
|
|
19
|
+
```
|
|
20
|
+
import contentstack from ‘@contentstack/marketplace-sdk’
|
|
21
|
+
|
|
22
|
+
contentstackClient = contentstack.client()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Authentication
|
|
26
|
+
To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
|
|
27
|
+
### Authtoken
|
|
28
|
+
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.
|
|
29
|
+
```
|
|
30
|
+
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
|
|
31
|
+
```
|
|
32
|
+
### Login
|
|
33
|
+
To Login to Contentstack by using credentials, you can use the following lines of code:
|
|
34
|
+
```
|
|
35
|
+
contentstackClient.login({ email: 'EMAIL', password: 'PASSWORD'})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### OAuth Token
|
|
39
|
+
[Contentstack OAuth](https://www.contentstack.com/docs/developers/developer-hub/contentstack-oauth) uses the OAuth 2.0 protocol that allows external applications and services to access Contentstack APIs on behalf of a user.
|
|
40
|
+
```
|
|
41
|
+
contentstackClient = contentstack.client({ authorization: 'OAUTH_TOKEN' })
|
|
42
|
+
```
|
|
43
|
+
### Contentstack Marketplace SDK: 5-minute Quickstart
|
|
44
|
+
#### Initializing Your SDK:
|
|
45
|
+
To use the Marketplace SDK, you need to first initialize it. To do this, use the following code:
|
|
46
|
+
```
|
|
47
|
+
import contentstack from ‘@contentstack/marketplace-sdk’
|
|
48
|
+
|
|
49
|
+
const contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
|
|
50
|
+
```
|
|
51
|
+
#### Find All Marketplace Apps
|
|
52
|
+
To retrieve the details of all the apps in your Contentstack organization, execute the following code:
|
|
53
|
+
```
|
|
54
|
+
import * as contentstack from '@contentstack/marketplace-sdk'
|
|
55
|
+
|
|
56
|
+
const client = contentstack.client({ authtoken: 'TOKEN'})
|
|
57
|
+
|
|
58
|
+
client.marketplace('organization_uid')
|
|
59
|
+
.findAllApps()
|
|
60
|
+
.then((collection) => {
|
|
61
|
+
console.log(collection)
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
#### Fetch single app details
|
|
65
|
+
To retrieve the details of a particular app, execute the following code:
|
|
66
|
+
```
|
|
67
|
+
import * as contentstack from '@contentstack/marketplace-sdk'
|
|
68
|
+
const client = contentstack.client({ authtoken: 'TOKEN'})
|
|
69
|
+
|
|
70
|
+
client.marketplace('organization_uid')
|
|
71
|
+
.app('manifest_uid')
|
|
72
|
+
.fetch()
|
|
73
|
+
.then((app) => console.log(app))
|
|
74
|
+
```
|
|
75
|
+
#### Create a new app
|
|
76
|
+
To create a new app/manifest in your Contentstack organization, execute the following code:
|
|
77
|
+
```
|
|
78
|
+
import * as contentstack from '@contentstack/marketplace-sdk'
|
|
79
|
+
const client = contentstack.client({ authtoken: 'TOKEN'})
|
|
80
|
+
const app = {
|
|
81
|
+
name: 'APP_NAME',
|
|
82
|
+
description: 'APP_DESCRIPTION',
|
|
83
|
+
target_type: 'stack'/'organization',
|
|
84
|
+
webhook: // optional
|
|
85
|
+
{
|
|
86
|
+
target_url: 'TARGET_URL',
|
|
87
|
+
channel: 'CHANNEL'
|
|
88
|
+
},
|
|
89
|
+
oauth: // optional
|
|
90
|
+
{
|
|
91
|
+
redirect_uri: 'REDIRECT_URI',
|
|
92
|
+
enabled: true,
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
client.marketplace('organization_uid')
|
|
97
|
+
.app()
|
|
98
|
+
.create(app)
|
|
99
|
+
.then((app) => console.log(app))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Helpful Links
|
|
103
|
+
|
|
104
|
+
- [Contentstack Website](https://www.contentstack.com/)
|
|
105
|
+
- [Official Documentation](https://contentstack.com/docs)
|
|
106
|
+
- [About Contentstack Marketplace](https://www.contentstack.com/docs/developers/marketplace-platform-guides/about-marketplace)
|
|
107
|
+
|
|
108
|
+
### The MIT License (MIT)
|
|
109
|
+
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
|
|
110
|
+
|
|
111
|
+
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:
|
|
112
|
+
|
|
113
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
114
|
+
|
|
115
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
## Security
|
|
2
|
+
|
|
3
|
+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
|
|
4
|
+
|
|
5
|
+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
|
|
6
|
+
|
|
7
|
+
## Reporting Security Issues
|
|
8
|
+
|
|
9
|
+
**Please do not report security vulnerabilities through public GitHub issues.**
|
|
10
|
+
|
|
11
|
+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
|
|
12
|
+
|
|
13
|
+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
|
|
14
|
+
|
|
15
|
+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
|
16
|
+
|
|
17
|
+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
|
18
|
+
* Full paths of source file(s) related to the manifestation of the issue
|
|
19
|
+
* The location of the affected source code (tag/branch/commit or direct URL)
|
|
20
|
+
* Any special configuration required to reproduce the issue
|
|
21
|
+
* Step-by-step instructions to reproduce the issue
|
|
22
|
+
* Proof-of-concept or exploit code (if possible)
|
|
23
|
+
* Impact of the issue, including how an attacker might exploit the issue
|
|
24
|
+
|
|
25
|
+
This information will help us triage your report more quickly.
|
|
26
|
+
|
|
27
|
+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
/**
|
|
5
|
+
* The Content Management API (CMA) is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account.
|
|
6
|
+
* @namespace Contentstack
|
|
7
|
+
*/
|
|
8
|
+
import packages from '../package.json';
|
|
9
|
+
import clonedeep from 'lodash/cloneDeep';
|
|
10
|
+
import getUserAgent from './core/Util.js';
|
|
11
|
+
import contentstackClient from './contentstackClient.js';
|
|
12
|
+
import httpClient from './core/contentstackHTTPClient.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create client instance
|
|
16
|
+
* @name client
|
|
17
|
+
* @memberof Contentstack
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import * as contentstack from '@contentstack/management'
|
|
21
|
+
* const client = contentstack.client()
|
|
22
|
+
*
|
|
23
|
+
* @param {object} params - Client initialization parameters
|
|
24
|
+
* @param {Object=} param.proxy -
|
|
25
|
+
* @prop {string=} params.endpoint - API endpoint that a service will talk to
|
|
26
|
+
* @example //Set the `endpoint` to 'https://api.contentstack.io:{port}/{version}'
|
|
27
|
+
* import * as contentstack from '@contentstack/management'
|
|
28
|
+
* const client = contentstack.client({ endpoint: 'https://api.contentstack.io:{port}/{version}' })
|
|
29
|
+
*
|
|
30
|
+
* @prop {string=} params.host - API host (default: api.contentstack.io)
|
|
31
|
+
* @example //Set the `host` to 'api.contentstack.io'
|
|
32
|
+
* import * as contentstack from '@contentstack/management'
|
|
33
|
+
* const client = contentstack.client({ host: 'api.contentstack.io' })
|
|
34
|
+
*
|
|
35
|
+
* @prop {object=} params.headers - Optional additional headers
|
|
36
|
+
* @example //Set the `headers` to { 'headerkey': 'value'}
|
|
37
|
+
* import * as contentstack from '@contentstack/management'
|
|
38
|
+
* const client = contentstack.client({ headers: { 'headerkey': 'value'} })
|
|
39
|
+
*
|
|
40
|
+
* @prop {string=} params.authtoken - Optional Authtoken is a read-write token used to make authorized CMA requests, but it is a user-specific token.
|
|
41
|
+
* @example //Set the `authtoken`
|
|
42
|
+
* import * as contentstack from '@contentstack/management'
|
|
43
|
+
* const client = contentstack.client({ authtoken: 'value' })
|
|
44
|
+
*
|
|
45
|
+
* @prop {string=} params.authorization - Optional authorization token is a read-write token used to make authorized CMA requests, but it is a user-specific token.
|
|
46
|
+
* @example //Set the `authorization`
|
|
47
|
+
* import * as contentstack from '@contentstack/management'
|
|
48
|
+
* const client = contentstack.client({ authorization: 'Bearer <token_value>' })
|
|
49
|
+
*
|
|
50
|
+
* @prop {number=} params.timeout - Optional number of milliseconds before the request times out. Default is 30000ms
|
|
51
|
+
* @example //Set the `timeout` to 50000ms
|
|
52
|
+
* import * as contentstack from '@contentstack/management'
|
|
53
|
+
* const client = contentstack.client({ timeout: 50000 })
|
|
54
|
+
*
|
|
55
|
+
* @prop {number=} params.maxRequests - Optional maximum number of requests SDK should send concurrently. Default is 5 concurrent request.
|
|
56
|
+
* @example //Set the `maxRequests` to 5
|
|
57
|
+
* import * as contentstack from '@contentstack/management'
|
|
58
|
+
* const client = contentstack.client({ maxRequests: 5 })
|
|
59
|
+
*
|
|
60
|
+
* @prop {boolean=} params.retryOnError - Optional boolean for retry on failure. Default is true
|
|
61
|
+
* @example //Set the `retryOnError` to false
|
|
62
|
+
* import * as contentstack from '@contentstack/management'
|
|
63
|
+
* const client = contentstack.client({ retryOnError: false })
|
|
64
|
+
*
|
|
65
|
+
* @prop {number=} params.retryLimit - Optional number of retries before failure. Default is 5
|
|
66
|
+
* @example //Set the `retryLimit` to 2
|
|
67
|
+
* import * as contentstack from '@contentstack/management'
|
|
68
|
+
* const client = contentstack.client({ retryLimit: 2 })
|
|
69
|
+
*
|
|
70
|
+
* @prop {number=} params.retryDelay - The number of milliseconds to use for operation retries. Default is 300ms
|
|
71
|
+
* @example //Set the `retryDelay` to 500ms
|
|
72
|
+
* import * as contentstack from '@contentstack/management'
|
|
73
|
+
* const client = contentstack.client({ retryDelay: 500 })
|
|
74
|
+
*
|
|
75
|
+
* @prop {Function=} params.retryCondition - A function to determine if the error can be retried. Default retry is on status 429.
|
|
76
|
+
* @example //Set the `retryCondition` on error status 429
|
|
77
|
+
* import * as contentstack from '@contentstack/management'
|
|
78
|
+
* const client = contentstack.client({ retryCondition: (error) => {
|
|
79
|
+
* if (error.response && error.response.status === 429) {
|
|
80
|
+
* return true
|
|
81
|
+
* }
|
|
82
|
+
* return false
|
|
83
|
+
* }
|
|
84
|
+
* })
|
|
85
|
+
*
|
|
86
|
+
* @prop {number=} params.retryDelayOptions.base - The base number of milliseconds to use in the exponential backoff for operation retries.
|
|
87
|
+
* @example Set base retry delay for all services to 300 ms
|
|
88
|
+
* import * as contentstack from '@contentstack/management'
|
|
89
|
+
* const client = contentstack.client({retryDelayOptions: {base: 300}})
|
|
90
|
+
*
|
|
91
|
+
* @prop {Function=} params.retryDelayOptions.customBackoff - A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds. (if you want not to retry for specific condition return -1)
|
|
92
|
+
* @example Set a custom backoff function to provide delay of 500 ms on retryCount < 3 and -1 for retryCount >= 3values on retries
|
|
93
|
+
* import * as contentstack from '@contentstack/management'
|
|
94
|
+
* const client = contentstack.client({retryDelayOptions: {customBackoff: function(retryCount, err) {
|
|
95
|
+
* if (retryCount < 3) {
|
|
96
|
+
* return 500
|
|
97
|
+
* } else {
|
|
98
|
+
* return -1 //returning -1 will hold next retry for request
|
|
99
|
+
* }
|
|
100
|
+
* }}}
|
|
101
|
+
* )
|
|
102
|
+
*
|
|
103
|
+
* @prop {number=} params.maxContentLength - Optional maximum content length in bytes (default: 1073741824 i.e. 1 GB)
|
|
104
|
+
* @example //Set the `maxContentLength` to 1024 ** 3
|
|
105
|
+
* import * as contentstack from '@contentstack/management'
|
|
106
|
+
* const client = contentstack.client({ maxContentLength: 1024 ** 3 })
|
|
107
|
+
*
|
|
108
|
+
* @prop {number=} params.maxBodyLength - Optional maximum body length in bytes (default: 10 MB)
|
|
109
|
+
* @example //Set the `maxBodyLength` to 1024 ** 2 * 10 // 10 MB
|
|
110
|
+
* import * as contentstack from '@contentstack/management'
|
|
111
|
+
* const client = contentstack.client({ maxBodyLength: 1024 ** 2 * 10 })
|
|
112
|
+
*
|
|
113
|
+
* @prop {function=} params.logHandler - A log handler function to process given log messages & errors.
|
|
114
|
+
* @example //Set the `logHandler`
|
|
115
|
+
* import * as contentstack from '@contentstack/management'
|
|
116
|
+
* const client = contentstack.client({ logHandler: (level, data) => {
|
|
117
|
+
if (level === 'error' && data) {
|
|
118
|
+
const title = [data.name, data.message].filter((a) => a).join(' - ')
|
|
119
|
+
console.error(`[error] ${title}`)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
console.log(`[${level}] ${data}`)
|
|
123
|
+
} })
|
|
124
|
+
*
|
|
125
|
+
* @prop {function=} params.refreshToken - Optional function used to refresh token.
|
|
126
|
+
* @example // OAuth example
|
|
127
|
+
* import * as contentstack from '@contentstack/management'
|
|
128
|
+
* const client = contentstack.client({
|
|
129
|
+
refreshToken: () => {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
return issueToken().then((res) => {
|
|
132
|
+
resolve({
|
|
133
|
+
authorization: res.authorization
|
|
134
|
+
})
|
|
135
|
+
}).catch((error) => {
|
|
136
|
+
reject(error)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
* @example // Auth Token example
|
|
142
|
+
* import * as contentstack from '@contentstack/management'
|
|
143
|
+
* const client = contentstack.client({
|
|
144
|
+
refreshToken: () => {
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
return issueToken().then((res) => {
|
|
147
|
+
resolve({
|
|
148
|
+
authtoken: res.authtoken
|
|
149
|
+
})
|
|
150
|
+
}).catch((error) => {
|
|
151
|
+
reject(error)
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
*
|
|
157
|
+
* @prop {string=} params.application - Application name and version e.g myApp/version
|
|
158
|
+
* @prop {string=} params.integration - Integration name and version e.g react/version
|
|
159
|
+
* @returns Contentstack.Client
|
|
160
|
+
*/
|
|
161
|
+
export function client() {
|
|
162
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
163
|
+
var defaultParameter = {
|
|
164
|
+
defaultHostName: 'developerhub-api.contentstack.com'
|
|
165
|
+
};
|
|
166
|
+
var sdkAgent = "contentstack-marketplace-sdk/".concat(packages.version);
|
|
167
|
+
var userAgentHeader = getUserAgent(sdkAgent, params.application, params.integration, params.feature);
|
|
168
|
+
var requiredHeaders = {
|
|
169
|
+
'X-User-Agent': sdkAgent,
|
|
170
|
+
'User-Agent': userAgentHeader
|
|
171
|
+
};
|
|
172
|
+
if (params.authtoken) {
|
|
173
|
+
requiredHeaders.authtoken = params.authtoken;
|
|
174
|
+
}
|
|
175
|
+
if (params.authorization) {
|
|
176
|
+
requiredHeaders.authorization = params.authorization;
|
|
177
|
+
}
|
|
178
|
+
params = _objectSpread(_objectSpread({}, defaultParameter), clonedeep(params));
|
|
179
|
+
params.headers = _objectSpread(_objectSpread({}, params.headers), requiredHeaders);
|
|
180
|
+
var http = httpClient(params);
|
|
181
|
+
return contentstackClient({
|
|
182
|
+
http: http
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @namespace ContentstackClient
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import error from './core/contentstackError';
|
|
6
|
+
import { Marketplace } from './marketplace/index.js';
|
|
7
|
+
export default function contentstackClient(_ref) {
|
|
8
|
+
var http = _ref.http;
|
|
9
|
+
/**
|
|
10
|
+
* @description The login call is used to sign in to your Contentstack account and obtain the authtoken.
|
|
11
|
+
* @memberof ContentstackClient
|
|
12
|
+
* @func login
|
|
13
|
+
* @param {Object} parameters - login parameters
|
|
14
|
+
* @prop {string} parameters.email - email id for user to login
|
|
15
|
+
* @prop {string} parameters.password - password for user to login
|
|
16
|
+
* @prop {string} parameters.token - token for user to login
|
|
17
|
+
* @returns {Promise}
|
|
18
|
+
* @example
|
|
19
|
+
* import * as contentstack from '@contentstack/management'
|
|
20
|
+
* const client = contentstack.client()
|
|
21
|
+
*
|
|
22
|
+
* client.login({ email: <emailid>, password: <password> })
|
|
23
|
+
* .then(() => console.log('Logged in successfully'))
|
|
24
|
+
*
|
|
25
|
+
* client.marketplace()
|
|
26
|
+
*/
|
|
27
|
+
function login(requestBody) {
|
|
28
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
29
|
+
http.defaults.versioningStrategy = 'path';
|
|
30
|
+
return http.post('https://api.contentstack.io:443/v3/user-session', {
|
|
31
|
+
user: requestBody
|
|
32
|
+
}, {
|
|
33
|
+
params: params
|
|
34
|
+
}).then(function (response) {
|
|
35
|
+
if (response.data.user != null && response.data.user.authtoken != null) {
|
|
36
|
+
http.defaults.headers.common.authtoken = response.data.user.authtoken;
|
|
37
|
+
}
|
|
38
|
+
return response.data;
|
|
39
|
+
}, error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users.
|
|
44
|
+
* @memberof ContentstackClient
|
|
45
|
+
* @func organization
|
|
46
|
+
* @param {String} uid - Organization UID.
|
|
47
|
+
* @returns {Organization} Instance of Organization.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* import * as contentstack from '@contentstack/management'
|
|
51
|
+
* const client = contentstack.client()
|
|
52
|
+
*
|
|
53
|
+
* client.organization().findAll()
|
|
54
|
+
* .then((organization) => console.log(organization))
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* import * as contentstack from '@contentstack/management'
|
|
58
|
+
* const client = contentstack.client()
|
|
59
|
+
*
|
|
60
|
+
* client.marketplace('org_uid')
|
|
61
|
+
*
|
|
62
|
+
*/
|
|
63
|
+
function marketplace(orgUid) {
|
|
64
|
+
http.defaults.versioningStrategy = 'path';
|
|
65
|
+
return new Marketplace(http, {
|
|
66
|
+
organization_uid: orgUid
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @description The Log out of your account call is used to sign out the user of Contentstack account.
|
|
72
|
+
* @memberof ContentstackClient
|
|
73
|
+
* @param {String} authtoken - Authtoken to logout from.
|
|
74
|
+
* @func logout
|
|
75
|
+
* @returns {Object} Response object.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* import * as contentstack from '@contentstack/management'
|
|
79
|
+
* const client = contentstack.client()
|
|
80
|
+
* client.logout()
|
|
81
|
+
* .then((response) => console.log(response))
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* import * as contentstack from '@contentstack/management'
|
|
85
|
+
* const client = contentstack.client()
|
|
86
|
+
* client.logout('AUTHTOKEN')
|
|
87
|
+
* .then((response) => console.log(response))
|
|
88
|
+
* */
|
|
89
|
+
function logout(authtoken) {
|
|
90
|
+
http.defaults.versioningStrategy = 'path';
|
|
91
|
+
if (authtoken !== undefined) {
|
|
92
|
+
return http["delete"]('https://api.contentstack.io:443/v3/user-session', {
|
|
93
|
+
headers: {
|
|
94
|
+
authtoken: authtoken
|
|
95
|
+
}
|
|
96
|
+
}).then(function (response) {
|
|
97
|
+
return response.data;
|
|
98
|
+
}, error);
|
|
99
|
+
}
|
|
100
|
+
return http["delete"]('https://api.contentstack.io:443/v3/user-session').then(function (response) {
|
|
101
|
+
if (http.defaults.headers.common) {
|
|
102
|
+
delete http.defaults.headers.common.authtoken;
|
|
103
|
+
}
|
|
104
|
+
delete http.defaults.headers.authtoken;
|
|
105
|
+
delete http.httpClientParams.authtoken;
|
|
106
|
+
delete http.httpClientParams.headers.authtoken;
|
|
107
|
+
return response.data;
|
|
108
|
+
}, error);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
login: login,
|
|
112
|
+
logout: logout,
|
|
113
|
+
marketplace: marketplace,
|
|
114
|
+
axiosInstance: http
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
/**
|
|
4
|
+
* @namespace ContentstackCollection
|
|
5
|
+
*/
|
|
6
|
+
var ContentstackCollection = /*#__PURE__*/_createClass(function ContentstackCollection(response, http) {
|
|
7
|
+
var stackHeaders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
8
|
+
var wrapperCollection = arguments.length > 3 ? arguments[3] : undefined;
|
|
9
|
+
_classCallCheck(this, ContentstackCollection);
|
|
10
|
+
var data = response.data || {};
|
|
11
|
+
if (stackHeaders) {
|
|
12
|
+
data.stackHeaders = stackHeaders;
|
|
13
|
+
}
|
|
14
|
+
if (wrapperCollection) {
|
|
15
|
+
this.items = wrapperCollection(http, data);
|
|
16
|
+
}
|
|
17
|
+
if (data.schema !== undefined) {
|
|
18
|
+
this.schema = data.schema;
|
|
19
|
+
}
|
|
20
|
+
if (data.content_type !== undefined) {
|
|
21
|
+
this.content_type = data.content_type;
|
|
22
|
+
}
|
|
23
|
+
if (data.count !== undefined) {
|
|
24
|
+
this.count = data.count;
|
|
25
|
+
}
|
|
26
|
+
if (data.notice !== undefined) {
|
|
27
|
+
this.notice = data.notice;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
export { ContentstackCollection as default };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { platform, release } from 'os';
|
|
2
|
+
var HOST_REGEX = /^(?!\w+:\/\/)([\w-:]+\.)+([\w-:]+)(?::(\d+))?(?!:)$/;
|
|
3
|
+
export function isHost(host) {
|
|
4
|
+
return HOST_REGEX.test(host);
|
|
5
|
+
}
|
|
6
|
+
export function isNode() {
|
|
7
|
+
return typeof process !== 'undefined' && !process.browser;
|
|
8
|
+
}
|
|
9
|
+
export function getNodeVersion() {
|
|
10
|
+
return process.versions.node ? "v".concat(process.versions.node) : process.version;
|
|
11
|
+
}
|
|
12
|
+
function isReactNative() {
|
|
13
|
+
return typeof window !== 'undefined' && 'navigator' in window && 'product' in window.navigator && window.navigator.product === 'ReactNative';
|
|
14
|
+
}
|
|
15
|
+
function getBrowserOS() {
|
|
16
|
+
if (!window) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
var userAgent = window.navigator.userAgent;
|
|
20
|
+
var platform = window.navigator.platform;
|
|
21
|
+
var macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'];
|
|
22
|
+
var windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
|
|
23
|
+
var iosPlatforms = ['iPhone', 'iPad', 'iPod'];
|
|
24
|
+
var os = null;
|
|
25
|
+
if (macosPlatforms.indexOf(platform) !== -1) {
|
|
26
|
+
os = 'macOS';
|
|
27
|
+
} else if (iosPlatforms.indexOf(platform) !== -1) {
|
|
28
|
+
os = 'iOS';
|
|
29
|
+
} else if (windowsPlatforms.indexOf(platform) !== -1) {
|
|
30
|
+
os = 'Windows';
|
|
31
|
+
} else if (/Android/.test(userAgent)) {
|
|
32
|
+
os = 'Android';
|
|
33
|
+
} else if (/Linux/.test(platform)) {
|
|
34
|
+
os = 'Linux';
|
|
35
|
+
}
|
|
36
|
+
return os;
|
|
37
|
+
}
|
|
38
|
+
function getNodeOS() {
|
|
39
|
+
var os = platform() || 'linux';
|
|
40
|
+
var version = release() || '0.0.0';
|
|
41
|
+
var osMap = {
|
|
42
|
+
android: 'Android',
|
|
43
|
+
aix: 'Linux',
|
|
44
|
+
darwin: 'macOS',
|
|
45
|
+
freebsd: 'Linux',
|
|
46
|
+
linux: 'Linux',
|
|
47
|
+
openbsd: 'Linux',
|
|
48
|
+
sunos: 'Linux',
|
|
49
|
+
win32: 'Windows'
|
|
50
|
+
};
|
|
51
|
+
if (os in osMap) {
|
|
52
|
+
return "".concat(osMap[os] || 'Linux', "/").concat(version);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
export default function getUserAgent(sdk, application, integration, feature) {
|
|
57
|
+
var headerParts = [];
|
|
58
|
+
if (application) {
|
|
59
|
+
headerParts.push("app ".concat(application));
|
|
60
|
+
}
|
|
61
|
+
if (integration) {
|
|
62
|
+
headerParts.push("integration ".concat(integration));
|
|
63
|
+
}
|
|
64
|
+
if (feature) {
|
|
65
|
+
headerParts.push('feature ' + feature);
|
|
66
|
+
}
|
|
67
|
+
headerParts.push("sdk ".concat(sdk));
|
|
68
|
+
var os = null;
|
|
69
|
+
try {
|
|
70
|
+
if (isReactNative()) {
|
|
71
|
+
os = getBrowserOS();
|
|
72
|
+
headerParts.push('platform ReactNative');
|
|
73
|
+
} else if (isNode()) {
|
|
74
|
+
os = getNodeOS();
|
|
75
|
+
headerParts.push("platform node.js/".concat(getNodeVersion()));
|
|
76
|
+
} else {
|
|
77
|
+
os = getBrowserOS();
|
|
78
|
+
headerParts.push("platform browser");
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
os = null;
|
|
82
|
+
}
|
|
83
|
+
if (os) {
|
|
84
|
+
headerParts.push("os ".concat(os));
|
|
85
|
+
}
|
|
86
|
+
return "".concat(headerParts.filter(function (item) {
|
|
87
|
+
return item !== '';
|
|
88
|
+
}).join('; '), ";");
|
|
89
|
+
}
|