@fluid-app/portal-sdk 0.1.165 → 0.1.166

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.
Files changed (32) hide show
  1. package/dist/{FluidProvider-DbLFKavY.cjs → FluidProvider-DMFD--HI.cjs} +16 -270
  2. package/dist/FluidProvider-DMFD--HI.cjs.map +1 -0
  3. package/dist/{FluidProvider-BfATASw-.mjs → FluidProvider-qmTRBp3-.mjs} +17 -259
  4. package/dist/FluidProvider-qmTRBp3-.mjs.map +1 -0
  5. package/dist/{MessagingScreen-Dhg3eu32.mjs → MessagingScreen-B78wJC_8.mjs} +2 -2
  6. package/dist/{MessagingScreen-Dhg3eu32.mjs.map → MessagingScreen-B78wJC_8.mjs.map} +1 -1
  7. package/dist/{MessagingScreen-lFvwnAU6.cjs → MessagingScreen-BlCjptc6.cjs} +3 -3
  8. package/dist/{MessagingScreen-lFvwnAU6.cjs.map → MessagingScreen-BlCjptc6.cjs.map} +1 -1
  9. package/dist/{MessagingScreen-Dd0EBrre.cjs → MessagingScreen-DRD8xnXj.cjs} +2 -2
  10. package/dist/{ProductsScreen-nHmUftQn.mjs → ProductsScreen-C8amMeRh.mjs} +2 -0
  11. package/dist/{ProfileScreen-DUj4bkhx.cjs → ProfileScreen-CfHE4Ded.cjs} +2 -2
  12. package/dist/{ProfileScreen-DUj4bkhx.cjs.map → ProfileScreen-CfHE4Ded.cjs.map} +1 -1
  13. package/dist/{ProfileScreen-BuIxKbXC.mjs → ProfileScreen-Ct-m03oC.mjs} +2 -2
  14. package/dist/{ProfileScreen-BuIxKbXC.mjs.map → ProfileScreen-Ct-m03oC.mjs.map} +1 -1
  15. package/dist/{ProfileScreen-uAud2ErT.cjs → ProfileScreen-hD0bjuys.cjs} +2 -2
  16. package/dist/{ShareablesScreen-CdTyyDRO.mjs → ShareablesScreen-JxVPd89h.mjs} +2 -0
  17. package/dist/{ShopScreen-BUXUtEuj.cjs → ShopScreen-D9clGspu.cjs} +2 -2
  18. package/dist/{ShopScreen-BUXUtEuj.cjs.map → ShopScreen-D9clGspu.cjs.map} +1 -1
  19. package/dist/{ShopScreen-BH6zQndJ.mjs → ShopScreen-DW0puWGa.mjs} +2 -2
  20. package/dist/{ShopScreen-BH6zQndJ.mjs.map → ShopScreen-DW0puWGa.mjs.map} +1 -1
  21. package/dist/{ShopScreen-BbucUNI7.cjs → ShopScreen-Dvsz_wyc.cjs} +2 -2
  22. package/dist/index.cjs +10 -12
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +24 -161
  25. package/dist/index.d.cts.map +1 -1
  26. package/dist/index.d.mts +24 -161
  27. package/dist/index.d.mts.map +1 -1
  28. package/dist/index.mjs +15 -15
  29. package/dist/index.mjs.map +1 -1
  30. package/package.json +16 -16
  31. package/dist/FluidProvider-BfATASw-.mjs.map +0 -1
  32. package/dist/FluidProvider-DbLFKavY.cjs.map +0 -1
