@fast-simon/bigcommerce_customer 1.0.44 → 1.0.46-beta.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/lib/@types/bigcommerceCustomerTypes.d.ts +22 -22
- package/lib/@types/bigcommerceCustomerTypes.js +2 -2
- package/lib/main.d.ts +2 -2
- package/lib/main.js +5 -5
- package/lib/utils/API.d.ts +23 -23
- package/lib/utils/API.js +115 -116
- package/lib/utils/bigcommerceCustomer.d.ts +8 -8
- package/lib/utils/bigcommerceCustomer.js +121 -109
- package/package.json +32 -33
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
interface customer {
|
|
2
|
-
email: string;
|
|
3
|
-
group_id: string;
|
|
4
|
-
id: number;
|
|
5
|
-
}
|
|
6
|
-
export interface bigcommerceCustomerResponse {
|
|
7
|
-
application_id: string;
|
|
8
|
-
aud: string;
|
|
9
|
-
customer: customer;
|
|
10
|
-
exp: number;
|
|
11
|
-
iat: number;
|
|
12
|
-
iss: string;
|
|
13
|
-
operation: string;
|
|
14
|
-
store_hash: string;
|
|
15
|
-
sub: string;
|
|
16
|
-
version: number;
|
|
17
|
-
}
|
|
18
|
-
export
|
|
19
|
-
export interface bigcommerceCustomerAPIResponse {
|
|
20
|
-
token: string;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
1
|
+
interface customer {
|
|
2
|
+
email: string;
|
|
3
|
+
group_id: string;
|
|
4
|
+
id: number;
|
|
5
|
+
}
|
|
6
|
+
export interface bigcommerceCustomerResponse {
|
|
7
|
+
application_id: string;
|
|
8
|
+
aud: string;
|
|
9
|
+
customer: customer;
|
|
10
|
+
exp: number;
|
|
11
|
+
iat: number;
|
|
12
|
+
iss: string;
|
|
13
|
+
operation: string;
|
|
14
|
+
store_hash: string;
|
|
15
|
+
sub: string;
|
|
16
|
+
version: number;
|
|
17
|
+
}
|
|
18
|
+
export type BigcommerceCustomerGroup = string | undefined;
|
|
19
|
+
export interface bigcommerceCustomerAPIResponse {
|
|
20
|
+
token: string;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/main.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { bigcommerceCustomer } from "./utils/bigcommerceCustomer";
|
|
2
|
-
export { bigcommerceCustomer };
|
|
1
|
+
import { bigcommerceCustomer } from "./utils/bigcommerceCustomer";
|
|
2
|
+
export { bigcommerceCustomer };
|
package/lib/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bigcommerceCustomer = void 0;
|
|
4
|
-
var bigcommerceCustomer_1 = require("./utils/bigcommerceCustomer");
|
|
5
|
-
Object.defineProperty(exports, "bigcommerceCustomer", { enumerable: true, get: function () { return bigcommerceCustomer_1.bigcommerceCustomer; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bigcommerceCustomer = void 0;
|
|
4
|
+
var bigcommerceCustomer_1 = require("./utils/bigcommerceCustomer");
|
|
5
|
+
Object.defineProperty(exports, "bigcommerceCustomer", { enumerable: true, get: function () { return bigcommerceCustomer_1.bigcommerceCustomer; } });
|
package/lib/utils/API.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from "axios";
|
|
2
|
-
interface Params {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}
|
|
5
|
-
interface GetProps {
|
|
6
|
-
url: string;
|
|
7
|
-
params?: Params;
|
|
8
|
-
config?: AxiosRequestConfig;
|
|
9
|
-
fallbackURL?: string;
|
|
10
|
-
timeout?: number;
|
|
11
|
-
}
|
|
12
|
-
interface PostProps {
|
|
13
|
-
url: string;
|
|
14
|
-
data?: Params;
|
|
15
|
-
config?: AxiosRequestConfig;
|
|
16
|
-
}
|
|
17
|
-
export declare const API: {
|
|
18
|
-
get: <T>({ url, params, config }: GetProps) => Promise<T>;
|
|
19
|
-
post: <T_1>({ url, config, data }: PostProps) => Promise<any>;
|
|
20
|
-
getWithFallback: <T_2>({ url, params, config, fallbackURL, timeout }: GetProps) => Promise<any>;
|
|
21
|
-
};
|
|
22
|
-
export declare const parseUrl: (url: string) => string;
|
|
23
|
-
export {};
|
|
1
|
+
import { AxiosRequestConfig } from "axios";
|
|
2
|
+
interface Params {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
interface GetProps {
|
|
6
|
+
url: string;
|
|
7
|
+
params?: Params;
|
|
8
|
+
config?: AxiosRequestConfig;
|
|
9
|
+
fallbackURL?: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
interface PostProps {
|
|
13
|
+
url: string;
|
|
14
|
+
data?: Params;
|
|
15
|
+
config?: AxiosRequestConfig;
|
|
16
|
+
}
|
|
17
|
+
export declare const API: {
|
|
18
|
+
get: <T>({ url, params, config }: GetProps) => Promise<T>;
|
|
19
|
+
post: <T_1>({ url, config, data }: PostProps) => Promise<any>;
|
|
20
|
+
getWithFallback: <T_2>({ url, params, config, fallbackURL, timeout }: GetProps) => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
export declare const parseUrl: (url: string) => string;
|
|
23
|
+
export {};
|
package/lib/utils/API.js
CHANGED
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.parseUrl = exports.API = void 0;
|
|
51
|
-
var axios_1 = require("axios");
|
|
52
|
-
exports.API = {
|
|
53
|
-
get: function (_a) {
|
|
54
|
-
var url = _a.url, params = _a.params, config = _a.config;
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var response;
|
|
57
|
-
return __generator(this, function (_b) {
|
|
58
|
-
switch (_b.label) {
|
|
59
|
-
case 0: return [4 /*yield*/, axios_1.default.get(url, __assign({ params: params }, config))];
|
|
60
|
-
case 1:
|
|
61
|
-
response = _b.sent();
|
|
62
|
-
return [2 /*return*/, response.data];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
post: function (_a) {
|
|
68
|
-
var url = _a.url, config = _a.config, data = _a.data;
|
|
69
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
-
var response;
|
|
71
|
-
return __generator(this, function (_b) {
|
|
72
|
-
switch (_b.label) {
|
|
73
|
-
case 0: return [4 /*yield*/, axios_1.default.post(url, data, config)];
|
|
74
|
-
case 1:
|
|
75
|
-
response = _b.sent();
|
|
76
|
-
return [2 /*return*/, response.data];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
getWithFallback: function (_a) {
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
e_1
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
response
|
|
101
|
-
|
|
102
|
-
case
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
exports.parseUrl = parseUrl;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.parseUrl = exports.API = void 0;
|
|
51
|
+
var axios_1 = require("axios");
|
|
52
|
+
exports.API = {
|
|
53
|
+
get: function (_a) {
|
|
54
|
+
var url = _a.url, params = _a.params, config = _a.config;
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var response;
|
|
57
|
+
return __generator(this, function (_b) {
|
|
58
|
+
switch (_b.label) {
|
|
59
|
+
case 0: return [4 /*yield*/, axios_1.default.get(url, __assign({ params: params }, config))];
|
|
60
|
+
case 1:
|
|
61
|
+
response = _b.sent();
|
|
62
|
+
return [2 /*return*/, response.data];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
post: function (_a) {
|
|
68
|
+
var url = _a.url, config = _a.config, data = _a.data;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var response;
|
|
71
|
+
return __generator(this, function (_b) {
|
|
72
|
+
switch (_b.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, axios_1.default.post(url, data, config)];
|
|
74
|
+
case 1:
|
|
75
|
+
response = _b.sent();
|
|
76
|
+
return [2 /*return*/, response.data];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
getWithFallback: function (_a) {
|
|
82
|
+
var url = _a.url, params = _a.params, config = _a.config, fallbackURL = _a.fallbackURL, timeout = _a.timeout;
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var response, e_1, response;
|
|
85
|
+
return __generator(this, function (_b) {
|
|
86
|
+
switch (_b.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
_b.trys.push([0, 2, , 5]);
|
|
89
|
+
return [4 /*yield*/, axios_1.default.get(url, __assign(__assign({ params: params }, config), { timeout: timeout, timeoutErrorMessage: 'Request timeout, using fallback endpoint instead' }))];
|
|
90
|
+
case 1:
|
|
91
|
+
response = _b.sent();
|
|
92
|
+
return [2 /*return*/, response.data];
|
|
93
|
+
case 2:
|
|
94
|
+
e_1 = _b.sent();
|
|
95
|
+
console.error(e_1 === null || e_1 === void 0 ? void 0 : e_1.message);
|
|
96
|
+
if (!(fallbackURL != null)) return [3 /*break*/, 4];
|
|
97
|
+
return [4 /*yield*/, axios_1.default.get(fallbackURL, __assign({ params: params }, config))];
|
|
98
|
+
case 3:
|
|
99
|
+
response = _b.sent();
|
|
100
|
+
return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
|
|
101
|
+
case 4: return [2 /*return*/, null];
|
|
102
|
+
case 5: return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var parseUrl = function (url) {
|
|
109
|
+
var fixed = url.replace("https://", "").replace("http://", "");
|
|
110
|
+
if (fixed[fixed.length - 1] === "/") {
|
|
111
|
+
return fixed.slice(0, fixed.length - 1);
|
|
112
|
+
}
|
|
113
|
+
return fixed;
|
|
114
|
+
};
|
|
115
|
+
exports.parseUrl = parseUrl;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare const __ISP_BC_GROUP_KEY = "__ISP_BC_GROUP_KEY";
|
|
2
|
-
export declare const __ISP_BC_GROUP_KEY_USER = "customerGroup";
|
|
3
|
-
export declare const __ISP_BC_GROUP_KEY_SAVED_DATE = "__ISP_BC_GROUP_KEY_SAVED_DATE";
|
|
4
|
-
export declare class bigcommerceCustomer {
|
|
5
|
-
private static get;
|
|
6
|
-
static setBigcommerceCustomerGroupId(): Promise<string | undefined>;
|
|
7
|
-
static getBigcommerceCustomerGroupId(): string | undefined;
|
|
8
|
-
}
|
|
1
|
+
export declare const __ISP_BC_GROUP_KEY = "__ISP_BC_GROUP_KEY";
|
|
2
|
+
export declare const __ISP_BC_GROUP_KEY_USER = "customerGroup";
|
|
3
|
+
export declare const __ISP_BC_GROUP_KEY_SAVED_DATE = "__ISP_BC_GROUP_KEY_SAVED_DATE";
|
|
4
|
+
export declare class bigcommerceCustomer {
|
|
5
|
+
private static get;
|
|
6
|
+
static setBigcommerceCustomerGroupId(): Promise<string | undefined>;
|
|
7
|
+
static getBigcommerceCustomerGroupId(): string | undefined;
|
|
8
|
+
}
|
|
@@ -1,109 +1,121 @@
|
|
|
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;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "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 (_) 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.bigcommerceCustomer = exports.__ISP_BC_GROUP_KEY_SAVED_DATE = exports.__ISP_BC_GROUP_KEY_USER = exports.__ISP_BC_GROUP_KEY = void 0;
|
|
40
|
-
exports.__ISP_BC_GROUP_KEY = '__ISP_BC_GROUP_KEY';
|
|
41
|
-
exports.__ISP_BC_GROUP_KEY_USER = 'customerGroup';
|
|
42
|
-
exports.__ISP_BC_GROUP_KEY_SAVED_DATE = '__ISP_BC_GROUP_KEY_SAVED_DATE';
|
|
43
|
-
var API_1 = require("./API");
|
|
44
|
-
var appClientId = "igimdk6jnrt5g5mbwui5gi7f7ke1w5p";
|
|
45
|
-
var bigcommerceCustomer = /** @class */ (function () {
|
|
46
|
-
function bigcommerceCustomer() {
|
|
47
|
-
}
|
|
48
|
-
bigcommerceCustomer.get = function () {
|
|
49
|
-
return API_1.API.get({
|
|
50
|
-
url: "/customer/current.jwt?app_client_id=".concat(appClientId),
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
bigcommerceCustomer.setBigcommerceCustomerGroupId = function () {
|
|
54
|
-
var _a;
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var groupIdFromStorage, res, currentCustomer, groupId, e_1;
|
|
57
|
-
return __generator(this, function (_b) {
|
|
58
|
-
switch (_b.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
groupIdFromStorage = (_a = localStorage.getItem(exports.__ISP_BC_GROUP_KEY)) !== null && _a !== void 0 ? _a : localStorage.getItem(exports.__ISP_BC_GROUP_KEY_USER);
|
|
61
|
-
if (!groupIdFromStorage) return [3 /*break*/, 1];
|
|
62
|
-
return [2 /*return*/, groupIdFromStorage];
|
|
63
|
-
case 1:
|
|
64
|
-
_b.trys.push([1, 3, , 4]);
|
|
65
|
-
return [4 /*yield*/, bigcommerceCustomer.get()];
|
|
66
|
-
case 2:
|
|
67
|
-
res = (_b.sent());
|
|
68
|
-
if (!(res === null || res === void 0 ? void 0 : res.token))
|
|
69
|
-
return [2 /*return*/];
|
|
70
|
-
currentCustomer = isp_parseJwt(res.token);
|
|
71
|
-
if (currentCustomer && currentCustomer.customer && currentCustomer.customer.group_id) {
|
|
72
|
-
groupId = currentCustomer.customer.group_id;
|
|
73
|
-
if (!groupId)
|
|
74
|
-
return [2 /*return*/];
|
|
75
|
-
localStorage.setItem(exports.__ISP_BC_GROUP_KEY, groupId);
|
|
76
|
-
localStorage.setItem(exports.__ISP_BC_GROUP_KEY_SAVED_DATE, Date.now().toString());
|
|
77
|
-
return [2 /*return*/, groupId];
|
|
78
|
-
}
|
|
79
|
-
return [3 /*break*/, 4];
|
|
80
|
-
case 3:
|
|
81
|
-
e_1 = _b.sent();
|
|
82
|
-
return [3 /*break*/, 4];
|
|
83
|
-
case 4: return [2 /*return*/];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
bigcommerceCustomer.getBigcommerceCustomerGroupId = function () {
|
|
89
|
-
var _a;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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.bigcommerceCustomer = exports.__ISP_BC_GROUP_KEY_SAVED_DATE = exports.__ISP_BC_GROUP_KEY_USER = exports.__ISP_BC_GROUP_KEY = void 0;
|
|
40
|
+
exports.__ISP_BC_GROUP_KEY = '__ISP_BC_GROUP_KEY';
|
|
41
|
+
exports.__ISP_BC_GROUP_KEY_USER = 'customerGroup';
|
|
42
|
+
exports.__ISP_BC_GROUP_KEY_SAVED_DATE = '__ISP_BC_GROUP_KEY_SAVED_DATE';
|
|
43
|
+
var API_1 = require("./API");
|
|
44
|
+
var appClientId = "igimdk6jnrt5g5mbwui5gi7f7ke1w5p";
|
|
45
|
+
var bigcommerceCustomer = /** @class */ (function () {
|
|
46
|
+
function bigcommerceCustomer() {
|
|
47
|
+
}
|
|
48
|
+
bigcommerceCustomer.get = function () {
|
|
49
|
+
return API_1.API.get({
|
|
50
|
+
url: "/customer/current.jwt?app_client_id=".concat(appClientId),
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
bigcommerceCustomer.setBigcommerceCustomerGroupId = function () {
|
|
54
|
+
var _a;
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var groupIdFromStorage, res, currentCustomer, groupId, e_1;
|
|
57
|
+
return __generator(this, function (_b) {
|
|
58
|
+
switch (_b.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
groupIdFromStorage = (_a = localStorage.getItem(exports.__ISP_BC_GROUP_KEY)) !== null && _a !== void 0 ? _a : localStorage.getItem(exports.__ISP_BC_GROUP_KEY_USER);
|
|
61
|
+
if (!groupIdFromStorage) return [3 /*break*/, 1];
|
|
62
|
+
return [2 /*return*/, groupIdFromStorage];
|
|
63
|
+
case 1:
|
|
64
|
+
_b.trys.push([1, 3, , 4]);
|
|
65
|
+
return [4 /*yield*/, bigcommerceCustomer.get()];
|
|
66
|
+
case 2:
|
|
67
|
+
res = (_b.sent());
|
|
68
|
+
if (!(res === null || res === void 0 ? void 0 : res.token))
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
currentCustomer = isp_parseJwt(res.token);
|
|
71
|
+
if (currentCustomer && currentCustomer.customer && currentCustomer.customer.group_id) {
|
|
72
|
+
groupId = currentCustomer.customer.group_id;
|
|
73
|
+
if (!groupId)
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
localStorage.setItem(exports.__ISP_BC_GROUP_KEY, groupId);
|
|
76
|
+
localStorage.setItem(exports.__ISP_BC_GROUP_KEY_SAVED_DATE, Date.now().toString());
|
|
77
|
+
return [2 /*return*/, groupId];
|
|
78
|
+
}
|
|
79
|
+
return [3 /*break*/, 4];
|
|
80
|
+
case 3:
|
|
81
|
+
e_1 = _b.sent();
|
|
82
|
+
return [3 /*break*/, 4];
|
|
83
|
+
case 4: return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
bigcommerceCustomer.getBigcommerceCustomerGroupId = function () {
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
// BigCommerce B2B: when enabled, read the live customer_group_id from the
|
|
91
|
+
// storefront Stencil context. It updates dynamically on masquerade, unlike
|
|
92
|
+
// the JWT-derived value cached in localStorage below (never refreshed on
|
|
93
|
+
// company switch). 0 is intentionally allowed (not filtered like the JWT
|
|
94
|
+
// path) — it means "not masquerading" and must be sent so the previous
|
|
95
|
+
// (stale) group isn't reused via the localStorage fallback.
|
|
96
|
+
if ((_a = window === null || window === void 0 ? void 0 : window.__fast_options) === null || _a === void 0 ? void 0 : _a.use_bigcommerce_jscontext_customer_group_id) {
|
|
97
|
+
var groupId = (_c = (_b = window === null || window === void 0 ? void 0 : window.jsContext) === null || _b === void 0 ? void 0 : _b.customer) === null || _c === void 0 ? void 0 : _c.customer_group_id;
|
|
98
|
+
if (groupId !== undefined && groupId !== null) {
|
|
99
|
+
return String(groupId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
var groupIdFromStorage = (_d = localStorage.getItem(exports.__ISP_BC_GROUP_KEY)) !== null && _d !== void 0 ? _d : localStorage.getItem(exports.__ISP_BC_GROUP_KEY_USER);
|
|
103
|
+
if (groupIdFromStorage) {
|
|
104
|
+
return groupIdFromStorage;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
};
|
|
108
|
+
return bigcommerceCustomer;
|
|
109
|
+
}());
|
|
110
|
+
exports.bigcommerceCustomer = bigcommerceCustomer;
|
|
111
|
+
function isp_parseJwt(token) {
|
|
112
|
+
try {
|
|
113
|
+
var base64Url = token.split('.')[1];
|
|
114
|
+
var base64 = base64Url.replace('-', '+').replace('_', '/');
|
|
115
|
+
return JSON.parse(window.atob(base64));
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.error(e);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fast-simon/bigcommerce_customer",
|
|
3
|
-
"files": [
|
|
4
|
-
"lib/**/*"
|
|
5
|
-
],
|
|
6
|
-
"types": "lib/main.d.ts",
|
|
7
|
-
"version": "1.0.
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "vite",
|
|
10
|
-
"build": "tsc && vite build",
|
|
11
|
-
"preview": "vite preview",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fast-simon/bigcommerce_customer",
|
|
3
|
+
"files": [
|
|
4
|
+
"lib/**/*"
|
|
5
|
+
],
|
|
6
|
+
"types": "lib/main.d.ts",
|
|
7
|
+
"version": "1.0.46-beta.0",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "tsc && vite build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"tsc": "tsc"
|
|
13
|
+
},
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Fast Simon inc",
|
|
17
|
+
"url": "",
|
|
18
|
+
"email": ""
|
|
19
|
+
},
|
|
20
|
+
"main": "lib/main.js",
|
|
21
|
+
"directories": {
|
|
22
|
+
"lib": "lib"
|
|
23
|
+
},
|
|
24
|
+
"description": "",
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^4.5.5",
|
|
27
|
+
"vite": "^2.9.18"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^0.28.0"
|
|
31
|
+
}
|
|
32
|
+
}
|