@misiki/gocommerce-connector 0.15.0 → 0.19.0
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/README.md +3 -2
- package/dist/{index-GdjWgh5b.d.cts → index-BsvUnF4H.d.cts} +111 -2
- package/dist/{index-GdjWgh5b.d.ts → index-BsvUnF4H.d.ts} +111 -2
- package/dist/index.cjs +110 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +109 -3
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +110 -2
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +109 -3
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/services/index.cjs
CHANGED
|
@@ -2854,6 +2854,71 @@ var ReviewService = class extends BaseService {
|
|
|
2854
2854
|
};
|
|
2855
2855
|
var reviewService = new ReviewService();
|
|
2856
2856
|
|
|
2857
|
+
// src/services/google-review-service.ts
|
|
2858
|
+
var PLUGIN = "google-reviews";
|
|
2859
|
+
var GoogleReviewService = class extends BaseService {
|
|
2860
|
+
facts = new StoreFacts(this._fetch);
|
|
2861
|
+
/**
|
|
2862
|
+
* Google's rating and its most relevant reviews, read live. Google's terms
|
|
2863
|
+
* forbid keeping them, so nothing here caches them either, and every call
|
|
2864
|
+
* is one the store pays Google for: call it when the section is in view.
|
|
2865
|
+
*/
|
|
2866
|
+
async place() {
|
|
2867
|
+
if (!await this.switchOn("show_place")) return null;
|
|
2868
|
+
const p = await this.orNull(() => this.data("/x/google-reviews/place"));
|
|
2869
|
+
if (!p?.user_rating_count) return null;
|
|
2870
|
+
return {
|
|
2871
|
+
rating: p.rating,
|
|
2872
|
+
count: p.user_rating_count,
|
|
2873
|
+
mapsUrl: p.google_maps_uri ?? "",
|
|
2874
|
+
reviews: (p.reviews ?? []).map((r) => ({
|
|
2875
|
+
author: r.author?.name ?? "",
|
|
2876
|
+
authorUrl: r.author?.uri ?? "",
|
|
2877
|
+
authorPhoto: r.author?.photo_uri ?? "",
|
|
2878
|
+
rating: r.rating,
|
|
2879
|
+
text: r.text ?? "",
|
|
2880
|
+
language: r.language ?? "",
|
|
2881
|
+
when: r.relative_time ?? "",
|
|
2882
|
+
visited: r.visit_date ?? "",
|
|
2883
|
+
url: r.google_maps_uri ?? "",
|
|
2884
|
+
reportUrl: r.flag_uri ?? ""
|
|
2885
|
+
}))
|
|
2886
|
+
};
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* What Google Customer Reviews' opt-in is rendered with, for an order placed
|
|
2890
|
+
* in this browser: its access token is kept here, and nowhere else can ask.
|
|
2891
|
+
* Every field is the order's own; the keys are Google's, to pass unchanged
|
|
2892
|
+
* to `gapi.surveyoptin.render`.
|
|
2893
|
+
*/
|
|
2894
|
+
async survey(orderNumber) {
|
|
2895
|
+
const kept = orderNumber ? placedOrder(orderNumber) : void 0;
|
|
2896
|
+
if (!kept || !await this.switchOn("customer_reviews")) return null;
|
|
2897
|
+
return this.orNull(
|
|
2898
|
+
() => this.data(`/x/google-reviews/survey/${encodeURIComponent(orderNumber)}`, {
|
|
2899
|
+
query: { token: kept.token }
|
|
2900
|
+
})
|
|
2901
|
+
);
|
|
2902
|
+
}
|
|
2903
|
+
async switchOn(setting) {
|
|
2904
|
+
try {
|
|
2905
|
+
return (await this.facts.plugins()).get(PLUGIN)?.settings?.[setting] === true;
|
|
2906
|
+
} catch {
|
|
2907
|
+
return false;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
/** Off, used up for the day, or refused by Google: nothing to show. Anything else still throws. */
|
|
2911
|
+
async orNull(call) {
|
|
2912
|
+
try {
|
|
2913
|
+
return await call();
|
|
2914
|
+
} catch (err) {
|
|
2915
|
+
if (err instanceof GoCommerceError && [404, 429, 502].includes(err.status)) return null;
|
|
2916
|
+
throw err;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
};
|
|
2920
|
+
var googleReviewService = new GoogleReviewService();
|
|
2921
|
+
|
|
2857
2922
|
// src/services/menu-service.ts
|
|
2858
2923
|
function linkFor(item) {
|
|
2859
2924
|
const t = item.target ?? "";
|
|
@@ -3033,6 +3098,21 @@ var StoreService = class extends BaseService {
|
|
|
3033
3098
|
...profile?.logo_url ? { logo: mediaUrl(profile.logo_url), logoDark: void 0 } : {},
|
|
3034
3099
|
...profile?.logo_dark_url ? { logoDark: mediaUrl(profile.logo_dark_url) } : {},
|
|
3035
3100
|
...profile?.icon_url ? { favicon: mediaUrl(profile.icon_url) } : {},
|
|
3101
|
+
// What the contact page shows (D156), only what the store published. The address
|
|
3102
|
+
// in the shape the storefront's contact page and home-page JSON-LD already read. The
|
|
3103
|
+
// country beside it, not over `country`: that is the address form's default country.
|
|
3104
|
+
...profile?.country ? { businessCountry: profile.country } : {},
|
|
3105
|
+
...profile?.address ? {
|
|
3106
|
+
address: {
|
|
3107
|
+
street: [profile.address.line1, profile.address.line2].filter(Boolean).join(", "),
|
|
3108
|
+
city: profile.address.city,
|
|
3109
|
+
state: profile.address.state,
|
|
3110
|
+
pincode: profile.address.postal_code,
|
|
3111
|
+
country: profile.address.country
|
|
3112
|
+
}
|
|
3113
|
+
} : {},
|
|
3114
|
+
...profile?.map_location ? { mapLocation: profile.map_location } : {},
|
|
3115
|
+
...profile?.opening_hours?.length ? { openingHours: profile.opening_hours } : {},
|
|
3036
3116
|
currencyCode: code,
|
|
3037
3117
|
currencySymbol: sameCurrency ? base.currencySymbol ?? symbolFor(code) : symbolFor(code),
|
|
3038
3118
|
currency: {
|
|
@@ -3046,10 +3126,28 @@ var StoreService = class extends BaseService {
|
|
|
3046
3126
|
// Features this connector serves from a module: on exactly when the
|
|
3047
3127
|
// module is installed and switched on, whatever the static record says.
|
|
3048
3128
|
isWishlist: { ...basePlugins.isWishlist, ...flag(plugins.has("wishlist")) },
|
|
3129
|
+
// The corner button and the contact page's WhatsApp card read the number from
|
|
3130
|
+
// here; the engine's plugin holds it, in international digits.
|
|
3131
|
+
whatsappChatButton: {
|
|
3132
|
+
...basePlugins.whatsappChatButton,
|
|
3133
|
+
...flag(plugins.has("whatsapp-chat")),
|
|
3134
|
+
...plugins.has("whatsapp-chat") ? {
|
|
3135
|
+
phone: String(plugins.get("whatsapp-chat")?.settings?.phone ?? ""),
|
|
3136
|
+
message: String(plugins.get("whatsapp-chat")?.settings?.message ?? "")
|
|
3137
|
+
} : {}
|
|
3138
|
+
},
|
|
3049
3139
|
isProductReviewsAndRatings: {
|
|
3050
3140
|
...basePlugins.isProductReviewsAndRatings,
|
|
3051
3141
|
...flag(plugins.has("product-reviews"))
|
|
3052
3142
|
},
|
|
3143
|
+
// Google Customer Reviews (ext/google-reviews): the confirmation page's survey offer,
|
|
3144
|
+
// whose fields the engine builds from the order, and Google's store widget, which
|
|
3145
|
+
// belongs to the same programme and so needs the survey on.
|
|
3146
|
+
googleReviewsOptIn: {
|
|
3147
|
+
...basePlugins.googleReviewsOptIn,
|
|
3148
|
+
...flag(googleSetting(plugins, "customer_reviews") === true)
|
|
3149
|
+
},
|
|
3150
|
+
googleStoreWidget: storeWidget(plugins),
|
|
3053
3151
|
// The footer's sign-up box posts to ext/newsletter, and the theme editor's footer
|
|
3054
3152
|
// switch (D131) can only show it while that is on.
|
|
3055
3153
|
newsletter: { ...basePlugins.newsletter, ...flag(plugins.has("newsletter")) },
|
|
@@ -3092,6 +3190,12 @@ function regionName(code) {
|
|
|
3092
3190
|
return code;
|
|
3093
3191
|
}
|
|
3094
3192
|
}
|
|
3193
|
+
var googleSetting = (plugins, key) => plugins.get("google-reviews")?.settings?.[key];
|
|
3194
|
+
function storeWidget(plugins) {
|
|
3195
|
+
const where = googleSetting(plugins, "store_widget");
|
|
3196
|
+
if (googleSetting(plugins, "customer_reviews") !== true || !where) return { active: false };
|
|
3197
|
+
return { active: true, position: where === "Bottom left" ? "LEFT_BOTTOM" : "RIGHT_BOTTOM" };
|
|
3198
|
+
}
|
|
3095
3199
|
var LOGIN_TYPES = { phone_otp: "PHONE", email_or_phone: "BOTH", email_password: "EMAIL" };
|
|
3096
3200
|
|
|
3097
3201
|
// src/services/page-service.ts
|
|
@@ -3272,7 +3376,8 @@ var ContactService = class extends BaseService {
|
|
|
3272
3376
|
email,
|
|
3273
3377
|
phone,
|
|
3274
3378
|
message,
|
|
3275
|
-
subject
|
|
3379
|
+
subject,
|
|
3380
|
+
website
|
|
3276
3381
|
}) {
|
|
3277
3382
|
return this.data("/x/contact/messages", {
|
|
3278
3383
|
method: "POST",
|
|
@@ -3281,7 +3386,8 @@ var ContactService = class extends BaseService {
|
|
|
3281
3386
|
email: String(email ?? ""),
|
|
3282
3387
|
...phone ? { phone: String(phone) } : {},
|
|
3283
3388
|
...subject ? { subject: String(subject) } : {},
|
|
3284
|
-
body: String(message ?? "")
|
|
3389
|
+
body: String(message ?? ""),
|
|
3390
|
+
...website ? { website: String(website) } : {}
|
|
3285
3391
|
}
|
|
3286
3392
|
});
|
|
3287
3393
|
}
|
|
@@ -3795,6 +3901,7 @@ exports.EnquiryService = EnquiryService;
|
|
|
3795
3901
|
exports.FaqService = FaqService;
|
|
3796
3902
|
exports.FeedbackService = FeedbackService;
|
|
3797
3903
|
exports.GalleryService = GalleryService;
|
|
3904
|
+
exports.GoogleReviewService = GoogleReviewService;
|
|
3798
3905
|
exports.HomeService = HomeService;
|
|
3799
3906
|
exports.InitService = InitService;
|
|
3800
3907
|
exports.LayoutService = LayoutService;
|
|
@@ -3849,6 +3956,7 @@ exports.enquiryService = enquiryService;
|
|
|
3849
3956
|
exports.faqService = faqService;
|
|
3850
3957
|
exports.feedbackService = feedbackService;
|
|
3851
3958
|
exports.galleryService = galleryService;
|
|
3959
|
+
exports.googleReviewService = googleReviewService;
|
|
3852
3960
|
exports.homeService = homeService;
|
|
3853
3961
|
exports.initService = initService;
|
|
3854
3962
|
exports.layoutService = layoutService;
|