@intlayer/api 9.6.0 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/fetcher.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +76 -22
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/analytics.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/analytics.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/asset.cjs +38 -8
- package/dist/cjs/getIntlayerAPI/asset.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/audit.cjs +70 -16
- package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs +39 -9
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/codeberg.cjs +21 -0
- package/dist/cjs/getIntlayerAPI/codeberg.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +59 -13
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/environment.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/environment.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/forge.cjs +64 -0
- package/dist/cjs/getIntlayerAPI/forge.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/gitee.cjs +21 -0
- package/dist/cjs/getIntlayerAPI/gitee.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/github.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/gitlab.cjs +39 -9
- package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +4 -0
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +28 -6
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +31 -5
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +72 -20
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +112 -29
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/reviewer.cjs +142 -31
- package/dist/cjs/getIntlayerAPI/reviewer.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +15 -3
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs +61 -15
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/status.cjs +16 -3
- package/dist/cjs/getIntlayerAPI/status.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +141 -35
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +33 -7
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/translate.cjs +46 -8
- package/dist/cjs/getIntlayerAPI/translate.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +58 -14
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/proxy.cjs +4 -0
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/public/createPublicClient.cjs +25 -5
- package/dist/cjs/public/createPublicClient.cjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/fetcher.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +76 -22
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/analytics.mjs +44 -10
- package/dist/esm/getIntlayerAPI/analytics.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/asset.mjs +38 -8
- package/dist/esm/getIntlayerAPI/asset.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/audit.mjs +70 -16
- package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/bitbucket.mjs +39 -9
- package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/codeberg.mjs +19 -0
- package/dist/esm/getIntlayerAPI/codeberg.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/dictionary.mjs +59 -13
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/environment.mjs +44 -10
- package/dist/esm/getIntlayerAPI/environment.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/forge.mjs +63 -0
- package/dist/esm/getIntlayerAPI/forge.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/gitee.mjs +19 -0
- package/dist/esm/getIntlayerAPI/gitee.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/github.mjs +44 -10
- package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/gitlab.mjs +39 -9
- package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +4 -0
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +28 -6
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +31 -5
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +72 -20
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +112 -29
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/reviewer.mjs +142 -31
- package/dist/esm/getIntlayerAPI/reviewer.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +15 -3
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs +61 -15
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/status.mjs +16 -3
- package/dist/esm/getIntlayerAPI/status.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +141 -35
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +33 -7
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/translate.mjs +46 -8
- package/dist/esm/getIntlayerAPI/translate.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +58 -14
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +4 -1
- package/dist/esm/proxy.mjs +4 -0
- package/dist/esm/proxy.mjs.map +1 -1
- package/dist/esm/public/createPublicClient.mjs +25 -5
- package/dist/esm/public/createPublicClient.mjs.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -1
- package/dist/types/fetcher.d.ts +1 -1
- package/dist/types/fetcher.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/analytics.d.ts +1 -1
- package/dist/types/getIntlayerAPI/analytics.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/asset.d.ts +1 -0
- package/dist/types/getIntlayerAPI/asset.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/audit.d.ts +47 -3
- package/dist/types/getIntlayerAPI/audit.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/bitbucket.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/codeberg.d.ts +23 -0
- package/dist/types/getIntlayerAPI/codeberg.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/dictionary.d.ts +1 -1
- package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/editor.d.ts +2 -1
- package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/environment.d.ts +1 -1
- package/dist/types/getIntlayerAPI/environment.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/forge.d.ts +17 -0
- package/dist/types/getIntlayerAPI/forge.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/gitee.d.ts +23 -0
- package/dist/types/getIntlayerAPI/gitee.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/github.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/gitlab.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +4 -0
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/oAuth.d.ts +2 -0
- package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/organization.d.ts +1 -3
- package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +2 -1
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/reviewer.d.ts +680 -35
- package/dist/types/getIntlayerAPI/reviewer.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts +1 -1
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/status.d.ts +3 -4
- package/dist/types/getIntlayerAPI/status.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/translate.d.ts +1 -1
- package/dist/types/getIntlayerAPI/translate.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/user.d.ts +4 -4
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/proxy.d.ts.map +1 -1
- package/dist/types/public/createPublicClient.d.ts +1 -7
- package/dist/types/public/createPublicClient.d.ts.map +1 -1
- package/dist/types/types.d.ts +5 -2
- package/package.json +20 -3
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/audit.ts
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const scanGroup = { prefix: "/api/scan" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const scanEndpoints = {
|
|
15
|
+
scan: {
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: "/"
|
|
18
|
+
},
|
|
19
|
+
getTechnologyUsage: {
|
|
20
|
+
method: "GET",
|
|
21
|
+
path: "/technologies"
|
|
22
|
+
},
|
|
23
|
+
getScannedHosts: {
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: "/hosts"
|
|
26
|
+
},
|
|
27
|
+
getScannedHost: {
|
|
28
|
+
method: "GET",
|
|
29
|
+
path: "/hosts/:host"
|
|
30
|
+
},
|
|
31
|
+
reportHostDetection: {
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: "/hosts/detections"
|
|
34
|
+
},
|
|
35
|
+
discoverUrls: {
|
|
36
|
+
method: "GET",
|
|
37
|
+
path: "/recursive/discover"
|
|
38
|
+
},
|
|
39
|
+
startRecursive: {
|
|
40
|
+
method: "POST",
|
|
41
|
+
path: "/recursive/start"
|
|
42
|
+
},
|
|
43
|
+
getRecursiveStatus: {
|
|
44
|
+
method: "GET",
|
|
45
|
+
path: "/recursive/:jobId"
|
|
46
|
+
},
|
|
47
|
+
cancelRecursive: {
|
|
48
|
+
method: "POST",
|
|
49
|
+
path: "/recursive/:jobId/cancel"
|
|
50
|
+
},
|
|
51
|
+
pauseRecursive: {
|
|
52
|
+
method: "POST",
|
|
53
|
+
path: "/recursive/:jobId/pause"
|
|
54
|
+
},
|
|
55
|
+
resumeRecursive: {
|
|
56
|
+
method: "POST",
|
|
57
|
+
path: "/recursive/:jobId/resume"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
6
60
|
const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
-
const
|
|
61
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
8
62
|
/**
|
|
9
63
|
* Streams a single-page SEO audit as Server-Sent Events.
|
|
10
64
|
*
|
|
@@ -17,8 +71,8 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
17
71
|
* });
|
|
18
72
|
* ```
|
|
19
73
|
*/
|
|
20
|
-
const discoverUrls = async (params, otherOptions = {}) => await fetcher(
|
|
21
|
-
method:
|
|
74
|
+
const discoverUrls = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.discoverUrls), authAPIOptions, otherOptions, {
|
|
75
|
+
method: scanEndpoints.discoverUrls.method,
|
|
22
76
|
params
|
|
23
77
|
});
|
|
24
78
|
const scanUrl = async (body, otherOptions = {}) => {
|
|
@@ -26,9 +80,9 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
26
80
|
const { url, refresh, onMessage, onDone } = body;
|
|
27
81
|
const params = new URLSearchParams({ url });
|
|
28
82
|
if (refresh) params.set("refresh", "true");
|
|
29
|
-
const endpoint = `${
|
|
83
|
+
const endpoint = `${buildRouteURL(backendURL, scanGroup, scanEndpoints.scan)}?${params.toString()}`;
|
|
30
84
|
const response = await fetch(endpoint, {
|
|
31
|
-
method:
|
|
85
|
+
method: scanEndpoints.scan.method,
|
|
32
86
|
headers: {
|
|
33
87
|
Accept: "text/event-stream",
|
|
34
88
|
...authAPIOptions.headers,
|
|
@@ -70,37 +124,37 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
70
124
|
/**
|
|
71
125
|
* Starts a recursive audit job for the given URL.
|
|
72
126
|
*/
|
|
73
|
-
const startRecursiveAudit = async (body, otherOptions = {}) => await fetcher(
|
|
74
|
-
method:
|
|
127
|
+
const startRecursiveAudit = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.startRecursive), authAPIOptions, otherOptions, {
|
|
128
|
+
method: scanEndpoints.startRecursive.method,
|
|
75
129
|
params: body?.url ? { url: body.url } : void 0,
|
|
76
130
|
body: body?.urls !== void 0 ? { urls: body.urls } : void 0
|
|
77
131
|
});
|
|
78
132
|
/**
|
|
79
133
|
* Gets the status of a recursive audit job.
|
|
80
134
|
*/
|
|
81
|
-
const getRecursiveAuditStatus = async (params, otherOptions = {}) => await fetcher(
|
|
82
|
-
const cancelRecursiveAudit = async (params, otherOptions = {}) => await fetcher(
|
|
83
|
-
const pauseRecursiveAudit = async (params, otherOptions = {}) => await fetcher(
|
|
84
|
-
const resumeRecursiveAudit = async (params, otherOptions = {}) => await fetcher(
|
|
135
|
+
const getRecursiveAuditStatus = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.getRecursiveStatus, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.getRecursiveStatus.method });
|
|
136
|
+
const cancelRecursiveAudit = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.cancelRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.cancelRecursive.method });
|
|
137
|
+
const pauseRecursiveAudit = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.pauseRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.pauseRecursive.method });
|
|
138
|
+
const resumeRecursiveAudit = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.resumeRecursive, { jobId: String(params?.jobId) }), authAPIOptions, otherOptions, { method: scanEndpoints.resumeRecursive.method });
|
|
85
139
|
/**
|
|
86
140
|
* Admin — number of scanned domains using each technology.
|
|
87
141
|
*/
|
|
88
|
-
const getTechnologyUsage = async (params, otherOptions = {}) => await fetcher(
|
|
89
|
-
method:
|
|
142
|
+
const getTechnologyUsage = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.getTechnologyUsage), authAPIOptions, otherOptions, {
|
|
143
|
+
method: scanEndpoints.getTechnologyUsage.method,
|
|
90
144
|
params
|
|
91
145
|
});
|
|
92
146
|
/**
|
|
93
147
|
* Admin — scanned hosts, most recently scanned first, filterable by
|
|
94
148
|
* technology.
|
|
95
149
|
*/
|
|
96
|
-
const getScannedHosts = async (params, otherOptions = {}) => await fetcher(
|
|
97
|
-
method:
|
|
150
|
+
const getScannedHosts = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.getScannedHosts), authAPIOptions, otherOptions, {
|
|
151
|
+
method: scanEndpoints.getScannedHosts.method,
|
|
98
152
|
params
|
|
99
153
|
});
|
|
100
154
|
/**
|
|
101
155
|
* Admin — a scanned host with its stored scans, newest first.
|
|
102
156
|
*/
|
|
103
|
-
const getScannedHost = async (params, otherOptions = {}) => await fetcher(
|
|
157
|
+
const getScannedHost = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, scanGroup, scanEndpoints.getScannedHost, { host: params?.host ?? "" }), authAPIOptions, otherOptions, { method: scanEndpoints.getScannedHost.method });
|
|
104
158
|
return {
|
|
105
159
|
getTechnologyUsage,
|
|
106
160
|
getScannedHosts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.mjs","names":[],"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,cAAc,OAAO,WAE1B;;;;;;;;;;;;;CActC,MAAM,eA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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,gBAAgB,eAAe,WAAW"}
|
|
1
|
+
{"version":3,"file":"audit.mjs","names":[],"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,MAAM;CAAI;CACjC,oBAAoB;EAAE,QAAQ;EAAO,MAAM;CAAgB;CAC3D,iBAAiB;EAAE,QAAQ;EAAO,MAAM;CAAS;CACjD,gBAAgB;EAAE,QAAQ;EAAO,MAAM;CAAe;CACtD,qBAAqB;EAAE,QAAQ;EAAQ,MAAM;CAAoB;CACjE,cAAc;EAAE,QAAQ;EAAO,MAAM;CAAsB;CAC3D,gBAAgB;EAAE,QAAQ;EAAQ,MAAM;CAAmB;CAC3D,oBAAoB;EAAE,QAAQ;EAAO,MAAM;CAAoB;CAC/D,iBAAiB;EAAE,QAAQ;EAAQ,MAAM;CAA2B;CACpE,gBAAgB;EAAE,QAAQ;EAAQ,MAAM;CAA0B;CAClE,iBAAiB;EAAE,QAAQ;EAAQ,MAAM;CAA2B;AACtE;AAEA,MAAa,eACX,iBAAiC,CAAC,GAClC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAc,OAAO,cAAc;;;;;;;;;;;;;CAc7D,MAAM,eAAe,OACnB,QACA,eAA+B,CAAC,MAEhC,M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,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,WAAW,cAAc,kBAAkB,GACrE,gBACA,cACA;EAAE,QAAQ,cAAc,mBAAmB;EAAQ;CAAO,CAC5D;;;;;CAMF,MAAM,kBAAkB,OACtB,QACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,WAAW,cAAc,eAAe,GAClE,gBACA,cACA;EAAE,QAAQ,cAAc,gBAAgB;EAAQ;CAAO,CACzD;;;;CAKF,MAAM,iBAAiB,OACrB,QACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,WAAW,cAAc,gBAAgB,EACjE,MAAM,QAAQ,QAAQ,GACxB,CAAC,GACD,gBACA,cACA,EAAE,QAAQ,cAAc,eAAe,OAAO,CAChD;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,gBAAgB,eAAe,WAAW"}
|
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/bitbucket.ts
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const bitbucketGroup = { prefix: "/api/bitbucket" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const bitbucketEndpoints = {
|
|
15
|
+
getAuthUrl: {
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: "/auth-url"
|
|
18
|
+
},
|
|
19
|
+
authCallback: {
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/auth"
|
|
22
|
+
},
|
|
23
|
+
listRepos: {
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: "/repos"
|
|
26
|
+
},
|
|
27
|
+
checkConfig: {
|
|
28
|
+
method: "POST",
|
|
29
|
+
path: "/check-config"
|
|
30
|
+
},
|
|
31
|
+
getConfigFile: {
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: "/get-config-file"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
6
36
|
const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
-
const
|
|
37
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
8
38
|
/**
|
|
9
39
|
* Get Bitbucket OAuth authorization URL
|
|
10
40
|
* @param redirectUri - Redirect URI after OAuth authorization
|
|
11
41
|
*/
|
|
12
|
-
const getAuthUrl = async (redirectUri, otherOptions = {}) => await fetcher(
|
|
42
|
+
const getAuthUrl = async (redirectUri, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.getAuthUrl), authAPIOptions, otherOptions, { params: { redirectUri } });
|
|
13
43
|
/**
|
|
14
44
|
* Exchange Bitbucket authorization code for access token
|
|
15
45
|
* @param code - Bitbucket authorization code
|
|
16
46
|
*/
|
|
17
|
-
const authenticate = async (code, otherOptions = {}) => await fetcher(
|
|
18
|
-
method:
|
|
47
|
+
const authenticate = async (code, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.authCallback), authAPIOptions, otherOptions, {
|
|
48
|
+
method: bitbucketEndpoints.authCallback.method,
|
|
19
49
|
body: { code }
|
|
20
50
|
});
|
|
21
51
|
/**
|
|
22
52
|
* Get user's Bitbucket repositories
|
|
23
53
|
* @param token - Optional Bitbucket access token. If not provided, backend will use session.
|
|
24
54
|
*/
|
|
25
|
-
const getRepositories = async (token, otherOptions = {}) => await fetcher(
|
|
55
|
+
const getRepositories = async (token, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.listRepos), authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
|
|
26
56
|
/**
|
|
27
57
|
* Check if intlayer.config.ts exists in a Bitbucket repository
|
|
28
58
|
* @param token - Optional Bitbucket access token. If not provided, backend will use session.
|
|
@@ -30,8 +60,8 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
30
60
|
* @param repoSlug - Repository slug
|
|
31
61
|
* @param branch - Branch name (default: 'main')
|
|
32
62
|
*/
|
|
33
|
-
const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await fetcher(
|
|
34
|
-
method:
|
|
63
|
+
const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await fetcher(buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.checkConfig), authAPIOptions, otherOptions, {
|
|
64
|
+
method: bitbucketEndpoints.checkConfig.method,
|
|
35
65
|
body: {
|
|
36
66
|
token: token ?? void 0,
|
|
37
67
|
workspace,
|
|
@@ -47,8 +77,8 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
47
77
|
* @param branch - Branch name (default: 'main')
|
|
48
78
|
* @param path - File path (default: 'intlayer.config.ts')
|
|
49
79
|
*/
|
|
50
|
-
const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await fetcher(
|
|
51
|
-
method:
|
|
80
|
+
const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await fetcher(buildRouteURL(backendURL, bitbucketGroup, bitbucketEndpoints.getConfigFile), authAPIOptions, otherOptions, {
|
|
81
|
+
method: bitbucketEndpoints.getConfigFile.method,
|
|
52
82
|
body: {
|
|
53
83
|
token: token ?? void 0,
|
|
54
84
|
workspace,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitbucket.mjs","names":[],"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
|
|
1
|
+
{"version":3,"file":"bitbucket.mjs","names":[],"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,aAAa;EAAE,QAAQ;EAAQ,MAAM;CAAgB;CACrD,eAAe;EAAE,QAAQ;EAAQ,MAAM;CAAmB;AAC5D;AAEA,MAAa,mBACX,iBAAiC,CAAC,GAClC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAc,OAAO,cAAc;;;;;CAM7D,MAAM,aAAa,OACjB,aACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,gBAAgB,mBAAmB,UAAU,GACvE,gBACA,cACA,EACE,QAAQ,EAAE,YAAY,EACxB,CACF;;;;;CAMF,MAAM,eAAe,OACnB,MACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cACE,YACA,gBACA,mBAAmB,YACrB,GACA,gBACA,cACA;EACE,QAAQ,mBAAmB,aAAa;EACxC,MAAM,EAAE,KAAK;CACf,CACF;;;;;CAMF,MAAM,kBAAkB,OACtB,OACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,gBAAgB,mBAAmB,SAAS,GACtE,gBACA,cACA,EACE,QAAQ,QAAQ,EAAE,MAAM,IAAI,OAC9B,CACF;;;;;;;;CASF,MAAM,sBAAsB,OAC1B,OACA,WACA,UACA,SAAiB,QACjB,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,gBAAgB,mBAAmB,WAAW,GACxE,gBACA,cACA;EACE,QAAQ,mBAAmB,YAAY;EACvC,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,MAAM,QACJ,cACE,YACA,gBACA,mBAAmB,aACrB,GACA,gBACA,cACA;EACE,QAAQ,mBAAmB,cAAc;EACzC,MAAM;GACJ,OAAO,SAAS;GAChB;GACA;GACA;GACA;EACF;CACF,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,oBAAoB,eAAe,eAAe"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
|
+
import { createForgeAPI } from "./forge.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayerAPI/codeberg.ts
|
|
5
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
6
|
+
const codebergGroup = { prefix: "/api/codeberg" };
|
|
7
|
+
/** Codeberg (Forgejo) repositories of the linked account. */
|
|
8
|
+
const getCodebergAPI = createForgeAPI(codebergGroup);
|
|
9
|
+
/**
|
|
10
|
+
* Authenticated `codeberg` endpoint bound to an Intlayer CMS authenticator.
|
|
11
|
+
*
|
|
12
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
13
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
14
|
+
*/
|
|
15
|
+
const codebergEndpoint = createEndpoint(getCodebergAPI);
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { codebergEndpoint, getCodebergAPI };
|
|
19
|
+
//# sourceMappingURL=codeberg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeberg.mjs","names":[],"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,iBAAiB,eAAe,aAAa;;;;;;;AAQ1D,MAAa,mBAAmB,eAAe,cAAc"}
|
|
@@ -1,32 +1,78 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/dictionary.ts
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const dictionaryGroup = { prefix: "/api/dictionary" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const dictionaryEndpoints = {
|
|
15
|
+
getDictionaries: {
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: "/"
|
|
18
|
+
},
|
|
19
|
+
getDictionariesKeys: {
|
|
20
|
+
method: "GET",
|
|
21
|
+
path: "/keys"
|
|
22
|
+
},
|
|
23
|
+
getDictionariesUpdateTimestamp: {
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: "/update"
|
|
26
|
+
},
|
|
27
|
+
getDictionariesByKeys: {
|
|
28
|
+
method: "GET",
|
|
29
|
+
path: "/by-keys"
|
|
30
|
+
},
|
|
31
|
+
getDictionary: {
|
|
32
|
+
method: "GET",
|
|
33
|
+
path: "/:dictionaryKey"
|
|
34
|
+
},
|
|
35
|
+
addDictionary: {
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/"
|
|
38
|
+
},
|
|
39
|
+
pushDictionaries: {
|
|
40
|
+
method: "PATCH",
|
|
41
|
+
path: "/"
|
|
42
|
+
},
|
|
43
|
+
updateDictionary: {
|
|
44
|
+
method: "PUT",
|
|
45
|
+
path: "/:dictionaryId"
|
|
46
|
+
},
|
|
47
|
+
deleteDictionary: {
|
|
48
|
+
method: "DELETE",
|
|
49
|
+
path: "/:dictionaryId"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
6
52
|
const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
-
const
|
|
53
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
8
54
|
/**
|
|
9
55
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
10
56
|
* @param filters - Filters and pagination options.
|
|
11
57
|
*/
|
|
12
|
-
const getDictionaries = async (filters, otherOptions = {}) => await fetcher(
|
|
58
|
+
const getDictionaries = async (filters, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionaries), authAPIOptions, otherOptions, {
|
|
13
59
|
cache: "no-store",
|
|
14
60
|
params: filters
|
|
15
61
|
});
|
|
16
62
|
/**
|
|
17
63
|
* Retrieves a list of dictionary keys related to the project.
|
|
18
64
|
*/
|
|
19
|
-
const getDictionariesKeys = async (otherOptions = {}) => await fetcher(
|
|
65
|
+
const getDictionariesKeys = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesKeys), authAPIOptions, otherOptions, { cache: "no-store" });
|
|
20
66
|
/**
|
|
21
67
|
* Retrieves a list of dictionary keys related to the project.
|
|
22
68
|
*/
|
|
23
|
-
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await fetcher(
|
|
69
|
+
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesUpdateTimestamp), authAPIOptions, otherOptions, { cache: "no-store" });
|
|
24
70
|
/**
|
|
25
71
|
* Retrieves a dictionary by its key and version.
|
|
26
72
|
* @param dictionaryKey - Dictionary key.
|
|
27
73
|
* @param version - Dictionary version of content.
|
|
28
74
|
*/
|
|
29
|
-
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await fetcher(
|
|
75
|
+
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionary, { dictionaryKey }), authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
|
|
30
76
|
/**
|
|
31
77
|
* Retrieves several dictionaries at once from their keys, in a single
|
|
32
78
|
* request. Keys matching no dictionary are absent from the result, so the
|
|
@@ -35,7 +81,7 @@ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
35
81
|
* @param dictionaryKeys - Dictionary keys to retrieve.
|
|
36
82
|
* @param version - Dictionary version of content.
|
|
37
83
|
*/
|
|
38
|
-
const getDictionariesByKeys = async (dictionaryKeys, version, otherOptions = {}) => await fetcher(
|
|
84
|
+
const getDictionariesByKeys = async (dictionaryKeys, version, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesByKeys), authAPIOptions, otherOptions, {
|
|
39
85
|
cache: "no-store",
|
|
40
86
|
params: {
|
|
41
87
|
keys: dictionaryKeys.join(","),
|
|
@@ -46,27 +92,27 @@ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
46
92
|
* Adds a new dictionary to the database.
|
|
47
93
|
* @param dictionary - Dictionary data.
|
|
48
94
|
*/
|
|
49
|
-
const addDictionary = async (body, otherOptions = {}) => await fetcher(
|
|
50
|
-
method:
|
|
95
|
+
const addDictionary = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.addDictionary), authAPIOptions, otherOptions, {
|
|
96
|
+
method: dictionaryEndpoints.addDictionary.method,
|
|
51
97
|
body
|
|
52
98
|
});
|
|
53
|
-
const pushDictionaries = async (dictionaries, otherOptions = {}) => await fetcher(
|
|
54
|
-
method:
|
|
99
|
+
const pushDictionaries = async (dictionaries, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.pushDictionaries), authAPIOptions, otherOptions, {
|
|
100
|
+
method: dictionaryEndpoints.pushDictionaries.method,
|
|
55
101
|
body: { dictionaries }
|
|
56
102
|
});
|
|
57
103
|
/**
|
|
58
104
|
* Updates an existing dictionary in the database.
|
|
59
105
|
* @param dictionary - Updated dictionary data.
|
|
60
106
|
*/
|
|
61
|
-
const updateDictionary = async (dictionary, otherOptions = {}) => await fetcher(
|
|
62
|
-
method:
|
|
107
|
+
const updateDictionary = async (dictionary, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.updateDictionary, { dictionaryId: String(dictionary.id) }), authAPIOptions, otherOptions, {
|
|
108
|
+
method: dictionaryEndpoints.updateDictionary.method,
|
|
63
109
|
body: dictionary
|
|
64
110
|
});
|
|
65
111
|
/**
|
|
66
112
|
* Deletes a dictionary from the database by its ID.
|
|
67
113
|
* @param id - Dictionary ID.
|
|
68
114
|
*/
|
|
69
|
-
const deleteDictionary = async (id, otherOptions = {}) => await fetcher(
|
|
115
|
+
const deleteDictionary = async (id, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, dictionaryGroup, dictionaryEndpoints.deleteDictionary, { dictionaryId: String(id) }), authAPIOptions, otherOptions, { method: dictionaryEndpoints.deleteDictionary.method });
|
|
70
116
|
return {
|
|
71
117
|
getDictionaries,
|
|
72
118
|
getDictionariesKeys,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesByKeysResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\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 getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n `${PROJECT_API_ROUTE}/update`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Retrieves several dictionaries at once from their keys, in a single\n * request. Keys matching no dictionary are absent from the result, so the\n * caller should reconcile the response against the requested keys.\n *\n * @param dictionaryKeys - Dictionary keys to retrieve.\n * @param version - Dictionary version of content.\n */\n const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesByKeysResult>(\n `${PROJECT_API_ROUTE}/by-keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n keys: dictionaryKeys.join(','),\n version: version?.toString(),\n },\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionary.id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}/${id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n getDictionariesByKeys,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n\n/**\n * Authenticated `dictionary` 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 dictionaryEndpoint = createEndpoint(getDictionaryAPI);\n"],"mappings":";;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CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,IACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,kBAAkB,GAAG,MACxB,gBACA,cACA,EACE,QAAQ,SACV,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,qBAAqB,eAAe,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n DictionaryRoutes,\n dictionaryContract,\n GetDictionariesByKeysResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '@intlayer/backend-contract/dictionary';\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 dictionaryGroup = {\n prefix: '/api/dictionary',\n} as const satisfies Pick<typeof dictionaryContract, '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 dictionaryEndpoints = {\n getDictionaries: { method: 'GET', path: '/' },\n getDictionariesKeys: { method: 'GET', path: '/keys' },\n getDictionariesUpdateTimestamp: { method: 'GET', path: '/update' },\n getDictionariesByKeys: { method: 'GET', path: '/by-keys' },\n getDictionary: { method: 'GET', path: '/:dictionaryKey' },\n addDictionary: { method: 'POST', path: '/' },\n pushDictionaries: { method: 'PATCH', path: '/' },\n updateDictionary: { method: 'PUT', path: '/:dictionaryId' },\n deleteDictionary: { method: 'DELETE', path: '/:dictionaryId' },\n} as const satisfies RouteEndpoints<DictionaryRoutes>;\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.getDictionaries\n ),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.getDictionariesKeys\n ),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.getDictionariesUpdateTimestamp\n ),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.getDictionary,\n { dictionaryKey }\n ),\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Retrieves several dictionaries at once from their keys, in a single\n * request. Keys matching no dictionary are absent from the result, so the\n * caller should reconcile the response against the requested keys.\n *\n * @param dictionaryKeys - Dictionary keys to retrieve.\n * @param version - Dictionary version of content.\n */\n const getDictionariesByKeys = async (\n dictionaryKeys: string[],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesByKeysResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.getDictionariesByKeys\n ),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n keys: dictionaryKeys.join(','),\n version: version?.toString(),\n },\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.addDictionary\n ),\n authAPIOptions,\n otherOptions,\n {\n method: dictionaryEndpoints.addDictionary.method,\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.pushDictionaries\n ),\n authAPIOptions,\n otherOptions,\n {\n method: dictionaryEndpoints.pushDictionaries.method,\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.updateDictionary,\n { dictionaryId: String(dictionary.id) }\n ),\n authAPIOptions,\n otherOptions,\n {\n method: dictionaryEndpoints.updateDictionary.method,\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n buildRouteURL(\n backendURL,\n dictionaryGroup,\n dictionaryEndpoints.deleteDictionary,\n { dictionaryId: String(id) }\n ),\n authAPIOptions,\n otherOptions,\n {\n method: dictionaryEndpoints.deleteDictionary.method,\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n getDictionariesByKeys,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n\n/**\n * Authenticated `dictionary` 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 dictionaryEndpoint = createEndpoint(getDictionaryAPI);\n"],"mappings":";;;;;;;;AA6BA,MAAM,kBAAkB,EACtB,QAAQ,kBACV;;;;;AAMA,MAAM,sBAAsB;CAC1B,iBAAiB;EAAE,QAAQ;EAAO,MAAM;CAAI;CAC5C,qBAAqB;EAAE,QAAQ;EAAO,MAAM;CAAQ;CACpD,gCAAgC;EAAE,QAAQ;EAAO,MAAM;CAAU;CACjE,uBAAuB;EAAE,QAAQ;EAAO,MAAM;CAAW;CACzD,eAAe;EAAE,QAAQ;EAAO,MAAM;CAAkB;CACxD,eAAe;EAAE,QAAQ;EAAQ,MAAM;CAAI;CAC3C,kBAAkB;EAAE,QAAQ;EAAS,MAAM;CAAI;CAC/C,kBAAkB;EAAE,QAAQ;EAAO,MAAM;CAAiB;CAC1D,kBAAkB;EAAE,QAAQ;EAAU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BAAoB,iBAAiB;EAC7C,MAAM,EAAE,aAAa;CACvB,CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,YACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cACE,YACA,iBACA,oBAAoB,kBACpB,EAAE,cAAc,OAAO,WAAW,EAAE,EAAE,CACxC,GACA,gBACA,cACA;EACE,QAAQ,oBAAoB,iBAAiB;EAC7C,MAAM;CACR,CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,IACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cACE,YACA,iBACA,oBAAoB,kBACpB,EAAE,cAAc,OAAO,EAAE,EAAE,CAC7B,GACA,gBACA,cACA,EACE,QAAQ,oBAAoB,iBAAiB,OAC/C,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,qBAAqB,eAAe,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const editorURL = intlayerConfig?.editor?.editorURL ?? editor.editorURL;\n\n const EDITOR_API_ROUTE = `${editorURL}/api`;\n\n /**\n * Get the Intlayer configuration\n */\n const getConfiguration = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetConfigurationResult> => {\n const response = await fetcher<GetConfigurationResult>(\n `${EDITOR_API_ROUTE}/config`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetConfigurationResult;\n };\n\n /**\n * Get the Intlayer configuration\n */\n const getDictionaries = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetEditorDictionariesResult> => {\n const response = await fetcher<GetEditorDictionariesResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetEditorDictionariesResult;\n };\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const writeDictionary = async (\n body: WriteContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<WriteContentDeclarationResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n return {\n getDictionaries,\n getConfiguration,\n writeDictionary,\n };\n};\n\n/**\n * Authenticated `editor` 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 editorEndpoint = createEndpoint(getEditorAPI);\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\n\nexport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n};\n\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const editorURL = intlayerConfig?.editor?.editorURL ?? editor.editorURL;\n\n const EDITOR_API_ROUTE = `${editorURL}/api`;\n\n /**\n * Get the Intlayer configuration\n */\n const getConfiguration = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetConfigurationResult> => {\n const response = await fetcher<GetConfigurationResult>(\n `${EDITOR_API_ROUTE}/config`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetConfigurationResult;\n };\n\n /**\n * Get the Intlayer configuration\n */\n const getDictionaries = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetEditorDictionariesResult> => {\n const response = await fetcher<GetEditorDictionariesResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetEditorDictionariesResult;\n };\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const writeDictionary = async (\n body: WriteContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<WriteContentDeclarationResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n return {\n getDictionaries,\n getConfiguration,\n writeDictionary,\n };\n};\n\n/**\n * Authenticated `editor` 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 editorEndpoint = createEndpoint(getEditorAPI);\n"],"mappings":";;;;;AAmBA,MAAa,gBACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,mBAAmB,GAFP,gBAAgB,QAAQ,aAAa,OAAO,UAExB;;;;CAKtC,MAAM,mBAAmB,OACvB,eAA+B,CAAC,MACI;EAOpC,QAAO,MANgB,QACrB,GAAG,iBAAiB,UACpB,gBACA,YACF,EAEe,CAAC;CAClB;;;;CAKA,MAAM,kBAAkB,OACtB,eAA+B,CAAC,MACS;EAOzC,QAAO,MANgB,QACrB,GAAG,iBAAiB,cACpB,gBACA,YACF,EAEe,CAAC;CAClB;;;;;CAMA,MAAM,kBAAkB,OACtB,MACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,iBAAiB,cACpB,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;CAEF,OAAO;EACL;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,iBAAiB,eAAe,YAAY"}
|
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/environment.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const environmentGroup = { prefix: "/api/project/environment" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const environmentEndpoints = {
|
|
15
|
+
addEnvironment: {
|
|
9
16
|
method: "POST",
|
|
17
|
+
path: "/"
|
|
18
|
+
},
|
|
19
|
+
updateEnvironment: {
|
|
20
|
+
method: "PUT",
|
|
21
|
+
path: "/:environmentId"
|
|
22
|
+
},
|
|
23
|
+
deleteEnvironment: {
|
|
24
|
+
method: "DELETE",
|
|
25
|
+
path: "/:environmentId"
|
|
26
|
+
},
|
|
27
|
+
resetToProductionEnvironment: {
|
|
28
|
+
method: "PUT",
|
|
29
|
+
path: "/production/select"
|
|
30
|
+
},
|
|
31
|
+
selectEnvironment: {
|
|
32
|
+
method: "PUT",
|
|
33
|
+
path: "/:environmentId/select"
|
|
34
|
+
},
|
|
35
|
+
migrateEnvironment: {
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/migrate"
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getEnvironmentAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
41
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
42
|
+
const addEnvironment = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.addEnvironment), authAPIOptions, otherOptions, {
|
|
43
|
+
method: environmentEndpoints.addEnvironment.method,
|
|
10
44
|
body
|
|
11
45
|
});
|
|
12
|
-
const updateEnvironment = async (environmentId, body, otherOptions = {}) => await fetcher(
|
|
13
|
-
method:
|
|
46
|
+
const updateEnvironment = async (environmentId, body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.updateEnvironment, { environmentId }), authAPIOptions, otherOptions, {
|
|
47
|
+
method: environmentEndpoints.updateEnvironment.method,
|
|
14
48
|
body
|
|
15
49
|
});
|
|
16
|
-
const deleteEnvironment = async (environmentId, otherOptions = {}) => await fetcher(
|
|
17
|
-
const selectEnvironment = async (environmentId, otherOptions = {}) => await fetcher(
|
|
18
|
-
const resetToProductionEnvironment = async (otherOptions = {}) => await fetcher(
|
|
19
|
-
const migrateEnvironment = async (body, otherOptions = {}) => await fetcher(
|
|
20
|
-
method:
|
|
50
|
+
const deleteEnvironment = async (environmentId, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.deleteEnvironment, { environmentId }), authAPIOptions, otherOptions, { method: environmentEndpoints.deleteEnvironment.method });
|
|
51
|
+
const selectEnvironment = async (environmentId, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.selectEnvironment, { environmentId }), authAPIOptions, otherOptions, { method: environmentEndpoints.selectEnvironment.method });
|
|
52
|
+
const resetToProductionEnvironment = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.resetToProductionEnvironment), authAPIOptions, otherOptions, { method: environmentEndpoints.resetToProductionEnvironment.method });
|
|
53
|
+
const migrateEnvironment = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, environmentGroup, environmentEndpoints.migrateEnvironment), authAPIOptions, otherOptions, {
|
|
54
|
+
method: environmentEndpoints.migrateEnvironment.method,
|
|
21
55
|
body
|
|
22
56
|
});
|
|
23
57
|
return {
|