@experiwall/react 0.3.0 → 0.3.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/server.d.mts CHANGED
@@ -38,6 +38,8 @@ interface ExperimentsResponse {
38
38
  *
39
39
  * Call this from server components to resolve variants at SSR time.
40
40
  * Pass a `userId` or `aliasId` to identify the visitor (e.g. from a cookie).
41
+ * If neither is provided, a random ID is generated automatically so the
42
+ * call always succeeds (useful on first visit before a cookie is set).
41
43
  */
42
44
  declare function fetchExperiments(config: ServerConfig): Promise<ExperimentsResponse>;
43
45
 
package/dist/server.d.ts CHANGED
@@ -38,6 +38,8 @@ interface ExperimentsResponse {
38
38
  *
39
39
  * Call this from server components to resolve variants at SSR time.
40
40
  * Pass a `userId` or `aliasId` to identify the visitor (e.g. from a cookie).
41
+ * If neither is provided, a random ID is generated automatically so the
42
+ * call always succeeds (useful on first visit before a cookie is set).
41
43
  */
42
44
  declare function fetchExperiments(config: ServerConfig): Promise<ExperimentsResponse>;
43
45
 
package/dist/server.js CHANGED
@@ -27,8 +27,9 @@ var DEFAULT_BASE_URL = "https://www.experiwall.com";
27
27
  async function fetchExperiments(config) {
28
28
  const base = config.baseUrl ?? DEFAULT_BASE_URL;
29
29
  const url = new URL("/api/sdk/init", base);
30
+ const aliasId = config.aliasId ?? (!config.userId ? crypto.randomUUID() : void 0);
30
31
  if (config.userId) url.searchParams.set("user_id", config.userId);
31
- if (config.aliasId) url.searchParams.set("alias_id", config.aliasId);
32
+ if (aliasId) url.searchParams.set("alias_id", aliasId);
32
33
  if (config.environment) url.searchParams.set("environment", config.environment);
33
34
  const res = await fetch(url.toString(), {
34
35
  headers: { "x-api-key": config.apiKey },
package/dist/server.mjs CHANGED
@@ -3,8 +3,9 @@ var DEFAULT_BASE_URL = "https://www.experiwall.com";
3
3
  async function fetchExperiments(config) {
4
4
  const base = config.baseUrl ?? DEFAULT_BASE_URL;
5
5
  const url = new URL("/api/sdk/init", base);
6
+ const aliasId = config.aliasId ?? (!config.userId ? crypto.randomUUID() : void 0);
6
7
  if (config.userId) url.searchParams.set("user_id", config.userId);
7
- if (config.aliasId) url.searchParams.set("alias_id", config.aliasId);
8
+ if (aliasId) url.searchParams.set("alias_id", aliasId);
8
9
  if (config.environment) url.searchParams.set("environment", config.environment);
9
10
  const res = await fetch(url.toString(), {
10
11
  headers: { "x-api-key": config.apiKey },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experiwall/react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Experiwall React SDK — code-first experimentation and A/B testing",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",