@prismicio/e2e-tests-utils 1.18.0 → 1.19.0-canary.d349d21

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.
Files changed (159) hide show
  1. package/README.md +24 -27
  2. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  3. package/dist/clients/apiClient.cjs +38 -38
  4. package/dist/clients/apiClient.cjs.map +1 -1
  5. package/dist/clients/apiClient.d.cts +30 -0
  6. package/dist/clients/apiClient.d.cts.map +1 -0
  7. package/dist/clients/apiClient.d.ts +23 -23
  8. package/dist/clients/apiClient.d.ts.map +1 -0
  9. package/dist/clients/apiClient.js +38 -38
  10. package/dist/clients/apiClient.js.map +1 -1
  11. package/dist/clients/assetApi.cjs +81 -93
  12. package/dist/clients/assetApi.cjs.map +1 -1
  13. package/dist/clients/assetApi.d.cts +105 -0
  14. package/dist/clients/assetApi.d.cts.map +1 -0
  15. package/dist/clients/assetApi.d.ts +96 -97
  16. package/dist/clients/assetApi.d.ts.map +1 -0
  17. package/dist/clients/assetApi.js +79 -91
  18. package/dist/clients/assetApi.js.map +1 -1
  19. package/dist/clients/authenticationApi.cjs +66 -73
  20. package/dist/clients/authenticationApi.cjs.map +1 -1
  21. package/dist/clients/authenticationApi.d.cts +20 -0
  22. package/dist/clients/authenticationApi.d.cts.map +1 -0
  23. package/dist/clients/authenticationApi.d.ts +18 -13
  24. package/dist/clients/authenticationApi.d.ts.map +1 -0
  25. package/dist/clients/authenticationApi.js +65 -72
  26. package/dist/clients/authenticationApi.js.map +1 -1
  27. package/dist/clients/contentApi.cjs +94 -103
  28. package/dist/clients/contentApi.cjs.map +1 -1
  29. package/dist/clients/contentApi.d.cts +116 -0
  30. package/dist/clients/contentApi.d.cts.map +1 -0
  31. package/dist/clients/contentApi.d.ts +102 -98
  32. package/dist/clients/contentApi.d.ts.map +1 -0
  33. package/dist/clients/contentApi.js +94 -103
  34. package/dist/clients/contentApi.js.map +1 -1
  35. package/dist/clients/coreApi.cjs +154 -145
  36. package/dist/clients/coreApi.cjs.map +1 -1
  37. package/dist/clients/coreApi.d.cts +143 -0
  38. package/dist/clients/coreApi.d.cts.map +1 -0
  39. package/dist/clients/coreApi.d.ts +132 -109
  40. package/dist/clients/coreApi.d.ts.map +1 -0
  41. package/dist/clients/coreApi.js +153 -144
  42. package/dist/clients/coreApi.js.map +1 -1
  43. package/dist/clients/customTypesApi.cjs +90 -99
  44. package/dist/clients/customTypesApi.cjs.map +1 -1
  45. package/dist/clients/customTypesApi.d.cts +46 -0
  46. package/dist/clients/customTypesApi.d.cts.map +1 -0
  47. package/dist/clients/customTypesApi.d.ts +45 -45
  48. package/dist/clients/customTypesApi.d.ts.map +1 -0
  49. package/dist/clients/customTypesApi.js +87 -98
  50. package/dist/clients/customTypesApi.js.map +1 -1
  51. package/dist/clients/integrationFields.cjs +96 -87
  52. package/dist/clients/integrationFields.cjs.map +1 -1
  53. package/dist/clients/integrationFields.d.cts +30 -0
  54. package/dist/clients/integrationFields.d.cts.map +1 -0
  55. package/dist/clients/integrationFields.d.ts +27 -22
  56. package/dist/clients/integrationFields.d.ts.map +1 -0
  57. package/dist/clients/integrationFields.js +93 -86
  58. package/dist/clients/integrationFields.js.map +1 -1
  59. package/dist/clients/manageV2.cjs +154 -171
  60. package/dist/clients/manageV2.cjs.map +1 -1
  61. package/dist/clients/manageV2.d.cts +105 -0
  62. package/dist/clients/manageV2.d.cts.map +1 -0
  63. package/dist/clients/manageV2.d.ts +103 -111
  64. package/dist/clients/manageV2.d.ts.map +1 -0
  65. package/dist/clients/manageV2.js +149 -169
  66. package/dist/clients/manageV2.js.map +1 -1
  67. package/dist/clients/migrationApi.cjs +37 -36
  68. package/dist/clients/migrationApi.cjs.map +1 -1
  69. package/dist/clients/migrationApi.d.cts +48 -0
  70. package/dist/clients/migrationApi.d.cts.map +1 -0
  71. package/dist/clients/migrationApi.d.ts +45 -39
  72. package/dist/clients/migrationApi.d.ts.map +1 -0
  73. package/dist/clients/migrationApi.js +35 -34
  74. package/dist/clients/migrationApi.js.map +1 -1
  75. package/dist/clients/wroom.cjs +101 -122
  76. package/dist/clients/wroom.cjs.map +1 -1
  77. package/dist/clients/wroom.d.cts +48 -0
  78. package/dist/clients/wroom.d.cts.map +1 -0
  79. package/dist/clients/wroom.d.ts +46 -47
  80. package/dist/clients/wroom.d.ts.map +1 -0
  81. package/dist/clients/wroom.js +99 -122
  82. package/dist/clients/wroom.js.map +1 -1
  83. package/dist/index.cjs +13 -15
  84. package/dist/index.d.cts +8 -0
  85. package/dist/index.d.ts +8 -7
  86. package/dist/index.js +5 -14
  87. package/dist/managers/repositories.cjs +159 -169
  88. package/dist/managers/repositories.cjs.map +1 -1
  89. package/dist/managers/repositories.d.cts +67 -0
  90. package/dist/managers/repositories.d.cts.map +1 -0
  91. package/dist/managers/repositories.d.ts +56 -63
  92. package/dist/managers/repositories.d.ts.map +1 -0
  93. package/dist/managers/repositories.js +148 -159
  94. package/dist/managers/repositories.js.map +1 -1
  95. package/dist/managers/repository.cjs +595 -616
  96. package/dist/managers/repository.cjs.map +1 -1
  97. package/dist/managers/repository.d.cts +341 -0
  98. package/dist/managers/repository.d.cts.map +1 -0
  99. package/dist/managers/repository.d.ts +336 -307
  100. package/dist/managers/repository.d.ts.map +1 -0
  101. package/dist/managers/repository.js +595 -616
  102. package/dist/managers/repository.js.map +1 -1
  103. package/dist/types.d.cts +41 -0
  104. package/dist/types.d.cts.map +1 -0
  105. package/dist/types.d.ts +35 -37
  106. package/dist/types.d.ts.map +1 -0
  107. package/dist/utils/cookies.cjs +19 -17
  108. package/dist/utils/cookies.cjs.map +1 -1
  109. package/dist/utils/cookies.js +20 -18
  110. package/dist/utils/cookies.js.map +1 -1
  111. package/dist/utils/envVariableManager.cjs +33 -34
  112. package/dist/utils/envVariableManager.cjs.map +1 -1
  113. package/dist/utils/envVariableManager.js +34 -35
  114. package/dist/utils/envVariableManager.js.map +1 -1
  115. package/dist/utils/log.cjs +18 -19
  116. package/dist/utils/log.cjs.map +1 -1
  117. package/dist/utils/log.js +18 -21
  118. package/dist/utils/log.js.map +1 -1
  119. package/dist/utils/random.cjs +13 -6
  120. package/dist/utils/random.cjs.map +1 -1
  121. package/dist/utils/random.js +13 -6
  122. package/dist/utils/random.js.map +1 -1
  123. package/dist/utils/strings.cjs +13 -7
  124. package/dist/utils/strings.cjs.map +1 -1
  125. package/dist/utils/strings.js +14 -8
  126. package/dist/utils/strings.js.map +1 -1
  127. package/dist/utils/urls.cjs +21 -10
  128. package/dist/utils/urls.cjs.map +1 -1
  129. package/dist/utils/urls.js +22 -12
  130. package/dist/utils/urls.js.map +1 -1
  131. package/package.json +42 -67
  132. package/src/clients/apiClient.ts +16 -21
  133. package/src/clients/assetApi.ts +75 -82
  134. package/src/clients/authenticationApi.ts +54 -27
  135. package/src/clients/contentApi.ts +111 -129
  136. package/src/clients/coreApi.ts +166 -117
  137. package/src/clients/customTypesApi.ts +54 -74
  138. package/src/clients/integrationFields.ts +59 -74
  139. package/src/clients/manageV2.ts +72 -96
  140. package/src/clients/migrationApi.ts +35 -39
  141. package/src/clients/wroom.ts +42 -56
  142. package/src/index.ts +7 -7
  143. package/src/managers/repositories.ts +85 -108
  144. package/src/managers/repository.ts +410 -378
  145. package/src/types.ts +31 -31
  146. package/src/utils/cookies.ts +8 -8
  147. package/src/utils/envVariableManager.ts +15 -15
  148. package/src/utils/log.ts +17 -21
  149. package/src/utils/random.ts +5 -6
  150. package/src/utils/strings.ts +7 -9
  151. package/src/utils/urls.ts +10 -12
  152. package/dist/index.cjs.map +0 -1
  153. package/dist/index.js.map +0 -1
  154. package/dist/utils/cookies.d.ts +0 -8
  155. package/dist/utils/envVariableManager.d.ts +0 -16
  156. package/dist/utils/log.d.ts +0 -5
  157. package/dist/utils/random.d.ts +0 -8
  158. package/dist/utils/strings.d.ts +0 -11
  159. package/dist/utils/urls.d.ts +0 -16
