@intlayer/api 9.6.0 → 9.7.1

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 (206) hide show
  1. package/dist/cjs/cms/createAuthManager.cjs +2 -3
  2. package/dist/cjs/cms/createIntlayerCMS.cjs +2 -3
  3. package/dist/cjs/cms/index.cjs +2 -2
  4. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +3 -4
  5. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
  6. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +3 -4
  7. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
  8. package/dist/cjs/distantDictionary/index.cjs +2 -2
  9. package/dist/cjs/fetcher.cjs +2 -3
  10. package/dist/cjs/fetcher.cjs.map +1 -1
  11. package/dist/cjs/getIntlayerAPI/ai.cjs +79 -26
  12. package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
  13. package/dist/cjs/getIntlayerAPI/analytics.cjs +47 -14
  14. package/dist/cjs/getIntlayerAPI/analytics.cjs.map +1 -1
  15. package/dist/cjs/getIntlayerAPI/asset.cjs +41 -12
  16. package/dist/cjs/getIntlayerAPI/asset.cjs.map +1 -1
  17. package/dist/cjs/getIntlayerAPI/audit.cjs +73 -20
  18. package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
  19. package/dist/cjs/getIntlayerAPI/bitbucket.cjs +42 -13
  20. package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
  21. package/dist/cjs/getIntlayerAPI/codeberg.cjs +20 -0
  22. package/dist/cjs/getIntlayerAPI/codeberg.cjs.map +1 -0
  23. package/dist/cjs/getIntlayerAPI/dictionary.cjs +62 -17
  24. package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
  25. package/dist/cjs/getIntlayerAPI/editor.cjs +3 -4
  26. package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
  27. package/dist/cjs/getIntlayerAPI/environment.cjs +47 -14
  28. package/dist/cjs/getIntlayerAPI/environment.cjs.map +1 -1
  29. package/dist/cjs/getIntlayerAPI/forge.cjs +63 -0
  30. package/dist/cjs/getIntlayerAPI/forge.cjs.map +1 -0
  31. package/dist/cjs/getIntlayerAPI/gitee.cjs +20 -0
  32. package/dist/cjs/getIntlayerAPI/gitee.cjs.map +1 -0
  33. package/dist/cjs/getIntlayerAPI/github.cjs +47 -14
  34. package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
  35. package/dist/cjs/getIntlayerAPI/gitlab.cjs +42 -13
  36. package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
  37. package/dist/cjs/getIntlayerAPI/index.cjs +27 -24
  38. package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
  39. package/dist/cjs/getIntlayerAPI/newsletter.cjs +31 -10
  40. package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
  41. package/dist/cjs/getIntlayerAPI/oAuth.cjs +33 -8
  42. package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
  43. package/dist/cjs/getIntlayerAPI/organization.cjs +75 -24
  44. package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
  45. package/dist/cjs/getIntlayerAPI/project.cjs +115 -33
  46. package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
  47. package/dist/cjs/getIntlayerAPI/reviewer.cjs +145 -35
  48. package/dist/cjs/getIntlayerAPI/reviewer.cjs.map +1 -1
  49. package/dist/cjs/getIntlayerAPI/search.cjs +18 -7
  50. package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
  51. package/dist/cjs/getIntlayerAPI/showcaseProject.cjs +64 -19
  52. package/dist/cjs/getIntlayerAPI/showcaseProject.cjs.map +1 -1
  53. package/dist/cjs/getIntlayerAPI/status.cjs +19 -7
  54. package/dist/cjs/getIntlayerAPI/status.cjs.map +1 -1
  55. package/dist/cjs/getIntlayerAPI/stripe.cjs +144 -39
  56. package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
  57. package/dist/cjs/getIntlayerAPI/tag.cjs +36 -11
  58. package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
  59. package/dist/cjs/getIntlayerAPI/translate.cjs +49 -12
  60. package/dist/cjs/getIntlayerAPI/translate.cjs.map +1 -1
  61. package/dist/cjs/getIntlayerAPI/user.cjs +61 -18
  62. package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
  63. package/dist/cjs/index.cjs +38 -30
  64. package/dist/cjs/proxy.cjs +28 -25
  65. package/dist/cjs/proxy.cjs.map +1 -1
  66. package/dist/cjs/public/createPublicClient.cjs +26 -7
  67. package/dist/cjs/public/createPublicClient.cjs.map +1 -1
  68. package/dist/cjs/public/index.cjs +1 -1
  69. package/dist/cjs/resolveInternalBackendUrl.cjs +1 -2
  70. package/dist/esm/cms/createAuthManager.mjs +1 -2
  71. package/dist/esm/cms/createIntlayerCMS.mjs +1 -2
  72. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +1 -2
  73. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
  74. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +1 -2
  75. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
  76. package/dist/esm/fetcher.mjs +1 -2
  77. package/dist/esm/fetcher.mjs.map +1 -1
  78. package/dist/esm/getIntlayerAPI/ai.mjs +78 -25
  79. package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
  80. package/dist/esm/getIntlayerAPI/analytics.mjs +46 -13
  81. package/dist/esm/getIntlayerAPI/analytics.mjs.map +1 -1
  82. package/dist/esm/getIntlayerAPI/asset.mjs +40 -11
  83. package/dist/esm/getIntlayerAPI/asset.mjs.map +1 -1
  84. package/dist/esm/getIntlayerAPI/audit.mjs +72 -19
  85. package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
  86. package/dist/esm/getIntlayerAPI/bitbucket.mjs +41 -12
  87. package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
  88. package/dist/esm/getIntlayerAPI/codeberg.mjs +18 -0
  89. package/dist/esm/getIntlayerAPI/codeberg.mjs.map +1 -0
  90. package/dist/esm/getIntlayerAPI/dictionary.mjs +61 -16
  91. package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
  92. package/dist/esm/getIntlayerAPI/editor.mjs +2 -3
  93. package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
  94. package/dist/esm/getIntlayerAPI/environment.mjs +46 -13
  95. package/dist/esm/getIntlayerAPI/environment.mjs.map +1 -1
  96. package/dist/esm/getIntlayerAPI/forge.mjs +62 -0
  97. package/dist/esm/getIntlayerAPI/forge.mjs.map +1 -0
  98. package/dist/esm/getIntlayerAPI/gitee.mjs +18 -0
  99. package/dist/esm/getIntlayerAPI/gitee.mjs.map +1 -0
  100. package/dist/esm/getIntlayerAPI/github.mjs +46 -13
  101. package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
  102. package/dist/esm/getIntlayerAPI/gitlab.mjs +41 -12
  103. package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
  104. package/dist/esm/getIntlayerAPI/index.mjs +6 -3
  105. package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
  106. package/dist/esm/getIntlayerAPI/newsletter.mjs +30 -9
  107. package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
  108. package/dist/esm/getIntlayerAPI/oAuth.mjs +32 -7
  109. package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
  110. package/dist/esm/getIntlayerAPI/organization.mjs +74 -23
  111. package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
  112. package/dist/esm/getIntlayerAPI/project.mjs +114 -32
  113. package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
  114. package/dist/esm/getIntlayerAPI/reviewer.mjs +144 -34
  115. package/dist/esm/getIntlayerAPI/reviewer.mjs.map +1 -1
  116. package/dist/esm/getIntlayerAPI/search.mjs +17 -6
  117. package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
  118. package/dist/esm/getIntlayerAPI/showcaseProject.mjs +63 -18
  119. package/dist/esm/getIntlayerAPI/showcaseProject.mjs.map +1 -1
  120. package/dist/esm/getIntlayerAPI/status.mjs +18 -6
  121. package/dist/esm/getIntlayerAPI/status.mjs.map +1 -1
  122. package/dist/esm/getIntlayerAPI/stripe.mjs +143 -38
  123. package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
  124. package/dist/esm/getIntlayerAPI/tag.mjs +35 -10
  125. package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
  126. package/dist/esm/getIntlayerAPI/translate.mjs +48 -11
  127. package/dist/esm/getIntlayerAPI/translate.mjs.map +1 -1
  128. package/dist/esm/getIntlayerAPI/user.mjs +60 -17
  129. package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
  130. package/dist/esm/index.mjs +10 -7
  131. package/dist/esm/proxy.mjs +6 -3
  132. package/dist/esm/proxy.mjs.map +1 -1
  133. package/dist/esm/public/createPublicClient.mjs +26 -7
  134. package/dist/esm/public/createPublicClient.mjs.map +1 -1
  135. package/dist/esm/resolveInternalBackendUrl.mjs +1 -2
  136. package/dist/types/cms/createAuthManager.d.ts +1 -2
  137. package/dist/types/cms/createAuthManager.d.ts.map +1 -1
  138. package/dist/types/cms/createIntlayerCMS.d.ts +0 -2
  139. package/dist/types/cms/createIntlayerCMS.d.ts.map +1 -1
  140. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +1 -3
  141. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
  142. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -3
  143. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
  144. package/dist/types/fetcher.d.ts +1 -3
  145. package/dist/types/fetcher.d.ts.map +1 -1
  146. package/dist/types/getIntlayerAPI/ai.d.ts +3 -5
  147. package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
  148. package/dist/types/getIntlayerAPI/analytics.d.ts +3 -5
  149. package/dist/types/getIntlayerAPI/analytics.d.ts.map +1 -1
  150. package/dist/types/getIntlayerAPI/asset.d.ts +3 -4
  151. package/dist/types/getIntlayerAPI/asset.d.ts.map +1 -1
  152. package/dist/types/getIntlayerAPI/audit.d.ts +49 -7
  153. package/dist/types/getIntlayerAPI/audit.d.ts.map +1 -1
  154. package/dist/types/getIntlayerAPI/bitbucket.d.ts +2 -4
  155. package/dist/types/getIntlayerAPI/bitbucket.d.ts.map +1 -1
  156. package/dist/types/getIntlayerAPI/codeberg.d.ts +59 -0
  157. package/dist/types/getIntlayerAPI/codeberg.d.ts.map +1 -0
  158. package/dist/types/getIntlayerAPI/dictionary.d.ts +3 -5
  159. package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
  160. package/dist/types/getIntlayerAPI/editor.d.ts +4 -5
  161. package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
  162. package/dist/types/getIntlayerAPI/environment.d.ts +3 -5
  163. package/dist/types/getIntlayerAPI/environment.d.ts.map +1 -1
  164. package/dist/types/getIntlayerAPI/forge.d.ts +34 -0
  165. package/dist/types/getIntlayerAPI/forge.d.ts.map +1 -0
  166. package/dist/types/getIntlayerAPI/gitee.d.ts +59 -0
  167. package/dist/types/getIntlayerAPI/gitee.d.ts.map +1 -0
  168. package/dist/types/getIntlayerAPI/github.d.ts +2 -4
  169. package/dist/types/getIntlayerAPI/github.d.ts.map +1 -1
  170. package/dist/types/getIntlayerAPI/gitlab.d.ts +2 -4
  171. package/dist/types/getIntlayerAPI/gitlab.d.ts.map +1 -1
  172. package/dist/types/getIntlayerAPI/index.d.ts +6 -3
  173. package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
  174. package/dist/types/getIntlayerAPI/newsletter.d.ts +3 -5
  175. package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
  176. package/dist/types/getIntlayerAPI/oAuth.d.ts +2 -2
  177. package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
  178. package/dist/types/getIntlayerAPI/organization.d.ts +3 -7
  179. package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
  180. package/dist/types/getIntlayerAPI/project.d.ts +4 -5
  181. package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
  182. package/dist/types/getIntlayerAPI/reviewer.d.ts +682 -39
  183. package/dist/types/getIntlayerAPI/reviewer.d.ts.map +1 -1
  184. package/dist/types/getIntlayerAPI/search.d.ts +3 -5
  185. package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
  186. package/dist/types/getIntlayerAPI/showcaseProject.d.ts +3 -5
  187. package/dist/types/getIntlayerAPI/showcaseProject.d.ts.map +1 -1
  188. package/dist/types/getIntlayerAPI/status.d.ts +5 -8
  189. package/dist/types/getIntlayerAPI/status.d.ts.map +1 -1
  190. package/dist/types/getIntlayerAPI/stripe.d.ts +3 -5
  191. package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
  192. package/dist/types/getIntlayerAPI/tag.d.ts +3 -5
  193. package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
  194. package/dist/types/getIntlayerAPI/translate.d.ts +3 -5
  195. package/dist/types/getIntlayerAPI/translate.d.ts.map +1 -1
  196. package/dist/types/getIntlayerAPI/user.d.ts +6 -8
  197. package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
  198. package/dist/types/index.d.ts +12 -9
  199. package/dist/types/proxy.d.ts +0 -2
  200. package/dist/types/proxy.d.ts.map +1 -1
  201. package/dist/types/public/createPublicClient.d.ts +1 -9
  202. package/dist/types/public/createPublicClient.d.ts.map +1 -1
  203. package/dist/types/resolveInternalBackendUrl.d.ts +0 -2
  204. package/dist/types/resolveInternalBackendUrl.d.ts.map +1 -1
  205. package/dist/types/types.d.ts +5 -2
  206. package/package.json +23 -6
