@farm.js/core 0.1.0-beta.1 → 0.1.0-beta.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/README.md +1 -1
- package/dist/agent-runtime.d.mts +1 -1
- package/dist/agent-runtime.d.ts +1 -1
- package/dist/api/route-manager.cjs +97 -5
- package/dist/api/route-manager.cjs.map +1 -1
- package/dist/api/route-manager.d.mts +3 -2
- package/dist/api/route-manager.d.ts +3 -2
- package/dist/api/route-manager.mjs +8 -8
- package/dist/api/runtime.cjs +441 -5
- package/dist/api/runtime.cjs.map +1 -1
- package/dist/api/runtime.d.mts +2 -16
- package/dist/api/runtime.d.ts +2 -16
- package/dist/api/runtime.mjs +7 -1
- package/dist/api.cjs +579 -263
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.mts +4 -147
- package/dist/api.d.ts +4 -147
- package/dist/api.mjs +30 -20
- package/dist/{app-BiX4qb-d.d.mts → app-BB3Iu3xh.d.mts} +2 -2
- package/dist/{app-CFRNJXP1.d.ts → app-DOKxo-LH.d.ts} +2 -2
- package/dist/app-markdown.cjs +1 -1
- package/dist/app-markdown.cjs.map +1 -1
- package/dist/app-markdown.d.mts +1 -1
- package/dist/app-markdown.d.ts +1 -1
- package/dist/app-markdown.mjs +1 -1
- package/dist/cache.cjs +19 -0
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.mts +21 -1
- package/dist/cache.d.ts +21 -1
- package/dist/cache.mjs +5 -3
- package/dist/{chunk-QF4PHCMA.mjs → chunk-2ED5Q2GH.mjs} +3 -3
- package/dist/chunk-2ED5Q2GH.mjs.map +1 -0
- package/dist/{chunk-GZP5W4K3.mjs → chunk-32W4QEJP.mjs} +1 -1
- package/dist/chunk-32W4QEJP.mjs.map +1 -0
- package/dist/{chunk-AGS7UJ52.mjs → chunk-45LKHSHJ.mjs} +2 -2
- package/dist/{chunk-TU4YJICB.mjs → chunk-5FW6PQ3J.mjs} +1 -1
- package/dist/{chunk-TU4YJICB.mjs.map → chunk-5FW6PQ3J.mjs.map} +1 -1
- package/dist/{chunk-TRORP7E4.mjs → chunk-5QH4IKY3.mjs} +2 -2
- package/dist/{chunk-RKI6TN3A.mjs → chunk-6VS6CKAV.mjs} +2 -2
- package/dist/chunk-6VS6CKAV.mjs.map +1 -0
- package/dist/{chunk-25D7G34K.mjs → chunk-6WXJ54TC.mjs} +4 -4
- package/dist/{chunk-3QJO55ZF.mjs → chunk-BIOIOWXZ.mjs} +5 -3
- package/dist/{chunk-3QJO55ZF.mjs.map → chunk-BIOIOWXZ.mjs.map} +1 -1
- package/dist/{chunk-QFQRHRZS.mjs → chunk-C33RALN7.mjs} +75 -11
- package/dist/chunk-C33RALN7.mjs.map +1 -0
- package/dist/{chunk-B6N4ZB2H.mjs → chunk-CSU4KJJF.mjs} +3 -3
- package/dist/{chunk-JN3UU635.mjs → chunk-EJ7T4TPB.mjs} +2 -2
- package/dist/chunk-EJ7T4TPB.mjs.map +1 -0
- package/dist/{chunk-ZJQNATYV.mjs → chunk-FRPWCMMG.mjs} +3 -3
- package/dist/chunk-FRPWCMMG.mjs.map +1 -0
- package/dist/{chunk-PRNYWD7K.mjs → chunk-G5I34UA6.mjs} +67 -239
- package/dist/chunk-G5I34UA6.mjs.map +1 -0
- package/dist/{chunk-QM6VV26B.mjs → chunk-GQVGIUSN.mjs} +3 -3
- package/dist/{chunk-QM6VV26B.mjs.map → chunk-GQVGIUSN.mjs.map} +1 -1
- package/dist/{chunk-UREJA4GZ.mjs → chunk-GXASWWJU.mjs} +1 -1
- package/dist/{chunk-UREJA4GZ.mjs.map → chunk-GXASWWJU.mjs.map} +1 -1
- package/dist/{chunk-4PTK6KT4.mjs → chunk-GZWT6VI5.mjs} +22 -4
- package/dist/chunk-GZWT6VI5.mjs.map +1 -0
- package/dist/{chunk-JLWMCADZ.mjs → chunk-HZYXGV4K.mjs} +2 -2
- package/dist/chunk-JNYVN7YP.mjs +10 -0
- package/dist/chunk-JNYVN7YP.mjs.map +1 -0
- package/dist/{chunk-YHU7SS6L.mjs → chunk-LG3YINQN.mjs} +11 -11
- package/dist/chunk-LWMGIEJA.mjs +593 -0
- package/dist/chunk-LWMGIEJA.mjs.map +1 -0
- package/dist/{chunk-HXP3ZSPC.mjs → chunk-MH6FKW2I.mjs} +3 -3
- package/dist/{chunk-O3HADRW6.mjs → chunk-MIUW47JX.mjs} +2 -2
- package/dist/{chunk-O3HADRW6.mjs.map → chunk-MIUW47JX.mjs.map} +1 -1
- package/dist/{chunk-6XDUHOEM.mjs → chunk-NRRFGX45.mjs} +3 -3
- package/dist/{chunk-G3B5BRDY.mjs → chunk-OHC6VCDI.mjs} +24 -25
- package/dist/{chunk-G3B5BRDY.mjs.map → chunk-OHC6VCDI.mjs.map} +1 -1
- package/dist/{chunk-S2XHZS7W.mjs → chunk-QGQX7SFC.mjs} +2 -2
- package/dist/chunk-QGQX7SFC.mjs.map +1 -0
- package/dist/{chunk-TXCFGOHW.mjs → chunk-SHRJG6OG.mjs} +25 -1
- package/dist/chunk-SHRJG6OG.mjs.map +1 -0
- package/dist/{chunk-UHE2TTLK.mjs → chunk-T543TMFY.mjs} +8 -8
- package/dist/chunk-T543TMFY.mjs.map +1 -0
- package/dist/{chunk-SXZTEK3V.mjs → chunk-UXUAWNO5.mjs} +2 -2
- package/dist/{chunk-Y2OJJD7R.mjs → chunk-XIVV5IWN.mjs} +7 -9
- package/dist/chunk-XIVV5IWN.mjs.map +1 -0
- package/dist/{chunk-CHFHNEMO.mjs → chunk-XJSHJN4M.mjs} +41 -42
- package/dist/chunk-XJSHJN4M.mjs.map +1 -0
- package/dist/{chunk-Y7A27276.mjs → chunk-XUBZ7JI4.mjs} +178 -15
- package/dist/chunk-XUBZ7JI4.mjs.map +1 -0
- package/dist/{chunk-OYXO65LI.mjs → chunk-YW7OBE6Q.mjs} +4 -4
- package/dist/chunk-YW7OBE6Q.mjs.map +1 -0
- package/dist/{chunk-SOU3Q3ZA.mjs → chunk-ZZ57EH5Z.mjs} +1 -1
- package/dist/chunk-ZZ57EH5Z.mjs.map +1 -0
- package/dist/{client-D_yUjVhe.d.mts → client-DiViK9yK.d.mts} +33 -7
- package/dist/{client-Dkc03WP8.d.ts → client-DpEBJbts.d.ts} +33 -7
- package/dist/{client-plugins-BZnpeTGA.d.ts → client-plugins-CTnsZz_A.d.ts} +1 -0
- package/dist/{client-plugins-g4bzuCmo.d.mts → client-plugins-Cnr0D3kk.d.mts} +1 -0
- package/dist/client-plugins.d.mts +1 -1
- package/dist/client-plugins.d.ts +1 -1
- package/dist/client.cjs +302 -54
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.mts +54 -2
- package/dist/client.d.ts +54 -2
- package/dist/client.mjs +20 -16
- package/dist/config.d.mts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.mjs +1 -1
- package/dist/{devtools-AE4RVXCM.mjs → devtools-HE4FTUDN.mjs} +10 -10
- package/dist/{devtools-client-6WPY2AQU.mjs → devtools-client-3XRTBND5.mjs} +2 -11
- package/dist/devtools-client-3XRTBND5.mjs.map +1 -0
- package/dist/docs.cjs +3 -1
- package/dist/docs.cjs.map +1 -1
- package/dist/docs.mjs +10 -10
- package/dist/i18n/server.cjs +2 -2
- package/dist/i18n/server.cjs.map +1 -1
- package/dist/i18n/server.mjs +1 -1
- package/dist/index.cjs +791 -317
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.mjs +125 -110
- package/dist/index.mjs.map +1 -1
- package/dist/integrations.d.mts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/internal/build-runtime.cjs +162 -60
- package/dist/internal/build-runtime.cjs.map +1 -1
- package/dist/internal/build-runtime.d.mts +3 -3
- package/dist/internal/build-runtime.d.ts +3 -3
- package/dist/internal/build-runtime.mjs +26 -25
- package/dist/internal/client-runtime.cjs.map +1 -1
- package/dist/internal/client-runtime.mjs +1 -1
- package/dist/internal/config-runtime.cjs +1 -1
- package/dist/internal/config-runtime.cjs.map +1 -1
- package/dist/internal/config-runtime.d.mts +2 -2
- package/dist/internal/config-runtime.d.ts +2 -2
- package/dist/internal/config-runtime.mjs +9 -9
- package/dist/internal/production-runtime.cjs +3 -3
- package/dist/internal/production-runtime.cjs.map +1 -1
- package/dist/internal/production-runtime.d.mts +3 -3
- package/dist/internal/production-runtime.d.ts +3 -3
- package/dist/internal/production-runtime.mjs +8 -8
- package/dist/{metadata-C9NZxMDW.d.mts → metadata-Dp8AdvsB.d.mts} +1 -1
- package/dist/{metadata-DAXRaOHx.d.ts → metadata-eoVmHoyv.d.ts} +1 -1
- package/dist/middleware.cjs +2 -2
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.mts +3 -3
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.mjs +3 -3
- package/dist/navigation.cjs.map +1 -1
- package/dist/navigation.mjs +3 -3
- package/dist/{nitro-KME62MWG.mjs → nitro-QO5LV6QK.mjs} +11 -13
- package/dist/{nitro-KME62MWG.mjs.map → nitro-QO5LV6QK.mjs.map} +1 -1
- package/dist/plugin.cjs +119 -39
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.mjs +22 -21
- package/dist/{production-runtime-DRkCHUvJ.d.ts → production-runtime-BqTnUTai.d.ts} +1 -1
- package/dist/{production-runtime-flrjp_nC.d.mts → production-runtime-DtDdG9fc.d.mts} +1 -1
- package/dist/routes.cjs.map +1 -1
- package/dist/routes.d.mts +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/routes.mjs +4 -4
- package/dist/runtime-C1B7pSGT.d.mts +207 -0
- package/dist/runtime-CdPHt0bv.d.ts +207 -0
- package/dist/server-action-security.cjs.map +1 -1
- package/dist/server-action-security.mjs +2 -2
- package/dist/server-fn-client.cjs.map +1 -1
- package/dist/server-fn-client.mjs +1 -1
- package/dist/server-fn.cjs.map +1 -1
- package/dist/server-fn.mjs +3 -3
- package/dist/server-plugins.d.mts +2 -2
- package/dist/server-plugins.d.ts +2 -2
- package/dist/server-query-client.cjs.map +1 -1
- package/dist/server-query-client.mjs +4 -4
- package/dist/server-query.cjs.map +1 -1
- package/dist/server-query.mjs +5 -5
- package/dist/server.cjs +148 -43
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.mts +6 -6
- package/dist/server.d.ts +6 -6
- package/dist/server.mjs +36 -31
- package/dist/server.mjs.map +1 -1
- package/dist/testing.cjs +95 -5
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.mts +3 -3
- package/dist/testing.d.ts +3 -3
- package/dist/testing.mjs +18 -18
- package/dist/{utils-DOXXivjL.d.mts → utils-8USa5BiY.d.mts} +1 -1
- package/dist/{utils-DA1yo54_.d.ts → utils-DKJb6K6G.d.ts} +1 -1
- package/dist/version.cjs +36 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.mts +3 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.mjs +8 -0
- package/dist/version.mjs.map +1 -0
- package/dist/vite.cjs +126 -40
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.mjs +22 -21
- package/dist/workflows.cjs +6 -8
- package/dist/workflows.cjs.map +1 -1
- package/dist/workflows.mjs +1 -1
- package/package.json +12 -5
- package/types/client.d.ts +136 -13
- package/dist/chunk-4PTK6KT4.mjs.map +0 -1
- package/dist/chunk-CHFHNEMO.mjs.map +0 -1
- package/dist/chunk-EVGBEZDF.mjs +0 -215
- package/dist/chunk-EVGBEZDF.mjs.map +0 -1
- package/dist/chunk-GZP5W4K3.mjs.map +0 -1
- package/dist/chunk-JN3UU635.mjs.map +0 -1
- package/dist/chunk-OYXO65LI.mjs.map +0 -1
- package/dist/chunk-PRNYWD7K.mjs.map +0 -1
- package/dist/chunk-QF4PHCMA.mjs.map +0 -1
- package/dist/chunk-QFQRHRZS.mjs.map +0 -1
- package/dist/chunk-RKI6TN3A.mjs.map +0 -1
- package/dist/chunk-S2XHZS7W.mjs.map +0 -1
- package/dist/chunk-SOU3Q3ZA.mjs.map +0 -1
- package/dist/chunk-TXCFGOHW.mjs.map +0 -1
- package/dist/chunk-UHE2TTLK.mjs.map +0 -1
- package/dist/chunk-Y2OJJD7R.mjs.map +0 -1
- package/dist/chunk-Y7A27276.mjs.map +0 -1
- package/dist/chunk-ZJQNATYV.mjs.map +0 -1
- package/dist/devtools-client-6WPY2AQU.mjs.map +0 -1
- /package/dist/{chunk-AGS7UJ52.mjs.map → chunk-45LKHSHJ.mjs.map} +0 -0
- /package/dist/{chunk-TRORP7E4.mjs.map → chunk-5QH4IKY3.mjs.map} +0 -0
- /package/dist/{chunk-25D7G34K.mjs.map → chunk-6WXJ54TC.mjs.map} +0 -0
- /package/dist/{chunk-B6N4ZB2H.mjs.map → chunk-CSU4KJJF.mjs.map} +0 -0
- /package/dist/{chunk-JLWMCADZ.mjs.map → chunk-HZYXGV4K.mjs.map} +0 -0
- /package/dist/{chunk-YHU7SS6L.mjs.map → chunk-LG3YINQN.mjs.map} +0 -0
- /package/dist/{chunk-HXP3ZSPC.mjs.map → chunk-MH6FKW2I.mjs.map} +0 -0
- /package/dist/{chunk-6XDUHOEM.mjs.map → chunk-NRRFGX45.mjs.map} +0 -0
- /package/dist/{chunk-SXZTEK3V.mjs.map → chunk-UXUAWNO5.mjs.map} +0 -0
- /package/dist/{devtools-AE4RVXCM.mjs.map → devtools-HE4FTUDN.mjs.map} +0 -0
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getFarmClientDataCache,
|
|
3
3
|
normalizeFarmClientCacheKey
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NRRFGX45.mjs";
|
|
5
|
+
import {
|
|
6
|
+
FARM_CACHE_INVALIDATION_HEADER,
|
|
7
|
+
applyFarmCacheInvalidations,
|
|
8
|
+
decodeFarmCacheInvalidations
|
|
9
|
+
} from "./chunk-SHRJG6OG.mjs";
|
|
5
10
|
import {
|
|
6
11
|
__name
|
|
7
12
|
} from "./chunk-CGILA3WO.mjs";
|
|
@@ -115,7 +120,7 @@ function mergeIntegrationClientData(...values) {
|
|
|
115
120
|
continue;
|
|
116
121
|
}
|
|
117
122
|
merged = {
|
|
118
|
-
...merged
|
|
123
|
+
...merged,
|
|
119
124
|
...data
|
|
120
125
|
};
|
|
121
126
|
}
|
|
@@ -801,6 +806,19 @@ function createServerNamespaceProxy(integrationKey, source, api, options) {
|
|
|
801
806
|
__name(createServerNamespaceProxy, "createServerNamespaceProxy");
|
|
802
807
|
|
|
803
808
|
// src/api/client.ts
|
|
809
|
+
var FARM_API_ROUTE_REF_SYMBOL = /* @__PURE__ */ Symbol.for("farm.api.route-ref");
|
|
810
|
+
var _APIClientError = class _APIClientError extends Error {
|
|
811
|
+
constructor(code, data, options) {
|
|
812
|
+
super(options.message);
|
|
813
|
+
this.name = "APIClientError";
|
|
814
|
+
this.code = code;
|
|
815
|
+
this.data = data;
|
|
816
|
+
this.status = options.status;
|
|
817
|
+
this.response = options.response;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
__name(_APIClientError, "APIClientError");
|
|
821
|
+
var APIClientError = _APIClientError;
|
|
804
822
|
function createAPIClient(options = {}) {
|
|
805
823
|
options ?? (options = {});
|
|
806
824
|
const baseURL = options.baseURL || (typeof window !== "undefined" ? window.location.origin : "http://localhost:3000");
|
|
@@ -838,6 +856,9 @@ function createAPIClient(options = {}) {
|
|
|
838
856
|
fetchOptions.body = JSON.stringify(requestOptions.body);
|
|
839
857
|
}
|
|
840
858
|
const response = await fetch(url.toString(), fetchOptions);
|
|
859
|
+
applyFarmCacheInvalidations(
|
|
860
|
+
decodeFarmCacheInvalidations(response.headers?.get?.(FARM_CACHE_INVALIDATION_HEADER))
|
|
861
|
+
);
|
|
841
862
|
let data = void 0;
|
|
842
863
|
if (response.status !== 204 && response.status !== 205) {
|
|
843
864
|
data = await response.json();
|
|
@@ -1077,9 +1098,15 @@ function createNestedProxy(path, client, routeMeta, baseURL, rootAliases) {
|
|
|
1077
1098
|
const proxy = new Proxy(target, {
|
|
1078
1099
|
// When accessing a property (api.hello)
|
|
1079
1100
|
get(_target, prop) {
|
|
1101
|
+
if (prop === FARM_API_ROUTE_REF_SYMBOL) {
|
|
1102
|
+
return path.length > 0;
|
|
1103
|
+
}
|
|
1080
1104
|
if (path.length === 0 && typeof prop === "string" && rootAliases && prop in rootAliases) {
|
|
1081
1105
|
return rootAliases[prop];
|
|
1082
1106
|
}
|
|
1107
|
+
if (typeof prop !== "string") {
|
|
1108
|
+
return Reflect.get(_target, prop);
|
|
1109
|
+
}
|
|
1083
1110
|
return createNestedProxy([...path, prop], client, routeMeta, baseURL, rootAliases);
|
|
1084
1111
|
},
|
|
1085
1112
|
// When calling as a function
|
|
@@ -1102,6 +1129,10 @@ function createNestedProxy(path, client, routeMeta, baseURL, rootAliases) {
|
|
|
1102
1129
|
return proxy;
|
|
1103
1130
|
}
|
|
1104
1131
|
__name(createNestedProxy, "createNestedProxy");
|
|
1132
|
+
function isAPIRouteRef(value) {
|
|
1133
|
+
return typeof value === "function" && value[FARM_API_ROUTE_REF_SYMBOL] === true;
|
|
1134
|
+
}
|
|
1135
|
+
__name(isAPIRouteRef, "isAPIRouteRef");
|
|
1105
1136
|
function createServerAPIClient(endpoints, options = {}) {
|
|
1106
1137
|
if (options.integrations === false || Object.prototype.hasOwnProperty.call(endpoints, "integrations")) {
|
|
1107
1138
|
return endpoints;
|
|
@@ -1168,7 +1199,10 @@ function resolveTargetKey(routeMeta, target, input, baseURL = "http://localhost:
|
|
|
1168
1199
|
}
|
|
1169
1200
|
if (Array.isArray(target)) {
|
|
1170
1201
|
const [route, routeInput] = target;
|
|
1171
|
-
|
|
1202
|
+
if (typeof route === "function") {
|
|
1203
|
+
return resolveTargetKey(routeMeta, route, routeInput, baseURL);
|
|
1204
|
+
}
|
|
1205
|
+
return normalizeFarmClientCacheKey(target);
|
|
1172
1206
|
}
|
|
1173
1207
|
if ("key" in target) return normalizeFarmClientCacheKey(target.key);
|
|
1174
1208
|
if ("path" in target) {
|
|
@@ -1194,18 +1228,45 @@ function resolveRouteMeta(meta) {
|
|
|
1194
1228
|
}
|
|
1195
1229
|
__name(resolveRouteMeta, "resolveRouteMeta");
|
|
1196
1230
|
function normalizeError(error) {
|
|
1197
|
-
if (error instanceof
|
|
1198
|
-
|
|
1231
|
+
if (error instanceof APIClientError) return error;
|
|
1232
|
+
const normalized = new APIClientError("network_error", void 0, {
|
|
1233
|
+
status: 0,
|
|
1234
|
+
message: error instanceof Error ? error.message : typeof error === "string" ? error : "Network request failed"
|
|
1235
|
+
});
|
|
1236
|
+
normalized.cause = error;
|
|
1237
|
+
return normalized;
|
|
1199
1238
|
}
|
|
1200
1239
|
__name(normalizeError, "normalizeError");
|
|
1201
1240
|
function createResponseError2(response, data) {
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1241
|
+
const expected = readEndpointErrorEnvelope(data);
|
|
1242
|
+
if (expected) {
|
|
1243
|
+
return new APIClientError(expected.code, expected.data, {
|
|
1244
|
+
status: response.status,
|
|
1245
|
+
message: expected.message,
|
|
1246
|
+
response
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
return new APIClientError("http_error", data, {
|
|
1250
|
+
status: response.status,
|
|
1251
|
+
message: `HTTP ${response.status}: ${response.statusText}`,
|
|
1252
|
+
response
|
|
1253
|
+
});
|
|
1207
1254
|
}
|
|
1208
1255
|
__name(createResponseError2, "createResponseError");
|
|
1256
|
+
function readEndpointErrorEnvelope(data) {
|
|
1257
|
+
if (!data || typeof data !== "object") return null;
|
|
1258
|
+
const error = data.error;
|
|
1259
|
+
if (!error || typeof error !== "object") return null;
|
|
1260
|
+
const code = error.code;
|
|
1261
|
+
const message = error.message;
|
|
1262
|
+
if (typeof code !== "string" || typeof message !== "string") return null;
|
|
1263
|
+
return {
|
|
1264
|
+
code,
|
|
1265
|
+
message,
|
|
1266
|
+
data: error.data
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
__name(readEndpointErrorEnvelope, "readEndpointErrorEnvelope");
|
|
1209
1270
|
|
|
1210
1271
|
export {
|
|
1211
1272
|
IntegrationClientError,
|
|
@@ -1218,7 +1279,10 @@ export {
|
|
|
1218
1279
|
createIntegrations,
|
|
1219
1280
|
getIntegrationAPIManifest,
|
|
1220
1281
|
integrationClients,
|
|
1282
|
+
FARM_API_ROUTE_REF_SYMBOL,
|
|
1283
|
+
APIClientError,
|
|
1221
1284
|
createAPIClient,
|
|
1285
|
+
isAPIRouteRef,
|
|
1222
1286
|
createServerAPIClient
|
|
1223
1287
|
};
|
|
1224
|
-
//# sourceMappingURL=chunk-
|
|
1288
|
+
//# sourceMappingURL=chunk-C33RALN7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/integration-client.ts","../src/api/client.ts"],"sourcesContent":["import type {\n FarmIntegrationAPI,\n FarmIntegrationAPIBodyFormat,\n FarmIntegrationAPIOperation,\n} from \"./integration-api\";\nimport type { FarmIntegration as FarmIntegrationDefinition } from \"./integrations\";\n\n/**\n * Small per-call integration metadata. When sent from a browser, values are\n * client-controlled and should be validated before authorization decisions.\n */\nexport type IntegrationClientData = Record<string, unknown>;\n\nexport type IntegrationClientOptions = {\n baseURL?: string;\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n data?: IntegrationClientData;\n isServer?: false | undefined;\n};\n\ntype IntegrationRequestOptionsBase = {\n headers?: Record<string, string>;\n signal?: AbortSignal;\n credentials?: RequestCredentials;\n data?: IntegrationClientData;\n};\n\nexport type IntegrationClientRequestOptions = IntegrationRequestOptionsBase;\n\nexport type IntegrationServerRequestLike =\n | Request\n | {\n url?: string;\n headers?: HeadersInit;\n };\n\nexport type IntegrationServerClientOptions = Omit<IntegrationClientOptions, \"isServer\"> & {\n isServer: true;\n request?: IntegrationServerRequestLike;\n forwardHeaders?: boolean | readonly string[];\n};\n\nexport type IntegrationServerClientRequestOptions = IntegrationRequestOptionsBase & {\n baseURL?: string;\n request?: IntegrationServerRequestLike;\n forwardHeaders?: boolean | readonly string[];\n};\n\nexport class IntegrationClientError<TData = unknown> extends Error {\n readonly status: number;\n readonly response: Response;\n readonly data: TData | undefined;\n\n constructor(message: string, response: Response, data?: TData) {\n super(message);\n this.name = \"IntegrationClientError\";\n this.status = response.status;\n this.response = response;\n this.data = data;\n }\n}\n\nexport type IntegrationOperationResult<\n TData = unknown,\n TError = IntegrationClientError<unknown> | Error,\n> = {\n data: TData | null;\n error: TError | null;\n};\n\ntype ExtractOperationBody<T> = T extends {\n __types?: { body: infer TBody };\n}\n ? TBody\n : never;\n\ntype ExtractOperationQuery<T> = T extends {\n __types?: { query: infer TQuery };\n}\n ? TQuery\n : never;\n\ntype ExtractOperationResponse<T> = T extends {\n __types?: { response: infer TResponse };\n}\n ? TResponse\n : unknown;\n\nexport type InferIntegrationOperationBody<T> = ExtractOperationBody<T>;\nexport type InferIntegrationOperationQuery<T> = ExtractOperationQuery<T>;\nexport type InferIntegrationOperationResponse<T> = ExtractOperationResponse<T>;\n\ntype IsNever<T> = [T] extends [never] ? true : false;\n\ntype OperationInput<T> =\n IsNever<ExtractOperationBody<T>> extends true\n ? IsNever<ExtractOperationQuery<T>> extends true\n ? {}\n : { query?: ExtractOperationQuery<T> }\n : IsNever<ExtractOperationQuery<T>> extends true\n ? { body: ExtractOperationBody<T> }\n : { body: ExtractOperationBody<T>; query?: ExtractOperationQuery<T> };\n\ntype ClientOperation<T> = (\n options?: OperationInput<T>,\n requestOptions?: IntegrationClientRequestOptions,\n) => Promise<IntegrationOperationResult<ExtractOperationResponse<T>>>;\n\ntype ServerOperation<T> = (\n options?: OperationInput<T>,\n requestOptions?: IntegrationServerClientRequestOptions,\n) => Promise<IntegrationOperationResult<ExtractOperationResponse<T>>>;\n\ntype IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : never;\n\ntype SingleKey<T> = [T] extends [never] ? never : IsUnion<T> extends true ? never : T;\n\ntype ExtractAPIFromSource<TSource> = TSource extends { api?: infer TAPI }\n ? NonNullable<TAPI> extends FarmIntegrationAPI\n ? NonNullable<TAPI>\n : never\n : TSource extends FarmIntegrationAPI\n ? TSource\n : never;\n\ntype SourceKeysWithAPI<TSources extends Record<string, any>> = {\n [K in keyof TSources]: [ExtractAPIFromSource<TSources[K]>] extends [never] ? never : K;\n}[keyof TSources];\n\ntype IsServerRegisteredOperation<T> = T extends { isServer: true } ? true : false;\n\ntype ClientOperationKeys<TAPI> = {\n [K in keyof TAPI]: TAPI[K] extends FarmIntegrationAPIOperation<any, any, any, any>\n ? IsServerRegisteredOperation<TAPI[K]> extends true\n ? never\n : K\n : never;\n}[keyof TAPI];\n\ntype ClientNamespaceShape<TAPI> = {\n [K in keyof TAPI as TAPI[K] extends FarmIntegrationAPIOperation<any, any, any, any>\n ? IsServerRegisteredOperation<TAPI[K]> extends true\n ? never\n : K\n : K]: TAPI[K] extends FarmIntegrationAPIOperation<any, any, any, any>\n ? ClientOperation<TAPI[K]>\n : TAPI[K] extends Record<string, any>\n ? IntegrationAPIToClient<TAPI[K]>\n : never;\n};\n\ntype SingleClientOperationKey<TAPI> =\n Exclude<keyof TAPI, ClientOperationKeys<TAPI>> extends never\n ? SingleKey<ClientOperationKeys<TAPI>>\n : never;\n\ntype IntegrationAPIToClient<TAPI> =\n TAPI extends FarmIntegrationAPIOperation<any, any, any, any>\n ? ClientOperation<TAPI>\n : TAPI extends Record<string, any>\n ? [SingleClientOperationKey<TAPI>] extends [never]\n ? ClientNamespaceShape<TAPI>\n : SingleClientOperationKey<TAPI> extends keyof TAPI\n ? ClientOperation<TAPI[SingleClientOperationKey<TAPI>]> & ClientNamespaceShape<TAPI>\n : ClientNamespaceShape<TAPI>\n : never;\n\nexport type IntegrationClient<TSources extends Record<string, any>> = {\n [K in SourceKeysWithAPI<TSources>]: IntegrationAPIToClient<ExtractAPIFromSource<TSources[K]>>;\n};\n\nexport type IntegrationClientRoot<TSources extends Record<string, any>> = {\n integrations: IntegrationClient<TSources>;\n};\n\ntype ServerOperationKeys<TAPI> = {\n [K in keyof TAPI]: TAPI[K] extends FarmIntegrationAPIOperation<any, any, any> ? K : never;\n}[keyof TAPI];\n\ntype ServerNamespaceShape<TAPI> = {\n [K in keyof TAPI]: TAPI[K] extends FarmIntegrationAPIOperation<any, any, any>\n ? ServerOperation<TAPI[K]>\n : TAPI[K] extends Record<string, any>\n ? IntegrationAPIToServerClient<TAPI[K]>\n : never;\n};\n\ntype SingleServerOperationKey<TAPI> =\n Exclude<keyof TAPI, ServerOperationKeys<TAPI>> extends never\n ? SingleKey<ServerOperationKeys<TAPI>>\n : never;\n\ntype IntegrationAPIToServerClient<TAPI> =\n TAPI extends FarmIntegrationAPIOperation<any, any, any>\n ? ServerOperation<TAPI>\n : TAPI extends Record<string, any>\n ? [SingleServerOperationKey<TAPI>] extends [never]\n ? ServerNamespaceShape<TAPI>\n : SingleServerOperationKey<TAPI> extends keyof TAPI\n ? ServerOperation<TAPI[SingleServerOperationKey<TAPI>]> & ServerNamespaceShape<TAPI>\n : ServerNamespaceShape<TAPI>\n : never;\n\nexport type IntegrationServerClient<TSources extends Record<string, any>> = {\n [K in SourceKeysWithAPI<TSources>]: IntegrationAPIToServerClient<\n ExtractAPIFromSource<TSources[K]>\n >;\n};\n\nexport type IntegrationServerClientRoot<TSources extends Record<string, any>> = {\n integrations: IntegrationServerClient<TSources>;\n};\n\nexport type IntegrationClientAliases<TSources extends Record<string, any>> =\n IntegrationClient<TSources> & {\n integrations: IntegrationClient<TSources>;\n };\n\nexport type IntegrationServerClientAliases<TSources extends Record<string, any>> =\n IntegrationServerClient<TSources> & {\n integrations: IntegrationServerClient<TSources>;\n };\n\nexport type IntegrationAPI<TSources extends Record<string, any>> =\n IntegrationClientAliases<TSources> & {\n server: (\n options: Omit<IntegrationServerClientOptions, \"isServer\">,\n ) => IntegrationServerClientAliases<TSources>;\n };\n\nexport type IntegrationClients<TSources extends Record<string, any>> = {\n api: IntegrationServerClientAliases<TSources>;\n apiClient: IntegrationClientAliases<TSources>;\n};\n\ntype ResolvedIntegrationNamespace = readonly [\n string,\n FarmIntegrationAPI,\n FarmIntegrationDefinition | FarmIntegrationAPI,\n];\n\ntype RegisteredIntegrationRuntime = {\n integration: FarmIntegrationDefinition;\n config: unknown;\n isDev: boolean;\n isProd: boolean;\n};\n\nconst INTEGRATION_RUNTIME_REGISTRY_KEY = Symbol.for(\"farm.integrationRuntimeRegistry\");\nconst CURRENT_REQUEST_RESOLVER_KEY = Symbol.for(\"farm.currentRequestResolver\");\nconst INTEGRATION_REQUEST_DISPATCHER_KEY = Symbol.for(\"farm.integrationRequestDispatcher\");\n\ntype IntegrationRequestDispatcher = (\n runtime: RegisteredIntegrationRuntime,\n request: Request,\n options?: { currentRequest?: Request; data?: IntegrationClientData; internal?: boolean },\n) => Promise<Response | null>;\n\ntype GlobalWithIntegrationRuntimeRegistry = typeof globalThis & {\n [INTEGRATION_RUNTIME_REGISTRY_KEY]?: Map<string, RegisteredIntegrationRuntime>;\n [CURRENT_REQUEST_RESOLVER_KEY]?: () => Request | undefined;\n [INTEGRATION_REQUEST_DISPATCHER_KEY]?: IntegrationRequestDispatcher;\n};\n\ntype GlobalWithIntegrationAPIManifest = typeof globalThis & {\n __FARM_INTEGRATION_API_MANIFEST__?: Record<string, FarmIntegrationAPI>;\n window?: {\n __FARM_INTEGRATION_API_MANIFEST__?: Record<string, FarmIntegrationAPI>;\n };\n};\n\nfunction isOperation(value: unknown): value is FarmIntegrationAPIOperation<any, any, any, any> {\n return (\n !!value &&\n typeof value === \"object\" &&\n (value as FarmIntegrationAPIOperation<any, any, any, any>).kind ===\n \"farm-integration-api-operation\"\n );\n}\n\nfunction resolveSourceAPI(\n source: FarmIntegrationDefinition | FarmIntegrationAPI,\n): FarmIntegrationAPI {\n if (\"kind\" in source && source.kind === \"farm-integration\") {\n if (!source.api) {\n throw new Error(`Integration \"${source.type}\" does not expose a client API definition.`);\n }\n\n return source.api as FarmIntegrationAPI;\n }\n\n return source as FarmIntegrationAPI;\n}\n\nfunction tryResolveSourceAPI(\n source: FarmIntegrationDefinition | FarmIntegrationAPI,\n): FarmIntegrationAPI | null {\n if (\"kind\" in source && source.kind === \"farm-integration\") {\n if (!source.api) {\n return null;\n }\n\n return source.api as FarmIntegrationAPI;\n }\n\n return source as FarmIntegrationAPI;\n}\n\nfunction getIntegrationRuntimeRegistry() {\n const globalState = globalThis as GlobalWithIntegrationRuntimeRegistry;\n return (\n globalState[INTEGRATION_RUNTIME_REGISTRY_KEY] || new Map<string, RegisteredIntegrationRuntime>()\n );\n}\n\nfunction getRegisteredIntegrationRuntimeLocal(\n key: string,\n): RegisteredIntegrationRuntime | undefined {\n return getIntegrationRuntimeRegistry().get(key);\n}\n\nfunction getRegisteredIntegrationsLocal(): Record<string, FarmIntegrationDefinition> {\n return Object.fromEntries(\n Array.from(getIntegrationRuntimeRegistry().entries()).map(([key, runtime]) => [\n key,\n runtime.integration,\n ]),\n );\n}\n\nfunction resolveCurrentRequestLocal(): Request | undefined {\n const globalState = globalThis as GlobalWithIntegrationRuntimeRegistry;\n return globalState[CURRENT_REQUEST_RESOLVER_KEY]?.();\n}\n\nfunction resolveIntegrationRequestDispatcherLocal(): IntegrationRequestDispatcher | undefined {\n const globalState = globalThis as GlobalWithIntegrationRuntimeRegistry;\n return globalState[INTEGRATION_REQUEST_DISPATCHER_KEY];\n}\n\nconst INTEGRATION_DATA_HEADER = \"x-farm-integration-data\";\nconst INTEGRATION_DATA_HEADER_MAX_LENGTH = 16 * 1024;\nconst BLOCKED_INTEGRATION_DATA_KEYS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nfunction isIntegrationClientData(value: unknown): value is IntegrationClientData {\n return !!value && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction isPlainIntegrationDataObject(value: unknown): value is Record<string, unknown> {\n if (!isIntegrationClientData(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction sanitizeIntegrationClientDataValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => sanitizeIntegrationClientDataValue(item));\n }\n\n if (!isPlainIntegrationDataObject(value)) {\n return value;\n }\n\n const sanitized: Record<string, unknown> = {};\n for (const [key, item] of Object.entries(value)) {\n if (BLOCKED_INTEGRATION_DATA_KEYS.has(key)) {\n continue;\n }\n\n sanitized[key] = sanitizeIntegrationClientDataValue(item);\n }\n\n return sanitized;\n}\n\nfunction normalizeIntegrationClientData(\n value: IntegrationClientData | undefined,\n): IntegrationClientData | undefined {\n if (!isIntegrationClientData(value)) {\n return undefined;\n }\n\n const sanitized = sanitizeIntegrationClientDataValue(value);\n return isIntegrationClientData(sanitized) && Object.keys(sanitized).length > 0\n ? sanitized\n : undefined;\n}\n\nfunction getIntegrationDataHeaderByteLength(value: string): number {\n return new TextEncoder().encode(value).byteLength;\n}\n\nfunction mergeIntegrationClientData(\n ...values: Array<IntegrationClientData | undefined>\n): IntegrationClientData | undefined {\n let merged: IntegrationClientData | undefined;\n\n for (const value of values) {\n const data = normalizeIntegrationClientData(value);\n if (!data) {\n continue;\n }\n\n merged = {\n ...merged,\n ...data,\n };\n }\n\n return merged && Object.keys(merged).length > 0 ? merged : undefined;\n}\n\nfunction serializeIntegrationClientData(data: IntegrationClientData): string {\n const serialized = JSON.stringify(data);\n if (getIntegrationDataHeaderByteLength(serialized) > INTEGRATION_DATA_HEADER_MAX_LENGTH) {\n throw new Error(\n `Integration client data must be smaller than ${INTEGRATION_DATA_HEADER_MAX_LENGTH} bytes when sent over HTTP headers.`,\n );\n }\n\n return serialized;\n}\n\nfunction appendIntegrationClientDataHeader(\n headers: Headers,\n data: IntegrationClientData | undefined,\n) {\n if (!data) {\n return;\n }\n\n headers.set(INTEGRATION_DATA_HEADER, serializeIntegrationClientData(data));\n}\n\nfunction resolveAutomaticClientNamespaces(): ResolvedIntegrationNamespace[] {\n const globalState = globalThis as GlobalWithIntegrationAPIManifest;\n const manifest =\n globalState.window?.__FARM_INTEGRATION_API_MANIFEST__ ||\n globalState.__FARM_INTEGRATION_API_MANIFEST__ ||\n {};\n\n return Object.entries(manifest).map(([key, api]) => [key, api, api] as const);\n}\n\nfunction resolveAutomaticServerNamespaces(): ResolvedIntegrationNamespace[] {\n return Object.entries(getRegisteredIntegrationsLocal()).flatMap(([key, source]) => {\n const api = tryResolveSourceAPI(source);\n return api ? [[key, api, source] as ResolvedIntegrationNamespace] : [];\n });\n}\n\nfunction appendQuery(url: URL, query: Record<string, unknown> | undefined) {\n if (!query) {\n return;\n }\n\n for (const [key, value] of Object.entries(query)) {\n if (value == null) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item != null) {\n url.searchParams.append(key, String(item));\n }\n }\n continue;\n }\n\n url.searchParams.set(key, String(value));\n }\n}\n\nfunction appendHeaders(target: Headers, source: HeadersInit | undefined) {\n if (!source) {\n return;\n }\n\n const headers = new Headers(source);\n headers.forEach((value, key) => {\n target.set(key, value);\n });\n}\n\nconst DEFAULT_FORWARDED_HEADERS = [\n \"authorization\",\n \"cookie\",\n \"x-client-ip\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n \"x-real-ip\",\n] as const;\n\nfunction resolveRequestLike(request: IntegrationServerRequestLike | undefined) {\n if (!request) {\n return undefined;\n }\n\n if (request instanceof Request) {\n return {\n url: request.url,\n headers: request.headers,\n };\n }\n\n return {\n url: request.url,\n headers: request.headers ? new Headers(request.headers) : undefined,\n };\n}\n\nfunction resolveServerBaseURL(\n explicitBaseURL: string | undefined,\n request: ReturnType<typeof resolveRequestLike>,\n) {\n if (explicitBaseURL) {\n return explicitBaseURL;\n }\n\n if (request?.url) {\n try {\n return new URL(request.url).origin;\n } catch {\n // Fall back to forwarded headers below.\n }\n }\n\n const headers = request?.headers;\n const host = headers?.get(\"x-forwarded-host\") || headers?.get(\"host\");\n if (host) {\n const proto = headers?.get(\"x-forwarded-proto\") || \"http\";\n return `${proto}://${host}`;\n }\n\n return \"http://localhost:3000\";\n}\n\nfunction resolveForwardHeaders(\n request: ReturnType<typeof resolveRequestLike>,\n forwardHeaders: boolean | readonly string[] | undefined,\n) {\n if (!request?.headers || forwardHeaders === false) {\n return new Headers();\n }\n\n const allowed =\n Array.isArray(forwardHeaders) && forwardHeaders.length > 0\n ? new Set(forwardHeaders.map((item) => item.toLowerCase()))\n : new Set<string>(DEFAULT_FORWARDED_HEADERS);\n\n const headers = new Headers();\n request.headers.forEach((value, key) => {\n if (allowed.has(key.toLowerCase())) {\n headers.set(key, value);\n }\n });\n\n return headers;\n}\n\nfunction createBody(\n format: FarmIntegrationAPIBodyFormat | undefined,\n body: unknown,\n headers: Headers,\n): BodyInit | undefined {\n if (body == null || format === \"none\") {\n return undefined;\n }\n\n if (format === \"form\") {\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n const form = new URLSearchParams();\n for (const [key, value] of Object.entries(body as Record<string, unknown>)) {\n if (value == null) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item != null) {\n form.append(key, String(item));\n }\n }\n continue;\n }\n\n form.set(key, String(value));\n }\n\n headers.set(\"content-type\", \"application/x-www-form-urlencoded;charset=UTF-8\");\n return form;\n }\n\n headers.set(\"content-type\", \"application/json\");\n return JSON.stringify(body);\n}\n\nasync function parseResponseData(response: Response): Promise<unknown> {\n if (response.status === 204 || response.status === 205) {\n return undefined;\n }\n\n const contentType = response.headers.get(\"content-type\") || \"\";\n\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n\n return await response.text();\n}\n\nasync function safeParseResponseData(response: Response): Promise<unknown> {\n try {\n return await parseResponseData(response);\n } catch {\n return undefined;\n }\n}\n\nfunction createResponseError(response: Response, errorData: unknown) {\n const message =\n typeof errorData === \"string\"\n ? errorData\n : typeof errorData === \"object\" && errorData\n ? String(\n (errorData as { error?: string; message?: string }).error ||\n (errorData as { error?: string; message?: string }).message ||\n response.statusText,\n )\n : response.statusText || \"Integration request failed.\";\n\n return new IntegrationClientError(message, response, errorData);\n}\n\nfunction normalizeExecutionError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n if (typeof error === \"string\" && error.length > 0) {\n return new Error(error);\n }\n\n return new Error(\"Integration request failed.\");\n}\n\nasync function finalizeOperationResponse(\n operation: FarmIntegrationAPIOperation<any, any, any>,\n response: Response,\n) {\n if (!response.ok) {\n const errorData = await safeParseResponseData(response);\n return {\n data: null,\n error: createResponseError(response, errorData),\n };\n }\n\n if (operation.responseFormat === \"response\") {\n return {\n data: response,\n error: null,\n };\n }\n\n return {\n data: (await parseResponseData(response)) as unknown,\n error: null,\n };\n}\n\nasync function executeClientOperation(\n operation: FarmIntegrationAPIOperation<any, any, any>,\n input: Record<string, unknown>,\n options: Pick<IntegrationClientOptions, \"baseURL\" | \"headers\" | \"credentials\" | \"data\">,\n requestOptions?: IntegrationClientRequestOptions,\n) {\n try {\n if (!operation.path) {\n return {\n data: null,\n error: new Error(\n \"Integration API operation path is missing. Pass a path to api.get/post/... or wrap pathless methods with api.route(path, { ... }).\",\n ),\n };\n }\n\n const baseURL =\n options.baseURL ||\n (typeof window !== \"undefined\" ? window.location.origin : \"http://localhost:3000\");\n const url = new URL(operation.path, baseURL);\n appendQuery(url, input.query as Record<string, unknown> | undefined);\n\n const headers = new Headers({\n \"x-farm-integration-client\": \"1\",\n ...options.headers,\n ...operation.headers,\n ...requestOptions?.headers,\n });\n\n if (operation.responseFormat !== \"response\") {\n headers.set(\"accept\", \"application/json\");\n }\n\n appendIntegrationClientDataHeader(\n headers,\n mergeIntegrationClientData(options.data, requestOptions?.data),\n );\n\n const response = await fetch(url.toString(), {\n method: operation.method,\n headers,\n body: createBody(operation.bodyFormat, input.body, headers),\n credentials:\n requestOptions?.credentials ?? operation.credentials ?? options.credentials ?? \"include\",\n signal: requestOptions?.signal,\n });\n\n if (!response.ok) {\n const errorData = await safeParseResponseData(response);\n return {\n data: null,\n error: createResponseError(response, errorData),\n };\n }\n\n if (operation.responseFormat === \"response\") {\n return {\n data: response,\n error: null,\n };\n }\n\n return {\n data: (await parseResponseData(response)) as unknown,\n error: null,\n };\n } catch (error) {\n return {\n data: null,\n error: normalizeExecutionError(error),\n };\n }\n}\n\nasync function executeServerOperation(\n operation: FarmIntegrationAPIOperation<any, any, any>,\n input: Record<string, unknown>,\n options: Pick<\n IntegrationServerClientOptions,\n \"baseURL\" | \"headers\" | \"credentials\" | \"data\" | \"request\" | \"forwardHeaders\"\n >,\n requestOptions?: IntegrationServerClientRequestOptions,\n integrationKey?: string,\n source?: FarmIntegrationDefinition | FarmIntegrationAPI,\n) {\n try {\n if (!operation.path) {\n return {\n data: null,\n error: new Error(\n \"Integration API operation path is missing. Pass a path to api.get/post/... or wrap pathless methods with api.route(path, { ... }).\",\n ),\n };\n }\n\n const serverRequestOptions =\n requestOptions &&\n (\"request\" in requestOptions ||\n \"baseURL\" in requestOptions ||\n \"forwardHeaders\" in requestOptions)\n ? requestOptions\n : undefined;\n const currentRequest =\n serverRequestOptions?.request instanceof Request\n ? serverRequestOptions.request\n : options.request instanceof Request\n ? options.request\n : resolveCurrentRequestLocal();\n const request = resolveRequestLike(\n serverRequestOptions?.request ?? options.request ?? currentRequest,\n );\n const baseURL = resolveServerBaseURL(serverRequestOptions?.baseURL ?? options.baseURL, request);\n const url = new URL(operation.path, baseURL);\n appendQuery(url, input.query as Record<string, unknown> | undefined);\n\n const headers = new Headers();\n appendHeaders(\n headers,\n resolveForwardHeaders(\n request,\n serverRequestOptions?.forwardHeaders ?? options.forwardHeaders,\n ),\n );\n appendHeaders(headers, options.headers);\n appendHeaders(headers, operation.headers);\n appendHeaders(headers, requestOptions?.headers);\n headers.set(\"x-farm-integration-client\", \"1\");\n\n if (operation.responseFormat !== \"response\") {\n headers.set(\"accept\", \"application/json\");\n }\n\n const data = mergeIntegrationClientData(options.data, requestOptions?.data);\n\n if (integrationKey) {\n const runtime =\n \"kind\" in (source || {}) &&\n (source as FarmIntegrationDefinition).kind === \"farm-integration\"\n ? getRegisteredIntegrationRuntimeLocal(integrationKey) || {\n integration: source as FarmIntegrationDefinition,\n config: {},\n isDev: process.env.NODE_ENV !== \"production\",\n isProd: process.env.NODE_ENV === \"production\",\n }\n : getRegisteredIntegrationRuntimeLocal(integrationKey);\n\n if (runtime) {\n const dispatchIntegrationRequest = resolveIntegrationRequestDispatcherLocal();\n const directResponse = dispatchIntegrationRequest\n ? await dispatchIntegrationRequest(\n runtime,\n new Request(url.toString(), {\n method: operation.method,\n headers,\n body: createBody(operation.bodyFormat, input.body, headers),\n }),\n {\n currentRequest,\n data,\n internal: true,\n },\n )\n : null;\n\n if (directResponse) {\n return await finalizeOperationResponse(operation, directResponse);\n }\n }\n }\n\n appendIntegrationClientDataHeader(headers, data);\n\n const response = await fetch(url.toString(), {\n method: operation.method,\n headers,\n body: createBody(operation.bodyFormat, input.body, headers),\n credentials:\n requestOptions?.credentials ?? operation.credentials ?? options.credentials ?? \"include\",\n signal: requestOptions?.signal,\n });\n\n return await finalizeOperationResponse(operation, response);\n } catch (error) {\n return {\n data: null,\n error: normalizeExecutionError(error),\n };\n }\n}\n\nexport function createIntegrationClient<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n options: IntegrationServerClientOptions,\n): IntegrationServerClientAliases<TSources>;\nexport function createIntegrationClient<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n options?: IntegrationClientOptions,\n): IntegrationClientAliases<TSources>;\nexport function createIntegrationClient<TSources extends Record<string, any>>(\n sources: TSources,\n options: IntegrationServerClientOptions,\n): IntegrationServerClient<TSources>;\nexport function createIntegrationClient<TSources extends Record<string, any>>(\n sources: TSources,\n options?: IntegrationClientOptions,\n): IntegrationClient<TSources>;\nexport function createIntegrationClient<TSources extends Record<string, any>>(\n sources: TSources | { integrations: TSources },\n options: IntegrationClientOptions | IntegrationServerClientOptions = {},\n):\n | IntegrationClient<TSources>\n | IntegrationClientAliases<TSources>\n | IntegrationServerClient<TSources>\n | IntegrationServerClientAliases<TSources> {\n const rawSources = \"integrations\" in sources ? sources.integrations : sources;\n const isServer = options.isServer === true;\n\n const namespaces = Object.entries(rawSources)\n .map(([key, source]) => {\n const api = tryResolveSourceAPI(source as FarmIntegrationDefinition | FarmIntegrationAPI);\n if (!api) {\n return null;\n }\n return [key, api, source as FarmIntegrationDefinition | FarmIntegrationAPI] as const;\n })\n .filter(\n (\n value,\n ): value is readonly [\n string,\n FarmIntegrationAPI,\n FarmIntegrationDefinition | FarmIntegrationAPI,\n ] => value !== null,\n );\n\n const cache = new Map<string, any>();\n\n const integrationNamespaces = new Proxy(\n {},\n {\n get(target, property) {\n if (typeof property !== \"string\") {\n return undefined;\n }\n\n if (Reflect.has(target, property)) {\n return Reflect.get(target, property);\n }\n\n if (cache.has(property)) {\n return cache.get(property);\n }\n\n const match = namespaces.find(([key]) => key === property);\n if (!match) {\n return undefined;\n }\n\n const namespace = isServer\n ? createServerNamespaceProxy(\n match[0],\n match[2],\n match[1],\n options as IntegrationServerClientOptions,\n )\n : createNamespaceProxy(match[1], options);\n cache.set(property, namespace);\n return namespace;\n },\n },\n ) as\n | IntegrationClient<TSources>\n | IntegrationClientAliases<TSources>\n | IntegrationServerClient<TSources>\n | IntegrationServerClientAliases<TSources>;\n\n if (\"integrations\" in sources) {\n Object.defineProperty(integrationNamespaces, \"integrations\", {\n value: integrationNamespaces,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n\n return integrationNamespaces as\n | IntegrationClientAliases<TSources>\n | IntegrationServerClientAliases<TSources>;\n }\n\n return integrationNamespaces as IntegrationClient<TSources> | IntegrationServerClient<TSources>;\n}\n\nfunction createAutomaticIntegrationAliases<TSources extends Record<string, any>>(\n isServer: boolean,\n options: IntegrationClientOptions | IntegrationServerClientOptions = {},\n): IntegrationClientAliases<TSources> | IntegrationServerClientAliases<TSources> {\n const cache = isServer ? new Map<string, any>() : null;\n\n const integrationNamespaces = new Proxy(\n {},\n {\n get(_target, property) {\n if (typeof property !== \"string\") {\n return undefined;\n }\n\n if (property === \"integrations\") {\n return integrationNamespaces;\n }\n\n if (cache?.has(property)) {\n return cache.get(property);\n }\n\n const namespaces = isServer\n ? resolveAutomaticServerNamespaces()\n : resolveAutomaticClientNamespaces();\n const match = namespaces.find(([key]) => key === property);\n if (!match) {\n return undefined;\n }\n\n const namespace = isServer\n ? createServerNamespaceProxy(\n match[0],\n match[2],\n match[1],\n options as IntegrationServerClientOptions,\n )\n : createNamespaceProxy(match[1], options as IntegrationClientOptions);\n\n cache?.set(property, namespace);\n return namespace;\n },\n },\n ) as IntegrationClientAliases<TSources> | IntegrationServerClientAliases<TSources>;\n\n Object.defineProperty(integrationNamespaces, \"integrations\", {\n value: integrationNamespaces,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n\n return integrationNamespaces;\n}\n\nexport function integrationsClient<\n TSources extends Record<string, any>,\n>(): IntegrationClientAliases<TSources>;\nexport function integrationsClient<TSources extends Record<string, any>>(\n options: IntegrationClientOptions,\n): IntegrationClientAliases<TSources>;\nexport function integrationsClient<TSources extends Record<string, any>>(\n options: IntegrationClientOptions = {},\n): IntegrationClientAliases<TSources> {\n return createAutomaticIntegrationAliases<TSources>(\n false,\n options,\n ) as IntegrationClientAliases<TSources>;\n}\n\nexport function integrationsServer<\n TSources extends Record<string, any>,\n>(): IntegrationServerClientAliases<TSources>;\nexport function integrationsServer<TSources extends Record<string, any>>(\n options: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationServerClientAliases<TSources>;\nexport function integrationsServer<TSources extends Record<string, any>>(\n options: Omit<IntegrationServerClientOptions, \"isServer\"> = {},\n): IntegrationServerClientAliases<TSources> {\n return createAutomaticIntegrationAliases<TSources>(true, {\n ...options,\n isServer: true,\n }) as IntegrationServerClientAliases<TSources>;\n}\n\nexport function createIntegrationServerClient<TSources extends Record<string, any>>(sources: {\n integrations: TSources;\n}): IntegrationServerClientAliases<TSources>;\nexport function createIntegrationServerClient<TSources extends Record<string, any>>(\n sources: TSources,\n): IntegrationServerClient<TSources>;\nexport function createIntegrationServerClient<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n options: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationServerClientAliases<TSources>;\nexport function createIntegrationServerClient<TSources extends Record<string, any>>(\n sources: TSources,\n options: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationServerClient<TSources>;\nexport function createIntegrationServerClient<TSources extends Record<string, any>>(\n sources: TSources | { integrations: TSources },\n options: Omit<IntegrationServerClientOptions, \"isServer\"> = {},\n): IntegrationServerClient<TSources> | IntegrationServerClientAliases<TSources> {\n return createIntegrationClient(sources, {\n ...options,\n isServer: true,\n }) as IntegrationServerClient<TSources> | IntegrationServerClientAliases<TSources>;\n}\n\nexport function createIntegrationApi<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n options: IntegrationClientOptions = {},\n): IntegrationAPI<TSources> {\n const client = createIntegrationClient(sources, options);\n\n return {\n ...client,\n server(serverOptions = {}) {\n return createIntegrationServerClient(sources, {\n ...options,\n ...serverOptions,\n });\n },\n };\n}\n\nfunction isIntegrationClientOptionsInput(value: unknown): value is IntegrationClientOptions {\n return (\n !!value &&\n typeof value === \"object\" &&\n !Array.isArray(value) &&\n (\"baseURL\" in value ||\n \"headers\" in value ||\n \"credentials\" in value ||\n \"data\" in value ||\n \"isServer\" in value)\n );\n}\n\nfunction resolveIntegrationServerOptions(\n clientOptions: IntegrationClientOptions = {},\n serverOptions: Omit<IntegrationServerClientOptions, \"isServer\"> = {},\n): Omit<IntegrationServerClientOptions, \"isServer\"> {\n const data = mergeIntegrationClientData(clientOptions.data, serverOptions.data);\n\n return {\n baseURL: clientOptions.baseURL,\n headers: clientOptions.headers,\n credentials: clientOptions.credentials,\n ...serverOptions,\n ...(data ? { data } : {}),\n };\n}\n\nexport function createIntegrationClients<TSources extends Record<string, any>>(\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrationClients<TSources extends Record<string, any>>(\n sources: TSources,\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrationClients<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrationClients<TSources extends Record<string, any>>(\n sources?: TSources | { integrations: TSources },\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources> {\n if (arguments.length === 0 || isIntegrationClientOptionsInput(sources)) {\n const automaticClientOptions = isIntegrationClientOptionsInput(sources) ? sources : {};\n const automaticServerOptions = arguments.length > 1 ? clientOptions : undefined;\n\n return {\n api: integrationsServer<TSources>(\n resolveIntegrationServerOptions(\n automaticClientOptions,\n automaticServerOptions as Omit<IntegrationServerClientOptions, \"isServer\"> | undefined,\n ),\n ),\n apiClient: integrationsClient<TSources>(automaticClientOptions),\n };\n }\n\n const explicitSources =\n sources && \"integrations\" in sources ? sources.integrations : (sources as TSources);\n\n return {\n api: createIntegrationServerClient(\n {\n integrations: explicitSources,\n },\n resolveIntegrationServerOptions(clientOptions, serverOptions),\n ) as IntegrationServerClientAliases<TSources>,\n apiClient: createIntegrationClient(\n {\n integrations: explicitSources,\n },\n clientOptions,\n ) as IntegrationClientAliases<TSources>,\n };\n}\n\nexport function createIntegrations<TSources extends Record<string, any>>(\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrations<TSources extends Record<string, any>>(\n sources: TSources,\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrations<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function createIntegrations<TSources extends Record<string, any>>(\n sources?: TSources | { integrations: TSources } | IntegrationClientOptions,\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources> {\n if (arguments.length === 0) {\n return createIntegrationClients<TSources>();\n }\n\n return createIntegrationClients<TSources>(\n sources as TSources,\n clientOptions,\n serverOptions,\n ) as IntegrationClients<TSources>;\n}\n\nfunction createClientSafeIntegrationAPI(\n api: FarmIntegrationAPI | undefined,\n): FarmIntegrationAPI | undefined {\n if (!api) {\n return undefined;\n }\n\n const entries = Object.entries(api as Record<string, unknown>).map(([key, value]) => {\n if (isOperation(value)) {\n return [\n key,\n {\n kind: value.kind,\n path: value.path,\n method: value.method,\n bodyFormat: value.bodyFormat,\n responseFormat: value.responseFormat,\n credentials: value.credentials,\n isServer: value.isServer,\n __pathless: value.__pathless,\n },\n ];\n }\n\n if (value && typeof value === \"object\") {\n return [key, createClientSafeIntegrationAPI(value as FarmIntegrationAPI)];\n }\n\n return [key, value];\n });\n\n return Object.fromEntries(entries) as FarmIntegrationAPI;\n}\n\nexport function getIntegrationAPIManifest(): Record<string, FarmIntegrationAPI> {\n const manifestEntries = Object.entries(getRegisteredIntegrationsLocal())\n .map(([key, integration]) => {\n const api = createClientSafeIntegrationAPI(integration.api);\n return api ? ([key, api] as const) : null;\n })\n .filter((value): value is readonly [string, FarmIntegrationAPI] => value !== null);\n\n return Object.fromEntries(manifestEntries);\n}\n\nexport function integrationClients<TSources extends Record<string, any>>(\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function integrationClients<TSources extends Record<string, any>>(\n sources: TSources,\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function integrationClients<TSources extends Record<string, any>>(\n sources: { integrations: TSources },\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources>;\nexport function integrationClients<TSources extends Record<string, any>>(\n sources?: TSources | { integrations: TSources },\n clientOptions?: IntegrationClientOptions,\n serverOptions?: Omit<IntegrationServerClientOptions, \"isServer\">,\n): IntegrationClients<TSources> {\n if (arguments.length === 0) {\n return createIntegrationClients<TSources>();\n }\n\n return createIntegrationClients<TSources>(\n sources as TSources,\n clientOptions,\n serverOptions,\n ) as IntegrationClients<TSources>;\n}\n\nfunction resolveSingleNamespaceOperation(api: FarmIntegrationAPI) {\n const entries = Object.entries(api as Record<string, unknown>);\n if (entries.length !== 1) {\n return null;\n }\n\n const [, value] = entries[0]!;\n return isOperation(value) ? value : null;\n}\n\nfunction createClientOperationCaller(\n operation: FarmIntegrationAPIOperation<any, any, any, any>,\n property: string,\n options: IntegrationClientOptions,\n) {\n if (operation.isServer === true) {\n return async () => {\n throw new Error(\n `Integration method \"${property}\" is registered with isServer: true and is only available from a server integration client.`,\n );\n };\n }\n\n return async (\n input: Record<string, unknown> = {},\n requestOptions?: IntegrationClientRequestOptions,\n ) => {\n if (typeof window === \"undefined\") {\n throw new Error(\n \"Client integration API cannot be called on the server. Pass { isServer: true } to createIntegrationClient(...) during server rendering, or provide { isServer: true, request } outside it.\",\n );\n }\n\n return executeClientOperation(operation, input, options, requestOptions);\n };\n}\n\nfunction createServerOperationCaller(\n operation: FarmIntegrationAPIOperation<any, any, any, any>,\n options: IntegrationServerClientOptions,\n integrationKey: string,\n source: FarmIntegrationDefinition | FarmIntegrationAPI,\n) {\n return async (\n input: Record<string, unknown> = {},\n requestOptions?: IntegrationServerClientRequestOptions,\n ) => {\n if (typeof window !== \"undefined\") {\n throw new Error(\n \"Server integration API cannot be called in the browser. Remove { isServer: true } and create a client integration API instead.\",\n );\n }\n\n return executeServerOperation(\n operation,\n input,\n options,\n requestOptions,\n integrationKey,\n source,\n );\n };\n}\n\nfunction createNamespaceProxy(api: FarmIntegrationAPI, options: IntegrationClientOptions) {\n const cache = new Map<string, any>();\n const directOperation = resolveSingleNamespaceOperation(api);\n const target = directOperation\n ? createClientOperationCaller(directOperation, directOperation.method.toLowerCase(), options)\n : {};\n\n return new Proxy(target, {\n get(targetObject, property, receiver) {\n if (typeof property !== \"string\") {\n return Reflect.get(targetObject, property, receiver);\n }\n\n if (cache.has(property)) {\n return cache.get(property);\n }\n\n const value = (api as Record<string, unknown>)[property];\n if (!value) {\n return Reflect.get(targetObject, property, receiver);\n }\n\n if (isOperation(value)) {\n const caller = createClientOperationCaller(value, property, options);\n cache.set(property, caller);\n return caller;\n }\n\n const namespace = createNamespaceProxy(value as FarmIntegrationAPI, options);\n cache.set(property, namespace);\n return namespace;\n },\n });\n}\n\nfunction createServerNamespaceProxy(\n integrationKey: string,\n source: FarmIntegrationDefinition | FarmIntegrationAPI,\n api: FarmIntegrationAPI,\n options: IntegrationServerClientOptions,\n) {\n const cache = new Map<string, any>();\n const directOperation = resolveSingleNamespaceOperation(api);\n const target = directOperation\n ? createServerOperationCaller(directOperation, options, integrationKey, source)\n : {};\n\n return new Proxy(target, {\n get(targetObject, property, receiver) {\n if (typeof property !== \"string\") {\n return Reflect.get(targetObject, property, receiver);\n }\n\n if (cache.has(property)) {\n return cache.get(property);\n }\n\n const value = (api as Record<string, unknown>)[property];\n if (!value) {\n return Reflect.get(targetObject, property, receiver);\n }\n\n if (isOperation(value)) {\n const caller = createServerOperationCaller(value, options, integrationKey, source);\n cache.set(property, caller);\n return caller;\n }\n\n const namespace = createServerNamespaceProxy(\n integrationKey,\n source,\n value as FarmIntegrationAPI,\n options,\n );\n cache.set(property, namespace);\n return namespace;\n },\n });\n}\n","import {\n integrationsClient,\n integrationsServer,\n type IntegrationClientOptions,\n type IntegrationClientRoot,\n type IntegrationServerClientOptions,\n type IntegrationServerClientRoot,\n} from \"../integration-client\";\nimport {\n getFarmClientDataCache,\n normalizeFarmClientCacheKey,\n type FarmClientCacheEntry,\n type FarmClientCacheKey,\n type FarmClientDataCache,\n} from \"../client-cache\";\nimport {\n applyFarmCacheInvalidations,\n decodeFarmCacheInvalidations,\n FARM_CACHE_INVALIDATION_HEADER,\n} from \"../cache-invalidation\";\nimport type { DefinedCacheKey, InferCacheKeyData, RouteDataCacheKey } from \"../cache\";\n\nexport const FARM_API_ROUTE_REF_SYMBOL: unique symbol = Symbol.for(\"farm.api.route-ref\") as any;\n\nexport type APIClientOptions = {\n baseURL?: string;\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n cacheDefaults?: CacheOptions;\n integrations?: IntegrationClientOptions;\n};\n\nexport type APIClientWithoutIntegrationsOptions = Omit<APIClientOptions, \"integrations\"> & {\n integrations: false;\n};\n\nexport type ServerAPIClientOptions = {\n integrations?: Omit<IntegrationServerClientOptions, \"isServer\">;\n};\n\nexport type ServerAPIClientWithoutIntegrationsOptions = Omit<\n ServerAPIClientOptions,\n \"integrations\"\n> & {\n integrations: false;\n};\n\nexport type StatusPhase = \"idle\" | \"pending\" | \"success\" | \"error\" | \"revalidating\" | \"invalidated\";\n\nexport type StatusEvent<TData = unknown, TError = unknown> = {\n phase: StatusPhase;\n requestId: string;\n method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\";\n key: string;\n input?: unknown;\n data?: TData;\n error?: TError;\n isBackground?: boolean;\n timestamp: number;\n};\n\nexport type CacheKey<TData = unknown> = string & {\n readonly __farmCacheData?: TData;\n};\n\nexport type APIResult<TData = unknown, TError = Error> = {\n data: TData | undefined;\n error: TError | null;\n key: CacheKey<TData>;\n};\n\nexport class APIClientError<\n TCode extends string = string,\n TData = unknown,\n TStatus extends number = number,\n> extends Error {\n readonly code: TCode;\n readonly data: TData;\n readonly status: TStatus;\n readonly response?: Response;\n\n constructor(\n code: TCode,\n data: TData,\n options: {\n status: TStatus;\n message: string;\n response?: Response;\n },\n ) {\n super(options.message);\n this.name = \"APIClientError\";\n this.code = code;\n this.data = data;\n this.status = options.status;\n this.response = options.response;\n }\n}\n\nexport type APIClientSystemError =\n | APIClientError<\"http_error\", unknown, number>\n | APIClientError<\"network_error\", unknown, 0>;\n\nexport type RequestEvent = {\n requestId: string;\n method: StatusEvent[\"method\"];\n key: string;\n path: string;\n input?: unknown;\n attempt: number;\n timestamp: number;\n};\n\nexport type ResponseEvent<TData = unknown, TError = Error> = {\n requestId: string;\n method: StatusEvent[\"method\"];\n key: string;\n path: string;\n input?: unknown;\n attempt: number;\n timestamp: number;\n response?: Response;\n data?: TData;\n error?: TError;\n ok?: boolean;\n status?: number;\n};\n\nexport type CachePolicy = \"cache-first\" | \"network-only\" | \"stale-while-revalidate\";\n\nexport type CacheOptions = {\n key?: FarmClientCacheKey;\n policy?: CachePolicy;\n staleTime?: number;\n gcTime?: number;\n dedupeMs?: number;\n};\n\nexport type RetryOptions = {\n count?: number;\n delay?: number | ((attempt: number) => number);\n};\n\nexport type InvalidateTarget =\n | FarmClientCacheKey\n | {\n key: FarmClientCacheKey;\n }\n | {\n path: string;\n method?: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\";\n input?: unknown;\n }\n | [CallableRouteRef<any>, unknown?];\n\nexport type InvalidateOptions =\n | InvalidateTarget[]\n | {\n targets: InvalidateTarget[];\n refetch?: boolean;\n };\n\nexport type OptimisticUpdate =\n | [CallableRouteRef<any>, unknown, (prev: any) => any]\n | [CacheKey<any> | DefinedCacheKey<any> | string, (prev: any) => any];\n\nexport type OptimisticOptions<TUpdates extends readonly unknown[] = readonly OptimisticUpdate[]> = {\n update: TUpdates & NormalizeOptimisticUpdates<TUpdates>;\n rollbackOnError?: boolean;\n};\n\nexport type ClientOptions<\n TData = unknown,\n TError = unknown,\n TUpdates extends readonly unknown[] = readonly OptimisticUpdate[],\n> = {\n key?: CacheKey<TData> | FarmClientCacheKey;\n cache?: CacheOptions;\n retry?: RetryOptions;\n invalidate?: InvalidateOptions;\n optimistic?: OptimisticOptions<TUpdates>;\n onRequest?: (event: RequestEvent) => void;\n onResponse?: (\n data: TData | undefined,\n error: TError | null,\n event: ResponseEvent<TData, TError>,\n ) => void;\n onSuccess?: (data: TData) => void;\n onError?: (err: TError) => void;\n onSettled?: (data?: TData, err?: TError | null) => void;\n onStatus?: (event: StatusEvent<TData, TError>) => void;\n};\n\ntype AnyRouteRef = (...args: any[]) => any;\ntype RouteRef<TData = any, TInput = any> = {\n readonly __farmRouteInput: TInput;\n readonly __farmRouteData: TData;\n};\ntype CallableRouteRef<TData = any, TInput = any> = AnyRouteRef & RouteRef<TData, TInput>;\n\ntype InferRouteInput<TRoute> = TRoute extends { readonly __farmRouteInput: infer TInput }\n ? TInput\n : never;\ntype InferRouteData<TRoute> = TRoute extends { readonly __farmRouteData: infer TData }\n ? TData\n : never;\n\ntype NormalizeOptimisticUpdate<TUpdate> = TUpdate extends readonly [\n infer TRoute,\n unknown,\n (prev: any) => any,\n]\n ? TRoute extends RouteRef<any, any>\n ? [\n TRoute,\n InferRouteInput<TRoute> | undefined,\n (prev: InferRouteData<TRoute> | undefined) => InferRouteData<TRoute>,\n ]\n : never\n : TUpdate extends readonly [infer TKey, (prev: any) => any]\n ? TKey extends DefinedCacheKey<any, RouteDataCacheKey>\n ? [TKey, (prev: InferCacheKeyData<TKey> | undefined) => InferCacheKeyData<TKey>]\n : TKey extends CacheKey<infer TData>\n ? [TKey, (prev: TData | undefined) => TData]\n : TKey extends string\n ? [TKey, (prev: unknown) => unknown]\n : never\n : never;\n\ntype NormalizeOptimisticUpdates<TUpdates extends readonly unknown[]> = {\n [K in keyof TUpdates]: NormalizeOptimisticUpdate<TUpdates[K]>;\n};\n\ntype TypedEndpointLike = {\n __types: {\n body: any;\n query: any;\n response: any;\n errors?: any;\n };\n};\n\ntype Simplify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\ntype IsNever<T> = [T] extends [never] ? true : false;\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype RequiredKeys<T> = T extends object\n ? {\n [K in keyof T]-?: {} extends Pick<T, K> ? never : K;\n }[keyof T]\n : never;\n\ntype BodyInputProp<TValue> =\n IsNever<TValue> extends true\n ? {}\n : IsAny<TValue> extends true\n ? { body?: TValue }\n : undefined extends TValue\n ? { body?: TValue }\n : { body: TValue };\n\ntype QueryInputProp<TValue> =\n IsNever<TValue> extends true\n ? {}\n : IsAny<TValue> extends true\n ? { query?: TValue }\n : undefined extends TValue\n ? { query?: TValue }\n : RequiredKeys<TValue> extends never\n ? { query?: TValue }\n : { query: TValue };\n\ntype HasRequiredKeys<T> = RequiredKeys<T> extends never ? false : true;\n\n// Type utilities to extract endpoint input/output types from TypedEndpoint\ntype InferEndpointInput<T> = T extends {\n __types: {\n body: infer TBody;\n query: infer TQuery;\n };\n}\n ? Simplify<BodyInputProp<TBody> & QueryInputProp<TQuery>>\n : {};\n\ntype InferEndpointOutput<T> = T extends {\n __types: {\n response: infer R;\n };\n}\n ? R\n : any;\n\ntype InferEndpointError<T> = T extends {\n __types: {\n errors: infer TErrors;\n };\n}\n ? keyof TErrors extends never\n ? Error\n :\n | {\n [TCode in keyof TErrors]: TErrors[TCode] extends {\n data: infer TData;\n status: infer TStatus extends number;\n }\n ? APIClientError<TCode & string, TData, TStatus>\n : never;\n }[keyof TErrors]\n | APIClientSystemError\n : Error;\n\n// Type for a single endpoint method\ntype EndpointMethod<T = any> = (<TUpdates extends readonly unknown[] = readonly OptimisticUpdate[]>(\n ...args: HasRequiredKeys<InferEndpointInput<T>> extends true\n ? [\n options: InferEndpointInput<T>,\n clientOptions?: ClientOptions<InferEndpointOutput<T>, InferEndpointError<T>, TUpdates>,\n ]\n : [\n options?: InferEndpointInput<T>,\n clientOptions?: ClientOptions<InferEndpointOutput<T>, InferEndpointError<T>, TUpdates>,\n ]\n) => Promise<APIResult<InferEndpointOutput<T>, InferEndpointError<T>>>) &\n RouteRef<InferEndpointOutput<T>, InferEndpointInput<T>>;\n\n// Type for converting router structure to client structure\ntype RouterToClient<T> = {\n [K in keyof T]: T[K] extends TypedEndpointLike\n ? EndpointMethod<T[K]>\n : T[K] extends Record<string, any>\n ? RouterToClient<T[K]> // Recurssive handling of the multi level api routes\n : EndpointMethod<T[K]>;\n};\n\nexport type RouteAPIClient<TRouter extends Record<string, any>> = RouterToClient<TRouter>;\n\nexport type APIClient<\n TRouter extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n> = RouteAPIClient<TRouter> & IntegrationClientRoot<TIntegrations>;\n\nexport type ServerAPIClient<\n TEndpoints extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n> = TEndpoints & IntegrationServerClientRoot<TIntegrations>;\n\n/**\n * Create a typed RPC client for Farm.js API routes\n *\n * Returns a nested proxy that supports:\n * - api.hello.get({ query: { name: 'World' } })\n * - api['auth/login'].post({ body: { email: '...', password: '...' } })\n * - api.users.get({ query: { limit: '10' } })\n * - api.integrations.billing.checkout({ body: { priceId: 'price_...' } })\n *\n * @example\n * ```typescript\n * import { createAPIClient } from 'farm/client';\n * import type { APIRouter } from '@/api';\n * import type { AppIntegrations } from '@/lib/integrations';\n *\n * export const api = createAPIClient<APIRouter, AppIntegrations>();\n *\n * // Use it (nested property access)\n * const result = await api.hello.get({ query: { name: 'World' } });\n * if (result.error) console.error(result.error);\n * else console.log(result.data);\n *\n * // Or with string keys for nested paths\n * const result = await api['auth/login'].post({\n * body: { email: 'test@example.com', password: 'pass123' }\n * });\n *\n * // Integration APIs live under a reserved namespace.\n * const checkout = await api.integrations.billing.checkout({\n * body: { priceId: 'price_123' }\n * });\n * ```\n */\nexport function createAPIClient<TRouter extends Record<string, any>>(\n options: APIClientWithoutIntegrationsOptions,\n): RouteAPIClient<TRouter>;\nexport function createAPIClient<\n TRouter extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n>(options?: APIClientOptions): APIClient<TRouter, TIntegrations>;\nexport function createAPIClient<\n TRouter extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n>(\n options: APIClientOptions | APIClientWithoutIntegrationsOptions = {},\n): RouteAPIClient<TRouter> | APIClient<TRouter, TIntegrations> {\n options ??= {};\n // Auto-detect baseURL\n const baseURL =\n options.baseURL ||\n (typeof window !== \"undefined\" ? window.location.origin : \"http://localhost:3000\");\n const integrationOptions =\n options.integrations === false\n ? false\n : {\n baseURL: options.baseURL,\n headers: options.headers,\n credentials: options.credentials,\n ...(typeof options.integrations === \"object\" ? options.integrations : {}),\n };\n const rootAliases =\n integrationOptions === false\n ? undefined\n : {\n integrations: integrationsClient<TIntegrations>(integrationOptions),\n };\n\n const cacheState = getFarmClientDataCache();\n const inflightState = new Map<string, InflightEntry>();\n const routeMeta = new WeakMap<AnyRouteRef, RouteMeta>();\n let requestCounter = 0;\n\n // Create a simple fetch-based client (browser compatible)\n const fetchClient = async (path: string, requestOptions: any = {}) => {\n const url = new URL(path, baseURL);\n\n // Handle query parameters\n if (requestOptions.query) {\n Object.entries(requestOptions.query).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n });\n }\n\n // Prepare fetch options\n const fetchOptions: RequestInit = {\n method: requestOptions.method || \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...options.headers,\n ...requestOptions.headers,\n },\n };\n\n // Handle body\n if (requestOptions.body) {\n fetchOptions.body = JSON.stringify(requestOptions.body);\n }\n\n const response = await fetch(url.toString(), fetchOptions);\n applyFarmCacheInvalidations(\n decodeFarmCacheInvalidations(response.headers?.get?.(FARM_CACHE_INVALIDATION_HEADER)),\n );\n let data: any = undefined;\n if (response.status !== 204 && response.status !== 205) {\n data = await response.json();\n }\n\n return { response, data };\n };\n\n const request = async (\n path: string,\n method: string,\n input: any = {},\n clientOptions?: ClientOptions<any, any>,\n ): Promise<APIResult<any, Error>> => {\n const methodUpper = method.toUpperCase() as StatusEvent[\"method\"];\n const requestId = `${Date.now()}-${++requestCounter}`;\n const cacheOptions = clientOptions?.cache\n ? {\n ...options.cacheDefaults,\n ...clientOptions.cache,\n }\n : undefined;\n const configuredCacheKey = clientOptions?.key ?? cacheOptions?.key;\n const cacheKey = normalizeFarmClientCacheKey(\n configuredCacheKey ?? buildCacheKey(methodUpper, path, input, baseURL),\n ) as CacheKey<any>;\n const now = Date.now();\n\n const emitStatus = (phase: StatusPhase, payload?: Partial<StatusEvent>) => {\n clientOptions?.onStatus?.({\n phase,\n requestId,\n method: methodUpper,\n key: cacheKey,\n input,\n timestamp: Date.now(),\n ...payload,\n });\n };\n\n const entry = getValidCacheEntry(cacheState, cacheKey, now);\n const policy = cacheOptions?.policy ?? (cacheOptions ? \"cache-first\" : \"network-only\");\n const staleTime = cacheOptions?.staleTime ?? 0;\n const isCacheEnabled = Boolean(cacheOptions) && methodUpper === \"GET\";\n const isStale = entry ? isEntryStale(entry, now) : true;\n\n const applyOptimisticUpdates = () => {\n if (!clientOptions?.optimistic?.update?.length) return [] as OptimisticSnapshot[];\n\n const snapshots: OptimisticSnapshot[] = [];\n for (const update of clientOptions.optimistic.update) {\n const [target, targetInput, updater] =\n update.length === 2\n ? [update[0], undefined, update[1]]\n : [update[0], update[1], update[2]];\n const targetKey = resolveTargetKey(routeMeta, target, targetInput, baseURL);\n if (!targetKey) continue;\n\n const targetEntry = getValidCacheEntry(cacheState, targetKey, now);\n const previousEntry = targetEntry ? { ...targetEntry } : undefined;\n const previousData = targetEntry?.data;\n const nextData = updater(previousData);\n cacheState.set(targetKey, {\n data: nextData,\n updatedAt: now,\n staleAt:\n targetEntry?.staleAt ??\n now + (cacheOptions?.staleTime ?? options.cacheDefaults?.staleTime ?? 0),\n gcAt:\n targetEntry?.gcAt ??\n getGcAt(now, cacheOptions?.gcTime ?? options.cacheDefaults?.gcTime),\n invalidatedAt: targetEntry?.invalidatedAt,\n });\n\n snapshots.push({ key: targetKey, entry: previousEntry });\n }\n\n return snapshots;\n };\n\n const rollbackOptimisticUpdates = (snapshots: OptimisticSnapshot[]) => {\n if (!clientOptions?.optimistic?.rollbackOnError) return;\n\n for (const snapshot of snapshots) {\n if (!snapshot.entry) {\n cacheState.delete(snapshot.key);\n continue;\n }\n\n cacheState.set(snapshot.key, { ...snapshot.entry });\n }\n };\n\n const executeNetwork = async (opts?: { isBackground?: boolean; callCallbacks?: boolean }) => {\n const dedupeMs = cacheOptions?.dedupeMs ?? 0;\n const inflight = inflightState.get(cacheKey);\n const allowDedupe = isCacheEnabled && dedupeMs > 0;\n\n if (allowDedupe && inflight && now - inflight.startedAt < dedupeMs) {\n emitStatus(\"pending\", { isBackground: opts?.isBackground, data: entry?.data });\n const result = await inflight.promise;\n\n if (result.error) {\n emitStatus(\"error\", { error: result.error, isBackground: opts?.isBackground });\n if (opts?.callCallbacks !== false) {\n clientOptions?.onError?.(result.error);\n }\n } else {\n emitStatus(\"success\", { data: result.data, isBackground: opts?.isBackground });\n if (opts?.callCallbacks !== false) {\n clientOptions?.onSuccess?.(result.data as any);\n }\n }\n\n return result;\n }\n\n emitStatus(opts?.isBackground ? \"revalidating\" : \"pending\", {\n isBackground: opts?.isBackground,\n });\n\n const promise = (async () => {\n const maxRetries = Math.max(0, clientOptions?.retry?.count ?? 0);\n let attempt = 0;\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n clientOptions?.onRequest?.({\n requestId,\n method: methodUpper,\n key: cacheKey,\n path,\n input,\n attempt,\n timestamp: Date.now(),\n });\n\n try {\n const { response, data } = await fetchClient(path, {\n ...input,\n method: methodUpper,\n });\n\n const error = response.ok ? null : createResponseError(response, data);\n\n const responseEvent: ResponseEvent<any, Error> = {\n requestId,\n method: methodUpper,\n key: cacheKey,\n path,\n input,\n attempt,\n timestamp: Date.now(),\n response,\n data: response.ok ? data : undefined,\n error: error ?? undefined,\n ok: response.ok,\n status: response.status,\n };\n\n clientOptions?.onResponse?.(response.ok ? data : undefined, error, responseEvent);\n\n if (!error) {\n return { data, error: null, key: cacheKey } as APIResult<any, Error>;\n }\n\n if (attempt >= maxRetries) {\n return { data: undefined, error, key: cacheKey } as APIResult<any, Error>;\n }\n } catch (err: any) {\n const error = normalizeError(err);\n const responseEvent: ResponseEvent<any, Error> = {\n requestId,\n method: methodUpper,\n key: cacheKey,\n path,\n input,\n attempt,\n timestamp: Date.now(),\n error,\n ok: false,\n };\n\n clientOptions?.onResponse?.(undefined, error, responseEvent);\n\n if (attempt >= maxRetries) {\n return { data: undefined, error, key: cacheKey } as APIResult<any, Error>;\n }\n }\n\n attempt += 1;\n const delay =\n typeof clientOptions?.retry?.delay === \"function\"\n ? clientOptions.retry.delay(attempt)\n : (clientOptions?.retry?.delay ?? 0);\n\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n })();\n\n inflightState.set(cacheKey, { promise, startedAt: now });\n\n try {\n const result = await promise;\n\n if (!result.error && isCacheEnabled) {\n const updatedAt = Date.now();\n cacheState.set(cacheKey, {\n data: result.data,\n updatedAt,\n staleAt: updatedAt + staleTime,\n gcAt: getGcAt(updatedAt, cacheOptions?.gcTime),\n invalidatedAt: undefined,\n });\n }\n\n if (result.error) {\n emitStatus(\"error\", { error: result.error, isBackground: opts?.isBackground });\n if (opts?.callCallbacks !== false) {\n clientOptions?.onError?.(result.error);\n }\n } else {\n emitStatus(\"success\", { data: result.data, isBackground: opts?.isBackground });\n if (opts?.callCallbacks !== false) {\n clientOptions?.onSuccess?.(result.data as any);\n }\n }\n\n return result;\n } finally {\n inflightState.delete(cacheKey);\n }\n };\n\n const invalidateTargets = async () => {\n if (!clientOptions?.invalidate) return;\n\n const invalidateOptions = Array.isArray(clientOptions.invalidate)\n ? { targets: clientOptions.invalidate, refetch: false }\n : {\n targets: clientOptions.invalidate.targets,\n refetch: clientOptions.invalidate.refetch ?? false,\n };\n\n for (const target of invalidateOptions.targets) {\n const targetKey = resolveTargetKey(routeMeta, target, undefined, baseURL);\n if (!targetKey) continue;\n\n const existing = cacheState.get(targetKey);\n if (existing) {\n cacheState.set(targetKey, {\n ...existing,\n staleAt: 0,\n invalidatedAt: Date.now(),\n });\n }\n\n emitStatus(\"invalidated\", { key: targetKey });\n\n if (invalidateOptions.refetch && existing && targetKey === cacheKey) {\n void executeNetwork({ isBackground: true, callCallbacks: false });\n }\n }\n };\n\n const optimisticSnapshots = applyOptimisticUpdates();\n\n if (isCacheEnabled) {\n if (entry && !isStale && policy !== \"network-only\") {\n emitStatus(\"success\", { data: entry.data });\n clientOptions?.onSuccess?.(entry.data);\n clientOptions?.onSettled?.(entry.data, null);\n return { data: entry.data, error: null, key: cacheKey };\n }\n\n if (entry && isStale && policy === \"stale-while-revalidate\") {\n emitStatus(\"success\", { data: entry.data });\n clientOptions?.onSuccess?.(entry.data);\n clientOptions?.onSettled?.(entry.data, null);\n\n void executeNetwork({ isBackground: true, callCallbacks: false });\n return { data: entry.data, error: null, key: cacheKey };\n }\n }\n\n const result = await executeNetwork();\n if (result.error) {\n rollbackOptimisticUpdates(optimisticSnapshots);\n }\n await invalidateTargets();\n clientOptions?.onSettled?.(result.data, result.error);\n return result;\n };\n\n // Return nested proxy (starts with empty path, user adds to it)\n return createNestedProxy([], request, routeMeta, baseURL, rootAliases) as APIClient<\n TRouter,\n TIntegrations\n >;\n}\n\n/**\n * Create a nested proxy that builds up the path\n *\n * Flow:\n * 1. api.hello -> Proxy(['hello'])\n * 2. api.hello.get -> Proxy(['hello', 'get'])\n * 3. api.hello.get({ query: {...} })\n * -> fetch('/api/hello', { method: 'GET', ... })\n *\n * For routes with single method:\n * 1. api.hello -> Proxy(['hello'])\n * 2. api.hello({ query: {...} })\n * -> fetch('/api/hello', ...)\n */\nfunction createNestedProxy(\n path: string[],\n client: any,\n routeMeta: WeakMap<AnyRouteRef, RouteMeta>,\n baseURL: string,\n rootAliases?: Record<string, unknown>,\n): any {\n const target = () => {};\n const proxy = new Proxy(target, {\n // When accessing a property (api.hello)\n get(_target, prop: string | symbol) {\n if (prop === FARM_API_ROUTE_REF_SYMBOL) {\n return path.length > 0;\n }\n\n if (path.length === 0 && typeof prop === \"string\" && rootAliases && prop in rootAliases) {\n return rootAliases[prop];\n }\n\n if (typeof prop !== \"string\") {\n return Reflect.get(_target, prop);\n }\n\n // Add prop to path and return new proxy\n return createNestedProxy([...path, prop], client, routeMeta, baseURL, rootAliases);\n },\n\n // When calling as a function\n apply(_target, _thisArg, args) {\n // Check if the last part is an HTTP method\n const lastPart = path[path.length - 1];\n const httpMethods = [\"get\", \"post\", \"put\", \"delete\", \"patch\", \"options\", \"head\"];\n\n if (httpMethods.includes(lastPart)) {\n // Method is explicitly called: api.users.get() or api['auth/login'].post()\n // Remove the method from path and use it as the HTTP method\n const routePath = \"/api/\" + path.slice(0, -1).join(\"/\");\n const method = lastPart.toUpperCase();\n\n // Extract options from arguments\n const [options, clientOptions] = args;\n\n // Call fetch client with explicit method\n return client(routePath, method, options, clientOptions);\n } else {\n // Direct call without method: api.hello()\n // Use the full path and let the server determine the method (usually GET)\n const routePath = \"/api/\" + path.join(\"/\");\n\n // Extract options from arguments\n const [options, clientOptions] = args;\n\n // Call fetch client (default method will be GET)\n return client(routePath, options?.method || \"GET\", options, clientOptions);\n }\n },\n });\n\n routeMeta.set(proxy, { path: [...path], baseURL });\n return proxy;\n}\n\nexport function isAPIRouteRef(value: unknown): value is CallableRouteRef {\n return (\n typeof value === \"function\" &&\n (value as { [FARM_API_ROUTE_REF_SYMBOL]?: unknown })[FARM_API_ROUTE_REF_SYMBOL] === true\n );\n}\n\n/**\n * Server-side API client that calls endpoints directly as functions\n * No HTTP overhead for app endpoints, and registered integration routes can be exposed at\n * api.integrations.* where Farm can dispatch them directly to the integration handler.\n *\n * @example\n * ```typescript\n * import { createServerAPIClient } from 'farm/client';\n * import type { AppIntegrations } from '@/lib/integrations';\n *\n * export const api = createServerAPIClient<{}, AppIntegrations>({});\n *\n * const result = await api.integrations.billing.status();\n * ```\n */\nexport function createServerAPIClient<TEndpoints extends Record<string, any>>(\n endpoints: TEndpoints,\n): TEndpoints;\nexport function createServerAPIClient<TEndpoints extends Record<string, any>>(\n endpoints: TEndpoints,\n options: ServerAPIClientWithoutIntegrationsOptions,\n): TEndpoints;\nexport function createServerAPIClient<\n TEndpoints extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n>(\n endpoints: TEndpoints,\n options?: ServerAPIClientOptions,\n): ServerAPIClient<TEndpoints, TIntegrations>;\nexport function createServerAPIClient<\n TEndpoints extends Record<string, any>,\n TIntegrations extends Record<string, any> = {},\n>(\n endpoints: TEndpoints,\n options: ServerAPIClientOptions | ServerAPIClientWithoutIntegrationsOptions = {},\n): TEndpoints | ServerAPIClient<TEndpoints, TIntegrations> {\n if (\n options.integrations === false ||\n Object.prototype.hasOwnProperty.call(endpoints, \"integrations\")\n ) {\n return endpoints;\n }\n\n Object.defineProperty(endpoints, \"integrations\", {\n get() {\n return integrationsServer<TIntegrations>(\n typeof options.integrations === \"object\" ? options.integrations : {},\n );\n },\n enumerable: false,\n configurable: true,\n });\n\n return endpoints as ServerAPIClient<TEndpoints, TIntegrations>;\n}\n\ntype CacheEntry = FarmClientCacheEntry<any>;\n\ntype InflightEntry = {\n promise: Promise<APIResult<any, Error>>;\n startedAt: number;\n};\n\ntype RouteMeta = {\n path: string[];\n baseURL: string;\n};\n\ntype OptimisticSnapshot = {\n key: string;\n entry?: CacheEntry;\n};\n\nfunction buildCacheKey(method: string, path: string, input: any, baseURL: string): string {\n const keyInput =\n input && typeof input === \"object\" ? { query: input.query, body: input.body } : input;\n const url = new URL(path, baseURL);\n return `${method}:${url.origin}${url.pathname}:${stableStringify(keyInput ?? {})}`;\n}\n\nfunction stableStringify(value: any): string {\n if (value === null || value === undefined) return String(value);\n if (value instanceof Date) return value.toISOString();\n if (typeof value !== \"object\") return JSON.stringify(value);\n if (Array.isArray(value)) {\n return `[${value.map((item) => stableStringify(item)).join(\",\")}]`;\n }\n\n const keys = Object.keys(value).sort();\n const entries = keys.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`);\n return `{${entries.join(\",\")}}`;\n}\n\nfunction getGcAt(now: number, gcTime?: number): number | undefined {\n if (gcTime === undefined) return undefined;\n if (!Number.isFinite(gcTime) || gcTime <= 0) return now;\n return now + gcTime;\n}\n\nfunction getValidCacheEntry(\n cacheState: FarmClientDataCache,\n key: string,\n now: number,\n): CacheEntry | undefined {\n const entry = cacheState.get(key);\n if (!entry) return undefined;\n\n if (entry.gcAt !== undefined && now >= entry.gcAt) {\n cacheState.delete(key);\n return undefined;\n }\n\n return entry;\n}\n\nfunction isEntryStale(entry: CacheEntry, now: number): boolean {\n if (entry.invalidatedAt !== undefined) return true;\n return now >= entry.staleAt;\n}\n\nfunction resolveTargetKey(\n routeMeta: WeakMap<AnyRouteRef, RouteMeta>,\n target: InvalidateTarget | AnyRouteRef,\n input?: unknown,\n baseURL = \"http://localhost:3000\",\n): string | null {\n if (!target) return null;\n\n if (typeof target === \"string\") return target;\n\n if (typeof target === \"function\") {\n const meta = routeMeta.get(target);\n if (!meta) return null;\n\n const { method, routePath } = resolveRouteMeta(meta);\n return buildCacheKey(method, routePath, input ?? {}, meta.baseURL);\n }\n\n if (Array.isArray(target)) {\n const [route, routeInput] = target;\n if (typeof route === \"function\") {\n return resolveTargetKey(routeMeta, route, routeInput, baseURL);\n }\n return normalizeFarmClientCacheKey(target);\n }\n\n if (\"key\" in target) return normalizeFarmClientCacheKey(target.key);\n\n if (\"path\" in target) {\n const method = target.method ?? \"GET\";\n return buildCacheKey(method, target.path, target.input ?? {}, baseURL);\n }\n\n return null;\n}\n\nfunction resolveRouteMeta(meta: RouteMeta): { routePath: string; method: string } {\n const httpMethods = [\"get\", \"post\", \"put\", \"delete\", \"patch\", \"options\", \"head\"];\n const lastPart = meta.path[meta.path.length - 1];\n if (lastPart && httpMethods.includes(lastPart)) {\n return {\n routePath: \"/api/\" + meta.path.slice(0, -1).join(\"/\"),\n method: lastPart.toUpperCase(),\n };\n }\n\n return {\n routePath: \"/api/\" + meta.path.join(\"/\"),\n method: \"GET\",\n };\n}\n\nfunction normalizeError(error: unknown): Error {\n if (error instanceof APIClientError) return error;\n\n const normalized = new APIClientError(\"network_error\", undefined, {\n status: 0,\n message:\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : \"Network request failed\",\n });\n (normalized as Error & { cause?: unknown }).cause = error;\n return normalized;\n}\n\nfunction createResponseError(response: Response, data: any): Error {\n const expected = readEndpointErrorEnvelope(data);\n if (expected) {\n return new APIClientError(expected.code, expected.data, {\n status: response.status,\n message: expected.message,\n response,\n });\n }\n\n return new APIClientError(\"http_error\", data, {\n status: response.status,\n message: `HTTP ${response.status}: ${response.statusText}`,\n response,\n });\n}\n\nfunction readEndpointErrorEnvelope(data: unknown): {\n code: string;\n message: string;\n data: unknown;\n} | null {\n if (!data || typeof data !== \"object\") return null;\n const error = (data as { error?: unknown }).error;\n if (!error || typeof error !== \"object\") return null;\n\n const code = (error as { code?: unknown }).code;\n const message = (error as { message?: unknown }).message;\n if (typeof code !== \"string\" || typeof message !== \"string\") return null;\n\n return {\n code,\n message,\n data: (error as { data?: unknown }).data,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAiDO,IAAM,0BAAN,MAAM,gCAAgD,MAAM;AAAA,EAKjE,YAAY,SAAiB,UAAoB,MAAc;AAC7D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS;AACvB,SAAK,WAAW;AAChB,SAAK,OAAO;AAAA,EACd;AACF;AAZmE;AAA5D,IAAM,yBAAN;AAwMP,IAAM,mCAAmC,uBAAO,IAAI,iCAAiC;AACrF,IAAM,+BAA+B,uBAAO,IAAI,6BAA6B;AAC7E,IAAM,qCAAqC,uBAAO,IAAI,mCAAmC;AAqBzF,SAAS,YAAY,OAA0E;AAC7F,SACE,CAAC,CAAC,SACF,OAAO,UAAU,YAChB,MAA0D,SACzD;AAEN;AAPS;AAuBT,SAAS,oBACP,QAC2B;AAC3B,M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,QAAO;AAEhD,QAAM,OAAQ,MAA6B;AAC3C,QAAM,UAAW,MAAgC;AACjD,MAAI,OAAO,SAAS,YAAY,OAAO,YAAY,SAAU,QAAO;AAEpE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,MAAO,MAA6B;AAAA,EACtC;AACF;AAlBS;","names":["result","createResponseError"]}
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-QKVUNGAH.mjs";
|
|
4
4
|
import {
|
|
5
5
|
normalizeFarmRouteRuntimeConfig
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GQVGIUSN.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createFarmCacheKey,
|
|
9
9
|
createRouteDataCacheTag,
|
|
10
10
|
getFarmDataCache
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-GZWT6VI5.mjs";
|
|
12
12
|
import {
|
|
13
13
|
__name
|
|
14
14
|
} from "./chunk-CGILA3WO.mjs";
|
|
@@ -715,4 +715,4 @@ export {
|
|
|
715
715
|
createLayoutModuleFromProgrammaticLayout,
|
|
716
716
|
scanProgrammaticPagePaths
|
|
717
717
|
};
|
|
718
|
-
//# sourceMappingURL=chunk-
|
|
718
|
+
//# sourceMappingURL=chunk-CSU4KJJF.mjs.map
|
|
@@ -371,7 +371,7 @@ function matchRoutePath(pathname, middlewarePath) {
|
|
|
371
371
|
if (!nestedMatch.matched) {
|
|
372
372
|
return { matched: false };
|
|
373
373
|
}
|
|
374
|
-
const params = { ...nestedMatch.params
|
|
374
|
+
const params = { ...nestedMatch.params };
|
|
375
375
|
delete params.__farmRest;
|
|
376
376
|
return {
|
|
377
377
|
matched: true,
|
|
@@ -619,4 +619,4 @@ export {
|
|
|
619
619
|
createProductionMiddlewareRunner,
|
|
620
620
|
applyProductionMiddlewareHeaders
|
|
621
621
|
};
|
|
622
|
-
//# sourceMappingURL=chunk-
|
|
622
|
+
//# sourceMappingURL=chunk-EJ7T4TPB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware/production-runtime.ts"],"sourcesContent":["import type {\n CookieJar,\n CookieOptions,\n FarmMiddlewareConfig,\n MiddlewareConfig,\n MiddlewareContext,\n MiddlewareFunction,\n MiddlewareMatcher,\n MiddlewareModule,\n MiddlewareResult,\n} from \"./types\";\nimport { emitFarmEvent } from \"../observability\";\nimport { normalizeMiddlewareModule } from \"./module\";\nimport { stripFarmLocaleFromPathname } from \"../i18n/routing\";\nimport type { ResolvedFarmI18nConfig } from \"../i18n/types\";\n\nexport interface ProductionMiddlewareModuleEntry {\n path: string;\n filePath?: string;\n module: MiddlewareModule | Record<string, any>;\n}\n\nexport interface ProductionMiddlewareRunnerOptions {\n config?: FarmMiddlewareConfig | null;\n modules?: ProductionMiddlewareModuleEntry[];\n i18n?: ResolvedFarmI18nConfig;\n}\n\nexport interface ProductionMiddlewareResult {\n request: Request;\n response: Response | null;\n data: Map<string, any>;\n context: Map<string, any>;\n headers: Headers;\n handled: boolean;\n}\n\ninterface ProductionMiddlewareEntry {\n path: string;\n filePath: string;\n handlers: MiddlewareFunction[];\n config?: MiddlewareConfig;\n source: \"config\" | \"file\";\n}\n\ninterface WebMiddlewareContextState {\n ctx: MiddlewareContext;\n getRequest(): Request;\n getResponse(): Response | null;\n}\n\nfunction parseCookies(cookieHeader?: string | null): Record<string, string> {\n if (!cookieHeader) return {};\n\n return cookieHeader.split(\";\").reduce(\n (cookies, cookie) => {\n const [name, ...rest] = cookie.split(\"=\");\n const value = rest.join(\"=\").trim();\n if (name && value) {\n cookies[name.trim()] = decodeURIComponent(value);\n }\n return cookies;\n },\n {} as Record<string, string>,\n );\n}\n\nfunction serializeCookie(name: string, value: string, options: CookieOptions = {}): string {\n let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;\n\n if (options.maxAge) cookie += `; Max-Age=${options.maxAge}`;\n if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;\n cookie += `; Path=${options.path || \"/\"}`;\n if (options.domain) cookie += `; Domain=${options.domain}`;\n if (options.secure) cookie += \"; Secure\";\n if (options.httpOnly) cookie += \"; HttpOnly\";\n if (options.sameSite) {\n cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase()}${options.sameSite.slice(1)}`;\n }\n\n return cookie;\n}\n\nclass WebCookieJar implements CookieJar {\n private cookies: Record<string, string>;\n private setCookies: string[] = [];\n\n constructor(\n request: Request,\n private headers: Map<string, string>,\n ) {\n this.cookies = parseCookies(request.headers.get(\"cookie\"));\n }\n\n get(name: string): string | undefined {\n return this.cookies[name];\n }\n\n set(name: string, value: string, options: CookieOptions = {}): void {\n this.cookies[name] = value;\n const cookieString = serializeCookie(name, value, options);\n this.setCookies.push(cookieString);\n this.headers.set(\"Set-Cookie\", this.setCookies.join(\", \"));\n }\n\n delete(name: string): void {\n delete this.cookies[name];\n const cookieString = serializeCookie(name, \"\", {\n maxAge: 0,\n expires: new Date(0),\n });\n this.setCookies.push(cookieString);\n this.headers.set(\"Set-Cookie\", this.setCookies.join(\", \"));\n }\n\n getAll(): Record<string, string> {\n return { ...this.cookies };\n }\n}\n\nfunction mapToHeaders(map: Map<string, string>): Headers {\n const headers = new Headers();\n for (const [key, value] of map) {\n if (key.toLowerCase() === \"set-cookie\") {\n headers.append(key, value);\n } else {\n headers.set(key, value);\n }\n }\n return headers;\n}\n\nfunction headersToRecord(headers: Map<string, string>): Record<string, string> {\n return Object.fromEntries(headers);\n}\n\nfunction isMiddlewareResponse(value: unknown): value is Response {\n return value instanceof Response;\n}\n\nfunction createResponseShim(headers: Map<string, string>): Record<string, any> {\n return {\n headersSent: false,\n writableEnded: false,\n setHeader(name: string, value: string | string[]) {\n headers.set(name, Array.isArray(value) ? value.join(\", \") : String(value));\n },\n getHeader(name: string) {\n return headers.get(name);\n },\n writeHead(status: number, responseHeaders?: Record<string, string>) {\n this.statusCode = status;\n if (responseHeaders) {\n for (const [key, value] of Object.entries(responseHeaders)) {\n headers.set(key, value);\n }\n }\n this.headersSent = true;\n },\n end() {\n this.writableEnded = true;\n },\n };\n}\n\nfunction withNodeRequestShape(request: Request): Request {\n const requestWithShape = request as Request & {\n socket?: { remoteAddress?: string };\n };\n\n if (!requestWithShape.socket) {\n const forwardedFor = request.headers.get(\"x-forwarded-for\")?.split(\",\")[0]?.trim();\n try {\n requestWithShape.socket = {\n remoteAddress: forwardedFor || \"127.0.0.1\",\n };\n } catch {\n // Some Request implementations may not be extensible.\n }\n }\n\n return requestWithShape;\n}\n\nfunction createHandledResponse(\n body: BodyInit | null,\n init: ResponseInit,\n headers: Map<string, string>,\n): Response {\n const responseHeaders = new Headers(init.headers);\n for (const [key, value] of headers) {\n if (key.toLowerCase() === \"set-cookie\") {\n responseHeaders.append(key, value);\n } else {\n responseHeaders.set(key, value);\n }\n }\n return new Response(body, { ...init, headers: responseHeaders });\n}\n\nfunction createWebMiddlewareContext(\n request: Request,\n parent?: MiddlewareContext[\"parent\"],\n): WebMiddlewareContextState {\n let currentRequest = withNodeRequestShape(request);\n let handledResponse: Response | null = null;\n const url = new URL(currentRequest.url);\n const data = parent?.data ? new Map(parent.data) : new Map<string, any>();\n const locals = parent?.locals ? new Map(parent.locals) : new Map<string, any>();\n const headers = new Map<string, string>();\n\n if (parent?.headers) {\n for (const [key, value] of Object.entries(parent.headers)) {\n headers.set(key, value);\n }\n }\n\n const ctx = {\n request: currentRequest as any,\n response: createResponseShim(headers) as any,\n url,\n pathname: url.pathname,\n searchParams: url.searchParams,\n method: currentRequest.method || \"GET\",\n params: {},\n route: url.pathname,\n parent,\n vite: {\n isDev: false,\n hmr: false,\n },\n data,\n locals,\n headers,\n cookies: new WebCookieJar(currentRequest, headers),\n _handled: false as boolean,\n _redirectUrl: undefined as string | undefined,\n _rewriteUrl: undefined as string | undefined,\n\n redirect(redirectUrl: string, status = 307): void {\n ctx._redirectUrl = redirectUrl;\n ctx._handled = true;\n handledResponse = createHandledResponse(\n `Redirecting to ${redirectUrl}`,\n {\n status,\n headers: {\n Location: redirectUrl,\n \"Content-Type\": \"text/plain\",\n },\n },\n headers,\n );\n },\n\n rewrite(rewriteUrl: string): void {\n ctx._rewriteUrl = rewriteUrl;\n const nextUrl = new URL(rewriteUrl, currentRequest.url);\n currentRequest = withNodeRequestShape(new Request(nextUrl, currentRequest));\n ctx.request = currentRequest as any;\n ctx.url = nextUrl;\n ctx.pathname = nextUrl.pathname;\n ctx.searchParams = nextUrl.searchParams;\n ctx.route = nextUrl.pathname;\n },\n\n json(jsonData: any, status = 200): void {\n ctx._handled = true;\n handledResponse = createHandledResponse(\n JSON.stringify(jsonData),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n headers,\n );\n },\n\n text(content: string, status = 200): void {\n ctx._handled = true;\n handledResponse = createHandledResponse(\n content,\n {\n status,\n headers: {\n \"Content-Type\": \"text/plain\",\n },\n },\n headers,\n );\n },\n\n html(content: string, status = 200): void {\n ctx._handled = true;\n handledResponse = createHandledResponse(\n content,\n {\n status,\n headers: {\n \"Content-Type\": \"text/html\",\n },\n },\n headers,\n );\n },\n } satisfies MiddlewareContext;\n\n return {\n ctx,\n getRequest: () => currentRequest,\n getResponse: () => handledResponse,\n };\n}\n\nfunction toMatcherList(matcher: MiddlewareConfig[\"matcher\"]): MiddlewareMatcher[] {\n if (!matcher) return [];\n return Array.isArray(matcher) ? matcher : [matcher];\n}\n\nfunction escapeRegex(value: string): string {\n return value.replace(/[|\\\\{}()[\\]^$+?.]/g, \"\\\\$&\");\n}\n\nfunction parseColonParam(segment: string): { name: string; modifier?: string } {\n const raw = segment.slice(1);\n const last = raw[raw.length - 1];\n const modifier = last === \"*\" || last === \"+\" || last === \"?\" ? last : undefined;\n return {\n name: modifier ? raw.slice(0, -1) : raw,\n modifier,\n };\n}\n\nfunction compilePathPattern(pattern: string): { regex: RegExp; params: string[] } {\n const params: string[] = [];\n const segments = pattern.split(\"/\").filter(Boolean);\n\n if (segments.length === 0) {\n return { regex: /^\\/$/, params };\n }\n\n const parts = segments.map((segment) => {\n if (segment === \"**\") {\n return \"(?:/.*)?\";\n }\n\n if (segment === \"*\") {\n return \"/[^/]+\";\n }\n\n if (segment.startsWith(\":\")) {\n const { name, modifier } = parseColonParam(segment);\n params.push(name);\n\n if (modifier === \"*\") {\n return \"(?:/(.*))?\";\n }\n if (modifier === \"+\") {\n return \"/(.+)\";\n }\n return \"/([^/]+)\";\n }\n\n if (segment.startsWith(\"[...\") && segment.endsWith(\"]\")) {\n params.push(segment.slice(4, -1));\n return \"(?:/(.*))?\";\n }\n\n if (segment.startsWith(\"[\") && segment.endsWith(\"]\")) {\n params.push(segment.slice(1, -1));\n return \"/([^/]+)\";\n }\n\n return `/${escapeRegex(segment).replace(/\\\\\\*/g, \"[^/]*\")}`;\n });\n\n return {\n regex: new RegExp(`^${parts.join(\"\")}$`),\n params,\n };\n}\n\nfunction matchPattern(\n pattern: string | RegExp,\n pathname: string,\n): { matched: boolean; params?: Record<string, string> } {\n if (pattern instanceof RegExp) {\n pattern.lastIndex = 0;\n const match = pattern.exec(pathname);\n return {\n matched: !!match,\n params: match?.groups ? { ...match.groups } : undefined,\n };\n }\n\n if (pattern === \"*\" || pattern === \"/(.*)\") {\n return { matched: true };\n }\n\n if (pattern.endsWith(\"(.*)\")) {\n const prefix = pattern.slice(0, -4);\n return { matched: pathname === prefix || pathname.startsWith(`${prefix}/`) };\n }\n\n const { regex, params } = compilePathPattern(pattern);\n const match = regex.exec(pathname);\n if (!match) {\n return { matched: false };\n }\n\n const values: Record<string, string> = {};\n params.forEach((param, index) => {\n values[param] = decodeURIComponent(match[index + 1] || \"\");\n });\n\n return {\n matched: true,\n params: Object.keys(values).length > 0 ? values : undefined,\n };\n}\n\nfunction matchesConfig(\n pathname: string,\n config: MiddlewareConfig,\n ctx: MiddlewareContext,\n): { matched: boolean; params?: Record<string, string> } {\n if (config.exclude) {\n for (const pattern of config.exclude) {\n if (matchPattern(pattern, pathname).matched) {\n return { matched: false };\n }\n }\n }\n\n if (config.matcher) {\n for (const matcher of toMatcherList(config.matcher)) {\n if (typeof matcher === \"string\" || matcher instanceof RegExp) {\n const result = matchPattern(matcher, pathname);\n if (result.matched) {\n return result;\n }\n } else if (typeof matcher === \"function\") {\n return { matched: matcher(ctx) };\n }\n }\n return { matched: false };\n }\n\n return { matched: true };\n}\n\nfunction matchRoutePath(\n pathname: string,\n middlewarePath: string,\n): { matched: boolean; params?: Record<string, string> } {\n if (middlewarePath === \"/\") return { matched: true };\n\n const exactMatch = matchPattern(middlewarePath, pathname);\n if (exactMatch.matched) {\n return exactMatch;\n }\n\n const nestedMatch = matchPattern(`${middlewarePath}/:__farmRest*`, pathname);\n if (!nestedMatch.matched) {\n return { matched: false };\n }\n\n const params = { ...nestedMatch.params };\n delete params.__farmRest;\n return {\n matched: true,\n params: Object.keys(params).length > 0 ? params : undefined,\n };\n}\n\nfunction getConfigHandlers(\n entry: MiddlewareConfig & {\n handler?: MiddlewareFunction;\n handlers?: MiddlewareFunction[];\n },\n): MiddlewareFunction[] {\n const handlers: MiddlewareFunction[] = [];\n if (\"handler\" in entry && typeof entry.handler === \"function\") {\n handlers.push(entry.handler);\n }\n if (\"handlers\" in entry && Array.isArray(entry.handlers)) {\n handlers.push(...entry.handlers.filter((handler) => typeof handler === \"function\"));\n }\n return handlers;\n}\n\nfunction toMiddlewareConfig(\n entry: MiddlewareConfig & {\n handler?: MiddlewareFunction;\n handlers?: MiddlewareFunction[];\n },\n): MiddlewareConfig {\n const { matcher, exclude, runtime } = entry;\n return { matcher, exclude, runtime };\n}\n\nfunction normalizeConfigMiddleware(config?: FarmMiddlewareConfig | null): {\n entries: ProductionMiddlewareEntry[];\n globalConfig?: MiddlewareConfig;\n} {\n const entries: ProductionMiddlewareEntry[] = [];\n let globalConfig: MiddlewareConfig | undefined;\n\n if (!config) {\n return { entries, globalConfig };\n }\n\n const configEntries = Array.isArray(config) ? config : [config];\n for (const [index, entry] of configEntries.entries()) {\n const handlers = getConfigHandlers(entry);\n const middlewareConfig = toMiddlewareConfig(entry);\n\n if (handlers.length === 0) {\n globalConfig = middlewareConfig;\n continue;\n }\n\n entries.push({\n path: \"/\",\n filePath: `farm.config.ts#middleware-${index}`,\n handlers,\n config: middlewareConfig,\n source: \"config\",\n });\n }\n\n return { entries, globalConfig };\n}\n\nfunction normalizeFileMiddleware(\n modules: ProductionMiddlewareModuleEntry[] = [],\n): ProductionMiddlewareEntry[] {\n const entries: ProductionMiddlewareEntry[] = [];\n\n for (const moduleEntry of modules) {\n const normalized = normalizeMiddlewareModule(moduleEntry.module, moduleEntry.path);\n if (!normalized) {\n continue;\n }\n\n entries.push({\n path: moduleEntry.path,\n filePath: moduleEntry.filePath || moduleEntry.path,\n handlers: normalized.handlers,\n config: normalized.config,\n source: \"file\",\n });\n }\n\n return entries;\n}\n\nasync function executeHandlers(\n handlers: MiddlewareFunction[],\n ctx: MiddlewareContext,\n): Promise<Response | undefined> {\n let handlerIndex = 0;\n let returnedResponse: Response | undefined;\n const executeNext = async (): Promise<MiddlewareResult> => {\n if (handlerIndex < handlers.length) {\n const handler = handlers[handlerIndex++];\n const result = await handler(ctx, executeNext);\n if (isMiddlewareResponse(result)) {\n returnedResponse = result;\n return result;\n }\n }\n return returnedResponse;\n };\n\n const result = await executeNext();\n return isMiddlewareResponse(result) ? result : returnedResponse;\n}\n\nfunction emptyResult(request: Request): ProductionMiddlewareResult {\n return {\n request,\n response: null,\n data: new Map(),\n context: new Map(),\n headers: new Headers(),\n handled: false,\n };\n}\n\nexport function createProductionMiddlewareRunner(options: ProductionMiddlewareRunnerOptions = {}) {\n const configMiddleware = normalizeConfigMiddleware(options.config);\n const fileMiddleware = normalizeFileMiddleware(options.modules);\n const entries = [...configMiddleware.entries, ...fileMiddleware];\n const globalConfig = configMiddleware.globalConfig;\n\n return async function runProductionMiddleware(\n request: Request,\n ): Promise<ProductionMiddlewareResult> {\n if (!globalConfig && entries.length === 0) {\n return emptyResult(request);\n }\n\n let contextState = createWebMiddlewareContext(request);\n let ctx = contextState.ctx;\n let currentRequest = contextState.getRequest();\n const initialPathname = options.i18n?.enabled\n ? stripFarmLocaleFromPathname(ctx.pathname, options.i18n)\n : ctx.pathname;\n let parentData: MiddlewareContext[\"parent\"] | undefined;\n\n if (globalConfig) {\n const globalMatch = matchesConfig(initialPathname, globalConfig, ctx);\n if (!globalMatch.matched) {\n return emptyResult(request);\n }\n if (globalMatch.params) {\n ctx.params = { ...ctx.params, ...globalMatch.params };\n }\n }\n\n const applicable = entries\n .map((entry) => ({\n entry,\n routeMatch:\n entry.source === \"config\"\n ? { matched: true }\n : matchRoutePath(initialPathname, entry.path),\n }))\n .filter((candidate) => candidate.routeMatch.matched);\n\n if (applicable.length === 0) {\n return {\n request: currentRequest,\n response: null,\n data: new Map(ctx.data),\n context: new Map(ctx.locals),\n headers: mapToHeaders(ctx.headers),\n handled: false,\n };\n }\n\n for (const candidate of applicable) {\n const { entry, routeMatch } = candidate;\n const configMatch = entry.config\n ? matchesConfig(initialPathname, entry.config, ctx)\n : { matched: true };\n if (!configMatch.matched) {\n continue;\n }\n\n if (parentData) {\n contextState = createWebMiddlewareContext(currentRequest, parentData);\n ctx = contextState.ctx;\n }\n\n if (routeMatch.params) {\n ctx.params = { ...ctx.params, ...routeMatch.params };\n }\n if (configMatch.params) {\n ctx.params = { ...ctx.params, ...configMatch.params };\n }\n\n const middlewareStartTime = Date.now();\n const middlewareEvent = {\n route: entry.path,\n pathname: initialPathname,\n name: entry.filePath,\n };\n emitFarmEvent({ type: \"middleware.start\", ...middlewareEvent });\n\n try {\n const returnedResponse = await executeHandlers(entry.handlers, ctx);\n currentRequest = contextState.getRequest();\n\n if (returnedResponse) {\n const response = applyProductionMiddlewareHeaders(\n returnedResponse,\n mapToHeaders(ctx.headers),\n );\n emitFarmEvent({\n type: \"middleware.shortCircuit\",\n ...middlewareEvent,\n status: response.status,\n });\n return {\n request: currentRequest,\n response,\n data: new Map(ctx.data),\n context: new Map(ctx.locals),\n headers: mapToHeaders(ctx.headers),\n handled: true,\n };\n }\n\n if (ctx._handled) {\n const response = contextState.getResponse() || new Response(null);\n emitFarmEvent({\n type: \"middleware.shortCircuit\",\n ...middlewareEvent,\n status: response.status,\n });\n return {\n request: currentRequest,\n response,\n data: new Map(ctx.data),\n context: new Map(ctx.locals),\n headers: mapToHeaders(ctx.headers),\n handled: true,\n };\n }\n\n emitFarmEvent({\n type: \"middleware.complete\",\n ...middlewareEvent,\n durationMs: Date.now() - middlewareStartTime,\n });\n } catch (error) {\n emitFarmEvent({\n type: \"middleware.error\",\n ...middlewareEvent,\n error,\n });\n throw error;\n }\n\n parentData = {\n data: new Map(ctx.data),\n locals: new Map(ctx.locals),\n headers: headersToRecord(ctx.headers),\n };\n }\n\n return {\n request: currentRequest,\n response: null,\n data: new Map(ctx.data),\n context: new Map(ctx.locals),\n headers: mapToHeaders(ctx.headers),\n handled: false,\n };\n };\n}\n\nexport function applyProductionMiddlewareHeaders(\n response: Response,\n middlewareHeaders?: Headers | null,\n): Response {\n if (!middlewareHeaders || Array.from(middlewareHeaders.keys()).length === 0) {\n return response;\n }\n\n const headers = new Headers(response.headers);\n for (const [key, value] of middlewareHeaders) {\n if (key.toLowerCase() === \"set-cookie\") {\n headers.append(key, value);\n } else {\n headers.set(key, value);\n }\n }\n\n return new Response(response.body, {\n status: response.status,\n statusText: response.statusText,\n headers,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAmDA,SAAS,aAAa,cAAsD;AAC1E,MAAI,CAAC,aAAc,QAAO,CAAC;AAE3B,SAAO,aAAa,MAAM,GAAG,EAAE;AAAA,IAC7B,CAAC,SAAS,WAAW;AACnB,YAAM,CAAC,MAAM,GAAG,IAAI,IAAI,OAAO,MAAM,GAAG;AACxC,YAAM,QAAQ,KAAK,KAAK,GAAG,EAAE,KAAK;AAClC,UAAI,QAAQ,OAAO;AACjB,gBAAQ,KAAK,KAAK,CAAC,IAAI,mBAAmB,KAAK;AAAA,MACjD;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AA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AC1B,SAAS,gBAAgB,IAAI,OAAO;AAAA,MACtC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,SAAS;AAAA,MACT,UAAU;AAAA,MACV,MAAM,IAAI,IAAI,IAAI,IAAI;AAAA,MACtB,SAAS,IAAI,IAAI,IAAI,MAAM;AAAA,MAC3B,SAAS,aAAa,IAAI,OAAO;AAAA,MACjC,SAAS;AAAA,IACX;AAAA,EACF,GAjJO;AAkJT;AAxJgB;AA0JT,SAAS,iCACd,UACA,mBACU;AACV,MAAI,CAAC,qBAAqB,MAAM,KAAK,kBAAkB,KAAK,CAAC,EAAE,WAAW,GAAG;AAC3E,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;AAC5C,aAAW,CAAC,KAAK,KAAK,KAAK,mBAAmB;AAC5C,QAAI,IAAI,YAAY,MAAM,cAAc;AACtC,cAAQ,OAAO,KAAK,KAAK;AAAA,IAC3B,OAAO;AACL,cAAQ,IAAI,KAAK,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SAAO,IAAI,SAAS,SAAS,MAAM;AAAA,IACjC,QAAQ,SAAS;AAAA,IACjB,YAAY,SAAS;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAtBgB;","names":["match","result"]}
|
|
@@ -18,7 +18,7 @@ function mergeMetadata(base, next) {
|
|
|
18
18
|
__name(mergeMetadata, "mergeMetadata");
|
|
19
19
|
function addMetadataImageReference(metadata, reference) {
|
|
20
20
|
if (reference.kind === "opengraph") {
|
|
21
|
-
const openGraph = { ...metadata.openGraph
|
|
21
|
+
const openGraph = { ...metadata.openGraph };
|
|
22
22
|
if (!hasMetadataImages(openGraph.images) && !hasMetadataImages(openGraph.image)) {
|
|
23
23
|
openGraph.images = [
|
|
24
24
|
{
|
|
@@ -35,7 +35,7 @@ function addMetadataImageReference(metadata, reference) {
|
|
|
35
35
|
openGraph
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
const twitter = { ...metadata.twitter
|
|
38
|
+
const twitter = { ...metadata.twitter };
|
|
39
39
|
if (!hasMetadataImages(twitter.images)) {
|
|
40
40
|
twitter.images = [reference.href];
|
|
41
41
|
twitter.card = twitter.card || "summary_large_image";
|
|
@@ -296,4 +296,4 @@ export {
|
|
|
296
296
|
addMetadataImageReference,
|
|
297
297
|
renderMetadataHead
|
|
298
298
|
};
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-FRPWCMMG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/metadata.ts"],"sourcesContent":["import type { Metadata } from \"./types\";\n\nexport type MetadataImageKind = \"opengraph\" | \"twitter\";\n\nexport interface FarmMetadataImageReference {\n kind: MetadataImageKind;\n href: string;\n alt?: string;\n width?: number;\n height?: number;\n contentType?: string;\n}\n\nexport interface RenderedMetadataHead {\n title: string;\n tags: string;\n hasFavicon: boolean;\n}\n\ntype MetadataRecord = Metadata & Record<string, any>;\n\nexport function mergeMetadata(\n base: MetadataRecord | undefined,\n next: MetadataRecord | undefined,\n): MetadataRecord {\n if (!base) return next ? { ...next } : {};\n if (!next) return { ...base };\n\n return {\n ...base,\n ...next,\n openGraph: mergeNestedMetadata(base.openGraph, next.openGraph),\n twitter: mergeNestedMetadata(base.twitter, next.twitter),\n alternates: mergeNestedMetadata((base as any).alternates, (next as any).alternates),\n icons: mergeNestedMetadata((base as any).icons, (next as any).icons),\n };\n}\n\nexport function addMetadataImageReference(\n metadata: MetadataRecord,\n reference: FarmMetadataImageReference,\n): MetadataRecord {\n if (reference.kind === \"opengraph\") {\n const openGraph = { ...metadata.openGraph };\n if (!hasMetadataImages(openGraph.images) && !hasMetadataImages((openGraph as any).image)) {\n openGraph.images = [\n {\n url: reference.href,\n width: reference.width,\n height: reference.height,\n alt: reference.alt,\n type: reference.contentType,\n },\n ];\n }\n\n return {\n ...metadata,\n openGraph,\n };\n }\n\n const twitter = { ...metadata.twitter };\n if (!hasMetadataImages(twitter.images)) {\n twitter.images = [reference.href];\n twitter.card = twitter.card || \"summary_large_image\";\n }\n\n return {\n ...metadata,\n twitter,\n };\n}\n\nexport function renderMetadataHead(metadata: MetadataRecord | undefined): RenderedMetadataHead {\n const resolvedMetadata = metadata || {};\n const metadataBase = resolveMetadataBase(resolvedMetadata);\n const title = resolveMetadataTitle(resolvedMetadata.title) || \"Farm.js App\";\n const tags: string[] = [];\n\n appendMetaName(tags, \"description\", resolvedMetadata.description);\n appendMetaName(tags, \"keywords\", normalizeKeywords(resolvedMetadata.keywords));\n appendMetaName(tags, \"author\", (resolvedMetadata as any).author);\n\n if (Array.isArray(resolvedMetadata.authors)) {\n for (const author of resolvedMetadata.authors) {\n appendMetaName(tags, \"author\", author?.name);\n if (author?.url) {\n appendLink(tags, \"author\", resolveMetadataUrl(author.url, metadataBase));\n }\n }\n }\n\n appendMetaName(tags, \"creator\", resolvedMetadata.creator);\n appendMetaName(tags, \"publisher\", resolvedMetadata.publisher);\n appendMetaName(tags, \"robots\", normalizeRobots(resolvedMetadata.robots));\n\n const alternates = (resolvedMetadata as any).alternates;\n if (isRecord(alternates)) {\n appendLink(tags, \"canonical\", resolveMetadataUrl(alternates.canonical, metadataBase));\n\n if (isRecord(alternates.languages)) {\n for (const [language, href] of Object.entries(alternates.languages)) {\n appendLink(tags, \"alternate\", resolveMetadataUrl(href, metadataBase), {\n hreflang: language,\n });\n }\n }\n }\n\n const hasFavicon = appendIcons(tags, (resolvedMetadata as any).icons, metadataBase);\n\n if ((resolvedMetadata as any).manifest) {\n appendLink(\n tags,\n \"manifest\",\n resolveMetadataUrl((resolvedMetadata as any).manifest, metadataBase),\n );\n }\n\n appendOpenGraph(tags, resolvedMetadata.openGraph, metadataBase);\n appendTwitter(tags, resolvedMetadata.twitter, metadataBase);\n\n return {\n title: escapeText(title),\n tags: tags.length > 0 ? `\\n ${tags.join(\"\\n \")}` : \"\",\n hasFavicon,\n };\n}\n\nfunction mergeNestedMetadata(base: unknown, next: unknown): any {\n if (isRecord(base) && isRecord(next)) {\n return {\n ...base,\n ...next,\n };\n }\n\n return next ?? base;\n}\n\nfunction appendOpenGraph(tags: string[], openGraph: Metadata[\"openGraph\"], metadataBase?: string) {\n if (!isRecord(openGraph)) return;\n\n appendMetaProperty(tags, \"og:title\", openGraph.title);\n appendMetaProperty(tags, \"og:description\", openGraph.description);\n appendMetaProperty(tags, \"og:url\", resolveMetadataUrl(openGraph.url, metadataBase));\n appendMetaProperty(tags, \"og:site_name\", openGraph.siteName);\n appendMetaProperty(tags, \"og:type\", openGraph.type);\n appendMetaProperty(tags, \"og:locale\", (openGraph as any).locale);\n\n const images = normalizeMetadataImages(\n openGraph.images ?? (openGraph as any).image,\n metadataBase,\n );\n for (const image of images) {\n appendMetaProperty(tags, \"og:image\", image.url);\n appendMetaProperty(tags, \"og:image:width\", image.width);\n appendMetaProperty(tags, \"og:image:height\", image.height);\n appendMetaProperty(tags, \"og:image:alt\", image.alt);\n appendMetaProperty(tags, \"og:image:type\", image.type);\n }\n}\n\nfunction appendTwitter(tags: string[], twitter: Metadata[\"twitter\"], metadataBase?: string) {\n if (!isRecord(twitter)) return;\n\n appendMetaName(tags, \"twitter:card\", twitter.card);\n appendMetaName(tags, \"twitter:site\", twitter.site);\n appendMetaName(tags, \"twitter:creator\", twitter.creator);\n appendMetaName(tags, \"twitter:title\", twitter.title);\n appendMetaName(tags, \"twitter:description\", twitter.description);\n\n for (const image of normalizeMetadataImages(twitter.images, metadataBase)) {\n appendMetaName(tags, \"twitter:image\", image.url);\n appendMetaName(tags, \"twitter:image:alt\", image.alt);\n }\n}\n\nfunction appendIcons(tags: string[], icons: unknown, metadataBase?: string): boolean {\n if (!icons) return false;\n\n if (typeof icons === \"string\") {\n const initialTagCount = tags.length;\n appendLink(tags, \"icon\", resolveMetadataUrl(icons, metadataBase));\n return tags.length > initialTagCount;\n }\n\n if (!isRecord(icons)) return false;\n\n const initialTagCount = tags.length;\n appendIconList(tags, \"icon\", icons.icon, metadataBase);\n appendIconList(tags, \"shortcut icon\", icons.shortcut, metadataBase);\n const hasFavicon = tags.length > initialTagCount;\n appendIconList(tags, \"apple-touch-icon\", icons.apple, metadataBase);\n return hasFavicon;\n}\n\nfunction appendIconList(tags: string[], rel: string, value: unknown, metadataBase?: string) {\n for (const icon of normalizeArray(value)) {\n if (typeof icon === \"string\") {\n appendLink(tags, rel, resolveMetadataUrl(icon, metadataBase));\n continue;\n }\n\n if (!isRecord(icon)) continue;\n appendLink(tags, rel, resolveMetadataUrl(icon.url, metadataBase), {\n sizes: icon.sizes,\n type: icon.type,\n });\n }\n}\n\nfunction appendMetaName(tags: string[], name: string, content: unknown) {\n const normalized = normalizeContent(content);\n if (!normalized) return;\n tags.push(`<meta name=\"${escapeAttribute(name)}\" content=\"${escapeAttribute(normalized)}\">`);\n}\n\nfunction appendMetaProperty(tags: string[], property: string, content: unknown) {\n const normalized = normalizeContent(content);\n if (!normalized) return;\n tags.push(\n `<meta property=\"${escapeAttribute(property)}\" content=\"${escapeAttribute(normalized)}\">`,\n );\n}\n\nfunction appendLink(\n tags: string[],\n rel: string,\n href: unknown,\n attrs: Record<string, unknown> = {},\n) {\n const normalizedHref = normalizeContent(href);\n if (!normalizedHref) return;\n\n const attrText = Object.entries(attrs)\n .map(([key, value]) => {\n const normalized = normalizeContent(value);\n return normalized ? ` ${key}=\"${escapeAttribute(normalized)}\"` : \"\";\n })\n .join(\"\");\n\n tags.push(\n `<link rel=\"${escapeAttribute(rel)}\" href=\"${escapeAttribute(normalizedHref)}\"${attrText}>`,\n );\n}\n\nfunction normalizeMetadataImages(\n value: unknown,\n metadataBase?: string,\n): Array<{\n url: string;\n width?: number;\n height?: number;\n alt?: string;\n type?: string;\n}> {\n return normalizeArray(value)\n .map((item) => {\n if (typeof item === \"string\") {\n return { url: resolveMetadataUrl(item, metadataBase) || item };\n }\n\n if (!isRecord(item)) return null;\n const rawUrl = item.url || item.src;\n const url = resolveMetadataUrl(rawUrl, metadataBase);\n if (!url) return null;\n\n return {\n url,\n width: normalizeNumber(item.width),\n height: normalizeNumber(item.height),\n alt: typeof item.alt === \"string\" ? item.alt : undefined,\n type: typeof item.type === \"string\" ? item.type : undefined,\n };\n })\n .filter((item): item is NonNullable<typeof item> => item !== null);\n}\n\nfunction normalizeArray(value: unknown): unknown[] {\n if (value == null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\nfunction hasMetadataImages(value: unknown): boolean {\n return normalizeMetadataImages(value).length > 0;\n}\n\nfunction resolveMetadataTitle(title: Metadata[\"title\"]): string | undefined {\n if (typeof title === \"string\") return title;\n if (isRecord(title)) {\n return normalizeContent(title.default);\n }\n return undefined;\n}\n\nfunction normalizeKeywords(keywords: Metadata[\"keywords\"]): string | undefined {\n if (Array.isArray(keywords)) return keywords.filter(Boolean).join(\", \");\n return keywords;\n}\n\nfunction normalizeRobots(robots: Metadata[\"robots\"]): string | undefined {\n if (typeof robots === \"string\") return robots;\n if (!isRecord(robots)) return undefined;\n\n const values: string[] = [];\n if (typeof robots.index === \"boolean\") values.push(robots.index ? \"index\" : \"noindex\");\n if (typeof robots.follow === \"boolean\") values.push(robots.follow ? \"follow\" : \"nofollow\");\n return values.join(\", \") || undefined;\n}\n\nfunction resolveMetadataBase(metadata: MetadataRecord): string | undefined {\n const base = metadata.metadataBase;\n if (!base) return undefined;\n return String(base);\n}\n\nfunction resolveMetadataUrl(value: unknown, metadataBase?: string): string | undefined {\n const normalized = normalizeContent(value);\n if (!normalized) return undefined;\n if (!metadataBase) return normalized;\n\n try {\n return new URL(normalized, metadataBase).toString();\n } catch {\n return normalized;\n }\n}\n\nfunction normalizeNumber(value: unknown): number | undefined {\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n if (typeof value === \"string\") {\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n }\n return undefined;\n}\n\nfunction normalizeContent(value: unknown): string | undefined {\n if (value == null) return undefined;\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") return String(value);\n if (value instanceof URL) return value.toString();\n return undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, any> {\n return !!value && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \""\");\n}\n"],"mappings":";;;;;AAqBO,SAAS,cACd,MACA,MACgB;AAChB,MAAI,CAAC,KAAM,QAAO,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;AACxC,MAAI,CAAC,KAAM,QAAO,EAAE,GAAG,KAAK;AAE5B,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,WAAW,oBAAoB,KAAK,WAAW,KAAK,SAAS;AAAA,IAC7D,SAAS,oBAAoB,KAAK,SAAS,KAAK,OAAO;AAAA,IACvD,YAAY,oBAAqB,KAAa,YAAa,KAAa,UAAU;AAAA,IAClF,OAAO,oBAAqB,KAAa,OAAQ,KAAa,KAAK;AAAA,EACrE;AACF;AAfgB;AAiBT,SAAS,0BACd,UACA,WACgB;AAChB,MAAI,UAAU,SAAS,aAAa;AAClC,UAAM,YAAY,EAAE,GAAG,SAAS,UAAU;AAC1C,QAAI,CAAC,kBAAkB,UAAU,MAAM,KAAK,CAAC,kBAAmB,UAAkB,KAAK,GAAG;AACxF,gBAAU,SAAS;AAAA,QACjB;AAAA,UACE,KAAK,UAAU;AAAA,UACf,OAAO,UAAU;AAAA,UACjB,QAAQ,UAAU;AAAA,UAClB,KAAK,UAAU;AAAA,UACf,MAAM,UAAU;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,EAAE,GAAG,SAAS,QAAQ;AACtC,MAAI,CAAC,kBAAkB,QAAQ,MAAM,GAAG;AACtC,YAAQ,SAAS,CAAC,UAAU,IAAI;AAChC,YA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