@@ -535,7 +535,7 @@ function useLanguagesApi() {
535
535
  /**
536
536
  * API Error class compatible with fluid-admin's ApiError
537
537
  */
538
- var ApiError$1 = class ApiError$1 extends Error {
538
+ var ApiError = class ApiError extends Error {
539
539
  status;
540
540
  data;
541
541
  constructor(message, status, data) {
@@ -543,7 +543,7 @@ var ApiError$1 = class ApiError$1 extends Error {
543
543
  this.name = "ApiError";
544
544
  this.status = status;
545
545
  this.data = data;
546
- if ("captureStackTrace" in Error) Error.captureStackTrace(this, ApiError$1);
546
+ if ("captureStackTrace" in Error) Error.captureStackTrace(this, ApiError);
547
547
  }
548
548
  toJSON() {
549
549
  return {
@@ -617,10 +617,10 @@ function createFetchClient(config) {
617
617
  try {
618
618
  data = JSON.parse(errorText);
619
619
  } catch {
620
- throw new ApiError$1(errorText.slice(0, 200) || `${method} request failed with status ${response.status}`, response.status, null);
620
+ throw new ApiError(errorText.slice(0, 200) || `${method} request failed with status ${response.status}`, response.status, null);
621
621
  }
622
- throw new ApiError$1(data.message || data.error_message || `${method} request failed`, response.status, data.errors || data);
623
- } else throw new ApiError$1(`${method} request failed with status ${response.status}`, response.status, null);
622
+ throw new ApiError(data.message || data.error_message || `${method} request failed`, response.status, data.errors || data);
623
+ } else throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null);
624
624
  }
625
625
  if (response.status === 204 || response.headers.get("content-length") === "0") return null;
626
626
  if (response.headers.get("content-type")?.includes("application/json")) try {
@@ -653,7 +653,7 @@ function createFetchClient(config) {
653
653
  if (signal) fetchOptions.signal = signal;
654
654
  response = await fetch(url, fetchOptions);
655
655
  } catch (networkError) {
656
- throw new ApiError$1(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
656
+ throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
657
657
  }
658
658
  return handleResponse(response, method, url);
659
659
  }
@@ -676,7 +676,7 @@ function createFetchClient(config) {
676
676
  if (signal) fetchOptions.signal = signal;
677
677
  response = await fetch(url, fetchOptions);
678
678
  } catch (networkError) {
679
- throw new ApiError$1(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
679
+ throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
680
680
  }
681
681
  return handleResponse(response, method, url);
682
682
  }
@@ -710,247 +710,6 @@ function createFetchClient(config) {
710
710
  };
711
711
  }
712
712
  //#endregion
713
- //#region src/client/types.ts
714
- /**
715
- * HTTP methods supported by the API client.
716
- * Use `as const` for literal type inference and type safety.
717
- */
718
- const HTTP_METHODS = {
719
- GET: "GET",
720
- POST: "POST",
721
- PUT: "PUT",
722
- PATCH: "PATCH",
723
- DELETE: "DELETE"
724
- };
725
- //#endregion
726
- //#region src/client/fluid-client.ts
727
- /**
728
- * Fluid API Client
729
- * Adapted from: packages/fluidos-api-client/src/lib/fetch-client.ts
730
- * Provides authenticated API access with domain-specific methods
731
- */
732
- /**
733
- * API Error class for structured error handling
734
- */
735
- var ApiError = class ApiError extends Error {
736
- status;
737
- data;
738
- constructor(message, status, data) {
739
- super(message);
740
- this.name = "ApiError";
741
- this.status = status;
742
- this.data = data;
743
- const errorWithCapture = Error;
744
- if (errorWithCapture.captureStackTrace) errorWithCapture.captureStackTrace(this, ApiError);
745
- }
746
- toJSON() {
747
- return {
748
- name: this.name,
749
- message: this.message,
750
- status: this.status,
751
- data: this.data
752
- };
753
- }
754
- };
755
- /**
756
- * Type guard for ApiError
757
- */
758
- function isApiError(error) {
759
- return error instanceof ApiError;
760
- }
761
- /**
762
- * Type guard to check if a value is a non-null string
763
- */
764
- function isString(value) {
765
- return typeof value === "string";
766
- }
767
- /**
768
- * Extract error message from API response data using `in` operator narrowing.
769
- * Checks common error message field names in order of precedence.
770
- */
771
- function extractErrorMessage(data, fallback) {
772
- if ("message" in data && isString(data.message)) return data.message;
773
- if ("error_message" in data && isString(data.error_message)) return data.error_message;
774
- if ("error" in data && isString(data.error)) return data.error;
775
- return fallback;
776
- }
777
- /**
778
- * Type guard to detect whether a parsed JSON value is an API envelope.
779
- * Envelopes always have numeric `status` and a `data` key.
780
- */
781
- function isApiEnvelope(value) {
782
- return typeof value === "object" && value !== null && "status" in value && typeof value.status === "number" && "data" in value;
783
- }
784
- /**
785
- * Creates a configured Fluid API client instance
786
- */
787
- function createFluidClient(config) {
788
- const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {} } = config;
789
- const fetchClient = createFetchClient({
790
- baseUrl,
791
- ...getAuthToken ? { getAuthToken } : {},
792
- onAuthError,
793
- defaultHeaders,
794
- credentials: "include"
795
- });
796
- /**
797
- * Build headers for a request.
798
- * Auth is handled by session cookies via `credentials: 'include'` on fetch calls.
799
- */
800
- function buildHeaders(customHeaders) {
801
- return {
802
- "Content-Type": "application/json",
803
- ...defaultHeaders,
804
- ...customHeaders
805
- };
806
- }
807
- /**
808
- * Build URL with query parameters (Rails-compatible)
809
- */
810
- function buildUrl(endpoint, params) {
811
- const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
812
- const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
813
- const url = normalizedBase ? new URL(normalizedBase + normalizedEndpoint) : new URL(normalizedEndpoint, typeof window !== "undefined" ? window.location.origin : "http://localhost");
814
- if (params) for (const [key, value] of Object.entries(params)) {
815
- if (value === void 0 || value === null) continue;
816
- if (Array.isArray(value)) for (const item of value) url.searchParams.append(`${key}[]`, String(item));
817
- else if (typeof value === "object") for (const [subKey, subValue] of Object.entries(value)) {
818
- if (subValue === void 0 || subValue === null) continue;
819
- if (Array.isArray(subValue)) for (const item of subValue) url.searchParams.append(`${key}[${subKey}][]`, String(item));
820
- else url.searchParams.append(`${key}[${subKey}]`, String(subValue));
821
- }
822
- else url.searchParams.append(key, String(value));
823
- }
824
- return url.toString();
825
- }
826
- /**
827
- * Default request options for type-safe defaults.
828
- * Uses `satisfies` to validate against RequestOptions while preserving literal types.
829
- */
830
- const defaultRequestOptions = { method: HTTP_METHODS.GET };
831
- /**
832
- * Main request function
833
- */
834
- async function request(endpoint, options = {}) {
835
- const { method = defaultRequestOptions.method, headers: customHeaders, params, body, signal } = options;
836
- const url = buildUrl(endpoint, method === HTTP_METHODS.GET ? params : void 0);
837
- const headers = buildHeaders(customHeaders);
838
- let response;
839
- try {
840
- const fetchOptions = {
841
- method,
842
- headers,
843
- credentials: "include"
844
- };
845
- if (signal !== void 0) fetchOptions.signal = signal;
846
- if (body && method !== HTTP_METHODS.GET) fetchOptions.body = JSON.stringify(body);
847
- response = await fetch(url, fetchOptions);
848
- } catch (networkError) {
849
- throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
850
- }
851
- if (response.status === 401) {
852
- onAuthError?.();
853
- throw new ApiError("Authentication required", 401, null);
854
- }
855
- if (!response.ok) try {
856
- if (response.headers.get("content-type")?.includes("application/json")) {
857
- const data = await response.json();
858
- throw new ApiError(extractErrorMessage(data, `${method} request failed`), response.status, "errors" in data ? data.errors : data);
859
- } else throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null);
860
- } catch (error) {
861
- if (isApiError(error)) throw error;
862
- throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null);
863
- }
864
- if (response.status === 204 || response.headers.get("content-length") === "0") return null;
865
- try {
866
- const raw = await response.json();
867
- if (raw === null || raw === void 0) throw new ApiError("Unexpected null/undefined in JSON response", response.status, null);
868
- return isApiEnvelope(raw) ? raw.data : raw;
869
- } catch (parseError) {
870
- if (isApiError(parseError)) throw parseError;
871
- throw new ApiError("Failed to parse response as JSON", response.status, null);
872
- }
873
- }
874
- /**
875
- * Request function for endpoints that may return null (204 No Content).
876
- * Properly types the return as T | null.
877
- */
878
- async function requestNullable(endpoint, options = {}) {
879
- return request(endpoint, options);
880
- }
881
- /**
882
- * Safe request wrapper that returns a discriminated union instead of throwing.
883
- * Use `isApiSuccess` or `isApiFailure` to narrow the result.
884
- */
885
- async function safeRequest(endpoint, options = {}) {
886
- try {
887
- return {
888
- success: true,
889
- data: await request(endpoint, options)
890
- };
891
- } catch (error) {
892
- if (isApiError(error)) return {
893
- success: false,
894
- error
895
- };
896
- return {
897
- success: false,
898
- error: new ApiError(error instanceof Error ? error.message : "Unknown error", 0, null)
899
- };
900
- }
901
- }
902
- /**
903
- * Helper to safely convert typed params to Record<string, unknown>.
904
- * Type assertion required: TypeScript's structural typing allows any object
905
- * to be treated as Record<string, unknown> when we only need to iterate
906
- * over its entries. This is safe because buildUrl only reads properties.
907
- */
908
- function toParams(params) {
909
- return params;
910
- }
911
- const get = (endpoint, params, options) => {
912
- const baseOptions = {
913
- ...options,
914
- method: HTTP_METHODS.GET
915
- };
916
- const convertedParams = toParams(params);
917
- return request(endpoint, convertedParams !== void 0 ? {
918
- ...baseOptions,
919
- params: convertedParams
920
- } : baseOptions);
921
- };
922
- const post = (endpoint, body, options) => request(endpoint, {
923
- ...options,
924
- method: HTTP_METHODS.POST,
925
- body
926
- });
927
- const put = (endpoint, body, options) => request(endpoint, {
928
- ...options,
929
- method: HTTP_METHODS.PUT,
930
- body
931
- });
932
- const patch = (endpoint, body, options) => request(endpoint, {
933
- ...options,
934
- method: HTTP_METHODS.PATCH,
935
- body
936
- });
937
- const del = (endpoint, options) => request(endpoint, {
938
- ...options,
939
- method: HTTP_METHODS.DELETE
940
- });
941
- return {
942
- fetchClient,
943
- request,
944
- requestNullable,
945
- safeRequest,
946
- get,
947
- post,
948
- put,
949
- patch,
950
- delete: del
951
- };
952
- }
953
- //#endregion
954
713
  //#region ../../api-clients/fluidos/src/namespaces/fluid_os.ts