@@ -1,18 +1,48 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_fetcher = require('../fetcher.cjs');
3
- const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.cjs');
2
+ const require_cms_createIntlayerCMS = require("../cms/createIntlayerCMS.cjs");
3
+ const require_fetcher = require("../fetcher.cjs");
4
4
  let _intlayer_config_built = require("@intlayer/config/built");
5
+ let _intlayer_backend_contract_defineRoute = require("@intlayer/backend-contract/defineRoute");
6
+ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
5
7
 
6
- //#region src/getIntlayerAPI/asset.ts
8
+ // src/getIntlayerAPI/asset.ts
9
+ /** Prefix of the routes, checked against the backend contract. */
10
+ const assetGroup = { prefix: "/api/assets" };
11
+ /**
12
+ * Method and path of every route, checked against the backend contract at
13
+ * compile time (the contract's zod schemas are never loaded).
14
+ */
15
+ const assetEndpoints = {
16
+ getAssets: {
17
+ method: "GET",
18
+ path: "/"
19
+ },
20
+ getAssetById: {
21
+ method: "GET",
22
+ path: "/:assetId"
23
+ },
24
+ uploadAsset: {
25
+ method: "POST",
26
+ path: "/"
27
+ },
28
+ updateAsset: {
29
+ method: "PATCH",
30
+ path: "/:assetId"
31
+ },
32
+ deleteAsset: {
33
+ method: "DELETE",
34
+ path: "/:assetId"
35
+ }
36
+ };
7
37
  const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
