@scalemule/nextjs 0.0.16 → 0.0.18

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.js CHANGED
@@ -2646,7 +2646,8 @@ function useAnalytics(options = {}) {
2646
2646
  if (typeof window !== "undefined") {
2647
2647
  fullEvent.page_url = window.location.href;
2648
2648
  fullEvent.page_title = document.title;
2649
- fullEvent.referrer = originalReferrerRef.current || document.referrer || void 0;
2649
+ fullEvent.referrer = originalReferrerRef.current || void 0;
2650
+ fullEvent.document_referrer = document.referrer || void 0;
2650
2651
  }
2651
2652
  return fullEvent;
2652
2653
  },
@@ -2719,7 +2720,7 @@ function useAnalytics(options = {}) {
2719
2720
  ...data?.properties || {},
2720
2721
  page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
2721
2722
  page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
2722
- referrer: data?.referrer || (typeof document !== "undefined" ? document.referrer : void 0)
2723
+ referrer: data?.referrer || originalReferrerRef.current || void 0
2723
2724
  }
2724
2725
  };
2725
2726
  return trackEvent(pageEvent);
@@ -2856,6 +2857,15 @@ function useFeatureFlags(options = {}) {
2856
2857
  enabled = true
2857
2858
  } = options;
2858
2859
  const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
