@postpeer/node 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -3
- package/LICENSE +1 -1
- package/README.md +28 -27
- package/client.d.mts +9 -9
- package/client.d.mts.map +1 -1
- package/client.d.ts +9 -9
- package/client.d.ts.map +1 -1
- package/client.js +37 -37
- package/client.js.map +1 -1
- package/client.mjs +35 -35
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +2 -2
- package/core/api-promise.d.ts +2 -2
- package/core/error.d.mts +2 -2
- package/core/error.d.ts +2 -2
- package/core/error.js +4 -4
- package/core/error.mjs +2 -2
- package/core/resource.d.mts +3 -3
- package/core/resource.d.ts +3 -3
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +4 -4
- package/index.mjs +3 -3
- package/internal/parse.d.mts +2 -2
- package/internal/parse.d.ts +2 -2
- package/internal/shims.js +1 -1
- package/internal/shims.mjs +1 -1
- package/internal/uploads.d.mts +4 -4
- package/internal/uploads.d.ts +4 -4
- package/internal/utils/base64.js +2 -2
- package/internal/utils/base64.mjs +3 -3
- package/internal/utils/log.d.mts +3 -3
- package/internal/utils/log.d.ts +3 -3
- package/internal/utils/path.js +1 -1
- package/internal/utils/path.mjs +2 -2
- package/internal/utils/values.js +5 -5
- package/internal/utils/values.mjs +6 -6
- package/package.json +4 -4
- package/src/client.ts +19 -19
- package/src/core/api-promise.ts +4 -4
- package/src/core/error.ts +2 -2
- package/src/core/resource.ts +3 -3
- package/src/index.ts +3 -3
- package/src/internal/parse.ts +2 -2
- package/src/internal/shims.ts +1 -1
- package/src/internal/uploads.ts +5 -5
- package/src/internal/utils/base64.ts +3 -3
- package/src/internal/utils/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/internal/utils/values.js
CHANGED
|
@@ -40,17 +40,17 @@ function isObj(obj) {
|
|
|
40
40
|
}
|
|
41
41
|
const ensurePresent = (value) => {
|
|
42
42
|
if (value == null) {
|
|
43
|
-
throw new error_1.
|
|
43
|
+
throw new error_1.PostpeerError(`Expected a value to be given but received ${value} instead.`);
|
|
44
44
|
}
|
|
45
45
|
return value;
|
|
46
46
|
};
|
|
47
47
|
exports.ensurePresent = ensurePresent;
|
|
48
48
|
const validatePositiveInteger = (name, n) => {
|
|
49
49
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new error_1.
|
|
50
|
+
throw new error_1.PostpeerError(`${name} must be an integer`);
|
|
51
51
|
}
|
|
52
52
|
if (n < 0) {
|
|
53
|
-
throw new error_1.
|
|
53
|
+
throw new error_1.PostpeerError(`${name} must be a positive integer`);
|
|
54
54
|
}
|
|
55
55
|
return n;
|
|
56
56
|
};
|
|
@@ -60,7 +60,7 @@ const coerceInteger = (value) => {
|
|
|
60
60
|
return Math.round(value);
|
|
61
61
|
if (typeof value === 'string')
|
|
62
62
|
return parseInt(value, 10);
|
|
63
|
-
throw new error_1.
|
|
63
|
+
throw new error_1.PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
64
64
|
};
|
|
65
65
|
exports.coerceInteger = coerceInteger;
|
|
66
66
|
const coerceFloat = (value) => {
|
|
@@ -68,7 +68,7 @@ const coerceFloat = (value) => {
|
|
|
68
68
|
return value;
|
|
69
69
|
if (typeof value === 'string')
|
|
70
70
|
return parseFloat(value);
|
|
71
|
-
throw new error_1.
|
|
71
|
+
throw new error_1.PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
72
72
|
};
|
|
73
73
|
exports.coerceFloat = coerceFloat;
|
|
74
74
|
const coerceBoolean = (value) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
import {
|
|
2
|
+
import { PostpeerError } from "../../core/error.mjs";
|
|
3
3
|
// https://url.spec.whatwg.org/#url-scheme-string
|
|
4
4
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
5
5
|
export const isAbsoluteURL = (url) => {
|
|
@@ -31,16 +31,16 @@ export function isObj(obj) {
|
|
|
31
31
|
}
|
|
32
32
|
export const ensurePresent = (value) => {
|
|
33
33
|
if (value == null) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new PostpeerError(`Expected a value to be given but received ${value} instead.`);
|
|
35
35
|
}
|
|
36
36
|
return value;
|
|
37
37
|
};
|
|
38
38
|
export const validatePositiveInteger = (name, n) => {
|
|
39
39
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new PostpeerError(`${name} must be an integer`);
|
|
41
41
|
}
|
|
42
42
|
if (n < 0) {
|
|
43
|
-
throw new
|
|
43
|
+
throw new PostpeerError(`${name} must be a positive integer`);
|
|
44
44
|
}
|
|
45
45
|
return n;
|
|
46
46
|
};
|
|
@@ -49,14 +49,14 @@ export const coerceInteger = (value) => {
|
|
|
49
49
|
return Math.round(value);
|
|
50
50
|
if (typeof value === 'string')
|
|
51
51
|
return parseInt(value, 10);
|
|
52
|
-
throw new
|
|
52
|
+
throw new PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
53
53
|
};
|
|
54
54
|
export const coerceFloat = (value) => {
|
|
55
55
|
if (typeof value === 'number')
|
|
56
56
|
return value;
|
|
57
57
|
if (typeof value === 'string')
|
|
58
58
|
return parseFloat(value);
|
|
59
|
-
throw new
|
|
59
|
+
throw new PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
60
60
|
};
|
|
61
61
|
export const coerceBoolean = (value) => {
|
|
62
62
|
if (typeof value === 'boolean')
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postpeer/node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The official TypeScript library for the
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "The official TypeScript library for the Postpeer API",
|
|
5
|
+
"author": "Postpeer <>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"type": "commonjs",
|
|
9
|
-
"repository": "github:PostPeer-API/postpeer-
|
|
9
|
+
"repository": "github:PostPeer-API/postpeer-node",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"files": [
|
|
12
12
|
"**/*"
|
package/src/client.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface ClientOptions {
|
|
|
54
54
|
/**
|
|
55
55
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
56
56
|
*
|
|
57
|
-
* Defaults to process.env['
|
|
57
|
+
* Defaults to process.env['POSTPEER_BASE_URL'].
|
|
58
58
|
*/
|
|
59
59
|
baseURL?: string | null | undefined;
|
|
60
60
|
|
|
@@ -108,7 +108,7 @@ export interface ClientOptions {
|
|
|
108
108
|
/**
|
|
109
109
|
* Set the log level.
|
|
110
110
|
*
|
|
111
|
-
* Defaults to process.env['
|
|
111
|
+
* Defaults to process.env['POSTPEER_LOG'] or 'warn' if it isn't set.
|
|
112
112
|
*/
|
|
113
113
|
logLevel?: LogLevel | undefined;
|
|
114
114
|
|
|
@@ -121,9 +121,9 @@ export interface ClientOptions {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* API Client for interfacing with the
|
|
124
|
+
* API Client for interfacing with the Postpeer API.
|
|
125
125
|
*/
|
|
126
|
-
export class
|
|
126
|
+
export class Postpeer {
|
|
127
127
|
apiKey: string;
|
|
128
128
|
|
|
129
129
|
baseURL: string;
|
|
@@ -139,10 +139,10 @@ export class PostPeer {
|
|
|
139
139
|
private _options: ClientOptions;
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
* API Client for interfacing with the
|
|
142
|
+
* API Client for interfacing with the Postpeer API.
|
|
143
143
|
*
|
|
144
144
|
* @param {string | undefined} [opts.apiKey=process.env['POSTPEER_API_KEY'] ?? undefined]
|
|
145
|
-
* @param {string} [opts.baseURL=process.env['
|
|
145
|
+
* @param {string} [opts.baseURL=process.env['POSTPEER_BASE_URL'] ?? https://api.example.com] - Override the default base URL for the API.
|
|
146
146
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
147
147
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
148
148
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -151,13 +151,13 @@ export class PostPeer {
|
|
|
151
151
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
152
152
|
*/
|
|
153
153
|
constructor({
|
|
154
|
-
baseURL = readEnv('
|
|
154
|
+
baseURL = readEnv('POSTPEER_BASE_URL'),
|
|
155
155
|
apiKey = readEnv('POSTPEER_API_KEY'),
|
|
156
156
|
...opts
|
|
157
157
|
}: ClientOptions = {}) {
|
|
158
158
|
if (apiKey === undefined) {
|
|
159
|
-
throw new Errors.
|
|
160
|
-
"The POSTPEER_API_KEY environment variable is missing or empty; either provide it, or instantiate the
|
|
159
|
+
throw new Errors.PostpeerError(
|
|
160
|
+
"The POSTPEER_API_KEY environment variable is missing or empty; either provide it, or instantiate the Postpeer client with an apiKey option, like new Postpeer({ apiKey: 'My API Key' }).",
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -168,14 +168,14 @@ export class PostPeer {
|
|
|
168
168
|
};
|
|
169
169
|
|
|
170
170
|
this.baseURL = options.baseURL!;
|
|
171
|
-
this.timeout = options.timeout ??
|
|
171
|
+
this.timeout = options.timeout ?? Postpeer.DEFAULT_TIMEOUT /* 1 minute */;
|
|
172
172
|
this.logger = options.logger ?? console;
|
|
173
173
|
const defaultLogLevel = 'warn';
|
|
174
174
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
175
175
|
this.logLevel = defaultLogLevel;
|
|
176
176
|
this.logLevel =
|
|
177
177
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
178
|
-
parseLogLevel(readEnv('
|
|
178
|
+
parseLogLevel(readEnv('POSTPEER_LOG'), "process.env['POSTPEER_LOG']", this) ??
|
|
179
179
|
defaultLogLevel;
|
|
180
180
|
this.fetchOptions = options.fetchOptions;
|
|
181
181
|
this.maxRetries = options.maxRetries ?? 2;
|
|
@@ -710,10 +710,10 @@ export class PostPeer {
|
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
-
static
|
|
713
|
+
static Postpeer = this;
|
|
714
714
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
715
715
|
|
|
716
|
-
static
|
|
716
|
+
static PostpeerError = Errors.PostpeerError;
|
|
717
717
|
static APIError = Errors.APIError;
|
|
718
718
|
static APIConnectionError = Errors.APIConnectionError;
|
|
719
719
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -736,13 +736,13 @@ export class PostPeer {
|
|
|
736
736
|
media: API.Media = new API.Media(this);
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
739
|
+
Postpeer.Health = Health;
|
|
740
|
+
Postpeer.Connect = Connect;
|
|
741
|
+
Postpeer.Platforms = Platforms;
|
|
742
|
+
Postpeer.Posts = Posts;
|
|
743
|
+
Postpeer.Media = Media;
|
|
744
744
|
|
|
745
|
-
export declare namespace
|
|
745
|
+
export declare namespace Postpeer {
|
|
746
746
|
export type RequestOptions = Opts.RequestOptions;
|
|
747
747
|
|
|
748
748
|
export {
|
package/src/core/api-promise.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type Postpeer } from '../client';
|
|
4
4
|
|
|
5
5
|
import { type PromiseOrValue } from '../internal/types';
|
|
6
6
|
import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
@@ -11,13 +11,13 @@ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
|
11
11
|
*/
|
|
12
12
|
export class APIPromise<T> extends Promise<T> {
|
|
13
13
|
private parsedPromise: Promise<T> | undefined;
|
|
14
|
-
#client:
|
|
14
|
+
#client: Postpeer;
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
client:
|
|
17
|
+
client: Postpeer,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
19
|
private parseResponse: (
|
|
20
|
-
client:
|
|
20
|
+
client: Postpeer,
|
|
21
21
|
props: APIResponseProps,
|
|
22
22
|
) => PromiseOrValue<T> = defaultParseResponse,
|
|
23
23
|
) {
|
package/src/core/error.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class PostpeerError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError<
|
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends
|
|
11
|
+
> extends PostpeerError {
|
|
12
12
|
/** HTTP status for the response that caused the error */
|
|
13
13
|
readonly status: TStatus;
|
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/core/resource.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Postpeer } from '../client';
|
|
4
4
|
|
|
5
5
|
export abstract class APIResource {
|
|
6
|
-
protected _client:
|
|
6
|
+
protected _client: Postpeer;
|
|
7
7
|
|
|
8
|
-
constructor(client:
|
|
8
|
+
constructor(client: Postpeer) {
|
|
9
9
|
this._client = client;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Postpeer as default } from './client';
|
|
4
4
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
|
-
export {
|
|
7
|
+
export { Postpeer, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
PostpeerError,
|
|
10
10
|
APIError,
|
|
11
11
|
APIConnectionError,
|
|
12
12
|
APIConnectionTimeoutError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Postpeer } from '../client';
|
|
5
5
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
@@ -13,7 +13,7 @@ export type APIResponseProps = {
|
|
|
13
13
|
startTime: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export async function defaultParseResponse<T>(client:
|
|
16
|
+
export async function defaultParseResponse<T>(client: Postpeer, props: APIResponseProps): Promise<T> {
|
|
17
17
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
18
|
const body = await (async () => {
|
|
19
19
|
// fetch refuses to read the body when the status code is 204.
|
package/src/internal/shims.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getDefaultFetch(): Fetch {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
throw new Error(
|
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new
|
|
19
|
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Postpeer({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RequestOptions } from './request-options';
|
|
2
2
|
import type { FilePropertyBag, Fetch } from './builtin-types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Postpeer } from '../client';
|
|
4
4
|
import { ReadableStreamFrom } from './shims';
|
|
5
5
|
|
|
6
6
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
@@ -74,7 +74,7 @@ export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
|
|
|
74
74
|
*/
|
|
75
75
|
export const maybeMultipartFormRequestOptions = async (
|
|
76
76
|
opts: RequestOptions,
|
|
77
|
-
fetch:
|
|
77
|
+
fetch: Postpeer | Fetch,
|
|
78
78
|
): Promise<RequestOptions> => {
|
|
79
79
|
if (!hasUploadableValue(opts.body)) return opts;
|
|
80
80
|
|
|
@@ -85,7 +85,7 @@ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknow
|
|
|
85
85
|
|
|
86
86
|
export const multipartFormRequestOptions = async (
|
|
87
87
|
opts: MultipartFormRequestOptions,
|
|
88
|
-
fetch:
|
|
88
|
+
fetch: Postpeer | Fetch,
|
|
89
89
|
): Promise<RequestOptions> => {
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
@@ -98,7 +98,7 @@ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>
|
|
|
98
98
|
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
99
99
|
* confusing error messages later on.
|
|
100
100
|
*/
|
|
101
|
-
function supportsFormData(fetchObject:
|
|
101
|
+
function supportsFormData(fetchObject: Postpeer | Fetch): Promise<boolean> {
|
|
102
102
|
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
|
103
103
|
const cached = supportsFormDataMap.get(fetch);
|
|
104
104
|
if (cached) return cached;
|
|
@@ -124,7 +124,7 @@ function supportsFormData(fetchObject: PostPeer | Fetch): Promise<boolean> {
|
|
|
124
124
|
|
|
125
125
|
export const createForm = async <T = Record<string, unknown>>(
|
|
126
126
|
body: T | undefined,
|
|
127
|
-
fetch:
|
|
127
|
+
fetch: Postpeer | Fetch,
|
|
128
128
|
): Promise<FormData> => {
|
|
129
129
|
if (!(await supportsFormData(fetch))) {
|
|
130
130
|
throw new TypeError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PostpeerError } from '../../core/error';
|
|
4
4
|
import { encodeUTF8 } from './bytes';
|
|
5
5
|
|
|
6
6
|
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
@@ -18,7 +18,7 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
|
|
|
18
18
|
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
throw new
|
|
21
|
+
throw new PostpeerError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const fromBase64 = (str: string): Uint8Array => {
|
|
@@ -36,5 +36,5 @@ export const fromBase64 = (str: string): Uint8Array => {
|
|
|
36
36
|
return buf;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
throw new
|
|
39
|
+
throw new PostpeerError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
40
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { hasOwn } from './values';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Postpeer } from '../../client';
|
|
5
5
|
import { RequestOptions } from '../request-options';
|
|
6
6
|
|
|
7
7
|
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
@@ -24,7 +24,7 @@ const levelNumbers = {
|
|
|
24
24
|
export const parseLogLevel = (
|
|
25
25
|
maybeLevel: string | undefined,
|
|
26
26
|
sourceName: string,
|
|
27
|
-
client:
|
|
27
|
+
client: Postpeer,
|
|
28
28
|
): LogLevel | undefined => {
|
|
29
29
|
if (!maybeLevel) {
|
|
30
30
|
return undefined;
|
|
@@ -60,7 +60,7 @@ const noopLogger = {
|
|
|
60
60
|
|
|
61
61
|
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
|
-
export function loggerFor(client:
|
|
63
|
+
export function loggerFor(client: Postpeer): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
65
65
|
const logLevel = client.logLevel ?? 'off';
|
|
66
66
|
if (!logger) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostpeerError } from '../../core/error';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
@@ -72,7 +72,7 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
72
72
|
return acc + spaces + arrows;
|
|
73
73
|
}, '');
|
|
74
74
|
|
|
75
|
-
throw new
|
|
75
|
+
throw new PostpeerError(
|
|
76
76
|
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
77
|
.map((e) => e.error)
|
|
78
78
|
.join('\n')}\n${path}\n${underline}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { PostpeerError } from '../../core/error';
|
|
4
4
|
|
|
5
5
|
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
6
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
@@ -39,7 +39,7 @@ export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
|
39
39
|
|
|
40
40
|
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
41
|
if (value == null) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new PostpeerError(`Expected a value to be given but received ${value} instead.`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return value;
|
|
@@ -47,10 +47,10 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
47
47
|
|
|
48
48
|
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
49
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new PostpeerError(`${name} must be an integer`);
|
|
51
51
|
}
|
|
52
52
|
if (n < 0) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new PostpeerError(`${name} must be a positive integer`);
|
|
54
54
|
}
|
|
55
55
|
return n;
|
|
56
56
|
};
|
|
@@ -59,14 +59,14 @@ export const coerceInteger = (value: unknown): number => {
|
|
|
59
59
|
if (typeof value === 'number') return Math.round(value);
|
|
60
60
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
61
|
|
|
62
|
-
throw new
|
|
62
|
+
throw new PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export const coerceFloat = (value: unknown): number => {
|
|
66
66
|
if (typeof value === 'number') return value;
|
|
67
67
|
if (typeof value === 'string') return parseFloat(value);
|
|
68
68
|
|
|
69
|
-
throw new
|
|
69
|
+
throw new PostpeerError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const coerceBoolean = (value: unknown): boolean => {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.4.0'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.4.0";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.4.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.4.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|