contentful-management 11.58.0-canary.1 → 11.58.0-canary.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.
@@ -13,7 +13,11 @@ import { getUploadHttpClient } from '../../../upload-http-client';
13
13
  import * as raw from './raw';
14
14
  import { create as createUpload } from './upload';
15
15
  import { normalizeSelect } from './utils';
16
+ import * as releaseAsset from './release-asset';
16
17
  export const get = (http, params, rawData, headers) => {
18
+ if (params.releaseId) {
19
+ return releaseAsset.get(http, params);
20
+ }
17
21
  return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}`, {
18
22
  params: normalizeSelect(params.query),
19
23
  headers: headers ? _objectSpread({}, headers) : undefined
@@ -26,6 +30,9 @@ export const getPublished = (http, params, rawData, headers) => {
26
30
  });
27
31
  };
28
32
  export const getMany = (http, params, rawData, headers) => {
33
+ if (params.releaseId) {
34
+ return releaseAsset.getMany(http, params);
35
+ }
29
36
  return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets`, {
30
37
  params: normalizeSelect(params.query),
31
38
  headers: headers ? _objectSpread({}, headers) : undefined
@@ -33,6 +40,9 @@ export const getMany = (http, params, rawData, headers) => {
33
40
  };
34
41
  export const update = (http, params, rawData, headers) => {
35
42
  var _rawData$sys$version;
43
+ if (params.releaseId) {
44
+ return releaseAsset.update(http, params, rawData, headers !== null && headers !== void 0 ? headers : {});
45
+ }
36
46
  const data = copy(rawData);
37
47
  delete data.sys;
38
48
  return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}`, data, {
@@ -85,14 +95,23 @@ export const unarchive = (http, params) => {
85
95
  return raw.del(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}/archived`);
86
96
  };
87
97
  export const create = (http, params, rawData) => {
98
+ if (params.releaseId) {
99
+ return releaseAsset.create(http, params, rawData, {});
100
+ }
88
101
  const data = copy(rawData);
89
102
  return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets`, data);
90
103
  };
91
104
  export const createWithId = (http, params, rawData) => {
105
+ if (params.releaseId) {
106
+ return releaseAsset.createWithId(http, params, rawData, {});
107
+ }
92
108
  const data = copy(rawData);
93
109
  return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${params.assetId}`, data);
94
110
  };
95
111
  export const createFromFiles = async (http, params, data) => {
112
+ if (params.releaseId) {
113
+ return releaseAsset.createFromFiles(http, params, data, {});
114
+ }
96
115
  const httpUpload = getUploadHttpClient(http, {
97
116
  uploadTimeout: params.uploadTimeout
98
117
  });
@@ -175,6 +194,16 @@ export const processForLocale = async (http, _ref) => {
175
194
  } = {}
176
195
  } = _ref,
177
196
  params = _objectWithoutProperties(_ref, _excluded);
197
+ if (asset.sys.release) {
198
+ return releaseAsset.processForLocale(http, _objectSpread({
199
+ asset: asset,
200
+ locale,
201
+ options: {
202
+ processingCheckRetries,
203
+ processingCheckWait
204
+ }
205
+ }, params));
206
+ }
178
207
  return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/assets/${asset.sys.id}/files/${locale}/process`, null, {
179
208
  headers: {
180
209
  'X-Contentful-Version': asset.sys.version
@@ -199,6 +228,12 @@ export const processForAllLocales = async (http, _ref2) => {
199
228
  options = {}
200
229
  } = _ref2,
201
230
  params = _objectWithoutProperties(_ref2, _excluded2);
231
+ if (asset.sys.release) {
232
+ return releaseAsset.processForAllLocales(http, _objectSpread({
233
+ asset: asset,
234
+ options
235
+ }, params));
236
+ }
202
237
  const locales = Object.keys(asset.fields.file || {});
203
238
  let mostUpToDateAssetVersion = asset;
204
239
 
@@ -10,9 +10,7 @@ import { normalizeSelect } from './utils';
10
10
  import * as releaseEntry from './release-entry';
11
11
  export const get = (http, params, rawData, headers) => {
12
12
  if (params.releaseId) {
13
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
14
- 'release[lte]': params.releaseId
15
- });
13
+ return releaseEntry.get(http, params);
16
14
  }
17
15
  return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`, {
18
16
  params: normalizeSelect(params.query),
@@ -27,9 +25,7 @@ export const getPublished = (http, params, rawData, headers) => {
27
25
  };
28
26
  export const getMany = (http, params, rawData, headers) => {
29
27
  if (params.releaseId) {
30
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
31
- 'release[lte]': params.releaseId
32
- });
28
+ return releaseEntry.getMany(http, params);
33
29
  }
