arky-sdk 0.3.23 → 0.3.25
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 +261 -61
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,114 +1,314 @@
|
|
|
1
|
-
#
|
|
1
|
+
# arky-sdk
|
|
2
2
|
|
|
3
3
|
Official TypeScript SDK for Arky - All-in-one business platform
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install
|
|
8
|
+
npm install arky-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
|
-
### API Client (No State)
|
|
14
|
-
|
|
15
13
|
```typescript
|
|
16
|
-
import {
|
|
14
|
+
import { createArkySDK } from 'arky-sdk'
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const arky = createArkySDK({
|
|
17
|
+
baseUrl: 'https://api.arky.io',
|
|
20
18
|
businessId: 'your-business-id',
|
|
21
|
-
storageUrl: 'https://storage.arky.io'
|
|
19
|
+
storageUrl: 'https://storage.arky.io',
|
|
20
|
+
market: 'us',
|
|
21
|
+
getToken: () => ({
|
|
22
|
+
accessToken: localStorage.getItem('accessToken') || '',
|
|
23
|
+
refreshToken: localStorage.getItem('refreshToken') || '',
|
|
24
|
+
provider: 'EMAIL',
|
|
25
|
+
expiresAt: 0,
|
|
26
|
+
}),
|
|
27
|
+
setToken: (tokens) => {
|
|
28
|
+
localStorage.setItem('accessToken', tokens.accessToken);
|
|
29
|
+
localStorage.setItem('refreshToken', tokens.refreshToken);
|
|
30
|
+
},
|
|
31
|
+
logout: () => {
|
|
32
|
+
localStorage.removeItem('accessToken');
|
|
33
|
+
localStorage.removeItem('refreshToken');
|
|
34
|
+
},
|
|
35
|
+
isAuthenticated: () => !!localStorage.getItem('accessToken'),
|
|
22
36
|
})
|
|
23
37
|
|
|
24
|
-
// Now use the
|
|
25
|
-
|
|
38
|
+
// Now use the SDK
|
|
39
|
+
const collections = await arky.cms.getCollections({});
|
|
40
|
+
const products = await arky.eshop.getProducts({});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Methods
|
|
44
|
+
|
|
45
|
+
The SDK provides the following API modules:
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
### User Management
|
|
48
|
+
```typescript
|
|
49
|
+
// Authentication
|
|
50
|
+
await arky.user.loginUser({ email, password })
|
|
51
|
+
await arky.user.registerUser({ email, password, name })
|
|
52
|
+
await arky.user.getMe()
|
|
53
|
+
await arky.user.logout()
|
|
54
|
+
|
|
55
|
+
// Profile
|
|
56
|
+
await arky.user.updateUser({ name, phoneNumber, addresses })
|
|
57
|
+
await arky.user.resetPassword({ oldPassword, newPassword })
|
|
29
58
|
```
|
|
30
59
|
|
|
31
|
-
###
|
|
60
|
+
### Business
|
|
61
|
+
```typescript
|
|
62
|
+
// Business CRUD
|
|
63
|
+
await arky.business.createBusiness({ name, slug })
|
|
64
|
+
await arky.business.getBusiness()
|
|
65
|
+
await arky.business.updateBusiness({ id, name })
|
|
66
|
+
await arky.business.deleteBusiness({ id })
|
|
67
|
+
|
|
68
|
+
// Subscriptions
|
|
69
|
+
await arky.business.createSubscription({ planId })
|
|
70
|
+
await arky.business.getSubscription()
|
|
71
|
+
await arky.business.cancelSubscription({ immediately: true })
|
|
72
|
+
```
|
|
32
73
|
|
|
74
|
+
### CMS & Newsletters
|
|
33
75
|
```typescript
|
|
34
|
-
|
|
35
|
-
|
|
76
|
+
// Collections
|
|
77
|
+
await arky.cms.createCollection({ name, slug, type: 'NEWSLETTER' })
|
|
78
|
+
await arky.cms.getCollections({ type: 'NEWSLETTER' })
|
|
79
|
+
await arky.cms.getCollection({ id })
|
|
80
|
+
await arky.cms.updateCollection({ id, name })
|
|
81
|
+
await arky.cms.deleteCollection({ id })
|
|
82
|
+
|
|
83
|
+
// Entries (Content)
|
|
84
|
+
await arky.cms.createCollectionEntry({ collectionId, blocks })
|
|
85
|
+
await arky.cms.getCollectionEntries({ collectionId })
|
|
86
|
+
await arky.cms.updateCollectionEntry({ id, blocks })
|
|
87
|
+
await arky.cms.sendEntry({ entryId, scheduledAt })
|
|
88
|
+
|
|
89
|
+
// Newsletter Subscriptions
|
|
90
|
+
await arky.cms.subscribeToCollection({
|
|
91
|
+
collectionId: 'newsletter_id',
|
|
92
|
+
email: 'user@example.com',
|
|
93
|
+
planId: 'plan_free', // Required
|
|
94
|
+
})
|
|
95
|
+
await arky.cms.getCollectionSubscribers({ id: 'newsletter_id' })
|
|
96
|
+
await arky.cms.unsubscribeFromCollection({ token: 'unsubscribe_token' })
|
|
97
|
+
```
|
|
36
98
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
99
|
+
### E-shop
|
|
100
|
+
```typescript
|
|
101
|
+
// Products
|
|
102
|
+
await arky.eshop.createProduct({ name, description, variants })
|
|
103
|
+
await arky.eshop.getProducts({ limit: 20, cursor: null })
|
|
104
|
+
await arky.eshop.getProduct({ id })
|
|
105
|
+
await arky.eshop.updateProduct({ id, name })
|
|
106
|
+
|
|
107
|
+
// Orders
|
|
108
|
+
await arky.eshop.checkout({ items, paymentMethod, shippingMethodId })
|
|
109
|
+
await arky.eshop.getOrders({})
|
|
110
|
+
await arky.eshop.getOrder({ id })
|
|
111
|
+
await arky.eshop.updateOrderStatus({ id, status: 'SHIPPED' })
|
|
112
|
+
|
|
113
|
+
// Quote
|
|
114
|
+
await arky.eshop.getQuote({
|
|
115
|
+
items: [{ productId, variantId, quantity }],
|
|
116
|
+
currency: 'usd',
|
|
117
|
+
paymentMethod: 'CREDIT_CARD',
|
|
40
118
|
})
|
|
119
|
+
```
|
|
41
120
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
121
|
+
### Reservations
|
|
122
|
+
```typescript
|
|
123
|
+
// Services
|
|
124
|
+
await arky.reservation.createService({ name, duration, price })
|
|
125
|
+
await arky.reservation.getServices({})
|
|
126
|
+
await arky.reservation.getAvailableSlots({ serviceId, start, end })
|
|
127
|
+
|
|
128
|
+
// Providers
|
|
129
|
+
await arky.reservation.createProvider({ name, serviceIds })
|
|
130
|
+
await arky.reservation.getProviders({})
|
|
131
|
+
|
|
132
|
+
// Reservations
|
|
133
|
+
await arky.reservation.createReservation({ parts, blocks })
|
|
134
|
+
await arky.reservation.checkout({ parts, paymentMethod })
|
|
135
|
+
await arky.reservation.searchReservations({ start, end })
|
|
45
136
|
```
|
|
46
137
|
|
|
47
|
-
|
|
138
|
+
### Media
|
|
139
|
+
```typescript
|
|
140
|
+
// Upload files
|
|
141
|
+
const media = await arky.media.uploadBusinessMedia({
|
|
142
|
+
files: [file1, file2],
|
|
143
|
+
urls: ['https://example.com/image.jpg'],
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// List media
|
|
147
|
+
const { items } = await arky.media.getBusinessMedia({ limit: 20 })
|
|
148
|
+
|
|
149
|
+
// Delete media
|
|
150
|
+
await arky.media.deleteBusinessMedia({ id: businessId, mediaId })
|
|
151
|
+
```
|
|
48
152
|
|
|
49
|
-
###
|
|
153
|
+
### Notifications
|
|
154
|
+
```typescript
|
|
155
|
+
// Get notifications
|
|
156
|
+
const notifications = await arky.notification.getNotifications({
|
|
157
|
+
limit: 20,
|
|
158
|
+
previous_id: null,
|
|
159
|
+
})
|
|
50
160
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
import { cartItems, eshopActions } from '@arky/sdk/stores'
|
|
54
|
-
</script>
|
|
161
|
+
// Mark as seen
|
|
162
|
+
await arky.notification.updateNotifications({})
|
|
55
163
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</button>
|
|
164
|
+
// Delivery stats
|
|
165
|
+
const stats = await arky.notification.getDeliveryStats({})
|
|
59
166
|
```
|
|
60
167
|
|
|
61
|
-
###
|
|
168
|
+
### Analytics
|
|
169
|
+
```typescript
|
|
170
|
+
// Query metrics
|
|
171
|
+
const data = await arky.analytics.getAnalytics({
|
|
172
|
+
start: '2024-01-01',
|
|
173
|
+
end: '2024-12-31',
|
|
174
|
+
metrics: ['revenue', 'orders', 'users'],
|
|
175
|
+
})
|
|
62
176
|
|
|
63
|
-
|
|
64
|
-
|
|
177
|
+
// Health check
|
|
178
|
+
const health = await arky.analytics.getAnalyticsHealth({})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Roles & Permissions
|
|
182
|
+
```typescript
|
|
183
|
+
await arky.role.createRole({ name, permissions })
|
|
184
|
+
await arky.role.getRoles({ action: 'READ' })
|
|
185
|
+
await arky.role.updateRole({ id, permissions })
|
|
186
|
+
await arky.user.setRole({ userId, roleId })
|
|
65
187
|
```
|
|
66
188
|
|
|
189
|
+
## Utility Functions
|
|
190
|
+
|
|
191
|
+
The SDK includes helpful utilities accessible via `arky.utils`:
|
|
192
|
+
|
|
193
|
+
### Block Utilities
|
|
67
194
|
```typescript
|
|
68
|
-
|
|
69
|
-
|
|
195
|
+
// Get image URL from block
|
|
196
|
+
const url = arky.utils.getImageUrl(imageBlock)
|
|
70
197
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
198
|
+
// Get block values
|
|
199
|
+
const value = arky.utils.getBlockValue(entry, 'title')
|
|
200
|
+
const values = arky.utils.getBlockValues(entry, 'gallery')
|
|
201
|
+
const text = arky.utils.getBlockTextValue(block, 'en')
|
|
202
|
+
|
|
203
|
+
// Format blocks
|
|
204
|
+
const formatted = arky.utils.formatBlockValue(block)
|
|
205
|
+
const forSubmit = arky.utils.prepareBlocksForSubmission(blocks)
|
|
75
206
|
```
|
|
76
207
|
|
|
77
|
-
###
|
|
208
|
+
### Price Utilities
|
|
209
|
+
```typescript
|
|
210
|
+
// Format prices
|
|
211
|
+
const formatted = arky.utils.formatMinor(999, 'usd') // "$9.99"
|
|
212
|
+
const payment = arky.utils.formatPayment(paymentObject)
|
|
78
213
|
|
|
79
|
-
|
|
80
|
-
|
|
214
|
+
// Get market prices
|
|
215
|
+
const price = arky.utils.getMarketPrice(prices, 'US', markets)
|
|
216
|
+
const amount = arky.utils.getPriceAmount(prices, 'US')
|
|
217
|
+
|
|
218
|
+
// Currency
|
|
219
|
+
const symbol = arky.utils.getCurrencySymbol('USD') // "$"
|
|
81
220
|
```
|
|
82
221
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
222
|
+
### Text Utilities
|
|
223
|
+
```typescript
|
|
224
|
+
const slug = arky.utils.slugify('Hello World') // "hello-world"
|
|
225
|
+
const title = arky.utils.humanize('hello-world') // "Hello World"
|
|
226
|
+
const category = arky.utils.categorify('hello-world') // "HELLO WORLD"
|
|
227
|
+
const date = arky.utils.formatDate(timestamp, 'en')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Validation
|
|
231
|
+
```typescript
|
|
232
|
+
const result = arky.utils.validatePhoneNumber('+1234567890')
|
|
233
|
+
// { isValid: true } or { isValid: false, error: "..." }
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### SVG Utilities
|
|
237
|
+
```typescript
|
|
238
|
+
// Fetch SVG content
|
|
239
|
+
const svgString = await arky.utils.fetchSvgContent(mediaBlock)
|
|
87
240
|
|
|
88
|
-
|
|
89
|
-
|
|
241
|
+
// For Astro
|
|
242
|
+
const svg = await arky.utils.getSvgContentForAstro(mediaBlock)
|
|
90
243
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
</template>
|
|
244
|
+
// Inject into element
|
|
245
|
+
await arky.utils.injectSvgIntoElement(mediaBlock, element, 'custom-class')
|
|
94
246
|
```
|
|
95
247
|
|
|
96
248
|
## Features
|
|
97
249
|
|
|
98
|
-
- 🚀 TypeScript-first
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
- 🔄
|
|
102
|
-
-
|
|
250
|
+
- 🚀 **TypeScript-first** - Full type safety and IntelliSense
|
|
251
|
+
- 📦 **Tree-shakeable** - Import only what you need
|
|
252
|
+
- ⚡ **Lightweight** - Minimal bundle size (~120KB)
|
|
253
|
+
- 🔄 **Auto-refresh** - Automatic token refresh
|
|
254
|
+
- 🎯 **Framework-agnostic** - Works with any JavaScript framework
|
|
103
255
|
|
|
104
256
|
## Modules
|
|
105
257
|
|
|
106
|
-
- **CMS** - Headless content management
|
|
107
|
-
- **E-shop** - E-commerce
|
|
108
|
-
- **Reservations** - Booking system
|
|
109
|
-
- **
|
|
110
|
-
- **
|
|
258
|
+
- **CMS** - Headless content management, newsletters, AI blocks
|
|
259
|
+
- **E-shop** - E-commerce, products, orders, checkout
|
|
260
|
+
- **Reservations** - Booking system, services, providers
|
|
261
|
+
- **Business** - Multi-tenant business management
|
|
262
|
+
- **User** - Authentication, profiles, roles
|
|
263
|
+
- **Media** - File upload, image management
|
|
264
|
+
- **Notifications** - Push, email, SMS
|
|
265
|
+
- **Analytics** - Business metrics and insights
|
|
266
|
+
- **Payment** - Stripe integration, quotes
|
|
267
|
+
|
|
268
|
+
## Configuration Options
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
createArkySDK({
|
|
272
|
+
// Required
|
|
273
|
+
baseUrl: string, // API URL
|
|
274
|
+
businessId: string, // Your business ID
|
|
275
|
+
market: string, // Market code (e.g., 'us', 'eu')
|
|
276
|
+
|
|
277
|
+
// Token management
|
|
278
|
+
getToken: () => TokenData,
|
|
279
|
+
setToken: (tokens: TokenData) => void,
|
|
280
|
+
|
|
281
|
+
// Optional
|
|
282
|
+
storageUrl?: string, // Storage URL (default: https://storage.arky.io/dev)
|
|
283
|
+
autoGuest?: boolean, // Auto-create guest token (default: true)
|
|
284
|
+
logout?: () => void, // Logout callback
|
|
285
|
+
isAuthenticated?: () => boolean,
|
|
286
|
+
navigate?: (path: string) => void,
|
|
287
|
+
notify?: (notification: { message: string; type: string }) => void,
|
|
288
|
+
})
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## TypeScript Support
|
|
292
|
+
|
|
293
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
import type {
|
|
297
|
+
HttpClientConfig,
|
|
298
|
+
ApiResponse,
|
|
299
|
+
Block,
|
|
300
|
+
Business,
|
|
301
|
+
Price,
|
|
302
|
+
// ... and many more
|
|
303
|
+
} from 'arky-sdk'
|
|
304
|
+
```
|
|
111
305
|
|
|
112
306
|
## License
|
|
113
307
|
|
|
114
308
|
MIT
|
|
309
|
+
|
|
310
|
+
## Links
|
|
311
|
+
|
|
312
|
+
- [Documentation](https://docs.arky.io)
|
|
313
|
+
- [GitHub](https://github.com/0xDjole/arky-sdk)
|
|
314
|
+
- [npm](https://www.npmjs.com/package/arky-sdk)
|
package/dist/index.cjs
CHANGED