contentful-management 12.0.0-beta.2 → 12.0.0-beta.3
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/README.md +3 -0
- package/dist/cjs/adapters/REST/endpoints/access-token.cjs +136 -0
- package/dist/cjs/adapters/REST/endpoints/ai-action-invocation.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/ai-action.cjs +53 -0
- package/dist/cjs/adapters/REST/endpoints/api-key.cjs +48 -0
- package/dist/cjs/adapters/REST/endpoints/app-access-token.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/app-action-call.cjs +65 -0
- package/dist/cjs/adapters/REST/endpoints/app-action.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/app-bundle.cjs +39 -0
- package/dist/cjs/adapters/REST/endpoints/app-definition.cjs +47 -0
- package/dist/cjs/adapters/REST/endpoints/app-details.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-event-subscription.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-installation.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/app-key.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/app-signed-request.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/app-signing-secret.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-upload.cjs +28 -0
- package/dist/cjs/adapters/REST/endpoints/asset-key.cjs +34 -0
- package/dist/cjs/adapters/REST/endpoints/asset.cjs +185 -0
- package/dist/cjs/adapters/REST/endpoints/bulk-action.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/comment.cjs +92 -0
- package/dist/cjs/adapters/REST/endpoints/concept-scheme.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/concept.cjs +65 -0
- package/dist/cjs/adapters/REST/endpoints/content-type.cjs +56 -0
- package/dist/cjs/adapters/REST/endpoints/editor-interface.cjs +24 -0
- package/dist/cjs/adapters/REST/endpoints/entry.cjs +104 -0
- package/dist/cjs/adapters/REST/endpoints/environment-alias.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/environment-template-installation.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/environment-template.cjs +49 -0
- package/dist/cjs/adapters/REST/endpoints/environment.cjs +47 -0
- package/dist/cjs/adapters/REST/endpoints/extension.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/function-log.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/function.cjs +25 -0
- package/dist/cjs/adapters/REST/endpoints/http.cjs +29 -0
- package/dist/cjs/adapters/REST/endpoints/index.cjs +139 -0
- package/dist/cjs/adapters/REST/endpoints/locale.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/oauth-application.cjs +147 -0
- package/dist/cjs/adapters/REST/endpoints/organization-invitation.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/organization-membership.cjs +32 -0
- package/dist/cjs/adapters/REST/endpoints/organization.cjs +28 -0
- package/dist/cjs/adapters/REST/endpoints/personal-access-token.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/preview-api-key.cjs +15 -0
- package/dist/cjs/adapters/REST/endpoints/raw.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/release-action.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/release.cjs +61 -0
- package/dist/cjs/adapters/REST/endpoints/resource-provider.cjs +18 -0
- package/dist/cjs/adapters/REST/endpoints/resource-type.cjs +30 -0
- package/dist/cjs/adapters/REST/endpoints/resource.cjs +10 -0
- package/dist/cjs/adapters/REST/endpoints/role.cjs +48 -0
- package/dist/cjs/adapters/REST/endpoints/scheduled-action.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/snapshot.cjs +30 -0
- package/dist/cjs/adapters/REST/endpoints/space-member.cjs +11 -0
- package/dist/cjs/adapters/REST/endpoints/space-membership.cjs +60 -0
- package/dist/cjs/adapters/REST/endpoints/space.cjs +34 -0
- package/dist/cjs/adapters/REST/endpoints/tag.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/task.cjs +40 -0
- package/dist/cjs/adapters/REST/endpoints/team-membership.cjs +35 -0
- package/dist/cjs/adapters/REST/endpoints/team-space-membership.cjs +46 -0
- package/dist/cjs/adapters/REST/endpoints/team.cjs +36 -0
- package/dist/cjs/adapters/REST/endpoints/ui-config.cjs +22 -0
- package/dist/cjs/adapters/REST/endpoints/upload-credentials.cjs +16 -0
- package/dist/cjs/adapters/REST/endpoints/upload.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/usage.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/user-ui-config.cjs +22 -0
- package/dist/cjs/adapters/REST/endpoints/user.cjs +27 -0
- package/dist/cjs/adapters/REST/endpoints/utils.cjs +20 -0
- package/dist/cjs/adapters/REST/endpoints/webhook.cjs +98 -0
- package/dist/cjs/adapters/REST/endpoints/workflow-definition.cjs +41 -0
- package/dist/cjs/adapters/REST/endpoints/workflow.cjs +49 -0
- package/dist/cjs/adapters/REST/endpoints/workflows-changelog.cjs +11 -0
- package/dist/cjs/adapters/REST/make-request.cjs +19 -0
- package/dist/cjs/adapters/REST/rest-adapter.cjs +32 -0
- package/dist/cjs/common-types.cjs +6 -0
- package/dist/cjs/common-utils.cjs +38 -0
- package/dist/cjs/constants/editor-interface-defaults/controls-defaults.cjs +161 -0
- package/dist/cjs/constants/editor-interface-defaults/editors-defaults.cjs +40 -0
- package/dist/cjs/constants/editor-interface-defaults/index.cjs +14 -0
- package/dist/cjs/constants/editor-interface-defaults/sidebar-defaults.cjs +71 -0
- package/dist/cjs/constants/editor-interface-defaults/types.cjs +18 -0
- package/dist/cjs/create-adapter.cjs +21 -0
- package/dist/cjs/create-app-definition-api.cjs +254 -0
- package/dist/cjs/create-contentful-api.cjs +592 -0
- package/dist/cjs/create-entry-api.cjs +481 -0
- package/dist/cjs/create-environment-api.cjs +2403 -0
- package/dist/cjs/create-environment-template-api.cjs +270 -0
- package/dist/cjs/create-organization-api.cjs +1136 -0
- package/dist/cjs/create-space-api.cjs +1591 -0
- package/dist/cjs/create-ui-config-api.cjs +55 -0
- package/dist/cjs/create-user-ui-config-api.cjs +55 -0
- package/dist/cjs/enhance-with-methods.cjs +26 -0
- package/dist/cjs/entities/access-token.cjs +36 -0
- package/dist/cjs/entities/ai-action-invocation.cjs +46 -0
- package/dist/cjs/entities/ai-action.cjs +94 -0
- package/dist/cjs/entities/api-key.cjs +59 -0
- package/dist/cjs/entities/app-access-token.cjs +17 -0
- package/dist/cjs/entities/app-action-call.cjs +67 -0
- package/dist/cjs/entities/app-action.cjs +48 -0
- package/dist/cjs/entities/app-bundle.cjs +48 -0
- package/dist/cjs/entities/app-definition.cjs +29 -0
- package/dist/cjs/entities/app-details.cjs +39 -0
- package/dist/cjs/entities/app-event-subscription.cjs +34 -0
- package/dist/cjs/entities/app-installation.cjs +55 -0
- package/dist/cjs/entities/app-key.cjs +44 -0
- package/dist/cjs/entities/app-signed-request.cjs +17 -0
- package/dist/cjs/entities/app-signing-secret.cjs +34 -0
- package/dist/cjs/entities/app-upload.cjs +47 -0
- package/dist/cjs/entities/asset-key.cjs +17 -0
- package/dist/cjs/entities/asset.cjs +124 -0
- package/dist/cjs/entities/bulk-action.cjs +60 -0
- package/dist/cjs/entities/comment.cjs +63 -0
- package/dist/cjs/entities/concept-scheme.cjs +2 -0
- package/dist/cjs/entities/concept.cjs +2 -0
- package/dist/cjs/entities/content-type.cjs +120 -0
- package/dist/cjs/entities/editor-interface.cjs +50 -0
- package/dist/cjs/entities/entry.cjs +27 -0
- package/dist/cjs/entities/environment-alias.cjs +58 -0
- package/dist/cjs/entities/environment-template-installation.cjs +23 -0
- package/dist/cjs/entities/environment-template.cjs +18 -0
- package/dist/cjs/entities/environment.cjs +34 -0
- package/dist/cjs/entities/extension.cjs +54 -0
- package/dist/cjs/entities/function-log.cjs +26 -0
- package/dist/cjs/entities/function.cjs +66 -0
- package/dist/cjs/entities/index.cjs +131 -0
- package/dist/cjs/entities/locale.cjs +57 -0
- package/dist/cjs/entities/oauth-application.cjs +66 -0
- package/dist/cjs/entities/organization-invitation.cjs +17 -0
- package/dist/cjs/entities/organization-membership.cjs +53 -0
- package/dist/cjs/entities/organization.cjs +32 -0
- package/dist/cjs/entities/personal-access-token.cjs +36 -0
- package/dist/cjs/entities/preview-api-key.cjs +31 -0
- package/dist/cjs/entities/release-action.cjs +55 -0
- package/dist/cjs/entities/release.cjs +111 -0
- package/dist/cjs/entities/resource-provider.cjs +139 -0
- package/dist/cjs/entities/resource-type.cjs +98 -0
- package/dist/cjs/entities/resource.cjs +13 -0
- package/dist/cjs/entities/role.cjs +53 -0
- package/dist/cjs/entities/scheduled-action.cjs +154 -0
- package/dist/cjs/entities/snapshot.cjs +36 -0
- package/dist/cjs/entities/space-member.cjs +23 -0
- package/dist/cjs/entities/space-membership.cjs +53 -0
- package/dist/cjs/entities/space.cjs +33 -0
- package/dist/cjs/entities/tag.cjs +56 -0
- package/dist/cjs/entities/task.cjs +57 -0
- package/dist/cjs/entities/team-membership.cjs +54 -0
- package/dist/cjs/entities/team-space-membership.cjs +53 -0
- package/dist/cjs/entities/team.cjs +53 -0
- package/dist/cjs/entities/ui-config.cjs +20 -0
- package/dist/cjs/entities/upload.cjs +38 -0
- package/dist/cjs/entities/usage.cjs +25 -0
- package/dist/cjs/entities/user-ui-config.cjs +20 -0
- package/dist/cjs/entities/user.cjs +28 -0
- package/dist/cjs/entities/webhook.cjs +77 -0
- package/dist/cjs/entities/workflow-definition.cjs +79 -0
- package/dist/cjs/index.cjs +65 -0
- package/dist/cjs/methods/action.cjs +53 -0
- package/dist/cjs/methods/content-type.cjs +51 -0
- package/dist/cjs/methods/utils.cjs +11 -0
- package/dist/cjs/plain/as-iterator.cjs +32 -0
- package/dist/cjs/plain/checks.cjs +15 -0
- package/dist/cjs/plain/pagination-helper.cjs +56 -0
- package/dist/cjs/plain/plain-client.cjs +516 -0
- package/dist/cjs/plain/wrappers/wrap.cjs +26 -0
- package/dist/cjs/upload-http-client.cjs +17 -0
- package/dist/contentful-management.browser.js +3 -3
- package/dist/contentful-management.browser.min.js +1 -1
- package/dist/contentful-management.cjs +3 -3
- package/dist/esm/create-contentful-api.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/plain/plain-client.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -155,6 +155,9 @@ const contentful = require('contentful-management')
|
|
|
155
155
|
If this does not work, you can directly require the CJS-compatible code:
|
|
156
156
|
|
|
157
157
|
```js
|
|
158
|
+
// pure cjs files
|
|
159
|
+
const contentful = require('contentful-management/dist/cjs/index.cjs')
|
|
160
|
+
// bundle
|
|
158
161
|
const contentful = require('contentful-management/dist/contentful-management.cjs')
|
|
159
162
|
```
|
|
160
163
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves an access token by its unique token ID for the currently authenticated user.
|
|
7
|
+
*
|
|
8
|
+
* @param {AxiosInstance} http - An Axios HTTP client instance.
|
|
9
|
+
* @param {Object} params - Parameters for the request.
|
|
10
|
+
* @param {string} params.tokenId - The unique token ID of the access token to retrieve.
|
|
11
|
+
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the retrieved access token information.
|
|
12
|
+
* @example ```javascript
|
|
13
|
+
* const contentful = require('contentful-management')
|
|
14
|
+
*
|
|
15
|
+
* const plainClient = contentful.createClient(
|
|
16
|
+
* {
|
|
17
|
+
* accessToken: '<content_management_api_key>'
|
|
18
|
+
* },
|
|
19
|
+
* { type: 'plain' }
|
|
20
|
+
* )
|
|
21
|
+
* plainClient.get({tokenId: 'TestTokenTd'})
|
|
22
|
+
* .then(token => console.log(token))
|
|
23
|
+
* .catch(console.error)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const get = (http, params) => {
|
|
27
|
+
return raw.get(http, `/users/me/access_tokens/${params.tokenId}`);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves multiple access tokens associated with the currently authenticated user.
|
|
31
|
+
*
|
|
32
|
+
* @param {AxiosInstance} http - An Axios HTTP client instance.
|
|
33
|
+
* @param {QueryParams} params - Query parameters to filter and customize the request.
|
|
34
|
+
* @returns {Promise<CollectionProp<AccessTokenProps>>} A Promise that resolves with a collection of access token properties.
|
|
35
|
+
* @example ```javascript
|
|
36
|
+
* const contentful = require('contentful-management')
|
|
37
|
+
*
|
|
38
|
+
* const plainClient = contentful.createClient(
|
|
39
|
+
* {
|
|
40
|
+
* accessToken: '<content_management_api_key>'
|
|
41
|
+
* },
|
|
42
|
+
* { type: 'plain' }
|
|
43
|
+
* )
|
|
44
|
+
* plainClient.getMany()
|
|
45
|
+
* .then(result => console.log(result.items))
|
|
46
|
+
* .catch(console.error)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
const getMany = (http, params) => {
|
|
50
|
+
return raw.get(http, '/users/me/access_tokens', {
|
|
51
|
+
params: params.query,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Creates a personal access token for the currently authenticated user.
|
|
56
|
+
*
|
|
57
|
+
* @param {AxiosInstance} http - Axios instance for making the HTTP request.
|
|
58
|
+
* @param {Object} _params - Unused parameters (can be an empty object).
|
|
59
|
+
* @param {CreatePersonalAccessTokenProps} rawData - Data for creating the personal access token.
|
|
60
|
+
* @param {RawAxiosRequestHeaders} [headers] - Optional HTTP headers for the request.
|
|
61
|
+
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the created personal access token.
|
|
62
|
+
* @example ```javascript
|
|
63
|
+
* const contentful = require('contentful-management')
|
|
64
|
+
*
|
|
65
|
+
* const plainClient = contentful.createClient(
|
|
66
|
+
* {
|
|
67
|
+
* accessToken: '<content_management_api_key>',
|
|
68
|
+
* },
|
|
69
|
+
* { type: 'plain' }
|
|
70
|
+
* )
|
|
71
|
+
* plainClient.createPersonalAccessToken({name: 'Test-Name', scope: ['content_management_manage'], expiresIn: 777596.92})
|
|
72
|
+
* .then(token => console.log(token))
|
|
73
|
+
* .catch(console.error)
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
const createPersonalAccessToken = (http, _params, rawData, headers) => {
|
|
77
|
+
return raw.post(http, '/users/me/access_tokens', rawData, {
|
|
78
|
+
headers,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Revokes an access token associated with the currently authenticated user.
|
|
83
|
+
*
|
|
84
|
+
* @param {AxiosInstance} http - The Axios HTTP client instance.
|
|
85
|
+
* @param {Object} params - The parameters for revoking the access token.
|
|
86
|
+
* @param {string} params.tokenId - The unique identifier of the access token to revoke.
|
|
87
|
+
* @returns {Promise<AccessTokenProps>} A Promise that resolves with the updated access token information after revocation.
|
|
88
|
+
* @example ```javascript
|
|
89
|
+
* const contentful = require('contentful-management')
|
|
90
|
+
*
|
|
91
|
+
* const plainClient = contentful.createClient(
|
|
92
|
+
* {
|
|
93
|
+
* accessToken: '<content_management_api_key>'
|
|
94
|
+
* },
|
|
95
|
+
* { type: 'plain' }
|
|
96
|
+
* )
|
|
97
|
+
* plainClient.revoke({tokenId: 'TestTokenTd'})
|
|
98
|
+
* .then(token => console.log(token))
|
|
99
|
+
* .catch(console.error)
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const revoke = (http, params) => {
|
|
103
|
+
return raw.put(http, `/users/me/access_tokens/${params.tokenId}/revoked`, null);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a list of redacted versions of access tokens for an organization, accessible to owners or administrators of an organization.
|
|
107
|
+
*
|
|
108
|
+
* @param {AxiosInstance} http - The Axios HTTP client instance.
|
|
109
|
+
* @param {GetOrganizationParams & QueryParams} params - Parameters for the request, including organization ID and query parameters.
|
|
110
|
+
* @param {string} params.organizationId - The unique identifier of the organization.
|
|
111
|
+
* @returns {Promise<CollectionProp<AccessTokenProps>>} A promise that resolves to a collection of access tokens.
|
|
112
|
+
* @example ```javascript
|
|
113
|
+
* const contentful = require('contentful-management')
|
|
114
|
+
*
|
|
115
|
+
* const plainClient = contentful.createClient(
|
|
116
|
+
* {
|
|
117
|
+
* accessToken: '<content_management_api_key>'
|
|
118
|
+
* },
|
|
119
|
+
* { type: 'plain' }
|
|
120
|
+
* )
|
|
121
|
+
* plainClient.getManyForOrganization({organizationId: 'OrgId'})
|
|
122
|
+
* .then(result => console.log(result.items))
|
|
123
|
+
* .catch(console.error)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
const getManyForOrganization = (http, params) => {
|
|
127
|
+
return raw.get(http, `/organizations/${params.organizationId}/access_tokens`, {
|
|
128
|
+
params: params.query,
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
exports.createPersonalAccessToken = createPersonalAccessToken;
|
|
133
|
+
exports.get = get;
|
|
134
|
+
exports.getMany = getMany;
|
|
135
|
+
exports.getManyForOrganization = getManyForOrganization;
|
|
136
|
+
exports.revoke = revoke;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const get = (http, params, headers) => {
|
|
6
|
+
return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/ai/actions/${params.aiActionId}/invocations/${params.invocationId}`, { headers });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.get = get;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var copy = require('fast-copy');
|
|
5
|
+
var raw = require('./raw.js');
|
|
6
|
+
|
|
7
|
+
const get = (http, params, headers) => {
|
|
8
|
+
return raw.get(http, `/spaces/${params.spaceId}/ai/actions/${params.aiActionId}`, {
|
|
9
|
+
headers,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const getMany = (http, params, headers) => {
|
|
13
|
+
return raw.get(http, `/spaces/${params.spaceId}/ai/actions`, {
|
|
14
|
+
params: params.query,
|
|
15
|
+
headers,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const create = (http, params, data, headers) => {
|
|
19
|
+
return raw.post(http, `/spaces/${params.spaceId}/ai/actions`, data, { headers });
|
|
20
|
+
};
|
|
21
|
+
const update = (http, params, rawData, headers) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const data = copy(rawData);
|
|
24
|
+
const payload = tslib.__rest(data, ["sys"]);
|
|
25
|
+
return raw.put(http, `/spaces/${params.spaceId}/ai/actions/${params.aiActionId}`, payload, {
|
|
26
|
+
headers: Object.assign({ 'X-Contentful-Version': (_a = rawData.sys.version) !== null && _a !== void 0 ? _a : 0 }, headers),
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const del = (http, params, headers) => {
|
|
30
|
+
return raw.del(http, `/spaces/${params.spaceId}/ai/actions/${params.aiActionId}`, { headers });
|
|
31
|
+
};
|
|
32
|
+
const publish = (http, params, rawData, headers) => {
|
|
33
|
+
return raw.put(http, `/spaces/${params.spaceId}/ai/actions/${params.aiActionId}/published`, null, {
|
|
34
|
+
headers: Object.assign({ 'X-Contentful-Version': params.version }, headers),
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const unpublish = (http, params, headers) => {
|
|
38
|
+
return raw.del(http, `/spaces/${params.spaceId}/ai/actions/${params.aiActionId}/published`, {
|
|
39
|
+
headers,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const invoke = (http, params, data, headers) => {
|
|
43
|
+
return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/ai/actions/${params.aiActionId}/invoke`, data, { headers });
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.create = create;
|
|
47
|
+
exports.del = del;
|
|
48
|
+
exports.get = get;
|
|
49
|
+
exports.getMany = getMany;
|
|
50
|
+
exports.invoke = invoke;
|
|
51
|
+
exports.publish = publish;
|
|
52
|
+
exports.unpublish = unpublish;
|
|
53
|
+
exports.update = update;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var copy = require('fast-copy');
|
|
4
|
+
var raw = require('./raw.js');
|
|
5
|
+
|
|
6
|
+
const get = (http, params) => {
|
|
7
|
+
return raw.get(http, `/spaces/${params.spaceId}/api_keys/${params.apiKeyId}`);
|
|
8
|
+
};
|
|
9
|
+
const getMany = (http, params) => {
|
|
10
|
+
return raw.get(http, `/spaces/${params.spaceId}/api_keys`, {
|
|
11
|
+
params: params.query,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const create = (http, params, data, headers) => {
|
|
15
|
+
return raw.post(http, `/spaces/${params.spaceId}/api_keys`, data, { headers });
|
|
16
|
+
};
|
|
17
|
+
const createWithId = (http, params, data, headers) => {
|
|
18
|
+
return raw.put(http, `/spaces/${params.spaceId}/api_keys/${params.apiKeyId}`, data, {
|
|
19
|
+
headers,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const update = (http, params, rawData, headers) => {
|
|
23
|
+
var _a;
|
|
24
|
+
const data = copy(rawData);
|
|
25
|
+
if ('accessToken' in data) {
|
|
26
|
+
delete data.accessToken;
|
|
27
|
+
}
|
|
28
|
+
if ('preview_api_key' in data) {
|
|
29
|
+
delete data.preview_api_key;
|
|
30
|
+
}
|
|
31
|
+
if ('policies' in data) {
|
|
32
|
+
delete data.policies;
|
|
33
|
+
}
|
|
34
|
+
delete data.sys;
|
|
35
|
+
return raw.put(http, `/spaces/${params.spaceId}/api_keys/${params.apiKeyId}`, data, {
|
|
36
|
+
headers: Object.assign({ 'X-Contentful-Version': (_a = rawData.sys.version) !== null && _a !== void 0 ? _a : 0 }, headers),
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const del = (http, params) => {
|
|
40
|
+
return raw.del(http, `/spaces/${params.spaceId}/api_keys/${params.apiKeyId}`);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.create = create;
|
|
44
|
+
exports.createWithId = createWithId;
|
|
45
|
+
exports.del = del;
|
|
46
|
+
exports.get = get;
|
|
47
|
+
exports.getMany = getMany;
|
|
48
|
+
exports.update = update;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const create = (http, params, data) => {
|
|
6
|
+
return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appDefinitionId}/access_tokens`, undefined, { headers: { Authorization: `Bearer ${data.jwt}` } });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.create = create;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var commonUtils = require('../../../common-utils.js');
|
|
5
|
+
|
|
6
|
+
const create = (http, params, data) => {
|
|
7
|
+
return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appDefinitionId}/actions/${params.appActionId}/calls`, data);
|
|
8
|
+
};
|
|
9
|
+
const getCallDetails = (http, params) => {
|
|
10
|
+
return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/actions/${params.appActionId}/calls/${params.callId}`);
|
|
11
|
+
};
|
|
12
|
+
const APP_ACTION_CALL_RETRY_INTERVAL = 2000;
|
|
13
|
+
const APP_ACTION_CALL_RETRIES = 15;
|
|
14
|
+
async function callAppActionResult(http, params, { callId, }) {
|
|
15
|
+
let checkCount = 1;
|
|
16
|
+
const retryInterval = params.retryInterval || APP_ACTION_CALL_RETRY_INTERVAL;
|
|
17
|
+
const retries = params.retries || APP_ACTION_CALL_RETRIES;
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const poll = async () => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
try {
|
|
22
|
+
const result = await getCallDetails(http, Object.assign(Object.assign({}, params), { callId: callId }));
|
|
23
|
+
// The lambda failed or returned a 404, so we shouldn't re-poll anymore
|
|
24
|
+
if (((_a = result === null || result === void 0 ? void 0 : result.response) === null || _a === void 0 ? void 0 : _a.statusCode) && !commonUtils.isSuccessful((_b = result === null || result === void 0 ? void 0 : result.response) === null || _b === void 0 ? void 0 : _b.statusCode)) {
|
|
25
|
+
const error = new Error('App action not found or lambda fails');
|
|
26
|
+
reject(error);
|
|
27
|
+
}
|
|
28
|
+
else if (commonUtils.isSuccessful(result.statusCode)) {
|
|
29
|
+
resolve(result);
|
|
30
|
+
}
|
|
31
|
+
// The logs are not ready yet. Continue waiting for them
|
|
32
|
+
else if (commonUtils.shouldRePoll(result.statusCode) && checkCount < retries) {
|
|
33
|
+
checkCount++;
|
|
34
|
+
await commonUtils.waitFor(retryInterval);
|
|
35
|
+
poll();
|
|
36
|
+
}
|
|
37
|
+
// If the response status code is not successful and is not a status code that should be repolled, reject with an error immediately
|
|
38
|
+
else {
|
|
39
|
+
const error = new Error('The app action response is taking longer than expected to process.');
|
|
40
|
+
reject(error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
checkCount++;
|
|
45
|
+
if (checkCount > retries) {
|
|
46
|
+
reject(new Error('The app action response is taking longer than expected to process.'));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// If `appActionCalls.getCallDetails` throws, we re-poll as it might mean that the lambda result is not available in the webhook logs yet
|
|
50
|
+
await commonUtils.waitFor(retryInterval);
|
|
51
|
+
poll();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
poll();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const createWithResponse = async (http, params, data) => {
|
|
58
|
+
const createResponse = await raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appDefinitionId}/actions/${params.appActionId}/calls`, data);
|
|
59
|
+
const callId = createResponse.sys.id;
|
|
60
|
+
return callAppActionResult(http, params, { callId });
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.create = create;
|
|
64
|
+
exports.createWithResponse = createWithResponse;
|
|
65
|
+
exports.getCallDetails = getCallDetails;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var utils = require('./utils.js');
|
|
5
|
+
|
|
6
|
+
const getBaseUrl = (params) => `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/actions`;
|
|
7
|
+
const getAppActionUrl = (params) => `${getBaseUrl(params)}/${params.appActionId}`;
|
|
8
|
+
const getAppActionsEnvUrl = (params) => {
|
|
9
|
+
if (params.environmentId) {
|
|
10
|
+
return `/spaces/${params.spaceId}/environments/${params.environmentId}/actions`;
|
|
11
|
+
}
|
|
12
|
+
return `/spaces/${params.spaceId}/actions`;
|
|
13
|
+
};
|
|
14
|
+
const get = (http, params) => {
|
|
15
|
+
return raw.get(http, getAppActionUrl(params));
|
|
16
|
+
};
|
|
17
|
+
const getMany = (http, params) => {
|
|
18
|
+
return raw.get(http, getBaseUrl(params), {
|
|
19
|
+
params: utils.normalizeSelect(params.query),
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const getManyForEnvironment = (http, params) => {
|
|
23
|
+
return raw.get(http, getAppActionsEnvUrl(params), {
|
|
24
|
+
params: utils.normalizeSelect(params.query),
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const del = (http, params) => {
|
|
28
|
+
return raw.del(http, getAppActionUrl(params));
|
|
29
|
+
};
|
|
30
|
+
const create = (http, params, data) => {
|
|
31
|
+
return raw.post(http, getBaseUrl(params), data);
|
|
32
|
+
};
|
|
33
|
+
const update = (http, params, data) => {
|
|
34
|
+
return raw.put(http, getAppActionUrl(params), data);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.create = create;
|
|
38
|
+
exports.del = del;
|
|
39
|
+
exports.get = get;
|
|
40
|
+
exports.getMany = getMany;
|
|
41
|
+
exports.getManyForEnvironment = getManyForEnvironment;
|
|
42
|
+
exports.update = update;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var utils = require('./utils.js');
|
|
5
|
+
|
|
6
|
+
const getBaseUrl = (params) => `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/app_bundles`;
|
|
7
|
+
const getAppBundleUrl = (params) => `${getBaseUrl(params)}/${params.appBundleId}`;
|
|
8
|
+
const get = (http, params) => {
|
|
9
|
+
return raw.get(http, getAppBundleUrl(params));
|
|
10
|
+
};
|
|
11
|
+
const getMany = (http, params) => {
|
|
12
|
+
return raw.get(http, getBaseUrl(params), {
|
|
13
|
+
params: utils.normalizeSelect(params.query),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
const del = (http, params) => {
|
|
17
|
+
return raw.del(http, getAppBundleUrl(params));
|
|
18
|
+
};
|
|
19
|
+
const create = (http, params, payload) => {
|
|
20
|
+
const { appUploadId, comment, actions, functions } = payload;
|
|
21
|
+
const data = {
|
|
22
|
+
upload: {
|
|
23
|
+
sys: {
|
|
24
|
+
type: 'Link',
|
|
25
|
+
linkType: 'AppUpload',
|
|
26
|
+
id: appUploadId,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
comment,
|
|
30
|
+
actions,
|
|
31
|
+
functions,
|
|
32
|
+
};
|
|
33
|
+
return raw.post(http, getBaseUrl(params), data);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.create = create;
|
|
37
|
+
exports.del = del;
|
|
38
|
+
exports.get = get;
|
|
39
|
+
exports.getMany = getMany;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var copy = require('fast-copy');
|
|
5
|
+
var utils = require('./utils.js');
|
|
6
|
+
|
|
7
|
+
const getBaseUrl = (params) => `/organizations/${params.organizationId}/app_definitions`;
|
|
8
|
+
const getAppDefinitionUrl = (params) => getBaseUrl(params) + `/${params.appDefinitionId}`;
|
|
9
|
+
const getBaseUrlForOrgInstallations = (params) => `/app_definitions/${params.appDefinitionId}/app_installations`;
|
|
10
|
+
const get = (http, params) => {
|
|
11
|
+
return raw.get(http, getAppDefinitionUrl(params), {
|
|
12
|
+
params: utils.normalizeSelect(params.query),
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const getMany = (http, params) => {
|
|
16
|
+
return raw.get(http, getBaseUrl(params), {
|
|
17
|
+
params: params.query,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const create = (http, params, rawData) => {
|
|
21
|
+
const data = copy(rawData);
|
|
22
|
+
return raw.post(http, getBaseUrl(params), data);
|
|
23
|
+
};
|
|
24
|
+
const update = (http, params, rawData, headers) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const data = copy(rawData);
|
|
27
|
+
delete data.sys;
|
|
28
|
+
return raw.put(http, getAppDefinitionUrl(params), data, {
|
|
29
|
+
headers: Object.assign({ 'X-Contentful-Version': (_a = rawData.sys.version) !== null && _a !== void 0 ? _a : 0 }, headers),
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const del = (http, params) => {
|
|
33
|
+
return raw.del(http, getAppDefinitionUrl(params));
|
|
34
|
+
};
|
|
35
|
+
const getInstallationsForOrg = (http, params) => {
|
|
36
|
+
return raw.get(http, getBaseUrlForOrgInstallations(params), {
|
|
37
|
+
params: Object.assign(Object.assign({}, utils.normalizeSpaceId(utils.normalizeSelect(params.query))), { 'sys.organization.sys.id[in]': params.organizationId }),
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
exports.create = create;
|
|
42
|
+
exports.del = del;
|
|
43
|
+
exports.get = get;
|
|
44
|
+
exports.getAppDefinitionUrl = getAppDefinitionUrl;
|
|
45
|
+
exports.getInstallationsForOrg = getInstallationsForOrg;
|
|
46
|
+
exports.getMany = getMany;
|
|
47
|
+
exports.update = update;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const get = (http, params) => {
|
|
6
|
+
return raw.get(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/details`);
|
|
7
|
+
};
|
|
8
|
+
const upsert = (http, params, data) => {
|
|
9
|
+
return raw.put(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/details`, data);
|
|
10
|
+
};
|
|
11
|
+
const del = (http, params) => {
|
|
12
|
+
return raw.del(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/details`);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.del = del;
|
|
16
|
+
exports.get = get;
|
|
17
|
+
exports.upsert = upsert;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const get = (http, params) => {
|
|
6
|
+
return raw.get(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/event_subscription`);
|
|
7
|
+
};
|
|
8
|
+
const upsert = (http, params, data) => {
|
|
9
|
+
return raw.put(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/event_subscription`, data);
|
|
10
|
+
};
|
|
11
|
+
const del = (http, params) => {
|
|
12
|
+
return raw.del(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/event_subscription`);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.del = del;
|
|
16
|
+
exports.get = get;
|
|
17
|
+
exports.upsert = upsert;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var utils = require('./utils.js');
|
|
5
|
+
var copy = require('fast-copy');
|
|
6
|
+
|
|
7
|
+
const getBaseUrl = (params) => `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations`;
|
|
8
|
+
const getBaseUrlForOrgInstallations = (params) => `/app_definitions/${params.appDefinitionId}/app_installations`;
|
|
9
|
+
const getAppInstallationUrl = (params) => getBaseUrl(params) + `/${params.appDefinitionId}`;
|
|
10
|
+
const get = (http, params) => {
|
|
11
|
+
return raw.get(http, getAppInstallationUrl(params), {
|
|
12
|
+
params: utils.normalizeSelect(params.query),
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const getMany = (http, params) => {
|
|
16
|
+
return raw.get(http, getBaseUrl(params), {
|
|
17
|
+
params: utils.normalizeSelect(params.query),
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const upsert = (http, params, rawData, headers) => {
|
|
21
|
+
const data = copy(rawData);
|
|
22
|
+
return raw.put(http, getAppInstallationUrl(params), data, {
|
|
23
|
+
headers: Object.assign(Object.assign({}, headers), (params.acceptAllTerms && {
|
|
24
|
+
'X-Contentful-Marketplace': 'i-accept-end-user-license-agreement,i-accept-marketplace-terms-of-service,i-accept-privacy-policy',
|
|
25
|
+
})),
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const del = (http, params) => {
|
|
29
|
+
return raw.del(http, getAppInstallationUrl(params));
|
|
30
|
+
};
|
|
31
|
+
const getForOrganization = (http, params) => {
|
|
32
|
+
return raw.get(http, getBaseUrlForOrgInstallations(params), {
|
|
33
|
+
params: Object.assign(Object.assign({}, utils.normalizeSpaceId(utils.normalizeSelect(params.query))), { 'sys.organization.sys.id[in]': params.organizationId }),
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.del = del;
|
|
38
|
+
exports.get = get;
|
|
39
|
+
exports.getAppInstallationUrl = getAppInstallationUrl;
|
|
40
|
+
exports.getForOrganization = getForOrganization;
|
|
41
|
+
exports.getMany = getMany;
|
|
42
|
+
exports.upsert = upsert;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const get = (http, params) => {
|
|
6
|
+
return raw.get(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/keys/${params.fingerprint}`);
|
|
7
|
+
};
|
|
8
|
+
const getMany = (http, params) => {
|
|
9
|
+
return raw.get(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/keys`);
|
|
10
|
+
};
|
|
11
|
+
const create = (http, params, data) => {
|
|
12
|
+
return raw.post(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/keys`, data);
|
|
13
|
+
};
|
|
14
|
+
const del = (http, params) => {
|
|
15
|
+
return raw.del(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/keys/${params.fingerprint}`);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.create = create;
|
|
19
|
+
exports.del = del;
|
|
20
|
+
exports.get = get;
|
|
21
|
+
exports.getMany = getMany;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const create = (http, params, data) => {
|
|
6
|
+
return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appDefinitionId}/signed_requests`, data);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.create = create;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const get = (http, params) => {
|
|
6
|
+
return raw.get(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/signing_secret`);
|
|
7
|
+
};
|
|
8
|
+
const upsert = (http, params, data) => {
|
|
9
|
+
return raw.put(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/signing_secret`, data);
|
|
10
|
+
};
|
|
11
|
+
const del = (http, params) => {
|
|
12
|
+
return raw.del(http, `/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/signing_secret`);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.del = del;
|
|
16
|
+
exports.get = get;
|
|
17
|
+
exports.upsert = upsert;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
var uploadHttpClient = require('../../../upload-http-client.js');
|
|
5
|
+
|
|
6
|
+
const getBaseUrl = (params) => `/organizations/${params.organizationId}/app_uploads`;
|
|
7
|
+
const getAppUploadUrl = (params) => `${getBaseUrl(params)}/${params.appUploadId}`;
|
|
8
|
+
const get = (http, params) => {
|
|
9
|
+
const httpUpload = uploadHttpClient.getUploadHttpClient(http);
|
|
10
|
+
return raw.get(httpUpload, getAppUploadUrl(params));
|
|
11
|
+
};
|
|
12
|
+
const del = (http, params) => {
|
|
13
|
+
const httpUpload = uploadHttpClient.getUploadHttpClient(http);
|
|
14
|
+
return raw.del(httpUpload, getAppUploadUrl(params));
|
|
15
|
+
};
|
|
16
|
+
const create = (http, params, payload) => {
|
|
17
|
+
const httpUpload = uploadHttpClient.getUploadHttpClient(http);
|
|
18
|
+
const { file } = payload;
|
|
19
|
+
return raw.post(httpUpload, getBaseUrl(params), file, {
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/octet-stream',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.create = create;
|
|
27
|
+
exports.del = del;
|
|
28
|
+
exports.get = get;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var raw = require('./raw.js');
|
|
4
|
+
|
|
5
|
+
const ASSET_KEY_MAX_LIFETIME = 48 * 60 * 60;
|
|
6
|
+
class ValidationError extends Error {
|
|
7
|
+
constructor(name, message) {
|
|
8
|
+
super(`Invalid "${name}" provided, ` + message);
|
|
9
|
+
this.name = 'ValidationError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const validateTimestamp = (name, timestamp, options) => {
|
|
13
|
+
options = options || {};
|
|
14
|
+
if (typeof timestamp !== 'number') {
|
|
15
|
+
throw new ValidationError(name, `only numeric values are allowed for timestamps, provided type was "${typeof timestamp}"`);
|
|
16
|
+
}
|
|
17
|
+
if (options.maximum && timestamp > options.maximum) {
|
|
18
|
+
throw new ValidationError(name, `value (${timestamp}) cannot be further in the future than expected maximum (${options.maximum})`);
|
|
19
|
+
}
|
|
20
|
+
if (options.now && timestamp < options.now) {
|
|
21
|
+
throw new ValidationError(name, `value (${timestamp}) cannot be in the past, current time was ${options.now}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const create = (http, params, data) => {
|
|
25
|
+
const expiresAt = data.expiresAt;
|
|
26
|
+
const now = Math.floor(Date.now() / 1000);
|
|
27
|
+
const currentMaxLifetime = now + ASSET_KEY_MAX_LIFETIME;
|
|
28
|
+
validateTimestamp('expiresAt', expiresAt, { maximum: currentMaxLifetime, now });
|
|
29
|
+
const postParams = { expiresAt };
|
|
30
|
+
return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/asset_keys`, postParams);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.ValidationError = ValidationError;
|
|
34
|
+
exports.create = create;
|