partnermax 0.2.0 → 0.2.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +60 -47
  2. package/LICENSE +201 -201
  3. package/README.md +370 -370
  4. package/api-promise.js +1 -1
  5. package/client.js +1 -1
  6. package/client.mjs +1 -1
  7. package/core/api-promise.js +1 -1
  8. package/core/api-promise.mjs +1 -1
  9. package/error.js +1 -1
  10. package/package.json +9 -15
  11. package/resource.js +1 -1
  12. package/resources/dealers/dealers.js +1 -1
  13. package/resources/dealers/nlt/nlt.js +1 -1
  14. package/resources/dealers/nlt.js +1 -1
  15. package/resources/dealers/vehicles/vehicles.js +1 -1
  16. package/resources/dealers/vehicles.js +1 -1
  17. package/resources/dealers.js +1 -1
  18. package/resources.js +1 -1
  19. package/src/api-promise.ts +2 -2
  20. package/src/client.ts +841 -841
  21. package/src/core/README.md +3 -3
  22. package/src/core/api-promise.ts +92 -92
  23. package/src/core/error.ts +130 -130
  24. package/src/core/resource.ts +11 -11
  25. package/src/core/uploads.ts +2 -2
  26. package/src/error.ts +2 -2
  27. package/src/index.ts +22 -22
  28. package/src/internal/README.md +3 -3
  29. package/src/internal/builtin-types.ts +93 -93
  30. package/src/internal/detect-platform.ts +196 -196
  31. package/src/internal/errors.ts +33 -33
  32. package/src/internal/headers.ts +97 -97
  33. package/src/internal/parse.ts +56 -56
  34. package/src/internal/request-options.ts +91 -91
  35. package/src/internal/shim-types.ts +26 -26
  36. package/src/internal/shims.ts +107 -107
  37. package/src/internal/to-file.ts +154 -154
  38. package/src/internal/types.ts +93 -93
  39. package/src/internal/uploads.ts +187 -187
  40. package/src/internal/utils/base64.ts +40 -40
  41. package/src/internal/utils/bytes.ts +32 -32
  42. package/src/internal/utils/env.ts +18 -18
  43. package/src/internal/utils/log.ts +128 -128
  44. package/src/internal/utils/path.ts +88 -88
  45. package/src/internal/utils/query.ts +23 -23
  46. package/src/internal/utils/sleep.ts +3 -3
  47. package/src/internal/utils/uuid.ts +17 -17
  48. package/src/internal/utils/values.ts +105 -105
  49. package/src/internal/utils.ts +9 -9
  50. package/src/lib/.keep +4 -4
  51. package/src/resource.ts +2 -2
  52. package/src/resources/dealers/dealers.ts +348 -348
  53. package/src/resources/dealers/index.ts +28 -28
  54. package/src/resources/dealers/nlt/index.ts +11 -11
  55. package/src/resources/dealers/nlt/nlt.ts +29 -29
  56. package/src/resources/dealers/nlt/offers.ts +427 -427
  57. package/src/resources/dealers/nlt-settings.ts +269 -269
  58. package/src/resources/dealers/nlt.ts +3 -3
  59. package/src/resources/dealers/vehicles/images.ts +153 -153
  60. package/src/resources/dealers/vehicles/index.ts +25 -25
  61. package/src/resources/dealers/vehicles/vehicles.ts +796 -796
  62. package/src/resources/dealers/vehicles.ts +3 -3
  63. package/src/resources/dealers.ts +3 -3
  64. package/src/resources/index.ts +12 -12
  65. package/src/resources/keys.ts +128 -128
  66. package/src/resources.ts +1 -1
  67. package/src/tsconfig.json +11 -11
  68. package/src/uploads.ts +2 -2
  69. package/src/version.ts +1 -1
  70. package/uploads.js +1 -1
  71. package/version.d.mts +1 -1
  72. package/version.d.ts +1 -1
  73. package/version.js +1 -1
  74. package/version.mjs +1 -1
