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.
- package/CHANGELOG.md +60 -47
- package/LICENSE +201 -201
- package/README.md +370 -370
- package/api-promise.js +1 -1
- package/client.js +1 -1
- package/client.mjs +1 -1
- package/core/api-promise.js +1 -1
- package/core/api-promise.mjs +1 -1
- package/error.js +1 -1
- package/package.json +9 -15
- package/resource.js +1 -1
- package/resources/dealers/dealers.js +1 -1
- package/resources/dealers/nlt/nlt.js +1 -1
- package/resources/dealers/nlt.js +1 -1
- package/resources/dealers/vehicles/vehicles.js +1 -1
- package/resources/dealers/vehicles.js +1 -1
- package/resources/dealers.js +1 -1
- package/resources.js +1 -1
- package/src/api-promise.ts +2 -2
- package/src/client.ts +841 -841
- package/src/core/README.md +3 -3
- package/src/core/api-promise.ts +92 -92
- package/src/core/error.ts +130 -130
- package/src/core/resource.ts +11 -11
- package/src/core/uploads.ts +2 -2
- package/src/error.ts +2 -2
- package/src/index.ts +22 -22
- package/src/internal/README.md +3 -3
- package/src/internal/builtin-types.ts +93 -93
- package/src/internal/detect-platform.ts +196 -196
- package/src/internal/errors.ts +33 -33
- package/src/internal/headers.ts +97 -97
- package/src/internal/parse.ts +56 -56
- package/src/internal/request-options.ts +91 -91
- package/src/internal/shim-types.ts +26 -26
- package/src/internal/shims.ts +107 -107
- package/src/internal/to-file.ts +154 -154
- package/src/internal/types.ts +93 -93
- package/src/internal/uploads.ts +187 -187
- package/src/internal/utils/base64.ts +40 -40
- package/src/internal/utils/bytes.ts +32 -32
- package/src/internal/utils/env.ts +18 -18
- package/src/internal/utils/log.ts +128 -128
- package/src/internal/utils/path.ts +88 -88
- package/src/internal/utils/query.ts +23 -23
- package/src/internal/utils/sleep.ts +3 -3
- package/src/internal/utils/uuid.ts +17 -17
- package/src/internal/utils/values.ts +105 -105
- package/src/internal/utils.ts +9 -9
- package/src/lib/.keep +4 -4
- package/src/resource.ts +2 -2
- package/src/resources/dealers/dealers.ts +348 -348
- package/src/resources/dealers/index.ts +28 -28
- package/src/resources/dealers/nlt/index.ts +11 -11
- package/src/resources/dealers/nlt/nlt.ts +29 -29
- package/src/resources/dealers/nlt/offers.ts +427 -427
- package/src/resources/dealers/nlt-settings.ts +269 -269
- package/src/resources/dealers/nlt.ts +3 -3
- package/src/resources/dealers/vehicles/images.ts +153 -153
- package/src/resources/dealers/vehicles/index.ts +25 -25
- package/src/resources/dealers/vehicles/vehicles.ts +796 -796
- package/src/resources/dealers/vehicles.ts +3 -3
- package/src/resources/dealers.ts +3 -3
- package/src/resources/index.ts +12 -12
- package/src/resources/keys.ts +128 -128
- package/src/resources.ts +1 -1
- package/src/tsconfig.json +11 -11
- package/src/uploads.ts +2 -2
- package/src/version.ts +1 -1
- package/uploads.js +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
import { PartnermaxError } from '../../core/error';
|
|
4
|
-
import { encodeUTF8 } from './bytes';
|
|
5
|
-
|
|
6
|
-
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
7
|
-
if (!data) return '';
|
|
8
|
-
|
|
9
|
-
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
10
|
-
return (globalThis as any).Buffer.from(data).toString('base64');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (typeof data === 'string') {
|
|
14
|
-
data = encodeUTF8(data);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (typeof btoa !== 'undefined') {
|
|
18
|
-
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
throw new PartnermaxError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const fromBase64 = (str: string): Uint8Array => {
|
|
25
|
-
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
26
|
-
const buf = (globalThis as any).Buffer.from(str, 'base64');
|
|
27
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof atob !== 'undefined') {
|
|
31
|
-
const bstr = atob(str);
|
|
32
|
-
const buf = new Uint8Array(bstr.length);
|
|
33
|
-
for (let i = 0; i < bstr.length; i++) {
|
|
34
|
-
buf[i] = bstr.charCodeAt(i);
|
|
35
|
-
}
|
|
36
|
-
return buf;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
throw new PartnermaxError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
|
-
};
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { PartnermaxError } from '../../core/error';
|
|
4
|
+
import { encodeUTF8 } from './bytes';
|
|
5
|
+
|
|
6
|
+
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
7
|
+
if (!data) return '';
|
|
8
|
+
|
|
9
|
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
10
|
+
return (globalThis as any).Buffer.from(data).toString('base64');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof data === 'string') {
|
|
14
|
+
data = encodeUTF8(data);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof btoa !== 'undefined') {
|
|
18
|
+
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
throw new PartnermaxError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const fromBase64 = (str: string): Uint8Array => {
|
|
25
|
+
if (typeof (globalThis as any).Buffer !== 'undefined') {
|
|
26
|
+
const buf = (globalThis as any).Buffer.from(str, 'base64');
|
|
27
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof atob !== 'undefined') {
|
|
31
|
+
const bstr = atob(str);
|
|
32
|
+
const buf = new Uint8Array(bstr.length);
|
|
33
|
+
for (let i = 0; i < bstr.length; i++) {
|
|
34
|
+
buf[i] = bstr.charCodeAt(i);
|
|
35
|
+
}
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw new PartnermaxError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
|
+
};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
export function concatBytes(buffers: Uint8Array[]): Uint8Array {
|
|
2
|
-
let length = 0;
|
|
3
|
-
for (const buffer of buffers) {
|
|
4
|
-
length += buffer.length;
|
|
5
|
-
}
|
|
6
|
-
const output = new Uint8Array(length);
|
|
7
|
-
let index = 0;
|
|
8
|
-
for (const buffer of buffers) {
|
|
9
|
-
output.set(buffer, index);
|
|
10
|
-
index += buffer.length;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let encodeUTF8_: (str: string) => Uint8Array;
|
|
17
|
-
export function encodeUTF8(str: string) {
|
|
18
|
-
let encoder;
|
|
19
|
-
return (
|
|
20
|
-
encodeUTF8_ ??
|
|
21
|
-
((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))
|
|
22
|
-
)(str);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let decodeUTF8_: (bytes: Uint8Array) => string;
|
|
26
|
-
export function decodeUTF8(bytes: Uint8Array) {
|
|
27
|
-
let decoder;
|
|
28
|
-
return (
|
|
29
|
-
decodeUTF8_ ??
|
|
30
|
-
((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))
|
|
31
|
-
)(bytes);
|
|
32
|
-
}
|
|
1
|
+
export function concatBytes(buffers: Uint8Array[]): Uint8Array {
|
|
2
|
+
let length = 0;
|
|
3
|
+
for (const buffer of buffers) {
|
|
4
|
+
length += buffer.length;
|
|
5
|
+
}
|
|
6
|
+
const output = new Uint8Array(length);
|
|
7
|
+
let index = 0;
|
|
8
|
+
for (const buffer of buffers) {
|
|
9
|
+
output.set(buffer, index);
|
|
10
|
+
index += buffer.length;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let encodeUTF8_: (str: string) => Uint8Array;
|
|
17
|
+
export function encodeUTF8(str: string) {
|
|
18
|
+
let encoder;
|
|
19
|
+
return (
|
|
20
|
+
encodeUTF8_ ??
|
|
21
|
+
((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))
|
|
22
|
+
)(str);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let decodeUTF8_: (bytes: Uint8Array) => string;
|
|
26
|
+
export function decodeUTF8(bytes: Uint8Array) {
|
|
27
|
+
let decoder;
|
|
28
|
+
return (
|
|
29
|
+
decodeUTF8_ ??
|
|
30
|
+
((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))
|
|
31
|
+
)(bytes);
|
|
32
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Read an environment variable.
|
|
5
|
-
*
|
|
6
|
-
* Trims beginning and trailing whitespace.
|
|
7
|
-
*
|
|
8
|
-
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
9
|
-
*/
|
|
10
|
-
export const readEnv = (env: string): string | undefined => {
|
|
11
|
-
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
-
return (globalThis as any).process.env?.[env]?.trim() || undefined;
|
|
13
|
-
}
|
|
14
|
-
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
-
return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined;
|
|
16
|
-
}
|
|
17
|
-
return undefined;
|
|
18
|
-
};
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read an environment variable.
|
|
5
|
+
*
|
|
6
|
+
* Trims beginning and trailing whitespace.
|
|
7
|
+
*
|
|
8
|
+
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
9
|
+
*/
|
|
10
|
+
export const readEnv = (env: string): string | undefined => {
|
|
11
|
+
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
+
return (globalThis as any).process.env?.[env]?.trim() || undefined;
|
|
13
|
+
}
|
|
14
|
+
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
+
return (globalThis as any).Deno.env?.get?.(env)?.trim() || undefined;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
import { hasOwn } from './values';
|
|
4
|
-
import { type Partnermax } from '../../client';
|
|
5
|
-
import { RequestOptions } from '../request-options';
|
|
6
|
-
|
|
7
|
-
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
8
|
-
export type Logger = {
|
|
9
|
-
error: LogFn;
|
|
10
|
-
warn: LogFn;
|
|
11
|
-
info: LogFn;
|
|
12
|
-
debug: LogFn;
|
|
13
|
-
};
|
|
14
|
-
export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
|
15
|
-
|
|
16
|
-
const levelNumbers = {
|
|
17
|
-
off: 0,
|
|
18
|
-
error: 200,
|
|
19
|
-
warn: 300,
|
|
20
|
-
info: 400,
|
|
21
|
-
debug: 500,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const parseLogLevel = (
|
|
25
|
-
maybeLevel: string | undefined,
|
|
26
|
-
sourceName: string,
|
|
27
|
-
client: Partnermax,
|
|
28
|
-
): LogLevel | undefined => {
|
|
29
|
-
if (!maybeLevel) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
if (hasOwn(levelNumbers, maybeLevel)) {
|
|
33
|
-
return maybeLevel;
|
|
34
|
-
}
|
|
35
|
-
loggerFor(client).warn(
|
|
36
|
-
`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(
|
|
37
|
-
Object.keys(levelNumbers),
|
|
38
|
-
)}`,
|
|
39
|
-
);
|
|
40
|
-
return undefined;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function noop() {}
|
|
44
|
-
|
|
45
|
-
function makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel: LogLevel) {
|
|
46
|
-
if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
|
|
47
|
-
return noop;
|
|
48
|
-
} else {
|
|
49
|
-
// Don't wrap logger functions, we want the stacktrace intact!
|
|
50
|
-
return logger[fnLevel].bind(logger);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const noopLogger = {
|
|
55
|
-
error: noop,
|
|
56
|
-
warn: noop,
|
|
57
|
-
info: noop,
|
|
58
|
-
debug: noop,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
|
-
|
|
63
|
-
export function loggerFor(client: Partnermax): Logger {
|
|
64
|
-
const logger = client.logger;
|
|
65
|
-
const logLevel = client.logLevel ?? 'off';
|
|
66
|
-
if (!logger) {
|
|
67
|
-
return noopLogger;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const cachedLogger = cachedLoggers.get(logger);
|
|
71
|
-
if (cachedLogger && cachedLogger[0] === logLevel) {
|
|
72
|
-
return cachedLogger[1];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const levelLogger = {
|
|
76
|
-
error: makeLogFn('error', logger, logLevel),
|
|
77
|
-
warn: makeLogFn('warn', logger, logLevel),
|
|
78
|
-
info: makeLogFn('info', logger, logLevel),
|
|
79
|
-
debug: makeLogFn('debug', logger, logLevel),
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
|
83
|
-
|
|
84
|
-
return levelLogger;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const formatRequestDetails = (details: {
|
|
88
|
-
options?: RequestOptions | undefined;
|
|
89
|
-
headers?: Headers | Record<string, string> | undefined;
|
|
90
|
-
retryOfRequestLogID?: string | undefined;
|
|
91
|
-
retryOf?: string | undefined;
|
|
92
|
-
url?: string | undefined;
|
|
93
|
-
status?: number | undefined;
|
|
94
|
-
method?: string | undefined;
|
|
95
|
-
durationMs?: number | undefined;
|
|
96
|
-
message?: unknown;
|
|
97
|
-
body?: unknown;
|
|
98
|
-
}) => {
|
|
99
|
-
if (details.options) {
|
|
100
|
-
details.options = { ...details.options };
|
|
101
|
-
delete details.options['headers']; // redundant + leaks internals
|
|
102
|
-
}
|
|
103
|
-
if (details.headers) {
|
|
104
|
-
details.headers = Object.fromEntries(
|
|
105
|
-
(details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(
|
|
106
|
-
([name, value]) => [
|
|
107
|
-
name,
|
|
108
|
-
(
|
|
109
|
-
name.toLowerCase() === 'authorization' ||
|
|
110
|
-
name.toLowerCase() === 'api-key' ||
|
|
111
|
-
name.toLowerCase() === 'x-api-key' ||
|
|
112
|
-
name.toLowerCase() === 'cookie' ||
|
|
113
|
-
name.toLowerCase() === 'set-cookie'
|
|
114
|
-
) ?
|
|
115
|
-
'***'
|
|
116
|
-
: value,
|
|
117
|
-
],
|
|
118
|
-
),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
if ('retryOfRequestLogID' in details) {
|
|
122
|
-
if (details.retryOfRequestLogID) {
|
|
123
|
-
details.retryOf = details.retryOfRequestLogID;
|
|
124
|
-
}
|
|
125
|
-
delete details.retryOfRequestLogID;
|
|
126
|
-
}
|
|
127
|
-
return details;
|
|
128
|
-
};
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { hasOwn } from './values';
|
|
4
|
+
import { type Partnermax } from '../../client';
|
|
5
|
+
import { RequestOptions } from '../request-options';
|
|
6
|
+
|
|
7
|
+
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
8
|
+
export type Logger = {
|
|
9
|
+
error: LogFn;
|
|
10
|
+
warn: LogFn;
|
|
11
|
+
info: LogFn;
|
|
12
|
+
debug: LogFn;
|
|
13
|
+
};
|
|
14
|
+
export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
|
15
|
+
|
|
16
|
+
const levelNumbers = {
|
|
17
|
+
off: 0,
|
|
18
|
+
error: 200,
|
|
19
|
+
warn: 300,
|
|
20
|
+
info: 400,
|
|
21
|
+
debug: 500,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const parseLogLevel = (
|
|
25
|
+
maybeLevel: string | undefined,
|
|
26
|
+
sourceName: string,
|
|
27
|
+
client: Partnermax,
|
|
28
|
+
): LogLevel | undefined => {
|
|
29
|
+
if (!maybeLevel) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (hasOwn(levelNumbers, maybeLevel)) {
|
|
33
|
+
return maybeLevel;
|
|
34
|
+
}
|
|
35
|
+
loggerFor(client).warn(
|
|
36
|
+
`${sourceName} was set to ${JSON.stringify(maybeLevel)}, expected one of ${JSON.stringify(
|
|
37
|
+
Object.keys(levelNumbers),
|
|
38
|
+
)}`,
|
|
39
|
+
);
|
|
40
|
+
return undefined;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function noop() {}
|
|
44
|
+
|
|
45
|
+
function makeLogFn(fnLevel: keyof Logger, logger: Logger | undefined, logLevel: LogLevel) {
|
|
46
|
+
if (!logger || levelNumbers[fnLevel] > levelNumbers[logLevel]) {
|
|
47
|
+
return noop;
|
|
48
|
+
} else {
|
|
49
|
+
// Don't wrap logger functions, we want the stacktrace intact!
|
|
50
|
+
return logger[fnLevel].bind(logger);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const noopLogger = {
|
|
55
|
+
error: noop,
|
|
56
|
+
warn: noop,
|
|
57
|
+
info: noop,
|
|
58
|
+
debug: noop,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
|
+
|
|
63
|
+
export function loggerFor(client: Partnermax): Logger {
|
|
64
|
+
const logger = client.logger;
|
|
65
|
+
const logLevel = client.logLevel ?? 'off';
|
|
66
|
+
if (!logger) {
|
|
67
|
+
return noopLogger;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const cachedLogger = cachedLoggers.get(logger);
|
|
71
|
+
if (cachedLogger && cachedLogger[0] === logLevel) {
|
|
72
|
+
return cachedLogger[1];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const levelLogger = {
|
|
76
|
+
error: makeLogFn('error', logger, logLevel),
|
|
77
|
+
warn: makeLogFn('warn', logger, logLevel),
|
|
78
|
+
info: makeLogFn('info', logger, logLevel),
|
|
79
|
+
debug: makeLogFn('debug', logger, logLevel),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
cachedLoggers.set(logger, [logLevel, levelLogger]);
|
|
83
|
+
|
|
84
|
+
return levelLogger;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const formatRequestDetails = (details: {
|
|
88
|
+
options?: RequestOptions | undefined;
|
|
89
|
+
headers?: Headers | Record<string, string> | undefined;
|
|
90
|
+
retryOfRequestLogID?: string | undefined;
|
|
91
|
+
retryOf?: string | undefined;
|
|
92
|
+
url?: string | undefined;
|
|
93
|
+
status?: number | undefined;
|
|
94
|
+
method?: string | undefined;
|
|
95
|
+
durationMs?: number | undefined;
|
|
96
|
+
message?: unknown;
|
|
97
|
+
body?: unknown;
|
|
98
|
+
}) => {
|
|
99
|
+
if (details.options) {
|
|
100
|
+
details.options = { ...details.options };
|
|
101
|
+
delete details.options['headers']; // redundant + leaks internals
|
|
102
|
+
}
|
|
103
|
+
if (details.headers) {
|
|
104
|
+
details.headers = Object.fromEntries(
|
|
105
|
+
(details.headers instanceof Headers ? [...details.headers] : Object.entries(details.headers)).map(
|
|
106
|
+
([name, value]) => [
|
|
107
|
+
name,
|
|
108
|
+
(
|
|
109
|
+
name.toLowerCase() === 'authorization' ||
|
|
110
|
+
name.toLowerCase() === 'api-key' ||
|
|
111
|
+
name.toLowerCase() === 'x-api-key' ||
|
|
112
|
+
name.toLowerCase() === 'cookie' ||
|
|
113
|
+
name.toLowerCase() === 'set-cookie'
|
|
114
|
+
) ?
|
|
115
|
+
'***'
|
|
116
|
+
: value,
|
|
117
|
+
],
|
|
118
|
+
),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if ('retryOfRequestLogID' in details) {
|
|
122
|
+
if (details.retryOfRequestLogID) {
|
|
123
|
+
details.retryOf = details.retryOfRequestLogID;
|
|
124
|
+
}
|
|
125
|
+
delete details.retryOfRequestLogID;
|
|
126
|
+
}
|
|
127
|
+
return details;
|
|
128
|
+
};
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { PartnermaxError } from '../../core/error';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
5
|
-
*
|
|
6
|
-
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
|
7
|
-
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
8
|
-
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
9
|
-
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
10
|
-
*/
|
|
11
|
-
export function encodeURIPath(str: string) {
|
|
12
|
-
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16
|
-
|
|
17
|
-
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
18
|
-
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
19
|
-
// If there are no params, no processing is needed.
|
|
20
|
-
if (statics.length === 1) return statics[0]!;
|
|
21
|
-
|
|
22
|
-
let postPath = false;
|
|
23
|
-
const invalidSegments = [];
|
|
24
|
-
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
25
|
-
if (/[?#]/.test(currentValue)) {
|
|
26
|
-
postPath = true;
|
|
27
|
-
}
|
|
28
|
-
const value = params[index];
|
|
29
|
-
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
30
|
-
if (
|
|
31
|
-
index !== params.length &&
|
|
32
|
-
(value == null ||
|
|
33
|
-
(typeof value === 'object' &&
|
|
34
|
-
// handle values from other realms
|
|
35
|
-
value.toString ===
|
|
36
|
-
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
|
37
|
-
?.toString))
|
|
38
|
-
) {
|
|
39
|
-
encoded = value + '';
|
|
40
|
-
invalidSegments.push({
|
|
41
|
-
start: previousValue.length + currentValue.length,
|
|
42
|
-
length: encoded.length,
|
|
43
|
-
error: `Value of type ${Object.prototype.toString
|
|
44
|
-
.call(value)
|
|
45
|
-
.slice(8, -1)} is not a valid path parameter`,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
49
|
-
}, '');
|
|
50
|
-
|
|
51
|
-
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
52
|
-
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
53
|
-
let match;
|
|
54
|
-
|
|
55
|
-
// Find all invalid segments
|
|
56
|
-
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
57
|
-
invalidSegments.push({
|
|
58
|
-
start: match.index,
|
|
59
|
-
length: match[0].length,
|
|
60
|
-
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
invalidSegments.sort((a, b) => a.start - b.start);
|
|
65
|
-
|
|
66
|
-
if (invalidSegments.length > 0) {
|
|
67
|
-
let lastEnd = 0;
|
|
68
|
-
const underline = invalidSegments.reduce((acc, segment) => {
|
|
69
|
-
const spaces = ' '.repeat(segment.start - lastEnd);
|
|
70
|
-
const arrows = '^'.repeat(segment.length);
|
|
71
|
-
lastEnd = segment.start + segment.length;
|
|
72
|
-
return acc + spaces + arrows;
|
|
73
|
-
}, '');
|
|
74
|
-
|
|
75
|
-
throw new PartnermaxError(
|
|
76
|
-
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
|
-
.map((e) => e.error)
|
|
78
|
-
.join('\n')}\n${path}\n${underline}`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return path;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
|
87
|
-
*/
|
|
88
|
-
export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
1
|
+
import { PartnermaxError } from '../../core/error';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
5
|
+
*
|
|
6
|
+
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
|
7
|
+
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
8
|
+
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
9
|
+
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
10
|
+
*/
|
|
11
|
+
export function encodeURIPath(str: string) {
|
|
12
|
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16
|
+
|
|
17
|
+
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
18
|
+
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
19
|
+
// If there are no params, no processing is needed.
|
|
20
|
+
if (statics.length === 1) return statics[0]!;
|
|
21
|
+
|
|
22
|
+
let postPath = false;
|
|
23
|
+
const invalidSegments = [];
|
|
24
|
+
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
25
|
+
if (/[?#]/.test(currentValue)) {
|
|
26
|
+
postPath = true;
|
|
27
|
+
}
|
|
28
|
+
const value = params[index];
|
|
29
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
30
|
+
if (
|
|
31
|
+
index !== params.length &&
|
|
32
|
+
(value == null ||
|
|
33
|
+
(typeof value === 'object' &&
|
|
34
|
+
// handle values from other realms
|
|
35
|
+
value.toString ===
|
|
36
|
+
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
|
37
|
+
?.toString))
|
|
38
|
+
) {
|
|
39
|
+
encoded = value + '';
|
|
40
|
+
invalidSegments.push({
|
|
41
|
+
start: previousValue.length + currentValue.length,
|
|
42
|
+
length: encoded.length,
|
|
43
|
+
error: `Value of type ${Object.prototype.toString
|
|
44
|
+
.call(value)
|
|
45
|
+
.slice(8, -1)} is not a valid path parameter`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
49
|
+
}, '');
|
|
50
|
+
|
|
51
|
+
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
52
|
+
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
53
|
+
let match;
|
|
54
|
+
|
|
55
|
+
// Find all invalid segments
|
|
56
|
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
57
|
+
invalidSegments.push({
|
|
58
|
+
start: match.index,
|
|
59
|
+
length: match[0].length,
|
|
60
|
+
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
65
|
+
|
|
66
|
+
if (invalidSegments.length > 0) {
|
|
67
|
+
let lastEnd = 0;
|
|
68
|
+
const underline = invalidSegments.reduce((acc, segment) => {
|
|
69
|
+
const spaces = ' '.repeat(segment.start - lastEnd);
|
|
70
|
+
const arrows = '^'.repeat(segment.length);
|
|
71
|
+
lastEnd = segment.start + segment.length;
|
|
72
|
+
return acc + spaces + arrows;
|
|
73
|
+
}, '');
|
|
74
|
+
|
|
75
|
+
throw new PartnermaxError(
|
|
76
|
+
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
|
+
.map((e) => e.error)
|
|
78
|
+
.join('\n')}\n${path}\n${underline}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return path;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
|
87
|
+
*/
|
|
88
|
+
export const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
import { PartnermaxError } from '../../core/error';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
7
|
-
*/
|
|
8
|
-
export function stringifyQuery(query: object | Record<string, unknown>) {
|
|
9
|
-
return Object.entries(query)
|
|
10
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
11
|
-
.map(([key, value]) => {
|
|
12
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
13
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
14
|
-
}
|
|
15
|
-
if (value === null) {
|
|
16
|
-
return `${encodeURIComponent(key)}=`;
|
|
17
|
-
}
|
|
18
|
-
throw new PartnermaxError(
|
|
19
|
-
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
20
|
-
);
|
|
21
|
-
})
|
|
22
|
-
.join('&');
|
|
23
|
-
}
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { PartnermaxError } from '../../core/error';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
7
|
+
*/
|
|
8
|
+
export function stringifyQuery(query: object | Record<string, unknown>) {
|
|
9
|
+
return Object.entries(query)
|
|
10
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
11
|
+
.map(([key, value]) => {
|
|
12
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
13
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
14
|
+
}
|
|
15
|
+
if (value === null) {
|
|
16
|
+
return `${encodeURIComponent(key)}=`;
|
|
17
|
+
}
|
|
18
|
+
throw new PartnermaxError(
|
|
19
|
+
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
|
|
20
|
+
);
|
|
21
|
+
})
|
|
22
|
+
.join('&');
|
|
23
|
+
}
|