partnermax 0.2.0 → 0.2.2

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 (179) hide show
  1. package/CHANGELOG.md +75 -47
  2. package/LICENSE +201 -201
  3. package/README.md +394 -370
  4. package/api-promise.js +1 -1
  5. package/client.d.mts +9 -3
  6. package/client.d.mts.map +1 -1
  7. package/client.d.ts +9 -3
  8. package/client.d.ts.map +1 -1
  9. package/client.js +12 -2
  10. package/client.js.map +1 -1
  11. package/client.mjs +12 -2
  12. package/client.mjs.map +1 -1
  13. package/core/api-promise.js +1 -1
  14. package/core/api-promise.mjs +1 -1
  15. package/core/pagination.d.mts +57 -0
  16. package/core/pagination.d.mts.map +1 -0
  17. package/core/pagination.d.ts +57 -0
  18. package/core/pagination.d.ts.map +1 -0
  19. package/core/pagination.js +108 -0
  20. package/core/pagination.js.map +1 -0
  21. package/core/pagination.mjs +102 -0
  22. package/core/pagination.mjs.map +1 -0
  23. package/error.js +1 -1
  24. package/index.d.mts +1 -0
  25. package/index.d.mts.map +1 -1
  26. package/index.d.ts +1 -0
  27. package/index.d.ts.map +1 -1
  28. package/index.js +3 -1
  29. package/index.js.map +1 -1
  30. package/index.mjs +1 -0
  31. package/index.mjs.map +1 -1
  32. package/internal/tslib.js +17 -17
  33. package/package.json +19 -15
  34. package/pagination.d.mts +3 -0
  35. package/pagination.d.mts.map +1 -0
  36. package/pagination.d.ts +3 -0
  37. package/pagination.d.ts.map +1 -0
  38. package/pagination.js +6 -0
  39. package/pagination.js.map +1 -0
  40. package/pagination.mjs +3 -0
  41. package/pagination.mjs.map +1 -0
  42. package/resource.js +1 -1
  43. package/resources/dealers/dealers.d.mts +7 -71
  44. package/resources/dealers/dealers.d.mts.map +1 -1
  45. package/resources/dealers/dealers.d.ts +7 -71
  46. package/resources/dealers/dealers.d.ts.map +1 -1
  47. package/resources/dealers/dealers.js +3 -16
  48. package/resources/dealers/dealers.js.map +1 -1
  49. package/resources/dealers/dealers.mjs +2 -15
  50. package/resources/dealers/dealers.mjs.map +1 -1
  51. package/resources/dealers/index.d.mts +2 -2
  52. package/resources/dealers/index.d.mts.map +1 -1
  53. package/resources/dealers/index.d.ts +2 -2
  54. package/resources/dealers/index.d.ts.map +1 -1
  55. package/resources/dealers/index.js.map +1 -1
  56. package/resources/dealers/index.mjs.map +1 -1
  57. package/resources/dealers/nlt/index.d.mts +1 -1
  58. package/resources/dealers/nlt/index.d.mts.map +1 -1
  59. package/resources/dealers/nlt/index.d.ts +1 -1
  60. package/resources/dealers/nlt/index.d.ts.map +1 -1
  61. package/resources/dealers/nlt/nlt.d.mts +2 -2
  62. package/resources/dealers/nlt/nlt.d.mts.map +1 -1
  63. package/resources/dealers/nlt/nlt.d.ts +2 -2
  64. package/resources/dealers/nlt/nlt.d.ts.map +1 -1
  65. package/resources/dealers/nlt/nlt.js +1 -1
  66. package/resources/dealers/nlt/offers.d.mts +55 -78
  67. package/resources/dealers/nlt/offers.d.mts.map +1 -1
  68. package/resources/dealers/nlt/offers.d.ts +55 -78
  69. package/resources/dealers/nlt/offers.d.ts.map +1 -1
  70. package/resources/dealers/nlt/offers.js +9 -11
  71. package/resources/dealers/nlt/offers.js.map +1 -1
  72. package/resources/dealers/nlt/offers.mjs +9 -11
  73. package/resources/dealers/nlt/offers.mjs.map +1 -1
  74. package/resources/dealers/nlt-settings.d.mts +24 -64
  75. package/resources/dealers/nlt-settings.d.mts.map +1 -1
  76. package/resources/dealers/nlt-settings.d.ts +24 -64
  77. package/resources/dealers/nlt-settings.d.ts.map +1 -1
  78. package/resources/dealers/nlt-settings.js +4 -13
  79. package/resources/dealers/nlt-settings.js.map +1 -1
  80. package/resources/dealers/nlt-settings.mjs +4 -13
  81. package/resources/dealers/nlt-settings.mjs.map +1 -1
  82. package/resources/dealers/nlt.js +1 -1
  83. package/resources/dealers/vehicles/images.d.mts +3 -2
  84. package/resources/dealers/vehicles/images.d.mts.map +1 -1
  85. package/resources/dealers/vehicles/images.d.ts +3 -2
  86. package/resources/dealers/vehicles/images.d.ts.map +1 -1
  87. package/resources/dealers/vehicles/images.js +3 -2
  88. package/resources/dealers/vehicles/images.js.map +1 -1
  89. package/resources/dealers/vehicles/images.mjs +3 -2
  90. package/resources/dealers/vehicles/images.mjs.map +1 -1
  91. package/resources/dealers/vehicles/index.d.mts +1 -1
  92. package/resources/dealers/vehicles/index.d.mts.map +1 -1
  93. package/resources/dealers/vehicles/index.d.ts +1 -1
  94. package/resources/dealers/vehicles/index.d.ts.map +1 -1
  95. package/resources/dealers/vehicles/index.js.map +1 -1
  96. package/resources/dealers/vehicles/index.mjs.map +1 -1
  97. package/resources/dealers/vehicles/vehicles.d.mts +57 -70
  98. package/resources/dealers/vehicles/vehicles.d.mts.map +1 -1
  99. package/resources/dealers/vehicles/vehicles.d.ts +57 -70
  100. package/resources/dealers/vehicles/vehicles.d.ts.map +1 -1
  101. package/resources/dealers/vehicles/vehicles.js +19 -19
  102. package/resources/dealers/vehicles/vehicles.js.map +1 -1
  103. package/resources/dealers/vehicles/vehicles.mjs +18 -18
  104. package/resources/dealers/vehicles/vehicles.mjs.map +1 -1
  105. package/resources/dealers/vehicles.js +1 -1
  106. package/resources/dealers.js +1 -1
  107. package/resources/index.d.mts +1 -1
  108. package/resources/index.d.mts.map +1 -1
  109. package/resources/index.d.ts +1 -1
  110. package/resources/index.d.ts.map +1 -1
  111. package/resources/index.js.map +1 -1
  112. package/resources/index.mjs.map +1 -1
  113. package/resources/keys.d.mts +7 -6
  114. package/resources/keys.d.mts.map +1 -1
  115. package/resources/keys.d.ts +7 -6
  116. package/resources/keys.d.ts.map +1 -1
  117. package/resources/keys.js +7 -6
  118. package/resources/keys.js.map +1 -1
  119. package/resources/keys.mjs +7 -6
  120. package/resources/keys.mjs.map +1 -1
  121. package/resources.js +1 -1
  122. package/src/api-promise.ts +2 -2
  123. package/src/client.ts +868 -841
  124. package/src/core/README.md +3 -3
  125. package/src/core/api-promise.ts +92 -92
  126. package/src/core/error.ts +130 -130
  127. package/src/core/pagination.ts +170 -0
  128. package/src/core/resource.ts +11 -11
  129. package/src/core/uploads.ts +2 -2
  130. package/src/error.ts +2 -2
  131. package/src/index.ts +23 -22
  132. package/src/internal/README.md +3 -3
  133. package/src/internal/builtin-types.ts +93 -93
  134. package/src/internal/detect-platform.ts +196 -196
  135. package/src/internal/errors.ts +33 -33
  136. package/src/internal/headers.ts +97 -97
  137. package/src/internal/parse.ts +56 -56
  138. package/src/internal/request-options.ts +91 -91
  139. package/src/internal/shim-types.ts +26 -26
  140. package/src/internal/shims.ts +107 -107
  141. package/src/internal/to-file.ts +154 -154
  142. package/src/internal/types.ts +93 -93
  143. package/src/internal/uploads.ts +187 -187
  144. package/src/internal/utils/base64.ts +40 -40
  145. package/src/internal/utils/bytes.ts +32 -32
  146. package/src/internal/utils/env.ts +18 -18
  147. package/src/internal/utils/log.ts +128 -128
  148. package/src/internal/utils/path.ts +88 -88
  149. package/src/internal/utils/query.ts +23 -23
  150. package/src/internal/utils/sleep.ts +3 -3
  151. package/src/internal/utils/uuid.ts +17 -17
  152. package/src/internal/utils/values.ts +105 -105
  153. package/src/internal/utils.ts +9 -9
  154. package/src/lib/.keep +4 -4
  155. package/src/pagination.ts +2 -0
  156. package/src/resource.ts +2 -2
  157. package/src/resources/dealers/dealers.ts +260 -348
  158. package/src/resources/dealers/index.ts +28 -28
  159. package/src/resources/dealers/nlt/index.ts +11 -11
  160. package/src/resources/dealers/nlt/nlt.ts +29 -29
  161. package/src/resources/dealers/nlt/offers.ts +403 -427
  162. package/src/resources/dealers/nlt-settings.ts +229 -269
  163. package/src/resources/dealers/nlt.ts +3 -3
  164. package/src/resources/dealers/vehicles/images.ts +154 -153
  165. package/src/resources/dealers/vehicles/index.ts +26 -25
  166. package/src/resources/dealers/vehicles/vehicles.ts +786 -796
  167. package/src/resources/dealers/vehicles.ts +3 -3
  168. package/src/resources/dealers.ts +3 -3
  169. package/src/resources/index.ts +11 -12
  170. package/src/resources/keys.ts +129 -128
  171. package/src/resources.ts +1 -1
  172. package/src/tsconfig.json +11 -11
  173. package/src/uploads.ts +2 -2
  174. package/src/version.ts +1 -1
  175. package/uploads.js +1 -1
  176. package/version.d.mts +1 -1
  177. package/version.d.ts +1 -1
  178. package/version.js +1 -1
  179. package/version.mjs +1 -1
