checkout-intents 0.1.0 → 0.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.
- package/CHANGELOG.md +49 -0
- package/LICENSE +4 -198
- package/README.md +155 -21
- package/client.d.mts +21 -7
- package/client.d.mts.map +1 -1
- package/client.d.ts +21 -7
- package/client.d.ts.map +1 -1
- package/client.js +37 -10
- package/client.js.map +1 -1
- package/client.mjs +37 -10
- package/client.mjs.map +1 -1
- package/internal/to-file.d.mts +1 -1
- package/internal/to-file.d.ts +1 -1
- package/internal/to-file.js +1 -1
- package/internal/to-file.mjs +1 -1
- package/internal/tslib.js +17 -17
- package/internal/utils/values.js +3 -3
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +3 -3
- package/internal/utils/values.mjs.map +1 -1
- package/package.json +3 -3
- package/resources/brands.d.mts +31 -0
- package/resources/brands.d.mts.map +1 -0
- package/resources/brands.d.ts +31 -0
- package/resources/brands.d.ts.map +1 -0
- package/resources/{api/v1/brands.js → brands.js} +5 -5
- package/resources/brands.js.map +1 -0
- package/resources/brands.mjs +15 -0
- package/resources/brands.mjs.map +1 -0
- package/resources/checkout-intents.d.mts +320 -0
- package/resources/checkout-intents.d.mts.map +1 -0
- package/resources/checkout-intents.d.ts +320 -0
- package/resources/checkout-intents.d.ts.map +1 -0
- package/resources/checkout-intents.js +248 -0
- package/resources/checkout-intents.js.map +1 -0
- package/resources/checkout-intents.mjs +244 -0
- package/resources/checkout-intents.mjs.map +1 -0
- package/resources/index.d.mts +2 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -5
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/src/client.ts +84 -14
- package/src/internal/to-file.ts +1 -1
- package/src/internal/utils/values.ts +3 -3
- package/src/resources/{api/v1/brands.ts → brands.ts} +9 -9
- package/src/resources/checkout-intents.ts +531 -0
- package/src/resources/index.ts +14 -2
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/api/api.d.mts +0 -10
- package/resources/api/api.d.mts.map +0 -1
- package/resources/api/api.d.ts +0 -10
- package/resources/api/api.d.ts.map +0 -1
- package/resources/api/api.js +0 -17
- package/resources/api/api.js.map +0 -1
- package/resources/api/api.mjs +0 -12
- package/resources/api/api.mjs.map +0 -1
- package/resources/api/index.d.mts +0 -3
- package/resources/api/index.d.mts.map +0 -1
- package/resources/api/index.d.ts +0 -3
- package/resources/api/index.d.ts.map +0 -1
- package/resources/api/index.js +0 -9
- package/resources/api/index.js.map +0 -1
- package/resources/api/index.mjs +0 -4
- package/resources/api/index.mjs.map +0 -1
- package/resources/api/v1/brands.d.mts +0 -31
- package/resources/api/v1/brands.d.mts.map +0 -1
- package/resources/api/v1/brands.d.ts +0 -31
- package/resources/api/v1/brands.d.ts.map +0 -1
- package/resources/api/v1/brands.js.map +0 -1
- package/resources/api/v1/brands.mjs +0 -15
- package/resources/api/v1/brands.mjs.map +0 -1
- package/resources/api/v1/checkout-intents.d.mts +0 -117
- package/resources/api/v1/checkout-intents.d.mts.map +0 -1
- package/resources/api/v1/checkout-intents.d.ts +0 -117
- package/resources/api/v1/checkout-intents.d.ts.map +0 -1
- package/resources/api/v1/checkout-intents.js +0 -33
- package/resources/api/v1/checkout-intents.js.map +0 -1
- package/resources/api/v1/checkout-intents.mjs +0 -29
- package/resources/api/v1/checkout-intents.mjs.map +0 -1
- package/resources/api/v1/index.d.mts +0 -4
- package/resources/api/v1/index.d.mts.map +0 -1
- package/resources/api/v1/index.d.ts +0 -4
- package/resources/api/v1/index.d.ts.map +0 -1
- package/resources/api/v1/index.js +0 -11
- package/resources/api/v1/index.js.map +0 -1
- package/resources/api/v1/index.mjs +0 -5
- package/resources/api/v1/index.mjs.map +0 -1
- package/resources/api/v1/v1.d.mts +0 -14
- package/resources/api/v1/v1.d.mts.map +0 -1
- package/resources/api/v1/v1.d.ts +0 -14
- package/resources/api/v1/v1.d.ts.map +0 -1
- package/resources/api/v1/v1.js +0 -21
- package/resources/api/v1/v1.js.map +0 -1
- package/resources/api/v1/v1.mjs +0 -16
- package/resources/api/v1/v1.mjs.map +0 -1
- package/resources/api/v1.d.mts +0 -2
- package/resources/api/v1.d.mts.map +0 -1
- package/resources/api/v1.d.ts +0 -2
- package/resources/api/v1.d.ts.map +0 -1
- package/resources/api/v1.js +0 -6
- package/resources/api/v1.js.map +0 -1
- package/resources/api/v1.mjs +0 -3
- package/resources/api/v1.mjs.map +0 -1
- package/resources/api.d.mts +0 -2
- package/resources/api.d.mts.map +0 -1
- package/resources/api.d.ts +0 -2
- package/resources/api.d.ts.map +0 -1
- package/resources/api.js +0 -6
- package/resources/api.js.map +0 -1
- package/resources/api.mjs +0 -3
- package/resources/api.mjs.map +0 -1
- package/resources/health.d.mts +0 -17
- package/resources/health.d.mts.map +0 -1
- package/resources/health.d.ts +0 -17
- package/resources/health.d.ts.map +0 -1
- package/resources/health.js +0 -15
- package/resources/health.js.map +0 -1
- package/resources/health.mjs +0 -11
- package/resources/health.mjs.map +0 -1
- package/src/resources/api/api.ts +0 -15
- package/src/resources/api/index.ts +0 -4
- package/src/resources/api/v1/checkout-intents.ts +0 -207
- package/src/resources/api/v1/index.ts +0 -15
- package/src/resources/api/v1/v1.ts +0 -41
- package/src/resources/api/v1.ts +0 -3
- package/src/resources/api.ts +0 -3
- package/src/resources/health.ts +0 -24
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
import { APIResource } from "../core/resource.mjs";
|
|
3
|
+
import { path } from "../internal/utils/path.mjs";
|
|
4
|
+
import { sleep } from "../internal/utils/sleep.mjs";
|
|
5
|
+
import { buildHeaders } from "../internal/headers.mjs";
|
|
6
|
+
export class CheckoutIntentsResource extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* Create a checkout intent with the given request body.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const checkoutIntent = await client.checkoutIntents.create({
|
|
13
|
+
* buyer: {
|
|
14
|
+
* address1: '123 Main St',
|
|
15
|
+
* city: 'New York',
|
|
16
|
+
* country: 'United States',
|
|
17
|
+
* email: 'john.doe@example.com',
|
|
18
|
+
* firstName: 'John',
|
|
19
|
+
* lastName: 'Doe',
|
|
20
|
+
* phone: '+1234567890',
|
|
21
|
+
* postalCode: '10001',
|
|
22
|
+
* province: 'NY',
|
|
23
|
+
* },
|
|
24
|
+
* productUrl: 'productUrl',
|
|
25
|
+
* quantity: 1,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
create(body, options) {
|
|
30
|
+
return this._client.post('/api/v1/checkout-intents', { body, ...options });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve a checkout intent by id
|
|
34
|
+
*
|
|
35
|
+
* Returns checkout intent information if the lookup succeeds.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const checkoutIntent =
|
|
40
|
+
* await client.checkoutIntents.retrieve('id');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
retrieve(id, options) {
|
|
44
|
+
return this._client.get(path `/api/v1/checkout-intents/${id}`, options);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Add payment details to a checkout intent
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const checkoutIntent =
|
|
52
|
+
* await client.checkoutIntents.addPayment('id', {
|
|
53
|
+
* paymentMethod: {
|
|
54
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
55
|
+
* type: 'stripe_token',
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
addPayment(id, body, options) {
|
|
61
|
+
return this._client.post(path `/api/v1/checkout-intents/${id}/payment`, { body, ...options });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Confirm a checkout intent with provided payment information
|
|
65
|
+
*
|
|
66
|
+
* Confirm means we have buyer's name, address and payment info, so we can move
|
|
67
|
+
* forward to place the order.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const checkoutIntent = await client.checkoutIntents.confirm(
|
|
72
|
+
* 'id',
|
|
73
|
+
* {
|
|
74
|
+
* paymentMethod: {
|
|
75
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
76
|
+
* type: 'stripe_token',
|
|
77
|
+
* },
|
|
78
|
+
* },
|
|
79
|
+
* );
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
confirm(id, body, options) {
|
|
83
|
+
return this._client.post(path `/api/v1/checkout-intents/${id}/confirm`, { body, ...options });
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A helper to poll a checkout intent until a specific condition is met.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* // Poll until completed or failed
|
|
91
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntil(
|
|
92
|
+
* 'id',
|
|
93
|
+
* (intent) => intent.state === 'completed' || intent.state === 'failed'
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
async pollUntil(id, condition, options) {
|
|
98
|
+
const maxAttempts = options?.maxAttempts ?? 120; // Default: 120 attempts
|
|
99
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 5000; // Default: 5 seconds
|
|
100
|
+
let attempts = 0;
|
|
101
|
+
const headers = buildHeaders([
|
|
102
|
+
options?.headers,
|
|
103
|
+
{
|
|
104
|
+
'X-Stainless-Poll-Helper': 'true',
|
|
105
|
+
'X-Stainless-Custom-Poll-Interval': pollIntervalMs.toString(),
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
while (attempts < maxAttempts) {
|
|
109
|
+
const { data: intent, response } = await this.retrieve(id, {
|
|
110
|
+
...options,
|
|
111
|
+
headers: { ...options?.headers, ...headers.values },
|
|
112
|
+
}).withResponse();
|
|
113
|
+
// Check if condition is met
|
|
114
|
+
if (condition(intent)) {
|
|
115
|
+
return intent;
|
|
116
|
+
}
|
|
117
|
+
attempts++;
|
|
118
|
+
// If we've reached max attempts, throw an error
|
|
119
|
+
if (attempts >= maxAttempts) {
|
|
120
|
+
throw new Error(`Polling timeout: condition not met after ${maxAttempts} attempts (${(maxAttempts * pollIntervalMs) / 1000}s)`);
|
|
121
|
+
}
|
|
122
|
+
// Check if server suggests a polling interval
|
|
123
|
+
let sleepInterval = pollIntervalMs;
|
|
124
|
+
const headerInterval = response.headers.get('retry-after-ms');
|
|
125
|
+
if (headerInterval) {
|
|
126
|
+
const headerIntervalMs = parseInt(headerInterval);
|
|
127
|
+
if (!isNaN(headerIntervalMs)) {
|
|
128
|
+
sleepInterval = headerIntervalMs;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
await sleep(sleepInterval);
|
|
132
|
+
}
|
|
133
|
+
// This should never be reached due to the throw above, but TypeScript needs it
|
|
134
|
+
throw new Error(`Polling timeout: condition not met after ${maxAttempts} attempts`);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A helper to poll a checkout intent until it reaches a completed state
|
|
138
|
+
* (completed or failed).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntilCompleted('id');
|
|
143
|
+
* if (checkoutIntent.state === 'completed') {
|
|
144
|
+
* console.log('Order placed successfully!');
|
|
145
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
146
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async pollUntilCompleted(id, options) {
|
|
151
|
+
return this.pollUntil(id, (intent) => intent.state === 'completed' || intent.state === 'failed', options);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A helper to poll a checkout intent until it's ready for confirmation
|
|
155
|
+
* (awaiting_confirmation state) or has failed. This is typically used after
|
|
156
|
+
* creating a checkout intent to wait for the offer to be retrieved from the merchant.
|
|
157
|
+
*
|
|
158
|
+
* The intent can reach awaiting_confirmation (success - ready to confirm) or failed
|
|
159
|
+
* (offer retrieval failed). Always check the state after polling.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const intent = await client.checkoutIntents.pollUntilAwaitingConfirmation('id');
|
|
164
|
+
*
|
|
165
|
+
* if (intent.state === 'awaiting_confirmation') {
|
|
166
|
+
* // Review the offer before confirming
|
|
167
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
168
|
+
* } else if (intent.state === 'failed') {
|
|
169
|
+
* // Handle failure (e.g., offer retrieval failed, product out of stock)
|
|
170
|
+
* console.log('Failed:', intent.failureReason);
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
async pollUntilAwaitingConfirmation(id, options) {
|
|
175
|
+
return this.pollUntil(id, (intent) => intent.state === 'awaiting_confirmation' || intent.state === 'failed', options);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* A helper to create a checkout intent and poll until it's ready for confirmation.
|
|
179
|
+
* This follows the Rye documented flow: create → poll until awaiting_confirmation.
|
|
180
|
+
*
|
|
181
|
+
* After this method completes, you should review the offer (pricing, shipping, taxes)
|
|
182
|
+
* with the user before calling confirm().
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* // Phase 1: Create and wait for offer
|
|
187
|
+
* const intent = await client.checkoutIntents.createAndPoll({
|
|
188
|
+
* buyer: {
|
|
189
|
+
* address1: '123 Main St',
|
|
190
|
+
* city: 'New York',
|
|
191
|
+
* country: 'United States',
|
|
192
|
+
* email: 'john.doe@example.com',
|
|
193
|
+
* firstName: 'John',
|
|
194
|
+
* lastName: 'Doe',
|
|
195
|
+
* phone: '+1234567890',
|
|
196
|
+
* postalCode: '10001',
|
|
197
|
+
* province: 'NY',
|
|
198
|
+
* },
|
|
199
|
+
* productUrl: 'https://example.com/product',
|
|
200
|
+
* quantity: 1,
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* // Review the offer with the user
|
|
204
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
205
|
+
*
|
|
206
|
+
* // Phase 2: Confirm with payment
|
|
207
|
+
* const completed = await client.checkoutIntents.confirmAndPoll(intent.id, {
|
|
208
|
+
* paymentMethod: { type: 'stripe_token', stripeToken: 'tok_visa' }
|
|
209
|
+
* });
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async createAndPoll(body, options) {
|
|
213
|
+
const intent = await this.create(body, options);
|
|
214
|
+
return this.pollUntilAwaitingConfirmation(intent.id, options);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A helper to confirm a checkout intent and poll until it reaches a completed state
|
|
218
|
+
* (completed or failed).
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* const checkoutIntent = await client.checkoutIntents.confirmAndPoll(
|
|
223
|
+
* 'id',
|
|
224
|
+
* {
|
|
225
|
+
* paymentMethod: {
|
|
226
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
227
|
+
* type: 'stripe_token',
|
|
228
|
+
* },
|
|
229
|
+
* }
|
|
230
|
+
* );
|
|
231
|
+
*
|
|
232
|
+
* if (checkoutIntent.state === 'completed') {
|
|
233
|
+
* console.log('Order placed successfully!');
|
|
234
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
235
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
async confirmAndPoll(id, body, options) {
|
|
240
|
+
const intent = await this.confirm(id, body, options);
|
|
241
|
+
return this.pollUntilCompleted(intent.id, options);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=checkout-intents.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-intents.mjs","sourceRoot":"","sources":["../src/resources/checkout-intents.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OAIf,EAAE,IAAI,EAAE;OACR,EAAE,KAAK,EAAE;OACT,EAAE,YAAY,EAAE;AAiBvB,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAgC,EAAE,OAAwB;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAU,EAAE,OAAwB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAA,4BAA4B,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,UAAU,CACR,EAAU,EACV,IAAoC,EACpC,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAA,4BAA4B,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC/F,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,CACL,EAAU,EACV,IAAiC,EACjC,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAA,4BAA4B,EAAE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,EACV,IAAiC,EACjC,OAAsC;QAEtC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;CACF"}
|
package/resources/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { Brands, type BrandRetrieveResponse } from "./brands.mjs";
|
|
2
|
+
export { CheckoutIntentsResource, type BaseCheckoutIntent, type Buyer, type CheckoutIntent, type Money, type Offer, type PaymentMethod, type VariantSelection, type CheckoutIntentCreateParams, type CheckoutIntentAddPaymentParams, type CheckoutIntentConfirmParams, } from "./checkout-intents.mjs";
|
|
3
3
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,KAAK,qBAAqB,EAAE;OACtC,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EACnC,KAAK,2BAA2B,GACjC"}
|
package/resources/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { Brands, type BrandRetrieveResponse } from "./brands.js";
|
|
2
|
+
export { CheckoutIntentsResource, type BaseCheckoutIntent, type Buyer, type CheckoutIntent, type Money, type Offer, type PaymentMethod, type VariantSelection, type CheckoutIntentCreateParams, type CheckoutIntentAddPaymentParams, type CheckoutIntentConfirmParams, } from "./checkout-intents.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/resources/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,KAAK,qBAAqB,EAAE;OACtC,EACL,uBAAuB,EACvB,KAAK,kBAAkB,EACvB,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EACnC,KAAK,2BAA2B,GACjC"}
|
package/resources/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
var
|
|
6
|
-
Object.defineProperty(exports, "
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "
|
|
4
|
+
exports.CheckoutIntentsResource = exports.Brands = void 0;
|
|
5
|
+
var brands_1 = require("./brands.js");
|
|
6
|
+
Object.defineProperty(exports, "Brands", { enumerable: true, get: function () { return brands_1.Brands; } });
|
|
7
|
+
var checkout_intents_1 = require("./checkout-intents.js");
|
|
8
|
+
Object.defineProperty(exports, "CheckoutIntentsResource", { enumerable: true, get: function () { return checkout_intents_1.CheckoutIntentsResource; } });
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/resources/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,sCAA8D;AAArD,gGAAA,MAAM,OAAA;AACf,0DAY4B;AAX1B,2HAAA,uBAAuB,OAAA"}
|
package/resources/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { Brands } from "./brands.mjs";
|
|
3
|
+
export { CheckoutIntentsResource, } from "./checkout-intents.mjs";
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
package/resources/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/resources/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,MAAM,EAA8B;OACtC,EACL,uBAAuB,GAWxB"}
|
package/src/client.ts
CHANGED
|
@@ -16,8 +16,20 @@ import * as Errors from './core/error';
|
|
|
16
16
|
import * as Uploads from './core/uploads';
|
|
17
17
|
import * as API from './resources/index';
|
|
18
18
|
import { APIPromise } from './core/api-promise';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { BrandRetrieveResponse, Brands } from './resources/brands';
|
|
20
|
+
import {
|
|
21
|
+
BaseCheckoutIntent,
|
|
22
|
+
Buyer,
|
|
23
|
+
CheckoutIntent,
|
|
24
|
+
CheckoutIntentAddPaymentParams,
|
|
25
|
+
CheckoutIntentConfirmParams,
|
|
26
|
+
CheckoutIntentCreateParams,
|
|
27
|
+
CheckoutIntentsResource,
|
|
28
|
+
Money,
|
|
29
|
+
Offer,
|
|
30
|
+
PaymentMethod,
|
|
31
|
+
VariantSelection,
|
|
32
|
+
} from './resources/checkout-intents';
|
|
21
33
|
import { type Fetch } from './internal/builtin-types';
|
|
22
34
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
23
35
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -31,12 +43,38 @@ import {
|
|
|
31
43
|
} from './internal/utils/log';
|
|
32
44
|
import { isEmptyObj } from './internal/utils/values';
|
|
33
45
|
|
|
46
|
+
const environments = {
|
|
47
|
+
staging: 'https://staging.api.rye.com/',
|
|
48
|
+
production: 'https://api.rye.com/',
|
|
49
|
+
};
|
|
50
|
+
type Environment = keyof typeof environments;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extracts the environment from a Rye API key.
|
|
54
|
+
* API keys follow the format: RYE/{environment}-{key}
|
|
55
|
+
* @param apiKey - The API key to parse
|
|
56
|
+
* @returns The extracted environment ('staging' or 'production'), or null if the format doesn't match
|
|
57
|
+
*/
|
|
58
|
+
function extractEnvironmentFromApiKey(apiKey: string): Environment | null {
|
|
59
|
+
const match = apiKey.match(/^RYE\/(staging|production)-/);
|
|
60
|
+
return match ? (match[1] as Environment) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
34
63
|
export interface ClientOptions {
|
|
35
64
|
/**
|
|
36
|
-
* Rye API key. Format: `
|
|
65
|
+
* Rye API key. Format: `RYE/{environment}-abcdef`
|
|
37
66
|
*/
|
|
38
67
|
apiKey?: string | undefined;
|
|
39
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Specifies the environment to use for the API.
|
|
71
|
+
*
|
|
72
|
+
* Each environment maps to a different base URL:
|
|
73
|
+
* - `staging` corresponds to `https://staging.api.rye.com/`
|
|
74
|
+
* - `production` corresponds to `https://api.rye.com/`
|
|
75
|
+
*/
|
|
76
|
+
environment?: Environment | undefined;
|
|
77
|
+
|
|
40
78
|
/**
|
|
41
79
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
42
80
|
*
|
|
@@ -128,6 +166,7 @@ export class CheckoutIntents {
|
|
|
128
166
|
* API Client for interfacing with the Checkout Intents API.
|
|
129
167
|
*
|
|
130
168
|
* @param {string | undefined} [opts.apiKey=process.env['CHECKOUT_INTENTS_API_KEY'] ?? undefined]
|
|
169
|
+
* @param {Environment} [opts.environment=staging] - Specifies the environment URL to use for the API.
|
|
131
170
|
* @param {string} [opts.baseURL=process.env['CHECKOUT_INTENTS_BASE_URL'] ?? https://staging.api.rye.com/] - Override the default base URL for the API.
|
|
132
171
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
133
172
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
@@ -147,13 +186,31 @@ export class CheckoutIntents {
|
|
|
147
186
|
);
|
|
148
187
|
}
|
|
149
188
|
|
|
189
|
+
// Auto-infer environment from API key
|
|
190
|
+
const inferredEnvironment = extractEnvironmentFromApiKey(apiKey);
|
|
191
|
+
|
|
192
|
+
// Validate environment option matches API key (if both provided)
|
|
193
|
+
if (opts.environment && inferredEnvironment && opts.environment !== inferredEnvironment) {
|
|
194
|
+
throw new Errors.CheckoutIntentsError(
|
|
195
|
+
`Environment mismatch: API key is for '${inferredEnvironment}' environment but 'environment' option is set to '${opts.environment}'. Please use an API key that matches your desired environment or omit the 'environment' option to auto-detect from the API key (only auto-detectable with the RYE/{environment}-abcdef api key format).`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
150
199
|
const options: ClientOptions = {
|
|
151
200
|
apiKey,
|
|
152
201
|
...opts,
|
|
153
|
-
baseURL
|
|
202
|
+
baseURL,
|
|
203
|
+
// Use provided environment, or infer from API key, or default to staging
|
|
204
|
+
environment: opts.environment ?? inferredEnvironment ?? 'staging',
|
|
154
205
|
};
|
|
155
206
|
|
|
156
|
-
|
|
207
|
+
if (baseURL && opts.environment) {
|
|
208
|
+
throw new Errors.CheckoutIntentsError(
|
|
209
|
+
'Ambiguous URL; The `baseURL` option (or CHECKOUT_INTENTS_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
this.baseURL = options.baseURL || environments[options.environment || 'staging'];
|
|
157
214
|
this.timeout = options.timeout ?? CheckoutIntents.DEFAULT_TIMEOUT /* 1 minute */;
|
|
158
215
|
this.logger = options.logger ?? console;
|
|
159
216
|
const defaultLogLevel = 'warn';
|
|
@@ -179,7 +236,8 @@ export class CheckoutIntents {
|
|
|
179
236
|
withOptions(options: Partial<ClientOptions>): this {
|
|
180
237
|
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
181
238
|
...this._options,
|
|
182
|
-
|
|
239
|
+
environment: options.environment ? options.environment : undefined,
|
|
240
|
+
baseURL: options.environment ? undefined : this.baseURL,
|
|
183
241
|
maxRetries: this.maxRetries,
|
|
184
242
|
timeout: this.timeout,
|
|
185
243
|
logger: this.logger,
|
|
@@ -196,7 +254,7 @@ export class CheckoutIntents {
|
|
|
196
254
|
* Check whether the base URL is set to its default.
|
|
197
255
|
*/
|
|
198
256
|
#baseURLOverridden(): boolean {
|
|
199
|
-
return this.baseURL !==
|
|
257
|
+
return this.baseURL !== environments[this._options.environment || 'staging'];
|
|
200
258
|
}
|
|
201
259
|
|
|
202
260
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
@@ -715,17 +773,29 @@ export class CheckoutIntents {
|
|
|
715
773
|
|
|
716
774
|
static toFile = Uploads.toFile;
|
|
717
775
|
|
|
718
|
-
|
|
719
|
-
|
|
776
|
+
checkoutIntents: API.CheckoutIntentsResource = new API.CheckoutIntentsResource(this);
|
|
777
|
+
brands: API.Brands = new API.Brands(this);
|
|
720
778
|
}
|
|
721
779
|
|
|
722
|
-
CheckoutIntents.
|
|
723
|
-
CheckoutIntents.
|
|
780
|
+
CheckoutIntents.CheckoutIntentsResource = CheckoutIntentsResource;
|
|
781
|
+
CheckoutIntents.Brands = Brands;
|
|
724
782
|
|
|
725
783
|
export declare namespace CheckoutIntents {
|
|
726
784
|
export type RequestOptions = Opts.RequestOptions;
|
|
727
785
|
|
|
728
|
-
export {
|
|
729
|
-
|
|
730
|
-
|
|
786
|
+
export {
|
|
787
|
+
CheckoutIntentsResource as CheckoutIntentsResource,
|
|
788
|
+
type BaseCheckoutIntent as BaseCheckoutIntent,
|
|
789
|
+
type Buyer as Buyer,
|
|
790
|
+
type CheckoutIntent as CheckoutIntent,
|
|
791
|
+
type Money as Money,
|
|
792
|
+
type Offer as Offer,
|
|
793
|
+
type PaymentMethod as PaymentMethod,
|
|
794
|
+
type VariantSelection as VariantSelection,
|
|
795
|
+
type CheckoutIntentCreateParams as CheckoutIntentCreateParams,
|
|
796
|
+
type CheckoutIntentAddPaymentParams as CheckoutIntentAddPaymentParams,
|
|
797
|
+
type CheckoutIntentConfirmParams as CheckoutIntentConfirmParams,
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
export { Brands as Brands, type BrandRetrieveResponse as BrandRetrieveResponse };
|
|
731
801
|
}
|
package/src/internal/to-file.ts
CHANGED
|
@@ -73,7 +73,7 @@ export type ToFileInput =
|
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
|
|
76
|
-
* @param value the raw content of the file.
|
|
76
|
+
* @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
|
|
77
77
|
* @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
|
|
78
78
|
* @param {Object=} options additional properties
|
|
79
79
|
* @param {string=} options.type the MIME type of the content
|
|
@@ -76,21 +76,21 @@ export const coerceBoolean = (value: unknown): boolean => {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
79
|
-
if (value
|
|
79
|
+
if (value == null) {
|
|
80
80
|
return undefined;
|
|
81
81
|
}
|
|
82
82
|
return coerceInteger(value);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
86
|
-
if (value
|
|
86
|
+
if (value == null) {
|
|
87
87
|
return undefined;
|
|
88
88
|
}
|
|
89
89
|
return coerceFloat(value);
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
93
|
-
if (value
|
|
93
|
+
if (value == null) {
|
|
94
94
|
return undefined;
|
|
95
95
|
}
|
|
96
96
|
return coerceBoolean(value);
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { APIResource } from '
|
|
4
|
-
import { APIPromise } from '
|
|
5
|
-
import { RequestOptions } from '
|
|
6
|
-
import { path } from '
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import { APIPromise } from '../core/api-promise';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options';
|
|
6
|
+
import { path } from '../internal/utils/path';
|
|
7
7
|
|
|
8
8
|
export class Brands extends APIResource {
|
|
9
9
|
/**
|
|
10
10
|
* Retrieve brand information by domain name
|
|
11
11
|
*
|
|
12
|
-
* Look up a brand by its domain name (e.g. "aloyoga.com").
|
|
13
|
-
* information including the marketplace type if the lookup succeeds.
|
|
12
|
+
* Look up a brand by its domain name (e.g. "aloyoga.com" or "www.amazon.com").
|
|
13
|
+
* Returns brand information including the marketplace type if the lookup succeeds.
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
retrieve(domain: string, options?: RequestOptions): APIPromise<BrandRetrieveResponse> {
|
|
16
16
|
return this._client.get(path`/api/v1/brands/domain/${domain}`, options);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export interface
|
|
20
|
+
export interface BrandRetrieveResponse {
|
|
21
21
|
/**
|
|
22
22
|
* A unique identifier for the brand.
|
|
23
23
|
*/
|
|
@@ -36,5 +36,5 @@ export interface BrandRetrieveByDomainResponse {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export declare namespace Brands {
|
|
39
|
-
export { type
|
|
39
|
+
export { type BrandRetrieveResponse as BrandRetrieveResponse };
|
|
40
40
|
}
|