@tolt/api 1.1.0 → 1.3.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.
Files changed (69) hide show
  1. package/README.md +43 -15
  2. package/dist/BaseClient.js +1 -1
  3. package/dist/Client.d.ts +3 -0
  4. package/dist/Client.js +4 -0
  5. package/dist/api/resources/embedTokens/client/Client.d.ts +1 -1
  6. package/dist/api/resources/embedTokens/client/Client.js +1 -1
  7. package/dist/api/resources/embedTokens/client/requests/CreateEmbedTokenRequest.d.ts +8 -2
  8. package/dist/api/resources/index.d.ts +3 -0
  9. package/dist/api/resources/index.js +3 -0
  10. package/dist/api/resources/partnerTags/client/Client.d.ts +118 -0
  11. package/dist/api/resources/partnerTags/client/Client.js +352 -0
  12. package/dist/api/resources/partnerTags/client/index.d.ts +1 -0
  13. package/dist/api/resources/partnerTags/client/index.js +1 -0
  14. package/dist/api/resources/partnerTags/client/requests/CreatePartnerTagRequest.d.ts +16 -0
  15. package/dist/api/resources/partnerTags/client/requests/CreatePartnerTagRequest.js +2 -0
  16. package/dist/api/resources/partnerTags/client/requests/DeletePartnerTagRequest.d.ts +9 -0
  17. package/dist/api/resources/partnerTags/client/requests/DeletePartnerTagRequest.js +2 -0
  18. package/dist/api/resources/partnerTags/client/requests/GetPartnerTagRequest.d.ts +9 -0
  19. package/dist/api/resources/partnerTags/client/requests/GetPartnerTagRequest.js +2 -0
  20. package/dist/api/resources/partnerTags/client/requests/ListPartnerTagsRequest.d.ts +29 -0
  21. package/dist/api/resources/partnerTags/client/requests/ListPartnerTagsRequest.js +2 -0
  22. package/dist/api/resources/partnerTags/client/requests/UpdatePartnerTagRequest.d.ts +15 -0
  23. package/dist/api/resources/partnerTags/client/requests/UpdatePartnerTagRequest.js +2 -0
  24. package/dist/api/resources/partnerTags/client/requests/index.d.ts +5 -0
  25. package/dist/api/resources/partnerTags/client/requests/index.js +1 -0
  26. package/dist/api/resources/partnerTags/exports.d.ts +2 -0
  27. package/dist/api/resources/partnerTags/exports.js +3 -0
  28. package/dist/api/resources/partnerTags/index.d.ts +2 -0
  29. package/dist/api/resources/partnerTags/index.js +2 -0
  30. package/dist/api/resources/partnerTags/types/CreatePartnerTagResponse.d.ts +6 -0
  31. package/dist/api/resources/partnerTags/types/CreatePartnerTagResponse.js +2 -0
  32. package/dist/api/resources/partnerTags/types/DeletePartnerTagResponse.d.ts +6 -0
  33. package/dist/api/resources/partnerTags/types/DeletePartnerTagResponse.js +2 -0
  34. package/dist/api/resources/partnerTags/types/GetPartnerTagResponse.d.ts +6 -0
  35. package/dist/api/resources/partnerTags/types/GetPartnerTagResponse.js +2 -0
  36. package/dist/api/resources/partnerTags/types/ListPartnerTagsRequestOrder.d.ts +6 -0
  37. package/dist/api/resources/partnerTags/types/ListPartnerTagsRequestOrder.js +6 -0
  38. package/dist/api/resources/partnerTags/types/ListPartnerTagsRequestSort.d.ts +6 -0
  39. package/dist/api/resources/partnerTags/types/ListPartnerTagsRequestSort.js +6 -0
  40. package/dist/api/resources/partnerTags/types/ListPartnerTagsResponse.d.ts +11 -0
  41. package/dist/api/resources/partnerTags/types/ListPartnerTagsResponse.js +2 -0
  42. package/dist/api/resources/partnerTags/types/UpdatePartnerTagResponse.d.ts +6 -0
  43. package/dist/api/resources/partnerTags/types/UpdatePartnerTagResponse.js +2 -0
  44. package/dist/api/resources/partnerTags/types/index.d.ts +7 -0
  45. package/dist/api/resources/partnerTags/types/index.js +7 -0
  46. package/dist/api/resources/partners/client/Client.d.ts +43 -0
  47. package/dist/api/resources/partners/client/Client.js +132 -1
  48. package/dist/api/resources/partners/client/requests/AddPartnerTagsRequest.d.ts +12 -0
  49. package/dist/api/resources/partners/client/requests/AddPartnerTagsRequest.js +2 -0
  50. package/dist/api/resources/partners/client/requests/ListPartnersRequest.d.ts +2 -0
  51. package/dist/api/resources/partners/client/requests/RemovePartnerTagRequest.d.ts +11 -0
  52. package/dist/api/resources/partners/client/requests/RemovePartnerTagRequest.js +2 -0
  53. package/dist/api/resources/partners/client/requests/index.d.ts +2 -0
  54. package/dist/api/resources/partners/types/AddPartnerTagsResponse.d.ts +6 -0
  55. package/dist/api/resources/partners/types/AddPartnerTagsResponse.js +2 -0
  56. package/dist/api/resources/partners/types/RemovePartnerTagResponse.d.ts +6 -0
  57. package/dist/api/resources/partners/types/RemovePartnerTagResponse.js +2 -0
  58. package/dist/api/resources/partners/types/index.d.ts +2 -0
  59. package/dist/api/resources/partners/types/index.js +2 -0
  60. package/dist/api/resources/transactions/client/requests/CreateTransactionRequest.d.ts +1 -1
  61. package/dist/api/types/EmbedToken.d.ts +2 -0
  62. package/dist/api/types/PartnerDetails.d.ts +2 -0
  63. package/dist/api/types/PartnerTag.d.ts +11 -0
  64. package/dist/api/types/PartnerTag.js +2 -0
  65. package/dist/api/types/PartnerTagSummary.d.ts +5 -0
  66. package/dist/api/types/PartnerTagSummary.js +2 -0
  67. package/dist/api/types/index.d.ts +2 -0
  68. package/dist/api/types/index.js +2 -0
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tolt/api
2
2
 
