@praxium/sdk 0.3.42 → 0.3.48

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 CHANGED
@@ -11,13 +11,12 @@ npm install @praxium/sdk
11
11
  ## Usage
12
12
 
13
13
  ```typescript
14
- import { createTenantClient } from '@praxium/sdk'
14
+ import { createPraxiumClient } from '@praxium/sdk'
15
15
 
16
- const client = createTenantClient({
16
+ const client = createPraxiumClient({
17
17
  baseUrl: process.env.PRAXIUM_API_URL!, // 'https://platform.praxium.nl'
18
- apiKey: process.env.PRAXIUM_API_KEY!, // HMAC key: 'hmac_v1_mypractice_1234567890_abc...'
19
- tenantSlug: 'mypractice', // must match the slug in the API key
20
- locale: 'en', // 'en' (English) or 'nl' (Dutch)
18
+ apiKey: process.env.PRAXIUM_API_KEY!, // tenant slug extracted from key automatically
19
+ locale: 'nl', // 'nl' | 'en' | '*' (multilingual)
21
20
  })
22
21
 
23
22
  // Returns data directly — throws PraxiumError on failure
@@ -25,6 +24,32 @@ const hours = await client.getOpeningHours()
25
24
  const team = await client.getTeamMembers()
26
25
  ```
27
26
 
27
+ ### Multilingual Mode
28
+
29
+ ```typescript
30
+ import { createPraxiumClient, localizeText } from '@praxium/sdk'
31
+
32
+ const client = createPraxiumClient({
33
+ baseUrl: process.env.PRAXIUM_API_URL!,
34
+ apiKey: process.env.PRAXIUM_API_KEY!,
35
+ locale: '*', // returns all translations
36
+ })
37
+
38
+ const team = await client.getTeamMembers()
39
+ // Returns MultilingualTeamMember[] — labels/values are { nl: "...", en: "..." } objects:
40
+ // {
41
+ // name: "Dr. Jan de Vries",
42
+ // role: "Fysiotherapeut",
43
+ // customFields: [
44
+ // { label: { nl: "Specialisatie", en: "Specialization" }, value: { nl: "Sport", en: "Sports" } }
45
+ // ]
46
+ // }
47
+
48
+ // Resolve multilingual text to a specific locale at render time
49
+ const label = localizeText(team[0].customFields[0].label, 'nl') // → "Specialisatie"
50
+ const value = localizeText(team[0].customFields[0].value, 'nl') // → "Sport"
51
+ ```
52
+
28
53
  ## Next.js Revalidation
29
54
 
30
55
  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
- interface TenantClientConfig {
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_{slug}_{timestamp}_{signature}) */
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 TenantClientBase {
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 TenantClient extends TenantClientBase {
697
+ interface PraxiumClient extends PraxiumClientBase {
691
698
  getTeamMembers: () => Promise<TeamMembers>;
692
699
  }
693
700
  /** Client for multilingual responses (locale='*') */
694
- interface MultilingualTenantClient extends TenantClientBase {
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 createTenantClient(config: TenantClientConfig & {
705
+ declare function createPraxiumClient(config: PraxiumClientConfig & {
699
706
  locale: '*';
700
- }): MultilingualTenantClient;
707
+ }): MultilingualPraxiumClient;
701
708
  /** Locale-specific mode: returns PublicTeamMember[] with resolved labels/values */
702
- declare function createTenantClient(config: TenantClientConfig): TenantClient;
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 `TenantClient` throws one of these errors when the
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 MultilingualTeamMember, type MultilingualTenantClient, type MultilingualText, type OpeningHours, type PaymentMethod, type PaymentMethodList, type PolicyInfo, type PolicyList, PraxiumAuthError, PraxiumError, PraxiumForbiddenError, PraxiumNotFoundError, PraxiumRateLimitError, PraxiumValidationError, type PricingVariant, type PricingVariants, type PublicDaySchedule, type PublicTeamMember, type ServiceCategoryInfo, type SocialLinks, type SupportedLocale, type TeamMembers, type TenantClient, type TenantClientConfig, type ValidationDetail, createTenantClient, getCustomField, getCustomFieldValue, localizeText };
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 createTenantClient(config) {
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: config.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
- createTenantClient,
1022
+ createPraxiumClient,
1023
+ extractTenantSlugFromApiKey,
1009
1024
  getCustomField,
1010
1025
  getCustomFieldValue,
1011
1026
  localizeText
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxium/sdk",
3
- "version": "0.3.42",
3
+ "version": "0.3.48",
4
4
  "description": "Official TypeScript SDK for the Praxium platform API",
5
5
  "type": "module",
6
6
  "exports": {