@tuppence/node 0.0.0-stage → 0.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/dist/index.js ADDED
@@ -0,0 +1,230 @@
1
+ import { HttpClient } from "./http.js";
2
+ import { resources } from "./resources.js";
3
+ import { constructEvent, generateTestHeader } from "./webhooks.js";
4
+ export { AGENT_PROOF_HEADER, signAgentProof } from "./agent-proof.js";
5
+ export * from "./errors.js";
6
+ export { DEFAULT_API_VERSION, VERSION } from "./http.js";
7
+ export * from "./types.js";
8
+ export { constructEvent, DEFAULT_TOLERANCE_SECONDS, SIGNATURE_HEADER } from "./webhooks.js";
9
+ /**
10
+ * The Tuppence API for Node.js.
11
+ *
12
+ * import { Tuppence } from "@tuppence/node";
13
+ * const tuppence = new Tuppence(process.env.TUPPENCE_SECRET_KEY!);
14
+ * const link = await tuppence.paymentLinks.create({ name: "Pro plan", amount: 2000, currency: "gbp" });
15
+ *
16
+ * Every POST carries an `Idempotency-Key` (yours, or a fresh one reused across this call's
17
+ * retries), so retries after a timeout never charge twice.
18
+ */
19
+ export class Tuppence {
20
+ http;
21
+ // Kept for `as()`, out of sight: never enumerable, printed or serialised.
22
+ #apiKey;
23
+ #options;
24
+ account;
25
+ /** Bacs Direct Debit by application: its status, applying, and asking for higher limits. */
26
+ directDebit;
27
+ /** Tuppence Connect: your connected accounts, and their people, banks and capabilities. */
28
+ accounts;
29
+ accountLinks;
30
+ files;
31
+ /** Your fees on your connected accounts' payments, and the refunds of them. */
32
+ applicationFees;
33
+ /** Money from your Connect balance to your connected accounts, and its reversals. */
34
+ transfers;
35
+ plans;
36
+ subscriptions;
37
+ paymentLinks;
38
+ payments;
39
+ refunds;
40
+ customers;
41
+ balance;
42
+ payouts;
43
+ disputes;
44
+ events;
45
+ /** Tuppence Events: `ticketing.events`, `.promoCodes`, `.fundsHolds`, `.reports`. */
46
+ ticketing;
47
+ ticketTypes;
48
+ ticketOrders;
49
+ tickets;
50
+ webhookEndpoints;
51
+ paymentMethodDomains;
52
+ meters;
53
+ credits;
54
+ meterEvents;
55
+ agents;
56
+ cardholders;
57
+ spendPolicies;
58
+ cards;
59
+ cardAuthorizations;
60
+ cardTransactions;
61
+ /** Disputing a card purchase: a draft, its evidence and files, then submitted by a person. */
62
+ cardDisputes;
63
+ /**
64
+ * The cards' own balance and its top-ups — `issuing.balance`, `issuing.topups`,
65
+ * `issuing.fundingInstructions` — and Issuing's limits for the account's tier (`issuing.limits`).
66
+ */
67
+ issuing;
68
+ /** TEST MODE only: `testHelpers.issuing.topups.arrive(id)`. */
69
+ testHelpers;
70
+ approvals;
71
+ locations;
72
+ countryPacks;
73
+ serviceCategories;
74
+ services;
75
+ staff;
76
+ scheduleExceptions;
77
+ resources;
78
+ bookingPolicy;
79
+ bookingPage;
80
+ availability;
81
+ bookings;
82
+ classSessions;
83
+ bookingSeries;
84
+ waitlist;
85
+ // The store (94-02).
86
+ reviews;
87
+ changeSets;
88
+ storeImports;
89
+ assistantJobs;
90
+ channelReports;
91
+ storeBriefs;
92
+ sites;
93
+ store;
94
+ fulfilments;
95
+ returns;
96
+ shippingManifests;
97
+ carrierPickups;
98
+ postage;
99
+ carrierAccounts;
100
+ shippingProfiles;
101
+ shippingPackages;
102
+ shippingServices;
103
+ media;
104
+ digitalAssets;
105
+ imageStudio;
106
+ collections;
107
+ drops;
108
+ products;
109
+ orders;
110
+ sitePolicies;
111
+ storePrivacyRequests;
112
+ recommendationRules;
113
+ subscriptionOffers;
114
+ storeCampaigns;
115
+ storeFlows;
116
+ salesChannels;
117
+ listings;
118
+ storeThreads;
119
+ merchantSendingDomains;
120
+ webhooks = { constructEvent, generateTestHeader };
121
+ constructor(apiKey, options = {}) {
122
+ this.http = new HttpClient(apiKey, options);
123
+ this.#apiKey = apiKey;
124
+ this.#options = options;
125
+ const r = resources(this.http);
126
+ this.account = r.account;
127
+ this.directDebit = r.directDebit;
128
+ this.accounts = r.accounts;
129
+ this.accountLinks = r.accountLinks;
130
+ this.files = r.files;
131
+ this.applicationFees = r.applicationFees;
132
+ this.transfers = r.transfers;
133
+ this.plans = r.plans;
134
+ this.subscriptions = r.subscriptions;
135
+ this.paymentLinks = r.paymentLinks;
136
+ this.payments = r.payments;
137
+ this.refunds = r.refunds;
138
+ this.customers = r.customers;
139
+ this.balance = r.balance;
140
+ this.payouts = r.payouts;
141
+ this.disputes = r.disputes;
142
+ this.events = r.events;
143
+ this.ticketing = r.ticketing;
144
+ this.ticketTypes = r.ticketTypes;
145
+ this.ticketOrders = r.ticketOrders;
146
+ this.tickets = r.tickets;
147
+ this.webhookEndpoints = r.webhookEndpoints;
148
+ this.paymentMethodDomains = r.paymentMethodDomains;
149
+ this.meters = r.meters;
150
+ this.credits = r.credits;
151
+ this.meterEvents = r.meterEvents;
152
+ this.agents = r.agents;
153
+ this.cardholders = r.cardholders;
154
+ this.spendPolicies = r.spendPolicies;
155
+ this.cards = r.cards;
156
+ this.cardAuthorizations = r.cardAuthorizations;
157
+ this.cardTransactions = r.cardTransactions;
158
+ this.cardDisputes = r.cardDisputes;
159
+ this.issuing = r.issuing;
160
+ this.testHelpers = r.testHelpers;
161
+ this.approvals = r.approvals;
162
+ this.locations = r.locations;
163
+ this.countryPacks = r.countryPacks;
164
+ this.serviceCategories = r.serviceCategories;
165
+ this.services = r.services;
166
+ this.staff = r.staff;
167
+ this.scheduleExceptions = r.scheduleExceptions;
168
+ this.resources = r.resources;
169
+ this.bookingPolicy = r.bookingPolicy;
170
+ this.bookingPage = r.bookingPage;
171
+ this.availability = r.availability;
172
+ this.bookings = r.bookings;
173
+ this.classSessions = r.classSessions;
174
+ this.bookingSeries = r.bookingSeries;
175
+ this.waitlist = r.waitlist;
176
+ this.reviews = r.reviews;
177
+ this.changeSets = r.changeSets;
178
+ this.storeImports = r.storeImports;
179
+ this.assistantJobs = r.assistantJobs;
180
+ this.channelReports = r.channelReports;
181
+ this.storeBriefs = r.storeBriefs;
182
+ this.sites = r.sites;
183
+ this.store = r.store;
184
+ this.fulfilments = r.fulfilments;
185
+ this.returns = r.returns;
186
+ this.shippingManifests = r.shippingManifests;
187
+ this.carrierPickups = r.carrierPickups;
188
+ this.postage = r.postage;
189
+ this.carrierAccounts = r.carrierAccounts;
190
+ this.shippingProfiles = r.shippingProfiles;
191
+ this.shippingPackages = r.shippingPackages;
192
+ this.shippingServices = r.shippingServices;
193
+ this.media = r.media;
194
+ this.digitalAssets = r.digitalAssets;
195
+ this.imageStudio = r.imageStudio;
196
+ this.collections = r.collections;
197
+ this.drops = r.drops;
198
+ this.products = r.products;
199
+ this.orders = r.orders;
200
+ this.sitePolicies = r.sitePolicies;
201
+ this.storePrivacyRequests = r.storePrivacyRequests;
202
+ this.recommendationRules = r.recommendationRules;
203
+ this.subscriptionOffers = r.subscriptionOffers;
204
+ this.storeCampaigns = r.storeCampaigns;
205
+ this.storeFlows = r.storeFlows;
206
+ this.salesChannels = r.salesChannels;
207
+ this.listings = r.listings;
208
+ this.storeThreads = r.storeThreads;
209
+ this.merchantSendingDomains = r.merchantSendingDomains;
210
+ }
211
+ /**
212
+ * Tuppence Connect: a client that acts as one of your connected accounts on every request —
213
+ * the `Tuppence-Account` header, with your key. A NEW client: this one is unchanged, so one
214
+ * shared client can serve every account. A request's own `tuppenceAccount` still wins.
215
+ *
216
+ * const bella = tuppence.as("acct_…");
217
+ * await bella.bookings.create({ … });
218
+ */
219
+ as(accountId) {
220
+ if (!accountId || typeof accountId !== "string") {
221
+ throw new TypeError('tuppence.as(accountId): a connected account id ("acct_…") is required.');
222
+ }
223
+ return new Tuppence(this.#apiKey, { ...this.#options, tuppenceAccount: accountId });
224
+ }
225
+ /** Any endpoint the SDK has no method for yet — same auth, retries and idempotency. */
226
+ request(method, path, options = {}) {
227
+ return this.http.request(method, path, options);
228
+ }
229
+ }
230
+ export default Tuppence;