@praxium/sdk 0.3.51 → 0.3.52
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 +69 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @praxium/sdk
|
|
2
2
|
|
|
3
|
-
Official TypeScript SDK for the Praxium platform API.
|
|
3
|
+
Official TypeScript SDK for the [Praxium](https://praxium.nl) platform API. Build tenant websites that display practice data (team, services, FAQ, opening hours) with full locale support.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,37 +8,43 @@ Official TypeScript SDK for the Praxium platform API.
|
|
|
8
8
|
npm install @praxium/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
13
|
### Locale-Specific Mode
|
|
14
14
|
|
|
15
|
+
Pass a locale to get pre-resolved labels and values in that language:
|
|
16
|
+
|
|
15
17
|
```typescript
|
|
16
18
|
import { createPraxiumClient } from '@praxium/sdk'
|
|
17
19
|
|
|
18
20
|
const client = createPraxiumClient({
|
|
19
|
-
baseUrl: process.env.PRAXIUM_API_URL!,
|
|
20
|
-
apiKey: process.env.PRAXIUM_API_KEY!,
|
|
21
|
-
locale: 'nl',
|
|
21
|
+
baseUrl: process.env.PRAXIUM_API_URL!,
|
|
22
|
+
apiKey: process.env.PRAXIUM_API_KEY!,
|
|
23
|
+
locale: 'nl', // 'nl' | 'en' | '*' (see Multilingual Mode)
|
|
22
24
|
})
|
|
23
25
|
|
|
24
|
-
// Returns data directly — throws PraxiumError on failure
|
|
25
26
|
const hours = await client.getOpeningHours()
|
|
26
27
|
const team = await client.getTeamMembers()
|
|
28
|
+
const faq = await client.getFaq()
|
|
27
29
|
```
|
|
28
30
|
|
|
31
|
+
All methods return data directly or throw a typed `PraxiumError` on failure (see [Error Handling](#error-handling)).
|
|
32
|
+
|
|
29
33
|
### Multilingual Mode
|
|
30
34
|
|
|
35
|
+
Pass `locale: '*'` to receive all translations as objects. Resolve them at render time with `localizeText()`:
|
|
36
|
+
|
|
31
37
|
```typescript
|
|
32
38
|
import { createPraxiumClient, localizeText } from '@praxium/sdk'
|
|
33
39
|
|
|
34
40
|
const client = createPraxiumClient({
|
|
35
41
|
baseUrl: process.env.PRAXIUM_API_URL!,
|
|
36
42
|
apiKey: process.env.PRAXIUM_API_KEY!,
|
|
37
|
-
locale: '*',
|
|
43
|
+
locale: '*',
|
|
38
44
|
})
|
|
39
45
|
|
|
40
46
|
const team = await client.getTeamMembers()
|
|
41
|
-
// Returns MultilingualTeamMember[] — labels
|
|
47
|
+
// Returns MultilingualTeamMember[] — labels and values are multilingual objects:
|
|
42
48
|
// {
|
|
43
49
|
// name: "Dr. Jan de Vries",
|
|
44
50
|
// role: "Fysiotherapeut",
|
|
@@ -47,27 +53,74 @@ const team = await client.getTeamMembers()
|
|
|
47
53
|
// ]
|
|
48
54
|
// }
|
|
49
55
|
|
|
50
|
-
// Resolve multilingual text to a specific locale at render time
|
|
51
56
|
const label = localizeText(team[0].customFields[0].label, 'nl') // → "Specialisatie"
|
|
52
57
|
const value = localizeText(team[0].customFields[0].value, 'nl') // → "Sport"
|
|
53
58
|
```
|
|
54
59
|
|
|
55
60
|
### Contact Form
|
|
56
61
|
|
|
62
|
+
Submit a contact form on behalf of a website visitor:
|
|
63
|
+
|
|
57
64
|
```typescript
|
|
58
65
|
const result = await client.submitContactForm({
|
|
59
66
|
name: 'Jan de Vries',
|
|
60
67
|
email: 'jan@example.nl',
|
|
61
68
|
phone: '+31612345678',
|
|
62
|
-
subject: '
|
|
63
|
-
message: '
|
|
69
|
+
subject: 'Appointment request',
|
|
70
|
+
message: 'I would like to book an appointment.',
|
|
64
71
|
})
|
|
65
72
|
// → { success: true, emailStatus: 'sent' }
|
|
66
73
|
```
|
|
67
74
|
|
|
68
|
-
##
|
|
75
|
+
## Available Methods
|
|
76
|
+
|
|
77
|
+
| Method | Description |
|
|
78
|
+
|--------|-------------|
|
|
79
|
+
| `getOpeningHours()` | Weekly opening schedule |
|
|
80
|
+
| `getTeamMembers()` | Staff members with photos and custom fields |
|
|
81
|
+
| `getContactDetails()` | Practice contact information |
|
|
82
|
+
| `getLocation()` | Address and map coordinates |
|
|
83
|
+
| `getBusinessName()` | Practice display name |
|
|
84
|
+
| `getSocialLinks()` | Social media URLs |
|
|
85
|
+
| `getFaq()` | FAQ grouped by category |
|
|
86
|
+
| `getServiceVariants()` | Service pricing and variants |
|
|
87
|
+
| `getInsuranceInfo()` | Accepted insurance providers |
|
|
88
|
+
| `getFeatures()` | Practice features and amenities |
|
|
89
|
+
| `getPaymentMethods()` | Accepted payment methods |
|
|
90
|
+
| `getPolicyInfo()` | Practice policies |
|
|
91
|
+
| `getBookableServices()` | Services available for online booking |
|
|
92
|
+
| `submitContactForm(body)` | Submit a contact form |
|
|
93
|
+
|
|
94
|
+
## Error Handling
|
|
95
|
+
|
|
96
|
+
All methods throw typed errors that you can catch individually:
|
|
69
97
|
|
|
70
|
-
|
|
98
|
+
```typescript
|
|
99
|
+
import { PraxiumNotFoundError, PraxiumAuthError } from '@praxium/sdk'
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const team = await client.getTeamMembers()
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error instanceof PraxiumNotFoundError) {
|
|
105
|
+
// 404 — resource not found
|
|
106
|
+
} else if (error instanceof PraxiumAuthError) {
|
|
107
|
+
// 401 — invalid or expired API key
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
| Error Class | HTTP Status | When |
|
|
113
|
+
|-------------|-------------|------|
|
|
114
|
+
| `PraxiumAuthError` | 401 | Invalid API key |
|
|
115
|
+
| `PraxiumForbiddenError` | 403 | Key doesn't match tenant |
|
|
116
|
+
| `PraxiumNotFoundError` | 404 | Resource not found |
|
|
117
|
+
| `PraxiumValidationError` | 400 | Invalid request data |
|
|
118
|
+
| `PraxiumRateLimitError` | 429 | Too many requests |
|
|
119
|
+
| `PraxiumError` | Other | Base class for all errors |
|
|
120
|
+
|
|
121
|
+
## Next.js ISR Revalidation
|
|
122
|
+
|
|
123
|
+
For websites using Next.js [ISR (Incremental Static Regeneration)](https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration), the SDK provides a webhook handler for on-demand cache revalidation. When an admin updates data (team, FAQ, opening hours), the platform sends an HMAC-signed webhook to your revalidation endpoint. The handler verifies the signature and calls `revalidatePath()` for the affected pages.
|
|
71
124
|
|
|
72
125
|
```typescript
|
|
73
126
|
// app/api/revalidate/route.ts
|
|
@@ -86,7 +139,9 @@ export const POST = createRevalidationHandler({
|
|
|
86
139
|
})
|
|
87
140
|
```
|
|
88
141
|
|
|
89
|
-
|
|
142
|
+
**Prerequisites:** Register your revalidation endpoint URL in the admin portal (Settings → Webhooks) before the platform can send webhook events to your website.
|
|
143
|
+
|
|
144
|
+
The handler includes HMAC-SHA256 signature verification, timestamp-based replay protection (5-minute window), and timing-safe comparison. Requires `next` as a peer dependency.
|
|
90
145
|
|
|
91
146
|
## Development
|
|
92
147
|
|