Skip to content

Commit 491cff9

Browse files
Merge pull request #26 from openfetch-js/dev
Enhance supply chain metadata and improve secure defaults
2 parents 6244c30 + 358f7f6 commit 491cff9

52 files changed

Lines changed: 1233 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dist/domain/error.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ export declare class OpenFetchError<T = unknown> extends Error {
5555
toJSON(): OpenFetchErrorShape;
5656
}
5757
export declare function isOpenFetchError(err: unknown): err is OpenFetchError;
58+
/** `OpenFetchError` with `code === "ERR_BAD_RESPONSE"` and a populated `response`. */
59+
export declare function isHTTPError(err: unknown): err is OpenFetchError;
60+
/** Per-attempt fetch timeout (`ERR_TIMEOUT`) or retry budget exceeded (`ERR_RETRY_TIMEOUT`). */
61+
export declare function isTimeoutError(err: unknown): err is OpenFetchError;
5862
//# sourceMappingURL=error.d.ts.map

dist/domain/error.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/domain/error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,14 @@ export class OpenFetchError extends Error {
6565
export function isOpenFetchError(err) {
6666
return err instanceof OpenFetchError;
6767
}
68+
/** `OpenFetchError` with `code === "ERR_BAD_RESPONSE"` and a populated `response`. */
69+
export function isHTTPError(err) {
70+
return (err instanceof OpenFetchError &&
71+
err.code === "ERR_BAD_RESPONSE" &&
72+
err.response != null);
73+
}
74+
/** Per-attempt fetch timeout (`ERR_TIMEOUT`) or retry budget exceeded (`ERR_RETRY_TIMEOUT`). */
75+
export function isTimeoutError(err) {
76+
return (err instanceof OpenFetchError &&
77+
(err.code === "ERR_TIMEOUT" || err.code === "ERR_RETRY_TIMEOUT"));
78+
}

dist/domain/forceRetry.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Throw from `retry.onAfterResponse` / hooks `onAfterResponse` (when wired through retry)
3+
* to force another fetch attempt (same semantics as Ky’s `ForceRetryError`).
4+
*/
5+
export declare class OpenFetchForceRetry extends Error {
6+
name: "OpenFetchForceRetry";
7+
constructor(message?: string);
8+
}
9+
export declare function isOpenFetchForceRetry(err: unknown): err is OpenFetchForceRetry;
10+
//# sourceMappingURL=forceRetry.d.ts.map

dist/domain/forceRetry.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/domain/forceRetry.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Throw from `retry.onAfterResponse` / hooks `onAfterResponse` (when wired through retry)
3+
* to force another fetch attempt (same semantics as Ky’s `ForceRetryError`).
4+
*/
5+
export class OpenFetchForceRetry extends Error {
6+
name = "OpenFetchForceRetry";
7+
constructor(message = "Force retry") {
8+
super(message);
9+
}
10+
}
11+
export function isOpenFetchForceRetry(err) {
12+
return err instanceof OpenFetchForceRetry;
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { StandardSchemaV1Issue } from "./standardSchema.js";
2+
/**
3+
* Thrown when {@link OpenFetchConfig.jsonSchema} / fluent `.json(schema)` validation fails.
4+
* Does not extend {@link OpenFetchError} — the HTTP round-trip succeeded; the schema rejected the payload.
5+
*/
6+
export declare class SchemaValidationError extends Error {
7+
name: "SchemaValidationError";
8+
readonly issues: readonly StandardSchemaV1Issue[];
9+
constructor(issues: readonly StandardSchemaV1Issue[]);
10+
}
11+
export declare function isSchemaValidationError(err: unknown): err is SchemaValidationError;
12+
//# sourceMappingURL=schemaValidationError.d.ts.map

dist/domain/schemaValidationError.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Thrown when {@link OpenFetchConfig.jsonSchema} / fluent `.json(schema)` validation fails.
3+
* Does not extend {@link OpenFetchError} — the HTTP round-trip succeeded; the schema rejected the payload.
4+
*/
5+
export class SchemaValidationError extends Error {
6+
name = "SchemaValidationError";
7+
issues;
8+
constructor(issues) {
9+
super("Response schema validation failed");
10+
this.issues = issues;
11+
}
12+
}
13+
export function isSchemaValidationError(err) {
14+
return err instanceof SchemaValidationError;
15+
}

dist/domain/standardSchema.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** [Standard Schema](https://github.com/standard-schema/standard-schema) v1 surface (types only). */
2+
export type StandardSchemaV1Issue = {
3+
readonly message: string;
4+
readonly path?: ReadonlyArray<PropertyKey | {
5+
readonly key: PropertyKey;
6+
}> | undefined;
7+
};
8+
export type StandardSchemaV1SuccessResult<OutputType> = {
9+
readonly value: OutputType;
10+
readonly issues?: undefined;
11+
};
12+
export type StandardSchemaV1FailureResult = {
13+
readonly issues: readonly StandardSchemaV1Issue[];
14+
readonly value?: undefined;
15+
};
16+
export type StandardSchemaV1Result<OutputType> = StandardSchemaV1SuccessResult<OutputType> | StandardSchemaV1FailureResult;
17+
export type StandardSchemaV1Types<InputType, OutputType> = {
18+
readonly input: InputType;
19+
readonly output: OutputType;
20+
};
21+
export type StandardSchemaV1Options = {
22+
readonly libraryOptions?: Readonly<Record<string, unknown>> | undefined;
23+
};
24+
export type StandardSchemaV1<InputType = unknown, OutputType = InputType> = {
25+
readonly "~standard": {
26+
readonly version: 1;
27+
readonly vendor: string;
28+
readonly validate: (value: unknown, options?: StandardSchemaV1Options) => StandardSchemaV1Result<OutputType> | Promise<StandardSchemaV1Result<OutputType>>;
29+
readonly types?: StandardSchemaV1Types<InputType, OutputType> | undefined;
30+
};
31+
};
32+
export type StandardSchemaV1InferOutput<Schema extends StandardSchemaV1> = Schema["~standard"] extends {
33+
readonly types: StandardSchemaV1Types<unknown, infer OutputType>;
34+
} ? OutputType : Extract<Awaited<ReturnType<Schema["~standard"]["validate"]>>, StandardSchemaV1SuccessResult<unknown>> extends StandardSchemaV1SuccessResult<infer OutputType> ? OutputType : unknown;
35+
//# sourceMappingURL=standardSchema.d.ts.map

0 commit comments

Comments
 (0)