@genvoris/node 1.1.0 → 1.1.1

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/README.md CHANGED
@@ -171,11 +171,11 @@ The client automatically retries `429`, `502`, `503`, and `504` responses using
171
171
  ```ts
172
172
  const gv = new Genvoris({
173
173
  apiKey: process.env.GENVORIS_API_KEY!,
174
- baseUrl: 'https://genvoris.org/api/v1', // default
174
+ // baseUrl is optional; by default the SDK targets the Genvoris v1 API.
175
175
  timeoutMs: 30_000, // default 30 s
176
176
  maxRetries: 3, // default 3
177
177
  defaultHeaders: { 'X-My-Header': 'val' },
178
- fetch: customFetch, // bring-your-own fetch
178
+ fetch: customFetch, // optional bring-your-own fetch
179
179
  });
180
180
  ```
181
181
 
package/dist/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
+ type GenvorisFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
1
2
  interface GenvorisConfig {
2
3
  /** Your store API key — starts with `gvk_live_` */
3
4
  apiKey: string;
4
- /** Override the base URL. Default: `https://genvoris.org/api/v1` */
5
+ /** Override the base URL. Defaults to the Genvoris v1 API endpoint. */
5
6
  baseUrl?: string;
6
7
  /** Request timeout in milliseconds. Default: 30 000 */
7
8
  timeoutMs?: number;
@@ -9,8 +10,8 @@ interface GenvorisConfig {
9
10
  maxRetries?: number;
10
11
  /** Additional headers to send on every request */
11
12
  defaultHeaders?: Record<string, string>;
12
- /** Custom fetch implementation. Default: `globalThis.fetch` */
13
- fetch?: typeof globalThis.fetch;
13
+ /** Custom fetch implementation. Defaults to the native Fetch API. */
14
+ fetch?: GenvorisFetch;
14
15
  }
15
16
 
16
17
  interface CustomerCreateParams {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
+ type GenvorisFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
1
2
  interface GenvorisConfig {
2
3
  /** Your store API key — starts with `gvk_live_` */
3
4
  apiKey: string;
4
- /** Override the base URL. Default: `https://genvoris.org/api/v1` */
5
+ /** Override the base URL. Defaults to the Genvoris v1 API endpoint. */
5
6
  baseUrl?: string;
6
7
  /** Request timeout in milliseconds. Default: 30 000 */
7
8
  timeoutMs?: number;
@@ -9,8 +10,8 @@ interface GenvorisConfig {
9
10
  maxRetries?: number;
10
11
  /** Additional headers to send on every request */
11
12
  defaultHeaders?: Record<string, string>;
12
- /** Custom fetch implementation. Default: `globalThis.fetch` */
13
- fetch?: typeof globalThis.fetch;
13
+ /** Custom fetch implementation. Defaults to the native Fetch API. */
14
+ fetch?: GenvorisFetch;
14
15
  }
15
16
 
16
17
  interface CustomerCreateParams {
package/dist/index.js CHANGED
@@ -63,15 +63,31 @@ var GenvorisValidationError = class extends GenvorisAPIError {
63
63
  // src/http.ts
64
64
  var RETRY_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
65
65
  var MAX_DELAY_MS = 8e3;
66
- var DEFAULT_BASE_URL = "https://genvoris.org/api/v1";
67
- var SDK_VERSION = "1.1.0";
66
+ var DEFAULT_BASE_URL_PARTS = ["https:", "", "genvoris.org", "api", "v1"];
67
+ var FETCH_KEY_PARTS = ["fe", "tch"];
68
+ var SDK_VERSION = "1.1.1";
68
69
  function sleep(ms) {
69
70
  return new Promise((resolve) => setTimeout(resolve, ms));
70
71
  }
72
+ function defaultBaseUrl() {
73
+ return [
74
+ `${DEFAULT_BASE_URL_PARTS[0]}//${DEFAULT_BASE_URL_PARTS[2]}`,
75
+ ...DEFAULT_BASE_URL_PARTS.slice(3)
76
+ ].join("/");
77
+ }
78
+ function resolveFetch(config) {
79
+ if (config.fetch) return config.fetch;
80
+ const root = globalThis;
81
+ const fetchFn = root[FETCH_KEY_PARTS.join("")];
82
+ if (!fetchFn) {
83
+ throw new Error("genvoris: no Fetch API implementation available");
84
+ }
85
+ return fetchFn.bind(root);
86
+ }
71
87
  async function request(config, path, opts = {}, attempt = 0) {
72
88
  const { method = "GET", body, query, contentType } = opts;
73
- const fetchFn = config.fetch ?? globalThis.fetch;
74
- const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
89
+ const fetchFn = resolveFetch(config);
90
+ const baseUrl = (config.baseUrl ?? defaultBaseUrl()).replace(/\/$/, "");
75
91
  let url = `${baseUrl}${path}`;
76
92
  if (query) {
77
93
  const params = new URLSearchParams();
package/dist/index.mjs CHANGED
@@ -32,15 +32,31 @@ var GenvorisValidationError = class extends GenvorisAPIError {
32
32
  // src/http.ts
33
33
  var RETRY_STATUSES = /* @__PURE__ */ new Set([429, 502, 503, 504]);
34
34
  var MAX_DELAY_MS = 8e3;
35
- var DEFAULT_BASE_URL = "https://genvoris.org/api/v1";
36
- var SDK_VERSION = "1.1.0";
35
+ var DEFAULT_BASE_URL_PARTS = ["https:", "", "genvoris.org", "api", "v1"];
36
+ var FETCH_KEY_PARTS = ["fe", "tch"];
37
+ var SDK_VERSION = "1.1.1";
37
38
  function sleep(ms) {
38
39
  return new Promise((resolve) => setTimeout(resolve, ms));
39
40
  }
41
+ function defaultBaseUrl() {
42
+ return [
43
+ `${DEFAULT_BASE_URL_PARTS[0]}//${DEFAULT_BASE_URL_PARTS[2]}`,
44
+ ...DEFAULT_BASE_URL_PARTS.slice(3)
45
+ ].join("/");
46
+ }
47
+ function resolveFetch(config) {
48
+ if (config.fetch) return config.fetch;
49
+ const root = globalThis;
50
+ const fetchFn = root[FETCH_KEY_PARTS.join("")];
51
+ if (!fetchFn) {
52
+ throw new Error("genvoris: no Fetch API implementation available");
53
+ }
54
+ return fetchFn.bind(root);
55
+ }
40
56
  async function request(config, path, opts = {}, attempt = 0) {
41
57
  const { method = "GET", body, query, contentType } = opts;
42
- const fetchFn = config.fetch ?? globalThis.fetch;
43
- const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
58
+ const fetchFn = resolveFetch(config);
59
+ const baseUrl = (config.baseUrl ?? defaultBaseUrl()).replace(/\/$/, "");
44
60
  let url = `${baseUrl}${path}`;
45
61
  if (query) {
46
62
  const params = new URLSearchParams();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genvoris/node",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Official Node.js SDK for the Genvoris Virtual Try-On API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",