955
714
  /**
956
715
  * Get active Fluid OS definition
@@ -2611,12 +2370,14 @@ function FluidProvider({ config, children, queryClient, initialTheme, themeConta
2611
2370
  }, []);
2612
2371
  const configRef = (0, react.useRef)(config);
2613
2372
  configRef.current = config;
2614
- const client = (0, react.useMemo)(() => createFluidClient({
2615
- ...configRef.current,
2616
- getAuthToken: () => configRef.current.getAuthToken?.() ?? null,
2617
- onAuthError: () => configRef.current.onAuthError?.()
2373
+ const fluidOsFetchClient = (0, react.useMemo)(() => createFetchClient({
2374
+ baseUrl: configRef.current.baseUrl,
2375
+ ...configRef.current.getAuthToken ? { getAuthToken: () => configRef.current.getAuthToken?.() ?? null } : {},
2376
+ onAuthError: () => configRef.current.onAuthError?.(),
2377
+ defaultHeaders: configRef.current.defaultHeaders,
2378
+ credentials: "include"
2618
2379
  }), [config.baseUrl]);
2619
- const fluidOsApi = (0, react.useMemo)(() => createFluidOsReadAdapter(client.fetchClient), [client.fetchClient]);
2380
+ const fluidOsApi = (0, react.useMemo)(() => createFluidOsReadAdapter(fluidOsFetchClient), [fluidOsFetchClient]);
2620
2381
  const csrfToken = typeof document !== "undefined" ? document.querySelector("meta[name=\"csrf-token\"]")?.getAttribute("content") : null;
2621
2382
  const portalTenantClient = (0, react.useMemo)(() => createFetchClient({
2622
2383
  baseUrl: configRef.current.baseUrl,
@@ -2630,10 +2391,7 @@ function FluidProvider({ config, children, queryClient, initialTheme, themeConta
2630
2391
  const countriesApi = (0, react.useMemo)(() => createCountriesApiAdapter(portalTenantClient), [portalTenantClient]);
2631
2392
  const languagesApi = (0, react.useMemo)(() => createLanguagesApiAdapter(portalTenantClient), [portalTenantClient]);
2632
2393
  const mysiteApi = (0, react.useMemo)(() => createMySiteApiAdapter(portalTenantClient), [portalTenantClient]);
2633
- const contextValue = (0, react.useMemo)(() => ({
2634
- client,
2635
- config: configRef.current
2636
- }), [client]);
2394
+ const contextValue = (0, react.useMemo)(() => ({ config }), [config.baseUrl]);
2637
2395
  const getApiHeaders = (0, react.useCallback)(() => {
2638
2396
  return { "Content-Type": "application/json" };
2639
2397
  }, []);
@@ -2720,12 +2478,6 @@ Object.defineProperty(exports, "ApiError", {
2720
2478
  return ApiError;
2721
2479
  }
2722
2480
  });
2723
- Object.defineProperty(exports, "ApiError$1", {
2724
- enumerable: true,
2725
- get: function() {
2726
- return ApiError$1;
2727
- }
2728
- });
2729
2481
  Object.defineProperty(exports, "DEFAULT_COLORS", {
2730
2482
  enumerable: true,
2731
2483
  get: function() {
@@ -2900,12 +2652,6 @@ Object.defineProperty(exports, "getForegroundColor", {
2900
2652
  return getForegroundColor;
2901
2653
  }
2902
2654
  });
2903
- Object.defineProperty(exports, "isApiError", {
2904
- enumerable: true,
2905
- get: function() {
2906
- return isApiError;
2907
- }
2908
- });
2909
2655
  Object.defineProperty(exports, "mergeDarkOverrides", {
2910
2656
  enumerable: true,
2911
2657
  get: function() {
@@ -2991,4 +2737,4 @@ Object.defineProperty(exports, "widgetPropertySchemas", {
2991
2737
  }
2992
2738
  });
2993
2739
 
2994
- //# sourceMappingURL=FluidProvider-DbLFKavY.cjs.map
2740
+ //# sourceMappingURL=FluidProvider-DMFD--HI.cjs.map