@praxium/sdk 0.3.42 → 0.3.49
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 +32 -5
- package/dist/index.d.ts +19 -12
- package/dist/index.js +18 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,14 +10,15 @@ npm install @praxium/sdk
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
### Locale-Specific Mode
|
|
14
|
+
|
|
13
15
|
```typescript
|
|
14
|
-
import {
|
|
16
|
+
import { createPraxiumClient } from '@praxium/sdk'
|
|
15
17
|
|
|
16
|
-
const client =
|
|
18
|
+
const client = createPraxiumClient({
|
|
17
19
|
baseUrl: process.env.PRAXIUM_API_URL!, // 'https://platform.praxium.nl'
|
|
18
|
-
apiKey: process.env.PRAXIUM_API_KEY!, //
|
|
19
|
-
|
|
20
|
-
locale: 'en', // 'en' (English) or 'nl' (Dutch)
|
|
20
|
+
apiKey: process.env.PRAXIUM_API_KEY!, // tenant slug extracted from key automatically
|
|
21
|
+
locale: 'nl', // 'nl' | 'en' | '*' (multilingual)
|
|
21
22
|
})
|
|
22
23
|
|
|
23
24
|
// Returns data directly — throws PraxiumError on failure
|
|
@@ -25,6 +26,32 @@ const hours = await client.getOpeningHours()
|
|
|
25
26
|
const team = await client.getTeamMembers()
|
|
26
27
|
```
|
|
27
28
|
|
|
29
|
+
### Multilingual Mode
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { createPraxiumClient, localizeText } from '@praxium/sdk'
|
|
33
|
+
|
|
34
|
+
const client = createPraxiumClient({
|
|
35
|
+
baseUrl: process.env.PRAXIUM_API_URL!,
|
|
36
|
+
apiKey: process.env.PRAXIUM_API_KEY!,
|
|
37
|
+
locale: '*', // returns all translations
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const team = await client.getTeamMembers()
|
|
41
|
+
// Returns MultilingualTeamMember[] — labels/values are { nl: "...", en: "..." } objects:
|
|
42
|
+
// {
|
|
43
|
+
// name: "Dr. Jan de Vries",
|
|
44
|
+
// role: "Fysiotherapeut",
|
|
45
|
+
// customFields: [
|
|
46
|
+
// { label: { nl: "Specialisatie", en: "Specialization" }, value: { nl: "Sport", en: "Sports" } }
|
|
47
|
+
// ]
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
// Resolve multilingual text to a specific locale at render time
|
|
51
|
+
const label = localizeText(team[0].customFields[0].label, 'nl') // → "Specialisatie"
|
|
52
|
+
const value = localizeText(team[0].customFields[0].value, 'nl') // → "Sport"
|
|
53
|
+
```
|
|
54
|
+
|
|
28
55
|
## Next.js Revalidation
|
|
29
56
|
|
|
30
57
|
Optional utilities for ISR cache revalidation (requires `next` as peer dependency):
|
package/dist/index.d.ts
CHANGED
|
@@ -660,18 +660,25 @@ type SupportedLocale = 'nl' | 'en';
|
|
|
660
660
|
* - `'*'` — server returns all translations (multilingual mode)
|
|
661
661
|
*/
|
|
662
662
|
type ClientLocale = SupportedLocale | '*';
|
|
663
|
-
|
|
663
|
+
/**
|
|
664
|
+
* Extract the tenant slug from a profile-scoped API key.
|
|
665
|
+
*
|
|
666
|
+
* Key format: hmac_v1_{tenantSlug}_{profileSlug}_{timestamp}_{signature}
|
|
667
|
+
* Parts: [0]hmac [1]v1 [2]tenantSlug [3]profileSlug [4]timestamp [5]signature
|
|
668
|
+
*
|
|
669
|
+
* @throws Error if key format is invalid (wrong prefix or insufficient parts)
|
|
670
|
+
*/
|
|
671
|
+
declare function extractTenantSlugFromApiKey(apiKey: string): string;
|
|
672
|
+
interface PraxiumClientConfig {
|
|
664
673
|
/** Platform base URL (e.g., 'https://platform.praxium.nl') */
|
|
665
674
|
baseUrl: string;
|
|
666
|
-
/** HMAC-signed API key (format: hmac_v1_{
|
|
675
|
+
/** HMAC-signed API key (format: hmac_v1_{tenantSlug}_{profileSlug}_{timestamp}_{signature}) */
|
|
667
676
|
apiKey: string;
|
|
668
|
-
/** Tenant identifier slug (must match the slug in the API key) */
|
|
669
|
-
tenantSlug: string;
|
|
670
677
|
/** Locale for server-side content resolution */
|
|
671
678
|
locale: ClientLocale;
|
|
672
679
|
}
|
|
673
680
|
/** Shared methods available on both client types */
|
|
674
|
-
interface
|
|
681
|
+
interface PraxiumClientBase {
|
|
675
682
|
getOpeningHours: () => Promise<OpeningHours>;
|
|
676
683
|
getContactDetails: () => Promise<ContactDetails>;
|
|
677
684
|
getLocation: () => Promise<Location>;
|
|
@@ -687,24 +694,24 @@ interface TenantClientBase {
|
|
|
687
694
|
submitContactForm: (body: SubmitContactFormData['body']) => Promise<ContactFormResult>;
|
|
688
695
|
}
|
|
689
696
|
/** Client for locale-specific responses (locale='nl', 'en', etc.) */
|
|
690
|
-
interface
|
|
697
|
+
interface PraxiumClient extends PraxiumClientBase {
|
|
691
698
|
getTeamMembers: () => Promise<TeamMembers>;
|
|
692
699
|
}
|
|
693
700
|
/** Client for multilingual responses (locale='*') */
|
|
694
|
-
interface
|
|
701
|
+
interface MultilingualPraxiumClient extends PraxiumClientBase {
|
|
695
702
|
getTeamMembers: () => Promise<MultilingualTeamMember[]>;
|
|
696
703
|
}
|
|
697
704
|
/** Multilingual mode: returns MultilingualTeamMember[] (use localizeText() helper for resolution) */
|
|
698
|
-
declare function
|
|
705
|
+
declare function createPraxiumClient(config: PraxiumClientConfig & {
|
|
699
706
|
locale: '*';
|
|
700
|
-
}):
|
|
707
|
+
}): MultilingualPraxiumClient;
|
|
701
708
|
/** Locale-specific mode: returns PublicTeamMember[] with resolved labels/values */
|
|
702
|
-
declare function
|
|
709
|
+
declare function createPraxiumClient(config: PraxiumClientConfig): PraxiumClient;
|
|
703
710
|
|
|
704
711
|
/**
|
|
705
712
|
* Typed error hierarchy for the Praxium SDK.
|
|
706
713
|
*
|
|
707
|
-
* Every method on `
|
|
714
|
+
* Every method on `PraxiumClient` throws one of these errors when the
|
|
708
715
|
* API returns a non-2xx response. Consumers can catch a specific
|
|
709
716
|
* subclass (e.g. `PraxiumNotFoundError`) or the base `PraxiumError`.
|
|
710
717
|
*
|
|
@@ -831,4 +838,4 @@ declare function getCustomField(member: MultilingualTeamMember, identifier: stri
|
|
|
831
838
|
*/
|
|
832
839
|
declare function localizeText(text: MultilingualText | null | undefined, locale: SupportedLocale): string;
|
|
833
840
|
|
|
834
|
-
export { type ApiError, type BilingualText, type BookableService, type BookableServices, type BookableVariantInfo, type BusinessName, type ClientLocale, type ContactDetails, type ContactFormResult, type CustomField, type FaqCategory, type FaqContent, type FaqGroup, type FaqItem, type FeatureItem, type FeatureList, type InsuranceInfo, type InsuranceList, type Location, type MultilingualCustomField, type
|
|
841
|
+
export { type ApiError, type BilingualText, type BookableService, type BookableServices, type BookableVariantInfo, type BusinessName, type ClientLocale, type ContactDetails, type ContactFormResult, type CustomField, type FaqCategory, type FaqContent, type FaqGroup, type FaqItem, type FeatureItem, type FeatureList, type InsuranceInfo, type InsuranceList, type Location, type MultilingualCustomField, type MultilingualPraxiumClient, type MultilingualTeamMember, type MultilingualText, type OpeningHours, type PaymentMethod, type PaymentMethodList, type PolicyInfo, type PolicyList, PraxiumAuthError, type PraxiumClient, type PraxiumClientConfig, PraxiumError, PraxiumForbiddenError, PraxiumNotFoundError, PraxiumRateLimitError, PraxiumValidationError, type PricingVariant, type PricingVariants, type PublicDaySchedule, type PublicTeamMember, type ServiceCategoryInfo, type SocialLinks, type SupportedLocale, type TeamMembers, type ValidationDetail, createPraxiumClient, extractTenantSlugFromApiKey, getCustomField, getCustomFieldValue, localizeText };
|
package/dist/index.js
CHANGED
|
@@ -929,6 +929,19 @@ var STATUS_ERROR_MAP = {
|
|
|
929
929
|
};
|
|
930
930
|
|
|
931
931
|
// src/tenant-client.ts
|
|
932
|
+
var API_KEY_PREFIX = "hmac_v1";
|
|
933
|
+
var API_KEY_SEPARATOR = "_";
|
|
934
|
+
function extractTenantSlugFromApiKey(apiKey) {
|
|
935
|
+
const parts = apiKey.split(API_KEY_SEPARATOR);
|
|
936
|
+
if (parts.length < 6 || `${parts[0]}${API_KEY_SEPARATOR}${parts[1]}` !== API_KEY_PREFIX) {
|
|
937
|
+
throw new PraxiumError(
|
|
938
|
+
400,
|
|
939
|
+
"INVALID_API_KEY_FORMAT",
|
|
940
|
+
`API key must start with '${API_KEY_PREFIX}' and contain at least 6 segments. Format: hmac_v1_{tenantSlug}_{profileSlug}_{timestamp}_{signature}`
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
return parts[2];
|
|
944
|
+
}
|
|
932
945
|
function unwrapOrThrow(result) {
|
|
933
946
|
if (result.data !== void 0 && result.error === void 0) {
|
|
934
947
|
return result.data.data;
|
|
@@ -944,7 +957,8 @@ function unwrapOrThrow(result) {
|
|
|
944
957
|
}
|
|
945
958
|
throw new PraxiumError(status, errorCode, message, details);
|
|
946
959
|
}
|
|
947
|
-
function
|
|
960
|
+
function createPraxiumClient(config) {
|
|
961
|
+
const tenantSlug = extractTenantSlugFromApiKey(config.apiKey);
|
|
948
962
|
const clientInstance = createClient(
|
|
949
963
|
createConfig({
|
|
950
964
|
baseUrl: config.baseUrl,
|
|
@@ -955,7 +969,7 @@ function createTenantClient(config) {
|
|
|
955
969
|
request.headers.set("Accept-Language", config.locale);
|
|
956
970
|
return request;
|
|
957
971
|
});
|
|
958
|
-
const path = { tenantSlug
|
|
972
|
+
const path = { tenantSlug };
|
|
959
973
|
const baseMethods = {
|
|
960
974
|
// ─── Layout Endpoints ───
|
|
961
975
|
getOpeningHours: () => getOpeningHours({ client: clientInstance, path }).then(unwrapOrThrow),
|
|
@@ -1005,7 +1019,8 @@ export {
|
|
|
1005
1019
|
PraxiumNotFoundError,
|
|
1006
1020
|
PraxiumRateLimitError,
|
|
1007
1021
|
PraxiumValidationError,
|
|
1008
|
-
|
|
1022
|
+
createPraxiumClient,
|
|
1023
|
+
extractTenantSlugFromApiKey,
|
|
1009
1024
|
getCustomField,
|
|
1010
1025
|
getCustomFieldValue,
|
|
1011
1026
|
localizeText
|