tremendous 2.2.0 → 3.0.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/README.md CHANGED
@@ -1,7 +1,9 @@
1
- tremendous
2
- ==============
1
+ A node.js client library for the [Tremendous API][docs].
3
2
 
4
- A node.js client library for the [Tremendous API][1].
3
+ > [!NOTE]
4
+ > This branch includes the v3 version of the Tremendous Node.JS client, a new version based
5
+ > on our [API schema][ref] docs. If you are using the v2 versions, please check our
6
+ > [`UPGRADING`](UPGRADING.md) guide
5
7
 
6
8
  ## Installation
7
9
 
@@ -11,79 +13,101 @@ $ npm install tremendous
11
13
 
12
14
  ## Getting started
13
15
 
14
- All API requests require an access token. A sandbox access token is assigned upon signup through the [Tremendous Sandbox Environment][2]. Once you are ready to move to production, you will be assigned a production access token.
16
+ All API requests require an access token. A sandbox access token is assigned upon signup through the [Tremendous Sandbox Environment][docs]. Once you are ready to move to production, you will be assigned a production access token.
15
17
 
16
18
  ### Authentication
19
+ ## Getting started
17
20
 
18
- ```javascript
19
- var Tremendous = require('tremendous');
21
+ All endpoints require a `Configuration` object with a `basePath` and an `accessToken` for either your
22
+ Production or Sandbox account:
20
23
 
21
- // Sandbox environment
22
- var client = new Tremendous("[SANDBOX_ACCESS_TOKEN]", "https://testflight.tremendous.com/api/v2/");
24
+ ```typescript
25
+ import { Configuration, Environments } from "tremendous";
23
26
 
24
- // Production environment
25
- var client = new Tremendous("[PRODUCTION_ACCESS_TOKEN]", "https://api.tremendous.com/api/v2/");
26
- ```
27
+ // when you are testing your code with the sandbox environment:
28
+ const configuration = new Configuration({
29
+ basePath: Environments.testflight,
30
+ accessToken: "YOUR-TESTFLIGHT-TOKEN",
31
+ });
27
32
 
33
+ // when you are ready to use the API:
34
+ const configuration = new Configuration({
35
+ basePath: Environments.production,
36
+ accessToken: "YOUR-PRODUCTION-TOKEN",
37
+ });
38
+ ```
28
39
 
29
- ### Orders
40
+ ## Examples
30
41
 
31
- See [API documentation][3] for all Order attributes.
42
+ Submitting an order:
32
43
 
33
- ```javascript
34
- // Create a new order, specifying your gift options
35
- // as an array of objects.
44
+ ```typescript
45
+ import { OrdersApi, CreateOrderRequest } from "tremendous";
36
46
 
37
- const order_data = {
47
+ const orders = new OrdersApi(configuration);
48
+ const params: CreateOrderRequest = {
38
49
  payment: {
39
- funding_source_id: "[FUNDING_SOURCE_ID]",
50
+ funding_source_id: "[FUNDING SOURCE ID HERE]",
40
51
  },
41
- reward: {
42
- value: {
43
- denomination: 25,
44
- currency_code: "USD"
45
- },
46
- campaign_id: "[CAMPAIGN_ID]",
47
- delivery: {
48
- method: "EMAIL",
49
- },
50
- recipient: {
51
- name: "Tremendous Recipient",
52
- email: "steve@stevens.com"
52
+ reward:
53
+ {
54
+ delivery: {
55
+ method: "EMAIL"
56
+ },
57
+ recipient: {
58
+ name: "Recipient Name",
59
+ email: "recipient@domain"
60
+ },
61
+ value: {
62
+ denomination: 5.0,
63
+ currency_code: "USD",
64
+ },
65
+ campaign_id: "[CAMPAIGN_ID]",
53
66
  }
54
- }
55
- }
67
+ };
56
68
 
57
- client.createOrder(order_data, function(err, results) {
58
- console.log(JSON.stringify(err, null, 2));
59
- console.log(JSON.stringify(results, null, 2));
60
- });
69
+ const { data } = await orders.createOrder(params);
70
+ console.log(`Order created! ID: ${data.order.id}`);
71
+ ```
61
72
 
73
+ Retrieving an Order and a Reward
62
74
 
63
- // Return a reward by ID
64
- client.getReward("[REWARD_ID]", function(err, result) {
65
- console.log(JSON.stringify(result, null, 2));
66
- });
75
+ ```typescript
76
+ import { OrdersApi, RewardsApi } from "tremendous";
77
+
78
+ const orders = new OrdersApi(configuration);
79
+ const rewards = new RewardsApi(configuration);
80
+
81
+ const { order } = (await orders.getOrder("[ORDER_ID]")).data;
82
+ const { reward } = (await rewards.getReward("[REWARD_ID]")).data;
83
+
84
+ console.log(`The order status is ${order.status}`);
85
+ console.log(`The reward was delivered to ${reward.recipient.email}`);
67
86
  ```
68
87
 
69
- ### Funding Sources
70
- Production funding sources must be added through the web dashboard. A sandbox funding source is provided during development.
88
+ Listing products:
71
89
 
72
- ```javascript
73
- // Retrieve a list of your funding sources (credit card, ach, etc).
74
- client.getFundingSources({}, function(err, results) {
75
- console.log(JSON.stringify(results, null, 2));
76
- });
90
+ ```typescript
91
+ import { ProductsApi } from "tremendous";
92
+
93
+ const client = new ProductsApi(configuration);
94
+
95
+ const { data } = await client.listProducts();
96
+
97
+ data.products.forEach(product => { /* */ });
77
98
  ```
78
99
 
79
- ### Products
100
+ Listing funding sources:
80
101
 
81
- ```javascript
82
- client.getProducts({}, function(err, results) {
83
- console.log(JSON.stringify(results, null, 2));
84
- });
102
+ ```typescript
103
+ import { FundingSourcesAPI } from "tremendous";
104
+
105
+ const client = new FundingSourcesAPI(configuration);
106
+
107
+ const { data } = await client.listFundingSources();
108
+
109
+ data.fundingSources.forEach(product => { /* */ });
85
110
  ```
86
111
 
87
- [1]: https://tremendous.com/docs
88
- [2]: https://testflight.tremendous.com/rewards
89
- [3]: https://tremendous.com/docs
112
+ [ref]: https://developers.tremendous.com/reference
113
+ [docs]: https://tremendous.com/docs