@@ -1,93 +1,93 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
-
5
- /**
6
- * An alias to the builtin `RequestInit` type so we can
7
- * easily alias it in import statements if there are name clashes.
8
- *
9
- * https://developer.mozilla.org/docs/Web/API/RequestInit
10
- */
11
- type _RequestInit = RequestInit;
12
-
13
- /**
14
- * An alias to the builtin `Response` type so we can
15
- * easily alias it in import statements if there are name clashes.
16
- *
17
- * https://developer.mozilla.org/docs/Web/API/Response
18
- */
19
- type _Response = Response;
20
-
21
- /**
22
- * The type for the first argument to `fetch`.
23
- *
24
- * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
25
- */
26
- type _RequestInfo = Request | URL | string;
27
-
28
- /**
29
- * The type for constructing `RequestInit` Headers.
30
- *
31
- * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
32
- */
33
- type _HeadersInit = RequestInit['headers'];
34
-
35
- /**
36
- * The type for constructing `RequestInit` body.
37
- *
38
- * https://developer.mozilla.org/docs/Web/API/RequestInit#body
39
- */
40
- type _BodyInit = RequestInit['body'];
41
-
42
- /**
43
- * An alias to the builtin `Array<T>` type so we can
44
- * easily alias it in import statements if there are name clashes.
45
- */
46
- type _Array<T> = Array<T>;
47
-
48
- /**
49
- * An alias to the builtin `Record<K, T>` type so we can
50
- * easily alias it in import statements if there are name clashes.
51
- */
52
- type _Record<K extends keyof any, T> = Record<K, T>;
53
-
54
- export type {
55
- _Array as Array,
56
- _BodyInit as BodyInit,
57
- _HeadersInit as HeadersInit,
58
- _Record as Record,
59
- _RequestInfo as RequestInfo,
60
- _RequestInit as RequestInit,
61
- _Response as Response,
62
- };
63
-
64
- /**
65
- * A copy of the builtin `EndingType` type as it isn't fully supported in certain
66
- * environments and attempting to reference the global version will error.
67
- *
68
- * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
69
- */
70
- type EndingType = 'native' | 'transparent';
71
-
72
- /**
73
- * A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
74
- * environments and attempting to reference the global version will error.
75
- *
76
- * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
77
- * https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
78
- */
79
- export interface BlobPropertyBag {
80
- endings?: EndingType;
81
- type?: string;
82
- }
83
-
84
- /**
85
- * A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
86
- * environments and attempting to reference the global version will error.
87
- *
88
- * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
89
- * https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
90
- */
91
- export interface FilePropertyBag extends BlobPropertyBag {
92
- lastModified?: number;
93
- }
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
+
5
+ /**
6
+ * An alias to the builtin `RequestInit` type so we can
7
+ * easily alias it in import statements if there are name clashes.
8
+ *
9
+ * https://developer.mozilla.org/docs/Web/API/RequestInit
10
+ */
11
+ type _RequestInit = RequestInit;
12
+
13
+ /**
14
+ * An alias to the builtin `Response` type so we can
15
+ * easily alias it in import statements if there are name clashes.
16
+ *
17
+ * https://developer.mozilla.org/docs/Web/API/Response
18
+ */
19
+ type _Response = Response;
20
+
21
+ /**
22
+ * The type for the first argument to `fetch`.
23
+ *
24
+ * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
25
+ */
26
+ type _RequestInfo = Request | URL | string;
27
+
28
+ /**
29
+ * The type for constructing `RequestInit` Headers.
30
+ *
31
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
32
+ */
33
+ type _HeadersInit = RequestInit['headers'];
34
+
35
+ /**
36
+ * The type for constructing `RequestInit` body.
37
+ *
38
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#body
39
+ */
40
+ type _BodyInit = RequestInit['body'];
41
+
42
+ /**
43
+ * An alias to the builtin `Array<T>` type so we can
44
+ * easily alias it in import statements if there are name clashes.
45
+ */
46
+ type _Array<T> = Array<T>;
47
+
48
+ /**
49
+ * An alias to the builtin `Record<K, T>` type so we can
50
+ * easily alias it in import statements if there are name clashes.
51
+ */
52
+ type _Record<K extends keyof any, T> = Record<K, T>;
53
+
54
+ export type {
55
+ _Array as Array,
56
+ _BodyInit as BodyInit,
57
+ _HeadersInit as HeadersInit,
58
+ _Record as Record,
59
+ _RequestInfo as RequestInfo,
60
+ _RequestInit as RequestInit,
61
+ _Response as Response,
62
+ };
63
+
64
+ /**
65
+ * A copy of the builtin `EndingType` type as it isn't fully supported in certain
66
+ * environments and attempting to reference the global version will error.
67
+ *
68
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
69
+ */
70
+ type EndingType = 'native' | 'transparent';
71
+
72
+ /**
73
+ * A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
74
+ * environments and attempting to reference the global version will error.
75
+ *
76
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
77
+ * https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
78
+ */
79
+ export interface BlobPropertyBag {
80
+ endings?: EndingType;
81
+ type?: string;
82
+ }
83
+
84
+ /**
85
+ * A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
86
+ * environments and attempting to reference the global version will error.
87
+ *
88
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
89
+ * https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
90
+ */
91
+ export interface FilePropertyBag extends BlobPropertyBag {
92
+ lastModified?: number;
93
+ }
@@ -1,196 +1,196 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- import { VERSION } from '../version';
4
-
5
- export const isRunningInBrowser = () => {
6
- return (
7
- // @ts-ignore
8
- typeof window !== 'undefined' &&
9
- // @ts-ignore
10
- typeof window.document !== 'undefined' &&
11
- // @ts-ignore
12
- typeof navigator !== 'undefined'
13
- );
14
- };
15
-
16
- type DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';
17
-
18
- /**
19
- * Note this does not detect 'browser'; for that, use getBrowserInfo().
20
- */
21
- function getDetectedPlatform(): DetectedPlatform {
22
- if (typeof Deno !== 'undefined' && Deno.build != null) {
23
- return 'deno';
24
- }
25
- if (typeof EdgeRuntime !== 'undefined') {
26
- return 'edge';
27
- }
28
- if (
29
- Object.prototype.toString.call(
30
- typeof (globalThis as any).process !== 'undefined' ? (globalThis as any).process : 0,
31
- ) === '[object process]'
32
- ) {
33
- return 'node';
34
- }
35
- return 'unknown';
36
- }
37
-
38
- declare const Deno: any;
39
- declare const EdgeRuntime: any;
40
- type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
41
- type PlatformName =
42
- | 'MacOS'
43
- | 'Linux'
44
- | 'Windows'
45
- | 'FreeBSD'
46
- | 'OpenBSD'
47
- | 'iOS'
48
- | 'Android'
49
- | `Other:${string}`
50
- | 'Unknown';
51
- type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
52
- type PlatformProperties = {
53
- 'X-Stainless-Lang': 'js';
54
- 'X-Stainless-Package-Version': string;
55
- 'X-Stainless-OS': PlatformName;
56
- 'X-Stainless-Arch': Arch;
57
- 'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
58
- 'X-Stainless-Runtime-Version': string;
59
- };
60
- const getPlatformProperties = (): PlatformProperties => {
61
- const detectedPlatform = getDetectedPlatform();
62
- if (detectedPlatform === 'deno') {
63
- return {
64
- 'X-Stainless-Lang': 'js',
65
- 'X-Stainless-Package-Version': VERSION,
66
- 'X-Stainless-OS': normalizePlatform(Deno.build.os),
67
- 'X-Stainless-Arch': normalizeArch(Deno.build.arch),
68
- 'X-Stainless-Runtime': 'deno',
69
- 'X-Stainless-Runtime-Version':
70
- typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
71
- };
72
- }
73
- if (typeof EdgeRuntime !== 'undefined') {
74
- return {
75
- 'X-Stainless-Lang': 'js',
76
- 'X-Stainless-Package-Version': VERSION,
77
- 'X-Stainless-OS': 'Unknown',
78
- 'X-Stainless-Arch': `other:${EdgeRuntime}`,
79
- 'X-Stainless-Runtime': 'edge',
80
- 'X-Stainless-Runtime-Version': (globalThis as any).process.version,
81
- };
82
- }
83
- // Check if Node.js
84
- if (detectedPlatform === 'node') {
85
- return {
86
- 'X-Stainless-Lang': 'js',
87
- 'X-Stainless-Package-Version': VERSION,
88
- 'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),
89
- 'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),
90
- 'X-Stainless-Runtime': 'node',
91
- 'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',
92
- };
93
- }
94
-
95
- const browserInfo = getBrowserInfo();
96
- if (browserInfo) {
97
- return {
98
- 'X-Stainless-Lang': 'js',
99
- 'X-Stainless-Package-Version': VERSION,
100
- 'X-Stainless-OS': 'Unknown',
101
- 'X-Stainless-Arch': 'unknown',
102
- 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
103
- 'X-Stainless-Runtime-Version': browserInfo.version,
104
- };
105
- }
106
-
107
- // TODO add support for Cloudflare workers, etc.
108
- return {
109
- 'X-Stainless-Lang': 'js',
110
- 'X-Stainless-Package-Version': VERSION,
111
- 'X-Stainless-OS': 'Unknown',
112
- 'X-Stainless-Arch': 'unknown',
113
- 'X-Stainless-Runtime': 'unknown',
114
- 'X-Stainless-Runtime-Version': 'unknown',
115
- };
116
- };
117
-
118
- type BrowserInfo = {
119
- browser: Browser;
120
- version: string;
121
- };
122
-
123
- declare const navigator: { userAgent: string } | undefined;
124
-
125
- // Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
126
- function getBrowserInfo(): BrowserInfo | null {
127
- if (typeof navigator === 'undefined' || !navigator) {
128
- return null;
129
- }
130
-
131
- // NOTE: The order matters here!
132
- const browserPatterns = [
133
- { key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
134
- { key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
135
- { key: 'ie' as const, pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
136
- { key: 'chrome' as const, pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
137
- { key: 'firefox' as const, pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
138
- { key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
139
- ];
140
-
141
- // Find the FIRST matching browser
142
- for (const { key, pattern } of browserPatterns) {
143
- const match = pattern.exec(navigator.userAgent);
144
- if (match) {
145
- const major = match[1] || 0;
146
- const minor = match[2] || 0;
147
- const patch = match[3] || 0;
148
-
149
- return { browser: key, version: `${major}.${minor}.${patch}` };
150
- }
151
- }
152
-
153
- return null;
154
- }
155
-
156
- const normalizeArch = (arch: string): Arch => {
157
- // Node docs:
158
- // - https://nodejs.org/api/process.html#processarch
159
- // Deno docs:
160
- // - https://doc.deno.land/deno/stable/~/Deno.build
161
- if (arch === 'x32') return 'x32';
162
- if (arch === 'x86_64' || arch === 'x64') return 'x64';
163
- if (arch === 'arm') return 'arm';
164
- if (arch === 'aarch64' || arch === 'arm64') return 'arm64';
165
- if (arch) return `other:${arch}`;
166
- return 'unknown';
167
- };
168
-
169
- const normalizePlatform = (platform: string): PlatformName => {
170
- // Node platforms:
171
- // - https://nodejs.org/api/process.html#processplatform
172
- // Deno platforms:
173
- // - https://doc.deno.land/deno/stable/~/Deno.build
174
- // - https://github.com/denoland/deno/issues/14799
175
-
176
- platform = platform.toLowerCase();
177
-
178
- // NOTE: this iOS check is untested and may not work
179
- // Node does not work natively on IOS, there is a fork at
180
- // https://github.com/nodejs-mobile/nodejs-mobile
181
- // however it is unknown at the time of writing how to detect if it is running
182
- if (platform.includes('ios')) return 'iOS';
183
- if (platform === 'android') return 'Android';
184
- if (platform === 'darwin') return 'MacOS';
185
- if (platform === 'win32') return 'Windows';
186
- if (platform === 'freebsd') return 'FreeBSD';
187
- if (platform === 'openbsd') return 'OpenBSD';
188
- if (platform === 'linux') return 'Linux';
189
- if (platform) return `Other:${platform}`;
190
- return 'Unknown';
191
- };
192
-
193
- let _platformHeaders: PlatformProperties;
194
- export const getPlatformHeaders = () => {
195
- return (_platformHeaders ??= getPlatformProperties());
196
- };
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { VERSION } from '../version';
4
+
5
+ export const isRunningInBrowser = () => {
6
+ return (
7
+ // @ts-ignore
8
+ typeof window !== 'undefined' &&
9
+ // @ts-ignore
10
+ typeof window.document !== 'undefined' &&
11
+ // @ts-ignore
12
+ typeof navigator !== 'undefined'
13
+ );
14
+ };
15
+
16
+ type DetectedPlatform = 'deno' | 'node' | 'edge' | 'unknown';
17
+
18
+ /**
19
+ * Note this does not detect 'browser'; for that, use getBrowserInfo().
20
+ */
21
+ function getDetectedPlatform(): DetectedPlatform {
22
+ if (typeof Deno !== 'undefined' && Deno.build != null) {
23
+ return 'deno';
24
+ }
25
+ if (typeof EdgeRuntime !== 'undefined') {
26
+ return 'edge';
27
+ }
28
+ if (
29
+ Object.prototype.toString.call(
30
+ typeof (globalThis as any).process !== 'undefined' ? (globalThis as any).process : 0,
31
+ ) === '[object process]'
32
+ ) {
33
+ return 'node';
34
+ }
35
+ return 'unknown';
36
+ }
37
+
38
+ declare const Deno: any;
39
+ declare const EdgeRuntime: any;
40
+ type Arch = 'x32' | 'x64' | 'arm' | 'arm64' | `other:${string}` | 'unknown';
41
+ type PlatformName =
42
+ | 'MacOS'
43
+ | 'Linux'
44
+ | 'Windows'
45
+ | 'FreeBSD'
46
+ | 'OpenBSD'
47
+ | 'iOS'
48
+ | 'Android'
49
+ | `Other:${string}`
50
+ | 'Unknown';
51
+ type Browser = 'ie' | 'edge' | 'chrome' | 'firefox' | 'safari';
52
+ type PlatformProperties = {
53
+ 'X-Stainless-Lang': 'js';
54
+ 'X-Stainless-Package-Version': string;
55
+ 'X-Stainless-OS': PlatformName;
56
+ 'X-Stainless-Arch': Arch;
57
+ 'X-Stainless-Runtime': 'node' | 'deno' | 'edge' | `browser:${Browser}` | 'unknown';
58
+ 'X-Stainless-Runtime-Version': string;
59
+ };
60
+ const getPlatformProperties = (): PlatformProperties => {
61
+ const detectedPlatform = getDetectedPlatform();
62
+ if (detectedPlatform === 'deno') {
63
+ return {
64
+ 'X-Stainless-Lang': 'js',
65
+ 'X-Stainless-Package-Version': VERSION,
66
+ 'X-Stainless-OS': normalizePlatform(Deno.build.os),
67
+ 'X-Stainless-Arch': normalizeArch(Deno.build.arch),
68
+ 'X-Stainless-Runtime': 'deno',
69
+ 'X-Stainless-Runtime-Version':
70
+ typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
71
+ };
72
+ }
73
+ if (typeof EdgeRuntime !== 'undefined') {
74
+ return {
75
+ 'X-Stainless-Lang': 'js',
76
+ 'X-Stainless-Package-Version': VERSION,
77
+ 'X-Stainless-OS': 'Unknown',
78
+ 'X-Stainless-Arch': `other:${EdgeRuntime}`,
79
+ 'X-Stainless-Runtime': 'edge',
80
+ 'X-Stainless-Runtime-Version': (globalThis as any).process.version,
81
+ };
82
+ }
83
+ // Check if Node.js
84
+ if (detectedPlatform === 'node') {
85
+ return {
86
+ 'X-Stainless-Lang': 'js',
87
+ 'X-Stainless-Package-Version': VERSION,
88
+ 'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),
89
+ 'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),
90
+ 'X-Stainless-Runtime': 'node',
91
+ 'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',
92
+ };
93
+ }
94
+
95
+ const browserInfo = getBrowserInfo();
96
+ if (browserInfo) {
97
+ return {
98
+ 'X-Stainless-Lang': 'js',
99
+ 'X-Stainless-Package-Version': VERSION,
100
+ 'X-Stainless-OS': 'Unknown',
101
+ 'X-Stainless-Arch': 'unknown',
102
+ 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
103
+ 'X-Stainless-Runtime-Version': browserInfo.version,
104
+ };
105
+ }
106
+
107
+ // TODO add support for Cloudflare workers, etc.
108
+ return {
109
+ 'X-Stainless-Lang': 'js',
110
+ 'X-Stainless-Package-Version': VERSION,
111
+ 'X-Stainless-OS': 'Unknown',
112
+ 'X-Stainless-Arch': 'unknown',
113
+ 'X-Stainless-Runtime': 'unknown',
114
+ 'X-Stainless-Runtime-Version': 'unknown',
115
+ };
116
+ };
117
+
118
+ type BrowserInfo = {
119
+ browser: Browser;
120
+ version: string;
121
+ };
122
+
123
+ declare const navigator: { userAgent: string } | undefined;
124
+
125
+ // Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
126
+ function getBrowserInfo(): BrowserInfo | null {
127
+ if (typeof navigator === 'undefined' || !navigator) {
128
+ return null;
129
+ }
130
+
131
+ // NOTE: The order matters here!
132
+ const browserPatterns = [
133
+ { key: 'edge' as const, pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
134
+ { key: 'ie' as const, pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
135
+ { key: 'ie' as const, pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
136
+ { key: 'chrome' as const, pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
137
+ { key: 'firefox' as const, pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
138
+ { key: 'safari' as const, pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
139
+ ];
140
+
141
+ // Find the FIRST matching browser
142
+ for (const { key, pattern } of browserPatterns) {
143
+ const match = pattern.exec(navigator.userAgent);
144
+ if (match) {
145
+ const major = match[1] || 0;
146
+ const minor = match[2] || 0;
147
+ const patch = match[3] || 0;
148
+
149
+ return { browser: key, version: `${major}.${minor}.${patch}` };
150
+ }
151
+ }
152
+
153
+ return null;
154
+ }
155
+
156
+ const normalizeArch = (arch: string): Arch => {
157
+ // Node docs:
158
+ // - https://nodejs.org/api/process.html#processarch
159
+ // Deno docs:
160
+ // - https://doc.deno.land/deno/stable/~/Deno.build
161
+ if (arch === 'x32') return 'x32';
162
+ if (arch === 'x86_64' || arch === 'x64') return 'x64';
163
+ if (arch === 'arm') return 'arm';
164
+ if (arch === 'aarch64' || arch === 'arm64') return 'arm64';
165
+ if (arch) return `other:${arch}`;
166
+ return 'unknown';
167
+ };
168
+
169
+ const normalizePlatform = (platform: string): PlatformName => {
170
+ // Node platforms:
171
+ // - https://nodejs.org/api/process.html#processplatform
172
+ // Deno platforms:
173
+ // - https://doc.deno.land/deno/stable/~/Deno.build
174
+ // - https://github.com/denoland/deno/issues/14799
175
+
176
+ platform = platform.toLowerCase();
177
+
178
+ // NOTE: this iOS check is untested and may not work
179
+ // Node does not work natively on IOS, there is a fork at
180
+ // https://github.com/nodejs-mobile/nodejs-mobile
181
+ // however it is unknown at the time of writing how to detect if it is running
182
+ if (platform.includes('ios')) return 'iOS';
183
+ if (platform === 'android') return 'Android';
184
+ if (platform === 'darwin') return 'MacOS';
185
+ if (platform === 'win32') return 'Windows';
186
+ if (platform === 'freebsd') return 'FreeBSD';
187
+ if (platform === 'openbsd') return 'OpenBSD';
188
+ if (platform === 'linux') return 'Linux';
189
+ if (platform) return `Other:${platform}`;
190
+ return 'Unknown';
191
+ };
192
+
193
+ let _platformHeaders: PlatformProperties;
194
+ export const getPlatformHeaders = () => {
195
+ return (_platformHeaders ??= getPlatformProperties());
196
+ };
@@ -1,33 +1,33 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- export function isAbortError(err: unknown) {
4
- return (
5
- typeof err === 'object' &&
6
- err !== null &&
7
- // Spec-compliant fetch implementations
8
- (('name' in err && (err as any).name === 'AbortError') ||
9
- // Expo fetch
10
- ('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))
11
- );
12
- }
13
-
14
- export const castToError = (err: any): Error => {
15
- if (err instanceof Error) return err;
16
- if (typeof err === 'object' && err !== null) {
17
- try {
18
- if (Object.prototype.toString.call(err) === '[object Error]') {
19
- // @ts-ignore - not all envs have native support for cause yet
20
- const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
21
- if (err.stack) error.stack = err.stack;
22
- // @ts-ignore - not all envs have native support for cause yet
23
- if (err.cause && !error.cause) error.cause = err.cause;
24
- if (err.name) error.name = err.name;
25
- return error;
26
- }
27
- } catch {}
28
- try {
29
- return new Error(JSON.stringify(err));
30
- } catch {}
31
- }
32
- return new Error(err);
33
- };
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export function isAbortError(err: unknown) {
4
+ return (
5
+ typeof err === 'object' &&
6
+ err !== null &&
7
+ // Spec-compliant fetch implementations
8
+ (('name' in err && (err as any).name === 'AbortError') ||
9
+ // Expo fetch
10
+ ('message' in err && String((err as any).message).includes('FetchRequestCanceledException')))
11
+ );
12
+ }
13
+
14
+ export const castToError = (err: any): Error => {
15
+ if (err instanceof Error) return err;
16
+ if (typeof err === 'object' && err !== null) {
17
+ try {
18
+ if (Object.prototype.toString.call(err) === '[object Error]') {
19
+ // @ts-ignore - not all envs have native support for cause yet
20
+ const error = new Error(err.message, err.cause ? { cause: err.cause } : {});
21
+ if (err.stack) error.stack = err.stack;
22
+ // @ts-ignore - not all envs have native support for cause yet
23
+ if (err.cause && !error.cause) error.cause = err.cause;
24
+ if (err.name) error.name = err.name;
25
+ return error;
26
+ }
27
+ } catch {}
28
+ try {
29
+ return new Error(JSON.stringify(err));
30
+ } catch {}
31
+ }
32
+ return new Error(err);
33
+ };