@checkoutpage/sdk 0.1.2

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,158 @@
1
+ # CheckoutPage JavaScript SDK
2
+
3
+ Official JavaScript/TypeScript SDK for the CheckoutPage API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @checkoutpage/sdk
9
+ ```
10
+
11
+ Or using pnpm:
12
+
13
+ ```bash
14
+ pnpm add @checkoutpage/sdk
15
+ ```
16
+
17
+ Or using yarn:
18
+
19
+ ```bash
20
+ yarn add @checkoutpage/sdk
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { CheckoutPage } from '@checkoutpage/sdk'
27
+
28
+ const checkoutpage = new CheckoutPage({
29
+ apiKey: 'YOUR_API_KEY',
30
+ })
31
+
32
+ // Get a customer
33
+ const customer = await checkoutpage.customers.get('customer_id')
34
+ console.log(customer)
35
+ ```
36
+
37
+ ## Authentication
38
+
39
+ The SDK requires an API key for authentication. You can obtain your API key from the [CheckoutPage Dashboard](https://app.checkoutpage.com).
40
+
41
+ ```typescript
42
+ const checkoutpage = new CheckoutPage({
43
+ apiKey: process.env.CHECKOUTPAGE_API_KEY,
44
+ })
45
+ ```
46
+
47
+ ### Custom Base URL
48
+
49
+ For testing or custom environments, you can override the base URL:
50
+
51
+ ```typescript
52
+ const checkoutpage = new CheckoutPage({
53
+ apiKey: 'YOUR_API_KEY',
54
+ baseUrl: 'https://custom-api.example.com',
55
+ })
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ ### Customers
61
+
62
+ #### Get a customer
63
+
64
+ ```typescript
65
+ const customer = await checkoutpage.customers.get('6812fe6e9f39b6760576f01c')
66
+ ```
67
+
68
+ ## Error Handling
69
+
70
+ The SDK provides typed error classes for different error scenarios:
71
+
72
+ ```typescript
73
+ import {
74
+ CheckoutPageError,
75
+ AuthenticationError,
76
+ NotFoundError,
77
+ RateLimitError,
78
+ ValidationError,
79
+ APIError,
80
+ } from '@checkoutpage/sdk'
81
+
82
+ try {
83
+ const customer = await checkoutpage.customers.get('customer_id')
84
+ } catch (error) {
85
+ if (error instanceof AuthenticationError) {
86
+ console.error('Invalid API key')
87
+ } else if (error instanceof NotFoundError) {
88
+ console.error('Customer not found')
89
+ } else if (error instanceof RateLimitError) {
90
+ console.error('Rate limit exceeded')
91
+ } else if (error instanceof ValidationError) {
92
+ console.error('Validation error')
93
+ } else if (error instanceof APIError) {
94
+ console.error('API error:', error.statusCode, error.message)
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### Error Types
100
+
101
+ - `CheckoutPageError` - Base error class
102
+ - `AuthenticationError` - Invalid API key or authentication failure (401, 403)
103
+ - `NotFoundError` - Resource not found (404)
104
+ - `RateLimitError` - Rate limit exceeded (429)
105
+ - `ValidationError` - Request validation failed (400, 422)
106
+ - `APIError` - Generic API error with status code and response
107
+
108
+ ## TypeScript Support
109
+
110
+ The SDK is written in TypeScript and provides full type definitions auto-generated from the OpenAPI specification:
111
+
112
+ ```typescript
113
+ import type { Customer, Address, Shipping } from '@checkoutpage/sdk'
114
+
115
+ const customer: Customer = await checkoutpage.customers.get('customer_id')
116
+ ```
117
+
118
+ ### Advanced Type Usage
119
+
120
+ Access all generated types for advanced use cases:
121
+
122
+ ```typescript
123
+ import type { operations, components, paths } from '@checkoutpage/sdk'
124
+
125
+ // Get request type for an operation
126
+ type CreateCouponRequest = operations['coupons/create']['requestBody']['content']['application/json']
127
+
128
+ // Get response type
129
+ type ListCustomersResponse = operations['customers/list']['responses'][200]['content']['application/json']
130
+
131
+ // Access schema components
132
+ type CustomerId = components['schemas']['CustomerId']
133
+ ```
134
+
135
+ See [TYPE_GENERATION.md](../TYPE_GENERATION.md) for more details on working with generated types.
136
+
137
+ ## Requirements
138
+
139
+ - Node.js >= 18.0.0
140
+ - TypeScript >= 5.0.0 (if using TypeScript)
141
+
142
+ ## Examples
143
+
144
+ See the [examples](../examples/js) directory for more usage examples.
145
+
146
+ ## Contributing
147
+
148
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for development setup and guidelines.
149
+
150
+ ## License
151
+
152
+ MIT
153
+
154
+ ## Support
155
+
156
+ - Documentation: https://docs.checkoutpage.com
157
+ - GitHub Issues: https://github.com/checkoutpage/checkoutpage-api-sdk/issues
158
+ - Email: support@checkoutpage.com