@prismicio/e2e-tests-utils 1.17.1-alpha.0 → 1.18.0-canary.933a809

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 +52 -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 +52 -73
  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 +123 -145
  36. package/dist/clients/coreApi.cjs.map +1 -1
  37. package/dist/clients/coreApi.d.cts +122 -0
  38. package/dist/clients/coreApi.d.cts.map +1 -0
  39. package/dist/clients/coreApi.d.ts +111 -109
  40. package/dist/clients/coreApi.d.ts.map +1 -0
  41. package/dist/clients/coreApi.js +122 -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 +529 -616
  96. package/dist/managers/repository.cjs.map +1 -1
  97. package/dist/managers/repository.d.cts +308 -0
  98. package/dist/managers/repository.d.cts.map +1 -0
  99. package/dist/managers/repository.d.ts +303 -307
  100. package/dist/managers/repository.d.ts.map +1 -0
  101. package/dist/managers/repository.js +529 -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 +25 -27
  135. package/src/clients/contentApi.ts +109 -129
  136. package/src/clients/coreApi.ts +113 -117
  137. package/src/clients/customTypesApi.ts +54 -76
  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 +303 -368
  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,100 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const isEqual = require("lodash.isequal");
4
- const log = require("../utils/log.cjs");
5
- const apiClient = require("./apiClient.cjs");
6
- class CustomTypesApiClient extends apiClient.AuthenticatedApiClient {
7
- constructor(baseURL, config) {
8
- super(baseURL, config.authToken, { repository: config.repository });
9
- }
10
- /**
11
- * Create or update a custom type or slice.
12
- *
13
- * @param endpoint - - The API endpoint for custom types or slices
14
- * ('customtypes' or 'slices').
15
- * @param data - - The data representing the custom type or slice.
16
- *
17
- * @throws Error if the item status cannot be retrieved or the item cannot be
18
- * created/updated.
19
- */
20
- async upsert(endpoint, operation, data) {
21
- const profiler = log.logger.startTimer();
22
- const path = `${endpoint}/${operation}`;
23
- const context = await this.getContext();
24
- const result = await context.post(path, { data });
25
- if (!result.ok()) {
26
- log.logPlaywrightApiResponse(result);
27
- throw new Error(`Could not ${operation} item`);
28
- }
29
- profiler.done({
30
- message: `called customtypes api /${path} for item with id '${data.id}'`
31
- });
32
- }
33
- async getRemoteItems(endpoint) {
34
- const context = await this.getContext();
35
- const result = await context.get(endpoint);
36
- if (!result.ok()) {
37
- log.logPlaywrightApiResponse(result);
38
- throw new Error("Could not get items status from the Custom Type api.");
39
- }
40
- return result.json();
41
- }
42
- async getDifference(remoteItems, local) {
43
- const remoteItem = remoteItems.find((remote) => remote.id === local.id);
44
- if (!remoteItem) {
45
- return "insert";
46
- }
47
- if (!isEqual(local, remoteItem)) {
48
- return "update";
49
- }
50
- return;
51
- }
52
- /** Create items only if they have changed compared to their remote status */
53
- async upsertIfChanged(itemType, localItems = []) {
54
- const remoteItems = await this.getRemoteItems(itemType);
55
- await Promise.all(localItems.map(async (localItem) => {
56
- const operation = await this.getDifference(remoteItems, localItem);
57
- return operation && this.upsert(itemType, operation, localItem);
58
- }));
59
- }
60
- /**
61
- * Create Custom Types using the Custom types api.
62
- *
63
- * @param customTypes -
64
- */
65
- async createCustomTypes(customTypes = []) {
66
- await this.upsertIfChanged("customtypes", customTypes);
67
- }
68
- async deleteCustomType(customTypeId) {
69
- const context = await this.getContext();
70
- const result = await context.delete(`customtypes/${customTypeId}`);
71
- if (!result.ok()) {
72
- log.logPlaywrightApiResponse(result);
73
- throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`);
74
- }
75
- }
76
- /**
77
- * Create slices using the Custom types api.
78
- *
79
- * @param slices -
80
- */
81
- async createSlices(slices = []) {
82
- await this.upsertIfChanged("slices", slices);
83
- }
84
- /**
85
- * Get a custom type by its id.
86
- *
87
- * @param customTypeId - The id of the custom type to get.
88
- */
89
- async getTypeById(customTypeId) {
90
- const context = await this.getContext();
91
- const result = await context.get(`customtypes/${customTypeId}`);
92
- if (!result.ok()) {
93
- log.logPlaywrightApiResponse(result);
94
- throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`);
95
- }
96
- return result.json();
97
- }
98
- }
1
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_log = require("../utils/log.cjs");
3
+ const require_apiClient = require("./apiClient.cjs");
4
+ let lodash_isequal = require("lodash.isequal");
5
+ lodash_isequal = require_runtime.__toESM(lodash_isequal, 1);
6
+ //#region src/clients/customTypesApi.ts
7
+ /** Client for interacting with the Custom Types API to create/update custom types and slices. */
8
+ var CustomTypesApiClient = class extends require_apiClient.AuthenticatedApiClient {
9
+ constructor(baseURL, config) {
10
+ super(baseURL, config.authToken, { repository: config.repository });
11
+ }
12
+ /**
13
+ * Create or update a custom type or slice.
14
+ *
15
+ * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').
16
+ * @param data - - The data representing the custom type or slice.
17
+ * @throws Error if the item status cannot be retrieved or the item cannot be
18
+ * created/updated.
19
+ */
20
+ async upsert(endpoint, operation, data) {
21
+ const profiler = require_log.logger.startTimer();
22
+ const path = `${endpoint}/${operation}`;
23
+ const result = await (await this.getContext()).post(path, { data });
24
+ if (!result.ok()) {
25
+ require_log.logPlaywrightApiResponse(result);
26
+ throw new Error(`Could not ${operation} item`);
27
+ }
28
+ profiler.done({ message: `called customtypes api /${path} for item with id '${data.id}'` });
29
+ }
30
+ async getRemoteItems(endpoint) {
31
+ const result = await (await this.getContext()).get(endpoint);
32
+ if (!result.ok()) {
33
+ require_log.logPlaywrightApiResponse(result);
34
+ throw new Error("Could not get items status from the Custom Type api.");
35
+ }
36
+ return result.json();
37
+ }
38
+ async getDifference(remoteItems, local) {
39
+ const remoteItem = remoteItems.find((remote) => remote.id === local.id);
40
+ if (!remoteItem) return "insert";
41
+ if (!(0, lodash_isequal.default)(local, remoteItem)) return "update";
42
+ }
43
+ /** Create items only if they have changed compared to their remote status */
44
+ async upsertIfChanged(itemType, localItems = []) {
45
+ const remoteItems = await this.getRemoteItems(itemType);
46
+ await Promise.all(localItems.map(async (localItem) => {
47
+ const operation = await this.getDifference(remoteItems, localItem);
48
+ return operation && this.upsert(itemType, operation, localItem);
49
+ }));
50
+ }
51
+ /**
52
+ * Create Custom Types using the Custom types api.
53
+ *
54
+ * @param customTypes
55
+ */
56
+ async createCustomTypes(customTypes = []) {
57
+ await this.upsertIfChanged("customtypes", customTypes);
58
+ }
59
+ async deleteCustomType(customTypeId) {
60
+ const result = await (await this.getContext()).delete(`customtypes/${customTypeId}`);
61
+ if (!result.ok()) {
62
+ require_log.logPlaywrightApiResponse(result);
63
+ throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`);
64
+ }
65
+ }
66
+ /**
67
+ * Create slices using the Custom types api.
68
+ *
69
+ * @param slices
70
+ */
71
+ async createSlices(slices = []) {
72
+ await this.upsertIfChanged("slices", slices);
73
+ }
74
+ /**
75
+ * Get a custom type by its id.
76
+ *
77
+ * @param customTypeId - The id of the custom type to get.
78
+ */
79
+ async getTypeById(customTypeId) {
80
+ const result = await (await this.getContext()).get(`customtypes/${customTypeId}`);
81
+ if (!result.ok()) {
82
+ require_log.logPlaywrightApiResponse(result);
83
+ throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`);
84
+ }
85
+ return result.json();
86
+ }
87
+ };
88
+ //#endregion
99
89
  exports.CustomTypesApiClient = CustomTypesApiClient;
