@diffsome/react 1.1.0 → 1.1.1

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/dist/index.d.mts CHANGED
@@ -11,7 +11,7 @@ interface DiffsomeContextValue {
11
11
  declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
12
12
  interface DiffsomeProviderProps {
13
13
  children: ReactNode;
14
- config: DiffsomeConfig;
14
+ config?: Partial<DiffsomeConfig>;
15
15
  }
16
16
  declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps): react_jsx_runtime.JSX.Element;
17
17
  declare function useDiffsome(): DiffsomeContextValue;
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ interface DiffsomeContextValue {
11
11
  declare const DiffsomeContext: react.Context<DiffsomeContextValue | null>;
12
12
  interface DiffsomeProviderProps {
13
13
  children: ReactNode;
14
- config: DiffsomeConfig;
14
+ config?: Partial<DiffsomeConfig>;
15
15
  }
16
16
  declare function DiffsomeProvider({ children, config }: DiffsomeProviderProps): react_jsx_runtime.JSX.Element;
17
17
  declare function useDiffsome(): DiffsomeContextValue;
package/dist/index.js CHANGED
@@ -87,15 +87,34 @@ var import_react = require("react");
87
87
  var import_sdk = require("@diffsome/sdk");
88
88
  var import_jsx_runtime = require("react/jsx-runtime");
89
89
  var DiffsomeContext = (0, import_react.createContext)(null);
90
- function DiffsomeProvider({ children, config }) {
90
+ var getEnvVar = (key) => {
91
+ if (typeof window !== "undefined" && window.__DIFFSOME_ENV__?.[key]) {
92
+ return window.__DIFFSOME_ENV__[key];
93
+ }
94
+ if (typeof process !== "undefined" && process?.env) {
95
+ return process.env[`NEXT_PUBLIC_${key}`] || process.env[`REACT_APP_${key}`] || process.env[key];
96
+ }
97
+ return void 0;
98
+ };
99
+ function DiffsomeProvider({ children, config = {} }) {
91
100
  const [isReady, setIsReady] = (0, import_react.useState)(false);
101
+ const tenantId = config.tenantId || getEnvVar("DIFFSOME_TENANT_ID");
102
+ const apiKey = config.apiKey || getEnvVar("DIFFSOME_API_KEY");
103
+ const baseUrl = config.baseUrl || getEnvVar("DIFFSOME_BASE_URL");
104
+ if (!tenantId) {
105
+ throw new Error(
106
+ "DiffsomeProvider: tenantId is required. Provide it via config prop or set NEXT_PUBLIC_DIFFSOME_TENANT_ID / VITE_DIFFSOME_TENANT_ID environment variable."
107
+ );
108
+ }
92
109
  const client = (0, import_react.useMemo)(() => {
93
110
  return new import_sdk.Diffsome({
94
- ...config,
111
+ tenantId,
112
+ apiKey,
113
+ baseUrl,
95
114
  persistToken: config.persistToken ?? true,
96
115
  storageType: config.storageType ?? "localStorage"
97
116
  });
98
- }, [config.tenantId, config.baseUrl, config.apiKey]);
117
+ }, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
99
118
  (0, import_react.useEffect)(() => {
100
119
  setIsReady(true);
101
120
  }, []);
package/dist/index.mjs CHANGED
@@ -3,15 +3,34 @@ import { createContext, useContext, useState, useEffect, useMemo } from "react";
3
3
  import { Diffsome } from "@diffsome/sdk";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  var DiffsomeContext = createContext(null);
6
- function DiffsomeProvider({ children, config }) {
6
+ var getEnvVar = (key) => {
7
+ if (typeof window !== "undefined" && window.__DIFFSOME_ENV__?.[key]) {
8
+ return window.__DIFFSOME_ENV__[key];
9
+ }
10
+ if (typeof process !== "undefined" && process?.env) {
11
+ return process.env[`NEXT_PUBLIC_${key}`] || process.env[`REACT_APP_${key}`] || process.env[key];
12
+ }
13
+ return void 0;
14
+ };
15
+ function DiffsomeProvider({ children, config = {} }) {
7
16
  const [isReady, setIsReady] = useState(false);
17
+ const tenantId = config.tenantId || getEnvVar("DIFFSOME_TENANT_ID");
18
+ const apiKey = config.apiKey || getEnvVar("DIFFSOME_API_KEY");
19
+ const baseUrl = config.baseUrl || getEnvVar("DIFFSOME_BASE_URL");
20
+ if (!tenantId) {
21
+ throw new Error(
22
+ "DiffsomeProvider: tenantId is required. Provide it via config prop or set NEXT_PUBLIC_DIFFSOME_TENANT_ID / VITE_DIFFSOME_TENANT_ID environment variable."
23
+ );
24
+ }
8
25
  const client = useMemo(() => {
9
26
  return new Diffsome({
10
- ...config,
27
+ tenantId,
28
+ apiKey,
29
+ baseUrl,
11
30
  persistToken: config.persistToken ?? true,
12
31
  storageType: config.storageType ?? "localStorage"
13
32
  });
14
- }, [config.tenantId, config.baseUrl, config.apiKey]);
33
+ }, [tenantId, baseUrl, apiKey, config.persistToken, config.storageType]);
15
34
  useEffect(() => {
16
35
  setIsReady(true);
17
36
  }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffsome/react",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "React hooks and providers for Diffsome SDK - Headless e-commerce & CMS",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -37,11 +37,12 @@
37
37
  "url": "https://github.com/diffsome/diffsome-react.git"
38
38
  },
39
39
  "peerDependencies": {
40
- "react": ">=18.0.0",
41
- "@diffsome/sdk": ">=3.2.0"
40
+ "@diffsome/sdk": ">=3.2.0",
41
+ "react": ">=18.0.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@diffsome/sdk": "^3.2.7",
45
+ "@types/node": "^25.0.10",
45
46
  "@types/react": "^18.2.0",
46
47
  "react": "^18.2.0",
47
48
  "tsup": "^8.0.0",