pocketsflow 1.0.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/README.md ADDED
@@ -0,0 +1,354 @@
1
+ # Pocketsflow Node.js SDK
2
+
3
+ Official Node.js/TypeScript SDK for the [Pocketsflow](https://pocketsflow.com) API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install pocketsflow
9
+ # or
10
+ yarn add pocketsflow
11
+ # or
12
+ pnpm add pocketsflow
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { Pocketsflow } from 'pocketsflow';
19
+
20
+ const pocketsflow = new Pocketsflow({
21
+ apiKey: 'pk_live_your_api_key_here',
22
+ });
23
+
24
+ // List all products
25
+ const products = await pocketsflow.products.list();
26
+
27
+ // Get a specific product
28
+ const product = await pocketsflow.products.get('product_id');
29
+
30
+ // Create a new product
31
+ const newProduct = await pocketsflow.products.create({
32
+ name: 'My Digital Product',
33
+ price: 29.99,
34
+ currency: 'USD',
35
+ });
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ ```typescript
41
+ const pocketsflow = new Pocketsflow({
42
+ apiKey: 'pk_live_your_api_key_here', // Required
43
+ baseUrl: 'https://api.pocketsflow.com', // Optional, defaults to production
44
+ timeout: 30000, // Optional, request timeout in ms
45
+ });
46
+ ```
47
+
48
+ ### Test Mode
49
+
50
+ Use a test mode API key (`pk_test_...`) to interact with test data:
51
+
52
+ ```typescript
53
+ const pocketsflow = new Pocketsflow({
54
+ apiKey: 'pk_test_your_test_key_here',
55
+ });
56
+ ```
57
+
58
+ ## Resources
59
+
60
+ ### Products
61
+
62
+ ```typescript
63
+ // List all products
64
+ const products = await pocketsflow.products.list();
65
+
66
+ // Get a product
67
+ const product = await pocketsflow.products.get('product_id');
68
+
69
+ // Create a product
70
+ const product = await pocketsflow.products.create({
71
+ name: 'Premium Course',
72
+ description: 'Learn everything about...',
73
+ price: 99.99,
74
+ currency: 'USD',
75
+ type: 'one-time', // or 'subscription'
76
+ });
77
+
78
+ // Update a product
79
+ const updated = await pocketsflow.products.update('product_id', {
80
+ name: 'Updated Name',
81
+ price: 149.99,
82
+ });
83
+
84
+ // Delete a product
85
+ await pocketsflow.products.delete('product_id');
86
+ ```
87
+
88
+ ### Product Variants
89
+
90
+ ```typescript
91
+ // Create a variant
92
+ const variant = await pocketsflow.variants.create({
93
+ productId: 'product_id',
94
+ name: 'Premium Version',
95
+ price: 149.99,
96
+ });
97
+
98
+ // Delete a variant
99
+ await pocketsflow.variants.delete('variant_id');
100
+ ```
101
+
102
+ ### Orders
103
+
104
+ ```typescript
105
+ // List orders with pagination and filters
106
+ const { orders, pagination } = await pocketsflow.orders.list({
107
+ page: 1,
108
+ pageSize: 20,
109
+ startDate: '2024-01-01',
110
+ endDate: '2024-12-31',
111
+ productId: 'product_id', // optional filter
112
+ });
113
+
114
+ // Get a specific order
115
+ const order = await pocketsflow.orders.get('order_id');
116
+ ```
117
+
118
+ ### Customers
119
+
120
+ ```typescript
121
+ // List all customers
122
+ const customers = await pocketsflow.customers.list({
123
+ email: 'customer@example.com', // optional filter
124
+ sortBy: 'createdAt',
125
+ sortOrder: 'desc',
126
+ });
127
+
128
+ // Get a customer
129
+ const customer = await pocketsflow.customers.get('customer_id');
130
+ ```
131
+
132
+ ### Reviews
133
+
134
+ ```typescript
135
+ // List all reviews
136
+ const reviews = await pocketsflow.reviews.list();
137
+
138
+ // Filter by product
139
+ const productReviews = await pocketsflow.reviews.list({
140
+ productId: 'product_id',
141
+ });
142
+ ```
143
+
144
+ ### Discounts
145
+
146
+ ```typescript
147
+ // List all discounts
148
+ const discounts = await pocketsflow.discounts.list();
149
+
150
+ // Get a discount
151
+ const discount = await pocketsflow.discounts.get('discount_id');
152
+
153
+ // Create a discount
154
+ const discount = await pocketsflow.discounts.create({
155
+ name: 'Summer Sale',
156
+ code: 'SUMMER20',
157
+ value: 20,
158
+ valueType: 'percentage', // or 'fixed'
159
+ mainProductIds: ['product_id_1', 'product_id_2'],
160
+ expiration: '2024-12-31',
161
+ });
162
+
163
+ // Update a discount
164
+ const updated = await pocketsflow.discounts.update('discount_id', {
165
+ value: 25,
166
+ active: true,
167
+ });
168
+
169
+ // Delete a discount
170
+ await pocketsflow.discounts.delete('discount_id');
171
+ ```
172
+
173
+ ### Upsells
174
+
175
+ ```typescript
176
+ // List all upsells
177
+ const { upsells } = await pocketsflow.upsells.list();
178
+
179
+ // Get an upsell
180
+ const upsell = await pocketsflow.upsells.get('upsell_id');
181
+
182
+ // Create an upsell
183
+ const upsell = await pocketsflow.upsells.create({
184
+ name: 'Premium Upgrade',
185
+ mainProductIds: ['product_id'],
186
+ upsellProductId: 'premium_product_id',
187
+ upsellPrice: 49.99,
188
+ upsellDescription: 'Upgrade to premium!',
189
+ primaryButtonText: 'Yes, upgrade me!',
190
+ secondaryButtonText: 'No thanks',
191
+ });
192
+
193
+ // Update an upsell
194
+ const updated = await pocketsflow.upsells.update('upsell_id', {
195
+ upsellPrice: 39.99,
196
+ active: true,
197
+ });
198
+
199
+ // Delete an upsell
200
+ await pocketsflow.upsells.delete('upsell_id');
201
+ ```
202
+
203
+ ### Subscriptions
204
+
205
+ ```typescript
206
+ // List subscription customers
207
+ const subscriptions = await pocketsflow.subscriptions.list({
208
+ page: 1,
209
+ pageSize: 20,
210
+ });
211
+
212
+ // Get a subscription
213
+ const subscription = await pocketsflow.subscriptions.get('subscription_id');
214
+
215
+ // Cancel a subscription
216
+ await pocketsflow.subscriptions.cancel('stripe_subscription_id');
217
+
218
+ // Refund a subscription
219
+ await pocketsflow.subscriptions.refund('stripe_subscription_id');
220
+ ```
221
+
222
+ ### Webhooks
223
+
224
+ ```typescript
225
+ // List all webhooks
226
+ const webhooks = await pocketsflow.webhooks.list();
227
+
228
+ // Get a webhook
229
+ const webhook = await pocketsflow.webhooks.get('webhook_id');
230
+
231
+ // Create a webhook
232
+ const webhook = await pocketsflow.webhooks.create({
233
+ url: 'https://your-server.com/webhook',
234
+ events: ['order.created', 'order.refunded'],
235
+ description: 'My webhook',
236
+ });
237
+
238
+ // Update a webhook
239
+ const updated = await pocketsflow.webhooks.update('webhook_id', {
240
+ events: ['order.created', 'order.refunded', 'subscription.created'],
241
+ active: true,
242
+ });
243
+
244
+ // Test a webhook
245
+ await pocketsflow.webhooks.test('webhook_id');
246
+
247
+ // Delete a webhook
248
+ await pocketsflow.webhooks.delete('webhook_id');
249
+ ```
250
+
251
+ ### User / Account
252
+
253
+ ```typescript
254
+ // Get current user info
255
+ const user = await pocketsflow.users.me();
256
+
257
+ // Update user settings
258
+ const updated = await pocketsflow.users.update({
259
+ firstName: 'John',
260
+ lastName: 'Doe',
261
+ currency: 'USD',
262
+ });
263
+ ```
264
+
265
+ ### Checkout Sessions
266
+
267
+ ```typescript
268
+ // Create a checkout session
269
+ const session = await pocketsflow.checkout.create({
270
+ productId: 'product_id',
271
+ successUrl: 'https://your-site.com/success',
272
+ cancelUrl: 'https://your-site.com/cancel',
273
+ customerEmail: 'customer@example.com', // optional
274
+ discountCode: 'SUMMER20', // optional
275
+ metadata: { orderId: '12345' }, // optional
276
+ });
277
+
278
+ // Redirect customer to checkout
279
+ console.log(session.url); // https://...pocketsflow.com/checkout/...
280
+ ```
281
+
282
+ ### Refunds
283
+
284
+ ```typescript
285
+ // List all refunds
286
+ const refunds = await pocketsflow.refunds.list();
287
+
288
+ // Get a refund
289
+ const refund = await pocketsflow.refunds.get('refund_id');
290
+
291
+ // Create a refund
292
+ const refund = await pocketsflow.refunds.create({
293
+ orderId: 'order_id',
294
+ amount: 29.99, // optional, defaults to full refund
295
+ reason: 'Customer requested refund',
296
+ });
297
+ ```
298
+
299
+ ## Error Handling
300
+
301
+ ```typescript
302
+ import { Pocketsflow, PocketsflowError } from 'pocketsflow';
303
+
304
+ try {
305
+ const product = await pocketsflow.products.get('invalid_id');
306
+ } catch (error) {
307
+ if (error instanceof PocketsflowError) {
308
+ console.error('API Error:', error.message);
309
+ console.error('Status:', error.status); // HTTP status code
310
+ console.error('Code:', error.code); // Error code if available
311
+ }
312
+ }
313
+ ```
314
+
315
+ ## TypeScript
316
+
317
+ The SDK is written in TypeScript and includes full type definitions:
318
+
319
+ ```typescript
320
+ import {
321
+ Pocketsflow,
322
+ Product,
323
+ Order,
324
+ Customer,
325
+ CreateProductParams,
326
+ } from 'pocketsflow';
327
+
328
+ const params: CreateProductParams = {
329
+ name: 'My Product',
330
+ price: 29.99,
331
+ currency: 'USD',
332
+ };
333
+
334
+ const product: Product = await pocketsflow.products.create(params);
335
+ ```
336
+
337
+ ## Requirements
338
+
339
+ - Node.js 16.0.0 or later
340
+ - A Pocketsflow account with API keys
341
+
342
+ ## API Documentation
343
+
344
+ For full API documentation, visit [https://api.pocketsflow.com/docs](https://api.pocketsflow.com/docs)
345
+
346
+ ## Support
347
+
348
+ - Documentation: [https://docs.pocketsflow.com](https://docs.pocketsflow.com)
349
+ - API Reference: [https://api.pocketsflow.com/docs](https://api.pocketsflow.com/docs)
350
+ - Support: [https://pocketsflow.com/support](https://pocketsflow.com/support)
351
+
352
+ ## License
353
+
354
+ MIT