@examplary/sdk 2.0.1 → 2.1.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,3 +0,0 @@
1
- "use strict";
2
- // This file is auto-generated. Do not edit by hand.
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import { type AxiosInstance } from "axios";
2
- import type { ExamplaryClientOptions } from "./options";
3
- export interface ClientContext {
4
- axios: AxiosInstance;
5
- apiKey: string;
6
- }
7
- export declare const createClientContext: (options: ExamplaryClientOptions) => ClientContext;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createClientContext = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const error_1 = require("./error");
9
- const createClientContext = (options) => {
10
- const { apiKey, baseUrl, headers, ...rest } = options;
11
- const instance = axios_1.default.create({
12
- baseURL: baseUrl ?? "https://api.examplary.ai",
13
- ...rest,
14
- headers: {
15
- Authorization: `Bearer ${apiKey}`,
16
- ...headers,
17
- },
18
- });
19
- instance.interceptors.response.use((response) => response, (error) => Promise.reject(error_1.ExamplaryError.fromAxiosError(error)));
20
- return { axios: instance, apiKey };
21
- };
22
- exports.createClientContext = createClientContext;
@@ -1,6 +0,0 @@
1
- import { AxiosError, type AxiosResponse, type InternalAxiosRequestConfig } from "axios";
2
- export declare class ExamplaryError<T = unknown, D = any> extends AxiosError<T, D> {
3
- originalMessage?: string;
4
- constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: any, response?: AxiosResponse<T, D>);
5
- static fromAxiosError(error: AxiosError): ExamplaryError;
6
- }
package/dist/src/error.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExamplaryError = void 0;
4
- const axios_1 = require("axios");
5
- class ExamplaryError extends axios_1.AxiosError {
6
- constructor(message, code, config, request, response) {
7
- super(message, code, config, request, response);
8
- this.name = "ExamplaryError";
9
- }
10
- static fromAxiosError(error) {
11
- const e = new ExamplaryError(error.message, error.code, error.config, error.request, error.response);
12
- const data = error.response?.data;
13
- if (typeof data?.error === "string") {
14
- e.originalMessage = error.message;
15
- e.message = data.error;
16
- }
17
- else if (typeof data?.error?.message === "string") {
18
- e.originalMessage = error.message;
19
- e.message = data.error.message;
20
- }
21
- return e;
22
- }
23
- }
24
- exports.ExamplaryError = ExamplaryError;
@@ -1,5 +0,0 @@
1
- export { Examplary } from "../generated/sdk";
2
- export type * from "../generated/sdk";
3
- export { ExamplaryError } from "./error";
4
- export type { ExamplaryClientOptions, ExamplaryRequestOptions, } from "./options";
5
- export type { components, operations, paths } from "../generated/types";
package/dist/src/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExamplaryError = exports.Examplary = void 0;
4
- var sdk_1 = require("../generated/sdk");
5
- Object.defineProperty(exports, "Examplary", { enumerable: true, get: function () { return sdk_1.Examplary; } });
6
- var error_1 = require("./error");
7
- Object.defineProperty(exports, "ExamplaryError", { enumerable: true, get: function () { return error_1.ExamplaryError; } });
@@ -1,6 +0,0 @@
1
- import type { AxiosRequestConfig, CreateAxiosDefaults } from "axios";
2
- export interface ExamplaryClientOptions extends Omit<CreateAxiosDefaults, "baseURL"> {
3
- apiKey: string;
4
- baseUrl?: string;
5
- }
6
- export type ExamplaryRequestOptions = Omit<AxiosRequestConfig, "method" | "url" | "data" | "params" | "baseURL">;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- import type { ClientContext } from "./context";
2
- import type { ExamplaryRequestOptions } from "./options";
3
- export declare const request: <T>(ctx: ClientContext, method: string, pathTemplate: string, pathKeys: readonly string[], queryKeys: readonly string[], hasBody: boolean, args: Record<string, unknown> | undefined, options: ExamplaryRequestOptions | undefined) => Promise<T>;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.request = void 0;
4
- const error_1 = require("./error");
5
- const API_KEY_REGEX = /^examp_[A-Za-z0-9]+$/;
6
- const request = async (ctx, method, pathTemplate, pathKeys, queryKeys, hasBody, args, options) => {
7
- if (!API_KEY_REGEX.test(ctx.apiKey)) {
8
- throw new error_1.ExamplaryError("Invalid API key");
9
- }
10
- const flat = args ?? {};
11
- const url = pathTemplate.replace(/\{(\w+)\}/g, (_, key) => {
12
- const value = flat[key];
13
- if (value === undefined || value === null) {
14
- throw new error_1.ExamplaryError(`Missing required path parameter "${key}"`);
15
- }
16
- return encodeURIComponent(String(value));
17
- });
18
- const params = {};
19
- for (const k of queryKeys) {
20
- if (flat[k] !== undefined)
21
- params[k] = flat[k];
22
- }
23
- let data;
24
- if (hasBody) {
25
- const consumed = new Set([...pathKeys, ...queryKeys]);
26
- const body = {};
27
- let any = false;
28
- for (const [k, v] of Object.entries(flat)) {
29
- if (consumed.has(k))
30
- continue;
31
- body[k] = v;
32
- any = true;
33
- }
34
- if (any)
35
- data = body;
36
- }
37
- const response = await ctx.axios.request({
38
- ...options,
39
- method,
40
- url,
41
- params: Object.keys(params).length ? params : undefined,
42
- data,
43
- });
44
- return response.data;
45
- };
46
- exports.request = request;