@afriex/sdk 5.1.0 → 6.1.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 +43 -0
- package/README.md +155 -148
- package/dist/cjs/client.d.ts +110 -0
- package/dist/cjs/client.js +231 -0
- package/dist/cjs/core/api-promise.d.ts +25 -0
- package/dist/cjs/core/api-promise.js +49 -0
- package/dist/cjs/core/errors.d.ts +78 -0
- package/dist/cjs/core/errors.js +143 -0
- package/dist/cjs/core/pagination.d.ts +47 -0
- package/dist/cjs/core/pagination.js +70 -0
- package/dist/cjs/core/resource.d.ts +18 -0
- package/dist/cjs/core/resource.js +36 -0
- package/dist/cjs/core/types.d.ts +43 -0
- package/dist/cjs/core/types.js +2 -0
- package/dist/cjs/generated/openapi.d.ts +5751 -0
- package/dist/cjs/generated/openapi.js +6 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/balance.d.ts +16 -0
- package/dist/cjs/resources/balance.js +19 -0
- package/dist/cjs/resources/checkout.d.ts +12 -0
- package/dist/cjs/resources/checkout.js +16 -0
- package/dist/cjs/resources/customers.d.ts +27 -0
- package/dist/cjs/resources/customers.js +56 -0
- package/dist/cjs/resources/media.d.ts +24 -0
- package/dist/cjs/resources/media.js +39 -0
- package/dist/cjs/resources/payment-batches.d.ts +41 -0
- package/dist/cjs/resources/payment-batches.js +76 -0
- package/dist/cjs/resources/payment-methods.d.ts +49 -0
- package/dist/cjs/resources/payment-methods.js +95 -0
- package/dist/cjs/resources/rates.d.ts +9 -0
- package/dist/cjs/resources/rates.js +13 -0
- package/dist/cjs/resources/sme-registration.d.ts +24 -0
- package/dist/cjs/resources/sme-registration.js +31 -0
- package/dist/cjs/resources/transactions.d.ts +39 -0
- package/dist/cjs/resources/transactions.js +67 -0
- package/dist/cjs/resources/webhooks.d.ts +43 -0
- package/dist/cjs/resources/webhooks.js +53 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/client.d.ts +110 -0
- package/dist/esm/client.js +227 -0
- package/dist/esm/core/api-promise.d.ts +25 -0
- package/dist/esm/core/api-promise.js +45 -0
- package/dist/esm/core/errors.d.ts +78 -0
- package/dist/esm/core/errors.js +126 -0
- package/dist/esm/core/pagination.d.ts +47 -0
- package/dist/esm/core/pagination.js +65 -0
- package/dist/esm/core/resource.d.ts +18 -0
- package/dist/esm/core/resource.js +30 -0
- package/dist/esm/core/types.d.ts +43 -0
- package/dist/esm/core/types.js +1 -0
- package/dist/esm/generated/openapi.d.ts +5751 -0
- package/dist/esm/generated/openapi.js +5 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/resources/balance.d.ts +16 -0
- package/dist/esm/resources/balance.js +15 -0
- package/dist/esm/resources/checkout.d.ts +12 -0
- package/dist/esm/resources/checkout.js +12 -0
- package/dist/esm/resources/customers.d.ts +27 -0
- package/dist/esm/resources/customers.js +52 -0
- package/dist/esm/resources/media.d.ts +24 -0
- package/dist/esm/resources/media.js +35 -0
- package/dist/esm/resources/payment-batches.d.ts +41 -0
- package/dist/esm/resources/payment-batches.js +72 -0
- package/dist/esm/resources/payment-methods.d.ts +49 -0
- package/dist/esm/resources/payment-methods.js +91 -0
- package/dist/esm/resources/rates.d.ts +9 -0
- package/dist/esm/resources/rates.js +9 -0
- package/dist/esm/resources/sme-registration.d.ts +24 -0
- package/dist/esm/resources/sme-registration.js +27 -0
- package/dist/esm/resources/transactions.d.ts +39 -0
- package/dist/esm/resources/transactions.js +63 -0
- package/dist/esm/resources/webhooks.d.ts +43 -0
- package/dist/esm/resources/webhooks.js +49 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/package.json +52 -68
- package/dist/index.d.ts +0 -54
- package/dist/index.js +0 -54
- package/dist/version.d.ts +0 -8
- package/dist/version.js +0 -8
- package/skills/afriex-go-live/SKILL.md +0 -386
- package/skills/afriex-sdk/SKILL.md +0 -275
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ErrorResponse } from '../generated/openapi.js';
|
|
2
|
+
/** Base class for every error the SDK throws. */
|
|
3
|
+
export declare class AfriexError extends Error {
|
|
4
|
+
constructor(message: string, options?: {
|
|
5
|
+
cause?: unknown;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The API answered with a status outside 2xx. Catch a subclass to handle one
|
|
10
|
+
* status, or this class to handle any of them.
|
|
11
|
+
*/
|
|
12
|
+
export declare class APIError extends AfriexError {
|
|
13
|
+
/** The HTTP status. */
|
|
14
|
+
readonly status: number;
|
|
15
|
+
/** Machine-readable error code from the body, such as `DUPLICATE_REQUEST`. */
|
|
16
|
+
readonly code: string | undefined;
|
|
17
|
+
/** The `details` object from the body, when the API sent one. */
|
|
18
|
+
readonly details: ErrorResponse['details'] | undefined;
|
|
19
|
+
/** The response body as received, parsed when it was JSON. */
|
|
20
|
+
readonly body: unknown;
|
|
21
|
+
readonly headers: Headers;
|
|
22
|
+
/** The `x-request-id` header. Quote it when you contact support. */
|
|
23
|
+
readonly requestId: string | undefined;
|
|
24
|
+
constructor(status: number, body: unknown, headers: Headers);
|
|
25
|
+
/** Builds the subclass that matches the status. */
|
|
26
|
+
static from(status: number, body: unknown, headers: Headers): APIError;
|
|
27
|
+
private static messageFrom;
|
|
28
|
+
}
|
|
29
|
+
/** 400: the request was malformed. Nothing was done. */
|
|
30
|
+
export declare class BadRequestError extends APIError {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 401: the API key is missing, wrong, revoked, or lacks the permission this
|
|
34
|
+
* endpoint needs. The API does not say which.
|
|
35
|
+
*/
|
|
36
|
+
export declare class AuthenticationError extends APIError {
|
|
37
|
+
}
|
|
38
|
+
/** 403: the request is not allowed, for example from an address outside your IP allowlist. */
|
|
39
|
+
export declare class PermissionDeniedError extends APIError {
|
|
40
|
+
}
|
|
41
|
+
/** 404: the resource does not exist, or belongs to another business. */
|
|
42
|
+
export declare class NotFoundError extends APIError {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 409: for a transaction, `DUPLICATE_REQUEST` means its idempotency key or
|
|
46
|
+
* reference is already taken. Look the transaction up by its reference rather
|
|
47
|
+
* than sending it again.
|
|
48
|
+
*/
|
|
49
|
+
export declare class ConflictError extends APIError {
|
|
50
|
+
}
|
|
51
|
+
/** 422: the request was well formed but failed validation. Nothing was done. */
|
|
52
|
+
export declare class UnprocessableEntityError extends APIError {
|
|
53
|
+
}
|
|
54
|
+
/** 429: the request was not processed. Retry after `retryAfter` seconds. */
|
|
55
|
+
export declare class RateLimitError extends APIError {
|
|
56
|
+
/** Seconds to wait, from the `Retry-After` header. */
|
|
57
|
+
get retryAfter(): number | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** 500 or above. */
|
|
60
|
+
export declare class InternalServerError extends APIError {
|
|
61
|
+
}
|
|
62
|
+
/** No response arrived: DNS, TLS, refused or reset connection. */
|
|
63
|
+
export declare class APIConnectionError extends AfriexError {
|
|
64
|
+
constructor(message?: string, options?: {
|
|
65
|
+
cause?: unknown;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** No response arrived within the timeout. */
|
|
69
|
+
export declare class APIConnectionTimeoutError extends APIConnectionError {
|
|
70
|
+
constructor(message?: string);
|
|
71
|
+
}
|
|
72
|
+
/** The request was cancelled through the `signal` you passed. */
|
|
73
|
+
export declare class APIUserAbortError extends AfriexError {
|
|
74
|
+
constructor(message?: string);
|
|
75
|
+
}
|
|
76
|
+
/** A webhook's signature did not match its body, or no public key was configured. */
|
|
77
|
+
export declare class WebhookVerificationError extends AfriexError {
|
|
78
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Base class for every error the SDK throws. */
|
|
2
|
+
export class AfriexError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The API answered with a status outside 2xx. Catch a subclass to handle one
|
|
10
|
+
* status, or this class to handle any of them.
|
|
11
|
+
*/
|
|
12
|
+
export class APIError extends AfriexError {
|
|
13
|
+
/** The HTTP status. */
|
|
14
|
+
status;
|
|
15
|
+
/** Machine-readable error code from the body, such as `DUPLICATE_REQUEST`. */
|
|
16
|
+
code;
|
|
17
|
+
/** The `details` object from the body, when the API sent one. */
|
|
18
|
+
details;
|
|
19
|
+
/** The response body as received, parsed when it was JSON. */
|
|
20
|
+
body;
|
|
21
|
+
headers;
|
|
22
|
+
/** The `x-request-id` header. Quote it when you contact support. */
|
|
23
|
+
requestId;
|
|
24
|
+
constructor(status, body, headers) {
|
|
25
|
+
super(APIError.messageFrom(status, body));
|
|
26
|
+
this.status = status;
|
|
27
|
+
this.body = body;
|
|
28
|
+
this.headers = headers;
|
|
29
|
+
this.requestId = headers.get('x-request-id') ?? undefined;
|
|
30
|
+
const parsed = isErrorResponse(body) ? body : undefined;
|
|
31
|
+
this.code = parsed?.code;
|
|
32
|
+
this.details = parsed?.details;
|
|
33
|
+
}
|
|
34
|
+
/** Builds the subclass that matches the status. */
|
|
35
|
+
static from(status, body, headers) {
|
|
36
|
+
if (status === 400)
|
|
37
|
+
return new BadRequestError(status, body, headers);
|
|
38
|
+
if (status === 401)
|
|
39
|
+
return new AuthenticationError(status, body, headers);
|
|
40
|
+
if (status === 403)
|
|
41
|
+
return new PermissionDeniedError(status, body, headers);
|
|
42
|
+
if (status === 404)
|
|
43
|
+
return new NotFoundError(status, body, headers);
|
|
44
|
+
if (status === 409)
|
|
45
|
+
return new ConflictError(status, body, headers);
|
|
46
|
+
if (status === 422) {
|
|
47
|
+
return new UnprocessableEntityError(status, body, headers);
|
|
48
|
+
}
|
|
49
|
+
if (status === 429)
|
|
50
|
+
return new RateLimitError(status, body, headers);
|
|
51
|
+
if (status >= 500)
|
|
52
|
+
return new InternalServerError(status, body, headers);
|
|
53
|
+
return new APIError(status, body, headers);
|
|
54
|
+
}
|
|
55
|
+
static messageFrom(status, body) {
|
|
56
|
+
if (isErrorResponse(body)) {
|
|
57
|
+
const message = body.details?.friendlyMessage ?? body.error ?? body.details?.errorMessage;
|
|
58
|
+
if (message) {
|
|
59
|
+
return body.code ? `${status} ${body.code}: ${message}` : `${status} ${message}`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (typeof body === 'string' && body)
|
|
63
|
+
return `${status} ${body}`;
|
|
64
|
+
return `${status} status code (no body)`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** 400: the request was malformed. Nothing was done. */
|
|
68
|
+
export class BadRequestError extends APIError {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 401: the API key is missing, wrong, revoked, or lacks the permission this
|
|
72
|
+
* endpoint needs. The API does not say which.
|
|
73
|
+
*/
|
|
74
|
+
export class AuthenticationError extends APIError {
|
|
75
|
+
}
|
|
76
|
+
/** 403: the request is not allowed, for example from an address outside your IP allowlist. */
|
|
77
|
+
export class PermissionDeniedError extends APIError {
|
|
78
|
+
}
|
|
79
|
+
/** 404: the resource does not exist, or belongs to another business. */
|
|
80
|
+
export class NotFoundError extends APIError {
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 409: for a transaction, `DUPLICATE_REQUEST` means its idempotency key or
|
|
84
|
+
* reference is already taken. Look the transaction up by its reference rather
|
|
85
|
+
* than sending it again.
|
|
86
|
+
*/
|
|
87
|
+
export class ConflictError extends APIError {
|
|
88
|
+
}
|
|
89
|
+
/** 422: the request was well formed but failed validation. Nothing was done. */
|
|
90
|
+
export class UnprocessableEntityError extends APIError {
|
|
91
|
+
}
|
|
92
|
+
/** 429: the request was not processed. Retry after `retryAfter` seconds. */
|
|
93
|
+
export class RateLimitError extends APIError {
|
|
94
|
+
/** Seconds to wait, from the `Retry-After` header. */
|
|
95
|
+
get retryAfter() {
|
|
96
|
+
const value = Number(this.headers.get('retry-after'));
|
|
97
|
+
return Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** 500 or above. */
|
|
101
|
+
export class InternalServerError extends APIError {
|
|
102
|
+
}
|
|
103
|
+
/** No response arrived: DNS, TLS, refused or reset connection. */
|
|
104
|
+
export class APIConnectionError extends AfriexError {
|
|
105
|
+
constructor(message = 'Connection error.', options) {
|
|
106
|
+
super(message, options);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** No response arrived within the timeout. */
|
|
110
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
111
|
+
constructor(message = 'Request timed out.') {
|
|
112
|
+
super(message);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The request was cancelled through the `signal` you passed. */
|
|
116
|
+
export class APIUserAbortError extends AfriexError {
|
|
117
|
+
constructor(message = 'Request was aborted.') {
|
|
118
|
+
super(message);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** A webhook's signature did not match its body, or no public key was configured. */
|
|
122
|
+
export class WebhookVerificationError extends AfriexError {
|
|
123
|
+
}
|
|
124
|
+
function isErrorResponse(body) {
|
|
125
|
+
return typeof body === 'object' && body !== null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { APIPromise, type RawResponse } from './api-promise.js';
|
|
2
|
+
/** Fetches one page of a list, given the page number and size. */
|
|
3
|
+
export type PageFetcher<Item> = (page: number, limit: number) => PagePromise<Item>;
|
|
4
|
+
interface PageBody<Item> {
|
|
5
|
+
data: Item[];
|
|
6
|
+
total: number;
|
|
7
|
+
page: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One page of a list endpoint: `{data, total, page}` as the API returns it,
|
|
11
|
+
* plus helpers to fetch the pages after it. Iterate it with `for await` to
|
|
12
|
+
* walk every item on this page and the pages after it.
|
|
13
|
+
*/
|
|
14
|
+
export declare class Page<Item> implements AsyncIterable<Item> {
|
|
15
|
+
#private;
|
|
16
|
+
/** The items on this page. */
|
|
17
|
+
readonly data: Item[];
|
|
18
|
+
/** The number of items that match your filters, across all pages. */
|
|
19
|
+
readonly total: number;
|
|
20
|
+
/** This page's number. The first page is `0`. */
|
|
21
|
+
readonly page: number;
|
|
22
|
+
/** The page size used to fetch the next page. */
|
|
23
|
+
readonly limit: number;
|
|
24
|
+
constructor(body: PageBody<Item>, requested: {
|
|
25
|
+
page?: number;
|
|
26
|
+
limit?: number;
|
|
27
|
+
}, fetchPage: PageFetcher<Item>);
|
|
28
|
+
/** Whether another page follows this one. The API has no cursor, so this compares against `total`. */
|
|
29
|
+
hasNextPage(): boolean;
|
|
30
|
+
/** Fetches the next page. Call `hasNextPage()` first. */
|
|
31
|
+
getNextPage(): Promise<Page<Item>>;
|
|
32
|
+
/** Yields this page, then each page after it. */
|
|
33
|
+
iterPages(): AsyncGenerator<Page<Item>>;
|
|
34
|
+
[Symbol.asyncIterator](): AsyncGenerator<Item>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What a list method returns. Await it for the first `Page`, or iterate it
|
|
38
|
+
* with `for await` to walk every item across all pages.
|
|
39
|
+
*/
|
|
40
|
+
export declare class PagePromise<Item> extends APIPromise<Page<Item>> implements AsyncIterable<Item> {
|
|
41
|
+
constructor(responsePromise: Promise<RawResponse>, requested: {
|
|
42
|
+
page?: number;
|
|
43
|
+
limit?: number;
|
|
44
|
+
}, fetchPage: PageFetcher<Item>);
|
|
45
|
+
[Symbol.asyncIterator](): AsyncGenerator<Item>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { APIPromise } from './api-promise.js';
|
|
2
|
+
import { AfriexError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* One page of a list endpoint: `{data, total, page}` as the API returns it,
|
|
5
|
+
* plus helpers to fetch the pages after it. Iterate it with `for await` to
|
|
6
|
+
* walk every item on this page and the pages after it.
|
|
7
|
+
*/
|
|
8
|
+
export class Page {
|
|
9
|
+
/** The items on this page. */
|
|
10
|
+
data;
|
|
11
|
+
/** The number of items that match your filters, across all pages. */
|
|
12
|
+
total;
|
|
13
|
+
/** This page's number. The first page is `0`. */
|
|
14
|
+
page;
|
|
15
|
+
/** The page size used to fetch the next page. */
|
|
16
|
+
limit;
|
|
17
|
+
#fetchPage;
|
|
18
|
+
constructor(body, requested, fetchPage) {
|
|
19
|
+
this.data = body.data ?? [];
|
|
20
|
+
this.total = body.total ?? 0;
|
|
21
|
+
this.page = body.page ?? requested.page ?? 0;
|
|
22
|
+
// Without an explicit limit the API used its default, which a full page
|
|
23
|
+
// reveals. A short page is the last one whatever the limit was.
|
|
24
|
+
this.limit = requested.limit ?? Math.max(this.data.length, 1);
|
|
25
|
+
this.#fetchPage = fetchPage;
|
|
26
|
+
}
|
|
27
|
+
/** Whether another page follows this one. The API has no cursor, so this compares against `total`. */
|
|
28
|
+
hasNextPage() {
|
|
29
|
+
return this.data.length > 0 && (this.page + 1) * this.limit < this.total;
|
|
30
|
+
}
|
|
31
|
+
/** Fetches the next page. Call `hasNextPage()` first. */
|
|
32
|
+
getNextPage() {
|
|
33
|
+
if (!this.hasNextPage()) {
|
|
34
|
+
throw new AfriexError('No next page. Check hasNextPage() before calling getNextPage().');
|
|
35
|
+
}
|
|
36
|
+
return this.#fetchPage(this.page + 1, this.limit);
|
|
37
|
+
}
|
|
38
|
+
/** Yields this page, then each page after it. */
|
|
39
|
+
async *iterPages() {
|
|
40
|
+
let current = this;
|
|
41
|
+
yield current;
|
|
42
|
+
while (current.hasNextPage()) {
|
|
43
|
+
current = await current.getNextPage();
|
|
44
|
+
yield current;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async *[Symbol.asyncIterator]() {
|
|
48
|
+
for await (const page of this.iterPages()) {
|
|
49
|
+
yield* page.data;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* What a list method returns. Await it for the first `Page`, or iterate it
|
|
55
|
+
* with `for await` to walk every item across all pages.
|
|
56
|
+
*/
|
|
57
|
+
export class PagePromise extends APIPromise {
|
|
58
|
+
constructor(responsePromise, requested, fetchPage) {
|
|
59
|
+
super(responsePromise, (raw) => new Page(raw.body, requested, fetchPage));
|
|
60
|
+
}
|
|
61
|
+
async *[Symbol.asyncIterator]() {
|
|
62
|
+
const page = await this;
|
|
63
|
+
yield* page;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Afriex } from '../client.js';
|
|
2
|
+
export declare abstract class APIResource {
|
|
3
|
+
protected readonly _client: Afriex;
|
|
4
|
+
constructor(client: Afriex);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Builds a request path, encoding each interpolated value. An empty id would
|
|
8
|
+
* otherwise turn `GET /customer/{id}` into `GET /customer`, the list endpoint,
|
|
9
|
+
* so it throws instead.
|
|
10
|
+
*/
|
|
11
|
+
export declare function path(strings: TemplateStringsArray, ...values: string[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns a response's `data`. The spec marks `data` optional on most
|
|
14
|
+
* responses, but a 2xx always carries it, so its type drops `undefined`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function data<T>(response: {
|
|
17
|
+
data?: T;
|
|
18
|
+
}): Exclude<T, undefined>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AfriexError } from './errors.js';
|
|
2
|
+
export class APIResource {
|
|
3
|
+
_client;
|
|
4
|
+
constructor(client) {
|
|
5
|
+
this._client = client;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Builds a request path, encoding each interpolated value. An empty id would
|
|
10
|
+
* otherwise turn `GET /customer/{id}` into `GET /customer`, the list endpoint,
|
|
11
|
+
* so it throws instead.
|
|
12
|
+
*/
|
|
13
|
+
export function path(strings, ...values) {
|
|
14
|
+
return strings.reduce((result, part, index) => {
|
|
15
|
+
if (index === 0)
|
|
16
|
+
return part;
|
|
17
|
+
const value = values[index - 1];
|
|
18
|
+
if (typeof value !== 'string' || value.trim() === '') {
|
|
19
|
+
throw new AfriexError(`Expected a non-empty string for the path parameter in "${strings.join('{}')}", got ${JSON.stringify(value)}.`);
|
|
20
|
+
}
|
|
21
|
+
return result + encodeURIComponent(value) + part;
|
|
22
|
+
}, '');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns a response's `data`. The spec marks `data` optional on most
|
|
26
|
+
* responses, but a 2xx always carries it, so its type drops `undefined`.
|
|
27
|
+
*/
|
|
28
|
+
export function data(response) {
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { operations } from '../generated/openapi.js';
|
|
2
|
+
export type OperationId = keyof operations;
|
|
3
|
+
type JSONContent<T> = T extends {
|
|
4
|
+
content: {
|
|
5
|
+
'application/json': infer B;
|
|
6
|
+
};
|
|
7
|
+
} ? B : never;
|
|
8
|
+
/** The JSON request body of an operation. */
|
|
9
|
+
export type Body<K extends OperationId> = operations[K] extends {
|
|
10
|
+
requestBody?: infer R;
|
|
11
|
+
} ? JSONContent<NonNullable<R>> : never;
|
|
12
|
+
/** The query parameters of an operation. */
|
|
13
|
+
export type Query<K extends OperationId> = operations[K] extends {
|
|
14
|
+
parameters: {
|
|
15
|
+
query?: infer Q;
|
|
16
|
+
};
|
|
17
|
+
} ? NonNullable<Q> : never;
|
|
18
|
+
type SuccessStatus = 200 | 201 | 202;
|
|
19
|
+
/** The JSON body of an operation's success response. */
|
|
20
|
+
export type Response<K extends OperationId> = operations[K] extends {
|
|
21
|
+
responses: infer R;
|
|
22
|
+
} ? JSONContent<R[Extract<keyof R, SuccessStatus>]> : never;
|
|
23
|
+
/**
|
|
24
|
+
* The `data` field of an operation's success response. The spec marks `data`
|
|
25
|
+
* optional on most responses, but a 2xx always carries it.
|
|
26
|
+
*/
|
|
27
|
+
export type Data<K extends OperationId> = Response<K> extends {
|
|
28
|
+
data?: infer D;
|
|
29
|
+
} ? Exclude<D, undefined> : never;
|
|
30
|
+
/** The item type of a paginated operation. */
|
|
31
|
+
export type Item<K extends OperationId> = Data<K> extends ReadonlyArray<infer I> ? I : never;
|
|
32
|
+
/** Options that apply to a single request, passed as each method's last argument. */
|
|
33
|
+
export interface RequestOptions {
|
|
34
|
+
/** Milliseconds to wait for a response. Overrides the client's `timeout`. */
|
|
35
|
+
timeout?: number;
|
|
36
|
+
/** Overrides the client's `maxRetries` for this request. */
|
|
37
|
+
maxRetries?: number;
|
|
38
|
+
/** Extra headers. A value of `null` removes a header the SDK would send. */
|
|
39
|
+
headers?: Record<string, string | null | undefined>;
|
|
40
|
+
/** Cancels the request when aborted. */
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|