@@ -1,89 +1,98 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_log = require("../utils/log.cjs");
3
+ const require_strings = require("../utils/strings.cjs");
4
+ let axios = require("axios");
5
+ axios = require_runtime.__toESM(axios, 1);
6
+ //#region src/clients/integrationFields.ts
7
+ /**
8
+ * Client for interacting with Integration Fields routes to create integration field catalogs and
9
+ * add them to custom type fields.
10
+ */
11
+ var IntegrationFieldsClient = class {
12
+ baseURL;
13
+ customTypesApiClient;
14
+ wroomClient;
15
+ repository;
16
+ tokens = {};
17
+ constructor(baseURL, config) {
18
+ this.baseURL = baseURL;
19
+ this.customTypesApiClient = config.customTypesApiClient;
20
+ this.wroomClient = config.wroomClient;
21
+ this.repository = config.repository;
22
+ }
23
+ async getClient(catalogId) {
24
+ const token = this.tokens[catalogId] || await this.createToken(catalogId);
25
+ return axios.default.create({
26
+ baseURL: `${this.baseURL}/if/`,
27
+ withCredentials: true,
28
+ validateStatus: () => true,
29
+ headers: {
30
+ "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
31
+ Authorization: `Bearer ${token}`
32
+ }
33
+ });
34
+ }
35
+ async addCatalog({ name, description }) {
36
+ const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
37
+ "catalog-name": name,
38
+ "catalog-description": description
39
+ });
40
+ const { data, status } = response;
41
+ if (!(status === 200 || status === 400 && data.includes("Already existing integration field"))) {
42
+ require_log.logHttpResponse(response);
43
+ throw new Error(`Could not add integration field catalog ${name}`);
44
+ }
45
+ return `${this.repository}--${require_strings.slugify(name)}`;
46
+ }
47
+ async createToken(catalogId) {
48
+ const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
49
+ const { data: tokenData, status } = response;
50
+ if (status !== 201) {
51
+ require_log.logHttpResponse(response);
52
+ throw new Error(`Could not create token for integration field catalog ${catalogId}`);
53
+ }
54
+ const token = tokenData[0];
55
+ this.tokens[catalogId] = token;
56
+ return token;
57
+ }
58
+ async addDataToCatalog({ catalogId, data }) {
59
+ const response = await (await this.getClient(catalogId)).post(`/write/${catalogId}`, JSON.stringify(data));
60
+ const { status } = response;
61
+ if (status !== 200) {
62
+ require_log.logHttpResponse(response);
63
+ throw new Error(`Could not add data to integration field catalog ${catalogId}`);
64
+ }
65
+ }
66
+ async addToCustomType({ catalogId, customTypeId, fieldId }) {
67
+ const customType = await this.customTypesApiClient.getTypeById(customTypeId);
68
+ const field = customType.json.Main[fieldId];
69
+ if (!field || field.type !== "IntegrationFields") throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
70
+ field.config = {
71
+ ...field.config,
72
+ catalog: catalogId
73
+ };
74
+ await this.customTypesApiClient.createCustomTypes([customType]);
75
+ }
76
+ async setupIntegrationFields(integrationFields) {
77
+ for (const integrationField of integrationFields) {
78
+ const { name, description, customTypeId, fieldId, data } = integrationField;
79
+ const catalogId = await this.addCatalog({
80
+ name,
81
+ description
82
+ });
83
+ await this.addDataToCatalog({
84
+ catalogId,
85
+ data
86
+ });
87
+ await this.addToCustomType({
88
+ catalogId,
89
+ customTypeId,
90
+ fieldId
91
+ });
92
+ }
93
+ }
7
94
  };