34
30
  return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries`, {
35
31
  params: normalizeSelect(params.query),
@@ -39,6 +39,7 @@ import * as OAuthApplication from './oauth-application';
39
39
  import * as PersonalAccessToken from './personal-access-token';
40
40
  import * as PreviewApiKey from './preview-api-key';
41
41
  import * as Release from './release';
42
+ import * as ReleaseAsset from './release-asset';
42
43
  import * as ReleaseEntry from './release-entry';
43
44
  import * as ReleaseAction from './release-action';
44
45
  import * as Resource from './resource';
@@ -107,6 +108,7 @@ export default {
107
108
  AccessToken,
108
109
  PreviewApiKey,
109
110
  Release,
111
+ ReleaseAsset,
110
112
  ReleaseEntry,
111
113
  ReleaseAction,
112
114
  Resource,
@@ -0,0 +1,179 @@
1
+ const _excluded = ["asset", "locale", "options"],
2
+ _excluded2 = ["asset", "options"];
3
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
4
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
5
+ 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; }
6
+ 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; }
7
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
9
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
+ import { errorHandler } from 'contentful-sdk-core';
11
+ import copy from 'fast-copy';
12
+ import * as raw from './raw';
13
+ import { getUploadHttpClient } from '../../../upload-http-client';
14
+ import { create as createUpload } from './upload';
15
+ import { normalizeSelect } from './utils';
16
+ export const get = (http, params, rawData, headers) => {
17
+ return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/assets/${params.assetId}`, {
18
+ params: normalizeSelect(params.query),
19
+ headers: headers ? _objectSpread({}, headers) : undefined
20
+ });
21
+ };
22
+ export const getMany = (http, params, rawData, headers) => {
23
+ params.query = _objectSpread(_objectSpread({}, params.query), {}, {
24
+ 'sys.schemaVersion': 'Release.V2'
25
+ });
26
+ return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/assets`, {
27
+ params: normalizeSelect(params.query),
28
+ headers: headers ? _objectSpread({}, headers) : undefined
29
+ });
30
+ };
31
+ export const update = (http, params, rawData, headers) => {
32
+ var _rawData$sys$version;
33
+ const data = copy(rawData);
34
+ delete data.sys;
35
+ return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/assets/${params.assetId}`, data, {
36
+ headers: _objectSpread({
37
+ 'X-Contentful-Version': (_rawData$sys$version = rawData.sys.version) !== null && _rawData$sys$version !== void 0 ? _rawData$sys$version : 0
38
+ }, headers)
39
+ });
40
+ };
41
+ export const create = (http, params, rawData, headers) => {
42
+ const data = copy(rawData);
43
+ return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/assets`, data, {
44
+ headers
45
+ });
46
+ };
47
+ export const createWithId = (http, params, rawData, headers) => {
48
+ const data = copy(rawData);
49
+ return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/assets/${params.assetId}`, data, {
50
+ headers
51
+ });
52
+ };
53
+ export const createFromFiles = async (http, params, data) => {
54
+ const httpUpload = getUploadHttpClient(http, {
55
+ uploadTimeout: params.uploadTimeout
56
+ });
57
+ const {
58
+ file
59
+ } = data.fields;
60
+ return Promise.all(Object.keys(file).map(async locale => {
61
+ const {
62
+ contentType,
63
+ fileName
64
+ } = file[locale];
65
+ return createUpload(httpUpload, params, file[locale]).then(upload => {
66
+ return {
67
+ [locale]: {
68
+ contentType,
69
+ fileName,
70
+ uploadFrom: {
71
+ sys: {
72
+ type: 'Link',
73
+ linkType: 'Upload',
74
+ id: upload.sys.id
75
+ }
76
+ }
77
+ }
78
+ };
79
+ });
80
+ })).then(uploads => {
81
+ const file = uploads.reduce((fieldsData, upload) => _objectSpread(_objectSpread({}, fieldsData), upload), {});
82
+ const asset = _objectSpread(_objectSpread({}, data), {}, {
83
+ fields: _objectSpread(_objectSpread({}, data.fields), {}, {
84
+ file
85
+ })
86
+ });
87
+ return create(http, params, asset, {});
88
+ }).catch(errorHandler);
89
+ };
90
+
91
+ /**
92
+ * Asset processing
93
+ */
94
+
95
+ const ASSET_PROCESSING_CHECK_WAIT = 3000;
96
+ const ASSET_PROCESSING_CHECK_RETRIES = 10;
97
+ async function checkIfAssetHasUrl(http, params, {
98
+ resolve,
99
+ reject,
100
+ locale,
101
+ processingCheckWait = ASSET_PROCESSING_CHECK_WAIT,
102
+ processingCheckRetries = ASSET_PROCESSING_CHECK_RETRIES,
103
+ checkCount = 0
104
+ }) {
105
+ return get(http, params).then(asset => {
106
+ if (asset.fields.file[locale].url) {
107
+ resolve(asset);
108
+ } else if (checkCount === processingCheckRetries) {
109
+ const error = new Error();
110
+ error.name = 'AssetProcessingTimeout';
111
+ error.message = 'Asset is taking longer then expected to process.';
112
+ reject(error);
113
+ } else {
114
+ checkCount++;
115
+ setTimeout(() => checkIfAssetHasUrl(http, params, {
116
+ resolve: resolve,
117
+ reject: reject,
118
+ locale: locale,
119
+ checkCount: checkCount,
120
+ processingCheckWait,
121
+ processingCheckRetries
122
+ }), processingCheckWait);
123
+ }
124
+ });
125
+ }
126
+ export const processForLocale = async (http, _ref) => {
127
+ let {
128
+ asset,
129
+ locale,
130
+ options: {
131
+ processingCheckRetries,
132
+ processingCheckWait
133
+ } = {}
134
+ } = _ref,
135
+ params = _objectWithoutProperties(_ref, _excluded);
136
+ return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${asset.sys.release.sys.id}/assets/${asset.sys.id}/files/${locale}/process`, null, {
137
+ headers: {
138
+ 'X-Contentful-Version': asset.sys.version
139
+ }
140
+ }).then(() => {
141
+ return new Promise((resolve, reject) => checkIfAssetHasUrl(http, {
142
+ spaceId: params.spaceId,
143
+ environmentId: params.environmentId,
144
+ assetId: asset.sys.id,
145
+ releaseId: asset.sys.release.sys.id
146
+ }, {
147
+ resolve,
148
+ reject,
149
+ locale,
150
+ processingCheckWait,
151
+ processingCheckRetries
152
+ }));
153
+ });
154
+ };
155
+ export const processForAllLocales = async (http, _ref2) => {
156
+ let {
157
+ asset,
158
+ options = {}
159
+ } = _ref2,
160
+ params = _objectWithoutProperties(_ref2, _excluded2);
161
+ const locales = Object.keys(asset.fields.file || {});
162
+ let mostUpToDateAssetVersion = asset;
163
+
164
+ // Let all the locales process
165
+ // Since they all resolve at different times,
166
+ // we need to pick the last resolved value
167
+ // to reflect the most recent state
168
+ const allProcessingLocales = locales.map(locale => processForLocale(http, _objectSpread(_objectSpread({}, params), {}, {
169
+ asset,
170
+ locale,
171
+ options
172
+ })).then(result => {
173
+ // Side effect of always setting the most up to date asset version
174
+ // The last one to call this will be the last one that finished
175
+ // and thus the most up to date
176
+ mostUpToDateAssetVersion = result;
177
+ }));
178
+ return Promise.all(allProcessingLocales).then(() => mostUpToDateAssetVersion);
179
+ };
@@ -5,21 +5,21 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
5
5
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
6
  import copy from 'fast-copy';
7
7
  import * as raw from './raw';
8
- export const get = (http, params) => {
9
- //TODO: not fully implemented yet, only the get method
10
- return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`);
8
+ import { normalizeSelect } from './utils';
9
+ export const get = (http, params, rawData, headers) => {
10
+ return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`, {
11
+ params: normalizeSelect(params.query),
12
+ headers: _objectSpread({}, headers)
13
+ });
11
14
  };
12
- export const getMany = (http, params) => {
13
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
14
- 'sys.schemaVersion': 'Release.V2'
15
+ export const getMany = (http, params, rawData, headers) => {
16
+ return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries`, {
17
+ params: normalizeSelect(params.query),
18
+ headers: _objectSpread({}, headers)
15
19
  });