8
- const ASSET_API_ROUTE = `${intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL}/api/assets`;
38
+ const backendURL = intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL ?? _intlayer_config_defaultValues.BACKEND_URL;
9
39
  /**
10
40
  * Retrieves all assets for the current session project, paginated.
11
41
  * @param page - Page number (1-based).
12
42
  * @param pageSize - Number of items per page.
13
43
  * @returns Paginated list of assets.
14
44
  */
15
- const getAssets = async (page, pageSize, otherOptions = {}) => await require_fetcher.fetcher(ASSET_API_ROUTE, authAPIOptions, otherOptions, {
45
+ const getAssets = async (page, pageSize, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, assetGroup, assetEndpoints.getAssets), authAPIOptions, otherOptions, {
16
46
  cache: "no-store",
17
47
  params: {
18
48
  ...page !== void 0 && { page: String(page) },
@@ -24,7 +54,7 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
24
54
  * @param assetId - The asset document ID.
25
55
  * @returns The asset.
26
56
  */
27
- const getAssetById = async (assetId, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { cache: "no-store" });
57
+ const getAssetById = async (assetId, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, assetGroup, assetEndpoints.getAssetById, { assetId: String(assetId) }), authAPIOptions, otherOptions, { cache: "no-store" });
28
58
  /**
29
59
  * Uploads a new asset image.
30
60
  * @param file - The image File object.
@@ -41,8 +71,8 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
41
71
  if (alt) headers["X-Alt-Text"] = alt;
42
72
  if (caption) headers["X-Caption"] = caption;
43
73
  const authHeaders = authAPIOptions.headers ?? {};
44
- const response = await fetch(ASSET_API_ROUTE, {
45
- method: "POST",
74
+ const response = await fetch((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, assetGroup, assetEndpoints.uploadAsset), {
75
+ method: assetEndpoints.uploadAsset.method,
46
76
  credentials: "include",
47
77
  headers: {
48
78
  ...authHeaders,
@@ -63,8 +93,8 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
63
93
  * @param data - Fields to update.
64
94
  * @returns The updated asset record.
65
95
  */
66
- const updateAsset = async (assetId, data, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, {
67
- method: "PATCH",
96
+ const updateAsset = async (assetId, data, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, assetGroup, assetEndpoints.updateAsset, { assetId: String(assetId) }), authAPIOptions, otherOptions, {
97
+ method: assetEndpoints.updateAsset.method,
68
98
  body: data
69
99
  });
70
100
  /**
@@ -72,7 +102,7 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
72
102
  * @param assetId - The asset document ID.
73
103
  * @returns Confirmation response.
74
104
  */
75
- const deleteAsset = async (assetId, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { method: "DELETE" });
105
+ const deleteAsset = async (assetId, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, assetGroup, assetEndpoints.deleteAsset, { assetId: String(assetId) }), authAPIOptions, otherOptions, { method: assetEndpoints.deleteAsset.method });
76
106
  return {
77
107
  getAssets,
78
108
  getAssetById,
@@ -89,7 +119,6 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
89
119
  */
90
120
  const assetEndpoint = require_cms_createIntlayerCMS.createEndpoint(getAssetAPI);
91
121
 
92
- //#endregion
93
122
  exports.assetEndpoint = assetEndpoint;
94
123
  exports.getAssetAPI = getAssetAPI;
95
124
  //# sourceMappingURL=asset.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset.cjs","names":["editor","fetcher","createEndpoint"],"sources":["../../../src/getIntlayerAPI/asset.ts"],"sourcesContent":["import type {\n DeleteAssetResult,\n GetAssetByIdResult,\n GetAssetsResult,\n UpdateAssetResult,\n UploadAssetResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getAssetAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const ASSET_API_ROUTE = `${backendURL}/api/assets`;\n\n /**\n * Retrieves all assets for the current session project, paginated.\n * @param page - Page number (1-based).\n * @param pageSize - Number of items per page.\n * @returns Paginated list of assets.\n */\n const getAssets = async (\n page?: number,\n pageSize?: number,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetsResult>(\n ASSET_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n ...(page !== undefined && { page: String(page) }),\n ...(pageSize !== undefined && { pageSize: String(pageSize) }),\n },\n }\n );\n\n /**\n * Retrieves a single asset by ID.\n * @param assetId - The asset document ID.\n * @returns The asset.\n */\n const getAssetById = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetByIdResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { cache: 'no-store' }\n );\n\n /**\n * Uploads a new asset image.\n * @param file - The image File object.\n * @param alt - Optional alt text.\n * @param caption - Optional caption.\n * @returns The created asset record with its public URL.\n */\n const uploadAsset = async (\n file: File,\n alt?: string,\n caption?: string,\n otherOptions: FetcherOptions = {}\n ) => {\n const buffer = await file.arrayBuffer();\n\n const headers: Record<string, string> = {\n 'Content-Type': file.type || 'image/jpeg',\n 'X-File-Name': file.name,\n };\n\n if (alt) headers['X-Alt-Text'] = alt;\n if (caption) headers['X-Caption'] = caption;\n\n const authHeaders =\n (authAPIOptions.headers as Record<string, string> | undefined) ?? {};\n\n const response = await fetch(ASSET_API_ROUTE, {\n method: 'POST',\n credentials: 'include',\n headers: { ...authHeaders, ...headers },\n body: buffer,\n signal: otherOptions.signal as AbortSignal | undefined,\n });\n\n if (!response.ok) {\n const result = await response.json();\n throw new Error(JSON.stringify(result.error) ?? 'Asset upload failed');\n }\n\n return (await response.json()) as UploadAssetResult;\n };\n\n /**\n * Updates mutable metadata (name, alt text, caption) of an asset.\n * @param assetId - The asset document ID.\n * @param data - Fields to update.\n * @returns The updated asset record.\n */\n const updateAsset = async (\n assetId: string,\n data: { originalName?: string; alt?: string; caption?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'PATCH', body: data as unknown as Record<string, unknown> }\n );\n\n /**\n * Deletes an asset by ID.\n * @param assetId - The asset document ID.\n * @returns Confirmation response.\n */\n const deleteAsset = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n return {\n getAssets,\n getAssetById,\n uploadAsset,\n updateAsset,\n deleteAsset,\n };\n};\n\n/**\n * Authenticated `asset` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const assetEndpoint = createEndpoint(getAssetAPI);\n"],"mappings":";;;;;;AAYA,MAAa,eACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,kBAAkB,GAFL,gBAAgB,QAAQ,cAAcA,8BAAO,WAE1B;;;;;;;CAQtC,MAAM,YAAY,OAChB,MACA,UACA,eAA+B,CAAC,MAEhC,MAAMC,wBACJ,iBACA,gBACA,cACA;EACE,OAAO;EACP,QAAQ;GACN,GAAI,SAAS,UAAa,EAAE,MAAM,OAAO,IAAI,EAAE;GAC/C,GAAI,aAAa,UAAa,EAAE,UAAU,OAAO,QAAQ,EAAE;EAC7D;CACF,CACF;;;;;;CAOF,MAAM,eAAe,OACnB,SACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA,EAAE,OAAO,WAAW,CACtB;;;;;;;;CASF,MAAM,cAAc,OAClB,MACA,KACA,SACA,eAA+B,CAAC,MAC7B;EACH,MAAM,SAAS,MAAM,KAAK,YAAY;EAEtC,MAAM,UAAkC;GACtC,gBAAgB,KAAK,QAAQ;GAC7B,eAAe,KAAK;EACtB;EAEA,IAAI,KAAK,QAAQ,gBAAgB;EACjC,IAAI,SAAS,QAAQ,eAAe;EAEpC,MAAM,cACH,eAAe,WAAkD,CAAC;EAErE,MAAM,WAAW,MAAM,MAAM,iBAAiB;GAC5C,QAAQ;GACR,aAAa;GACb,SAAS;IAAE,GAAG;IAAa,GAAG;GAAQ;GACtC,MAAM;GACN,QAAQ,aAAa;EACvB,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,SAAS,MAAM,SAAS,KAAK;GACnC,MAAM,IAAI,MAAM,KAAK,UAAU,OAAO,KAAK,KAAK,qBAAqB;EACvE;EAEA,OAAQ,MAAM,SAAS,KAAK;CAC9B;;;;;;;CAQA,MAAM,cAAc,OAClB,SACA,MACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA;EAAE,QAAQ;EAAS,MAAM;CAA2C,CACtE;;;;;;CAOF,MAAM,cAAc,OAClB,SACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA,EAAE,QAAQ,SAAS,CACrB;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,gBAAgBC,6CAAe,WAAW"}
1
+ {"version":3,"file":"asset.cjs","names":["editor","BACKEND_URL","fetcher","buildRouteURL","createEndpoint"],"sources":["../../../src/getIntlayerAPI/asset.ts"],"sourcesContent":["import type {\n AssetRoutes,\n assetContract,\n DeleteAssetResult,\n GetAssetByIdResult,\n GetAssetsResult,\n UpdateAssetResult,\n UploadAssetResult,\n} from '@intlayer/backend-contract/asset';\nimport type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\n/** Prefix of the routes, checked against the backend contract. */\nconst assetGroup = {\n prefix: '/api/assets',\n} as const satisfies Pick<typeof assetContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst assetEndpoints = {\n getAssets: { method: 'GET', path: '/' },\n getAssetById: { method: 'GET', path: '/:assetId' },\n uploadAsset: { method: 'POST', path: '/' },\n updateAsset: { method: 'PATCH', path: '/:assetId' },\n deleteAsset: { method: 'DELETE', path: '/:assetId' },\n} as const satisfies RouteEndpoints<AssetRoutes>;\n\nexport const getAssetAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Retrieves all assets for the current session project, paginated.\n * @param page - Page number (1-based).\n * @param pageSize - Number of items per page.\n * @returns Paginated list of assets.\n */\n const getAssets = async (\n page?: number,\n pageSize?: number,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetsResult>(\n buildRouteURL(backendURL, assetGroup, assetEndpoints.getAssets),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n ...(page !== undefined && { page: String(page) }),\n ...(pageSize !== undefined && { pageSize: String(pageSize) }),\n },\n }\n );\n\n /**\n * Retrieves a single asset by ID.\n * @param assetId - The asset document ID.\n * @returns The asset.\n */\n const getAssetById = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetByIdResult>(\n buildRouteURL(backendURL, assetGroup, assetEndpoints.getAssetById, {\n assetId: String(assetId),\n }),\n authAPIOptions,\n otherOptions,\n { cache: 'no-store' }\n );\n\n /**\n * Uploads a new asset image.\n * @param file - The image File object.\n * @param alt - Optional alt text.\n * @param caption - Optional caption.\n * @returns The created asset record with its public URL.\n */\n const uploadAsset = async (\n file: File,\n alt?: string,\n caption?: string,\n otherOptions: FetcherOptions = {}\n ) => {\n const buffer = await file.arrayBuffer();\n\n const headers: Record<string, string> = {\n 'Content-Type': file.type || 'image/jpeg',\n 'X-File-Name': file.name,\n };\n\n if (alt) headers['X-Alt-Text'] = alt;\n if (caption) headers['X-Caption'] = caption;\n\n const authHeaders =\n (authAPIOptions.headers as Record<string, string> | undefined) ?? {};\n\n const response = await fetch(\n buildRouteURL(backendURL, assetGroup, assetEndpoints.uploadAsset),\n {\n method: assetEndpoints.uploadAsset.method,\n credentials: 'include',\n headers: { ...authHeaders, ...headers },\n body: buffer,\n signal: otherOptions.signal as AbortSignal | undefined,\n }\n );\n\n if (!response.ok) {\n const result = await response.json();\n throw new Error(JSON.stringify(result.error) ?? 'Asset upload failed');\n }\n\n return (await response.json()) as UploadAssetResult;\n };\n\n /**\n * Updates mutable metadata (name, alt text, caption) of an asset.\n * @param assetId - The asset document ID.\n * @param data - Fields to update.\n * @returns The updated asset record.\n */\n const updateAsset = async (\n assetId: string,\n data: { originalName?: string; alt?: string; caption?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAssetResult>(\n buildRouteURL(backendURL, assetGroup, assetEndpoints.updateAsset, {\n assetId: String(assetId),\n }),\n authAPIOptions,\n otherOptions,\n {\n method: assetEndpoints.updateAsset.method,\n body: data as unknown as Record<string, unknown>,\n }\n );\n\n /**\n * Deletes an asset by ID.\n * @param assetId - The asset document ID.\n * @returns Confirmation response.\n */\n const deleteAsset = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAssetResult>(\n buildRouteURL(backendURL, assetGroup, assetEndpoints.deleteAsset, {\n assetId: String(assetId),\n }),\n authAPIOptions,\n otherOptions,\n { method: assetEndpoints.deleteAsset.method }\n );\n\n return {\n getAssets,\n getAssetById,\n uploadAsset,\n updateAsset,\n deleteAsset,\n };\n};\n\n/**\n * Authenticated `asset` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const assetEndpoint = createEndpoint(getAssetAPI);\n"],"mappings":";;;;;;;;;AAkBA,MAAM,aAAa,EACjB,QAAQ,cACV;;;;;AAMA,MAAM,iBAAiB;CACrB,WAAW;EAAE,QAAQ;EAAO,MAAM;CAAI;CACtC,cAAc;EAAE,QAAQ;EAAO,MAAM;CAAY;CACjD,aAAa;EAAE,QAAQ;EAAQ,MAAM;CAAI;CACzC,aAAa;EAAE,QAAQ;EAAS,MAAM;CAAY;CAClD,aAAa;EAAE,QAAQ;EAAU,MAAM;CAAY;AACrD;AAEA,MAAa,eACX,iBAAiC,CAAC,GAClC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAcA,8BAAO,cAAcC;;;;;;;CAQ7D,MAAM,YAAY,OAChB,MACA,UACA,eAA+B,CAAC,MAEhC,MAAMC,4BACJC,sDAAc,YAAY,YAAY,eAAe,SAAS,GAC9D,gBACA,cACA;EACE,OAAO;EACP,QAAQ;GACN,GAAI,SAAS,UAAa,EAAE,MAAM,OAAO,IAAI,EAAE;GAC/C,GAAI,aAAa,UAAa,EAAE,UAAU,OAAO,QAAQ,EAAE;EAC7D;CACF,CACF;;;;;;CAOF,MAAM,eAAe,OACnB,SACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDAAc,YAAY,YAAY,eAAe,cAAc,EACjE,SAAS,OAAO,OAAO,EACzB,CAAC,GACD,gBACA,cACA,EAAE,OAAO,WAAW,CACtB;;;;;;;;CASF,MAAM,cAAc,OAClB,MACA,KACA,SACA,eAA+B,CAAC,MAC7B;EACH,MAAM,SAAS,MAAM,KAAK,YAAY;EAEtC,MAAM,UAAkC;GACtC,gBAAgB,KAAK,QAAQ;GAC7B,eAAe,KAAK;EACtB;EAEA,IAAI,KAAK,QAAQ,gBAAgB;EACjC,IAAI,SAAS,QAAQ,eAAe;EAEpC,MAAM,cACH,eAAe,WAAkD,CAAC;EAErE,MAAM,WAAW,MAAM,UACrBA,sDAAc,YAAY,YAAY,eAAe,WAAW,GAChE;GACE,QAAQ,eAAe,YAAY;GACnC,aAAa;GACb,SAAS;IAAE,GAAG;IAAa,GAAG;GAAQ;GACtC,MAAM;GACN,QAAQ,aAAa;EACvB,CACF;EAEA,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,SAAS,MAAM,SAAS,KAAK;GACnC,MAAM,IAAI,MAAM,KAAK,UAAU,OAAO,KAAK,KAAK,qBAAqB;EACvE;EAEA,OAAQ,MAAM,SAAS,KAAK;CAC9B;;;;;;;CAQA,MAAM,cAAc,OAClB,SACA,MACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDAAc,YAAY,YAAY,eAAe,aAAa,EAChE,SAAS,OAAO,OAAO,EACzB,CAAC,GACD,gBACA,cACA;EACE,QAAQ,eAAe,YAAY;EACnC,MAAM;CACR,CACF;;;;;;CAOF,MAAM,cAAc,OAClB,SACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDAAc,YAAY,YAAY,eAAe,aAAa,EAChE,SAAS,OAAO,OAAO,EACzB,CAAC,GACD,gBACA,cACA,EAAE,QAAQ,eAAe,YAAY,OAAO,CAC9C;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,gBAAgBC,6CAAe,WAAW"}
@@ -1,11 +1,65 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_fetcher = require('../fetcher.cjs');
3
- const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.cjs');
2
+ const require_cms_createIntlayerCMS = require("../cms/createIntlayerCMS.cjs");
3
+ const require_fetcher = require("../fetcher.cjs");
4
4
  let _intlayer_config_built = require("@intlayer/config/built");
5
+ let _intlayer_backend_contract_defineRoute = require("@intlayer/backend-contract/defineRoute");
6
+ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
5
7
 
6
- //#region src/getIntlayerAPI/audit.ts
8
+ // src/getIntlayerAPI/audit.ts
9
+ /** Prefix of the routes, checked against the backend contract. */
10
+ const scanGroup = { prefix: "/api/scan" };
11
+ /**
12
+ * Method and path of every route, checked against the backend contract at
13
+ * compile time (the contract's zod schemas are never loaded).
14
+ */
15
+ const scanEndpoints = {
16
+ scan: {
17
+ method: "GET",
18
+ path: "/"
19
+ },
20
+ getTechnologyUsage: {
21
+ method: "GET",
22
+ path: "/technologies"
23
+ },
24
+ getScannedHosts: {
25
+ method: "GET",
26
+ path: "/hosts"
27
+ },
28
+ getScannedHost: {
29
+ method: "GET",
30
+ path: "/hosts/:host"
31
+ },
32
+ reportHostDetection: {
33
+ method: "POST",
34
+ path: "/hosts/detections"
35
+ },
36
+ discoverUrls: {
37
+ method: "GET",
38
+ path: "/recursive/discover"
39
+ },
40
+ startRecursive: {
41
+ method: "POST",
42
+ path: "/recursive/start"
43
+ },
44
+ getRecursiveStatus: {
45
+ method: "GET",
46
+ path: "/recursive/:jobId"
47
+ },
48
+ cancelRecursive: {
49
+ method: "POST",
50
+ path: "/recursive/:jobId/cancel"
51
+ },
52
+ pauseRecursive: {
53
+ method: "POST",
54
+ path: "/recursive/:jobId/pause"
55
+ },
56
+ resumeRecursive: {
57
+ method: "POST",
58
+ path: "/recursive/:jobId/resume"
59
+ }
60
+ };
7
61
  const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
8
- const AUDIT_API_ROUTE = `${intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL}/api/scan`;
62
+ const backendURL = intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL ?? _intlayer_config_defaultValues.BACKEND_URL;
9
63
  /**
10
64
  * Streams a single-page SEO audit as Server-Sent Events.
11
65
  *
@@ -18,8 +72,8 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
18
72
  * });
19
73
  * ```
20
74
  */
21
- const discoverUrls = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/discover`, authAPIOptions, otherOptions, {
22
- method: "GET",
75
+ const discoverUrls = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.discoverUrls), authAPIOptions, otherOptions, {
76
+ method: scanEndpoints.discoverUrls.method,
23
77
  params
24
78
  });
25
79
  const scanUrl = async (body, otherOptions = {}) => {
@@ -27,9 +81,9 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
27
81
  const { url, refresh, onMessage, onDone } = body;
28
82
  const params = new URLSearchParams({ url });
29
83
  if (refresh) params.set("refresh", "true");
30
- const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;
84
+ const endpoint = `${(0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.scan)}?${params.toString()}`;
31
85
  const response = await fetch(endpoint, {
32
- method: "GET",
86
+ method: scanEndpoints.scan.method,
33
87
  headers: {
34
88
  Accept: "text/event-stream",
35
89
  ...authAPIOptions.headers,
@@ -71,37 +125,37 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
71
125
  /**
72
126
  * Starts a recursive audit job for the given URL.
73
127
  */
74
- const startRecursiveAudit = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/start`, authAPIOptions, otherOptions, {
75
- method: "POST",
128
+ const startRecursiveAudit = async (body, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.startRecursive), authAPIOptions, otherOptions, {
129
+ method: scanEndpoints.startRecursive.method,
76
130
  params: body?.url ? { url: body.url } : void 0,
77
131
  body: body?.urls !== void 0 ? { urls: body.urls } : void 0
78
132
  });
79
133
  /**
80
134
  * Gets the status of a recursive audit job.
81
135
  */
82
- const getRecursiveAuditStatus = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}`, authAPIOptions, otherOptions, { method: "GET" });
83
- const cancelRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`, authAPIOptions, otherOptions, { method: "POST" });
84
- const pauseRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`, authAPIOptions, otherOptions, { method: "POST" });
85
- const resumeRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`, authAPIOptions, otherOptions, { method: "POST" });
136
+ const getRecursiveAuditStatus = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.getRecursiveStatus, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.getRecursiveStatus.method });
137
+ const cancelRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.cancelRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.cancelRecursive.method });
138
+ const pauseRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.pauseRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.pauseRecursive.method });
139
+ const resumeRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.resumeRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.resumeRecursive.method });
86
140
  /**
87
141
  * Admin — number of scanned domains using each technology.
88
142
  */