2860
+ const warnedRef = react.useRef(false);
2861
+ react.useEffect(() => {
2862
+ if (!warnedRef.current && (!keys || keys.length === 0)) {
2863
+ warnedRef.current = true;
2864
+ console.warn(
2865
+ 'useFeatureFlags: "keys" option should be provided. Calling /evaluate/all without explicit keys is deprecated and will be blocked in a future release. Pass keys: ["flag1", "flag2"].'
2866
+ );
2867
+ }
2868
+ }, [keys]);
2859
2869
  const initialFlags = react.useMemo(() => {
2860
2870
  if (!bootstrapFlags) return {};
2861
2871
  const result = {};
@@ -2871,10 +2881,14 @@ function useFeatureFlags(options = {}) {
2871
2881
  const [loading, setLoading] = react.useState(enabled && !hasBootstrap);
2872
2882
  const [error, setError] = react.useState(null);
2873
2883
  const contextRef = react.useRef(context);
2884
+ const keysRef = react.useRef(keys);
2874
2885
  const keysKey = react.useMemo(() => keys && keys.length > 0 ? [...keys].sort().join("|") : "", [keys]);
2875
2886
  react.useEffect(() => {
2876
2887
  contextRef.current = context;
2877
2888
  }, [context]);
2889
+ react.useEffect(() => {
2890
+ keysRef.current = keys;
2891
+ }, [keys]);
2878
2892
  const refresh = react.useCallback(async () => {
2879
2893
  if (!enabled) {
2880
2894
  setLoading(false);
@@ -2882,8 +2896,9 @@ function useFeatureFlags(options = {}) {
2882
2896
  }
2883
2897
  setLoading(true);
2884
2898
  try {
2885
- const payload = keys && keys.length > 0 ? { flag_keys: keys, environment, context: contextRef.current } : { environment, context: contextRef.current };
2886
- const endpoint = keys && keys.length > 0 ? "/v1/flags/evaluate/batch" : "/v1/flags/evaluate/all";
2899
+ const currentKeys = keysRef.current;
2900
+ const payload = currentKeys && currentKeys.length > 0 ? { flag_keys: currentKeys, environment, context: contextRef.current } : { environment, context: contextRef.current };
2901
+ const endpoint = currentKeys && currentKeys.length > 0 ? "/v1/flags/evaluate/batch" : "/v1/flags/evaluate/all";
2887
2902
  let result;
2888
2903
  if (publishableKey && gatewayUrl) {
2889
2904
  const response = await fetch(`${gatewayUrl}${endpoint}`, {
@@ -2909,7 +2924,7 @@ function useFeatureFlags(options = {}) {
2909
2924
  } finally {
2910
2925
  setLoading(false);
2911
2926
  }
2912
- }, [client, enabled, environment, keys, keysKey, publishableKey, gatewayUrl]);
2927
+ }, [client, enabled, environment, keysKey, publishableKey, gatewayUrl]);
2913
2928
  const bootstrapCoversKeys = react.useMemo(() => {
2914
2929
  if (!hasBootstrap || !keys || keys.length === 0) return false;
2915
2930
  if (!keys.every((k) => k in initialFlags)) return false;
package/dist/index.mjs CHANGED
@@ -2644,7 +2644,8 @@ function useAnalytics(options = {}) {
2644
2644
  if (typeof window !== "undefined") {
2645
2645
  fullEvent.page_url = window.location.href;
2646
2646
  fullEvent.page_title = document.title;
2647
- fullEvent.referrer = originalReferrerRef.current || document.referrer || void 0;
2647
+ fullEvent.referrer = originalReferrerRef.current || void 0;
2648
+ fullEvent.document_referrer = document.referrer || void 0;
2648
2649
  }
2649
2650
  return fullEvent;
2650
2651
  },
@@ -2717,7 +2718,7 @@ function useAnalytics(options = {}) {
2717
2718
  ...data?.properties || {},
2718
2719
  page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
2719
2720
  page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
2720
- referrer: data?.referrer || (typeof document !== "undefined" ? document.referrer : void 0)
2721
+ referrer: data?.referrer || originalReferrerRef.current || void 0
2721
2722
  }
2722
2723
  };
2723
2724
  return trackEvent(pageEvent);
@@ -2854,6 +2855,15 @@ function useFeatureFlags(options = {}) {
2854
2855
  enabled = true
2855
2856
  } = options;
2856
2857
  const { client, publishableKey, gatewayUrl, bootstrapFlags } = smContext;
2858
+ const warnedRef = useRef(false);
2859
+ useEffect(() => {
2860
+ if (!warnedRef.current && (!keys || keys.length === 0)) {
2861
+ warnedRef.current = true;
2862
+ console.warn(
2863
+ 'useFeatureFlags: "keys" option should be provided. Calling /evaluate/all without explicit keys is deprecated and will be blocked in a future release. Pass keys: ["flag1", "flag2"].'
2864
+ );
2865
+ }
2866
+ }, [keys]);
2857
2867
  const initialFlags = useMemo(() => {
2858
2868
  if (!bootstrapFlags) return {};
2859
2869
  const result = {};
@@ -2869,10 +2879,14 @@ function useFeatureFlags(options = {}) {
2869
2879
  const [loading, setLoading] = useState(enabled && !hasBootstrap);
2870
2880
  const [error, setError] = useState(null);
2871
2881
  const contextRef = useRef(context);
2882
+ const keysRef = useRef(keys);
2872
2883
  const keysKey = useMemo(() => keys && keys.length > 0 ? [...keys].sort().join("|") : "", [keys]);
2873
2884
  useEffect(() => {
2874
2885
  contextRef.current = context;
2875
2886
  }, [context]);
2887
+ useEffect(() => {
2888
+ keysRef.current = keys;
2889
+ }, [keys]);
2876
2890
  const refresh = useCallback(async () => {
2877
2891
  if (!enabled) {
2878
2892
  setLoading(false);
@@ -2880,8 +2894,9 @@ function useFeatureFlags(options = {}) {
2880
2894
  }
2881
2895
  setLoading(true);
2882
2896
  try {
2883
- const payload = keys && keys.length > 0 ? { flag_keys: keys, environment, context: contextRef.current } : { environment, context: contextRef.current };
2884
- const endpoint = keys && keys.length > 0 ? "/v1/flags/evaluate/batch" : "/v1/flags/evaluate/all";
2897
+ const currentKeys = keysRef.current;
2898
+ const payload = currentKeys && currentKeys.length > 0 ? { flag_keys: currentKeys, environment, context: contextRef.current } : { environment, context: contextRef.current };
2899
+ const endpoint = currentKeys && currentKeys.length > 0 ? "/v1/flags/evaluate/batch" : "/v1/flags/evaluate/all";
2885
2900
  let result;
2886
2901
  if (publishableKey && gatewayUrl) {
2887
2902
  const response = await fetch(`${gatewayUrl}${endpoint}`, {
@@ -2907,7 +2922,7 @@ function useFeatureFlags(options = {}) {
2907
2922
  } finally {
2908
2923
  setLoading(false);
2909
2924
  }
2910
- }, [client, enabled, environment, keys, keysKey, publishableKey, gatewayUrl]);
2925
+ }, [client, enabled, environment, keysKey, publishableKey, gatewayUrl]);
2911
2926
  const bootstrapCoversKeys = useMemo(() => {
2912
2927
  if (!hasBootstrap || !keys || keys.length === 0) return false;
2913
2928
  if (!keys.every((k) => k in initialFlags)) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -48,11 +48,11 @@
48
48
  "test": "vitest run",
49
49
  "test:watch": "vitest",
50
50
  "type-check": "tsc --noEmit",
51
- "lint": "eslint src --ext .ts,.tsx",
51
+ "lint": "tsc --noEmit",
52
52
  "clean": "rm -rf dist"
53
53
  },
54
54
  "dependencies": {
55
- "@scalemule/sdk": "^0.0.15"
55
+ "@scalemule/sdk": "^0.0.16"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "next": ">=14.0.0",