package/src/index.ts CHANGED
@@ -1,22 +1,23 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- export { Partnermax as default } from './client';
4
-
5
- export { type Uploadable, toFile } from './core/uploads';
6
- export { APIPromise } from './core/api-promise';
7
- export { Partnermax, type ClientOptions } from './client';
8
- export {
9
- PartnermaxError,
10
- APIError,
11
- APIConnectionError,
12
- APIConnectionTimeoutError,
13
- APIUserAbortError,
14
- NotFoundError,
15
- ConflictError,
16
- RateLimitError,
17
- BadRequestError,
18
- AuthenticationError,
19
- InternalServerError,
20
- PermissionDeniedError,
21
- UnprocessableEntityError,
22
- } from './core/error';
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Partnermax as default } from './client';
4
+
5
+ export { type Uploadable, toFile } from './core/uploads';
6
+ export { APIPromise } from './core/api-promise';
7
+ export { Partnermax, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
9
+ export {
10
+ PartnermaxError,
11
+ APIError,
12
+ APIConnectionError,
13
+ APIConnectionTimeoutError,
14
+ APIUserAbortError,
15
+ NotFoundError,
16
+ ConflictError,
17
+ RateLimitError,
18
+ BadRequestError,
19
+ AuthenticationError,
20
+ InternalServerError,
21
+ PermissionDeniedError,
22
+ UnprocessableEntityError,
23
+ } from './core/error';
@@ -1,3 +1,3 @@
1
- # `internal`
2
-
3
- The modules in this directory are not importable outside this package and will change between releases.
1
+ # `internal`
2
+
3
+ The modules in this directory are not importable outside this package and will change between releases.
@@ -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
+ };