89
- const getTechnologyUsage = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/technologies`, authAPIOptions, otherOptions, {
90
- method: "GET",
143
+ const getTechnologyUsage = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.getTechnologyUsage), authAPIOptions, otherOptions, {
144
+ method: scanEndpoints.getTechnologyUsage.method,
91
145
  params
92
146
  });
93
147
  /**
94
148
  * Admin — scanned hosts, most recently scanned first, filterable by
95
149
  * technology.
96
150
  */
97
- const getScannedHosts = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/hosts`, authAPIOptions, otherOptions, {
98
- method: "GET",
151
+ const getScannedHosts = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.getScannedHosts), authAPIOptions, otherOptions, {
152
+ method: scanEndpoints.getScannedHosts.method,
99
153
  params
100
154
  });
101
155
  /**
102
156
  * Admin — a scanned host with its stored scans, newest first.
103
157
  */
104
- const getScannedHost = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AUDIT_API_ROUTE}/hosts/${encodeURIComponent(params?.host ?? "")}`, authAPIOptions, otherOptions, { method: "GET" });
158
+ const getScannedHost = async (params, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.getScannedHost, { host: params?.host ?? "" }), authAPIOptions, otherOptions, { method: scanEndpoints.getScannedHost.method });
105
159
  return {
106
160
  getTechnologyUsage,
107
161
  getScannedHosts,
@@ -123,7 +177,6 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
123
177
  */
124
178
  const auditEndpoint = require_cms_createIntlayerCMS.createEndpoint(getAuditAPI);
125
179
 
126
- //#endregion
127
180
  exports.auditEndpoint = auditEndpoint;
128
181
  exports.getAuditAPI = getAuditAPI;
129
182
  //# sourceMappingURL=audit.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit.cjs","names":["editor","fetcher","createEndpoint"],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n GetScannedHostParams,\n GetScannedHostResult,\n GetScannedHostsQuery,\n GetScannedHostsResult,\n GetTechnologyUsageQuery,\n GetTechnologyUsageResult,\n StartRecursiveAuditResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n GetScannedHostParams,\n GetScannedHostResult,\n GetScannedHostsQuery,\n GetScannedHostsResult,\n GetTechnologyUsageQuery,\n GetTechnologyUsageResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n /**\n * Force a new audit. Without it, a URL audited less than an hour ago is\n * replayed from cache (its first event carries `cachedAt`).\n */\n refresh?: boolean;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const AUDIT_API_ROUTE = `${backendURL}/api/scan`;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n `${AUDIT_API_ROUTE}/recursive/discover`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, refresh, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n if (refresh) params.set('refresh', 'true');\n const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n `${AUDIT_API_ROUTE}/recursive/start`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n /**\n * Admin — number of scanned domains using each technology.\n */\n const getTechnologyUsage = async (\n params?: GetTechnologyUsageQuery,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetTechnologyUsageResult>(\n `${AUDIT_API_ROUTE}/technologies`,\n authAPIOptions,\n otherOptions,\n { method: 'GET', params }\n );\n\n /**\n * Admin — scanned hosts, most recently scanned first, filterable by\n * technology.\n */\n const getScannedHosts = async (\n params?: GetScannedHostsQuery,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetScannedHostsResult>(\n `${AUDIT_API_ROUTE}/hosts`,\n authAPIOptions,\n otherOptions,\n { method: 'GET', params }\n );\n\n /**\n * Admin — a scanned host with its stored scans, newest first.\n */\n const getScannedHost = async (\n params?: GetScannedHostParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetScannedHostResult>(\n `${AUDIT_API_ROUTE}/hosts/${encodeURIComponent(params?.host ?? '')}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n return {\n getTechnologyUsage,\n getScannedHosts,\n getScannedHost,\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n\n/**\n * Authenticated `audit` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const auditEndpoint = createEndpoint(getAuditAPI);\n"],"mappings":";;;;;;AA4DA,MAAa,eACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,kBAAkB,GAFL,gBAAgB,QAAQ,cAAcA,8BAAO,WAE1B;;;;;;;;;;;;;CActC,MAAM,eAAe,OACnB,QACA,eAA+B,CAAC,MAEhC,MAAMC,wBACJ,GAAG,gBAAgB,sBACnB,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;CAEF,MAAM,UAAU,OACd,MACA,eAA+B,CAAC,MAC7B;EACH,IAAI,CAAC,MAAM,KAAK;EAEhB,MAAM,EAAE,KAAK,SAAS,WAAW,WAAW;EAE5C,MAAM,SAAS,IAAI,gBAAgB,EAAE,IAAI,CAAC;EAC1C,IAAI,SAAS,OAAO,IAAI,WAAW,MAAM;EACzC,MAAM,WAAW,GAAG,gBAAgB,GAAG,OAAO,SAAS;EAEvD,MAAM,WAAW,MAAM,MAAM,UAAU;GACrC,QAAQ;GACR,SAAS;IACP,QAAQ;IACR,GAAG,eAAe;IAClB,GAAG,aAAa;GAClB;GACA,aAAa;GACb,QAAQ,aAAa;EACvB,CAAC;EAED,IAAI,CAAC,SAAS,IAAI;GAChB,IAAI,eAAe;GACnB,IAAI;IACF,MAAM,YAAY,MAAM,SAAS,KAAK;IACtC,eAAe,KAA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BAAsB,OAC1B,QACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,aAAa,QAAQ,MAAM,SAC9C,gBACA,cACA,EAAE,QAAQ,OAAO,CACnB;CAEF,MAAM,uBAAuB,OAC3B,QACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,aAAa,QAAQ,MAAM,UAC9C,gBACA,cACA,EAAE,QAAQ,OAAO,CACnB;;;;CAKF,MAAM,qBAAqB,OACzB,QACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,gBACnB,gBACA,cACA;EAAE,QAAQ;EAAO;CAAO,CAC1B;;;;;CAMF,MAAM,kBAAkB,OACtB,QACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,SACnB,gBACA,cACA;EAAE,QAAQ;EAAO;CAAO,CAC1B;;;;CAKF,MAAM,iBAAiB,OACrB,QACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,gBAAgB,SAAS,mBAAmB,QAAQ,QAAQ,EAAE,KACjE,gBACA,cACA,EAAE,QAAQ,MAAM,CAClB;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,gBAAgBC,6CAAe,WAAW"}
1
+ {"version":3,"file":"audit.cjs","names":["editor","BACKEND_URL","fetcher","buildRouteURL","createEndpoint"],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n GetScannedHostParams,\n GetScannedHostResult,\n GetScannedHostsQuery,\n GetScannedHostsResult,\n GetTechnologyUsageQuery,\n GetTechnologyUsageResult,\n ScanRoutes,\n StartRecursiveAuditResult,\n scanContract,\n} from '@intlayer/backend-contract/scan';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n GetScannedHostParams,\n GetScannedHostResult,\n GetScannedHostsQuery,\n GetScannedHostsResult,\n GetTechnologyUsageQuery,\n GetTechnologyUsageResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n /**\n * Force a new audit. Without it, a URL audited less than an hour ago is\n * replayed from cache (its first event carries `cachedAt`).\n */\n refresh?: boolean;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\n/** Prefix of the routes, checked against the backend contract. */\nconst scanGroup = {\n prefix: '/api/scan',\n} as const satisfies Pick<typeof scanContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst scanEndpoints = {\n scan: { method: 'GET', path: '/' },\n getTechnologyUsage: { method: 'GET', path: '/technologies' },\n getScannedHosts: { method: 'GET', path: '/hosts' },\n getScannedHost: { method: 'GET', path: '/hosts/:host' },\n reportHostDetection: { method: 'POST', path: '/hosts/detections' },\n discoverUrls: { method: 'GET', path: '/recursive/discover' },\n startRecursive: { method: 'POST', path: '/recursive/start' },\n getRecursiveStatus: { method: 'GET', path: '/recursive/:jobId' },\n cancelRecursive: { method: 'POST', path: '/recursive/:jobId/cancel' },\n pauseRecursive: { method: 'POST', path: '/recursive/:jobId/pause' },\n resumeRecursive: { method: 'POST', path: '/recursive/:jobId/resume' },\n} as const satisfies RouteEndpoints<ScanRoutes>;\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.discoverUrls),\n authAPIOptions,\n otherOptions,\n {\n method: scanEndpoints.discoverUrls.method,\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, refresh, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n if (refresh) params.set('refresh', 'true');\n const endpoint = `${buildRouteURL(backendURL, scanGroup, scanEndpoints.scan)}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: scanEndpoints.scan.method,\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.startRecursive),\n authAPIOptions,\n otherOptions,\n {\n method: scanEndpoints.startRecursive.method,\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.getRecursiveStatus, {\n jobId: String(params?.jobId),\n }),\n authAPIOptions,\n otherOptions,\n {\n method: scanEndpoints.getRecursiveStatus.method,\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.cancelRecursive, {\n jobId: String(params?.jobId),\n }),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.cancelRecursive.method }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.pauseRecursive, {\n jobId: String(params?.jobId),\n }),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.pauseRecursive.method }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.resumeRecursive, {\n jobId: String(params?.jobId),\n }),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.resumeRecursive.method }\n );\n\n /**\n * Admin — number of scanned domains using each technology.\n */\n const getTechnologyUsage = async (\n params?: GetTechnologyUsageQuery,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetTechnologyUsageResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.getTechnologyUsage),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.getTechnologyUsage.method, params }\n );\n\n /**\n * Admin — scanned hosts, most recently scanned first, filterable by\n * technology.\n */\n const getScannedHosts = async (\n params?: GetScannedHostsQuery,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetScannedHostsResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.getScannedHosts),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.getScannedHosts.method, params }\n );\n\n /**\n * Admin — a scanned host with its stored scans, newest first.\n */\n const getScannedHost = async (\n params?: GetScannedHostParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetScannedHostResult>(\n buildRouteURL(backendURL, scanGroup, scanEndpoints.getScannedHost, {\n host: params?.host ?? '',\n }),\n authAPIOptions,\n otherOptions,\n { method: scanEndpoints.getScannedHost.method }\n );\n\n return {\n getTechnologyUsage,\n getScannedHosts,\n getScannedHost,\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n\n/**\n * Authenticated `audit` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const auditEndpoint = createEndpoint(getAuditAPI);\n"],"mappings":";;;;;;;;;AAkEA,MAAM,YAAY,EAChB,QAAQ,YACV;;;;;AAMA,MAAM,gBAAgB;CACpB,MAAM;EAAE,QAAQ;EAAO,MAA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ACF;;;;;;;AAQA,MAAa,gBAAgBC,6CAAe,WAAW"}
@@ -1,29 +1,59 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_fetcher = require('../fetcher.cjs');
3
- const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.cjs');
2
+ const require_cms_createIntlayerCMS = require("../cms/createIntlayerCMS.cjs");
3
+ const require_fetcher = require("../fetcher.cjs");
4
4
  let _intlayer_config_built = require("@intlayer/config/built");
5
+ let _intlayer_backend_contract_defineRoute = require("@intlayer/backend-contract/defineRoute");
6
+ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
5
7
 
6
- //#region src/getIntlayerAPI/bitbucket.ts
8
+ // src/getIntlayerAPI/bitbucket.ts
9
+ /** Prefix of the routes, checked against the backend contract. */
10
+ const bitbucketGroup = { prefix: "/api/bitbucket" };
11
+ /**
12
+ * Method and path of every route, checked against the backend contract at
13
+ * compile time (the contract's zod schemas are never loaded).
14
+ */
15
+ const bitbucketEndpoints = {
16
+ getAuthUrl: {
17
+ method: "GET",
18
+ path: "/auth-url"
19
+ },
20
+ authCallback: {
21
+ method: "POST",
22
+ path: "/auth"
23
+ },
24
+ listRepos: {
25
+ method: "GET",
26
+ path: "/repos"
27
+ },
28
+ checkConfig: {
29
+ method: "POST",
30
+ path: "/check-config"
31
+ },
32
+ getConfigFile: {
33
+ method: "POST",
34
+ path: "/get-config-file"
35
+ }
36
+ };
7
37
  const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
8
- const BITBUCKET_API_ROUTE = `${intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL}/api/bitbucket`;
38
+ const backendURL = intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL ?? _intlayer_config_defaultValues.BACKEND_URL;
9
39
  /**
10
40
  * Get Bitbucket OAuth authorization URL
11
41
  * @param redirectUri - Redirect URI after OAuth authorization
12
42
  */
13
- const getAuthUrl = async (redirectUri, otherOptions = {}) => await require_fetcher.fetcher(`${BITBUCKET_API_ROUTE}/auth-url`, authAPIOptions, otherOptions, { params: { redirectUri } });
43
+ const getAuthUrl = async (redirectUri, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, bitbucketGroup, bitbucketEndpoints.getAuthUrl), authAPIOptions, otherOptions, { params: { redirectUri } });
14
44
  /**
15
45
  * Exchange Bitbucket authorization code for access token
16
46
  * @param code - Bitbucket authorization code
17
47
  */
18
- const authenticate = async (code, otherOptions = {}) => await require_fetcher.fetcher(`${BITBUCKET_API_ROUTE}/auth`, authAPIOptions, otherOptions, {
19
- method: "POST",
48
+ const authenticate = async (code, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, bitbucketGroup, bitbucketEndpoints.authCallback), authAPIOptions, otherOptions, {
49
+ method: bitbucketEndpoints.authCallback.method,
20
50
  body: { code }
21
51
  });
22
52
  /**
23
53
  * Get user's Bitbucket repositories
24
54
  * @param token - Optional Bitbucket access token. If not provided, backend will use session.
25
55
  */
26
- const getRepositories = async (token, otherOptions = {}) => await require_fetcher.fetcher(`${BITBUCKET_API_ROUTE}/repos`, authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
56
+ const getRepositories = async (token, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, bitbucketGroup, bitbucketEndpoints.listRepos), authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
27
57
  /**
28
58
  * Check if intlayer.config.ts exists in a Bitbucket repository
29
59
  * @param token - Optional Bitbucket access token. If not provided, backend will use session.
@@ -31,8 +61,8 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
31
61
  * @param repoSlug - Repository slug
32
62
  * @param branch - Branch name (default: 'main')
33
63
  */
34
- const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await require_fetcher.fetcher(`${BITBUCKET_API_ROUTE}/check-config`, authAPIOptions, otherOptions, {
35
- method: "POST",
64
+ const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, bitbucketGroup, bitbucketEndpoints.checkConfig), authAPIOptions, otherOptions, {
65
+ method: bitbucketEndpoints.checkConfig.method,
36
66
  body: {
37
67
  token: token ?? void 0,
38
68
  workspace,
@@ -48,8 +78,8 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
48
78
  * @param branch - Branch name (default: 'main')
49
79
  * @param path - File path (default: 'intlayer.config.ts')
50
80
  */
51
- const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await require_fetcher.fetcher(`${BITBUCKET_API_ROUTE}/get-config-file`, authAPIOptions, otherOptions, {
52
- method: "POST",
81
+ const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, bitbucketGroup, bitbucketEndpoints.getConfigFile), authAPIOptions, otherOptions, {
82
+ method: bitbucketEndpoints.getConfigFile.method,
53
83
  body: {
54
84
  token: token ?? void 0,
55
85
  workspace,
@@ -74,7 +104,6 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
74
104
  */
75
105
  const bitbucketEndpoint = require_cms_createIntlayerCMS.createEndpoint(getBitbucketAPI);
76
106
 
77
- //#endregion
78
107
  exports.bitbucketEndpoint = bitbucketEndpoint;
79
108
  exports.getBitbucketAPI = getBitbucketAPI;
80
109
  //# sourceMappingURL=bitbucket.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucket.cjs","names":["editor","fetcher","createEndpoint"],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n `${BITBUCKET_API_ROUTE}/auth-url`,\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n `${BITBUCKET_API_ROUTE}/auth`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n `${BITBUCKET_API_ROUTE}/repos`,\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n `${BITBUCKET_API_ROUTE}/check-config`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n `${BITBUCKET_API_ROUTE}/get-config-file`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n\n/**\n * Authenticated `bitbucket` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const bitbucketEndpoint = createEndpoint(getBitbucketAPI);\n"],"mappings":";;;;;;AAiFA,MAAa,mBACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,sBAAsB,GAFT,gBAAgB,QAAQ,cAAcA,8BAAO,WAEtB;;;;;CAM1C,MAAM,aAAa,OACjB,aACA,eAA+B,CAAC,MAEhC,MAAMC,wBACJ,GAAG,oBAAoB,YACvB,gBACA,cACA,EACE,QAAQ,EAAE,YAAY,EACxB,CACF;;;;;CAMF,MAAM,eAAe,OACnB,MACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,oBAAoB,QACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,KAAK;CACf,CACF;;;;;CAMF,MAAM,kBAAkB,OACtB,OACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,oBAAoB,SACvB,gBACA,cACA,EACE,QAAQ,QAAQ,EAAE,MAAM,IAAI,OAC9B,CACF;;;;;;;;CASF,MAAM,sBAAsB,OAC1B,OACA,WACA,UACA,SAAiB,QACjB,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,oBAAoB,gBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GAAE,OAAO,SAAS;GAAW;GAAW;GAAU;EAAO;CACjE,CACF;;;;;;;;;CAUF,MAAM,gBAAgB,OACpB,OACA,WACA,UACA,SAAiB,QACjB,OAAe,sBACf,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,oBAAoB,mBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GACJ,OAAO,SAAS;GAChB;GACA;GACA;GACA;EACF;CACF,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,oBAAoBC,6CAAe,eAAe"}
1
+ {"version":3,"file":"bitbucket.cjs","names":["editor","BACKEND_URL","fetcher","buildRouteURL","createEndpoint"],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n BitbucketRoutes,\n bitbucketContract,\n} from '@intlayer/backend-contract/gitProviders';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\n/** Prefix of the routes, checked against the backend contract. */\nconst bitbucketGroup = {\n prefix: '/api/bitbucket',\n} as const satisfies Pick<typeof bitbucketContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst bitbucketEndpoints = {\n getAuthUrl: { method: 'GET', path: '/auth-url' },\n authCallback: { method: 'POST', path: '/auth' },\n listRepos: { method: 'GET', path: '/repos' },\n checkConfig: { method: 'POST', path: '/check-config' },\n getConfigFile: { method: 'POST', path: '/get-config-file' },\n} as const satisfies RouteEndpoints<BitbucketRoutes>;\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.getAuthUrl),\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n buildRouteURL(\n backendURL,\n bitbucketGroup,\n bitbucketEndpoints.authCallback\n ),\n authAPIOptions,\n otherOptions,\n {\n method: bitbucketEndpoints.authCallback.method,\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.listRepos),\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.checkConfig),\n authAPIOptions,\n otherOptions,\n {\n method: bitbucketEndpoints.checkConfig.method,\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n buildRouteURL(\n backendURL,\n bitbucketGroup,\n bitbucketEndpoints.getConfigFile\n ),\n authAPIOptions,\n otherOptions,\n {\n method: bitbucketEndpoints.getConfigFile.method,\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n\n/**\n * Authenticated `bitbucket` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const bitbucketEndpoint = createEndpoint(getBitbucketAPI);\n"],"mappings":";;;;;;;;;AAyFA,MAAM,iBAAiB,EACrB,QAAQ,iBACV;;;;;AAMA,MAAM,qBAAqB;CACzB,YAAY;EAAE,QAAQ;EAAO,MAAM;CAAY;CAC/C,cAAc;EAAE,QAAQ;EAAQ,MAAM;CAAQ;CAC9C,WAAW;EAAE,QAAQ;EAAO,MAAM;CAAS;CAC3C,aA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;;;;;;AAQA,MAAa,oBAAoBC,6CAAe,eAAe"}
@@ -0,0 +1,20 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_cms_createIntlayerCMS = require("../cms/createIntlayerCMS.cjs");
3
+ const require_getIntlayerAPI_forge = require("./forge.cjs");
4
+
5
+ // src/getIntlayerAPI/codeberg.ts
6
+ /** Prefix of the routes, checked against the backend contract. */
7
+ const codebergGroup = { prefix: "/api/codeberg" };
8
+ /** Codeberg (Forgejo) repositories of the linked account. */
9
+ const getCodebergAPI = require_getIntlayerAPI_forge.createForgeAPI(codebergGroup);
10
+ /**
11
+ * Authenticated `codeberg` endpoint bound to an Intlayer CMS authenticator.
12
+ *
13
+ * Pass an authenticator created with `createIntlayerCMS`, or omit it to use
14
+ * the build-time configuration (`@intlayer/config/built`).
15
+ */
16
+ const codebergEndpoint = require_cms_createIntlayerCMS.createEndpoint(getCodebergAPI);
17
+
18
+ exports.codebergEndpoint = codebergEndpoint;
19
+ exports.getCodebergAPI = getCodebergAPI;
20
+ //# sourceMappingURL=codeberg.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codeberg.cjs","names":["createForgeAPI","createEndpoint"],"sources":["../../../src/getIntlayerAPI/codeberg.ts"],"sourcesContent":["import type { codebergContract } from '@intlayer/backend-contract/gitProviders';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { createForgeAPI } from './forge';\n\n/** Prefix of the routes, checked against the backend contract. */\nconst codebergGroup = {\n prefix: '/api/codeberg',\n} as const satisfies Pick<typeof codebergContract, 'prefix'>;\n\n/** Codeberg (Forgejo) repositories of the linked account. */\nexport const getCodebergAPI = createForgeAPI(codebergGroup);\n\n/**\n * Authenticated `codeberg` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const codebergEndpoint = createEndpoint(getCodebergAPI);\n"],"mappings":";;;;;;AAKA,MAAM,gBAAgB,EACpB,QAAQ,gBACV;;AAGA,MAAa,iBAAiBA,4CAAe,aAAa;;;;;;;AAQ1D,MAAa,mBAAmBC,6CAAe,cAAc"}