8
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
- const axios = require("axios");
10
- const log = require("../utils/log.cjs");
11
- const strings = require("../utils/strings.cjs");
12
- class IntegrationFieldsClient {
13
- constructor(baseURL, config) {
14
- __publicField(this, "baseURL");
15
- __publicField(this, "customTypesApiClient");
16
- __publicField(this, "wroomClient");
17
- __publicField(this, "repository");
18
- __publicField(this, "tokens", {});
19
- this.baseURL = baseURL;
20
- this.customTypesApiClient = config.customTypesApiClient;
21
- this.wroomClient = config.wroomClient;
22
- this.repository = config.repository;
23
- }
24
- async getClient(catalogId) {
25
- const token = this.tokens[catalogId] || await this.createToken(catalogId);
26
- const client = axios.create({
27
- baseURL: `${this.baseURL}/if/`,
28
- withCredentials: true,
29
- validateStatus: () => true,
30
- headers: {
31
- "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
32
- Authorization: `Bearer ${token}`
33
- }
34
- });
35
- return client;
36
- }
37
- async addCatalog({ name, description }) {
38
- const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
39
- "catalog-name": name,
40
- "catalog-description": description
41
- });
42
- const { data, status } = response;
43
- const success = status === 200 || status === 400 && data.includes("Already existing integration field");
44
- if (!success) {
45
- log.logHttpResponse(response);
46
- throw new Error(`Could not add integration field catalog ${name}`);
47
- }
48
- return `${this.repository}--${strings.slugify(name)}`;
49
- }
50
- async createToken(catalogId) {
51
- const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
52
- const { data: tokenData, status } = response;
53
- if (status !== 201) {
54
- log.logHttpResponse(response);
55
- throw new Error(`Could not create token for integration field catalog ${catalogId}`);
56
- }
57
- const token = tokenData[0];
58
- this.tokens[catalogId] = token;
59
- return token;
60
- }
61
- async addDataToCatalog({ catalogId, data }) {
62
- const client = await this.getClient(catalogId);
63
- const response = await client.post(`/write/${catalogId}`, JSON.stringify(data));
64
- const { status } = response;
65
- if (status !== 200) {
66
- log.logHttpResponse(response);
67
- throw new Error(`Could not add data to integration field catalog ${catalogId}`);
68
- }
69
- }
70
- async addToCustomType({ catalogId, customTypeId, fieldId }) {
71
- const customType = await this.customTypesApiClient.getTypeById(customTypeId);
72
- const field = customType.json.Main[fieldId];
73
- if (!field || field.type !== "IntegrationFields") {
74
- throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
75
- }
76
- field.config = { ...field.config ?? {}, catalog: catalogId };
77
- await this.customTypesApiClient.createCustomTypes([customType]);
78
- }
79
- async setupIntegrationFields(integrationFields) {
80
- for (const integrationField of integrationFields) {
81
- const { name, description, customTypeId, fieldId, data } = integrationField;
82
- const catalogId = await this.addCatalog({ name, description });
83
- await this.addDataToCatalog({ catalogId, data });
84
- await this.addToCustomType({ catalogId, customTypeId, fieldId });
85
- }
86
- }
87
- }
95
+ //#endregion
88
96
  exports.IntegrationFieldsClient = IntegrationFieldsClient;
