@doany-ai/sdk 0.2.8 → 0.3.0-alpha.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/client.js +53 -5
- package/dist/client.types.d.ts +60 -4
- package/dist/index.d.ts +8 -2
- package/dist/modules/auth.js +6 -0
- package/dist/modules/auth.types.d.ts +30 -0
- package/dist/modules/catalog.d.ts +9 -0
- package/dist/modules/catalog.js +62 -0
- package/dist/modules/catalog.types.d.ts +163 -0
- package/dist/modules/catalog.types.js +1 -0
- package/dist/modules/contacts.d.ts +9 -0
- package/dist/modules/contacts.js +42 -0
- package/dist/modules/contacts.types.d.ts +112 -0
- package/dist/modules/contacts.types.js +1 -0
- package/dist/modules/events.d.ts +9 -0
- package/dist/modules/events.js +15 -0
- package/dist/modules/events.types.d.ts +42 -0
- package/dist/modules/events.types.js +1 -0
- package/dist/modules/order-access.d.ts +20 -0
- package/dist/modules/order-access.js +84 -0
- package/dist/modules/orders.d.ts +25 -0
- package/dist/modules/orders.js +296 -0
- package/dist/modules/orders.types.d.ts +215 -0
- package/dist/modules/orders.types.js +1 -0
- package/dist/modules/payments.d.ts +2 -1
- package/dist/modules/payments.js +28 -1
- package/dist/modules/payments.types.d.ts +146 -0
- package/dist/modules/project.d.ts +31 -0
- package/dist/modules/project.js +52 -0
- package/dist/modules/project.types.d.ts +58 -0
- package/dist/modules/project.types.js +1 -0
- package/dist/modules/users.d.ts +7 -13
- package/dist/modules/users.js +24 -11
- package/dist/modules/users.types.d.ts +62 -0
- package/dist/modules/users.types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { Address, Page, PageParams, VersionInput } from "./project.types";
|
|
2
|
+
/**
|
|
3
|
+
* - `pending`: placed on the site, waiting for its payment; expires after an hour unpaid.
|
|
4
|
+
* - `placed`: paid, free, or entered by the business. Has an order number.
|
|
5
|
+
* - `completed`: the business marked it done. Cannot be canceled any more.
|
|
6
|
+
* - `canceled`, `expired`.
|
|
7
|
+
*/
|
|
8
|
+
export type OrderStatus = "pending" | "placed" | "completed" | "canceled" | "expired";
|
|
9
|
+
export type OrderChannel = "online" | "staff";
|
|
10
|
+
/** Delivery is marked for the whole order. */
|
|
11
|
+
export type FulfillmentStatus = "not_required" | "unfulfilled" | "fulfilled";
|
|
12
|
+
/** A line of an order. Names, price and duration are as they were when it was placed. */
|
|
13
|
+
export interface OrderItem {
|
|
14
|
+
id: string;
|
|
15
|
+
variant_id: string | null;
|
|
16
|
+
item_name: string;
|
|
17
|
+
variant_name: string | null;
|
|
18
|
+
duration_minutes: number | null;
|
|
19
|
+
unit_amount: number;
|
|
20
|
+
quantity: number;
|
|
21
|
+
line_amount: number;
|
|
22
|
+
}
|
|
23
|
+
export interface OrderBuyer {
|
|
24
|
+
name: string;
|
|
25
|
+
email: string | null;
|
|
26
|
+
phone: string | null;
|
|
27
|
+
}
|
|
28
|
+
/** An address, plus who receives it (empty: the buyer). */
|
|
29
|
+
export interface ShippingAddress extends Address {
|
|
30
|
+
name: string | null;
|
|
31
|
+
phone: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface Order {
|
|
34
|
+
id: string;
|
|
35
|
+
/** Consecutive per business and environment, given when the order is placed. Show it as `#12`. */
|
|
36
|
+
order_number: number | null;
|
|
37
|
+
status: OrderStatus;
|
|
38
|
+
channel: OrderChannel;
|
|
39
|
+
/** When a `pending` order stops waiting for its payment. */
|
|
40
|
+
expires_at: string | null;
|
|
41
|
+
fulfillment_status: FulfillmentStatus;
|
|
42
|
+
currency: string;
|
|
43
|
+
/** In the currency's smallest unit (cents). */
|
|
44
|
+
total_amount: number;
|
|
45
|
+
/** A test (preview) order or a real one. */
|
|
46
|
+
livemode: boolean;
|
|
47
|
+
/** The site it was placed on. */
|
|
48
|
+
app_id: string | null;
|
|
49
|
+
contact_id: string | null;
|
|
50
|
+
/** The account that placed it. */
|
|
51
|
+
user_id: string | null;
|
|
52
|
+
buyer: OrderBuyer;
|
|
53
|
+
shipping_address: ShippingAddress | null;
|
|
54
|
+
customer_note: string | null;
|
|
55
|
+
/** Only the site's admin and service callers see it. */
|
|
56
|
+
internal_note?: string | null;
|
|
57
|
+
/** In the order they were bought in. */
|
|
58
|
+
items: OrderItem[];
|
|
59
|
+
payment: {
|
|
60
|
+
/** `false` for a free order, which is `placed` as soon as it is created. */
|
|
61
|
+
required: boolean;
|
|
62
|
+
amount_received: number;
|
|
63
|
+
amount_refunded: number;
|
|
64
|
+
};
|
|
65
|
+
/** Only the site's admin and service callers see it. */
|
|
66
|
+
created_by?: "customer" | "owner" | "system";
|
|
67
|
+
created_by_user_id?: string | null;
|
|
68
|
+
access?: {
|
|
69
|
+
issued: boolean;
|
|
70
|
+
revoked: boolean;
|
|
71
|
+
};
|
|
72
|
+
version: number;
|
|
73
|
+
created_at: string;
|
|
74
|
+
updated_at: string;
|
|
75
|
+
placed_at: string | null;
|
|
76
|
+
completed_at: string | null;
|
|
77
|
+
canceled_at: string | null;
|
|
78
|
+
}
|
|
79
|
+
export interface OrderSummary {
|
|
80
|
+
id: string;
|
|
81
|
+
order_number: number | null;
|
|
82
|
+
status: OrderStatus;
|
|
83
|
+
channel: OrderChannel;
|
|
84
|
+
fulfillment_status: FulfillmentStatus;
|
|
85
|
+
currency: string;
|
|
86
|
+
total_amount: number;
|
|
87
|
+
livemode: boolean;
|
|
88
|
+
app_id: string | null;
|
|
89
|
+
contact_id: string | null;
|
|
90
|
+
user_id: string | null;
|
|
91
|
+
buyer: {
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
created_at: string;
|
|
95
|
+
}
|
|
96
|
+
export interface CreateOrderParams {
|
|
97
|
+
/** `online` (default): a customer on the site. `staff`: the business entering one. */
|
|
98
|
+
channel?: OrderChannel;
|
|
99
|
+
/** The site it is placed on. Defaults to this client's app. */
|
|
100
|
+
app_id?: string | null;
|
|
101
|
+
/** 1–100 variants, each once. Prices are not sent: the order takes them from the catalog. */
|
|
102
|
+
items: Array<{
|
|
103
|
+
variant_id: string;
|
|
104
|
+
quantity?: number;
|
|
105
|
+
}>;
|
|
106
|
+
/** Who it is for. `email` or `phone` is required; `phone` in E.164 form (`+14155550123`). */
|
|
107
|
+
buyer: {
|
|
108
|
+
name: string;
|
|
109
|
+
email?: string;
|
|
110
|
+
phone?: string;
|
|
111
|
+
};
|
|
112
|
+
/** Required when something in it is shipped (`kind: "physical"`): at least `line` and `country`. */
|
|
113
|
+
shipping_address?: Partial<ShippingAddress>;
|
|
114
|
+
/** Up to 1000 characters. */
|
|
115
|
+
customer_note?: string;
|
|
116
|
+
/** `staff` only, and required there: a real order or a test. */
|
|
117
|
+
livemode?: boolean;
|
|
118
|
+
/** `staff` only: the contact it is for, instead of matching the buyer. */
|
|
119
|
+
contact_id?: string;
|
|
120
|
+
/** `staff` only. */
|
|
121
|
+
internal_note?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface CreateOrderOptions {
|
|
124
|
+
/**
|
|
125
|
+
* Identifies this attempt, so that a retry does not place a second order.
|
|
126
|
+
* Optional: the SDK reuses one key for an identical order that is still in
|
|
127
|
+
* flight or failed without an answer.
|
|
128
|
+
*/
|
|
129
|
+
idempotencyKey?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface CreateOrderResult {
|
|
132
|
+
order: Order;
|
|
133
|
+
/**
|
|
134
|
+
* Lets someone who is not signed in open this order again. The SDK keeps it
|
|
135
|
+
* for the rest of the browser session, so `orders.get`, `orders.cancel` and
|
|
136
|
+
* the payments calls work without passing it; put it in a link (after `#`)
|
|
137
|
+
* to reach the order from elsewhere.
|
|
138
|
+
*/
|
|
139
|
+
access_token?: string;
|
|
140
|
+
/** `false` when the order is free and already placed. */
|
|
141
|
+
payment_required: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface OrderListParams extends PageParams {
|
|
144
|
+
status?: OrderStatus;
|
|
145
|
+
channel?: OrderChannel;
|
|
146
|
+
/** Orders placed on this site. */
|
|
147
|
+
app_id?: string;
|
|
148
|
+
/** The contact's orders, and those of contacts merged into it. */
|
|
149
|
+
contact_id?: string;
|
|
150
|
+
user_id?: string;
|
|
151
|
+
/** Order number, buyer name or email. */
|
|
152
|
+
q?: string;
|
|
153
|
+
created_from?: string;
|
|
154
|
+
created_to?: string;
|
|
155
|
+
}
|
|
156
|
+
export interface OrderAccessOptions {
|
|
157
|
+
/** The order's `access_token`, when it came from a link rather than from this browser session. */
|
|
158
|
+
accessToken?: string;
|
|
159
|
+
}
|
|
160
|
+
export interface UpdateOrderParams extends VersionInput {
|
|
161
|
+
/** Not once the order is delivered, completed or closed. */
|
|
162
|
+
shipping_address?: Partial<ShippingAddress> | null;
|
|
163
|
+
internal_note?: string | null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Orders.
|
|
167
|
+
*
|
|
168
|
+
* Who sees an order: the account that placed it, accounts with the records
|
|
169
|
+
* of its contact, anyone holding its access token, the site's admin and
|
|
170
|
+
* service callers. Anyone else gets 404.
|
|
171
|
+
*/
|
|
172
|
+
export interface OrdersModule {
|
|
173
|
+
/**
|
|
174
|
+
* Places an order for catalog variants. Works signed in or not.
|
|
175
|
+
*
|
|
176
|
+
* Rejects with 409 `NOT_PURCHASABLE` (`details.variant_id`, `details.reason`)
|
|
177
|
+
* when something in it cannot be bought, 409 `MIXED_CURRENCY`, or 429
|
|
178
|
+
* `RATE_LIMITED`.
|
|
179
|
+
*
|
|
180
|
+
* An `online` order takes its environment (preview or published) from the
|
|
181
|
+
* page's `Origin`, which a backend function does not send: with
|
|
182
|
+
* `asServiceRole`, enter a `staff` order and say `livemode` instead.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const { order, payment_required } = await doany.orders.create({
|
|
187
|
+
* items: [{ variant_id: variant.id, quantity: 1 }],
|
|
188
|
+
* buyer: { name, email },
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
create(params: CreateOrderParams, options?: CreateOrderOptions): Promise<CreateOrderResult>;
|
|
193
|
+
/** The orders the caller may see, newest first. Rejects with 401 when nobody is signed in. */
|
|
194
|
+
list(params?: OrderListParams): Promise<Page<OrderSummary>>;
|
|
195
|
+
/** One order. */
|
|
196
|
+
get(orderId: string, options?: OrderAccessOptions): Promise<Order>;
|
|
197
|
+
/** Changes the shipping address or the internal note. The site's admin and service callers only. */
|
|
198
|
+
update(orderId: string, params: UpdateOrderParams): Promise<Order>;
|
|
199
|
+
/**
|
|
200
|
+
* Cancels a `pending` or `placed` order (a customer: only one not paid yet).
|
|
201
|
+
* Canceling is not refunding. Rejects with 409 `INVALID_STATE` once the
|
|
202
|
+
* order is completed or expired, 409 `PAYMENT_UNRESOLVED` while a payment
|
|
203
|
+
* is still being confirmed.
|
|
204
|
+
*/
|
|
205
|
+
cancel(orderId: string, options?: OrderAccessOptions & Partial<VersionInput>): Promise<Order>;
|
|
206
|
+
/** Marks the whole order delivered, or takes that back. `placed` orders only. */
|
|
207
|
+
setFulfillment(orderId: string, params: VersionInput & {
|
|
208
|
+
status: "fulfilled" | "unfulfilled";
|
|
209
|
+
}): Promise<Order>;
|
|
210
|
+
/**
|
|
211
|
+
* Says the order is done. Nothing may still be owed (409 `INVALID_STATE`,
|
|
212
|
+
* `details.amount_due`); delivery is not required.
|
|
213
|
+
*/
|
|
214
|
+
complete(orderId: string, params: VersionInput): Promise<Order>;
|
|
215
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { PaymentsModule, ProductsModule } from "./payments.types";
|
|
3
|
+
import { ProjectScope } from "./project.js";
|
|
3
4
|
/**
|
|
4
5
|
* The product reads.
|
|
5
6
|
*
|
|
@@ -21,4 +22,4 @@ export declare function createProductsModule(axios: AxiosInstance, appId: string
|
|
|
21
22
|
*
|
|
22
23
|
* @internal
|
|
23
24
|
*/
|
|
24
|
-
export declare function createPaymentsModule(axios: AxiosInstance, appId: string): PaymentsModule;
|
|
25
|
+
export declare function createPaymentsModule(axios: AxiosInstance, appId: string, project: ProjectScope): PaymentsModule;
|
package/dist/modules/payments.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { orderAccessHeaders } from "./order-access.js";
|
|
2
|
+
import { queryOf, seg } from "./project.js";
|
|
1
3
|
/**
|
|
2
4
|
* The product reads.
|
|
3
5
|
*
|
|
@@ -47,7 +49,7 @@ export function createProductsModule(axios, appId) {
|
|
|
47
49
|
*
|
|
48
50
|
* @internal
|
|
49
51
|
*/
|
|
50
|
-
export function createPaymentsModule(axios, appId) {
|
|
52
|
+
export function createPaymentsModule(axios, appId, project) {
|
|
51
53
|
async function createCheckoutSession(params) {
|
|
52
54
|
const data = await axios.request({
|
|
53
55
|
method: "POST",
|
|
@@ -84,5 +86,30 @@ export function createPaymentsModule(axios, appId) {
|
|
|
84
86
|
});
|
|
85
87
|
return data;
|
|
86
88
|
},
|
|
89
|
+
// Paying for an order: /projects/{project_id}/orders/{order_id}/...
|
|
90
|
+
// The order's access token rides along, as for orders.get.
|
|
91
|
+
async checkout(orderId, params = {}, options) {
|
|
92
|
+
const data = await axios.request({
|
|
93
|
+
method: "POST",
|
|
94
|
+
url: await project.path(`/orders/${seg(orderId)}/checkout`),
|
|
95
|
+
data: params,
|
|
96
|
+
headers: orderAccessHeaders(axios, appId, orderId, options === null || options === void 0 ? void 0 : options.accessToken),
|
|
97
|
+
});
|
|
98
|
+
return data;
|
|
99
|
+
},
|
|
100
|
+
async getForOrder(orderId, options) {
|
|
101
|
+
const data = await axios.get(await project.path(`/orders/${seg(orderId)}/payments`), {
|
|
102
|
+
headers: orderAccessHeaders(axios, appId, orderId, options === null || options === void 0 ? void 0 : options.accessToken),
|
|
103
|
+
});
|
|
104
|
+
return data;
|
|
105
|
+
},
|
|
106
|
+
async list(params = {}) {
|
|
107
|
+
const data = await axios.get(await project.path("/payments"), { params: queryOf(params) });
|
|
108
|
+
return data;
|
|
109
|
+
},
|
|
110
|
+
async get(paymentId) {
|
|
111
|
+
const data = await axios.get(await project.path(`/payments/${seg(paymentId)}`));
|
|
112
|
+
return data;
|
|
113
|
+
},
|
|
87
114
|
};
|
|
88
115
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Page, PageParams } from "./project.types";
|
|
1
2
|
/**
|
|
2
3
|
* One thing being sold in a checkout.
|
|
3
4
|
*
|
|
@@ -409,4 +410,149 @@ export interface PaymentsModule {
|
|
|
409
410
|
createBillingPortalSession(params: BillingPortalParams): Promise<{
|
|
410
411
|
url: string;
|
|
411
412
|
}>;
|
|
413
|
+
/**
|
|
414
|
+
* The way to pay for an order: an embedded Stripe checkout (`ui_mode`
|
|
415
|
+
* `embedded`, the default) or a hosted payment page (`hosted`, returns
|
|
416
|
+
* `url` — e.g. a payment link to send). One checkout per order at a time:
|
|
417
|
+
* asking again with the same options answers with the open one.
|
|
418
|
+
*
|
|
419
|
+
* Sends the order's access token kept by `orders.create`. Rejects with 404
|
|
420
|
+
* when the caller may not see the order, 409 `ENVIRONMENT_MISMATCH` when the
|
|
421
|
+
* page's environment (preview / published) is not the order's, 409
|
|
422
|
+
* `PAYMENT_UNRESOLVED` while an earlier payment is still being confirmed,
|
|
423
|
+
* 409 `INVALID_STATE` once the order no longer takes payment.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const { client_secret, publishable_key, stripe_account } =
|
|
428
|
+
* await doany.payments.checkout(order.id, { success_path: `/orders/${order.id}` });
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
checkout(orderId: string, params?: OrderCheckoutParams, options?: {
|
|
432
|
+
accessToken?: string;
|
|
433
|
+
}): Promise<OrderCheckout>;
|
|
434
|
+
/**
|
|
435
|
+
* Where an order's payment stands — what a "thank you" page polls: show
|
|
436
|
+
* success once `order_status` is `placed` (or `completed`), "confirming"
|
|
437
|
+
* while it is `pending`, and "not paid" when `expired` or `canceled`.
|
|
438
|
+
* Usually readable 1–3 seconds after paying. Sends the order's access token.
|
|
439
|
+
*/
|
|
440
|
+
getForOrder(orderId: string, options?: {
|
|
441
|
+
accessToken?: string;
|
|
442
|
+
}): Promise<OrderPayments>;
|
|
443
|
+
/** Payments of the business. The site's admin and service callers only. */
|
|
444
|
+
list(params?: PaymentListParams): Promise<Page<Payment>>;
|
|
445
|
+
/** One payment, with its refunds. The site's admin and service callers only. */
|
|
446
|
+
get(paymentId: string): Promise<Payment>;
|
|
447
|
+
}
|
|
448
|
+
/** How to open an order's checkout. */
|
|
449
|
+
export interface OrderCheckoutParams {
|
|
450
|
+
/** `embedded` (default): Stripe's form inside the page. `hosted`: Stripe's page, see `url`. */
|
|
451
|
+
ui_mode?: "embedded" | "hosted";
|
|
452
|
+
/** The site to come back to; defaults to the one the order was placed on. */
|
|
453
|
+
app_id?: string;
|
|
454
|
+
/** A path on the site (`/…`, no `#`, no access token), default `/`. */
|
|
455
|
+
success_path?: string;
|
|
456
|
+
cancel_path?: string;
|
|
457
|
+
}
|
|
458
|
+
/** An order's open checkout. */
|
|
459
|
+
export interface OrderCheckout {
|
|
460
|
+
/** The payment this checkout is. */
|
|
461
|
+
id: string;
|
|
462
|
+
status: string;
|
|
463
|
+
expires_at: string | null;
|
|
464
|
+
amount_total: number;
|
|
465
|
+
currency: string;
|
|
466
|
+
ui_mode: "embedded" | "hosted";
|
|
467
|
+
/** `embedded`: to load Stripe's form in the page. */
|
|
468
|
+
client_secret: string | null;
|
|
469
|
+
publishable_key: string | null;
|
|
470
|
+
stripe_account: string | null;
|
|
471
|
+
/** `hosted`: the payment page. */
|
|
472
|
+
url: string | null;
|
|
473
|
+
mode: "test" | "live";
|
|
474
|
+
}
|
|
475
|
+
/** The money of one order. */
|
|
476
|
+
export interface OrderPayments {
|
|
477
|
+
order_id: string;
|
|
478
|
+
order_status: string;
|
|
479
|
+
currency: string;
|
|
480
|
+
total_amount: number;
|
|
481
|
+
/** What successful payments took. */
|
|
482
|
+
amount_received: number;
|
|
483
|
+
/** What successful refunds gave back — kept apart, never netted. */
|
|
484
|
+
amount_refunded: number;
|
|
485
|
+
payments: Array<{
|
|
486
|
+
id: string;
|
|
487
|
+
status: PaymentStatus;
|
|
488
|
+
requested_amount: number;
|
|
489
|
+
received_amount: number;
|
|
490
|
+
payment_method_type: string | null;
|
|
491
|
+
paid_at: string | null;
|
|
492
|
+
}>;
|
|
493
|
+
refunds: Array<{
|
|
494
|
+
id: string;
|
|
495
|
+
payment_id: string;
|
|
496
|
+
status: RefundStatus;
|
|
497
|
+
amount: number;
|
|
498
|
+
succeeded_at: string | null;
|
|
499
|
+
}>;
|
|
500
|
+
}
|
|
501
|
+
/** `failed` is not final: the same checkout can be paid with another card. */
|
|
502
|
+
export type PaymentStatus = "pending" | "processing" | "requires_action" | "authorized" | "succeeded" | "failed" | "canceled";
|
|
503
|
+
export type RefundStatus = "requested" | "pending" | "succeeded" | "failed" | "canceled";
|
|
504
|
+
export interface Refund {
|
|
505
|
+
id: string;
|
|
506
|
+
payment_id: string;
|
|
507
|
+
amount: number;
|
|
508
|
+
currency: string;
|
|
509
|
+
status: RefundStatus;
|
|
510
|
+
/** Refunds are made in the payment dashboard and synced here (`external`). */
|
|
511
|
+
origin: "doany" | "external";
|
|
512
|
+
reason: string | null;
|
|
513
|
+
failure_code: string | null;
|
|
514
|
+
provider_refund_id: string | null;
|
|
515
|
+
provider_status: string | null;
|
|
516
|
+
succeeded_at: string | null;
|
|
517
|
+
last_synced_at: string | null;
|
|
518
|
+
created_at: string | null;
|
|
519
|
+
version: number;
|
|
520
|
+
}
|
|
521
|
+
export interface Payment {
|
|
522
|
+
id: string;
|
|
523
|
+
order_id: string | null;
|
|
524
|
+
contact_id: string | null;
|
|
525
|
+
status: PaymentStatus;
|
|
526
|
+
requested_amount: number;
|
|
527
|
+
received_amount: number;
|
|
528
|
+
currency: string;
|
|
529
|
+
livemode: boolean;
|
|
530
|
+
/** How it was collected; `null` for a payment recorded by hand. */
|
|
531
|
+
ui_mode: "embedded" | "hosted" | "direct" | "terminal" | null;
|
|
532
|
+
/** The site the customer returns to. */
|
|
533
|
+
app_id: string | null;
|
|
534
|
+
payment_method_type: string | null;
|
|
535
|
+
has_dispute: boolean;
|
|
536
|
+
/** Taken back by a lost dispute. */
|
|
537
|
+
amount_disputed: number;
|
|
538
|
+
provider: string | null;
|
|
539
|
+
provider_account_id: string | null;
|
|
540
|
+
provider_payment_id: string | null;
|
|
541
|
+
provider_charge_id: string | null;
|
|
542
|
+
provider_status: string | null;
|
|
543
|
+
last_error_code: string | null;
|
|
544
|
+
paid_at: string | null;
|
|
545
|
+
last_synced_at: string | null;
|
|
546
|
+
created_at: string | null;
|
|
547
|
+
version: number;
|
|
548
|
+
/** Only in `payments.get`. */
|
|
549
|
+
refunds?: Refund[];
|
|
550
|
+
}
|
|
551
|
+
export interface PaymentListParams extends PageParams {
|
|
552
|
+
order_id?: string;
|
|
553
|
+
contact_id?: string;
|
|
554
|
+
status?: PaymentStatus;
|
|
555
|
+
has_dispute?: boolean;
|
|
556
|
+
created_from?: string;
|
|
557
|
+
created_to?: string;
|
|
412
558
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { AppModule } from "./project.types";
|
|
3
|
+
/**
|
|
4
|
+
* Where a site's business data lives: `/projects/{project_id}/...`.
|
|
5
|
+
*
|
|
6
|
+
* A site knows its app id; the project it belongs to comes from its public
|
|
7
|
+
* settings, read the first time a business module needs it and then kept.
|
|
8
|
+
* `createClient({ projectId })` skips the read.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export interface ProjectScope {
|
|
13
|
+
/** The project id, as given or as read from the public settings. */
|
|
14
|
+
projectId(): Promise<string>;
|
|
15
|
+
/** `/projects/{project_id}` + `path`. */
|
|
16
|
+
path(path: string): Promise<string>;
|
|
17
|
+
app: AppModule;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
export declare function createProjectScope(axios: AxiosInstance, appId: string, projectId?: string): ProjectScope;
|
|
21
|
+
/** `encodeURIComponent` for one path segment. @internal */
|
|
22
|
+
export declare const seg: (value: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* A query string from the params that were actually given: `undefined` and
|
|
25
|
+
* `null` are left out, booleans become `"true"` / `"false"`.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function queryOf(params: object | undefined): Record<string, string | number>;
|
|
30
|
+
/** The Idempotency-Key header, when one was given. @internal */
|
|
31
|
+
export declare function idempotencyHeaders(key?: string): Record<string, string>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export function createProjectScope(axios, appId, projectId) {
|
|
3
|
+
let settings = null;
|
|
4
|
+
function getPublicSettings() {
|
|
5
|
+
if (!settings) {
|
|
6
|
+
const reading = axios.get(`/apps/public/prod/public-settings/by-id/${encodeURIComponent(appId)}`);
|
|
7
|
+
// A failed read is not kept: the next call tries again.
|
|
8
|
+
settings = reading.catch((error) => {
|
|
9
|
+
settings = null;
|
|
10
|
+
throw error;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return settings;
|
|
14
|
+
}
|
|
15
|
+
async function resolveProjectId() {
|
|
16
|
+
if (projectId)
|
|
17
|
+
return projectId;
|
|
18
|
+
const read = await getPublicSettings();
|
|
19
|
+
if (!(read === null || read === void 0 ? void 0 : read.project_id)) {
|
|
20
|
+
throw new Error("This app's public settings carry no project_id; pass projectId to createClient()");
|
|
21
|
+
}
|
|
22
|
+
return read.project_id;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
projectId: resolveProjectId,
|
|
26
|
+
async path(path) {
|
|
27
|
+
return `/projects/${encodeURIComponent(await resolveProjectId())}${path}`;
|
|
28
|
+
},
|
|
29
|
+
app: { getPublicSettings },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** `encodeURIComponent` for one path segment. @internal */
|
|
33
|
+
export const seg = (value) => encodeURIComponent(value);
|
|
34
|
+
/**
|
|
35
|
+
* A query string from the params that were actually given: `undefined` and
|
|
36
|
+
* `null` are left out, booleans become `"true"` / `"false"`.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export function queryOf(params) {
|
|
41
|
+
const out = {};
|
|
42
|
+
for (const [key, value] of Object.entries(params !== null && params !== void 0 ? params : {})) {
|
|
43
|
+
if (value === undefined || value === null || value === "")
|
|
44
|
+
continue;
|
|
45
|
+
out[key] = typeof value === "boolean" ? String(value) : value;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** The Idempotency-Key header, when one was given. @internal */
|
|
50
|
+
export function idempotencyHeaders(key) {
|
|
51
|
+
return key ? { "Idempotency-Key": key } : {};
|
|
52
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One page of a list. Every `/projects/...` list answers in this shape.
|
|
3
|
+
*
|
|
4
|
+
* Pass `next_cursor` back as `cursor` to get the next page; it is `null` on the
|
|
5
|
+
* last one. Change the sort and you start again from the first page.
|
|
6
|
+
*/
|
|
7
|
+
export interface Page<T> {
|
|
8
|
+
data: T[];
|
|
9
|
+
has_more: boolean;
|
|
10
|
+
next_cursor: string | null;
|
|
11
|
+
}
|
|
12
|
+
/** What every `/projects/...` list accepts, besides its own filters. */
|
|
13
|
+
export interface PageParams {
|
|
14
|
+
/** 1–200, default 50. */
|
|
15
|
+
limit?: number;
|
|
16
|
+
/** The `next_cursor` of the previous page. */
|
|
17
|
+
cursor?: string;
|
|
18
|
+
/** A field name, `-` in front for descending. Each list documents its fields. */
|
|
19
|
+
sort?: string;
|
|
20
|
+
}
|
|
21
|
+
/** The version a change is based on: send back the `version` you last read. */
|
|
22
|
+
export interface VersionInput {
|
|
23
|
+
version: number;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Makes a retry of the same create answer with the first record instead of
|
|
28
|
+
* making a second one (16–255 characters). Optional.
|
|
29
|
+
*/
|
|
30
|
+
idempotencyKey?: string;
|
|
31
|
+
}
|
|
32
|
+
/** An address: every part may be empty; `country` is two upper-case letters. */
|
|
33
|
+
export interface Address {
|
|
34
|
+
line: string | null;
|
|
35
|
+
city: string | null;
|
|
36
|
+
region: string | null;
|
|
37
|
+
postal_code: string | null;
|
|
38
|
+
country: string | null;
|
|
39
|
+
}
|
|
40
|
+
/** What a site reads about itself before anything else. */
|
|
41
|
+
export interface AppPublicSettings {
|
|
42
|
+
/** The app (site) id. */
|
|
43
|
+
id: string;
|
|
44
|
+
/** The business the site belongs to: the `/projects/{project_id}/...` APIs are under it. */
|
|
45
|
+
project_id: string;
|
|
46
|
+
/** Whatever the site stored; `null` when it stored nothing. */
|
|
47
|
+
public_settings: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The site itself.
|
|
51
|
+
*/
|
|
52
|
+
export interface AppModule {
|
|
53
|
+
/**
|
|
54
|
+
* The site's public settings, including the `project_id` its business data
|
|
55
|
+
* lives under. Read once per client and kept.
|
|
56
|
+
*/
|
|
57
|
+
getPublicSettings(): Promise<AppPublicSettings>;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/modules/users.d.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
+
import { ProjectScope } from "./project.js";
|
|
3
|
+
import { UsersModule } from "./users.types";
|
|
2
4
|
/**
|
|
3
|
-
* Creates the users module
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
5
|
+
* Creates the users module: inviting (`/apps/{app_id}/...`) and account
|
|
6
|
+
* management (`/projects/{project_id}/users/...`).
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
7
9
|
*/
|
|
8
|
-
export declare function createUsersModule(axios: AxiosInstance, appId: string):
|
|
9
|
-
/**
|
|
10
|
-
* Invite a user to the application
|
|
11
|
-
* @param {string} user_email - User's email address
|
|
12
|
-
* @param {'user'|'admin'} role - User's role (user or admin)
|
|
13
|
-
* @returns {Promise<any>}
|
|
14
|
-
*/
|
|
15
|
-
inviteUser(user_email: string, role: "user" | "admin"): Promise<any>;
|
|
16
|
-
};
|
|
10
|
+
export declare function createUsersModule(axios: AxiosInstance, appId: string, project: ProjectScope): UsersModule;
|
package/dist/modules/users.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
+
import { queryOf, seg } from "./project.js";
|
|
1
2
|
/**
|
|
2
|
-
* Creates the users module
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
3
|
+
* Creates the users module: inviting (`/apps/{app_id}/...`) and account
|
|
4
|
+
* management (`/projects/{project_id}/users/...`).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
6
7
|
*/
|
|
7
|
-
export function createUsersModule(axios, appId) {
|
|
8
|
+
export function createUsersModule(axios, appId, project) {
|
|
9
|
+
const users = (suffix = "") => project.path(`/users${suffix}`);
|
|
8
10
|
return {
|
|
9
|
-
/**
|
|
10
|
-
* Invite a user to the application
|
|
11
|
-
* @param {string} user_email - User's email address
|
|
12
|
-
* @param {'user'|'admin'} role - User's role (user or admin)
|
|
13
|
-
* @returns {Promise<any>}
|
|
14
|
-
*/
|
|
15
11
|
async inviteUser(user_email, role) {
|
|
16
12
|
if (role !== "user" && role !== "admin") {
|
|
17
13
|
throw new Error(`Invalid role: "${role}". Role must be either "user" or "admin".`);
|
|
@@ -19,5 +15,22 @@ export function createUsersModule(axios, appId) {
|
|
|
19
15
|
const response = await axios.post(`/apps/${appId}/runtime/users/invite-user`, { user_email, role });
|
|
20
16
|
return response;
|
|
21
17
|
},
|
|
18
|
+
async list(params = {}) {
|
|
19
|
+
return (await axios.get(await users(), { params: queryOf(params) }));
|
|
20
|
+
},
|
|
21
|
+
async get(userId) {
|
|
22
|
+
return (await axios.get(await users(`/${seg(userId)}`)));
|
|
23
|
+
},
|
|
24
|
+
async disable(userId) {
|
|
25
|
+
return (await axios.request({ method: "POST", url: await users(`/${seg(userId)}/disable`) }));
|
|
26
|
+
},
|
|
27
|
+
async enable(userId) {
|
|
28
|
+
return (await axios.request({ method: "POST", url: await users(`/${seg(userId)}/enable`) }));
|
|
29
|
+
},
|
|
30
|
+
async setContact(userId, contactId) {
|
|
31
|
+
return (await axios.put(await users(`/${seg(userId)}/contact`), {
|
|
32
|
+
contact_id: contactId,
|
|
33
|
+
}));
|
|
34
|
+
},
|
|
22
35
|
};
|
|
23
36
|
}
|