16
- return raw.get(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries`);
17
20
  };
18
21
  export const update = (http, params, rawData, headers) => {
19
22
  var _rawData$sys$version;
20
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
21
- 'sys.schemaVersion': 'Release.V2'
22
- });
23
23
  const data = copy(rawData);
24
24
  delete data.sys;
25
25
  return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`, data, {
@@ -29,9 +29,6 @@ export const update = (http, params, rawData, headers) => {
29
29
  });
30
30
  };
31
31
  export const patch = (http, params, data, headers) => {
32
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
33
- 'sys.schemaVersion': 'Release.V2'
34
- });
35
32
  return raw.patch(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`, data, {
36
33
  headers: _objectSpread({
37
34
  'X-Contentful-Version': params.version,
@@ -40,9 +37,6 @@ export const patch = (http, params, data, headers) => {
40
37
  });
41
38
  };
42
39
  export const create = (http, params, rawData, headers) => {
43
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
44
- 'sys.schemaVersion': 'Release.V2'
45
- });
46
40
  const data = copy(rawData);
47
41
  return raw.post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries`, data, {
48
42
  headers: _objectSpread({
@@ -51,9 +45,6 @@ export const create = (http, params, rawData, headers) => {
51
45
  });
52
46
  };
53
47
  export const createWithId = (http, params, rawData, headers) => {
54
- params.query = _objectSpread(_objectSpread({}, params.query), {}, {
55
- 'sys.schemaVersion': 'Release.V2'
56
- });
57
48
  const data = copy(rawData);
58
49
  return raw.put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/releases/${params.releaseId}/entries/${params.entryId}`, data, {
59
50
  headers: _objectSpread({
@@ -47,7 +47,7 @@ function createClient(params, opts = {}) {
47
47
  const sdkMain = opts.type === 'plain' ? 'contentful-management-plain.js' : 'contentful-management.js';
48
48
  const userAgent = getUserAgentHeader(
49
49
  // @ts-expect-error
50
- `${sdkMain}/${"11.58.0-canary.1"}`, params.application, params.integration, params.feature);
50
+ `${sdkMain}/${"11.58.0-canary.2"}`, params.application, params.integration, params.feature);
51
51
  const adapter = createAdapter(_objectSpread(_objectSpread({}, params), {}, {
52
52
  userAgent
53
53
  }));
@@ -346,6 +346,31 @@ export const createPlainClient = (makeRequest, defaults) => {
346
346
  getManyForOrganization: wrap(wrapParams, 'Usage', 'getManyForOrganization')
347
347
  },
348
348
  release: {
349
+ asset: {
350
+ get: wrap(wrapParams, 'ReleaseAsset', 'get'),
351
+ getMany: wrap(wrapParams, 'ReleaseAsset', 'getMany'),
352
+ update: wrap(wrapParams, 'ReleaseAsset', 'update'),
353
+ create: wrap(wrapParams, 'ReleaseAsset', 'create'),
354
+ createWithId: wrap(wrapParams, 'ReleaseAsset', 'createWithId'),
355
+ createFromFiles: wrap(wrapParams, 'ReleaseAsset', 'createFromFiles'),
356
+ processForAllLocales: (params, asset, options) => makeRequest({
357
+ entityType: 'ReleaseAsset',
358
+ action: 'processForAllLocales',
359
+ params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {
360
+ options,
361
+ asset
362
+ })
363
+ }),
364
+ processForLocale: (params, asset, locale, options) => makeRequest({
365
+ entityType: 'ReleaseAsset',
366
+ action: 'processForLocale',
367
+ params: _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, defaults), params)), {}, {
368
+ locale,
369
+ asset,
370
+ options
371
+ })
372
+ })
373
+ },
349
374
  entry: {
350
375
  get: wrap(wrapParams, 'ReleaseEntry', 'get'),
351
376
  getMany: wrap(wrapParams, 'ReleaseEntry', 'getMany'),
@@ -39,6 +39,7 @@ import * as OAuthApplication from './oauth-application';
39
39
  import * as PersonalAccessToken from './personal-access-token';
40
40
  import * as PreviewApiKey from './preview-api-key';
41
41
  import * as Release from './release';
42
+ import * as ReleaseAsset from './release-asset';
42
43
  import * as ReleaseEntry from './release-entry';
43
44
  import * as ReleaseAction from './release-action';
44
45
  import * as Resource from './resource';
@@ -107,6 +108,7 @@ declare const _default: {
107
108
  AccessToken: typeof AccessToken;
108
109
  PreviewApiKey: typeof PreviewApiKey;
109
110
  Release: typeof Release;
111
+ ReleaseAsset: typeof ReleaseAsset;
110
112
  ReleaseEntry: typeof ReleaseEntry;
111
113
  ReleaseAction: typeof ReleaseAction;
112
114
  Resource: typeof Resource;
@@ -0,0 +1,9 @@
1
+ import type { RestEndpoint } from '../types';
2
+ export declare const get: RestEndpoint<'ReleaseAsset', 'get'>;
3
+ export declare const getMany: RestEndpoint<'ReleaseAsset', 'getMany'>;
4
+ export declare const update: RestEndpoint<'ReleaseAsset', 'update'>;
5
+ export declare const create: RestEndpoint<'ReleaseAsset', 'create'>;
6
+ export declare const createWithId: RestEndpoint<'ReleaseAsset', 'createWithId'>;
7
+ export declare const createFromFiles: RestEndpoint<'ReleaseAsset', 'createFromFiles'>;
8
+ export declare const processForLocale: RestEndpoint<'ReleaseAsset', 'processForLocale'>;
9
+ export declare const processForAllLocales: RestEndpoint<'ReleaseAsset', 'processForAllLocales'>;