fast-simon-sdk 1.6.140 → 1.6.142
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/lib/models/common.d.ts +1 -0
- package/lib/models/common.js.map +1 -1
- package/lib/models/events.d.ts +1 -0
- package/lib/models/fullTextSearch.d.ts +1 -1
- package/lib/models/smartCollections.d.ts +1 -1
- package/lib/sections/eventReporter/index.js +5 -1
- package/lib/sections/eventReporter/index.js.map +1 -1
- package/lib/sections/fullTextSearch/index.js +9 -8
- package/lib/sections/fullTextSearch/index.js.map +1 -1
- package/lib/sections/index.js +32 -24
- package/lib/sections/index.js.map +1 -1
- package/lib/sections/initialization/index.js +9 -8
- package/lib/sections/initialization/index.js.map +1 -1
- package/lib/sections/instantSearch/utils.js +6 -5
- package/lib/sections/instantSearch/utils.js.map +1 -1
- package/lib/sections/landingPage/index.js +5 -4
- package/lib/sections/landingPage/index.js.map +1 -1
- package/lib/sections/lookAlikeProductRecommendation/index.js +3 -2
- package/lib/sections/lookAlikeProductRecommendation/index.js.map +1 -1
- package/lib/sections/recommendations/index.js +9 -8
- package/lib/sections/recommendations/index.js.map +1 -1
- package/lib/sections/smartCollections/index.js +8 -7
- package/lib/sections/smartCollections/index.js.map +1 -1
- package/lib/services/autocomplete.d.ts +1 -1
- package/lib/services/autocomplete.js.map +1 -1
- package/lib/services/common.d.ts +2 -2
- package/lib/services/common.js.map +1 -1
- package/lib/services/landingPage.d.ts +1 -1
- package/lib/services/lookAlikeProductRecommendation.d.ts +1 -1
- package/lib/services/related.d.ts +3 -3
- package/lib/services/related.js.map +1 -1
- package/lib/utils/companyLocation.d.ts +3 -0
- package/lib/utils/companyLocation.js +93 -0
- package/lib/utils/companyLocation.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* The B2B buyer's company location, sent as `company_location_context`.
|
|
3
|
+
|
|
4
|
+
Serving resolves the shopper's B2B catalogs from this parameter alone: with no company
|
|
5
|
+
location it evaluates the buyer as an ordinary shopper in their market, and on a store that
|
|
6
|
+
restricts products to a B2B catalog the buyer's own catalog is hidden from them (ZD 114806).
|
|
7
|
+
|
|
8
|
+
The historic source is window.__FAST_CUSTOMER_DETAILS.customer_current_location, read here and
|
|
9
|
+
in 21 other files across the frontends and written by NOTHING we ship -- no SDK code, no theme
|
|
10
|
+
extension, no init option. So the parameter has never gone out on Shopify B2B unless a merchant
|
|
11
|
+
populated that global themselves, which nothing documents. `companyLocationProvider` is the
|
|
12
|
+
supported channel; the global stays as a fallback so a storefront already setting it keeps
|
|
13
|
+
working.
|
|
14
|
+
|
|
15
|
+
Mirrors __fast_options.cartTokenProvider in ./cartToken deliberately, including resolving on
|
|
16
|
+
every CALL rather than at init: a B2B buyer switches location mid-session (Shopify's location
|
|
17
|
+
picker, or masquerading between companies), and a value pinned at boot would keep serving the
|
|
18
|
+
previous location's catalog. This is the same reason BigCommerce B2B reads customer_group_id
|
|
19
|
+
from the live storefront context instead of the app JWT. */
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.hasCompanyLocationProvider = hasCompanyLocationProvider;
|
|
22
|
+
exports.readMerchantCompanyLocation = readMerchantCompanyLocation;
|
|
23
|
+
exports.getCompanyLocationContext = getCompanyLocationContext;
|
|
24
|
+
/* Each warning fires at most once per page load: the provider is read on every request, so
|
|
25
|
+
per-call warnings would spam DevTools when a merchant's callback is misconfigured. */
|
|
26
|
+
var warnedNotFunction = false;
|
|
27
|
+
var warnedThrew = false;
|
|
28
|
+
var warnedNonString = false;
|
|
29
|
+
function hasCompanyLocationProvider() {
|
|
30
|
+
var _a;
|
|
31
|
+
return typeof ((_a = window === null || window === void 0 ? void 0 : window.__fast_options) === null || _a === void 0 ? void 0 : _a.companyLocationProvider) === "function";
|
|
32
|
+
}
|
|
33
|
+
/* undefined means "no company location", which is also every non-B2B shopper. */
|
|
34
|
+
function readMerchantCompanyLocation() {
|
|
35
|
+
var _a;
|
|
36
|
+
var fn = (_a = window === null || window === void 0 ? void 0 : window.__fast_options) === null || _a === void 0 ? void 0 : _a.companyLocationProvider;
|
|
37
|
+
/* not configured -- silent fall-through (the default for every non-opted-in merchant) */
|
|
38
|
+
if (fn === undefined || fn === null)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof fn !== "function") {
|
|
41
|
+
if (!warnedNotFunction) {
|
|
42
|
+
warnedNotFunction = true;
|
|
43
|
+
console.warn("[FastSimon] __fast_options.companyLocationProvider is set but is not a function; ignoring.");
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
var value;
|
|
48
|
+
try {
|
|
49
|
+
value = fn();
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
if (!warnedThrew) {
|
|
53
|
+
warnedThrew = true;
|
|
54
|
+
console.warn("[FastSimon] __fast_options.companyLocationProvider threw:", err);
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
/* null/undefined is a legitimate "this shopper is not buying on behalf of a company" signal,
|
|
59
|
+
not a misconfiguration -- the same provider runs for B2C and B2B visitors alike. */
|
|
60
|
+
if (value === undefined || value === null)
|
|
61
|
+
return undefined;
|
|
62
|
+
/* Numbers are accepted: Shopify exposes the location as a GID string, but a merchant reading
|
|
63
|
+
the id off their own data layer can reasonably hand us the bare numeric id. */
|
|
64
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
65
|
+
if (!warnedNonString) {
|
|
66
|
+
warnedNonString = true;
|
|
67
|
+
console.warn("[FastSimon] __fast_options.companyLocationProvider returned a non-string value; ignoring. Got:", value);
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
var trimmed = String(value).trim();
|
|
72
|
+
if (!trimmed || trimmed === "null" || trimmed === "undefined")
|
|
73
|
+
return undefined;
|
|
74
|
+
return trimmed;
|
|
75
|
+
}
|
|
76
|
+
/* The one way to obtain `company_location_context`. `hasShopifyMarkets` gates it because the
|
|
77
|
+
parameter is meaningless without Markets, and every call site already had that guard inline. */
|
|
78
|
+
function getCompanyLocationContext(hasShopifyMarkets) {
|
|
79
|
+
var _a;
|
|
80
|
+
if (!hasShopifyMarkets)
|
|
81
|
+
return undefined;
|
|
82
|
+
/* A configured provider is AUTHORITATIVE, exactly as cartTokenProvider is: it returns undefined
|
|
83
|
+
for a shopper who is not buying on behalf of a company, and falling back to the global there
|
|
84
|
+
would send the previous or another shopper's location, which serves the wrong catalog. */
|
|
85
|
+
if (hasCompanyLocationProvider())
|
|
86
|
+
return readMerchantCompanyLocation();
|
|
87
|
+
var fromGlobal = (_a = window === null || window === void 0 ? void 0 : window.__FAST_CUSTOMER_DETAILS) === null || _a === void 0 ? void 0 : _a.customer_current_location;
|
|
88
|
+
if (fromGlobal === undefined || fromGlobal === null)
|
|
89
|
+
return undefined;
|
|
90
|
+
var trimmed = String(fromGlobal).trim();
|
|
91
|
+
return trimmed || undefined;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=companyLocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"companyLocation.js","sourceRoot":"","sources":["../../src/utils/companyLocation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;8DAiB8D;;AAQ9D,gEAEC;AAGD,kEA2CC;AAID,8DAaC;AAvED;wFACwF;AACxF,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,eAAe,GAAG,KAAK,CAAC;AAE5B,SAAgB,0BAA0B;;IACtC,OAAO,OAAO,CAAA,MAAC,MAAc,aAAd,MAAM,uBAAN,MAAM,CAAU,cAAc,0CAAE,uBAAuB,CAAA,KAAK,UAAU,CAAC;AAC1F,CAAC;AAED,iFAAiF;AACjF,SAAgB,2BAA2B;;IACvC,IAAM,EAAE,GAAG,MAAC,MAAc,aAAd,MAAM,uBAAN,MAAM,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