89
- //# sourceMappingURL=integrationFields.cjs.map
97
+
98
+ //# sourceMappingURL=integrationFields.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFields.cjs","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { slugify } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } =\n\t\t\t\tintegrationField;\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description });\n\t\t\tawait this.addDataToCatalog({ catalogId, data });\n\t\t\tawait this.addToCustomType({ catalogId, customTypeId, fieldId });\n\t\t}\n\t}\n}\n"],"names":["logHttpResponse","slugify"],"mappings":";;;;;;;;;;;MAca,wBAAuB;AAAA,EAOnC,YACC,SACA,QAIC;AAZe;AACA;AACA;AACA;AACA,kCAAiC,CAAA;AAUjD,SAAK,UAAU;AACf,SAAK,uBAAuB,OAAO;AACnC,SAAK,cAAc,OAAO;AAC1B,SAAK,aAAa,OAAO;AAAA,EAC1B;AAAA,EAEQ,MAAM,UAAU,WAAiB;AAClC,UAAA,QAAQ,KAAK,OAAO,SAAS,KAAM,MAAM,KAAK,YAAY,SAAS;AAEnE,UAAA,SAAS,MAAM,OAAO;AAAA,MAC3B,SAAS,GAAG,KAAK,OAAO;AAAA,MACxB,iBAAiB;AAAA,MACjB,gBAAgB,MAAM;AAAA,MACtB,SAAS;AAAA,QACR,cAAc;AAAA,QACd,eAAe,UAAU,KAAK;AAAA,MAC9B;AAAA,IAAA,CACD;AAEM,WAAA;AA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KAAK,OAAO;AAC1C,QAAI,CAAC,SAAS,MAAM,SAAS,qBAAqB;AACjD,YAAM,IAAI,MACT,SAAS,OAAO,2CAA2C;AAAA,IAE7D;AAEM,UAAA,SAAS,EAAE,GAAI,MAAM,UAAU,IAAK,SAAS;AAEnD,UAAM,KAAK,qBAAqB,kBAAkB,CAAC,UAAU,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,uBACL,mBAA2C;AAE3C,eAAW,oBAAoB,mBAAmB;AACjD,YAAM,EAAE,MAAM,aAAa,cAAc,SAAS,KACjD,IAAA;AAED,YAAM,YAAY,MAAM,KAAK,WAAW,EAAE,MAAM,aAAa;AAC7D,YAAM,KAAK,iBAAiB,EAAE,WAAW,KAAM,CAAA;AAC/C,YAAM,KAAK,gBAAgB,EAAE,WAAW,cAAc,SAAS;AAAA,IAChE;AAAA,EACD;AACA;;"}
1
+ {"version":3,"file":"integrationFields.cjs","names":["slugify"],"sources":["../../src/clients/integrationFields.ts"],"sourcesContent":["import type { AxiosInstance } from \"axios\"\nimport axios from \"axios\"\n\nimport type { IntegrationFieldConfig, IntegrationFieldData } from \"../types\"\nimport { logHttpResponse } from \"../utils/log\"\nimport { slugify } from \"../utils/strings\"\nimport type { CustomTypesApiClient } from \"./customTypesApi\"\nimport type { WroomClient } from \"./wroom\"\n\n/**\n * Client for interacting with Integration Fields routes to create integration field catalogs and\n * add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string\n\tprivate readonly customTypesApiClient: CustomTypesApiClient\n\tprivate readonly wroomClient: WroomClient\n\tprivate readonly repository: string\n\tprivate readonly tokens: Record<string, string> = {}\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient\n\t\t\twroomClient: WroomClient\n\t\t\trepository: string\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL\n\t\tthis.customTypesApiClient = config.customTypesApiClient\n\t\tthis.wroomClient = config.wroomClient\n\t\tthis.repository = config.repository\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId))\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t})\n\n\t\treturn client\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string\n\t\tdescription: string\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t)\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && (data as string).includes(\"Already existing integration field\"))\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`)\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t)\n\n\t\tconst { data: tokenData, status } = response\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not create token for integration field catalog ${catalogId}`)\n\t\t}\n\n\t\tconst token = tokenData[0]\n\t\tthis.tokens[catalogId] = token\n\n\t\treturn token\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string\n\t\tdata: IntegrationFieldData[]\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId)\n\t\tconst response = await client.post(`/write/${catalogId}`, JSON.stringify(data))\n\n\t\tconst { status } = response\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not add data to integration field catalog ${catalogId}`)\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string\n\t\tcustomTypeId: string\n\t\tfieldId: string\n\t}): Promise<void> {\n\t\tconst customType = await this.customTypesApiClient.getTypeById(customTypeId)\n\n\t\tconst field = customType.json.Main[fieldId]\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(`Field ${fieldId} not found or is not an Integration Field`)\n\t\t}\n\n\t\tfield.config = { ...field.config, catalog: catalogId }\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType])\n\t}\n\n\tasync setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } = integrationField\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description })\n\t\t\tawait this.addDataToCatalog({ catalogId, data })\n\t\t\tawait this.addToCustomType({ catalogId, customTypeId, fieldId })\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAa,0BAAb,MAAqC;CACpC;CACA;CACA;CACA;CACA,SAAkD,CAAC;CAEnD,YACC,SACA,QAKC;EACD,KAAK,UAAU;EACf,KAAK,uBAAuB,OAAO;EACnC,KAAK,cAAc,OAAO;EAC1B,KAAK,aAAa,OAAO;CAC1B;CAEA,MAAc,UAAU,WAA2C;EAClE,MAAM,QAAQ,KAAK,OAAO,cAAe,MAAM,KAAK,YAAY,SAAS;EAYzE,OAVe,MAAA,QAAM,OAAO;GAC3B,SAAS,GAAG,KAAK,QAAQ;GACzB,iBAAiB;GACjB,sBAAsB;GACtB,SAAS;IACR,cAAc;IACd,e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,SAAS;EAAU;EAErD,MAAM,KAAK,qBAAqB,kBAAkB,CAAC,UAAU,CAAC;CAC/D;CAEA,MAAM,uBAAuB,mBAA4D;EACxF,KAAK,MAAM,oBAAoB,mBAAmB;GACjD,MAAM,EAAE,MAAM,aAAa,cAAc,SAAS,SAAS;GAE3D,MAAM,YAAY,MAAM,KAAK,WAAW;IAAE;IAAM;GAAY,CAAC;GAC7D,MAAM,KAAK,iBAAiB;IAAE;IAAW;GAAK,CAAC;GAC/C,MAAM,KAAK,gBAAgB;IAAE;IAAW;IAAc;GAAQ,CAAC;EAChE;CACD;AACD"}
@@ -0,0 +1,30 @@
1
+ import { IntegrationFieldConfig } from "../types.cjs";
2
+ import { CustomTypesApiClient } from "./customTypesApi.cjs";
3
+ import { WroomClient } from "./wroom.cjs";
4
+
5
+ //#region src/clients/integrationFields.d.ts
6
+ /**
7
+ * Client for interacting with Integration Fields routes to create integration field catalogs and
8
+ * add them to custom type fields.
9
+ */
10
+ declare class IntegrationFieldsClient {
11
+ private readonly baseURL;
12
+ private readonly customTypesApiClient;
13
+ private readonly wroomClient;
14
+ private readonly repository;
15
+ private readonly tokens;
16
+ constructor(baseURL: string, config: {
17
+ customTypesApiClient: CustomTypesApiClient;
18
+ wroomClient: WroomClient;
19
+ repository: string;
20
+ });
21
+ private getClient;
22
+ private addCatalog;
23
+ private createToken;
24
+ private addDataToCatalog;
25
+ private addToCustomType;
26
+ setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void>;
27
+ }
28
+ //#endregion
29
+ export { IntegrationFieldsClient };
30
+ //# sourceMappingURL=integrationFields.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrationFields.d.cts","names":[],"sources":["../../src/clients/integrationFields.ts"],"mappings":";;;;;;;AAaA;;cAAa,uBAAA;EAAA,iBACK,OAAA;EAAA,iBACA,oBAAA;EAAA,iBACA,WAAA;EAAA,iBACA,UAAA;EAAA,iBACA,MAAA;cAGhB,OAAA,UACA,MAAA;IACC,oBAAA,EAAsB,oBAAA;IACtB,WAAA,EAAa,WAAA;IACb,UAAA;EAAA;EAAA,QASY,SAAA;EAAA,QAgBA,UAAA;EAAA,QA4BA,WAAA;EAAA,QAkBA,gBAAA;EAAA,QAiBA,eAAA;EAqBR,sBAAA,CAAuB,iBAAA,EAAmB,sBAAA,KAA2B,OAAA;AAAA"}
@@ -1,25 +1,30 @@
1
- import { IntegrationFieldConfig } from "../types";
2
- import { CustomTypesApiClient } from "./customTypesApi";
3
- import { WroomClient } from "./wroom";
1
+ import { IntegrationFieldConfig } from "../types.js";
2
+ import { CustomTypesApiClient } from "./customTypesApi.js";
3
+ import { WroomClient } from "./wroom.js";
4
+
5
+ //#region src/clients/integrationFields.d.ts
4
6
  /**
5
- * Client for interacting with Integration Fields routes to create integration
6
- * field catalogs and add them to custom type fields.
7
+ * Client for interacting with Integration Fields routes to create integration field catalogs and
8
+ * add them to custom type fields.
7
9
  */
8
- export declare class IntegrationFieldsClient {
9
- private readonly baseURL;
10
- private readonly customTypesApiClient;
11
- private readonly wroomClient;
12
- private readonly repository;
13
- private readonly tokens;
14
- constructor(baseURL: string, config: {
15
- customTypesApiClient: CustomTypesApiClient;
16
- wroomClient: WroomClient;
17
- repository: string;
18
- });
19
- private getClient;
20
- private addCatalog;
21
- private createToken;
22
- private addDataToCatalog;
23
- private addToCustomType;
24
- setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void>;
10
+ declare class IntegrationFieldsClient {
11
+ private readonly baseURL;
12
+ private readonly customTypesApiClient;
13
+ private readonly wroomClient;
14
+ private readonly repository;
15
+ private readonly tokens;
16
+ constructor(baseURL: string, config: {
17
+ customTypesApiClient: CustomTypesApiClient;
18
+ wroomClient: WroomClient;
19
+ repository: string;
20
+ });
21
+ private getClient;
22
+ private addCatalog;
23
+ private createToken;
24
+ private addDataToCatalog;
25
+ private addToCustomType;
26
+ setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void>;
25
27
  }
28
+ //#endregion
29
+ export { IntegrationFieldsClient };
30
+ //# sourceMappingURL=integrationFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrationFields.d.ts","names":[],"sources":["../../src/clients/integrationFields.ts"],"mappings":";;;;;;;AAaA;;cAAa,uBAAA;EAAA,iBACK,OAAA;EAAA,iBACA,oBAAA;EAAA,iBACA,WAAA;EAAA,iBACA,UAAA;EAAA,iBACA,MAAA;cAGhB,OAAA,UACA,MAAA;IACC,oBAAA,EAAsB,oBAAA;IACtB,WAAA,EAAa,WAAA;IACb,UAAA;EAAA;EAAA,QASY,SAAA;EAAA,QAgBA,UAAA;EAAA,QA4BA,WAAA;EAAA,QAkBA,gBAAA;EAAA,QAiBA,eAAA;EAqBR,sBAAA,CAAuB,iBAAA,EAAmB,sBAAA,KAA2B,OAAA;AAAA"}
@@ -1,89 +1,96 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- import axios from "axios";
8
1
  import { logHttpResponse } from "../utils/log.js";
9
2
  import { slugify } from "../utils/strings.js";
10
- class IntegrationFieldsClient {
11
- constructor(baseURL, config) {
12
- __publicField(this, "baseURL");
13
- __publicField(this, "customTypesApiClient");
14
- __publicField(this, "wroomClient");
15
- __publicField(this, "repository");
16
- __publicField(this, "tokens", {});
17
- this.baseURL = baseURL;
18
- this.customTypesApiClient = config.customTypesApiClient;
19
- this.wroomClient = config.wroomClient;
20
- this.repository = config.repository;
21
- }
22
- async getClient(catalogId) {
23
- const token = this.tokens[catalogId] || await this.createToken(catalogId);
24
- const client = axios.create({
25
- baseURL: `${this.baseURL}/if/`,
26
- withCredentials: true,
27
- validateStatus: () => true,
28
- headers: {
29
- "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
30
- Authorization: `Bearer ${token}`
31
- }
32
- });
33
- return client;
34
- }
35
- async addCatalog({ name, description }) {
36
- const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
37
- "catalog-name": name,
38
- "catalog-description": description
39
- });
40
- const { data, status } = response;
41
- const success = status === 200 || status === 400 && data.includes("Already existing integration field");
42
- if (!success) {
43
- logHttpResponse(response);
44
- throw new Error(`Could not add integration field catalog ${name}`);
45
- }
46
- return `${this.repository}--${slugify(name)}`;
47
- }
48
- async createToken(catalogId) {
49
- const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
50
- const { data: tokenData, status } = response;
51
- if (status !== 201) {
52
- logHttpResponse(response);
53
- throw new Error(`Could not create token for integration field catalog ${catalogId}`);
54
- }
55
- const token = tokenData[0];
56
- this.tokens[catalogId] = token;
57
- return token;
58
- }
59
- async addDataToCatalog({ catalogId, data }) {
60
- const client = await this.getClient(catalogId);
61
- const response = await client.post(`/write/${catalogId}`, JSON.stringify(data));
62
- const { status } = response;
63
- if (status !== 200) {
64
- logHttpResponse(response);
65
- throw new Error(`Could not add data to integration field catalog ${catalogId}`);
66
- }
67
- }
68
- async addToCustomType({ catalogId, customTypeId, fieldId }) {
69
- const customType = await this.customTypesApiClient.getTypeById(customTypeId);
70
- const field = customType.json.Main[fieldId];
71
- if (!field || field.type !== "IntegrationFields") {
72
- throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
73
- }
74
- field.config = { ...field.config ?? {}, catalog: catalogId };
75
- await this.customTypesApiClient.createCustomTypes([customType]);
76
- }
77
- async setupIntegrationFields(integrationFields) {
78
- for (const integrationField of integrationFields) {
79
- const { name, description, customTypeId, fieldId, data } = integrationField;
80
- const catalogId = await this.addCatalog({ name, description });
81
- await this.addDataToCatalog({ catalogId, data });
82
- await this.addToCustomType({ catalogId, customTypeId, fieldId });
83
- }
84
- }
85
- }
86
- export {
87
- IntegrationFieldsClient
3
+ import axios from "axios";
4
+ //#region src/clients/integrationFields.ts
5
+ /**
6
+ * Client for interacting with Integration Fields routes to create integration field catalogs and
7
+ * add them to custom type fields.
8
+ */
9
+ var IntegrationFieldsClient = class {
10
+ baseURL;
11
+ customTypesApiClient;
12
+ wroomClient;
13
+ repository;
14
+ tokens = {};
15
+ constructor(baseURL, config) {
16
+ this.baseURL = baseURL;
17
+ this.customTypesApiClient = config.customTypesApiClient;
18
+ this.wroomClient = config.wroomClient;
19
+ this.repository = config.repository;
20
+ }
21
+ async getClient(catalogId) {
22
+ const token = this.tokens[catalogId] || await this.createToken(catalogId);
23
+ return axios.create({
24
+ baseURL: `${this.baseURL}/if/`,
25
+ withCredentials: true,
26
+ validateStatus: () => true,
27
+ headers: {
28
+ "User-Agent": "prismic-cli/prismic-e2e-tests-utils",
29
+ Authorization: `Bearer ${token}`
30
+ }
31
+ });
32
+ }
33
+ async addCatalog({ name, description }) {
34
+ const response = await this.wroomClient.post(this.repository, "app/settings/integrationfields/pushcustom", {
35
+ "catalog-name": name,
36
+ "catalog-description": description
37
+ });
38
+ const { data, status } = response;
39
+ if (!(status === 200 || status === 400 && data.includes("Already existing integration field"))) {
40
+ logHttpResponse(response);
41
+ throw new Error(`Could not add integration field catalog ${name}`);
42
+ }
43
+ return `${this.repository}--${slugify(name)}`;
44
+ }
45
+ async createToken(catalogId) {
46
+ const response = await this.wroomClient.post(this.repository, `app/settings/integrationfields/pushcustom/${catalogId}/token`);
47
+ const { data: tokenData, status } = response;
48
+ if (status !== 201) {
49
+ logHttpResponse(response);
50
+ throw new Error(`Could not create token for integration field catalog ${catalogId}`);
51
+ }
52
+ const token = tokenData[0];
53
+ this.tokens[catalogId] = token;
54
+ return token;
55
+ }
56
+ async addDataToCatalog({ catalogId, data }) {
57
+ const response = await (await this.getClient(catalogId)).post(`/write/${catalogId}`, JSON.stringify(data));
58
+ const { status } = response;
59
+ if (status !== 200) {
60
+ logHttpResponse(response);
61
+ throw new Error(`Could not add data to integration field catalog ${catalogId}`);
62
+ }
63
+ }
64
+ async addToCustomType({ catalogId, customTypeId, fieldId }) {
65
+ const customType = await this.customTypesApiClient.getTypeById(customTypeId);
66
+ const field = customType.json.Main[fieldId];
67
+ if (!field || field.type !== "IntegrationFields") throw new Error(`Field ${fieldId} not found or is not an Integration Field`);
68
+ field.config = {
69
+ ...field.config,
70
+ catalog: catalogId
71
+ };
72
+ await this.customTypesApiClient.createCustomTypes([customType]);
73
+ }
74
+ async setupIntegrationFields(integrationFields) {
75
+ for (const integrationField of integrationFields) {
76
+ const { name, description, customTypeId, fieldId, data } = integrationField;
77
+ const catalogId = await this.addCatalog({
78
+ name,
79
+ description
80
+ });
81
+ await this.addDataToCatalog({
82
+ catalogId,
83
+ data
84
+ });
85
+ await this.addToCustomType({
86
+ catalogId,
87
+ customTypeId,
88
+ fieldId
89
+ });
90
+ }
91
+ }
88
92
  };
89
- //# sourceMappingURL=integrationFields.js.map
93
+ //#endregion
94
+ export { IntegrationFieldsClient };
95
+
96
+ //# sourceMappingURL=integrationFields.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"integrationFields.js","sources":["../../../src/clients/integrationFields.ts"],"sourcesContent":["import axios, { AxiosInstance } from \"axios\";\n\nimport { IntegrationFieldConfig, IntegrationFieldData } from \"../types\";\n\nimport { logHttpResponse } from \"../utils/log\";\nimport { slugify } from \"../utils/strings\";\n\nimport { CustomTypesApiClient } from \"./customTypesApi\";\nimport { WroomClient } from \"./wroom\";\n\n/**\n * Client for interacting with Integration Fields routes to create integration\n * field catalogs and add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string;\n\tprivate readonly customTypesApiClient: CustomTypesApiClient;\n\tprivate readonly wroomClient: WroomClient;\n\tprivate readonly repository: string;\n\tprivate readonly tokens: Record<string, string> = {};\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient;\n\t\t\twroomClient: WroomClient;\n\t\t\trepository: string;\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL;\n\t\tthis.customTypesApiClient = config.customTypesApiClient;\n\t\tthis.wroomClient = config.wroomClient;\n\t\tthis.repository = config.repository;\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId));\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t});\n\n\t\treturn client;\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string;\n\t\tdescription: string;\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t);\n\n\t\tconst { data, status } = response;\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 &&\n\t\t\t\t(data as string).includes(\"Already existing integration field\"));\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`);\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`;\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t);\n\n\t\tconst { data: tokenData, status } = response;\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not create token for integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\n\t\tconst token = tokenData[0];\n\t\tthis.tokens[catalogId] = token;\n\n\t\treturn token;\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string;\n\t\tdata: IntegrationFieldData[];\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId);\n\t\tconst response = await client.post(\n\t\t\t`/write/${catalogId}`,\n\t\t\tJSON.stringify(data),\n\t\t);\n\n\t\tconst { status } = response;\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not add data to integration field catalog ${catalogId}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string;\n\t\tcustomTypeId: string;\n\t\tfieldId: string;\n\t}): Promise<void> {\n\t\tconst customType =\n\t\t\tawait this.customTypesApiClient.getTypeById(customTypeId);\n\n\t\tconst field = customType.json.Main[fieldId];\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(\n\t\t\t\t`Field ${fieldId} not found or is not an Integration Field`,\n\t\t\t);\n\t\t}\n\n\t\tfield.config = { ...(field.config ?? {}), catalog: catalogId };\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType]);\n\t}\n\n\tasync setupIntegrationFields(\n\t\tintegrationFields: IntegrationFieldConfig[],\n\t): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } =\n\t\t\t\tintegrationField;\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description });\n\t\t\tawait this.addDataToCatalog({ catalogId, data });\n\t\t\tawait this.addToCustomType({ catalogId, customTypeId, fieldId });\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;MAca,wBAAuB;AAAA,EAOnC,YACC,SACA,QAIC;AAZe;AACA;AACA;AACA;AACA,kCAAiC,CAAA;AAUjD,SAAK,UAAU;AACf,SAAK,uBAAuB,OAAO;AACnC,SAAK,cAAc,OA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WAAW,MAAM,OAAO,KAC7B,UAAU,SAAS,IACnB,KAAK,UAAU,IAAI,CAAC;AAGf,UAAA,EAAE,OAAW,IAAA;AACnB,QAAI,WAAW,KAAK;AACnB,sBAAgB,QAAQ;AACxB,YAAM,IAAI,MACT,mDAAmD,SAAS,EAAE;AAAA,IAEhE;AAAA,EACD;AAAA,EAEQ,MAAM,gBAAgB,EAC7B,WACA,cACA,WAKA;AACA,UAAM,aACL,MAAM,KAAK,qBAAqB,YAAY,YAAY;AAEzD,UAAM,QAAQ,WAAW,KAAK,KAAK,OAAO;AAC1C,QAAI,CAAC,SAAS,MAAM,SAAS,qBAAqB;AACjD,YAAM,IAAI,MACT,SAAS,OAAO,2CAA2C;AAAA,IAE7D;AAEM,UAAA,SAAS,EAAE,GAAI,MAAM,UAAU,IAAK,SAAS;AAEnD,UAAM,KAAK,qBAAqB,kBAAkB,CAAC,UAAU,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,uBACL,mBAA2C;AAE3C,eAAW,oBAAoB,mBAAmB;AACjD,YAAM,EAAE,MAAM,aAAa,cAAc,SAAS,KACjD,IAAA;AAED,YAAM,YAAY,MAAM,KAAK,WAAW,EAAE,MAAM,aAAa;AAC7D,YAAM,KAAK,iBAAiB,EAAE,WAAW,KAAM,CAAA;AAC/C,YAAM,KAAK,gBAAgB,EAAE,WAAW,cAAc,SAAS;AAAA,IAChE;AAAA,EACD;AACA;"}
1
+ {"version":3,"file":"integrationFields.js","names":[],"sources":["../../src/clients/integrationFields.ts"],"sourcesContent":["import type { AxiosInstance } from \"axios\"\nimport axios from \"axios\"\n\nimport type { IntegrationFieldConfig, IntegrationFieldData } from \"../types\"\nimport { logHttpResponse } from \"../utils/log\"\nimport { slugify } from \"../utils/strings\"\nimport type { CustomTypesApiClient } from \"./customTypesApi\"\nimport type { WroomClient } from \"./wroom\"\n\n/**\n * Client for interacting with Integration Fields routes to create integration field catalogs and\n * add them to custom type fields.\n */\nexport class IntegrationFieldsClient {\n\tprivate readonly baseURL: string\n\tprivate readonly customTypesApiClient: CustomTypesApiClient\n\tprivate readonly wroomClient: WroomClient\n\tprivate readonly repository: string\n\tprivate readonly tokens: Record<string, string> = {}\n\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: {\n\t\t\tcustomTypesApiClient: CustomTypesApiClient\n\t\t\twroomClient: WroomClient\n\t\t\trepository: string\n\t\t},\n\t) {\n\t\tthis.baseURL = baseURL\n\t\tthis.customTypesApiClient = config.customTypesApiClient\n\t\tthis.wroomClient = config.wroomClient\n\t\tthis.repository = config.repository\n\t}\n\n\tprivate async getClient(catalogId: string): Promise<AxiosInstance> {\n\t\tconst token = this.tokens[catalogId] || (await this.createToken(catalogId))\n\n\t\tconst client = axios.create({\n\t\t\tbaseURL: `${this.baseURL}/if/`,\n\t\t\twithCredentials: true,\n\t\t\tvalidateStatus: () => true,\n\t\t\theaders: {\n\t\t\t\t\"User-Agent\": \"prismic-cli/prismic-e2e-tests-utils\",\n\t\t\t\tAuthorization: `Bearer ${token}`,\n\t\t\t},\n\t\t})\n\n\t\treturn client\n\t}\n\n\tprivate async addCatalog({\n\t\tname,\n\t\tdescription,\n\t}: {\n\t\tname: string\n\t\tdescription: string\n\t}): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t\"app/settings/integrationfields/pushcustom\",\n\t\t\t{\n\t\t\t\t\"catalog-name\": name,\n\t\t\t\t\"catalog-description\": description,\n\t\t\t},\n\t\t)\n\n\t\tconst { data, status } = response\n\t\tconst success =\n\t\t\tstatus === 200 ||\n\t\t\t(status === 400 && (data as string).includes(\"Already existing integration field\"))\n\t\tif (!success) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not add integration field catalog ${name}`)\n\t\t}\n\n\t\treturn `${this.repository}--${slugify(name)}`\n\t}\n\n\tprivate async createToken(catalogId: string): Promise<string> {\n\t\tconst response = await this.wroomClient.post(\n\t\t\tthis.repository,\n\t\t\t`app/settings/integrationfields/pushcustom/${catalogId}/token`,\n\t\t)\n\n\t\tconst { data: tokenData, status } = response\n\t\tif (status !== 201) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not create token for integration field catalog ${catalogId}`)\n\t\t}\n\n\t\tconst token = tokenData[0]\n\t\tthis.tokens[catalogId] = token\n\n\t\treturn token\n\t}\n\n\tprivate async addDataToCatalog({\n\t\tcatalogId,\n\t\tdata,\n\t}: {\n\t\tcatalogId: string\n\t\tdata: IntegrationFieldData[]\n\t}): Promise<void> {\n\t\tconst client = await this.getClient(catalogId)\n\t\tconst response = await client.post(`/write/${catalogId}`, JSON.stringify(data))\n\n\t\tconst { status } = response\n\t\tif (status !== 200) {\n\t\t\tlogHttpResponse(response)\n\t\t\tthrow new Error(`Could not add data to integration field catalog ${catalogId}`)\n\t\t}\n\t}\n\n\tprivate async addToCustomType({\n\t\tcatalogId,\n\t\tcustomTypeId,\n\t\tfieldId,\n\t}: {\n\t\tcatalogId: string\n\t\tcustomTypeId: string\n\t\tfieldId: string\n\t}): Promise<void> {\n\t\tconst customType = await this.customTypesApiClient.getTypeById(customTypeId)\n\n\t\tconst field = customType.json.Main[fieldId]\n\t\tif (!field || field.type !== \"IntegrationFields\") {\n\t\t\tthrow new Error(`Field ${fieldId} not found or is not an Integration Field`)\n\t\t}\n\n\t\tfield.config = { ...field.config, catalog: catalogId }\n\n\t\tawait this.customTypesApiClient.createCustomTypes([customType])\n\t}\n\n\tasync setupIntegrationFields(integrationFields: IntegrationFieldConfig[]): Promise<void> {\n\t\tfor (const integrationField of integrationFields) {\n\t\t\tconst { name, description, customTypeId, fieldId, data } = integrationField\n\n\t\t\tconst catalogId = await this.addCatalog({ name, description })\n\t\t\tawait this.addDataToCatalog({ catalogId, data })\n\t\t\tawait this.addToCustomType({ catalogId, customTypeId, fieldId })\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,0BAAb,MAAqC;CACpC;CACA;CACA;CACA;CACA,SAAkD,CAAC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