100
- //# sourceMappingURL=customTypesApi.cjs.map
90
+
91
+ //# sourceMappingURL=customTypesApi.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"customTypesApi.cjs","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.delete(`customtypes/${customTypeId}`);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not delete ${customTypeId} from the Custom Type api.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<CustomType> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(`customtypes/${customTypeId}`);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not get ${customTypeId} type from the Custom Type api.`,\n\t\t\t);\n\t\t}\n\n\t\treturn result.json();\n\t}\n}\n"],"names":["AuthenticatedApiClient","logger","logPlaywrightApiResponse"],"mappings":";;;;;AAmBM,MAAO,6BAA6BA,UAAAA,uBAAsB;AAAA,EAC/D,YACC,SACA,QAA0D;AAE1D,UAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,YAAY;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYQ,MAAM,OACb,UACA,WACA,MAAc;AAER,UAAA,WAAWC,WAAO;AACxB,UAAM,OAAO,GAAG,QAAQ,IAAI,SAAS;AAE/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,KAAK,MAAM,EAAE,MAAM;AAC5C,QAAA,CAAC,OAAO,MAAM;AACjBC,UAAA,yBAAyB,MAAM;AAC/B,YAAM,IAAI,MAAM,aAAa,SAAS,OAAO;AAAA,IAC9C;AACA,aAAS,KAAK;AAAA,MACb,SAAS,2BAA2B,IAAI,sBAAsB,KAAK,EAAE;AAAA,IAAA,CACrE;AAAA,EACF;AAAA,EAEQ,MAAM,eACb,UAAsB;AAEhB,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AAErC,QAAA,CAAC,OAAO,MAAM;AACjBA,UAAA,yBAAyB,MAAM;AACzB,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AAEA,WAAO,OAAO;EACf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,iBAAiB,YAAY,iCAAiC;AAAA,IAEhE;AAEA,WAAO,OAAO;EACf;AACA;;"}
1
+ {"version":3,"file":"customTypesApi.cjs","names":["AuthenticatedApiClient","logger"],"sources":["../../src/clients/customTypesApi.ts"],"sourcesContent":["import type { StaticCustomTypeModel, SharedSliceModel } from \"@prismicio/types-internal\"\nimport isEqual from \"lodash.isequal\"\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\"\nimport type { AuthServerToken } from \"./apiClient\"\nimport { AuthenticatedApiClient } from \"./apiClient\"\n\ntype ItemType = StaticCustomTypeModel | SharedSliceModel\ntype ItemTypePath = \"customtypes\" | \"slices\"\ntype ItemOperation = \"insert\" | \"update\"\n\n/** Client for interacting with the Custom Types API to create/update custom types and slices. */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(baseURL: string, config: { authToken: AuthServerToken; repository: string }) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository })\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(endpoint: ItemTypePath, operation: ItemOperation, data: ItemType) {\n\t\tconst profiler = logger.startTimer()\n\t\tconst path = `${endpoint}/${operation}`\n\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.post(path, { data })\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not ${operation} item`)\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t})\n\t}\n\n\tprivate async getRemoteItems(endpoint: ItemTypePath): Promise<StaticCustomTypeModel[] | SharedSliceModel[]> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.get(endpoint)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\")\n\t\t}\n\n\t\treturn result.json()\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: StaticCustomTypeModel[] | SharedSliceModel[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: StaticCustomTypeModel | SharedSliceModel) => remote.id === local.id,\n\t\t)\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\"\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\"\n\t\t}\n\n\t\treturn\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType)\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem)\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem)\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes\n\t */\n\tasync createCustomTypes(customTypes: StaticCustomTypeModel[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes)\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.delete(`customtypes/${customTypeId}`)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not delete ${customTypeId} from the Custom Type api.`)\n\t\t}\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices\n\t */\n\tasync createSlices(slices: SharedSliceModel[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices)\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<StaticCustomTypeModel> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.get(`customtypes/${customTypeId}`)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not get ${customTypeId} type from the Custom Type api.`)\n\t\t}\n\n\t\treturn result.json()\n\t}\n}\n"],"mappings":";;;;;;;AAYA,IAAa,uBAAb,cAA0CA,kBAAAA,uBAAuB;CAChE,YAAY,SAAiB,QAA4D;EACxF,MAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,WAAW,CAAC;CACnE;;;;;;;;;CAUA,MAAc,OAAO,UAAwB,WAA0B,MAAgB;EACtF,MAAM,WAAWC,YAAAA,OAAO,WAAW;EACnC,MAAM,OAAO,GAAG,SAAS,GAAG;EAG5B,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,KAAK,MAAM,EAAE,KAAK,CAAC;EAChD,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,aAAa,UAAU,MAAM;EAC9C;EACA,SAAS,KAAK,EACb,SAAS,2BAA2B,KAAK,qBAAqB,KAAK,GAAG,GACvE,CAAC;CACF;CAEA,MAAc,eAAe,UAA+E;EAE3G,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,IAAI,QAAQ;EAEzC,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,sDAAsD;EACvE;EAEA,OAAO,OAAO,KAAK;CACpB;CAEA,MAAc,cACb,aACA,OACqC;EACrC,MAAM,aAAa,YAAY,MAC7B,WAAqD,OAAO,OAAO,MAAM,EAC3E;EACA,IAAI,CAAC,YACJ,OAAO;EAER,IAAI,EAAA,GAAA,eAAA,QAAA,CAAS,OAAO,UAAU,GAC7B,OAAO;CAIT;;CAGA,MAAc,gBACb,UACA,aAAyB,CAAC,GACV;EAChB,MAAM,cAAc,MAAM,KAAK,eAAe,QAAQ;EACtD,MAAM,QAAQ,IACb,WAAW,IAAI,OAAO,cAAc;GACnC,MAAM,YAAY,MAAM,KAAK,cAAc,aAAa,SAAS;GAEjE,OAAO,aAAa,KAAK,OAAO,UAAU,WAAW,SAAS;EAC/D,CAAC,CACF;CACD;;;;;;CAOA,MAAM,kBAAkB,cAAuC,CAAC,GAAkB;EACjF,MAAM,KAAK,gBAAgB,eAAe,WAAW;CACtD;CAEA,MAAM,iBAAiB,cAAqC;EAE3D,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,OAAO,eAAe,cAAc;EAEjE,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,oBAAoB,aAAa,2BAA2B;EAC7E;CACD;;;;;;CAOA,MAAM,aAAa,SAA6B,CAAC,GAAkB;EAClE,MAAM,KAAK,gBAAgB,UAAU,MAAM;CAC5C;;;;;;CAOA,MAAM,YAAY,cAAsD;EAEvE,MAAM,SAAS,OAAM,MADC,KAAK,WAAW,EAAA,CACT,IAAI,eAAe,cAAc;EAE9D,IAAI,CAAC,OAAO,GAAG,GAAG;GACjB,YAAA,yBAAyB,MAAM;GAC/B,MAAM,IAAI,MAAM,iBAAiB,aAAa,gCAAgC;EAC/E;EAEA,OAAO,OAAO,KAAK;CACpB;AACD"}
@@ -0,0 +1,46 @@
1
+ import { AuthServerToken, AuthenticatedApiClient } from "./apiClient.cjs";
2
+ import { SharedSliceModel, StaticCustomTypeModel } from "@prismicio/types-internal";
3
+
4
+ //#region src/clients/customTypesApi.d.ts
5
+ /** Client for interacting with the Custom Types API to create/update custom types and slices. */
6
+ declare class CustomTypesApiClient extends AuthenticatedApiClient {
7
+ constructor(baseURL: string, config: {
8
+ authToken: AuthServerToken;
9
+ repository: string;
10
+ });
11
+ /**
12
+ * Create or update a custom type or slice.
13
+ *
14
+ * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').
15
+ * @param data - - The data representing the custom type or slice.
16
+ * @throws Error if the item status cannot be retrieved or the item cannot be
17
+ * created/updated.
18
+ */
19
+ private upsert;
20
+ private getRemoteItems;
21
+ private getDifference;
22
+ /** Create items only if they have changed compared to their remote status */
23
+ private upsertIfChanged;
24
+ /**
25
+ * Create Custom Types using the Custom types api.
26
+ *
27
+ * @param customTypes
28
+ */
29
+ createCustomTypes(customTypes?: StaticCustomTypeModel[]): Promise<void>;
30
+ deleteCustomType(customTypeId: string): Promise<void>;
31
+ /**
32
+ * Create slices using the Custom types api.
33
+ *
34
+ * @param slices
35
+ */
36
+ createSlices(slices?: SharedSliceModel[]): Promise<void>;
37
+ /**
38
+ * Get a custom type by its id.
39
+ *
40
+ * @param customTypeId - The id of the custom type to get.
41
+ */
42
+ getTypeById(customTypeId: string): Promise<StaticCustomTypeModel>;
43
+ }
44
+ //#endregion
45
+ export { CustomTypesApiClient };
46
+ //# sourceMappingURL=customTypesApi.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customTypesApi.d.cts","names":[],"sources":["../../src/clients/customTypesApi.ts"],"mappings":";;;;;cAYa,oBAAA,SAA6B,sBAAA;cAC7B,OAAA,UAAiB,MAAA;IAAU,SAAA,EAAW,eAAA;IAAiB,UAAA;EAAA;EA4EC;;;;;;;;EAAA,QAhEtD,MAAA;EAAA,QAeA,cAAA;EAAA,QAYA,aAAA;EAvCF;EAAA,QAyDE,eAAA;EAzDoC;;;;;EA4E5C,iBAAA,CAAkB,WAAA,GAAa,qBAAA,KAA+B,OAAA;EAI9D,gBAAA,CAAiB,YAAA,WAAuB,OAAA;EAJxC;;;;;EAmBA,YAAA,CAAa,MAAA,GAAQ,gBAAA,KAA0B,OAAA;EAfP;;;;;EAwBxC,WAAA,CAAY,YAAA,WAAuB,OAAA,CAAQ,qBAAA;AAAA"}
@@ -1,46 +1,46 @@
1
- import { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
- import { AuthServerToken, AuthenticatedApiClient } from "./apiClient";
3
- /**
4
- * Client for interacting with the Custom Types API to create/update custom
5
- * types and slices.
6
- */
7
- export declare class CustomTypesApiClient extends AuthenticatedApiClient {
8
- constructor(baseURL: string, config: {
9
- authToken: AuthServerToken;
10
- repository: string;
11
- });
12
- /**
13
- * Create or update a custom type or slice.
14
- *
15
- * @param endpoint - - The API endpoint for custom types or slices
16
- * ('customtypes' or 'slices').
17
- * @param data - - The data representing the custom type or slice.
18
- *
19
- * @throws Error if the item status cannot be retrieved or the item cannot be
20
- * created/updated.
21
- */
22
- private upsert;
23
- private getRemoteItems;
24
- private getDifference;
25
- /** Create items only if they have changed compared to their remote status */
26
- private upsertIfChanged;
27
- /**
28
- * Create Custom Types using the Custom types api.
29
- *
30
- * @param customTypes -
31
- */
32
- createCustomTypes(customTypes?: CustomType[]): Promise<void>;
33
- deleteCustomType(customTypeId: string): Promise<void>;
34
- /**
35
- * Create slices using the Custom types api.
36
- *
37
- * @param slices -
38
- */
39
- createSlices(slices?: SharedSlice[]): Promise<void>;
40
- /**
41
- * Get a custom type by its id.
42
- *
43
- * @param customTypeId - The id of the custom type to get.
44
- */
45
- getTypeById(customTypeId: string): Promise<CustomType>;
1
+ import { AuthServerToken, AuthenticatedApiClient } from "./apiClient.js";
2
+ import { SharedSliceModel, StaticCustomTypeModel } from "@prismicio/types-internal";
3
+
4
+ //#region src/clients/customTypesApi.d.ts
5
+ /** Client for interacting with the Custom Types API to create/update custom types and slices. */
6
+ declare class CustomTypesApiClient extends AuthenticatedApiClient {
7
+ constructor(baseURL: string, config: {
8
+ authToken: AuthServerToken;
9
+ repository: string;
10
+ });
11
+ /**
12
+ * Create or update a custom type or slice.
13
+ *
14
+ * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').
15
+ * @param data - - The data representing the custom type or slice.
16
+ * @throws Error if the item status cannot be retrieved or the item cannot be
17
+ * created/updated.
18
+ */
19
+ private upsert;
20
+ private getRemoteItems;
21
+ private getDifference;
22
+ /** Create items only if they have changed compared to their remote status */
23
+ private upsertIfChanged;
24
+ /**
25
+ * Create Custom Types using the Custom types api.
26
+ *
27
+ * @param customTypes
28
+ */
29
+ createCustomTypes(customTypes?: StaticCustomTypeModel[]): Promise<void>;
30
+ deleteCustomType(customTypeId: string): Promise<void>;
31
+ /**
32
+ * Create slices using the Custom types api.
33
+ *
34
+ * @param slices
35
+ */
36
+ createSlices(slices?: SharedSliceModel[]): Promise<void>;
37
+ /**
38
+ * Get a custom type by its id.
39
+ *
40
+ * @param customTypeId - The id of the custom type to get.
41
+ */
42
+ getTypeById(customTypeId: string): Promise<StaticCustomTypeModel>;
46
43
  }
44
+ //#endregion
45
+ export { CustomTypesApiClient };
46
+ //# sourceMappingURL=customTypesApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customTypesApi.d.ts","names":[],"sources":["../../src/clients/customTypesApi.ts"],"mappings":";;;;;cAYa,oBAAA,SAA6B,sBAAA;cAC7B,OAAA,UAAiB,MAAA;IAAU,SAAA,EAAW,eAAA;IAAiB,UAAA;EAAA;EA4EC;;;;;;;;EAAA,QAhEtD,MAAA;EAAA,QAeA,cAAA;EAAA,QAYA,aAAA;EAvCF;EAAA,QAyDE,eAAA;EAzDoC;;;;;EA4E5C,iBAAA,CAAkB,WAAA,GAAa,qBAAA,KAA+B,OAAA;EAI9D,gBAAA,CAAiB,YAAA,WAAuB,OAAA;EAJxC;;;;;EAmBA,YAAA,CAAa,MAAA,GAAQ,gBAAA,KAA0B,OAAA;EAfP;;;;;EAwBxC,WAAA,CAAY,YAAA,WAAuB,OAAA,CAAQ,qBAAA;AAAA"}
@@ -1,100 +1,89 @@
1
- import isEqual from "lodash.isequal";
2
- import { logger, logPlaywrightApiResponse } from "../utils/log.js";
1
+ import { logPlaywrightApiResponse, logger } from "../utils/log.js";
3
2
  import { AuthenticatedApiClient } from "./apiClient.js";
4
- class CustomTypesApiClient extends AuthenticatedApiClient {
5
- constructor(baseURL, config) {
6
- super(baseURL, config.authToken, { repository: config.repository });
7
- }
8
- /**
9
- * Create or update a custom type or slice.
10
- *
11
- * @param endpoint - - The API endpoint for custom types or slices
12
- * ('customtypes' or 'slices').
13
- * @param data - - The data representing the custom type or slice.
14
- *
15
- * @throws Error if the item status cannot be retrieved or the item cannot be
16
- * created/updated.
17
- */
18
- async upsert(endpoint, operation, data) {
19
- const profiler = logger.startTimer();
20
- const path = `${endpoint}/${operation}`;
21
- const context = await this.getContext();
22
- const result = await context.post(path, { data });
23
- if (!result.ok()) {
24
- logPlaywrightApiResponse(result);
25
- throw new Error(`Could not ${operation} item`);
26
- }
27
- profiler.done({
28
- message: `called customtypes api /${path} for item with id '${data.id}'`
29
- });
30
- }
31
- async getRemoteItems(endpoint) {
32
- const context = await this.getContext();
33
- const result = await context.get(endpoint);
34
- if (!result.ok()) {
35
- logPlaywrightApiResponse(result);
36
- throw new Error("Could not get items status from the Custom Type api.");
37
- }
38
- return result.json();
39
- }
40
- async getDifference(remoteItems, local) {
41
- const remoteItem = remoteItems.find((remote) => remote.id === local.id);
42
- if (!remoteItem) {
43
- return "insert";
44
- }
45
- if (!isEqual(local, remoteItem)) {
46
- return "update";
47
- }
48
- return;
49
- }
50
- /** Create items only if they have changed compared to their remote status */
51
- async upsertIfChanged(itemType, localItems = []) {
52
- const remoteItems = await this.getRemoteItems(itemType);
53
- await Promise.all(localItems.map(async (localItem) => {
54
- const operation = await this.getDifference(remoteItems, localItem);
55
- return operation && this.upsert(itemType, operation, localItem);
56
- }));
57
- }
58
- /**
59
- * Create Custom Types using the Custom types api.
60
- *
61
- * @param customTypes -
62
- */
63
- async createCustomTypes(customTypes = []) {
64
- await this.upsertIfChanged("customtypes", customTypes);
65
- }
66
- async deleteCustomType(customTypeId) {
67
- const context = await this.getContext();
68
- const result = await context.delete(`customtypes/${customTypeId}`);
69
- if (!result.ok()) {
70
- logPlaywrightApiResponse(result);
71
- throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`);
72
- }
73
- }
74
- /**
75
- * Create slices using the Custom types api.
76
- *
77
- * @param slices -
78
- */
79
- async createSlices(slices = []) {
80
- await this.upsertIfChanged("slices", slices);
81
- }
82
- /**
83
- * Get a custom type by its id.
84
- *
85
- * @param customTypeId - The id of the custom type to get.
86
- */
87
- async getTypeById(customTypeId) {
88
- const context = await this.getContext();
89
- const result = await context.get(`customtypes/${customTypeId}`);
90
- if (!result.ok()) {
91
- logPlaywrightApiResponse(result);
92
- throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`);
93
- }
94
- return result.json();
95
- }
96
- }
97
- export {
98
- CustomTypesApiClient
3
+ import isEqual from "lodash.isequal";
4
+ //#region src/clients/customTypesApi.ts
5
+ /** Client for interacting with the Custom Types API to create/update custom types and slices. */
6
+ var CustomTypesApiClient = class extends AuthenticatedApiClient {
7
+ constructor(baseURL, config) {
8
+ super(baseURL, config.authToken, { repository: config.repository });
9
+ }
10
+ /**
11
+ * Create or update a custom type or slice.
12
+ *
13
+ * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').
14
+ * @param data - - The data representing the custom type or slice.
15
+ * @throws Error if the item status cannot be retrieved or the item cannot be
16
+ * created/updated.
17
+ */
18
+ async upsert(endpoint, operation, data) {
19
+ const profiler = logger.startTimer();
20
+ const path = `${endpoint}/${operation}`;
21
+ const result = await (await this.getContext()).post(path, { data });
22
+ if (!result.ok()) {
23
+ logPlaywrightApiResponse(result);
24
+ throw new Error(`Could not ${operation} item`);
25
+ }
26
+ profiler.done({ message: `called customtypes api /${path} for item with id '${data.id}'` });
27
+ }
28
+ async getRemoteItems(endpoint) {
29
+ const result = await (await this.getContext()).get(endpoint);
30
+ if (!result.ok()) {
31
+ logPlaywrightApiResponse(result);
32
+ throw new Error("Could not get items status from the Custom Type api.");
33
+ }
34
+ return result.json();
35
+ }
36
+ async getDifference(remoteItems, local) {
37
+ const remoteItem = remoteItems.find((remote) => remote.id === local.id);
38
+ if (!remoteItem) return "insert";
39
+ if (!isEqual(local, remoteItem)) return "update";
40
+ }
41
+ /** Create items only if they have changed compared to their remote status */
42
+ async upsertIfChanged(itemType, localItems = []) {
43
+ const remoteItems = await this.getRemoteItems(itemType);
44
+ await Promise.all(localItems.map(async (localItem) => {
45
+ const operation = await this.getDifference(remoteItems, localItem);
46
+ return operation && this.upsert(itemType, operation, localItem);
47
+ }));
48
+ }
49
+ /**
50
+ * Create Custom Types using the Custom types api.
51
+ *
52
+ * @param customTypes
53
+ */
54
+ async createCustomTypes(customTypes = []) {
55
+ await this.upsertIfChanged("customtypes", customTypes);
56
+ }
57
+ async deleteCustomType(customTypeId) {
58
+ const result = await (await this.getContext()).delete(`customtypes/${customTypeId}`);
59
+ if (!result.ok()) {
60
+ logPlaywrightApiResponse(result);
61
+ throw new Error(`Could not delete ${customTypeId} from the Custom Type api.`);
62
+ }
63
+ }
64
+ /**
65
+ * Create slices using the Custom types api.
66
+ *
67
+ * @param slices
68
+ */
69
+ async createSlices(slices = []) {
70
+ await this.upsertIfChanged("slices", slices);
71
+ }
72
+ /**
73
+ * Get a custom type by its id.
74
+ *
75
+ * @param customTypeId - The id of the custom type to get.
76
+ */
77
+ async getTypeById(customTypeId) {
78
+ const result = await (await this.getContext()).get(`customtypes/${customTypeId}`);
79
+ if (!result.ok()) {
80
+ logPlaywrightApiResponse(result);
81
+ throw new Error(`Could not get ${customTypeId} type from the Custom Type api.`);
82
+ }
83
+ return result.json();
84
+ }
99
85
  };
100
- //# sourceMappingURL=customTypesApi.js.map
86
+ //#endregion
87
+ export { CustomTypesApiClient };
88
+
89
+ //# sourceMappingURL=customTypesApi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customTypesApi.js","sources":["../../../src/clients/customTypesApi.ts"],"sourcesContent":["import isEqual from \"lodash.isequal\";\n\nimport {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\";\n\nimport { AuthServerToken, AuthenticatedApiClient } from \"./apiClient\";\n\ntype ItemType = CustomType | SharedSlice;\ntype ItemTypePath = \"customtypes\" | \"slices\";\ntype ItemOperation = \"insert\" | \"update\";\n\n/**\n * Client for interacting with the Custom Types API to create/update custom\n * types and slices.\n */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(\n\t\tbaseURL: string,\n\t\tconfig: { authToken: AuthServerToken; repository: string },\n\t) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository });\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices\n\t * ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t *\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(\n\t\tendpoint: ItemTypePath,\n\t\toperation: ItemOperation,\n\t\tdata: ItemType,\n\t) {\n\t\tconst profiler = logger.startTimer();\n\t\tconst path = `${endpoint}/${operation}`;\n\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.post(path, { data });\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(`Could not ${operation} item`);\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t});\n\t}\n\n\tprivate async getRemoteItems(\n\t\tendpoint: ItemTypePath,\n\t): Promise<CustomType[] | SharedSlice[]> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(endpoint);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\");\n\t\t}\n\n\t\treturn result.json();\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: CustomType[] | SharedSlice[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: CustomType | SharedSlice) => remote.id === local.id,\n\t\t);\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\";\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\";\n\t\t}\n\n\t\treturn;\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType);\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem);\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem);\n\t\t\t}),\n\t\t);\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes -\n\t */\n\tasync createCustomTypes(customTypes: CustomType[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes);\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.delete(`customtypes/${customTypeId}`);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not delete ${customTypeId} from the Custom Type api.`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices -\n\t */\n\tasync createSlices(slices: SharedSlice[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices);\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<CustomType> {\n\t\tconst context = await this.getContext();\n\t\tconst result = await context.get(`customtypes/${customTypeId}`);\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result);\n\t\t\tthrow new Error(\n\t\t\t\t`Could not get ${customTypeId} type from the Custom Type api.`,\n\t\t\t);\n\t\t}\n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AClC,YAAM,YAAY,MAAM,KAAK,cAAc,aAAa,SAAS;AAEjE,aAAO,aAAa,KAAK,OAAO,UAAU,WAAW,SAAS;AAAA,IAC9D,CAAA,CAAC;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,cAA4B,IAAE;AAC/C,UAAA,KAAK,gBAAgB,eAAe,WAAW;AAAA,EACtD;AAAA,EAEA,MAAM,iBAAiB,cAAoB;AACpC,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,OAAO,eAAe,YAAY,EAAE;AAE7D,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AAC/B,YAAM,IAAI,MACT,oBAAoB,YAAY,4BAA4B;AAAA,IAE9D;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,SAAwB,IAAE;AACtC,UAAA,KAAK,gBAAgB,UAAU,MAAM;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,YAAY,cAAoB;AAC/B,UAAA,UAAU,MAAM,KAAK;AAC3B,UAAM,SAAS,MAAM,QAAQ,IAAI,eAAe,YAAY,EAAE;AAE1D,QAAA,CAAC,OAAO,MAAM;AACjB,+BAAyB,MAAM;AAC/B,YAAM,IAAI,MACT,iBAAiB,YAAY,iCAAiC;AAAA,IAEhE;AAEA,WAAO,OAAO;EACf;AACA;"}
1
+ {"version":3,"file":"customTypesApi.js","names":[],"sources":["../../src/clients/customTypesApi.ts"],"sourcesContent":["import type { StaticCustomTypeModel, SharedSliceModel } from \"@prismicio/types-internal\"\nimport isEqual from \"lodash.isequal\"\n\nimport { logPlaywrightApiResponse, logger } from \"../utils/log\"\nimport type { AuthServerToken } from \"./apiClient\"\nimport { AuthenticatedApiClient } from \"./apiClient\"\n\ntype ItemType = StaticCustomTypeModel | SharedSliceModel\ntype ItemTypePath = \"customtypes\" | \"slices\"\ntype ItemOperation = \"insert\" | \"update\"\n\n/** Client for interacting with the Custom Types API to create/update custom types and slices. */\nexport class CustomTypesApiClient extends AuthenticatedApiClient {\n\tconstructor(baseURL: string, config: { authToken: AuthServerToken; repository: string }) {\n\t\tsuper(baseURL, config.authToken, { repository: config.repository })\n\t}\n\n\t/**\n\t * Create or update a custom type or slice.\n\t *\n\t * @param endpoint - - The API endpoint for custom types or slices ('customtypes' or 'slices').\n\t * @param data - - The data representing the custom type or slice.\n\t * @throws Error if the item status cannot be retrieved or the item cannot be\n\t * created/updated.\n\t */\n\tprivate async upsert(endpoint: ItemTypePath, operation: ItemOperation, data: ItemType) {\n\t\tconst profiler = logger.startTimer()\n\t\tconst path = `${endpoint}/${operation}`\n\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.post(path, { data })\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not ${operation} item`)\n\t\t}\n\t\tprofiler.done({\n\t\t\tmessage: `called customtypes api /${path} for item with id '${data.id}'`,\n\t\t})\n\t}\n\n\tprivate async getRemoteItems(endpoint: ItemTypePath): Promise<StaticCustomTypeModel[] | SharedSliceModel[]> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.get(endpoint)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(\"Could not get items status from the Custom Type api.\")\n\t\t}\n\n\t\treturn result.json()\n\t}\n\n\tprivate async getDifference(\n\t\tremoteItems: StaticCustomTypeModel[] | SharedSliceModel[],\n\t\tlocal: ItemType,\n\t): Promise<ItemOperation | undefined> {\n\t\tconst remoteItem = remoteItems.find(\n\t\t\t(remote: StaticCustomTypeModel | SharedSliceModel) => remote.id === local.id,\n\t\t)\n\t\tif (!remoteItem) {\n\t\t\treturn \"insert\"\n\t\t}\n\t\tif (!isEqual(local, remoteItem)) {\n\t\t\treturn \"update\"\n\t\t}\n\n\t\treturn\n\t}\n\n\t/** Create items only if they have changed compared to their remote status */\n\tprivate async upsertIfChanged(\n\t\titemType: ItemTypePath,\n\t\tlocalItems: ItemType[] = [],\n\t): Promise<void> {\n\t\tconst remoteItems = await this.getRemoteItems(itemType)\n\t\tawait Promise.all(\n\t\t\tlocalItems.map(async (localItem) => {\n\t\t\t\tconst operation = await this.getDifference(remoteItems, localItem)\n\n\t\t\t\treturn operation && this.upsert(itemType, operation, localItem)\n\t\t\t}),\n\t\t)\n\t}\n\n\t/**\n\t * Create Custom Types using the Custom types api.\n\t *\n\t * @param customTypes\n\t */\n\tasync createCustomTypes(customTypes: StaticCustomTypeModel[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"customtypes\", customTypes)\n\t}\n\n\tasync deleteCustomType(customTypeId: string): Promise<void> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.delete(`customtypes/${customTypeId}`)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not delete ${customTypeId} from the Custom Type api.`)\n\t\t}\n\t}\n\n\t/**\n\t * Create slices using the Custom types api.\n\t *\n\t * @param slices\n\t */\n\tasync createSlices(slices: SharedSliceModel[] = []): Promise<void> {\n\t\tawait this.upsertIfChanged(\"slices\", slices)\n\t}\n\n\t/**\n\t * Get a custom type by its id.\n\t *\n\t * @param customTypeId - The id of the custom type to get.\n\t */\n\tasync getTypeById(customTypeId: string): Promise<StaticCustomTypeModel> {\n\t\tconst context = await this.getContext()\n\t\tconst result = await context.get(`customtypes/${customTypeId}`)\n\n\t\tif (!result.ok()) {\n\t\t\tlogPlaywrightApiResponse(result)\n\t\t\tthrow new Error(`Could not get ${customTypeId} type from the Custom Type api.`)\n\t\t}\n\n\t\treturn result.json()\n\t}\n}\n"],"mappings":";;;;;AAYA,IAAa,uBAAb,cAA0C,uBAAuB;CAChE,YAAY,SAAiB,QAA4D;EACxF,MAAM,SAAS,OAAO,WAAW,EAAE,YAAY,OAAO,WAAW,CAAC;CACnE;;;;;;;;;CAUA,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