payload-intl 1.1.1 → 1.1.3
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/endpoints/get-messages.js +3 -3
- package/dist/endpoints/get-messages.js.map +1 -1
- package/dist/requests/fetchMessageFromAPI.d.ts +10 -0
- package/dist/requests/fetchMessageFromAPI.d.ts.map +1 -0
- package/dist/requests/fetchMessageFromAPI.js +13 -0
- package/dist/requests/fetchMessageFromAPI.js.map +1 -0
- package/dist/requests/fetchMessageFromPayload.d.ts +3 -0
- package/dist/requests/fetchMessageFromPayload.d.ts.map +1 -0
- package/dist/requests/fetchMessageFromPayload.js +30 -0
- package/dist/requests/fetchMessageFromPayload.js.map +1 -0
- package/dist/requests/fetchMessages.d.ts +1 -9
- package/dist/requests/fetchMessages.d.ts.map +1 -1
- package/dist/requests/fetchMessages.js +8 -36
- package/dist/requests/fetchMessages.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ENDPOINT_CONFIG as a } from "../const.js";
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
2
|
+
import { fetchMessagesFromPayload as t } from "../requests/fetchMessageFromPayload.js";
|
|
3
|
+
const m = {
|
|
4
4
|
...a.getMessages,
|
|
5
5
|
handler: async (s) => {
|
|
6
6
|
const { locale: e } = s.routeParams, o = await t(s.payload, e);
|
|
@@ -8,6 +8,6 @@ const c = {
|
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
export {
|
|
11
|
-
|
|
11
|
+
m as getMessagesEndpoint
|
|
12
12
|
};
|
|
13
13
|
//# sourceMappingURL=get-messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-messages.js","sources":["../../src/endpoints/get-messages.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload';\nimport { ENDPOINT_CONFIG } from '@/const';\nimport {
|
|
1
|
+
{"version":3,"file":"get-messages.js","sources":["../../src/endpoints/get-messages.ts"],"sourcesContent":["import type { Endpoint, PayloadRequest } from 'payload';\nimport { ENDPOINT_CONFIG } from '@/const';\nimport { fetchMessagesFromPayload } from '@/requests/fetchMessageFromPayload';\n\nexport const getMessagesEndpoint: Endpoint = {\n ...ENDPOINT_CONFIG.getMessages,\n handler: async (req: PayloadRequest) => {\n const { locale } = req.routeParams as { locale: string };\n const messages = await fetchMessagesFromPayload(req.payload, locale);\n return Response.json(messages);\n },\n};\n"],"names":["getMessagesEndpoint","ENDPOINT_CONFIG","req","locale","messages","fetchMessagesFromPayload"],"mappings":";;AAIO,MAAMA,IAAgC;AAAA,EAC3C,GAAGC,EAAgB;AAAA,EACnB,SAAS,OAAOC,MAAwB;AACtC,UAAM,EAAE,QAAAC,MAAWD,EAAI,aACjBE,IAAW,MAAMC,EAAyBH,EAAI,SAASC,CAAM;AACnE,WAAO,SAAS,KAAKC,CAAQ;AAAA,EAC/B;AACF;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface MessagesRequestConfig {
|
|
2
|
+
serverUrl: string;
|
|
3
|
+
/**
|
|
4
|
+
* If defined a custom api route in your payload.config.ts (`routes.api`), add them same here.
|
|
5
|
+
* @default 'api'
|
|
6
|
+
*/
|
|
7
|
+
apiRoute?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function fetchMessagesFromAPI({ serverUrl, apiRoute }: MessagesRequestConfig, locale: string): Promise<any>;
|
|
10
|
+
//# sourceMappingURL=fetchMessageFromAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchMessageFromAPI.d.ts","sourceRoot":"","sources":["../../src/requests/fetchMessageFromAPI.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,oBAAoB,CACxC,EAAE,SAAS,EAAE,QAAgB,EAAE,EAAE,qBAAqB,EACtD,MAAM,EAAE,MAAM,gBAmBf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ENDPOINT_CONFIG as i } from "../const.js";
|
|
2
|
+
async function g({ serverUrl: s, apiRoute: a = "api" }, e) {
|
|
3
|
+
const r = a.replace(/^\/|\/$/g, ""), n = i.getMessages.path.replace(/^\/|\/$/g, "").replace(":locale", e), c = `/${r}/${n}`, t = new URL(c, s);
|
|
4
|
+
console.debug(`PAYLOAD_INTL: Fetching messages from API: ${t.toString()}`);
|
|
5
|
+
const o = await fetch(t.toString());
|
|
6
|
+
if (!o.ok)
|
|
7
|
+
throw new Error(`Failed to fetch messages for locale ${e}`);
|
|
8
|
+
return await o.json();
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
g as fetchMessagesFromAPI
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=fetchMessageFromAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchMessageFromAPI.js","sources":["../../src/requests/fetchMessageFromAPI.ts"],"sourcesContent":["import { ENDPOINT_CONFIG } from '@/const';\n\nexport interface MessagesRequestConfig {\n serverUrl: string;\n /**\n * If defined a custom api route in your payload.config.ts (`routes.api`), add them same here.\n * @default 'api'\n */\n apiRoute?: string;\n}\n\nexport async function fetchMessagesFromAPI(\n { serverUrl, apiRoute = 'api' }: MessagesRequestConfig,\n locale: string,\n) {\n const cleanApiRoute = apiRoute.replace(/^\\/|\\/$/g, '');\n\n const relativePath = ENDPOINT_CONFIG.getMessages.path\n .replace(/^\\/|\\/$/g, '')\n .replace(':locale', locale);\n\n const fullPath = `/${cleanApiRoute}/${relativePath}`;\n\n const url = new URL(fullPath, serverUrl);\n\n console.debug(`PAYLOAD_INTL: Fetching messages from API: ${url.toString()}`);\n\n const response = await fetch(url.toString());\n if (!response.ok) {\n throw new Error(`Failed to fetch messages for locale ${locale}`);\n }\n return await response.json();\n}\n"],"names":["fetchMessagesFromAPI","serverUrl","apiRoute","locale","cleanApiRoute","relativePath","ENDPOINT_CONFIG","fullPath","url","response"],"mappings":";AAWA,eAAsBA,EACpB,EAAE,WAAAC,GAAW,UAAAC,IAAW,MAAA,GACxBC,GACA;AACA,QAAMC,IAAgBF,EAAS,QAAQ,YAAY,EAAE,GAE/CG,IAAeC,EAAgB,YAAY,KAC9C,QAAQ,YAAY,EAAE,EACtB,QAAQ,WAAWH,CAAM,GAEtBI,IAAW,IAAIH,CAAa,IAAIC,CAAY,IAE5CG,IAAM,IAAI,IAAID,GAAUN,CAAS;AAEvC,UAAQ,MAAM,6CAA6CO,EAAI,SAAA,CAAU,EAAE;AAE3E,QAAMC,IAAW,MAAM,MAAMD,EAAI,UAAU;AAC3C,MAAI,CAACC,EAAS;AACZ,UAAM,IAAI,MAAM,uCAAuCN,CAAM,EAAE;AAEjE,SAAO,MAAMM,EAAS,KAAA;AACxB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchMessageFromPayload.d.ts","sourceRoot":"","sources":["../../src/requests/fetchMessageFromPayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,gBAkCf"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getPluginContext as a } from "../utils/config.js";
|
|
2
|
+
import { getErrorMessage as c } from "../utils/error-handling.js";
|
|
3
|
+
async function g(t, o) {
|
|
4
|
+
const {
|
|
5
|
+
docs: [r]
|
|
6
|
+
} = await t.find({
|
|
7
|
+
collection: a(t.config).collectionSlug,
|
|
8
|
+
where: { locale: { equals: o } }
|
|
9
|
+
});
|
|
10
|
+
if (!r)
|
|
11
|
+
return console.warn(`No messages found for locale ${o}`), {};
|
|
12
|
+
const { url: n } = r;
|
|
13
|
+
console.debug(`PAYLOAD_INTL: Fetching messages from stroage: ${n}`);
|
|
14
|
+
const e = await fetch(n);
|
|
15
|
+
if (!e.ok) {
|
|
16
|
+
const s = await c(e);
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Could not fetch messages for locale "${o}": ${s}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (e.headers.get("content-type") !== "application/json")
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Could not fetch messages for locale "${o}": The page did not return a JSON file.`
|
|
24
|
+
);
|
|
25
|
+
return await e.json();
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
g as fetchMessagesFromPayload
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=fetchMessageFromPayload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchMessageFromPayload.js","sources":["../../src/requests/fetchMessageFromPayload.ts"],"sourcesContent":["import type { BasePayload } from 'payload';\nimport { getPluginContext } from '@/utils/config';\nimport { getErrorMessage } from '@/utils/error-handling';\n\nexport async function fetchMessagesFromPayload(\n payload: BasePayload,\n locale: string,\n) {\n const {\n docs: [doc],\n } = await payload.find({\n collection: getPluginContext(payload.config).collectionSlug,\n where: { locale: { equals: locale } },\n });\n\n if (!doc) {\n console.warn(`No messages found for locale ${locale}`);\n return {};\n }\n\n const { url } = doc as unknown as { url: string };\n\n console.debug(`PAYLOAD_INTL: Fetching messages from stroage: ${url}`);\n\n const response = await fetch(url);\n\n if (!response.ok) {\n const error = await getErrorMessage(response);\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": ${error}`,\n );\n }\n\n if (response.headers.get('content-type') !== 'application/json') {\n throw new Error(\n `Could not fetch messages for locale \"${locale}\": The page did not return a JSON file.`,\n );\n }\n\n return await response.json();\n}\n"],"names":["fetchMessagesFromPayload","payload","locale","doc","getPluginContext","url","response","error","getErrorMessage"],"mappings":";;AAIA,eAAsBA,EACpBC,GACAC,GACA;AACA,QAAM;AAAA,IACJ,MAAM,CAACC,CAAG;AAAA,EAAA,IACR,MAAMF,EAAQ,KAAK;AAAA,IACrB,YAAYG,EAAiBH,EAAQ,MAAM,EAAE;AAAA,IAC7C,OAAO,EAAE,QAAQ,EAAE,QAAQC,IAAO;AAAA,EAAE,CACrC;AAED,MAAI,CAACC;AACH,mBAAQ,KAAK,gCAAgCD,CAAM,EAAE,GAC9C,CAAA;AAGT,QAAM,EAAE,KAAAG,MAAQF;AAEhB,UAAQ,MAAM,iDAAiDE,CAAG,EAAE;AAEpE,QAAMC,IAAW,MAAM,MAAMD,CAAG;AAEhC,MAAI,CAACC,EAAS,IAAI;AAChB,UAAMC,IAAQ,MAAMC,EAAgBF,CAAQ;AAC5C,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM,MAAMK,CAAK;AAAA,IAAA;AAAA,EAE7D;AAEA,MAAID,EAAS,QAAQ,IAAI,cAAc,MAAM;AAC3C,UAAM,IAAI;AAAA,MACR,wCAAwCJ,CAAM;AAAA,IAAA;AAIlD,SAAO,MAAMI,EAAS,KAAA;AACxB;"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { BasePayload } from 'payload';
|
|
2
2
|
import { Messages } from '../types';
|
|
3
|
-
|
|
4
|
-
serverUrl: string;
|
|
5
|
-
/**
|
|
6
|
-
* If defined a custom api route in your payload.config.ts (`routes.api`), add them same here.
|
|
7
|
-
* @default 'api'
|
|
8
|
-
*/
|
|
9
|
-
apiRoute?: string;
|
|
10
|
-
}
|
|
3
|
+
import { MessagesRequestConfig } from './fetchMessageFromAPI';
|
|
11
4
|
export declare function fetchMessages(config: MessagesRequestConfig, locale: string): Promise<Messages>;
|
|
12
5
|
export declare function fetchMessages(payload: BasePayload, locale: string): Promise<Messages>;
|
|
13
|
-
export {};
|
|
14
6
|
//# sourceMappingURL=fetchMessages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchMessages.d.ts","sourceRoot":"","sources":["../../src/requests/fetchMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchMessages.d.ts","sourceRoot":"","sources":["../../src/requests/fetchMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,wBAAsB,aAAa,CACjC,MAAM,EAAE,qBAAqB,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrB,wBAAsB,aAAa,CACjC,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -1,41 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
`PAYLOAD_INTL: Fetching messages from API: ${c.toString()}`
|
|
9
|
-
);
|
|
10
|
-
const i = await fetch(c.toString());
|
|
11
|
-
if (!i.ok)
|
|
12
|
-
throw new Error(`Failed to fetch messages for locale ${e}`);
|
|
13
|
-
return await i.json();
|
|
1
|
+
async function r(e, t) {
|
|
2
|
+
if ("serverUrl" in e) {
|
|
3
|
+
const { fetchMessagesFromAPI: s } = await import("./fetchMessageFromAPI.js");
|
|
4
|
+
return s(e, t);
|
|
5
|
+
} else {
|
|
6
|
+
const { fetchMessagesFromPayload: s } = await import("./fetchMessageFromPayload.js");
|
|
7
|
+
return s(e, t);
|
|
14
8
|
}
|
|
15
|
-
const s = t, {
|
|
16
|
-
docs: [n]
|
|
17
|
-
} = await s.find({
|
|
18
|
-
collection: h(s.config).collectionSlug,
|
|
19
|
-
where: { locale: { equals: e } }
|
|
20
|
-
});
|
|
21
|
-
if (!n)
|
|
22
|
-
return console.warn(`No messages found for locale ${e}`), {};
|
|
23
|
-
const { url: a } = n;
|
|
24
|
-
console.debug(`PAYLOAD_INTL: Fetching messages from stroage: ${a}`);
|
|
25
|
-
const o = await fetch(a);
|
|
26
|
-
if (!o.ok) {
|
|
27
|
-
const r = await w(o);
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Could not fetch messages for locale "${e}": ${r}`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
if (o.headers.get("content-type") !== "application/json")
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Could not fetch messages for locale "${e}": The page did not return a JSON file.`
|
|
35
|
-
);
|
|
36
|
-
return await o.json();
|
|
37
9
|
}
|
|
38
10
|
export {
|
|
39
|
-
|
|
11
|
+
r as fetchMessages
|
|
40
12
|
};
|
|
41
13
|
//# sourceMappingURL=fetchMessages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchMessages.js","sources":["../../src/requests/fetchMessages.ts"],"sourcesContent":["import type { BasePayload } from 'payload';\nimport
|
|
1
|
+
{"version":3,"file":"fetchMessages.js","sources":["../../src/requests/fetchMessages.ts"],"sourcesContent":["import type { BasePayload } from 'payload';\nimport type { Messages } from '../types';\nimport type { MessagesRequestConfig } from './fetchMessageFromAPI';\n\nexport async function fetchMessages(\n config: MessagesRequestConfig,\n locale: string,\n): Promise<Messages>;\nexport async function fetchMessages(\n payload: BasePayload,\n locale: string,\n): Promise<Messages>;\nexport async function fetchMessages(\n configOrPayload: MessagesRequestConfig | BasePayload,\n locale: string,\n): Promise<Messages> {\n if ('serverUrl' in configOrPayload) {\n const { fetchMessagesFromAPI } = await import('./fetchMessageFromAPI');\n return fetchMessagesFromAPI(configOrPayload, locale);\n } else {\n const { fetchMessagesFromPayload } = await import(\n './fetchMessageFromPayload'\n );\n return fetchMessagesFromPayload(configOrPayload, locale);\n }\n}\n"],"names":["fetchMessages","configOrPayload","locale","fetchMessagesFromAPI","fetchMessagesFromPayload"],"mappings":"AAYA,eAAsBA,EACpBC,GACAC,GACmB;AACnB,MAAI,eAAeD,GAAiB;AAClC,UAAM,EAAE,sBAAAE,EAAA,IAAyB,MAAM,OAAO,0BAAuB;AACrE,WAAOA,EAAqBF,GAAiBC,CAAM;AAAA,EACrD,OAAO;AACL,UAAM,EAAE,0BAAAE,EAAA,IAA6B,MAAM,OACzC,8BACF;AACA,WAAOA,EAAyBH,GAAiBC,CAAM;AAAA,EACzD;AACF;"}
|