3
- TypeScript SDK for the [Tolt](https://tolt.com) public API (v2). Generated from our OpenAPI spec with [Fern](https://buildwithfern.com); do not edit by hand.
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 client = new ToltApiClient({
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 transactions = await client.transactions.list();
22
- const overview = await client.reports.overview();
23
- const clicks = await client.clicks.list();
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
- Sub-clients cover the whole API: `transactions`, `commissions`, `customers`, `partners`, `programs`, `links`, `promotionCodes`, `groups`, `flows`, `clicks`, `reports`. Every path, request, and response is typed from the spec.
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
- ## Build
27
+ Resources: `partners`, `customers`, `transactions`, `commissions`, `links`, `clicks`, `promotionCodes`, `programs`, `groups`, `flows`, `reports`, `embedTokens`.
29
28
 
30
- ```bash
31
- npm install # runs the build via the prepare script
32
- npm run build # -> dist/
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
- ## Regenerating
55
+ The client talks to `https://platform.tolt.com` by default. Pass `baseUrl` to point it elsewhere.
56
+
57
+ ## Development
36
58
 
37
- This package is generated. Regenerate it from the OpenAPI spec in the `tolt-sdks-v2` Fern workspace (`fern generate --local`).
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
+ ```
@@ -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.1.0",
8
+ "User-Agent": "tolt-typescript/1.3.0",
9
9
  "X-Fern-Runtime": core.RUNTIME.type,
10
10
  "X-Fern-Runtime-Version": core.RUNTIME.version,
11
11
  }, options?.headers);
package/dist/Client.d.ts CHANGED
@@ -6,6 +6,7 @@ import { FlowsClient } from "./api/resources/flows/client/Client.js";
6
6
  import { GroupsClient } from "./api/resources/groups/client/Client.js";
7
7
  import { LinksClient } from "./api/resources/links/client/Client.js";
8
8
  import { PartnersClient } from "./api/resources/partners/client/Client.js";
9
+ import { PartnerTagsClient } from "./api/resources/partnerTags/client/Client.js";
9
10
  import { ProgramsClient } from "./api/resources/programs/client/Client.js";
10
11
  import { PromotionCodesClient } from "./api/resources/promotionCodes/client/Client.js";
11
12
  import { ReportsClient } from "./api/resources/reports/client/Client.js";
@@ -25,6 +26,7 @@ export declare class ToltApiClient {
25
26
  protected _flows: FlowsClient | undefined;
26
27
  protected _clicks: ClicksClient | undefined;
27
28
  protected _partners: PartnersClient | undefined;
29
+ protected _partnerTags: PartnerTagsClient | undefined;
28
30
  protected _programs: ProgramsClient | undefined;
29
31
  protected _customers: CustomersClient | undefined;
30
32
  protected _commissions: CommissionsClient | undefined;
@@ -38,6 +40,7 @@ export declare class ToltApiClient {
38
40
  get flows(): FlowsClient;
39
41
  get clicks(): ClicksClient;
40
42
  get partners(): PartnersClient;
43
+ get partnerTags(): PartnerTagsClient;
41
44
  get programs(): ProgramsClient;
42
45
  get customers(): CustomersClient;
43
46
  get commissions(): CommissionsClient;
package/dist/Client.js CHANGED
@@ -7,6 +7,7 @@ import { FlowsClient } from "./api/resources/flows/client/Client.js";
7
7
  import { GroupsClient } from "./api/resources/groups/client/Client.js";
8
8
  import { LinksClient } from "./api/resources/links/client/Client.js";
9
9
  import { PartnersClient } from "./api/resources/partners/client/Client.js";
10
+ import { PartnerTagsClient } from "./api/resources/partnerTags/client/Client.js";
10
11
  import { ProgramsClient } from "./api/resources/programs/client/Client.js";
11
12
  import { PromotionCodesClient } from "./api/resources/promotionCodes/client/Client.js";
12
13
  import { ReportsClient } from "./api/resources/reports/client/Client.js";
@@ -32,6 +33,9 @@ export class ToltApiClient {
32
33
  get partners() {
33
34
  return (this._partners ??= new PartnersClient(this._options));
34
35
  }
36
+ get partnerTags() {
37
+ return (this._partnerTags ??= new PartnerTagsClient(this._options));
38
+ }
35
39
  get programs() {
36
40
  return (this._programs ??= new ProgramsClient(this._options));
37
41
  }
@@ -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
- /** Look up an onboarded partner by email within a program. Send this or partner_id, not both. */
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
- * Look up an onboarded partner by email within a program. Send this or partner_id, not both.
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
  }
@@ -22,6 +22,9 @@ export * from "./links/types/index.js";
22
22
  export * from "./partners/client/requests/index.js";
23
23
  export * as partners from "./partners/index.js";
24
24
  export * from "./partners/types/index.js";
25
+ export * from "./partnerTags/client/requests/index.js";
26
+ export * as partnerTags from "./partnerTags/index.js";
27
+ export * from "./partnerTags/types/index.js";
25
28
  export * from "./programs/client/requests/index.js";
26
29
  export * as programs from "./programs/index.js";
27
30
  export * from "./programs/types/index.js";
@@ -22,6 +22,9 @@ export * from "./links/types/index.js";
22
22
  export * from "./partners/client/requests/index.js";
23
23
  export * as partners from "./partners/index.js";
24
24
  export * from "./partners/types/index.js";
25
+ export * from "./partnerTags/client/requests/index.js";
26
+ export * as partnerTags from "./partnerTags/index.js";
27
+ export * from "./partnerTags/types/index.js";
25
28
  export * from "./programs/client/requests/index.js";
26
29
  export * as programs from "./programs/index.js";
27
30
  export * from "./programs/types/index.js";
@@ -0,0 +1,118 @@
1
+ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
2
+ import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
3
+ import * as core from "../../../../core/index.js";
4
+ import * as ToltApi from "../../../index.js";
5
+ export declare namespace PartnerTagsClient {
6
+ type Options = BaseClientOptions;
7
+ interface RequestOptions extends BaseRequestOptions {
8
+ }
9
+ }
10
+ export declare class PartnerTagsClient {
11
+ protected readonly _options: NormalizedClientOptionsWithAuth<PartnerTagsClient.Options>;
12
+ constructor(options: PartnerTagsClient.Options);
13
+ /**
14
+ * Lists the tags you can put on partners. Filter by program, search by name, and page with cursors.
15
+ *
16
+ * @param {ToltApi.ListPartnerTagsRequest} request
17
+ * @param {PartnerTagsClient.RequestOptions} requestOptions - Request-specific configuration.
18
+ *
19
+ * @throws {@link ToltApi.BadRequestError}
20
+ * @throws {@link ToltApi.UnauthorizedError}
21
+ * @throws {@link ToltApi.ContentTooLargeError}
22
+ * @throws {@link ToltApi.TooManyRequestsError}
23
+ * @throws {@link errors.ToltApiError}
24
+ * @throws {@link errors.ToltApiTimeoutError}
25
+ *
26
+ * @example
27
+ * await client.partnerTags.listPartnerTags()
28
+ */
29
+ listPartnerTags(request?: ToltApi.ListPartnerTagsRequest, requestOptions?: PartnerTagsClient.RequestOptions): core.HttpResponsePromise<ToltApi.ListPartnerTagsResponse>;
30
+ private __listPartnerTags;
31
+ /**
32
+ * Creates a tag in a program. Put it on partners with POST /v2/partners/{id}/tags.
33
+ *
34
+ * @param {ToltApi.CreatePartnerTagRequest} request
35
+ * @param {PartnerTagsClient.RequestOptions} requestOptions - Request-specific configuration.
36
+ *
37
+ * @throws {@link ToltApi.BadRequestError}
38
+ * @throws {@link ToltApi.UnauthorizedError}
39
+ * @throws {@link ToltApi.ConflictError}
40
+ * @throws {@link ToltApi.ContentTooLargeError}
41
+ * @throws {@link ToltApi.TooManyRequestsError}
42
+ * @throws {@link errors.ToltApiError}
43
+ * @throws {@link errors.ToltApiTimeoutError}
44
+ *
45
+ * @example
46
+ * await client.partnerTags.createPartnerTag({
47
+ * program_id: "prg_T6z8aRW3XCmvFWP972RKxpAd",
48
+ * name: "VIP",
49
+ * color: "#2457D6"
50
+ * })
51
+ */
52
+ createPartnerTag(request: ToltApi.CreatePartnerTagRequest, requestOptions?: PartnerTagsClient.RequestOptions): core.HttpResponsePromise<ToltApi.CreatePartnerTagResponse>;
53
+ private __createPartnerTag;
54
+ /**
55
+ * Gets a partner tag by ID, with how many partners have it.
56
+ *
57
+ * @param {ToltApi.GetPartnerTagRequest} request
58
+ * @param {PartnerTagsClient.RequestOptions} requestOptions - Request-specific configuration.
59
+ *
60
+ * @throws {@link ToltApi.UnauthorizedError}
61
+ * @throws {@link ToltApi.NotFoundError}
62
+ * @throws {@link ToltApi.ContentTooLargeError}
63
+ * @throws {@link ToltApi.TooManyRequestsError}
64
+ * @throws {@link errors.ToltApiError}
65
+ * @throws {@link errors.ToltApiTimeoutError}
66
+ *
67
+ * @example
68
+ * await client.partnerTags.getPartnerTag({
69
+ * id: "ptag_zDEcdqNuNBPcokarWxBnk9gB"
70
+ * })
71
+ */
72
+ getPartnerTag(request: ToltApi.GetPartnerTagRequest, requestOptions?: PartnerTagsClient.RequestOptions): core.HttpResponsePromise<ToltApi.GetPartnerTagResponse>;
73
+ private __getPartnerTag;
74
+ /**
75
+ * Renames a tag or changes its color. Partners who have the tag keep it.
76
+ *
77
+ * @param {ToltApi.UpdatePartnerTagRequest} request
78
+ * @param {PartnerTagsClient.RequestOptions} requestOptions - Request-specific configuration.
79
+ *
80
+ * @throws {@link ToltApi.BadRequestError}
81
+ * @throws {@link ToltApi.UnauthorizedError}
82
+ * @throws {@link ToltApi.NotFoundError}
83
+ * @throws {@link ToltApi.ConflictError}
84
+ * @throws {@link ToltApi.ContentTooLargeError}
85
+ * @throws {@link ToltApi.TooManyRequestsError}
86
+ * @throws {@link errors.ToltApiError}
87
+ * @throws {@link errors.ToltApiTimeoutError}
88
+ *
89
+ * @example
90
+ * await client.partnerTags.updatePartnerTag({
91
+ * id: "ptag_zDEcdqNuNBPcokarWxBnk9gB",
92
+ * name: "VIP",
93
+ * color: "#2457D6"
94
+ * })
95
+ */
96
+ updatePartnerTag(request: ToltApi.UpdatePartnerTagRequest, requestOptions?: PartnerTagsClient.RequestOptions): core.HttpResponsePromise<ToltApi.UpdatePartnerTagResponse>;
97
+ private __updatePartnerTag;
98
+ /**
99
+ * Deletes a tag and removes it from every partner who has it.
100
+ *
101
+ * @param {ToltApi.DeletePartnerTagRequest} request
102
+ * @param {PartnerTagsClient.RequestOptions} requestOptions - Request-specific configuration.
103
+ *
104
+ * @throws {@link ToltApi.UnauthorizedError}
105
+ * @throws {@link ToltApi.NotFoundError}
106
+ * @throws {@link ToltApi.ContentTooLargeError}
107
+ * @throws {@link ToltApi.TooManyRequestsError}
108
+ * @throws {@link errors.ToltApiError}
109
+ * @throws {@link errors.ToltApiTimeoutError}
110
+ *
111
+ * @example
112
+ * await client.partnerTags.deletePartnerTag({
113
+ * id: "ptag_zDEcdqNuNBPcokarWxBnk9gB"
114
+ * })
115
+ */
116
+ deletePartnerTag(request: ToltApi.DeletePartnerTagRequest, requestOptions?: PartnerTagsClient.RequestOptions): core.HttpResponsePromise<ToltApi.DeletePartnerTagResponse>;
117
+ private __deletePartnerTag;
118
+ }