@athoscommerce/snap-platforms 1.0.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/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/cjs/bigcommerce/src/addToCart.d.ts +7 -0
- package/dist/cjs/bigcommerce/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/addToCart.js +181 -0
- package/dist/cjs/bigcommerce/src/index.d.ts +4 -0
- package/dist/cjs/bigcommerce/src/index.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/index.js +9 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts +6 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceAddToCart.js +61 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts +10 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.js +103 -0
- package/dist/cjs/common/src/index.d.ts +5 -0
- package/dist/cjs/common/src/index.d.ts.map +1 -0
- package/dist/cjs/common/src/index.js +11 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.d.ts +8 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginAddToCart.js +66 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.d.ts +7 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginBackgroundFilters.js +123 -0
- package/dist/cjs/common/src/plugins/pluginLogger.d.ts +5 -0
- package/dist/cjs/common/src/plugins/pluginLogger.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginLogger.js +58 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.d.ts +13 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.d.ts.map +1 -0
- package/dist/cjs/common/src/plugins/pluginScrollToTop.js +75 -0
- package/dist/cjs/common/src/types.d.ts +27 -0
- package/dist/cjs/common/src/types.d.ts.map +1 -0
- package/dist/cjs/common/src/types.js +2 -0
- package/dist/cjs/magento2/src/addToCart.d.ts +9 -0
- package/dist/cjs/magento2/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/magento2/src/addToCart.js +156 -0
- package/dist/cjs/magento2/src/getFormKey.d.ts +2 -0
- package/dist/cjs/magento2/src/getFormKey.d.ts.map +1 -0
- package/dist/cjs/magento2/src/getFormKey.js +9 -0
- package/dist/cjs/magento2/src/getUenc.d.ts +2 -0
- package/dist/cjs/magento2/src/getUenc.d.ts.map +1 -0
- package/dist/cjs/magento2/src/getUenc.js +9 -0
- package/dist/cjs/magento2/src/index.d.ts +7 -0
- package/dist/cjs/magento2/src/index.d.ts.map +1 -0
- package/dist/cjs/magento2/src/index.js +15 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.d.ts +6 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2AddToCart.js +61 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts +10 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2BackgroundFilters.js +89 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.d.ts +9 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.d.ts.map +1 -0
- package/dist/cjs/magento2/src/plugins/pluginMagento2Base.js +123 -0
- package/dist/cjs/shopify/src/addToCart.d.ts +12 -0
- package/dist/cjs/shopify/src/addToCart.d.ts.map +1 -0
- package/dist/cjs/shopify/src/addToCart.js +117 -0
- package/dist/cjs/shopify/src/index.d.ts +5 -0
- package/dist/cjs/shopify/src/index.d.ts.map +1 -0
- package/dist/cjs/shopify/src/index.js +11 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.d.ts +6 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyAddToCart.js +61 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts +12 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyBackgroundFilters.js +107 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.d.ts +16 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.d.ts.map +1 -0
- package/dist/cjs/shopify/src/plugins/pluginShopifyMutateResults.js +80 -0
- package/dist/esm/bigcommerce/src/addToCart.d.ts +7 -0
- package/dist/esm/bigcommerce/src/addToCart.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/addToCart.js +103 -0
- package/dist/esm/bigcommerce/src/index.d.ts +4 -0
- package/dist/esm/bigcommerce/src/index.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/index.js +3 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts +6 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceAddToCart.js +11 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts +10 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.js +53 -0
- package/dist/esm/common/src/index.d.ts +5 -0
- package/dist/esm/common/src/index.d.ts.map +1 -0
- package/dist/esm/common/src/index.js +4 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.d.ts +8 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginAddToCart.js +15 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.d.ts +7 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginBackgroundFilters.js +63 -0
- package/dist/esm/common/src/plugins/pluginLogger.d.ts +5 -0
- package/dist/esm/common/src/plugins/pluginLogger.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginLogger.js +9 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.d.ts +13 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.d.ts.map +1 -0
- package/dist/esm/common/src/plugins/pluginScrollToTop.js +24 -0
- package/dist/esm/common/src/types.d.ts +27 -0
- package/dist/esm/common/src/types.d.ts.map +1 -0
- package/dist/esm/common/src/types.js +1 -0
- package/dist/esm/magento2/src/addToCart.d.ts +9 -0
- package/dist/esm/magento2/src/addToCart.d.ts.map +1 -0
- package/dist/esm/magento2/src/addToCart.js +80 -0
- package/dist/esm/magento2/src/getFormKey.d.ts +2 -0
- package/dist/esm/magento2/src/getFormKey.d.ts.map +1 -0
- package/dist/esm/magento2/src/getFormKey.js +5 -0
- package/dist/esm/magento2/src/getUenc.d.ts +2 -0
- package/dist/esm/magento2/src/getUenc.d.ts.map +1 -0
- package/dist/esm/magento2/src/getUenc.js +4 -0
- package/dist/esm/magento2/src/index.d.ts +7 -0
- package/dist/esm/magento2/src/index.d.ts.map +1 -0
- package/dist/esm/magento2/src/index.js +6 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.d.ts +6 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2AddToCart.js +11 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts +10 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2BackgroundFilters.js +39 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.d.ts +9 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.d.ts.map +1 -0
- package/dist/esm/magento2/src/plugins/pluginMagento2Base.js +64 -0
- package/dist/esm/shopify/src/addToCart.d.ts +12 -0
- package/dist/esm/shopify/src/addToCart.d.ts.map +1 -0
- package/dist/esm/shopify/src/addToCart.js +63 -0
- package/dist/esm/shopify/src/index.d.ts +5 -0
- package/dist/esm/shopify/src/index.d.ts.map +1 -0
- package/dist/esm/shopify/src/index.js +4 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.d.ts +6 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyAddToCart.js +11 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts +12 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyBackgroundFilters.js +56 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.d.ts +16 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.d.ts.map +1 -0
- package/dist/esm/shopify/src/plugins/pluginShopifyMutateResults.js +28 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Athos Commerce
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Snap Platforms
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Snap Platforms contains functionality that makes working with various shopping platforms easier. Several platforms have standardized APIs that can be leveraged for things like adding products to the cart. The most commonly used platforms are currently supported with a standard `addToCart` function. This function can be used within Snap projects. Each platform may also support other functionality, checkout the documentation for each platform to find out more.
|
|
5
|
+
|
|
6
|
+
[Common](https://github.com/athoscommerce/snap/tree/main/packages/snap-platforms/common)
|
|
7
|
+
|
|
8
|
+
[Shopify](https://athoscommerce.github.io/snap/reference-platforms-shopify)
|
|
9
|
+
|
|
10
|
+
[BigCommerce](https://athoscommerce.github.io/snap/reference-platforms-bigcommerce)
|
|
11
|
+
|
|
12
|
+
[Magento2](https://athoscommerce.github.io/snap/reference-platforms-magento2)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Product } from '@athoscommerce/snap-store-mobx';
|
|
2
|
+
export type BigCommerceAddToCartConfig = {
|
|
3
|
+
redirect?: boolean | string;
|
|
4
|
+
idFieldName?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const addToCart: (items: Product[], config?: BigCommerceAddToCartConfig) => Promise<any>;
|
|
7
|
+
//# sourceMappingURL=addToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addToCart.d.ts","sourceRoot":"","sources":["../../../../bigcommerce/src/addToCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,MAAM,MAAM,0BAA0B,GAAG;IACxC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF,eAAO,MAAM,SAAS,UAAiB,OAAO,EAAE,WAAW,0BAA0B,iBA+DpF,CAAC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.addToCart = void 0;
|
|
40
|
+
var addToCart = function (items, config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
41
|
+
var lineItems, addToCartResponse;
|
|
42
|
+
return __generator(this, function (_a) {
|
|
43
|
+
switch (_a.label) {
|
|
44
|
+
case 0:
|
|
45
|
+
if (!items) {
|
|
46
|
+
console.error('bigcommerce/addToCart: No products to add!');
|
|
47
|
+
return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
lineItems = [];
|
|
50
|
+
items.map(function (item) {
|
|
51
|
+
var _a, _b, _c, _d, _e;
|
|
52
|
+
var id = (_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.display) === null || _a === void 0 ? void 0 : _a.mappings) === null || _b === void 0 ? void 0 : _b.core) === null || _c === void 0 ? void 0 : _c.uid;
|
|
53
|
+
// try to find custom field in data
|
|
54
|
+
if (config === null || config === void 0 ? void 0 : config.idFieldName) {
|
|
55
|
+
var level_1 = item;
|
|
56
|
+
config.idFieldName.split('.').map(function (field) {
|
|
57
|
+
if (level_1 && level_1[field]) {
|
|
58
|
+
level_1 = level_1[field];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.error("bigcommerce/addToCart: Could not find column in item data. Please verify 'idFieldName' in the config.");
|
|
62
|
+
level_1 = undefined;
|
|
63
|
+
id = undefined;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (level_1 && level_1 !== item) {
|
|
68
|
+
id = level_1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (id && item.quantity) {
|
|
72
|
+
var productDetails_1 = {
|
|
73
|
+
product_id: id,
|
|
74
|
+
quantity: item.quantity,
|
|
75
|
+
};
|
|
76
|
+
var options_1 = (_e = (_d = item.variants) === null || _d === void 0 ? void 0 : _d.active) === null || _e === void 0 ? void 0 : _e.options;
|
|
77
|
+
if (options_1) {
|
|
78
|
+
productDetails_1.optionSelections = [];
|
|
79
|
+
Object.keys(options_1).forEach(function (option) {
|
|
80
|
+
var _a;
|
|
81
|
+
var optionId = options_1[option].optionId;
|
|
82
|
+
var optionValue = options_1[option].optionValue;
|
|
83
|
+
if (optionId && optionValue) {
|
|
84
|
+
(_a = productDetails_1.optionSelections) === null || _a === void 0 ? void 0 : _a.push({ optionId: optionId, optionValue: optionValue });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
lineItems.push(productDetails_1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (!lineItems.length) return [3 /*break*/, 2];
|
|
92
|
+
return [4 /*yield*/, addLineItemsToCart(lineItems)];
|
|
93
|
+
case 1:
|
|
94
|
+
addToCartResponse = _a.sent();
|
|
95
|
+
// do redirect (or not)
|
|
96
|
+
if ((config === null || config === void 0 ? void 0 : config.redirect) !== false) {
|
|
97
|
+
setTimeout(function () { return (window.location.href = typeof (config === null || config === void 0 ? void 0 : config.redirect) == 'string' ? config === null || config === void 0 ? void 0 : config.redirect : '/cart.php'); });
|
|
98
|
+
}
|
|
99
|
+
return [2 /*return*/, addToCartResponse];
|
|
100
|
+
case 2: return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); };
|
|
104
|
+
exports.addToCart = addToCart;
|
|
105
|
+
function addLineItemsToCart(lineItems) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var cartId, addToCartUrl, body, response, responseData, err_1;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
_a.trys.push([0, 4, , 5]);
|
|
112
|
+
return [4 /*yield*/, getExistingCartId()];
|
|
113
|
+
case 1:
|
|
114
|
+
cartId = _a.sent();
|
|
115
|
+
addToCartUrl = '/api/storefront/carts';
|
|
116
|
+
if (cartId) {
|
|
117
|
+
addToCartUrl = "/api/storefront/carts/".concat(cartId, "/items");
|
|
118
|
+
}
|
|
119
|
+
body = JSON.stringify({ lineItems: lineItems });
|
|
120
|
+
return [4 /*yield*/, fetch(addToCartUrl, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
headers: {
|
|
123
|
+
Accept: 'application/json',
|
|
124
|
+
'Content-Type': 'application/json',
|
|
125
|
+
},
|
|
126
|
+
body: body,
|
|
127
|
+
})];
|
|
128
|
+
case 2:
|
|
129
|
+
response = _a.sent();
|
|
130
|
+
if (response.status !== 200) {
|
|
131
|
+
throw new Error("API rejected addToCart: ".concat(response.status));
|
|
132
|
+
}
|
|
133
|
+
return [4 /*yield*/, response.json()];
|
|
134
|
+
case 3:
|
|
135
|
+
responseData = _a.sent();
|
|
136
|
+
if (responseData === null || responseData === void 0 ? void 0 : responseData.id) {
|
|
137
|
+
// cart Id should exist now.
|
|
138
|
+
return [2 /*return*/, responseData];
|
|
139
|
+
}
|
|
140
|
+
return [3 /*break*/, 5];
|
|
141
|
+
case 4:
|
|
142
|
+
err_1 = _a.sent();
|
|
143
|
+
console.error('bigcommerce/addToCart: Encountered an error!');
|
|
144
|
+
console.error(err_1);
|
|
145
|
+
return [3 /*break*/, 5];
|
|
146
|
+
case 5: return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function getExistingCartId() {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var response, responseData, err_2;
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
switch (_a.label) {
|
|
156
|
+
case 0:
|
|
157
|
+
_a.trys.push([0, 3, , 4]);
|
|
158
|
+
return [4 /*yield*/, fetch('/api/storefront/carts', {
|
|
159
|
+
method: 'GET',
|
|
160
|
+
headers: {
|
|
161
|
+
Accept: 'application/json',
|
|
162
|
+
'Content-Type': 'application/json',
|
|
163
|
+
},
|
|
164
|
+
})];
|
|
165
|
+
case 1:
|
|
166
|
+
response = _a.sent();
|
|
167
|
+
return [4 /*yield*/, response.json()];
|
|
168
|
+
case 2:
|
|
169
|
+
responseData = _a.sent();
|
|
170
|
+
if (Array.isArray(responseData) && responseData.length) {
|
|
171
|
+
return [2 /*return*/, responseData[0].id];
|
|
172
|
+
}
|
|
173
|
+
return [3 /*break*/, 4];
|
|
174
|
+
case 3:
|
|
175
|
+
err_2 = _a.sent();
|
|
176
|
+
return [3 /*break*/, 4];
|
|
177
|
+
case 4: return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { addToCart, BigCommerceAddToCartConfig as AddToCartConfig } from './addToCart';
|
|
2
|
+
export { pluginBigcommerceBackgroundFilters as pluginBackgroundFilters, PluginBigcommerceBackgroundFiltersConfig as PluginBackgroundFiltersConfig, } from './plugins/pluginBigcommerceBackgroundFilters';
|
|
3
|
+
export { pluginBigcommerceAddToCart as pluginAddToCart, PluginBigCommerceAddToCartConfig as PluginAddToCartConfig, } from './plugins/pluginBigcommerceAddToCart';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../bigcommerce/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,0BAA0B,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EACN,kCAAkC,IAAI,uBAAuB,EAC7D,wCAAwC,IAAI,6BAA6B,GACzE,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,0BAA0B,IAAI,eAAe,EAC7C,gCAAgC,IAAI,qBAAqB,GACzD,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginAddToCart = exports.pluginBackgroundFilters = exports.addToCart = void 0;
|
|
4
|
+
var addToCart_1 = require("./addToCart");
|
|
5
|
+
Object.defineProperty(exports, "addToCart", { enumerable: true, get: function () { return addToCart_1.addToCart; } });
|
|
6
|
+
var pluginBigcommerceBackgroundFilters_1 = require("./plugins/pluginBigcommerceBackgroundFilters");
|
|
7
|
+
Object.defineProperty(exports, "pluginBackgroundFilters", { enumerable: true, get: function () { return pluginBigcommerceBackgroundFilters_1.pluginBigcommerceBackgroundFilters; } });
|
|
8
|
+
var pluginBigcommerceAddToCart_1 = require("./plugins/pluginBigcommerceAddToCart");
|
|
9
|
+
Object.defineProperty(exports, "pluginAddToCart", { enumerable: true, get: function () { return pluginBigcommerceAddToCart_1.pluginBigcommerceAddToCart; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import { BigCommerceAddToCartConfig } from '../addToCart';
|
|
3
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
4
|
+
export type PluginBigCommerceAddToCartConfig = AbstractPluginConfig & BigCommerceAddToCartConfig;
|
|
5
|
+
export declare const pluginBigcommerceAddToCart: (cntrlr: AbstractController, config?: PluginBigCommerceAddToCartConfig) => void;
|
|
6
|
+
//# sourceMappingURL=pluginBigcommerceAddToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginBigcommerceAddToCart.d.ts","sourceRoot":"","sources":["../../../../../bigcommerce/src/plugins/pluginBigcommerceAddToCart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,MAAM,gCAAgC,GAAG,oBAAoB,GAAG,0BAA0B,CAAC;AAEjG,eAAO,MAAM,0BAA0B,WAAY,kBAAkB,WAAW,gCAAgC,SAU/G,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginBigcommerceAddToCart = void 0;
|
|
40
|
+
var addToCart_1 = require("../addToCart");
|
|
41
|
+
var pluginBigcommerceAddToCart = function (cntrlr, config) {
|
|
42
|
+
// do nothing if plugin is disabled
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
44
|
+
return;
|
|
45
|
+
var addToCartBigcommerceEvent = function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
46
|
+
var products = _b.products;
|
|
47
|
+
return __generator(this, function (_c) {
|
|
48
|
+
switch (_c.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, (0, addToCart_1.addToCart)(products, config)];
|
|
50
|
+
case 1:
|
|
51
|
+
_c.sent();
|
|
52
|
+
return [4 /*yield*/, next()];
|
|
53
|
+
case 2:
|
|
54
|
+
_c.sent();
|
|
55
|
+
return [2 /*return*/];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}); };
|
|
59
|
+
cntrlr.on('addToCart', addToCartBigcommerceEvent);
|
|
60
|
+
};
|
|
61
|
+
exports.pluginBigcommerceAddToCart = pluginBigcommerceAddToCart;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
3
|
+
export type PluginBigcommerceBackgroundFiltersConfig = AbstractPluginConfig & {
|
|
4
|
+
fieldNames?: {
|
|
5
|
+
brand?: string;
|
|
6
|
+
category?: string;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const pluginBigcommerceBackgroundFilters: (cntrlr: AbstractController, config?: PluginBigcommerceBackgroundFiltersConfig) => void;
|
|
10
|
+
//# sourceMappingURL=pluginBigcommerceBackgroundFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginBigcommerceBackgroundFilters.d.ts","sourceRoot":"","sources":["../../../../../bigcommerce/src/plugins/pluginBigcommerceBackgroundFilters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,KAAK,EAAE,oBAAoB,EAAgC,MAAM,2BAA2B,CAAC;AAEpG,MAAM,MAAM,wCAAwC,GAAG,oBAAoB,GAAG;IAC7E,UAAU,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACF,CAAC;AAEF,eAAO,MAAM,kCAAkC,WAAY,kBAAkB,WAAW,wCAAwC,SAwC/H,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginBigcommerceBackgroundFilters = void 0;
|
|
40
|
+
var pluginBigcommerceBackgroundFilters = function (cntrlr, config) {
|
|
41
|
+
var _a, _b, _c, _d, _e, _f;
|
|
42
|
+
// do nothing if plugin is disabled
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
44
|
+
return;
|
|
45
|
+
// only applies to search controllers
|
|
46
|
+
if (cntrlr.type != 'search')
|
|
47
|
+
return;
|
|
48
|
+
var backgroundFilters = [];
|
|
49
|
+
if ((_b = (_a = cntrlr.context) === null || _a === void 0 ? void 0 : _a.category) === null || _b === void 0 ? void 0 : _b.path) {
|
|
50
|
+
var categoryPath = replaceCharacters(cntrlr.context.category.path);
|
|
51
|
+
backgroundFilters.push({
|
|
52
|
+
type: 'value',
|
|
53
|
+
field: ((_c = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _c === void 0 ? void 0 : _c.category) || 'categories_hierarchy',
|
|
54
|
+
value: categoryPath,
|
|
55
|
+
background: true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if ((_e = (_d = cntrlr.context) === null || _d === void 0 ? void 0 : _d.brand) === null || _e === void 0 ? void 0 : _e.name) {
|
|
59
|
+
var brandName = replaceCharacters(cntrlr.context.brand.name);
|
|
60
|
+
backgroundFilters.push({
|
|
61
|
+
type: 'value',
|
|
62
|
+
field: ((_f = config === null || config === void 0 ? void 0 : config.fieldNames) === null || _f === void 0 ? void 0 : _f.brand) || 'brand',
|
|
63
|
+
value: brandName,
|
|
64
|
+
background: true,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// don't do anything if there are no background filters found
|
|
68
|
+
if (!backgroundFilters.length) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
cntrlr.on('init', function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
72
|
+
var controller = _b.controller;
|
|
73
|
+
return __generator(this, function (_c) {
|
|
74
|
+
switch (_c.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
controller.config = controller.config || {};
|
|
77
|
+
controller.config.globals = controller.config.globals || {};
|
|
78
|
+
controller.config.globals.filters = controller.config.globals.filters || [];
|
|
79
|
+
controller.config.globals.filters = controller.config.globals.filters.concat(backgroundFilters);
|
|
80
|
+
return [4 /*yield*/, next()];
|
|
81
|
+
case 1:
|
|
82
|
+
_c.sent();
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}); });
|
|
87
|
+
};
|
|
88
|
+
exports.pluginBigcommerceBackgroundFilters = pluginBigcommerceBackgroundFilters;
|
|
89
|
+
function replaceCharacters(value) {
|
|
90
|
+
if (value) {
|
|
91
|
+
return value
|
|
92
|
+
.replace(/\&\;/g, '&')
|
|
93
|
+
.replace(/\<\;/g, '<')
|
|
94
|
+
.replace(/\>\;/g, '>')
|
|
95
|
+
.replace(/\"\;/g, '"')
|
|
96
|
+
.replace(/\'\;/g, "'")
|
|
97
|
+
.replace(/\'\;/g, "'")
|
|
98
|
+
.trim();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { pluginBackgroundFilters, PluginBackgroundFiltersConfig } from './plugins/pluginBackgroundFilters';
|
|
2
|
+
export { pluginScrollToTop, PluginScrollToTopConfig } from './plugins/pluginScrollToTop';
|
|
3
|
+
export { pluginLogger, PluginLoggerConfig } from './plugins/pluginLogger';
|
|
4
|
+
export { pluginAddToCart, PluginAddToCartConfig } from './plugins/pluginAddToCart';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../common/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginAddToCart = exports.pluginLogger = exports.pluginScrollToTop = exports.pluginBackgroundFilters = void 0;
|
|
4
|
+
var pluginBackgroundFilters_1 = require("./plugins/pluginBackgroundFilters");
|
|
5
|
+
Object.defineProperty(exports, "pluginBackgroundFilters", { enumerable: true, get: function () { return pluginBackgroundFilters_1.pluginBackgroundFilters; } });
|
|
6
|
+
var pluginScrollToTop_1 = require("./plugins/pluginScrollToTop");
|
|
7
|
+
Object.defineProperty(exports, "pluginScrollToTop", { enumerable: true, get: function () { return pluginScrollToTop_1.pluginScrollToTop; } });
|
|
8
|
+
var pluginLogger_1 = require("./plugins/pluginLogger");
|
|
9
|
+
Object.defineProperty(exports, "pluginLogger", { enumerable: true, get: function () { return pluginLogger_1.pluginLogger; } });
|
|
10
|
+
var pluginAddToCart_1 = require("./plugins/pluginAddToCart");
|
|
11
|
+
Object.defineProperty(exports, "pluginAddToCart", { enumerable: true, get: function () { return pluginAddToCart_1.pluginAddToCart; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Product } from '@athoscommerce/snap-store-mobx';
|
|
2
|
+
import { AbstractController } from '@athoscommerce/snap-controller';
|
|
3
|
+
import type { AbstractPluginConfig } from '../../../common/src/types';
|
|
4
|
+
export type PluginAddToCartConfig = AbstractPluginConfig & {
|
|
5
|
+
function?: (products: Product[], controller?: AbstractController) => void | Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const pluginAddToCart: (cntrlr: AbstractController, config?: PluginAddToCartConfig) => void;
|
|
8
|
+
//# sourceMappingURL=pluginAddToCart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginAddToCart.d.ts","sourceRoot":"","sources":["../../../../../common/src/plugins/pluginAddToCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,GAAG;IAC1D,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,UAAU,CAAC,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,kBAAkB,WAAW,qBAAqB,SAczF,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.pluginAddToCart = void 0;
|
|
40
|
+
var pluginAddToCart = function (cntrlr, config) {
|
|
41
|
+
// do nothing if plugin is disabled
|
|
42
|
+
if ((config === null || config === void 0 ? void 0 : config.enabled) === false)
|
|
43
|
+
return;
|
|
44
|
+
var addToCartEvent = function (_a, next_1) { return __awaiter(void 0, [_a, next_1], void 0, function (_b, next) {
|
|
45
|
+
var controller = _b.controller, products = _b.products;
|
|
46
|
+
return __generator(this, function (_c) {
|
|
47
|
+
switch (_c.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
if (!(config === null || config === void 0 ? void 0 : config.function)) return [3 /*break*/, 2];
|
|
50
|
+
return [4 /*yield*/, ((config === null || config === void 0 ? void 0 : config.function) && config.function(products, controller))];
|
|
51
|
+
case 1:
|
|
52
|
+
_c.sent();
|
|
53
|
+
return [3 /*break*/, 3];
|
|
54
|
+
case 2:
|
|
55
|
+
cntrlr.log.error('common/addToCart: Error - No function provided in config!');
|
|
56
|
+
_c.label = 3;
|
|
57
|
+
case 3: return [4 /*yield*/, next()];
|
|
58
|
+
case 4:
|
|
59
|
+
_c.sent();
|
|
60
|
+
return [2 /*return*/];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}); };
|
|
64
|
+
cntrlr.on('addToCart', addToCartEvent);
|
|
65
|
+
};
|
|
66
|
+
exports.pluginAddToCart = pluginAddToCart;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AbstractController } from '@athoscommerce/snap-controller';
|
|
2
|
+
import type { AbstractPluginConfig, PluginBackgroundFilter, PluginControl } from '../types';
|
|
3
|
+
export type PluginBackgroundFiltersConfig = AbstractPluginConfig & {
|
|
4
|
+
filters?: (PluginBackgroundFilter & PluginControl)[];
|
|
5
|
+
};
|
|
6
|
+
export declare const pluginBackgroundFilters: (cntrlr: AbstractController, config?: PluginBackgroundFiltersConfig) => void;
|
|
7
|
+
//# sourceMappingURL=pluginBackgroundFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginBackgroundFilters.d.ts","sourceRoot":"","sources":["../../../../../common/src/plugins/pluginBackgroundFilters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAgC,aAAa,EAAE,MAAM,UAAU,CAAC;AAE1H,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,GAAG;IAClE,OAAO,CAAC,EAAE,CAAC,sBAAsB,GAAG,aAAa,CAAC,EAAE,CAAC;CACrD,CAAC;AAEF,eAAO,MAAM,uBAAuB,WAAY,kBAAkB,WAAW,6BAA6B,SA8DzG,CAAC"}
|