@apifuse/provider-sdk 2.2.0-beta.11 → 2.2.0-beta.13
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/AUTHORING.md +238 -0
- package/CHANGELOG.md +14 -0
- package/README.md +44 -2
- package/bin/apifuse-pack-smoke.ts +14 -0
- package/bin/apifuse-pack-types.ts +40 -1
- package/bin/apifuse-record.ts +622 -57
- package/bin/apifuse-submit-check.ts +43 -10
- package/dist/config/loader.d.ts +9 -1
- package/dist/config/loader.js +9 -0
- package/dist/define.d.ts +2 -1
- package/dist/define.js +61 -3
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +15 -0
- package/dist/fixture-sanitization.d.ts +26 -0
- package/dist/fixture-sanitization.js +216 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +1 -0
- package/dist/runtime/http.js +86 -32
- package/dist/runtime/instrumentation.js +295 -9
- package/dist/runtime/native-network.d.ts +53 -0
- package/dist/runtime/native-network.js +477 -0
- package/dist/runtime/proxy-nodemaven.d.ts +14 -0
- package/dist/runtime/proxy-nodemaven.js +20 -2
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/stealth.d.ts +3 -1
- package/dist/runtime/stealth.js +352 -86
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/self-test-input-tokens.d.ts +2 -1
- package/dist/server/self-test-input-tokens.js +18 -14
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +451 -19
- package/dist/types.d.ts +201 -7
- package/package.json +3 -1
- package/src/config/loader.ts +22 -1
- package/src/define.ts +81 -3
- package/src/errors.ts +15 -0
- package/src/fixture-sanitization.ts +247 -0
- package/src/index.ts +45 -1
- package/src/provider.ts +37 -0
- package/src/runtime/http.ts +144 -38
- package/src/runtime/instrumentation.ts +424 -8
- package/src/runtime/native-network.ts +600 -0
- package/src/runtime/proxy-nodemaven.ts +37 -2
- package/src/runtime/request-options.ts +680 -1
- package/src/runtime/stealth.ts +420 -88
- package/src/server/index.ts +4 -1
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/stream-evidence.ts +988 -0
- package/src/testing/index.ts +9 -1
- package/src/testing/run.ts +608 -12
- package/src/types.ts +235 -7
package/src/server/index.ts
CHANGED
|
@@ -35,7 +35,10 @@ export {
|
|
|
35
35
|
SelfTestRequestSchema,
|
|
36
36
|
type SelfTestResponse,
|
|
37
37
|
} from "./self-test.js";
|
|
38
|
-
export {
|
|
38
|
+
export {
|
|
39
|
+
type InputDateTokenCalendar,
|
|
40
|
+
resolveHealthCheckInputDateTokens,
|
|
41
|
+
} from "./self-test-input-tokens.js";
|
|
39
42
|
export {
|
|
40
43
|
collectSelfTestSensitiveValues,
|
|
41
44
|
redactSelfTestText,
|
|
@@ -1,46 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Relative
|
|
3
|
-
*
|
|
4
|
-
* so
|
|
2
|
+
* Relative date-token resolution for health-check case inputs and fixture
|
|
3
|
+
* requests. The calendar defaults to KST; callers that need UTC must opt in
|
|
4
|
+
* explicitly so UTC and KST do not silently disagree from 15:00–23:59 UTC.
|
|
5
5
|
*
|
|
6
|
-
* Supported token: `+<days>d` or `+<days>d:YYYYMMDD` (1..365 days ahead
|
|
6
|
+
* Supported token: `+<days>d` or `+<days>d:YYYYMMDD` (1..365 days ahead).
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const RELATIVE_DATE_TOKEN = /^\+(\d{1,3})d(?::(YYYYMMDD))?$/i;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
export type InputDateTokenCalendar = "KST" | "UTC";
|
|
11
|
+
|
|
12
|
+
function dateFromDaysAhead(
|
|
11
13
|
daysAhead: number,
|
|
12
14
|
now = new Date(),
|
|
13
15
|
format: "YYYY-MM-DD" | "YYYYMMDD" = "YYYY-MM-DD",
|
|
16
|
+
calendar: InputDateTokenCalendar = "KST",
|
|
14
17
|
): string {
|
|
15
|
-
const
|
|
18
|
+
const calendarNow = new Date(now.getTime() + (calendar === "KST" ? 9 * 60 * 60 * 1000 : 0));
|
|
16
19
|
const date = new Date(
|
|
17
|
-
Date.UTC(
|
|
20
|
+
Date.UTC(
|
|
21
|
+
calendarNow.getUTCFullYear(),
|
|
22
|
+
calendarNow.getUTCMonth(),
|
|
23
|
+
calendarNow.getUTCDate() + daysAhead,
|
|
24
|
+
),
|
|
18
25
|
);
|
|
19
26
|
const isoDate = date.toISOString().slice(0, 10);
|
|
20
27
|
return format === "YYYYMMDD" ? isoDate.replace(/-/g, "") : isoDate;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
export function resolveHealthCheckInputDateTokens(
|
|
30
|
+
export function resolveHealthCheckInputDateTokens(
|
|
31
|
+
value: unknown,
|
|
32
|
+
now = new Date(),
|
|
33
|
+
calendar: InputDateTokenCalendar = "KST",
|
|
34
|
+
): unknown {
|
|
24
35
|
if (typeof value === "string") {
|
|
25
|
-
const relative = value.match(
|
|
36
|
+
const relative = value.match(RELATIVE_DATE_TOKEN);
|
|
26
37
|
if (!relative) return value;
|
|
27
38
|
const daysAhead = Number(relative[1]);
|
|
28
39
|
if (!Number.isInteger(daysAhead) || daysAhead < 1 || daysAhead > 365) {
|
|
29
40
|
return value;
|
|
30
41
|
}
|
|
31
42
|
const format = relative[2]?.toUpperCase() === "YYYYMMDD" ? "YYYYMMDD" : "YYYY-MM-DD";
|
|
32
|
-
return
|
|
43
|
+
return dateFromDaysAhead(daysAhead, now, format, calendar);
|
|
33
44
|
}
|
|
34
45
|
if (Array.isArray(value)) {
|
|
35
|
-
|
|
46
|
+
const resolved = value.map((entry) => resolveHealthCheckInputDateTokens(entry, now, calendar));
|
|
47
|
+
return resolved.some((entry, index) => entry !== value[index]) ? resolved : value;
|
|
36
48
|
}
|
|
37
49
|
if (value && typeof value === "object") {
|
|
38
|
-
|
|
50
|
+
const resolved = Object.fromEntries(
|
|
39
51
|
Object.entries(value).map(([key, entry]) => [
|
|
40
52
|
key,
|
|
41
|
-
resolveHealthCheckInputDateTokens(entry, now),
|
|
53
|
+
resolveHealthCheckInputDateTokens(entry, now, calendar),
|
|
42
54
|
]),
|
|
43
55
|
);
|
|
56
|
+
return Object.entries(resolved).some(([key, entry]) => entry !== Reflect.get(value, key))
|
|
57
|
+
? resolved
|
|
58
|
+
: value;
|
|
44
59
|
}
|
|
45
60
|
return value;
|
|
46
61
|
}
|