@coveo/shopify 1.1.1-pre.fe37143864 → 1.2.0-pre.7b4dd8aaef
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/headless.d.ts +7 -1
- package/dist/headless.esm.js +15 -7
- package/dist/headless.js +20 -5
- package/package.json +3 -3
package/dist/headless.d.ts
CHANGED
|
@@ -25,10 +25,11 @@ export interface AppProxyResponse {
|
|
|
25
25
|
* environment, and tracking ID.
|
|
26
26
|
*/
|
|
27
27
|
export declare function fetchAppProxyConfig({ appProxyUrl, marketId, }: AppProxyOptions): Promise<AppProxyResponse>;
|
|
28
|
+
type ShopifyCustomEnvironment = Omit<CustomEnvironment, 'storage' | 'generateUUID'>;
|
|
28
29
|
interface BuildShopifyCommerceEngineOptions {
|
|
29
30
|
commerceEngineOptions: CommerceEngineOptions;
|
|
30
31
|
shopifyCookie?: string;
|
|
31
|
-
environment?:
|
|
32
|
+
environment?: ShopifyCustomEnvironment;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Builds the commerce engine for a Shopify store.
|
|
@@ -39,6 +40,11 @@ interface BuildShopifyCommerceEngineOptions {
|
|
|
39
40
|
* - Storing a client identifier derived from the shop and cookie value in the browser environment's storage.
|
|
40
41
|
* - Building and returning the commerce engine with the provided options.
|
|
41
42
|
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* The `generateUUID` and `storage` properties are omitted from the custom environment for Shopify
|
|
45
|
+
* to ensure that client IDs are generated consistently across web pixels and storefronts. This is
|
|
46
|
+
* critical for maintaining a unified tracking and personalization experience.
|
|
47
|
+
*
|
|
42
48
|
* @param commerceEngineOptions - Options to configure the commerce engine.
|
|
43
49
|
* @param shopifyCookie - Optional value of the "_shopify_y" cookie. If not provided, it will attempt to retrieve it from the browser's cookies.
|
|
44
50
|
* @param environment - Optional browser environment; if not provided, a default one is created. Mainly useful when not running in a browser environment.
|
package/dist/headless.esm.js
CHANGED
|
@@ -20,10 +20,7 @@
|
|
|
20
20
|
import {
|
|
21
21
|
buildCommerceEngine
|
|
22
22
|
} from "@coveo/headless/commerce";
|
|
23
|
-
import {
|
|
24
|
-
buildBrowserEnvironment,
|
|
25
|
-
clientIdKey
|
|
26
|
-
} from "@coveo/relay";
|
|
23
|
+
import { buildBrowserEnvironment } from "@coveo/relay";
|
|
27
24
|
|
|
28
25
|
// src/utilities.ts
|
|
29
26
|
import { v5 } from "uuid";
|
|
@@ -47,15 +44,26 @@ function buildShopifyCommerceEngine({
|
|
|
47
44
|
shopifyCookie,
|
|
48
45
|
environment
|
|
49
46
|
}) {
|
|
50
|
-
const
|
|
47
|
+
const customEnvironment = environment ?? getShopifyCustomEnvironment(buildBrowserEnvironment());
|
|
51
48
|
const cookie = shopifyCookie || getShopifyCookie();
|
|
52
49
|
if (!cookie) {
|
|
53
50
|
throw new Error(
|
|
54
51
|
"Unable to find the _shopify_y cookie. Please ensure you are running this code in a Shopify store."
|
|
55
52
|
);
|
|
56
53
|
}
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const clientId = getClientId(cookie);
|
|
55
|
+
const engine = buildCommerceEngine(commerceEngineOptions);
|
|
56
|
+
engine.relay.updateConfig({
|
|
57
|
+
environment: {
|
|
58
|
+
...customEnvironment,
|
|
59
|
+
generateUUID: () => clientId
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return engine;
|
|
63
|
+
}
|
|
64
|
+
function getShopifyCustomEnvironment(environment) {
|
|
65
|
+
const { storage, generateUUID, ...rest } = environment;
|
|
66
|
+
return rest;
|
|
59
67
|
}
|
|
60
68
|
function getShopifyCookie(name = SHOPIFY_COOKIE_KEY) {
|
|
61
69
|
const match = document.cookie.match(
|
package/dist/headless.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildCommerceEngine, } from '@coveo/headless/commerce';
|
|
2
|
-
import { buildBrowserEnvironment
|
|
2
|
+
import { buildBrowserEnvironment } from '@coveo/relay';
|
|
3
3
|
import { getClientId } from './utilities';
|
|
4
4
|
export * from '@coveo/headless/commerce';
|
|
5
5
|
export * from './utilities';
|
|
@@ -28,6 +28,11 @@ export async function fetchAppProxyConfig({ appProxyUrl = '/apps/coveo', marketI
|
|
|
28
28
|
* - Storing a client identifier derived from the shop and cookie value in the browser environment's storage.
|
|
29
29
|
* - Building and returning the commerce engine with the provided options.
|
|
30
30
|
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* The `generateUUID` and `storage` properties are omitted from the custom environment for Shopify
|
|
33
|
+
* to ensure that client IDs are generated consistently across web pixels and storefronts. This is
|
|
34
|
+
* critical for maintaining a unified tracking and personalization experience.
|
|
35
|
+
*
|
|
31
36
|
* @param commerceEngineOptions - Options to configure the commerce engine.
|
|
32
37
|
* @param shopifyCookie - Optional value of the "_shopify_y" cookie. If not provided, it will attempt to retrieve it from the browser's cookies.
|
|
33
38
|
* @param environment - Optional browser environment; if not provided, a default one is created. Mainly useful when not running in a browser environment.
|
|
@@ -35,14 +40,24 @@ export async function fetchAppProxyConfig({ appProxyUrl = '/apps/coveo', marketI
|
|
|
35
40
|
* @throws Error if the required "_shopify_y" cookie is not found, ensuring the code runs within a Shopify store.
|
|
36
41
|
*/
|
|
37
42
|
export function buildShopifyCommerceEngine({ commerceEngineOptions, shopifyCookie, environment, }) {
|
|
38
|
-
const
|
|
43
|
+
const customEnvironment = environment ?? getShopifyCustomEnvironment(buildBrowserEnvironment());
|
|
39
44
|
const cookie = shopifyCookie || getShopifyCookie();
|
|
40
45
|
if (!cookie) {
|
|
41
46
|
throw new Error('Unable to find the _shopify_y cookie. Please ensure you are running this code in a Shopify store.');
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
const clientId = getClientId(cookie);
|
|
49
|
+
const engine = buildCommerceEngine(commerceEngineOptions);
|
|
50
|
+
engine.relay.updateConfig({
|
|
51
|
+
environment: {
|
|
52
|
+
...customEnvironment,
|
|
53
|
+
generateUUID: () => clientId,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return engine;
|
|
57
|
+
}
|
|
58
|
+
function getShopifyCustomEnvironment(environment) {
|
|
59
|
+
const { storage, generateUUID, ...rest } = environment;
|
|
60
|
+
return rest;
|
|
46
61
|
}
|
|
47
62
|
/**
|
|
48
63
|
* Retrieves the value of a specified Shopify cookie by its name.
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"main": "./dist/headless.esm.js",
|
|
9
9
|
"module": "./dist/headless.esm.js",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
|
-
"version": "1.
|
|
11
|
+
"version": "1.2.0-pre.7b4dd8aaef",
|
|
12
12
|
"files": [
|
|
13
13
|
"dist/"
|
|
14
14
|
],
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"vitest": "3.1.2"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@coveo/headless": "3.
|
|
50
|
-
"@coveo/relay": "1.
|
|
49
|
+
"@coveo/headless": "3.24.0-pre.7b4dd8aaef",
|
|
50
|
+
"@coveo/relay": "1.2.0",
|
|
51
51
|
"uuid": "^11.0.0"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|