zlient 2.1.11 → 3.0.0

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.
@@ -1,9 +1,8 @@
1
- import { z } from 'zod';
2
1
  import { HttpClient } from '../http/http-client';
3
- import { HTTPMethod } from '../types';
4
- export type EndpointConfig<ResSchema extends z.ZodType | Record<number, z.ZodType>, ReqSchema extends z.ZodType | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined, PathSchema extends z.ZodType | undefined = undefined, MustHeaderKeys extends readonly string[] = readonly []> = {
2
+ import { HTTPMethod, ResponseSchema, SchemaMap, StandardSchemaV1 } from '../types';
3
+ export type EndpointConfig<ResSchema extends ResponseSchema, ReqSchema extends StandardSchemaV1 | undefined = undefined, QuerySchema extends StandardSchemaV1 | undefined = undefined, PathSchema extends StandardSchemaV1 | undefined = undefined, MustHeaderKeys extends readonly string[] = readonly []> = {
5
4
  method: keyof typeof HTTPMethod;
6
- path: string | ((params: z.infer<Exclude<PathSchema, undefined>>) => string);
5
+ path: string | ((params: StandardSchemaV1.InferOutput<Exclude<PathSchema, undefined>>) => string);
7
6
  response: ResSchema;
8
7
  request?: ReqSchema;
9
8
  query?: QuerySchema;
@@ -21,19 +20,21 @@ export type EndpointConfig<ResSchema extends z.ZodType | Record<number, z.ZodTyp
21
20
  type RequiredHeaders<Keys extends readonly string[]> = Keys extends readonly [] ? Record<string, string> | undefined : {
22
21
  [K in Keys[number]]: string;
23
22
  } & Record<string, string>;
24
- export type EndpointCallParams<ReqSchema extends z.ZodType | undefined, QuerySchema extends z.ZodType | undefined, PathSchema extends z.ZodType | undefined, MustHeaderKeys extends readonly string[] = readonly []> = {
25
- data?: ReqSchema extends z.ZodType ? z.infer<ReqSchema> : never;
26
- query?: QuerySchema extends z.ZodType ? z.infer<QuerySchema> : never;
27
- pathParams?: PathSchema extends z.ZodType ? z.infer<PathSchema> : never;
23
+ export type EndpointCallParams<ReqSchema extends StandardSchemaV1 | undefined, QuerySchema extends StandardSchemaV1 | undefined, PathSchema extends StandardSchemaV1 | undefined, MustHeaderKeys extends readonly string[] = readonly []> = {
24
+ data?: ReqSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<ReqSchema> : never;
25
+ query?: QuerySchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<QuerySchema> : never;
26
+ pathParams?: PathSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<PathSchema> : never;
28
27
  signal?: globalThis.AbortSignal;
29
28
  } & (MustHeaderKeys extends readonly [] ? {
30
29
  headers?: Record<string, string>;
31
30
  } : {
32
31
  headers: RequiredHeaders<MustHeaderKeys>;
33
32
  });
34
- type InferResponse<S> = S extends z.ZodType ? z.infer<S> : S extends Record<number, z.ZodType> ? z.infer<S[keyof S]> : never;
35
- export type EndpointCall<ResSchema extends z.ZodType | Record<number, z.ZodType>, ReqSchema extends z.ZodType | undefined, QuerySchema extends z.ZodType | undefined, PathSchema extends z.ZodType | undefined, MustHeaderKeys extends readonly string[] = readonly []> = (params: EndpointCallParams<ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>) => Promise<InferResponse<ResSchema>>;
36
- export declare class EndpointImpl<ResSchema extends z.ZodType | Record<number, z.ZodType>, ReqSchema extends z.ZodType | undefined, QuerySchema extends z.ZodType | undefined, PathSchema extends z.ZodType | undefined, MustHeaderKeys extends readonly string[] = readonly []> {
33
+ type InferResponse<S> = S extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S> : S extends SchemaMap ? {
34
+ [K in keyof S]: S[K] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<S[K]> : never;
35
+ }[keyof S] : never;
36
+ export type EndpointCall<ResSchema extends ResponseSchema, ReqSchema extends StandardSchemaV1 | undefined, QuerySchema extends StandardSchemaV1 | undefined, PathSchema extends StandardSchemaV1 | undefined, MustHeaderKeys extends readonly string[] = readonly []> = (params: EndpointCallParams<ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>) => Promise<InferResponse<ResSchema>>;
37
+ export declare class EndpointImpl<ResSchema extends ResponseSchema, ReqSchema extends StandardSchemaV1 | undefined, QuerySchema extends StandardSchemaV1 | undefined, PathSchema extends StandardSchemaV1 | undefined, MustHeaderKeys extends readonly string[] = readonly []> {
37
38
  private client;
38
39
  private config;
39
40
  constructor(client: HttpClient, config: EndpointConfig<ResSchema, ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>);
@@ -1 +1 @@
1
- {"version":3,"file":"base-endpoint.d.ts","sourceRoot":"","sources":["../../lib/endpoint/base-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAyB,MAAM,UAAU,CAAC;AAG7D,MAAM,MAAM,cAAc,CACxB,SAAS,SAAS,CAAC,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EACvD,SAAS,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACnD,WAAW,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACrD,UAAU,SAAS,CAAC,CAAC,OAAO,GAAG,SAAS,GAAG,SAAS,EACpD,cAAc,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,IACpD;IACF,MAAM,EAAE,MAAM,OAAO,UAAU,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;IAC7E,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,QAAQ,CA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GACjB;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CAAE,CAAC,MAAM,CAAC,CAAC,GACvG,KAAK,CAAC;AAEZ,MAAM,MAAM,YAAY,CACtB,SAAS,SAAS,cAAc,EAChC,SAAS,SAAS,gBAAgB,GAAG,SAAS,EAC9C,WAAW,SAAS,gBAAgB,GAAG,SAAS,EAChD,UAAU,SAAS,gBAAgB,GAAG,SAAS,EAC/C,cAAc,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,IACpD,CACF,MAAM,EAAE,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC,KAC3E,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;AAEvC,qBAAa,YAAY,CACvB,SAAS,SAAS,cAAc,EAChC,SAAS,SAAS,gBAAgB,GAAG,SAAS,EAC9C,WAAW,SAAS,gBAAgB,GAAG,SAAS,EAChD,UAAU,SAAS,gBAAgB,GAAG,SAAS,EAC/C,cAAc,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE;IAGpD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;gBADN,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC;IAGzF,IAAI,CACR,MAAM,EAAE,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC,GAC7E,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;CAsFrC"}
@@ -1,7 +1,6 @@
1
- import { z } from 'zod';
2
1
  import type { AuthProvider } from '../auth';
3
2
  import { EndpointCall, EndpointConfig } from '../endpoint/base-endpoint';
4
- import { ClientOptions, HTTPMethod, HTTPStatusCodeNumber, RequestOptions } from '../types';
3
+ import { ClientOptions, HTTPMethod, HTTPStatusCodeNumber, RequestOptions, ResponseSchema, StandardSchemaV1 } from '../types';
5
4
  /**
6
5
  * HTTP client with built-in retry logic, authentication, and interceptors.
7
6
  * Supports multiple base URLs, type-safe requests, and comprehensive error handling.
@@ -164,10 +163,32 @@ export declare class HttpClient {
164
163
  }>;
165
164
  /**
166
165
  * Create a strongly-typed endpoint builder.
166
+ * Works with any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.)
167
167
  *
168
- * @param config - Endpoint configuration
169
- * @returns Endpoint instance
168
+ * @param config - Endpoint configuration with schemas
169
+ * @returns Endpoint call function
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * // With Zod
174
+ * import { z } from 'zod';
175
+ * const getUser = client.createEndpoint({
176
+ * method: 'GET',
177
+ * path: '/users/:id',
178
+ * response: z.object({ id: z.string(), name: z.string() }),
179
+ * pathParams: z.object({ id: z.string() }),
180
+ * });
181
+ *
182
+ * // With Valibot
183
+ * import * as v from 'valibot';
184
+ * const getUser = client.createEndpoint({
185
+ * method: 'GET',
186
+ * path: '/users/:id',
187
+ * response: v.object({ id: v.string(), name: v.string() }),
188
+ * pathParams: v.object({ id: v.string() }),
189
+ * });
190
+ * ```
170
191
  */
171
- createEndpoint<ResSchema extends z.ZodType | Record<number, z.ZodType>, ReqSchema extends z.ZodType | undefined = undefined, QuerySchema extends z.ZodType | undefined = undefined, PathSchema extends z.ZodType | undefined = undefined, MustHeaderKeys extends readonly string[] = readonly []>(config: EndpointConfig<ResSchema, ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>): EndpointCall<ResSchema, ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>;
192
+ createEndpoint<ResSchema extends ResponseSchema, ReqSchema extends StandardSchemaV1 | undefined = undefined, QuerySchema extends StandardSchemaV1 | undefined = undefined, PathSchema extends StandardSchemaV1 | undefined = undefined, MustHeaderKeys extends readonly string[] = readonly []>(config: EndpointConfig<ResSchema, ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>): EndpointCall<ResSchema, ReqSchema, QuerySchema, PathSchema, MustHeaderKeys>;
172
193
  }
173
194
  //# sourceMappingURL=http-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../lib/http/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAgB,MAAM,2BAA2B,CAAC;AAGvF,OAAO,EAEL,aAAa,EAEb,UAAU,EAGV,oBAAoB,EAEpB,cAAc,EAGf,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,iBAAiB,CAAC,CAAqD;IAE/E;;;;;OAKG;gBACS,IAAI,EAAE,aAAa;IAuD/B;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY;IAI1B,OAAO,CAAC,cAAc;IAUtB;;;OAGG;IACH,OAAO,CAAC,KAAK;IAIb;;;OAGG;YACW,SAAS;IAmBvB;;;OAGG;YACW,cAAc;IAM5B;;;OAGG;YACW,aAAa;IAM3B;;;;OAIG;IACI,WAAW;IAIlB;;;;;OAKG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM;IAI7B;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,C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OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;IAIrD;;;;;;;OAOG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;IAIrD;;;;;;;OAOG;IACG,MAAM,CAAC,CAAC,GAAG,OAAO,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;IAIrD;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,cAAc,CACZ,SAAS,SAAS,cAAc,EAChC,SAAS,SAAS,gBAAgB,GAAG,SAAS,GAAG,SAAS,EAC1D,WAAW,SAAS,gBAAgB,GAAG,SAAS,GAAG,SAAS,EAC5D,UAAU,SAAS,gBAAgB,GAAG,SAAS,GAAG,SAAS,EAC3D,cAAc,SAAS,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,EAEtD,MAAM,EAAE,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC,GACpF,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,CAAC;CAI/E"}
package/dist/index.cjs CHANGED
@@ -1,28 +1,4 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
-
23
- //#endregion
24
- const zod = __toESM(require("zod"));
25
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
26
2
  //#region lib/auth.ts
27
3
  /**
28
4
  * No-op authentication provider (no authentication applied).
@@ -96,7 +72,6 @@ var BearerTokenAuth = class {
96
72
  };
97
73
  }
98
74
  };
99
-
100
75
  //#endregion
101
76
  //#region lib/types.ts
102
77
  const HTTPMethod = {
@@ -185,23 +160,20 @@ const HTTPStatusCode = {
185
160
  * ```
186
161
  */
187
162
  var ApiError = class ApiError extends Error {
188
- status;
189
- details;
190
- zodError;
191
163
  constructor(message, options) {
192
164
  super(message);
193
165
  this.name = "ApiError";
194
166
  this.status = options?.status;
195
167
  this.details = options?.details;
196
168
  this.cause = options?.cause;
197
- this.zodError = options?.zodError;
169
+ this.validationIssues = options?.validationIssues;
198
170
  if (Error.captureStackTrace) Error.captureStackTrace(this, ApiError);
199
171
  }
200
172
  /**
201
- * Check if this is a validation error (has zodError)
173
+ * Check if this is a validation error (has validationIssues)
202
174
  */
203
175
  isValidationError() {
204
- return !!this.zodError;
176
+ return !!this.validationIssues && this.validationIssues.length > 0;
205
177
  }
206
178
  /**
207
179
  * Check if this is a client error (4xx status)
@@ -224,7 +196,7 @@ var ApiError = class ApiError extends Error {
224
196
  message: this.message,
225
197
  status: this.status,
226
198
  details: this.details,
227
- zodError: this.zodError?.issues,
199
+ validationIssues: this.validationIssues,
228
200
  stack: this.stack
229
201
  };
230
202
  }
@@ -242,15 +214,6 @@ var SchemaDefinitionError = class SchemaDefinitionError extends Error {
242
214
  }
243
215
  };
244
216
  /**
245
- * Schema for paginated responses
246
- */
247
- const PaginationSchema = zod.z.object({
248
- items: zod.z.array(zod.z.unknown()),
249
- total: zod.z.number().int().nonnegative(),
250
- page: zod.z.number().int().nonnegative(),
251
- pageSize: zod.z.number().int().positive()
252
- });
253
- /**
254
217
  * Converts query parameters to a URL query string.
255
218
  * Filters out undefined values automatically.
256
219
  *
@@ -266,8 +229,8 @@ const PaginationSchema = zod.z.object({
266
229
  function toQueryString(q) {
267
230
  if (!q) return "";
268
231
  if (q instanceof URLSearchParams) {
269
- const s$1 = q.toString();
270
- return s$1 ? `?${s$1}` : "";
232
+ const s = q.toString();
233
+ return s ? `?${s}` : "";
271
234
  }
272
235
  const params = new URLSearchParams();
273
236
  Object.entries(q).forEach(([k, v]) => {
@@ -276,36 +239,88 @@ function toQueryString(q) {
276
239
  const s = params.toString();
277
240
  return s ? `?${s}` : "";
278
241
  }
279
-
280
242
  //#endregion
281
243
  //#region lib/validation.ts
282
244
  /**
283
- * Parse data with a Zod schema, throwing an ApiError on validation failure.
245
+ * Safely parse/validate data with any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.).
246
+ * Returns a result object with success status and data or issues.
247
+ *
248
+ * @param schema - A Standard Schema-compatible validator
249
+ * @param data - Data to validate
250
+ * @returns Result object with success flag and data/issues
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * // Works with Zod
255
+ * import { z } from 'zod';
256
+ * const result = await safeParse(z.object({ name: z.string() }), userData);
257
+ *
258
+ * // Works with Valibot
259
+ * import * as v from 'valibot';
260
+ * const result = await safeParse(v.object({ name: v.string() }), userData);
261
+ *
262
+ * // Works with ArkType
263
+ * import { type } from 'arktype';
264
+ * const result = await safeParse(type({ name: 'string' }), userData);
265
+ *
266
+ * if (result.success) {
267
+ * console.log(result.data);
268
+ * } else {
269
+ * console.error(result.issues);
270
+ * }
271
+ * ```
272
+ */
273
+ async function safeParse(schema, data) {
274
+ const result = await schema["~standard"].validate(data);
275
+ if (result.issues) return {
276
+ success: false,
277
+ issues: result.issues
278
+ };
279
+ return {
280
+ success: true,
281
+ data: result.value
282
+ };
283
+ }
284
+ /**
285
+ * Parse/validate data with any Standard Schema-compatible library, throwing an ApiError on failure.
284
286
  * Use this when you want to fail fast on invalid data.
285
287
  *
286
- * @param schema - Zod schema to validate against
288
+ * @param schema - A Standard Schema-compatible validator
287
289
  * @param data - Data to validate
288
290
  * @returns Validated and typed data
289
- * @throws {ApiError} If validation fails
291
+ * @throws {ApiError} If validation fails (with validationIssues property)
290
292
  *
291
293
  * @example
292
294
  * ```ts
295
+ * // Works with any Standard Schema-compatible library
293
296
  * try {
294
- * const user = parseOrThrow(UserSchema, userData);
297
+ * const user = await parseOrThrow(UserSchema, userData);
295
298
  * console.log(user);
296
299
  * } catch (error) {
297
- * if (error instanceof ApiError && error.zodError) {
298
- * console.error('Validation failed:', error.zodError.issues);
300
+ * if (error instanceof ApiError && error.isValidationError()) {
301
+ * console.error('Validation failed:', error.validationIssues);
299
302
  * }
300
303
  * }
301
304
  * ```
302
305
  */
303
- function parseOrThrow(schema, data) {
304
- const res = schema.safeParse(data);
305
- if (!res.success) throw new ApiError("Response validation failed", { zodError: res.error });
306
- return res.data;
306
+ async function parseOrThrow(schema, data) {
307
+ const result = await schema["~standard"].validate(data);
308
+ if (result.issues) throw new ApiError(`Validation failed: ${result.issues.map((issue) => issue.message).join(", ")}`, { validationIssues: result.issues });
309
+ return result.value;
310
+ }
311
+ /**
312
+ * Type guard to check if a value is a Standard Schema-compatible validator.
313
+ * Handles both object-based schemas (Zod, Valibot) and function-based schemas (ArkType).
314
+ *
315
+ * @param value - Value to check
316
+ * @returns True if the value implements Standard Schema v1
317
+ */
318
+ function isStandardSchema(value) {
319
+ if (value === null || value === void 0) return false;
320
+ if (typeof value !== "object" && typeof value !== "function") return false;
321
+ const schema = value;
322
+ return "~standard" in schema && typeof schema["~standard"] === "object" && schema["~standard"] !== null && schema["~standard"].version === 1 && typeof schema["~standard"].validate === "function";
307
323
  }
308
-
309
324
  //#endregion
310
325
  //#region lib/endpoint/base-endpoint.ts
311
326
  var EndpointImpl = class {
@@ -322,18 +337,9 @@ var EndpointImpl = class {
322
337
  const missingHeaders = this.config.mustHeaderKeys.filter((key) => !headers || !(key in headers));
323
338
  if (missingHeaders.length > 0) throw new Error(`Missing required header(s): ${missingHeaders.join(", ")}`);
324
339
  }
325
- if (!skipRequestValidation && this.config.request && data !== void 0) {
326
- const parsed = this.config.request.safeParse(data);
327
- if (!parsed.success) throw parsed.error;
328
- }
329
- if (!skipRequestValidation && this.config.query && query !== void 0) {
330
- const parsed = this.config.query.safeParse(query);
331
- if (!parsed.success) throw parsed.error;
332
- }
333
- if (!skipRequestValidation && this.config.pathParams && pathParams !== void 0) {
334
- const parsed = this.config.pathParams.safeParse(pathParams);
335
- if (!parsed.success) throw parsed.error;
336
- }
340
+ if (!skipRequestValidation && this.config.request && data !== void 0) await parseOrThrow(this.config.request, data);
341
+ if (!skipRequestValidation && this.config.query && query !== void 0) await parseOrThrow(this.config.query, query);
342
+ if (!skipRequestValidation && this.config.pathParams && pathParams !== void 0) await parseOrThrow(this.config.pathParams, pathParams);
337
343
  if (this.config.request && data === void 0) throw new Error("Missing required request body (data)");
338
344
  if (this.config.pathParams && pathParams === void 0) throw new Error("Missing required path parameters (pathParams)");
339
345
  let pathStr;
@@ -351,24 +357,23 @@ var EndpointImpl = class {
351
357
  });
352
358
  const schema = this.config.response;
353
359
  if (skipResponseValidation) return responseData;
354
- if (schema instanceof zod.z.ZodType) return parseOrThrow(schema, responseData);
360
+ if (isStandardSchema(schema)) return await parseOrThrow(schema, responseData);
355
361
  const specificSchema = schema[status];
356
362
  if (!specificSchema) throw new SchemaDefinitionError(status);
357
- return parseOrThrow(specificSchema, responseData);
363
+ return await parseOrThrow(specificSchema, responseData);
358
364
  }
359
365
  };
360
-
361
366
  //#endregion
362
367
  //#region lib/logger.ts
363
368
  /**
364
369
  * Log levels for structured logging.
365
370
  */
366
- let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
367
- LogLevel$1["DEBUG"] = "debug";
368
- LogLevel$1["INFO"] = "info";
369
- LogLevel$1["WARN"] = "warn";
370
- LogLevel$1["ERROR"] = "error";
371
- return LogLevel$1;
371
+ let LogLevel = /* @__PURE__ */ function(LogLevel) {
372
+ LogLevel["DEBUG"] = "debug";
373
+ LogLevel["INFO"] = "info";
374
+ LogLevel["WARN"] = "warn";
375
+ LogLevel["ERROR"] = "error";
376
+ return LogLevel;
372
377
  }({});
373
378
  /**
374
379
  * Default console logger implementation.
@@ -385,9 +390,7 @@ var ConsoleLogger = class {
385
390
  LogLevel.WARN,
386
391
  LogLevel.ERROR
387
392
  ];
388
- const entryLevelIndex = levels.indexOf(entry.level);
389
- const minLevelIndex = levels.indexOf(this.minLevel);
390
- if (entryLevelIndex < minLevelIndex) return;
393
+ if (levels.indexOf(entry.level) < levels.indexOf(this.minLevel)) return;
391
394
  const output = {
392
395
  ...entry,
393
396
  error: entry.error ? {
@@ -430,7 +433,7 @@ var LoggerUtil = class {
430
433
  this.logger.log({
431
434
  level: LogLevel.DEBUG,
432
435
  message,
433
- timestamp: new Date().toISOString(),
436
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
434
437
  context
435
438
  });
436
439
  }
@@ -438,7 +441,7 @@ var LoggerUtil = class {
438
441
  this.logger.log({
439
442
  level: LogLevel.INFO,
440
443
  message,
441
- timestamp: new Date().toISOString(),
444
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
442
445
  context
443
446
  });
444
447
  }
@@ -446,7 +449,7 @@ var LoggerUtil = class {
446
449
  this.logger.log({
447
450
  level: LogLevel.WARN,
448
451
  message,
449
- timestamp: new Date().toISOString(),
452
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
450
453
  context
451
454
  });
452
455
  }
@@ -454,13 +457,12 @@ var LoggerUtil = class {
454
457
  this.logger.log({
455
458
  level: LogLevel.ERROR,
456
459
  message,
457
- timestamp: new Date().toISOString(),
460
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
458
461
  context,
459
462
  error
460
463
  });
461
464
  }
462
465
  };
463
-
464
466
  //#endregion
465
467
  //#region lib/metrics.ts
466
468
  /**
@@ -474,9 +476,8 @@ var NoOpMetricsCollector = class {
474
476
  * Stores metrics in memory with configurable retention.
475
477
  */
476
478
  var InMemoryMetricsCollector = class {
477
- metrics = [];
478
- maxEntries;
479
479
  constructor(maxEntries = 1e3) {
480
+ this.metrics = [];
480
481
  this.maxEntries = maxEntries;
481
482
  }
482
483
  collect(metrics) {
@@ -535,7 +536,6 @@ var ConsoleMetricsCollector = class {
535
536
  console.log("[METRICS]", JSON.stringify(metrics));
536
537
  }
537
538
  };
538
-
539
539
  //#endregion
540
540
  //#region lib/http/http-client.ts
541
541
  /**
@@ -555,16 +555,6 @@ var ConsoleMetricsCollector = class {
555
555
  * ```
556
556
  */
557
557
  var HttpClient = class {
558
- fetchImpl;
559
- baseUrls;
560
- headers;
561
- interceptors;
562
- retry;
563
- timeoutMs;
564
- auth;
565
- logger;
566
- metrics;
567
- onUnauthenticated;
568
558
  /**
569
559
  * Creates a new HTTP client instance.
570
560
  *
@@ -705,8 +695,7 @@ var HttpClient = class {
705
695
  */
706
696
  async request(method, path, body, options) {
707
697
  const startTime = Date.now();
708
- const base = this.resolveBaseUrl(options?.baseUrlKey);
709
- let url = `${base}${path}${toQueryString(options?.query)}`;
698
+ let url = `${this.resolveBaseUrl(options?.baseUrlKey)}${path}${toQueryString(options?.query)}`;
710
699
  this.logger.debug("HTTP request initiated", {
711
700
  method,
712
701
  path,
@@ -744,7 +733,7 @@ var HttpClient = class {
744
733
  while (true) {
745
734
  let timeoutId;
746
735
  if (this.timeoutMs && !options?.signal) timeoutId = setTimeout(() => {
747
- const timeoutError = new Error("Request timeout");
736
+ const timeoutError = /* @__PURE__ */ new Error("Request timeout");
748
737
  timeoutError.name = "TimeoutError";
749
738
  controller.abort(timeoutError);
750
739
  }, this.timeoutMs);
@@ -761,8 +750,7 @@ var HttpClient = class {
761
750
  const req = new Request(url, init);
762
751
  const res = await this.fetchImpl(req);
763
752
  if (res.status === 401 && this.onUnauthenticated && !refreshAttempted) {
764
- const shouldRetry = await this.onUnauthenticated(res.clone());
765
- if (shouldRetry) {
753
+ if (await this.onUnauthenticated(res.clone())) {
766
754
  refreshAttempted = true;
767
755
  if (timeoutId) clearTimeout(timeoutId);
768
756
  continue;
@@ -787,7 +775,7 @@ var HttpClient = class {
787
775
  path,
788
776
  status: res.status,
789
777
  durationMs: duration,
790
- timestamp: new Date().toISOString(),
778
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
791
779
  success: true
792
780
  });
793
781
  return {
@@ -806,7 +794,7 @@ var HttpClient = class {
806
794
  path,
807
795
  status: error instanceof ApiError ? error.status : void 0,
808
796
  durationMs: duration,
809
- timestamp: new Date().toISOString(),
797
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
810
798
  success: false,
811
799
  error: error instanceof Error ? error.message : String(error)
812
800
  });
@@ -822,8 +810,7 @@ var HttpClient = class {
822
810
  if (errorName === "AbortError" || errorName === "TimeoutError") return false;
823
811
  }
824
812
  if (error instanceof ApiError && error.status) {
825
- const retryCodes = this.retry.retryStatusCodes;
826
- if (retryCodes?.some((codeKey) => HTTPStatusCode[codeKey] === error.status)) return true;
813
+ if (this.retry.retryStatusCodes?.some((codeKey) => HTTPStatusCode[codeKey] === error.status)) return true;
827
814
  }
828
815
  return false;
829
816
  };
@@ -887,121 +874,57 @@ var HttpClient = class {
887
874
  }
888
875
  /**
889
876
  * Create a strongly-typed endpoint builder.
877
+ * Works with any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.)
878
+ *
879
+ * @param config - Endpoint configuration with schemas
880
+ * @returns Endpoint call function
890
881
  *
891
- * @param config - Endpoint configuration
892
- * @returns Endpoint instance
882
+ * @example
883
+ * ```ts
884
+ * // With Zod
885
+ * import { z } from 'zod';
886
+ * const getUser = client.createEndpoint({
887
+ * method: 'GET',
888
+ * path: '/users/:id',
889
+ * response: z.object({ id: z.string(), name: z.string() }),
890
+ * pathParams: z.object({ id: z.string() }),
891
+ * });
892
+ *
893
+ * // With Valibot
894
+ * import * as v from 'valibot';
895
+ * const getUser = client.createEndpoint({
896
+ * method: 'GET',
897
+ * path: '/users/:id',
898
+ * response: v.object({ id: v.string(), name: v.string() }),
899
+ * pathParams: v.object({ id: v.string() }),
900
+ * });
901
+ * ```
893
902
  */
894
903
  createEndpoint(config) {
895
904
  const endpoint = new EndpointImpl(this, config);
896
905
  return (params) => endpoint.call(params);
897
906
  }
898
907
  };
899
-
900
- //#endregion
901
- //#region lib/schemas/common.ts
902
- /**
903
- * Common ID type that supports strings, numbers, or UUIDs.
904
- * Use this for entity identifiers in your schemas.
905
- *
906
- * @example
907
- * ```ts
908
- * const UserSchema = z.object({ id: Id, name: z.string() });
909
- * ```
910
- */
911
- const Id = zod.z.union([
912
- zod.z.string().min(1),
913
- zod.z.number(),
914
- zod.z.uuid({ version: "v4" })
915
- ]);
916
- /**
917
- * Common timestamp fields for entities.
918
- * Use this for database models with creation/update tracking.
919
- *
920
- * @example
921
- * ```ts
922
- * const UserSchema = z.object({
923
- * id: Id,
924
- * name: z.string(),
925
- * ...Timestamps.shape
926
- * });
927
- * ```
928
- */
929
- const Timestamps = zod.z.object({
930
- createdAt: zod.z.iso.datetime(),
931
- updatedAt: zod.z.iso.datetime()
932
- });
933
- /**
934
- * Metadata information typically included in API responses.
935
- * Contains request tracking and debugging information.
936
- */
937
- const Meta = zod.z.object({ timestamp: zod.z.iso.datetime().optional() });
938
- /**
939
- * Detailed error information for a specific field or path.
940
- */
941
- const ErrorDetail = zod.z.object({
942
- path: zod.z.string().optional(),
943
- message: zod.z.string()
944
- });
945
- /**
946
- * Standard API error response schema.
947
- * Use this for consistent error handling across your API.
948
- */
949
- const ApiErrorSchema = zod.z.object({
950
- code: zod.z.string(),
951
- message: zod.z.string(),
952
- details: zod.z.array(ErrorDetail).optional()
953
- });
954
- /**
955
- * Generic envelope wrapper for API responses.
956
- * Provides consistent structure with success flag, data, error, and metadata.
957
- *
958
- * @param inner - Zod schema for the response data
959
- * @returns Envelope schema wrapping the inner schema
960
- *
961
- * @example
962
- * ```ts
963
- * const UserResponseSchema = Envelope(z.object({ id: Id, name: z.string() }));
964
- *
965
- * // Response structure:
966
- * // {
967
- * // success: true,
968
- * // data: { id: 1, name: 'John' },
969
- * // meta: { timestamp: '...' }
970
- * // }
971
- * ```
972
- */
973
- const Envelope = (inner, meta) => {
974
- return zod.z.object({
975
- success: zod.z.boolean(),
976
- data: inner.optional().nullable(),
977
- error: ApiErrorSchema.optional(),
978
- meta: meta !== void 0 ? meta : Meta.optional()
979
- });
980
- };
981
-
982
908
  //#endregion
983
909
  exports.ApiError = ApiError;
984
- exports.ApiErrorSchema = ApiErrorSchema;
985
910
  exports.ApiKeyAuth = ApiKeyAuth;
986
911
  exports.BearerTokenAuth = BearerTokenAuth;
987
912
  exports.ConsoleLogger = ConsoleLogger;
988
913
  exports.ConsoleMetricsCollector = ConsoleMetricsCollector;
989
914
  exports.EndpointImpl = EndpointImpl;
990
- exports.Envelope = Envelope;
991
- exports.ErrorDetail = ErrorDetail;
992
915
  exports.HTTPMethod = HTTPMethod;
993
916
  exports.HTTPStatusCode = HTTPStatusCode;
994
917
  exports.HttpClient = HttpClient;
995
- exports.Id = Id;
996
918
  exports.InMemoryMetricsCollector = InMemoryMetricsCollector;
997
919
  exports.LogLevel = LogLevel;
998
920
  exports.LoggerUtil = LoggerUtil;
999
- exports.Meta = Meta;
1000
921
  exports.NoAuth = NoAuth;
1001
922
  exports.NoOpLogger = NoOpLogger;
1002
923
  exports.NoOpMetricsCollector = NoOpMetricsCollector;
1003
- exports.PaginationSchema = PaginationSchema;
1004
924
  exports.SchemaDefinitionError = SchemaDefinitionError;
1005
- exports.Timestamps = Timestamps;
925
+ exports.isStandardSchema = isStandardSchema;
926
+ exports.parseOrThrow = parseOrThrow;
927
+ exports.safeParse = safeParse;
1006
928
  exports.toQueryString = toQueryString;
929
+
1007
930
  //# sourceMappingURL=index.cjs.map