@developer_tribe/react-builder 1.2.28 → 1.2.29

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.
@@ -25,3 +25,27 @@ export * from './extractAndroidParams';
25
25
  export * from './extractIOSParams';
26
26
  export * from './buildPaywallLocalizationParams';
27
27
  export * from './usePaywallLocalizationParams';
28
+ import type { Product } from './types';
29
+ /** Preset map: preset key → product array. */
30
+ export type MockProductPresets = Record<string, Product[]>;
31
+ /**
32
+ * Returns a deep-copy of all mock product presets.
33
+ *
34
+ * Use this instead of importing `mockProducts.json` directly so that:
35
+ * 1. Consumers don't couple to a JSON file path.
36
+ * 2. Each call returns a fresh copy (safe to mutate).
37
+ *
38
+ * @example
39
+ * import { getMockProducts } from '@developer_tribe/react-builder';
40
+ * const presets = getMockProducts(); // { 'preset-1': [...], ... }
41
+ */
42
+ export declare function getMockProducts(): MockProductPresets;
43
+ /**
44
+ * Returns the product list for a specific preset key (deep-copied).
45
+ * Returns an empty array if the key doesn't exist.
46
+ *
47
+ * @example
48
+ * import { getMockProductsByPreset } from '@developer_tribe/react-builder';
49
+ * const products = getMockProductsByPreset('preset-1');
50
+ */
51
+ export declare function getMockProductsByPreset(presetKey: string): Product[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@developer_tribe/react-builder",
3
- "version": "1.2.28",
3
+ "version": "1.2.29",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "restricted": true,
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "supportedProjectVersion": "1.1.2",
3
- "reactBuilderVersion": "1.2.27"
3
+ "reactBuilderVersion": "1.2.28"
4
4
  }
package/src/index.ts CHANGED
@@ -79,6 +79,8 @@ export {
79
79
  buildPaywallLocalizationParams,
80
80
  usePaywallLocalizationParams,
81
81
  } from './product-base';
82
+ export type { MockProductPresets } from './product-base';
83
+ export { getMockProducts, getMockProductsByPreset } from './product-base';
82
84
 
83
85
  // Context (RN-safe). In React Native, `products` should come from an IAP wrapper
84
86
  // (e.g. `react-native-iap`) and be passed into `BuilderProvider` by the host app.
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import Modal from './Modal';
3
3
  import type { Product } from '../paywall/types/paywall-types';
4
- import presetsJson from '../product-base/mockProducts.json';
4
+ import { getMockProducts } from '../product-base';
5
5
 
6
6
  type PresetMap = Record<string, Product[]>;
7
7
  const DEFAULT_PRESET_KEY = 'preset-1';
@@ -18,7 +18,7 @@ function ensureProductId(p: Product): Product {
18
18
  }
19
19
 
20
20
  function getPresetMap(): PresetMap {
21
- const raw = presetsJson as PresetMap;
21
+ const raw = getMockProducts();
22
22
  const safe: PresetMap = {};
23
23
  Object.entries(raw ?? {}).forEach(([key, list]) => {
24
24
  if (!key || typeof key !== 'string') return;
@@ -26,3 +26,39 @@ export * from './extractAndroidParams';
26
26
  export * from './extractIOSParams';
27
27
  export * from './buildPaywallLocalizationParams';
28
28
  export * from './usePaywallLocalizationParams';
29
+
30
+ /* ── Mock Products ── */
31
+
32
+ import presetsJson from './mockProducts.json';
33
+ import type { Product } from './types';
34
+
35
+ /** Preset map: preset key → product array. */
36
+ export type MockProductPresets = Record<string, Product[]>;
37
+
38
+ /**
39
+ * Returns a deep-copy of all mock product presets.
40
+ *
41
+ * Use this instead of importing `mockProducts.json` directly so that:
42
+ * 1. Consumers don't couple to a JSON file path.
43
+ * 2. Each call returns a fresh copy (safe to mutate).
44
+ *
45
+ * @example
46
+ * import { getMockProducts } from '@developer_tribe/react-builder';
47
+ * const presets = getMockProducts(); // { 'preset-1': [...], ... }
48
+ */
49
+ export function getMockProducts(): MockProductPresets {
50
+ return JSON.parse(JSON.stringify(presetsJson)) as MockProductPresets;
51
+ }
52
+
53
+ /**
54
+ * Returns the product list for a specific preset key (deep-copied).
55
+ * Returns an empty array if the key doesn't exist.
56
+ *
57
+ * @example
58
+ * import { getMockProductsByPreset } from '@developer_tribe/react-builder';
59
+ * const products = getMockProductsByPreset('preset-1');
60
+ */
61
+ export function getMockProductsByPreset(presetKey: string): Product[] {
62
+ const all = getMockProducts();
63
+ return all[presetKey] ?? [];
64
+ }
@@ -1,6 +1,6 @@
1
1
  export function replaceLocalizationParams(
2
2
  text: string,
3
- params?: Record<string, string | undefined> | null
3
+ params?: Record<string, string | undefined> | null,
4
4
  ): string {
5
5
  if (!text) return text;
6
6
  if (!params) return text;