@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
|
@@ -2,10 +2,64 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_fetcher = require('../fetcher.cjs');
|
|
3
3
|
const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.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
8
|
//#region 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
|
|
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(
|
|
22
|
-
method:
|
|
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 = `${
|
|
84
|
+
const endpoint = `${(0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, scanGroup, scanEndpoints.scan)}?${params.toString()}`;
|
|
31
85
|
const response = await fetch(endpoint, {
|
|
32
|
-
method:
|
|
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(
|
|
75
|
-
method:
|
|
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(
|
|
83
|
-
const cancelRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(
|
|
84
|
-
const pauseRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(
|
|
85
|
-
const resumeRecursiveAudit = async (params, otherOptions = {}) => await require_fetcher.fetcher(
|
|
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(
|
|
90
|
-
method:
|
|
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(
|
|
98
|
-
method:
|
|
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(
|
|
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,
|
|
@@ -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,KAAK,UAAU,UAAU,KAAK,KAAK;GACpD,QAAQ;IACN,IAAI;KACF,MAAM,YAA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gB,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,MAAM;CAAI;CACjC,oBAAoB;EAAE,QAAQ;EAAO,MAAM;CAAgB;CA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2,28 +2,58 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_fetcher = require('../fetcher.cjs');
|
|
3
3
|
const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.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
8
|
//#region 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
|
|
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(
|
|
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(
|
|
19
|
-
method:
|
|
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(
|
|
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(
|
|
35
|
-
method:
|
|
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(
|
|
52
|
-
method:
|
|
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,
|
|
@@ -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
|
|
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,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,cAAcA,8BAAO,cAAcC;;;;;CAM7D,MAAM,aAAa,OACjB,aACA,eAA+B,CAAC,MAEhC,MAAMC,4BACJC,sDAAc,YAAY,gBAAgB,mBAAmB,UAAU,GACvE,gBACA,cACA,EACE,QAAQ,EAAE,YAAY,EACxB,CACF;;;;;CAMF,MAAM,eAAe,OACnB,MACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDACE,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,MAAMD,4BACJC,sDAAc,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,MAAMD,4BACJC,sDAAc,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,MAAMD,4BACJC,sDACE,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,oBAAoBC,6CAAe,eAAe"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
//#region 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
|
+
//#endregion
|
|
19
|
+
exports.codebergEndpoint = codebergEndpoint;
|
|
20
|
+
exports.getCodebergAPI = getCodebergAPI;
|
|
21
|
+
//# 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"}
|
|
@@ -2,32 +2,78 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_fetcher = require('../fetcher.cjs');
|
|
3
3
|
const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.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
8
|
//#region src/getIntlayerAPI/dictionary.ts
|
|
9
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
10
|
+
const dictionaryGroup = { prefix: "/api/dictionary" };
|
|
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 dictionaryEndpoints = {
|
|
16
|
+
getDictionaries: {
|
|
17
|
+
method: "GET",
|
|
18
|
+
path: "/"
|
|
19
|
+
},
|
|
20
|
+
getDictionariesKeys: {
|
|
21
|
+
method: "GET",
|
|
22
|
+
path: "/keys"
|
|
23
|
+
},
|
|
24
|
+
getDictionariesUpdateTimestamp: {
|
|
25
|
+
method: "GET",
|
|
26
|
+
path: "/update"
|
|
27
|
+
},
|
|
28
|
+
getDictionariesByKeys: {
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/by-keys"
|
|
31
|
+
},
|
|
32
|
+
getDictionary: {
|
|
33
|
+
method: "GET",
|
|
34
|
+
path: "/:dictionaryKey"
|
|
35
|
+
},
|
|
36
|
+
addDictionary: {
|
|
37
|
+
method: "POST",
|
|
38
|
+
path: "/"
|
|
39
|
+
},
|
|
40
|
+
pushDictionaries: {
|
|
41
|
+
method: "PATCH",
|
|
42
|
+
path: "/"
|
|
43
|
+
},
|
|
44
|
+
updateDictionary: {
|
|
45
|
+
method: "PUT",
|
|
46
|
+
path: "/:dictionaryId"
|
|
47
|
+
},
|
|
48
|
+
deleteDictionary: {
|
|
49
|
+
method: "DELETE",
|
|
50
|
+
path: "/:dictionaryId"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
7
53
|
const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
8
|
-
const
|
|
54
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL ?? _intlayer_config_defaultValues.BACKEND_URL;
|
|
9
55
|
/**
|
|
10
56
|
* Retrieves a list of dictionaries based on filters and pagination.
|
|
11
57
|
* @param filters - Filters and pagination options.
|
|
12
58
|
*/
|
|
13
|
-
const getDictionaries = async (filters, otherOptions = {}) => await require_fetcher.fetcher(
|
|
59
|
+
const getDictionaries = async (filters, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionaries), authAPIOptions, otherOptions, {
|
|
14
60
|
cache: "no-store",
|
|
15
61
|
params: filters
|
|
16
62
|
});
|
|
17
63
|
/**
|
|
18
64
|
* Retrieves a list of dictionary keys related to the project.
|
|
19
65
|
*/
|
|
20
|
-
const getDictionariesKeys = async (otherOptions = {}) => await require_fetcher.fetcher(
|
|
66
|
+
const getDictionariesKeys = async (otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesKeys), authAPIOptions, otherOptions, { cache: "no-store" });
|
|
21
67
|
/**
|
|
22
68
|
* Retrieves a list of dictionary keys related to the project.
|
|
23
69
|
*/
|
|
24
|
-
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await require_fetcher.fetcher(
|
|
70
|
+
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesUpdateTimestamp), authAPIOptions, otherOptions, { cache: "no-store" });
|
|
25
71
|
/**
|
|
26
72
|
* Retrieves a dictionary by its key and version.
|
|
27
73
|
* @param dictionaryKey - Dictionary key.
|
|
28
74
|
* @param version - Dictionary version of content.
|
|
29
75
|
*/
|
|
30
|
-
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await require_fetcher.fetcher(
|
|
76
|
+
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionary, { dictionaryKey }), authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
|
|
31
77
|
/**
|
|
32
78
|
* Retrieves several dictionaries at once from their keys, in a single
|
|
33
79
|
* request. Keys matching no dictionary are absent from the result, so the
|
|
@@ -36,7 +82,7 @@ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
36
82
|
* @param dictionaryKeys - Dictionary keys to retrieve.
|
|
37
83
|
* @param version - Dictionary version of content.
|
|
38
84
|
*/
|
|
39
|
-
const getDictionariesByKeys = async (dictionaryKeys, version, otherOptions = {}) => await require_fetcher.fetcher(
|
|
85
|
+
const getDictionariesByKeys = async (dictionaryKeys, version, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.getDictionariesByKeys), authAPIOptions, otherOptions, {
|
|
40
86
|
cache: "no-store",
|
|
41
87
|
params: {
|
|
42
88
|
keys: dictionaryKeys.join(","),
|
|
@@ -47,27 +93,27 @@ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
47
93
|
* Adds a new dictionary to the database.
|
|
48
94
|
* @param dictionary - Dictionary data.
|
|
49
95
|
*/
|
|
50
|
-
const addDictionary = async (body, otherOptions = {}) => await require_fetcher.fetcher(
|
|
51
|
-
method:
|
|
96
|
+
const addDictionary = async (body, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.addDictionary), authAPIOptions, otherOptions, {
|
|
97
|
+
method: dictionaryEndpoints.addDictionary.method,
|
|
52
98
|
body
|
|
53
99
|
});
|
|
54
|
-
const pushDictionaries = async (dictionaries, otherOptions = {}) => await require_fetcher.fetcher(
|
|
55
|
-
method:
|
|
100
|
+
const pushDictionaries = async (dictionaries, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.pushDictionaries), authAPIOptions, otherOptions, {
|
|
101
|
+
method: dictionaryEndpoints.pushDictionaries.method,
|
|
56
102
|
body: { dictionaries }
|
|
57
103
|
});
|
|
58
104
|
/**
|
|
59
105
|
* Updates an existing dictionary in the database.
|
|
60
106
|
* @param dictionary - Updated dictionary data.
|
|
61
107
|
*/
|
|
62
|
-
const updateDictionary = async (dictionary, otherOptions = {}) => await require_fetcher.fetcher(
|
|
63
|
-
method:
|
|
108
|
+
const updateDictionary = async (dictionary, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.updateDictionary, { dictionaryId: String(dictionary.id) }), authAPIOptions, otherOptions, {
|
|
109
|
+
method: dictionaryEndpoints.updateDictionary.method,
|
|
64
110
|
body: dictionary
|
|
65
111
|
});
|
|
66
112
|
/**
|
|
67
113
|
* Deletes a dictionary from the database by its ID.
|
|
68
114
|
* @param id - Dictionary ID.
|
|
69
115
|
*/
|
|
70
|
-
const deleteDictionary = async (id, otherOptions = {}) => await require_fetcher.fetcher(
|
|
116
|
+
const deleteDictionary = async (id, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, dictionaryGroup, dictionaryEndpoints.deleteDictionary, { dictionaryId: String(id) }), authAPIOptions, otherOptions, { method: dictionaryEndpoints.deleteDictionary.method });
|
|
71
117
|
return {
|
|
72
118
|
getDictionaries,
|
|
73
119
|
getDictionariesKeys,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.cjs","names":["editor","fetcher","createEndpoint"],"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":";;;;;;AAuBA,MAAa,oBACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAcA,8BAAO,WAExB;;;;;CAMxC,MAAM,kBAAkB,OACtB,SACA,eAA+B,CAAC,MAEhC,MAAMC,wBACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;CACV,CACF;;;;CAKF,MAAM,sBAAsB,OAAO,eAA+B,CAAC,MACjE,MAAMA,wBACJ,GAAG,kBAAkB,QACrB,gBACA,cACA,EACE,OAAO,WACT,CACF;;;;CAKF,MAAM,iCAAiC,OACrC,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,kBAAkB,UACrB,gBACA,cACA,EACE,OAAO,WACT,CACF;;;;;;CAOF,MAAM,gBAAgB,OACpB,eACA,SACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,kBAAkB,GAAG,iBACxB,gBACA,cACA,EACE,QAAQ,UAAU,EAAE,SAAS,QAAQ,SAAS,EAAE,IAAI,OACtD,CACF;;;;;;;;;CAUF,MAAM,wBAAwB,OAC5B,gBACA,SACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,kBAAkB,WACrB,gBACA,cACA;EACE,OAAO;EACP,QAAQ;GACN,MAAM,eAAe,KAAK,GAAG;GAC7B,SAAS,SAAS,SAAS;EAC7B;CACF,CACF;;;;;CAMF,MAAM,gBAAgB,OACpB,MACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;CAEF,MAAM,mBAAmB,OACvB,cACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,aAAa;CACvB,CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,YACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,kBAAkB,GAAG,WAAW,MACnC,gBACA,cACA;EACE,QAAQ;EACR,MAAM;CACR,CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,IACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,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,qBAAqBC,6CAAe,gBAAgB"}
|
|
1
|
+
{"version":3,"file":"dictionary.cjs","names":["editor","BACKEND_URL","fetcher","buildRouteURL","createEndpoint"],"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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SAAS,QAAQ,SAAS,EAAE,IAAI,OACtD,CACF;;;;;;;;;CAUF,MAAM,wBAAwB,OAC5B,gBACA,SACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDACE,YACA,iBACA,oBAAoB,qBACtB,GACA,gBACA,cACA;EACE,OAAO;EACP,QAAQ;GACN,MAAM,eAAe,KAAK,GAAG;GAC7B,SAAS,SAAS,SAAS;EAC7B;CACF,CACF;;;;;CAMF,MAAM,gBAAgB,OACpB,MACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDACE,YACA,iBACA,oBAAoB,aACtB,GACA,gBACA,cACA;EACE,QAAQ,oBAAoB,cAAc;EAC1C;CACF,CACF;CAEF,MAAM,mBAAmB,OACvB,cACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDACE,YACA,iBACA,oBAAoB,gBACtB,GACA,gBACA,cACA;EACE,QAAQ,oBAAoB,iBAAiB;EAC7C,MAAM,EAAE,aAAa;CACvB,CACF;;;;;CAMF,MAAM,mBAAmB,OACvB,YACA,eAA+B,CAAC,MAEhC,MAAMD,4BACJC,sDACE,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,MAAMD,4BACJC,sDACE,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,qBAAqBC,6CAAe,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.cjs","names":["editor","fetcher","createEndpoint"],"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.cjs","names":["editor","fetcher","createEndpoint"],"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,aAAaA,8BAAO,UAExB;;;;CAKtC,MAAM,mBAAmB,OACvB,eAA+B,CAAC,MACI;EAOpC,QAAO,MANgBC,wBACrB,GAAG,iBAAiB,UACpB,gBACA,YACF,EAEe,CAAC;CAClB;;;;CAKA,MAAM,kBAAkB,OACtB,eAA+B,CAAC,MACS;EAOzC,QAAO,MANgBA,wBACrB,GAAG,iBAAiB,cACpB,gBACA,YACF,EAEe,CAAC;CAClB;;;;;CAMA,MAAM,kBAAkB,OACtB,MACA,eAA+B,CAAC,MAEhC,MAAMA,wBACJ,GAAG,iBAAiB,cACpB,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;CAEF,OAAO;EACL;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,iBAAiBC,6CAAe,YAAY"}
|
|
@@ -2,23 +2,57 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_fetcher = require('../fetcher.cjs');
|
|
3
3
|
const require_cms_createIntlayerCMS = require('../cms/createIntlayerCMS.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
8
|
//#region src/getIntlayerAPI/environment.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
10
|
+
const environmentGroup = { prefix: "/api/project/environment" };
|
|
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 environmentEndpoints = {
|
|
16
|
+
addEnvironment: {
|
|
10
17
|
method: "POST",
|
|
18
|
+
path: "/"
|
|
19
|
+
},
|
|
20
|
+
updateEnvironment: {
|
|
21
|
+
method: "PUT",
|
|
22
|
+
path: "/:environmentId"
|
|
23
|
+
},
|
|
24
|
+
deleteEnvironment: {
|
|
25
|
+
method: "DELETE",
|
|
26
|
+
path: "/:environmentId"
|
|
27
|
+
},
|
|
28
|
+
resetToProductionEnvironment: {
|
|
29
|
+
method: "PUT",
|
|
30
|
+
path: "/production/select"
|
|
31
|
+
},
|
|
32
|
+
selectEnvironment: {
|
|
33
|
+
method: "PUT",
|
|
34
|
+
path: "/:environmentId/select"
|
|
35
|
+
},
|
|
36
|
+
migrateEnvironment: {
|
|
37
|
+
method: "POST",
|
|
38
|
+
path: "/migrate"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const getEnvironmentAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
42
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL ?? _intlayer_config_defaultValues.BACKEND_URL;
|
|
43
|
+
const addEnvironment = async (body, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.addEnvironment), authAPIOptions, otherOptions, {
|
|
44
|
+
method: environmentEndpoints.addEnvironment.method,
|
|
11
45
|
body
|
|
12
46
|
});
|
|
13
|
-
const updateEnvironment = async (environmentId, body, otherOptions = {}) => await require_fetcher.fetcher(
|
|
14
|
-
method:
|
|
47
|
+
const updateEnvironment = async (environmentId, body, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.updateEnvironment, { environmentId }), authAPIOptions, otherOptions, {
|
|
48
|
+
method: environmentEndpoints.updateEnvironment.method,
|
|
15
49
|
body
|
|
16
50
|
});
|
|
17
|
-
const deleteEnvironment = async (environmentId, otherOptions = {}) => await require_fetcher.fetcher(
|
|
18
|
-
const selectEnvironment = async (environmentId, otherOptions = {}) => await require_fetcher.fetcher(
|
|
19
|
-
const resetToProductionEnvironment = async (otherOptions = {}) => await require_fetcher.fetcher(
|
|
20
|
-
const migrateEnvironment = async (body, otherOptions = {}) => await require_fetcher.fetcher(
|
|
21
|
-
method:
|
|
51
|
+
const deleteEnvironment = async (environmentId, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.deleteEnvironment, { environmentId }), authAPIOptions, otherOptions, { method: environmentEndpoints.deleteEnvironment.method });
|
|
52
|
+
const selectEnvironment = async (environmentId, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.selectEnvironment, { environmentId }), authAPIOptions, otherOptions, { method: environmentEndpoints.selectEnvironment.method });
|
|
53
|
+
const resetToProductionEnvironment = async (otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.resetToProductionEnvironment), authAPIOptions, otherOptions, { method: environmentEndpoints.resetToProductionEnvironment.method });
|
|
54
|
+
const migrateEnvironment = async (body, otherOptions = {}) => await require_fetcher.fetcher((0, _intlayer_backend_contract_defineRoute.buildRouteURL)(backendURL, environmentGroup, environmentEndpoints.migrateEnvironment), authAPIOptions, otherOptions, {
|
|
55
|
+
method: environmentEndpoints.migrateEnvironment.method,
|
|
22
56
|
body
|
|
23
57
|
});
|
|
24
58
|
return {
|