@datocms/cma-client 5.8.1 → 6.1.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/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/resources/Upload.js +139 -0
- package/dist/cjs/resources/Upload.js.map +1 -1
- package/dist/cjs/utilities/defaultFieldMetadata.js +130 -0
- package/dist/cjs/utilities/defaultFieldMetadata.js.map +1 -0
- package/dist/cjs/utilities/environmentSettings.js +65 -0
- package/dist/cjs/utilities/environmentSettings.js.map +1 -0
- package/dist/esm/generated/Client.js +25 -23
- package/dist/esm/generated/Client.js.map +1 -1
- package/dist/esm/generated/resources/BuildEvent.js +5 -44
- package/dist/esm/generated/resources/BuildEvent.js.map +1 -1
- package/dist/esm/generated/resources/Item.js +5 -44
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.js +5 -44
- package/dist/esm/generated/resources/ItemVersion.js.map +1 -1
- package/dist/esm/generated/resources/SearchIndexEvent.js +5 -44
- package/dist/esm/generated/resources/SearchIndexEvent.js.map +1 -1
- package/dist/esm/generated/resources/SearchResult.js +5 -44
- package/dist/esm/generated/resources/SearchResult.js.map +1 -1
- package/dist/esm/generated/resources/Upload.js +5 -44
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/generated/resources/UploadSmartTag.js +5 -44
- package/dist/esm/generated/resources/UploadSmartTag.js.map +1 -1
- package/dist/esm/generated/resources/UploadTag.js +5 -44
- package/dist/esm/generated/resources/UploadTag.js.map +1 -1
- package/dist/esm/generated/resources/WebhookCall.js +5 -44
- package/dist/esm/generated/resources/WebhookCall.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/resources/Role.js +23 -25
- package/dist/esm/resources/Role.js.map +1 -1
- package/dist/esm/resources/Upload.d.ts +53 -40
- package/dist/esm/resources/Upload.js +68 -0
- package/dist/esm/resources/Upload.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.js +4 -1
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/defaultFieldMetadata.d.ts +84 -0
- package/dist/esm/utilities/defaultFieldMetadata.js +113 -0
- package/dist/esm/utilities/defaultFieldMetadata.js.map +1 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +25 -47
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -1
- package/dist/esm/utilities/environmentSettings.d.ts +35 -0
- package/dist/esm/utilities/environmentSettings.js +49 -0
- package/dist/esm/utilities/environmentSettings.js.map +1 -0
- package/dist/esm/utilities/inspectItem.js +1 -12
- package/dist/esm/utilities/inspectItem.js.map +1 -1
- package/dist/esm/utilities/nonRecursiveBlocks.js +109 -260
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/normalizedFieldValues.js +30 -53
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -1
- package/dist/esm/utilities/recursiveBlocks.js +108 -131
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.js +266 -333
- package/dist/esm/utilities/schemaRepository.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/resources/Upload.d.ts +53 -40
- package/dist/types/utilities/defaultFieldMetadata.d.ts +84 -0
- package/dist/types/utilities/environmentSettings.d.ts +35 -0
- package/package.json +3 -3
- package/src/generated/Client.ts +1 -1
- package/src/index.ts +1 -1
- package/src/resources/Upload.ts +87 -31
- package/src/utilities/defaultFieldMetadata.ts +193 -0
- package/src/utilities/environmentSettings.ts +80 -0
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import BaseRole from '../generated/resources/Role.js';
|
|
11
2
|
function sameValue(a, b) {
|
|
12
3
|
if ((a === undefined || a === null) && (b === undefined || b === null)) {
|
|
@@ -33,7 +24,10 @@ function applyChanges(currentRules, changes, currentEnvironmentId, context) {
|
|
|
33
24
|
return [
|
|
34
25
|
...(rulesToRemove
|
|
35
26
|
? rulesToRemove.reduce((filteredRules, ruleToRemove) => {
|
|
36
|
-
const ruleToRemoveWithEnvironmentId =
|
|
27
|
+
const ruleToRemoveWithEnvironmentId = {
|
|
28
|
+
...ruleToRemove,
|
|
29
|
+
environment: currentEnvironmentId,
|
|
30
|
+
};
|
|
37
31
|
const foundRule = filteredRules.find((rule) => sameRule(rule, ruleToRemoveWithEnvironmentId));
|
|
38
32
|
if (!foundRule) {
|
|
39
33
|
throw new Error(`Cannot find rule ${JSON.stringify(ruleToRemoveWithEnvironmentId)} to remove in ${context}!`);
|
|
@@ -42,7 +36,10 @@ function applyChanges(currentRules, changes, currentEnvironmentId, context) {
|
|
|
42
36
|
}, currentRules)
|
|
43
37
|
: currentRules),
|
|
44
38
|
...(rulesToAdd
|
|
45
|
-
? rulesToAdd.map((change) => (
|
|
39
|
+
? rulesToAdd.map((change) => ({
|
|
40
|
+
environment: currentEnvironmentId,
|
|
41
|
+
...change,
|
|
42
|
+
}))
|
|
46
43
|
: []),
|
|
47
44
|
];
|
|
48
45
|
}
|
|
@@ -52,28 +49,29 @@ export default class RoleResource extends BaseRole {
|
|
|
52
49
|
*
|
|
53
50
|
* Read more: https://www.datocms.com/docs/content-management-api/resources/role/update
|
|
54
51
|
*/
|
|
55
|
-
updateCurrentEnvironmentPermissions(roleId, changes) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
async updateCurrentEnvironmentPermissions(roleId, changes) {
|
|
53
|
+
const currentEnvironmentId = this.client.config.environment ||
|
|
54
|
+
(await this.client.environments.list()).find((environment) => environment.meta.primary).id;
|
|
55
|
+
const role = await this.find(roleId);
|
|
56
|
+
const updateItemTypePermissions = Boolean(changes.positive_item_type_permissions ||
|
|
57
|
+
changes.negative_item_type_permissions);
|
|
58
|
+
const updateUploadPermissions = Boolean(changes.positive_upload_permissions ||
|
|
59
|
+
changes.negative_upload_permissions);
|
|
60
|
+
const body = {
|
|
61
|
+
...(updateItemTypePermissions
|
|
65
62
|
? {
|
|
66
63
|
positive_item_type_permissions: applyChanges(role.positive_item_type_permissions, changes.positive_item_type_permissions, currentEnvironmentId, 'positive_item_type_permissions'),
|
|
67
64
|
negative_item_type_permissions: applyChanges(role.negative_item_type_permissions, changes.negative_item_type_permissions, currentEnvironmentId, 'negative_item_type_permissions'),
|
|
68
65
|
}
|
|
69
|
-
: {})
|
|
66
|
+
: {}),
|
|
67
|
+
...(updateUploadPermissions
|
|
70
68
|
? {
|
|
71
69
|
positive_upload_permissions: applyChanges(role.positive_upload_permissions, changes.positive_upload_permissions, currentEnvironmentId, 'positive_upload_permissions'),
|
|
72
70
|
negative_upload_permissions: applyChanges(role.negative_upload_permissions, changes.negative_upload_permissions, currentEnvironmentId, 'negative_upload_permissions'),
|
|
73
71
|
}
|
|
74
|
-
: {})
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
: {}),
|
|
73
|
+
};
|
|
74
|
+
return this.update(roleId, body);
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
//# sourceMappingURL=Role.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Role.js","sourceRoot":"","sources":["../../../src/resources/Role.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"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AI,GAA8B;YACtC,GAAG,CAAC,yBAAyB;gBAC3B,CAAC,CAAC;oBACE,8BAA8B,EAAE,YAAY,CAC1C,IAAI,CAAC,8BAA8B,EACnC,OAAO,CAAC,8BAA8B,EACtC,oBAAoB,EACpB,gCAAgC,CACjC;oBACD,8BAA8B,EAAE,YAAY,CAC1C,IAAI,CAAC,8BAA8B,EACnC,OAAO,CAAC,8BAA8B,EACtC,oBAAoB,EACpB,gCAAgC,CACjC;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,uBAAuB;gBACzB,CAAC,CAAC;oBACE,2BAA2B,EAAE,YAAY,CACvC,IAAI,CAAC,2BAA2B,EAChC,OAAO,CAAC,2BAA2B,EACnC,oBAAoB,EACpB,6BAA6B,CAC9B;oBACD,2BAA2B,EAAE,YAAY,CACvC,IAAI,CAAC,2BAA2B,EAChC,OAAO,CAAC,2BAA2B,EACnC,oBAAoB,EACpB,6BAA6B,CAC9B;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -1,46 +1,59 @@
|
|
|
1
|
+
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
1
2
|
import BaseUpload from '../generated/resources/Upload.js';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* `default_field_metadata` travels in one of two shapes, and which one an
|
|
5
|
+
* environment speaks depends on the `non_localized_focal_points` opt-in — each
|
|
6
|
+
* rejects the other with `422 INVALID_FORMAT`. This resource hides that: you
|
|
7
|
+
* always read and write the field-keyed shape the types describe, and the
|
|
8
|
+
* legacy one is converted to and from as needed.
|
|
6
9
|
*
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
* targeting opted-out environments during the transition can cast the
|
|
10
|
-
* response value to a structurally accurate shape.
|
|
10
|
+
* The raw methods are deliberately left alone: they are the escape hatch for
|
|
11
|
+
* anyone who needs to see what actually goes over the wire.
|
|
11
12
|
*/
|
|
12
|
-
export type UploadLocaleKeyedDefaultFieldMetadata = {
|
|
13
|
-
[localeCode: string]: {
|
|
14
|
-
alt: string | null;
|
|
15
|
-
title: string | null;
|
|
16
|
-
custom_data: {
|
|
17
|
-
[k: string]: unknown;
|
|
18
|
-
};
|
|
19
|
-
focal_point: {
|
|
20
|
-
x: number;
|
|
21
|
-
y: number;
|
|
22
|
-
} | null;
|
|
23
|
-
poster_time: number | null;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Legacy locale-keyed shape accepted on `create` / `update` request bodies
|
|
28
|
-
* by environments where the `non_localized_focal_points` opt-in is inactive.
|
|
29
|
-
* All fields are optional, matching the partial-write contract.
|
|
30
|
-
*/
|
|
31
|
-
export type UploadLocaleKeyedDefaultFieldMetadataInRequest = {
|
|
32
|
-
[localeCode: string]: {
|
|
33
|
-
alt?: string | null;
|
|
34
|
-
title?: string | null;
|
|
35
|
-
custom_data?: {
|
|
36
|
-
[k: string]: unknown;
|
|
37
|
-
};
|
|
38
|
-
focal_point?: {
|
|
39
|
-
x: number;
|
|
40
|
-
y: number;
|
|
41
|
-
} | null;
|
|
42
|
-
poster_time?: number | null;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
13
|
export default class UploadResource extends BaseUpload {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new upload
|
|
16
|
+
*
|
|
17
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/create
|
|
18
|
+
*
|
|
19
|
+
* @throws {ApiError}
|
|
20
|
+
* @throws {TimeoutError}
|
|
21
|
+
*/
|
|
22
|
+
create(body: ApiTypes.UploadCreateSchema): Promise<ApiTypes.Upload>;
|
|
23
|
+
/**
|
|
24
|
+
* Update an upload
|
|
25
|
+
*
|
|
26
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/update
|
|
27
|
+
*
|
|
28
|
+
* @throws {ApiError}
|
|
29
|
+
* @throws {TimeoutError}
|
|
30
|
+
*/
|
|
31
|
+
update(uploadId: string | ApiTypes.UploadData, body: ApiTypes.UploadUpdateSchema, queryParams?: ApiTypes.UploadUpdateHrefSchema): Promise<ApiTypes.Upload>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve an upload
|
|
34
|
+
*
|
|
35
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/self
|
|
36
|
+
*
|
|
37
|
+
* @throws {ApiError}
|
|
38
|
+
* @throws {TimeoutError}
|
|
39
|
+
*/
|
|
40
|
+
find(uploadId: string | ApiTypes.UploadData): Promise<ApiTypes.Upload>;
|
|
41
|
+
/**
|
|
42
|
+
* List all uploads
|
|
43
|
+
*
|
|
44
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances
|
|
45
|
+
*
|
|
46
|
+
* @throws {ApiError}
|
|
47
|
+
* @throws {TimeoutError}
|
|
48
|
+
*/
|
|
49
|
+
list(queryParams?: ApiTypes.UploadInstancesHrefSchema): Promise<ApiTypes.Upload[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Async iterator to auto-paginate over elements returned by list()
|
|
52
|
+
*
|
|
53
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances
|
|
54
|
+
*
|
|
55
|
+
* @throws {ApiError}
|
|
56
|
+
* @throws {TimeoutError}
|
|
57
|
+
*/
|
|
58
|
+
listPagedIterator(...args: Parameters<BaseUpload['listPagedIterator']>): AsyncGenerator<ApiTypes.Upload, void, unknown>;
|
|
46
59
|
}
|
|
@@ -1,4 +1,72 @@
|
|
|
1
1
|
import BaseUpload from '../generated/resources/Upload.js';
|
|
2
|
+
import { encodeDefaultFieldMetadata, normalizeUpload, } from '../utilities/defaultFieldMetadata.js';
|
|
3
|
+
/**
|
|
4
|
+
* `default_field_metadata` travels in one of two shapes, and which one an
|
|
5
|
+
* environment speaks depends on the `non_localized_focal_points` opt-in — each
|
|
6
|
+
* rejects the other with `422 INVALID_FORMAT`. This resource hides that: you
|
|
7
|
+
* always read and write the field-keyed shape the types describe, and the
|
|
8
|
+
* legacy one is converted to and from as needed.
|
|
9
|
+
*
|
|
10
|
+
* The raw methods are deliberately left alone: they are the escape hatch for
|
|
11
|
+
* anyone who needs to see what actually goes over the wire.
|
|
12
|
+
*/
|
|
2
13
|
export default class UploadResource extends BaseUpload {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new upload
|
|
16
|
+
*
|
|
17
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/create
|
|
18
|
+
*
|
|
19
|
+
* @throws {ApiError}
|
|
20
|
+
* @throws {TimeoutError}
|
|
21
|
+
*/
|
|
22
|
+
async create(body) {
|
|
23
|
+
return normalizeUpload(await super.create(await encodeDefaultFieldMetadata(this.client, body)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Update an upload
|
|
27
|
+
*
|
|
28
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/update
|
|
29
|
+
*
|
|
30
|
+
* @throws {ApiError}
|
|
31
|
+
* @throws {TimeoutError}
|
|
32
|
+
*/
|
|
33
|
+
async update(uploadId, body, queryParams) {
|
|
34
|
+
return normalizeUpload(await super.update(uploadId, await encodeDefaultFieldMetadata(this.client, body), queryParams));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve an upload
|
|
38
|
+
*
|
|
39
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/self
|
|
40
|
+
*
|
|
41
|
+
* @throws {ApiError}
|
|
42
|
+
* @throws {TimeoutError}
|
|
43
|
+
*/
|
|
44
|
+
async find(uploadId) {
|
|
45
|
+
return normalizeUpload(await super.find(uploadId));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* List all uploads
|
|
49
|
+
*
|
|
50
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances
|
|
51
|
+
*
|
|
52
|
+
* @throws {ApiError}
|
|
53
|
+
* @throws {TimeoutError}
|
|
54
|
+
*/
|
|
55
|
+
async list(queryParams) {
|
|
56
|
+
return (await super.list(queryParams)).map(normalizeUpload);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Async iterator to auto-paginate over elements returned by list()
|
|
60
|
+
*
|
|
61
|
+
* Read more: https://www.datocms.com/docs/content-management-api/resources/upload/instances
|
|
62
|
+
*
|
|
63
|
+
* @throws {ApiError}
|
|
64
|
+
* @throws {TimeoutError}
|
|
65
|
+
*/
|
|
66
|
+
async *listPagedIterator(...args) {
|
|
67
|
+
for await (const upload of super.listPagedIterator(...args)) {
|
|
68
|
+
yield normalizeUpload(upload);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
3
71
|
}
|
|
4
72
|
//# sourceMappingURL=Upload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Upload.js","sourceRoot":"","sources":["../../../src/resources/Upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Upload.js","sourceRoot":"","sources":["../../../src/resources/Upload.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EACL,0BAA0B,EAC1B,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU;IACpD;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,IAAiC;QAC5C,OAAO,eAAe,CACpB,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,0BAA0B,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,QAAsC,EACtC,IAAiC,EACjC,WAA6C;QAE7C,OAAO,eAAe,CACpB,MAAM,KAAK,CAAC,MAAM,CAChB,QAAQ,EACR,MAAM,0BAA0B,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EACnD,WAAW,CACZ,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,QAAsC;QAC/C,OAAO,eAAe,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,WAAgD;QACzD,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,iBAAiB,CACtB,GAAG,IAAiD;QAEpD,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,EAAE;YAC3D,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC;SAC/B;IACH,CAAC;CACF"}
|
|
@@ -19,6 +19,9 @@ export function buildBlockRecord(body) {
|
|
|
19
19
|
const itemTypeId = (_c = (_a = body.__itemTypeId) !== null && _a !== void 0 ? _a : (_b = body.item_type) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : (_f = (_e = (_d = data.relationships) === null || _d === void 0 ? void 0 : _d.item_type) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.id;
|
|
20
20
|
if (itemTypeId === undefined)
|
|
21
21
|
return data;
|
|
22
|
-
return
|
|
22
|
+
return {
|
|
23
|
+
...data,
|
|
24
|
+
__itemTypeId: itemTypeId,
|
|
25
|
+
};
|
|
23
26
|
}
|
|
24
27
|
//# sourceMappingURL=buildBlockRecord.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBlockRecord.js","sourceRoot":"","sources":["../../../src/utilities/buildBlockRecord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM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IACvE,MAAM,UAAU,GACd,MAAA,MAAA,IAAI,CAAC,YAAY,mCACjB,MAAA,IAAI,CAAC,SAAS,0CAAE,EAAE,mCAClB,MAAA,MAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,SAAS,0CAAE,IAAI,0CAAE,EAAE,CAAC;IAE1C,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAE1C,OAAO;QACL,GAAG,IAAI;QACP,YAAY,EAAE,UAAU;KACQ,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
|
+
import type { Client } from '../generated/Client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Legacy locale-keyed shape of an upload's `default_field_metadata`, as
|
|
5
|
+
* returned and accepted by environments where the `non_localized_focal_points`
|
|
6
|
+
* opt-in is inactive.
|
|
7
|
+
*
|
|
8
|
+
* The `uploads` resource converts to and from this shape on your behalf, so you
|
|
9
|
+
* only ever see the field-keyed one. The type is exported for those working at
|
|
10
|
+
* the raw layer, which performs no conversion.
|
|
11
|
+
*/
|
|
12
|
+
export type UploadLocaleKeyedDefaultFieldMetadata = {
|
|
13
|
+
[localeCode: string]: {
|
|
14
|
+
alt: string | null;
|
|
15
|
+
title: string | null;
|
|
16
|
+
custom_data: {
|
|
17
|
+
[k: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
focal_point: {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
} | null;
|
|
23
|
+
poster_time: number | null;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Legacy locale-keyed shape accepted on `create` / `update` request bodies
|
|
28
|
+
* by environments where the `non_localized_focal_points` opt-in is inactive.
|
|
29
|
+
* All fields are optional, matching the partial-write contract.
|
|
30
|
+
*/
|
|
31
|
+
export type UploadLocaleKeyedDefaultFieldMetadataInRequest = {
|
|
32
|
+
[localeCode: string]: {
|
|
33
|
+
alt?: string | null;
|
|
34
|
+
title?: string | null;
|
|
35
|
+
custom_data?: {
|
|
36
|
+
[k: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
focal_point?: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
} | null;
|
|
42
|
+
poster_time?: number | null;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type DefaultFieldMetadata = ApiTypes.Upload['default_field_metadata'];
|
|
46
|
+
export type DefaultFieldMetadataInRequest = NonNullable<ApiTypes.UploadUpdateSchema['default_field_metadata']>;
|
|
47
|
+
/**
|
|
48
|
+
* Tells the two wire shapes apart. A field-keyed payload always carries a
|
|
49
|
+
* top-level `focal_point`, and a locale-keyed one never can: its keys are
|
|
50
|
+
* locale codes, and no locale code is the literal string `focal_point`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isFieldKeyed(metadata: DefaultFieldMetadata | UploadLocaleKeyedDefaultFieldMetadata): metadata is DefaultFieldMetadata;
|
|
53
|
+
/**
|
|
54
|
+
* Collapses a legacy response payload into the field-keyed shape. The API
|
|
55
|
+
* replicates the non-localized values into every locale entry on read, so every
|
|
56
|
+
* entry carries the same value and the first one is enough.
|
|
57
|
+
*/
|
|
58
|
+
export declare function fromLocaleKeyed(byLocale: UploadLocaleKeyedDefaultFieldMetadata): DefaultFieldMetadata;
|
|
59
|
+
/**
|
|
60
|
+
* Rewrites a field-keyed patch into the legacy locale-keyed one: the localized
|
|
61
|
+
* keys are pivoted per locale, and the non-localized ones ride along on a
|
|
62
|
+
* single entry. The API takes `focal_point` / `poster_time` off the first entry
|
|
63
|
+
* that carries one and ignores the rest, so writing them once is enough — on
|
|
64
|
+
* any locale the patch already touches, or the environment's first one when it
|
|
65
|
+
* touches none.
|
|
66
|
+
*/
|
|
67
|
+
export declare function toLocaleKeyed({ alt, title, custom_data, focal_point, poster_time, }: DefaultFieldMetadataInRequest, environmentLocales: string[]): UploadLocaleKeyedDefaultFieldMetadataInRequest;
|
|
68
|
+
/**
|
|
69
|
+
* Normalizes an upload as served by the API into the field-keyed shape the
|
|
70
|
+
* `Upload` type describes. Returns the entity untouched — no copy — when it is
|
|
71
|
+
* already field-keyed, which is the case for every environment that has taken
|
|
72
|
+
* the opt-in.
|
|
73
|
+
*/
|
|
74
|
+
export declare function normalizeUpload(upload: ApiTypes.Upload): ApiTypes.Upload;
|
|
75
|
+
/**
|
|
76
|
+
* Encodes a `create` / `update` body into the shape the environment accepts.
|
|
77
|
+
*
|
|
78
|
+
* The environment is only consulted when there is metadata to encode, so a
|
|
79
|
+
* client that never writes asset metadata never asks — and when it does ask,
|
|
80
|
+
* the lookup is memoized and shared, so a batch of writes pays for one.
|
|
81
|
+
*/
|
|
82
|
+
export declare function encodeDefaultFieldMetadata<T extends {
|
|
83
|
+
default_field_metadata?: DefaultFieldMetadataInRequest;
|
|
84
|
+
}>(client: Client, body: T): Promise<T>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { fetchEnvironmentSettings, isEnvironmentFlagActive, } from './environmentSettings.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tells the two wire shapes apart. A field-keyed payload always carries a
|
|
4
|
+
* top-level `focal_point`, and a locale-keyed one never can: its keys are
|
|
5
|
+
* locale codes, and no locale code is the literal string `focal_point`.
|
|
6
|
+
*/
|
|
7
|
+
export function isFieldKeyed(metadata) {
|
|
8
|
+
return 'focal_point' in metadata;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Collapses a legacy response payload into the field-keyed shape. The API
|
|
12
|
+
* replicates the non-localized values into every locale entry on read, so every
|
|
13
|
+
* entry carries the same value and the first one is enough.
|
|
14
|
+
*/
|
|
15
|
+
export function fromLocaleKeyed(byLocale) {
|
|
16
|
+
const alt = {};
|
|
17
|
+
const title = {};
|
|
18
|
+
const customData = {};
|
|
19
|
+
let focalPoint = null;
|
|
20
|
+
let posterTime = null;
|
|
21
|
+
let seenAnEntry = false;
|
|
22
|
+
for (const [locale, entry] of Object.entries(byLocale)) {
|
|
23
|
+
alt[locale] = entry.alt;
|
|
24
|
+
title[locale] = entry.title;
|
|
25
|
+
customData[locale] = entry.custom_data;
|
|
26
|
+
if (!seenAnEntry) {
|
|
27
|
+
seenAnEntry = true;
|
|
28
|
+
focalPoint = entry.focal_point;
|
|
29
|
+
posterTime = entry.poster_time;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
alt,
|
|
34
|
+
title,
|
|
35
|
+
custom_data: customData,
|
|
36
|
+
focal_point: focalPoint,
|
|
37
|
+
poster_time: posterTime,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Rewrites a field-keyed patch into the legacy locale-keyed one: the localized
|
|
42
|
+
* keys are pivoted per locale, and the non-localized ones ride along on a
|
|
43
|
+
* single entry. The API takes `focal_point` / `poster_time` off the first entry
|
|
44
|
+
* that carries one and ignores the rest, so writing them once is enough — on
|
|
45
|
+
* any locale the patch already touches, or the environment's first one when it
|
|
46
|
+
* touches none.
|
|
47
|
+
*/
|
|
48
|
+
export function toLocaleKeyed({ alt, title, custom_data, focal_point, poster_time, }, environmentLocales) {
|
|
49
|
+
var _a;
|
|
50
|
+
const result = {};
|
|
51
|
+
function entryFor(locale) {
|
|
52
|
+
var _a;
|
|
53
|
+
const entry = (_a = result[locale]) !== null && _a !== void 0 ? _a : {};
|
|
54
|
+
result[locale] = entry;
|
|
55
|
+
return entry;
|
|
56
|
+
}
|
|
57
|
+
for (const [locale, value] of Object.entries(alt !== null && alt !== void 0 ? alt : {})) {
|
|
58
|
+
entryFor(locale).alt = value;
|
|
59
|
+
}
|
|
60
|
+
for (const [locale, value] of Object.entries(title !== null && title !== void 0 ? title : {})) {
|
|
61
|
+
entryFor(locale).title = value;
|
|
62
|
+
}
|
|
63
|
+
for (const [locale, value] of Object.entries(custom_data !== null && custom_data !== void 0 ? custom_data : {})) {
|
|
64
|
+
entryFor(locale).custom_data = value;
|
|
65
|
+
}
|
|
66
|
+
if (focal_point !== undefined || poster_time !== undefined) {
|
|
67
|
+
const locale = (_a = Object.keys(result)[0]) !== null && _a !== void 0 ? _a : environmentLocales[0];
|
|
68
|
+
if (locale) {
|
|
69
|
+
if (focal_point !== undefined)
|
|
70
|
+
entryFor(locale).focal_point = focal_point;
|
|
71
|
+
if (poster_time !== undefined)
|
|
72
|
+
entryFor(locale).poster_time = poster_time;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Normalizes an upload as served by the API into the field-keyed shape the
|
|
79
|
+
* `Upload` type describes. Returns the entity untouched — no copy — when it is
|
|
80
|
+
* already field-keyed, which is the case for every environment that has taken
|
|
81
|
+
* the opt-in.
|
|
82
|
+
*/
|
|
83
|
+
export function normalizeUpload(upload) {
|
|
84
|
+
const metadata = upload.default_field_metadata;
|
|
85
|
+
if (!metadata || isFieldKeyed(metadata)) {
|
|
86
|
+
return upload;
|
|
87
|
+
}
|
|
88
|
+
return { ...upload, default_field_metadata: fromLocaleKeyed(metadata) };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Encodes a `create` / `update` body into the shape the environment accepts.
|
|
92
|
+
*
|
|
93
|
+
* The environment is only consulted when there is metadata to encode, so a
|
|
94
|
+
* client that never writes asset metadata never asks — and when it does ask,
|
|
95
|
+
* the lookup is memoized and shared, so a batch of writes pays for one.
|
|
96
|
+
*/
|
|
97
|
+
export async function encodeDefaultFieldMetadata(client, body) {
|
|
98
|
+
const metadata = body.default_field_metadata;
|
|
99
|
+
if (!metadata) {
|
|
100
|
+
return body;
|
|
101
|
+
}
|
|
102
|
+
if (await isEnvironmentFlagActive(client, 'non_localized_focal_points')) {
|
|
103
|
+
return body;
|
|
104
|
+
}
|
|
105
|
+
const { locales } = await fetchEnvironmentSettings(client);
|
|
106
|
+
return {
|
|
107
|
+
...body,
|
|
108
|
+
// The declared type describes the field-keyed shape, which is what callers
|
|
109
|
+
// write. The legacy payload is this module's business.
|
|
110
|
+
default_field_metadata: toLocaleKeyed(metadata, locales),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=defaultFieldMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFieldMetadata.js","sourceRoot":"","sources":["../../../src/utilities/defaultFieldMetadata.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AA0ClC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAsE;IAEtE,OAAO,aAAa,IAAI,QAAQ,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,QAA+C;IAE/C,MAAM,GAAG,GAAkC,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAkC,EAAE,CAAC;IAChD,MAAM,UAAU,GAA6C,EAAE,CAAC;IAEhE,IAAI,UAAU,GAAoC,IAAI,CAAC;IACvD,IAAI,UAAU,GAAkB,IAAI,CAAC;IACrC,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACtD,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;QACxB,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QAC5B,UAAU,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC;QAEvC,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI,CAAC;YACnB,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC;YAC/B,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC;SAChC;KACF;IAED,OAAO;QACL,GAAG;QACH,KAAK;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,UAAU;Q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AS;gBAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC;YAC1E,IAAI,WAAW,KAAK,SAAS;gBAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC;SAC3E;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACrD,MAAM,QAAQ,GAAG,MAAM,CAAC,sBAAsB,CAAC;IAE/C,IAAI,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE;QACvC,OAAO,MAAM,CAAC;KACf;IAED,OAAO,EAAE,GAAG,MAAM,EAAE,sBAAsB,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAE9C,MAAc,EAAE,IAAO;IACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC;IAE7C,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,IAAI,CAAC;KACb;IAED,IAAI,MAAM,uBAAuB,CAAC,MAAM,EAAE,4BAA4B,CAAC,EAAE;QACvE,OAAO,IAAI,CAAC;KACb;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAE3D,OAAO;QACL,GAAG,IAAI;QACP,2EAA2E;QAC3E,uDAAuD;QACvD,sBAAsB,EAAE,aAAa,CACnC,QAAQ,EACR,OAAO,CACoC;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -1,50 +1,28 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
-
var t = {};
|
|
12
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
-
t[p] = s[p];
|
|
14
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
-
t[p[i]] = s[p[i]];
|
|
18
|
-
}
|
|
19
|
-
return t;
|
|
20
|
-
};
|
|
21
1
|
import { mapBlocksInNonLocalizedFieldValue } from './recursiveBlocks.js';
|
|
22
|
-
export function duplicateBlockRecord(existingBlock, schemaRepository) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
newBlock.attributes[field.attributes.api_key]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return newBlock;
|
|
48
|
-
});
|
|
2
|
+
export async function duplicateBlockRecord(existingBlock, schemaRepository) {
|
|
3
|
+
const { __itemTypeId, type, attributes, relationships } = existingBlock;
|
|
4
|
+
const itemType = await schemaRepository.getRawItemTypeById(existingBlock.relationships.item_type.data.id);
|
|
5
|
+
const newBlock = {
|
|
6
|
+
__itemTypeId,
|
|
7
|
+
type,
|
|
8
|
+
relationships,
|
|
9
|
+
attributes,
|
|
10
|
+
};
|
|
11
|
+
const fields = await schemaRepository.getRawItemTypeFields(itemType);
|
|
12
|
+
for (const field of fields) {
|
|
13
|
+
newBlock.attributes[field.attributes.api_key] =
|
|
14
|
+
await mapBlocksInNonLocalizedFieldValue(newBlock.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, (block, path) => {
|
|
15
|
+
if (typeof block === 'string') {
|
|
16
|
+
throw new Error(`Block cannot be duplicated as it contains nested block at ${path.join('.')} that is expressed as ID (${block}) instead of full object!`);
|
|
17
|
+
}
|
|
18
|
+
if ('id' in block) {
|
|
19
|
+
const { id, meta, ...blockWithoutIdAndMeta } = block;
|
|
20
|
+
return blockWithoutIdAndMeta;
|
|
21
|
+
}
|
|
22
|
+
const { meta, ...blockWithoutMeta } = block;
|
|
23
|
+
return blockWithoutMeta;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return newBlock;
|
|
49
27
|
}
|
|
50
28
|
//# sourceMappingURL=duplicateBlockRecord.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicateBlockRecord.js","sourceRoot":"","sources":["../../../src/utilities/duplicateBlockRecord.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"duplicateBlockRecord.js","sourceRoot":"","sources":["../../../src/utilities/duplicateBlockRecord.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iCAAiC,EAAE,MAAM,sBAAsB,CAAC;AAKzE,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAGxC,aAAoD,EACpD,gBAAkC;IAQlC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,aAAa,CAAC;IAExE,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,kBAAkB,CACxD,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC9C,CAAC;IAEF,MAAM,QAAQ,GAAG;QACf,YAAY;QACZ,IAAI;QACJ,aAAa;QACb,UAAU;KACU,CAAC;IAEvB,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAErE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;YAC3C,MAAM,iCAAiC,CACrC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAC7C,KAAK,CAAC,UAAU,CAAC,UAAU,EAC3B,gBAAgB,EAChB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;gBACd,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;oBAC7B,MAAM,IAAI,KAAK,CACb,6DAA6D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B,KAAK,2BAA2B,CACzI,CAAC;iBACH;gBAED,IAAI,IAAI,IAAI,KAAK,EAAE;oBACjB,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,qBAAqB,EAAE,GAAG,KAAK,CAAC;oBAErD,OAAO,qBAA0C,CAAC;iBACnD;gBAED,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAAC;gBAC5C,OAAO,gBAAqC,CAAC;YAC/C,CAAC,CACF,CAAC;KACL;IAED,OAAO,QAIE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as ApiTypes from '../generated/ApiTypes.js';
|
|
2
|
+
import type { Client } from '../generated/Client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Every boolean an environment reports about itself in `site.meta`: the
|
|
5
|
+
* product-update opt-ins (`improved_items_listing`, `milliseconds_in_datetime`,
|
|
6
|
+
* `non_localized_focal_points`, …) plus the plain state flags.
|
|
7
|
+
*
|
|
8
|
+
* Derived from the generated type rather than listed, so a flag added to the
|
|
9
|
+
* schema is usable here as soon as the types are regenerated, with nothing to
|
|
10
|
+
* keep in sync.
|
|
11
|
+
*/
|
|
12
|
+
export type EnvironmentFlag = {
|
|
13
|
+
[K in keyof ApiTypes.SiteMeta]-?: boolean extends ApiTypes.SiteMeta[K] ? K : never;
|
|
14
|
+
}[keyof ApiTypes.SiteMeta];
|
|
15
|
+
/**
|
|
16
|
+
* `site.find()`, memoized per client for {@link TTL_MS}.
|
|
17
|
+
*
|
|
18
|
+
* The promise is cached rather than its result, so concurrent callers share one
|
|
19
|
+
* request instead of firing one each — the difference between one lookup and
|
|
20
|
+
* ten thousand when a batch job starts. A failed lookup is not cached.
|
|
21
|
+
*
|
|
22
|
+
* Everything expires on the same clock, including flags that in practice never
|
|
23
|
+
* change back: re-reading `site` every twenty minutes costs nothing next to the
|
|
24
|
+
* work these clients are doing, and it means a client stays correct across an
|
|
25
|
+
* activation that happens while it runs.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fetchEnvironmentSettings(client: Client): Promise<ApiTypes.Site>;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a `site.meta` flag is on for the environment this client talks to.
|
|
30
|
+
*
|
|
31
|
+
* An API predating a flag omits it from the meta entirely, which the types
|
|
32
|
+
* don't admit but runtime does — so anything short of an explicit `true` reads
|
|
33
|
+
* as off.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isEnvironmentFlagActive(client: Client, flag: EnvironmentFlag): Promise<boolean>;
|