@tolt/api 1.0.0 → 1.2.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/README.md +43 -15
- package/dist/BaseClient.js +1 -1
- package/dist/api/resources/embedTokens/client/Client.d.ts +1 -1
- package/dist/api/resources/embedTokens/client/Client.js +1 -1
- package/dist/api/resources/embedTokens/client/requests/CreateEmbedTokenRequest.d.ts +8 -2
- package/dist/api/resources/transactions/client/requests/CreateTransactionRequest.d.ts +1 -1
- package/dist/api/types/EmbedToken.d.ts +2 -0
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tolt/api
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for the
|
|
3
|
+
TypeScript SDK for the Tolt API (v2). Run it on your server: it needs your secret API key. Requires Node 18 or newer.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -13,25 +13,53 @@ npm install @tolt/api
|
|
|
13
13
|
```ts
|
|
14
14
|
import { ToltApiClient } from "@tolt/api";
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
baseUrl: "https://api.tolt.com",
|
|
18
|
-
token: process.env.TOLT_API_KEY!, // your Tolt API key
|
|
19
|
-
});
|
|
16
|
+
const tolt = new ToltApiClient({ token: process.env.TOLT_API_KEY! });
|
|
20
17
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
18
|
+
const { data: partner } = await tolt.partners.get({ id: "part_8fKq2LmZx7RtYw3nVbHc5dPj" });
|
|
19
|
+
|
|
20
|
+
for await (const customer of await tolt.customers.list()) {
|
|
21
|
+
console.log(customer.id);
|
|
22
|
+
}
|
|
24
23
|
```
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
Single-item calls return the API envelope, so read `.data`. `list` returns a page: iterate it with `for await` to walk every page, or read `page.data` for one page.
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
Resources: `partners`, `customers`, `transactions`, `commissions`, `links`, `clicks`, `promotionCodes`, `programs`, `groups`, `flows`, `reports`, `embedTokens`.
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
## Errors
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { ToltApi, ToltApiError, ToltApiTimeoutError } from "@tolt/api";
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await tolt.partners.get({ id: "part_8fKq2LmZx7RtYw3nVbHc5dPj" });
|
|
36
|
+
} catch (err) {
|
|
37
|
+
if (err instanceof ToltApi.NotFoundError) {
|
|
38
|
+
// err.body.code === "not_found"
|
|
39
|
+
} else if (err instanceof ToltApiTimeoutError) {
|
|
40
|
+
// no response within timeoutInSeconds
|
|
41
|
+
} else if (err instanceof ToltApiError) {
|
|
42
|
+
console.error(err.statusCode, err.body, err.requestId);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Retries and timeouts
|
|
48
|
+
|
|
49
|
+
Failed requests (408, 429, 5xx) are retried twice with backoff. Calls that create something (every `create`, and `transactions.rerunFlows`) are never retried, so a server error can't create a duplicate. Override per client or per call:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const tolt = new ToltApiClient({ token: process.env.TOLT_API_KEY!, maxRetries: 3, timeoutInSeconds: 30 });
|
|
33
53
|
```
|
|
34
54
|
|
|
35
|
-
|
|
55
|
+
The client talks to `https://platform.tolt.com` by default. Pass `baseUrl` to point it elsewhere.
|
|
56
|
+
|
|
57
|
+
## Development
|
|
36
58
|
|
|
37
|
-
|
|
59
|
+
`src/` is generated by [Fern](https://buildwithfern.com) from the API's OpenAPI spec in [toltapp/tolt-sdks](https://github.com/toltapp/tolt-sdks), which opens a pull request here when the spec changes. Don't edit `src/` by hand.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm ci
|
|
63
|
+
npm run build
|
|
64
|
+
npm test
|
|
65
|
+
```
|
package/dist/BaseClient.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as core from "./core/index.js";
|
|
|
5
5
|
export function normalizeClientOptions(options) {
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
|
-
"User-Agent": "tolt-typescript/1.
|
|
8
|
+
"User-Agent": "tolt-typescript/1.2.0",
|
|
9
9
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
10
10
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
11
11
|
}, options?.headers);
|
|
@@ -11,7 +11,7 @@ export declare class EmbedTokensClient {
|
|
|
11
11
|
protected readonly _options: NormalizedClientOptionsWithAuth<EmbedTokensClient.Options>;
|
|
12
12
|
constructor(options: EmbedTokensClient.Options);
|
|
13
13
|
/**
|
|
14
|
-
* Mint a short-lived, partner-scoped token for the embedded referral dashboard. Safe to send to the browser.
|
|
14
|
+
* Mint a short-lived, partner-scoped token for the embedded referral dashboard. Safe to send to the browser. With partner (email and program_id), the partner is created when the program has none with that email, so one call covers a user's first visit.
|
|
15
15
|
*
|
|
16
16
|
* @param {ToltApi.CreateEmbedTokenRequest} request
|
|
17
17
|
* @param {EmbedTokensClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -12,7 +12,7 @@ export class EmbedTokensClient {
|
|
|
12
12
|
this._options = normalizeClientOptionsWithAuth(options);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Mint a short-lived, partner-scoped token for the embedded referral dashboard. Safe to send to the browser.
|
|
15
|
+
* Mint a short-lived, partner-scoped token for the embedded referral dashboard. Safe to send to the browser. With partner (email and program_id), the partner is created when the program has none with that email, so one call covers a user's first visit.
|
|
16
16
|
*
|
|
17
17
|
* @param {ToltApi.CreateEmbedTokenRequest} request
|
|
18
18
|
* @param {EmbedTokensClient.RequestOptions} requestOptions - Request-specific configuration.
|
|
@@ -5,17 +5,23 @@
|
|
|
5
5
|
export interface CreateEmbedTokenRequest {
|
|
6
6
|
/** Id of an existing partner (part_...). Send this or partner, not both. */
|
|
7
7
|
partner_id?: string;
|
|
8
|
-
/**
|
|
8
|
+
/** Find the partner by email within the program, or create them (active, with a referral link) when the program has no partner with that email. Send this or partner_id, not both. */
|
|
9
9
|
partner?: CreateEmbedTokenRequest.Partner;
|
|
10
10
|
}
|
|
11
11
|
export declare namespace CreateEmbedTokenRequest {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Find the partner by email within the program, or create them (active, with a referral link) when the program has no partner with that email. Send this or partner_id, not both.
|
|
14
14
|
*/
|
|
15
15
|
interface Partner {
|
|
16
16
|
/** Email of the partner, matched without regard to case. */
|
|
17
17
|
email: string;
|
|
18
18
|
/** Program the partner belongs to (prg_...). */
|
|
19
19
|
program_id: string;
|
|
20
|
+
/** First name, used only when the partner is created. */
|
|
21
|
+
first_name?: string | undefined;
|
|
22
|
+
/** Last name, used only when the partner is created. */
|
|
23
|
+
last_name?: string | undefined;
|
|
24
|
+
/** Group for a newly created partner. Defaults to the program's default group. */
|
|
25
|
+
group_id?: string | undefined;
|
|
20
26
|
}
|
|
21
27
|
}
|
|
@@ -17,7 +17,7 @@ export interface CreateTransactionRequest {
|
|
|
17
17
|
product_id?: string;
|
|
18
18
|
/** Readable name of the purchased product, such as Pro plan. It is saved as the transaction's product name, which revenue_by_product groups revenue by; flows match on product_id, not on this name. */
|
|
19
19
|
product_name?: string;
|
|
20
|
-
/** The payment amount in the smallest unit of the program currency (cents for USD); percentage commissions are calculated from it. */
|
|
20
|
+
/** The payment amount in the smallest unit of the program currency (cents for USD); percentage commissions are calculated from it. It must be 0 or more: to reverse a payment, refund its transaction instead of recording a negative amount. */
|
|
21
21
|
amount: number;
|
|
22
22
|
/** Id of the customer who paid (cus_...), as returned when listing customers. The transaction goes to that customer's partner and program, and the customer becomes active. */
|
|
23
23
|
customer_id: string;
|
package/dist/environments.d.ts
CHANGED
package/dist/environments.js
CHANGED