@apifn/core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +67 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +67 -20
- package/dist/index.js.map +1 -1
- package/package.json +4 -8
package/dist/index.d.cts
CHANGED
|
@@ -415,6 +415,8 @@ interface MockServerOptions {
|
|
|
415
415
|
validateRequests?: boolean;
|
|
416
416
|
/** Delay responses by ms (simulates latency) */
|
|
417
417
|
delay?: number;
|
|
418
|
+
/** Maximum accepted request body size in bytes (default: 10 MiB) */
|
|
419
|
+
maxRequestBodyBytes?: number;
|
|
418
420
|
/** CORS configuration */
|
|
419
421
|
cors?: boolean | CorsOptions;
|
|
420
422
|
}
|
|
@@ -539,6 +541,8 @@ interface WatchFnMiddlewareOptions {
|
|
|
539
541
|
fireAndForget?: boolean;
|
|
540
542
|
/** Suppress console warnings on errors (default: false) */
|
|
541
543
|
silent?: boolean;
|
|
544
|
+
/** Event POST timeout in ms (default: 2000) */
|
|
545
|
+
timeoutMs?: number;
|
|
542
546
|
}
|
|
543
547
|
/**
|
|
544
548
|
* Fetch endpoint metrics from a watchfn query API endpoint.
|
package/dist/index.d.ts
CHANGED
|
@@ -415,6 +415,8 @@ interface MockServerOptions {
|
|
|
415
415
|
validateRequests?: boolean;
|
|
416
416
|
/** Delay responses by ms (simulates latency) */
|
|
417
417
|
delay?: number;
|
|
418
|
+
/** Maximum accepted request body size in bytes (default: 10 MiB) */
|
|
419
|
+
maxRequestBodyBytes?: number;
|
|
418
420
|
/** CORS configuration */
|
|
419
421
|
cors?: boolean | CorsOptions;
|
|
420
422
|
}
|
|
@@ -539,6 +541,8 @@ interface WatchFnMiddlewareOptions {
|
|
|
539
541
|
fireAndForget?: boolean;
|
|
540
542
|
/** Suppress console warnings on errors (default: false) */
|
|
541
543
|
silent?: boolean;
|
|
544
|
+
/** Event POST timeout in ms (default: 2000) */
|
|
545
|
+
timeoutMs?: number;
|
|
542
546
|
}
|
|
543
547
|
/**
|
|
544
548
|
* Fetch endpoint metrics from a watchfn query API endpoint.
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var KNOWN_DESCRIPTOR_KEYS = [
|
|
|
14
14
|
"headers",
|
|
15
15
|
"security"
|
|
16
16
|
];
|
|
17
|
-
var PATH_PARAM_PATTERN = /:([A-Za-z0-9_]+)/g;
|
|
18
17
|
function isObject(value) {
|
|
19
18
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
19
|
}
|
|
@@ -47,10 +46,29 @@ function withBasePath(path2, basePath) {
|
|
|
47
46
|
}
|
|
48
47
|
function toOpenApiPath(path2) {
|
|
49
48
|
const params = [];
|
|
50
|
-
|
|
49
|
+
let openApiPath = "";
|
|
50
|
+
let index = 0;
|
|
51
|
+
while (index < path2.length) {
|
|
52
|
+
const char = path2[index];
|
|
53
|
+
if (char !== ":") {
|
|
54
|
+
openApiPath += char;
|
|
55
|
+
index += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
let end = index + 1;
|
|
59
|
+
while (end < path2.length && /[A-Za-z0-9_]/.test(path2[end])) {
|
|
60
|
+
end += 1;
|
|
61
|
+
}
|
|
62
|
+
if (end === index + 1) {
|
|
63
|
+
openApiPath += char;
|
|
64
|
+
index += 1;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const param = path2.slice(index + 1, end);
|
|
51
68
|
params.push(param);
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
openApiPath += `{${param}}`;
|
|
70
|
+
index = end;
|
|
71
|
+
}
|
|
54
72
|
return { path: openApiPath, pathParams: params };
|
|
55
73
|
}
|
|
56
74
|
function pathParamsToDescriptors(pathParams) {
|
|
@@ -597,8 +615,6 @@ function upconvertNode(value) {
|
|
|
597
615
|
const merged = new Set(currentType);
|
|
598
616
|
merged.add("null");
|
|
599
617
|
output.type = Array.from(merged);
|
|
600
|
-
} else {
|
|
601
|
-
output.type = ["null"];
|
|
602
618
|
}
|
|
603
619
|
}
|
|
604
620
|
return output;
|
|
@@ -690,8 +706,19 @@ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch",
|
|
|
690
706
|
function isRef(obj) {
|
|
691
707
|
return typeof obj === "object" && obj !== null && "$ref" in obj;
|
|
692
708
|
}
|
|
693
|
-
function
|
|
694
|
-
|
|
709
|
+
function emitUnresolvedRef(opPath, location, ref, emit) {
|
|
710
|
+
emit({
|
|
711
|
+
type: "modified",
|
|
712
|
+
breaking: true,
|
|
713
|
+
path: `${opPath}.${location}`,
|
|
714
|
+
description: `Parameter reference '${ref}' in ${opPath} could not be resolved; diff coverage is incomplete`
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
function resolveParam(p, opPath, location, emit) {
|
|
718
|
+
if (isRef(p)) {
|
|
719
|
+
emitUnresolvedRef(opPath, location, p.$ref, emit);
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
695
722
|
if (typeof p === "object" && p !== null && "name" in p && "in" in p) {
|
|
696
723
|
return p;
|
|
697
724
|
}
|
|
@@ -715,8 +742,8 @@ function isTypeNarrowing(before, after) {
|
|
|
715
742
|
return false;
|
|
716
743
|
}
|
|
717
744
|
function diffParameters(opPath, before, after, emit) {
|
|
718
|
-
const beforeParams = (before.parameters ?? []).map(resolveParam).filter((p) => p !== null);
|
|
719
|
-
const afterParams = (after.parameters ?? []).map(resolveParam).filter((p) => p !== null);
|
|
745
|
+
const beforeParams = (before.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
|
|
746
|
+
const afterParams = (after.parameters ?? []).map((param, index) => resolveParam(param, opPath, `parameters[${index}]`, emit)).filter((p) => p !== null);
|
|
720
747
|
const beforeMap = /* @__PURE__ */ new Map();
|
|
721
748
|
for (const p of beforeParams) {
|
|
722
749
|
beforeMap.set(`${p.in}:${p.name}`, p);
|
|
@@ -796,6 +823,16 @@ function diffRequestBody(opPath, before, after, emit) {
|
|
|
796
823
|
return;
|
|
797
824
|
}
|
|
798
825
|
if (!beforeBody || !afterBody) return;
|
|
826
|
+
if (!beforeBody.required && afterBody.required) {
|
|
827
|
+
emit({
|
|
828
|
+
type: "modified",
|
|
829
|
+
breaking: true,
|
|
830
|
+
path: `${opPath}.requestBody.required`,
|
|
831
|
+
description: `Request body became required in ${opPath}`,
|
|
832
|
+
before: false,
|
|
833
|
+
after: true
|
|
834
|
+
});
|
|
835
|
+
}
|
|
799
836
|
const beforeSchema = beforeBody.content?.["application/json"]?.schema ?? null;
|
|
800
837
|
const afterSchema = afterBody.content?.["application/json"]?.schema ?? null;
|
|
801
838
|
if (!beforeSchema || !afterSchema) return;
|
|
@@ -817,12 +854,12 @@ function diffObjectSchemaRequiredFields(opPath, schemaPath, before, after, emit)
|
|
|
817
854
|
const afterProps = after.properties ?? {};
|
|
818
855
|
const beforeProps = before.properties ?? {};
|
|
819
856
|
for (const field of afterRequired) {
|
|
820
|
-
if (!beforeRequired.has(field)
|
|
857
|
+
if (!beforeRequired.has(field)) {
|
|
821
858
|
emit({
|
|
822
859
|
type: "modified",
|
|
823
860
|
breaking: true,
|
|
824
861
|
path: `${opPath}.${schemaPath}.required`,
|
|
825
|
-
description: `New required field '${field}' added to request body in ${opPath}`
|
|
862
|
+
description: beforeProps[field] ? `Existing request body field '${field}' became required in ${opPath}` : `New required field '${field}' added to request body in ${opPath}`
|
|
826
863
|
});
|
|
827
864
|
}
|
|
828
865
|
}
|
|
@@ -920,11 +957,12 @@ function diffSecurity(opPath, before, after, emit) {
|
|
|
920
957
|
}
|
|
921
958
|
for (const key of beforeKeys) {
|
|
922
959
|
if (!afterKeys.has(key)) {
|
|
960
|
+
const removedAlternative = afterSec.length > 0;
|
|
923
961
|
emit({
|
|
924
962
|
type: "removed",
|
|
925
|
-
breaking:
|
|
963
|
+
breaking: removedAlternative,
|
|
926
964
|
path: `${opPath}.security`,
|
|
927
|
-
description: `Security requirement removed from ${opPath}`,
|
|
965
|
+
description: removedAlternative ? `Security requirement alternative removed from ${opPath} \u2014 breaking` : `Security requirement removed from ${opPath}`,
|
|
928
966
|
before: beforeSec,
|
|
929
967
|
after: afterSec
|
|
930
968
|
});
|
|
@@ -1200,7 +1238,8 @@ function apifnWatchMiddleware(options) {
|
|
|
1200
1238
|
baseUrl,
|
|
1201
1239
|
apiKey,
|
|
1202
1240
|
fireAndForget = true,
|
|
1203
|
-
silent = false
|
|
1241
|
+
silent = false,
|
|
1242
|
+
timeoutMs = 2e3
|
|
1204
1243
|
} = options;
|
|
1205
1244
|
const eventUrl = `${baseUrl.replace(/\/$/, "")}/api/events`;
|
|
1206
1245
|
const headers = {
|
|
@@ -1210,11 +1249,19 @@ function apifnWatchMiddleware(options) {
|
|
|
1210
1249
|
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
1211
1250
|
async function sendEvent(event) {
|
|
1212
1251
|
try {
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1252
|
+
const controller = new AbortController();
|
|
1253
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1254
|
+
let res;
|
|
1255
|
+
try {
|
|
1256
|
+
res = await fetch(eventUrl, {
|
|
1257
|
+
method: "POST",
|
|
1258
|
+
headers,
|
|
1259
|
+
body: JSON.stringify(event),
|
|
1260
|
+
signal: controller.signal
|
|
1261
|
+
});
|
|
1262
|
+
} finally {
|
|
1263
|
+
clearTimeout(timer);
|
|
1264
|
+
}
|
|
1218
1265
|
if (!res.ok && !silent) {
|
|
1219
1266
|
console.warn(`[apifn/watchfn] Event POST returned HTTP ${res.status}`);
|
|
1220
1267
|
}
|