@blux.ai/web-sdk 0.0.3

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.
Files changed (61) hide show
  1. package/.prettierrc +5 -0
  2. package/.vscode/settings.json +7 -0
  3. package/LICENSE +1 -0
  4. package/README.md +21 -0
  5. package/dist/BluxClient.d.ts +17 -0
  6. package/dist/BluxClient.js +104 -0
  7. package/dist/core/BaseErrorHandler.d.ts +3 -0
  8. package/dist/core/BaseErrorHandler.js +13 -0
  9. package/dist/core/HTTPClient.d.ts +10 -0
  10. package/dist/core/HTTPClient.js +122 -0
  11. package/dist/core/LocalStorage.d.ts +13 -0
  12. package/dist/core/LocalStorage.js +43 -0
  13. package/dist/core/Logger.d.ts +14 -0
  14. package/dist/core/Logger.js +90 -0
  15. package/dist/index.d.ts +4 -0
  16. package/dist/index.js +18 -0
  17. package/dist/requests/Devices/ActivateDevice.d.ts +8 -0
  18. package/dist/requests/Devices/ActivateDevice.js +39 -0
  19. package/dist/requests/Devices/CreateDevice.d.ts +14 -0
  20. package/dist/requests/Devices/CreateDevice.js +54 -0
  21. package/dist/requests/Devices/UpdateDevice.d.ts +17 -0
  22. package/dist/requests/Devices/UpdateDevice.js +61 -0
  23. package/dist/requests/Devices/index.d.ts +3 -0
  24. package/dist/requests/Devices/index.js +19 -0
  25. package/dist/requests/Events/AddCartaddEvent.d.ts +5 -0
  26. package/dist/requests/Events/AddCartaddEvent.js +39 -0
  27. package/dist/requests/Events/AddCustomEvent.d.ts +5 -0
  28. package/dist/requests/Events/AddCustomEvent.js +40 -0
  29. package/dist/requests/Events/AddLikeEvent.d.ts +5 -0
  30. package/dist/requests/Events/AddLikeEvent.js +39 -0
  31. package/dist/requests/Events/AddPageViewEvent.d.ts +5 -0
  32. package/dist/requests/Events/AddPageViewEvent.js +37 -0
  33. package/dist/requests/Events/AddProductDetailViewEvent.d.ts +5 -0
  34. package/dist/requests/Events/AddProductDetailViewEvent.js +39 -0
  35. package/dist/requests/Events/AddPurchaseEvent.d.ts +5 -0
  36. package/dist/requests/Events/AddPurchaseEvent.js +38 -0
  37. package/dist/requests/Events/AddRateEvent.d.ts +5 -0
  38. package/dist/requests/Events/AddRateEvent.js +40 -0
  39. package/dist/requests/Events/AddRecommendationViewEvent.d.ts +5 -0
  40. package/dist/requests/Events/AddRecommendationViewEvent.js +38 -0
  41. package/dist/requests/Events/EventRequest.d.ts +17 -0
  42. package/dist/requests/Events/EventRequest.js +56 -0
  43. package/dist/requests/Events/index.d.ts +8 -0
  44. package/dist/requests/Events/index.js +24 -0
  45. package/dist/requests/Events/types.d.ts +42 -0
  46. package/dist/requests/Events/types.js +2 -0
  47. package/dist/requests/Request.d.ts +12 -0
  48. package/dist/requests/Request.js +22 -0
  49. package/dist/requests/Users/UpdateUserProperties.d.ts +17 -0
  50. package/dist/requests/Users/UpdateUserProperties.js +54 -0
  51. package/dist/requests/Users/index.d.ts +1 -0
  52. package/dist/requests/Users/index.js +17 -0
  53. package/dist/requests/Users/types.d.ts +12 -0
  54. package/dist/requests/Users/types.js +2 -0
  55. package/dist/requests/index.d.ts +3 -0
  56. package/dist/requests/index.js +19 -0
  57. package/dist/utils/helper.d.ts +1 -0
  58. package/dist/utils/helper.js +7 -0
  59. package/dist/utils/types.d.ts +2 -0
  60. package/dist/utils/types.js +11 -0
  61. package/package.json +20 -0
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "printWidth": 120,
3
+ "tabWidth": 2,
4
+ "singleQuote": false
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
3
+ "editor.formatOnSave": true,
4
+ "editor.codeActionsOnSave": {
5
+ "source.fixAll.eslint": "explicit"
6
+ }
7
+ }
package/LICENSE ADDED
@@ -0,0 +1 @@
1
+ (c) Copyright 2024 Z.Ai Inc. All rights reserved.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @blux.ai/web-sdk
2
+
3
+ The BluxClient Web SDK Library is a set of methods attached to a global bluxclient object intended to be used by websites wishing to send data to Blux collector api.
4
+
5
+ ### Requirements
6
+
7
+ ---
8
+
9
+ - [Node.js](https://github.com/nodejs/node) >= 10.24.1 (ES6 2015 지원)
10
+ - TypeScript (권장)
11
+
12
+ ### Installation
13
+
14
+ ---
15
+
16
+ ```shell
17
+ // NPM 이용
18
+ npm install @blux.ai/web-sdk
19
+ // Yarn 이용
20
+ yarn add @blux.ai/web-sdk
21
+ ```
@@ -0,0 +1,17 @@
1
+ import { Request } from "./requests/Request";
2
+ export default class BluxClient {
3
+ static sdkInfo: {
4
+ type: string;
5
+ version: string;
6
+ };
7
+ static bluxClientID: string | null;
8
+ static bluxAPIKey: string | null;
9
+ static init({ bluxClientId, bluxAPIKey }: {
10
+ bluxClientId: string;
11
+ bluxAPIKey: string;
12
+ }): void;
13
+ static setLogLevel(logLevel: "trace" | "debug" | "info" | "warn" | "error"): void;
14
+ protected static deviceRegisterOrActivate(): void;
15
+ static setUserId(userId: string | null): void;
16
+ static sendRequest(request: Request | Request[]): void;
17
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ var BaseErrorHandler_1 = require("./core/BaseErrorHandler");
4
+ var HTTPClient_1 = require("./core/HTTPClient");
5
+ var LocalStorage_1 = require("./core/LocalStorage");
6
+ var Logger_1 = require("./core/Logger");
7
+ var ActivateDevice_1 = require("./requests/Devices/ActivateDevice");
8
+ var CreateDevice_1 = require("./requests/Devices/CreateDevice");
9
+ var UpdateDevice_1 = require("./requests/Devices/UpdateDevice");
10
+ var types_1 = require("./utils/types");
11
+ var BluxClient = /** @class */ (function () {
12
+ function BluxClient() {
13
+ }
14
+ BluxClient.init = function (_a) {
15
+ var bluxClientId = _a.bluxClientId, bluxAPIKey = _a.bluxAPIKey;
16
+ try {
17
+ Logger_1.Logger.debug("Init with client id: " + bluxClientId);
18
+ BluxClient.bluxClientID = bluxClientId;
19
+ BluxClient.bluxAPIKey = bluxAPIKey;
20
+ BluxClient.deviceRegisterOrActivate();
21
+ }
22
+ catch (e) {
23
+ BaseErrorHandler_1.BaseErrorHandler.handle(e);
24
+ }
25
+ };
26
+ BluxClient.setLogLevel = function (logLevel) {
27
+ Logger_1.Logger.setLevel(logLevel);
28
+ };
29
+ BluxClient.deviceRegisterOrActivate = function () {
30
+ try {
31
+ var clientId = BluxClient.bluxClientID;
32
+ var deviceId = LocalStorage_1.LocalStorage.getDeviceId();
33
+ var bluxId = LocalStorage_1.LocalStorage.getBluxId();
34
+ if ((0, types_1.isNullOrUndefined)(clientId) || (clientId && (0, types_1.isEmptyString)(clientId))) {
35
+ throw new Error("Client ID is not intialized. Please initialize BluxClient.");
36
+ }
37
+ if (!deviceId || !bluxId) {
38
+ // Create Device 호출 -> bluxId, deviceId 저장
39
+ Logger_1.Logger.debug("Saved Device ID and Blux ID are not exists, newly registered.");
40
+ var createDeviceRequest = new CreateDevice_1.CreateDevice();
41
+ HTTPClient_1.HTTPClient.sendRequestWithBody(createDeviceRequest).then(function (response) {
42
+ if (response) {
43
+ LocalStorage_1.LocalStorage.setBluxId(response.blux_id);
44
+ LocalStorage_1.LocalStorage.setDeviceId(response.device_id);
45
+ }
46
+ });
47
+ }
48
+ else {
49
+ Logger_1.Logger.debug("Saved Device ID and Blux ID are exists : " + deviceId + " | " + bluxId);
50
+ // Activate Device 호출
51
+ var activateDeviceRequest = new ActivateDevice_1.ActivateDevice(bluxId, deviceId);
52
+ HTTPClient_1.HTTPClient.sendRequestWithBody(activateDeviceRequest);
53
+ }
54
+ }
55
+ catch (e) {
56
+ BaseErrorHandler_1.BaseErrorHandler.handle(e);
57
+ }
58
+ };
59
+ BluxClient.setUserId = function (userId) {
60
+ try {
61
+ // localStorage로부터 device_id, blux_id를 가져온다.
62
+ var deviceId = LocalStorage_1.LocalStorage.getDeviceId();
63
+ var bluxId = LocalStorage_1.LocalStorage.getBluxId();
64
+ if (!deviceId || !bluxId) {
65
+ throw new Error("Both deviceId and bluxId are not found in localStorage. Please initialize BluxClient.");
66
+ }
67
+ var updateDeviceRequest = new UpdateDevice_1.UpdateDevice(bluxId, deviceId, userId);
68
+ HTTPClient_1.HTTPClient.sendRequestWithBody(updateDeviceRequest).then(function (response) {
69
+ var _a;
70
+ if (response) {
71
+ LocalStorage_1.LocalStorage.setBluxId(response.blux_id);
72
+ LocalStorage_1.LocalStorage.setDeviceId(response.device_id);
73
+ LocalStorage_1.LocalStorage.setUserId((_a = response.user_id) !== null && _a !== void 0 ? _a : "undefined");
74
+ }
75
+ });
76
+ }
77
+ catch (e) {
78
+ BaseErrorHandler_1.BaseErrorHandler.handle(e);
79
+ }
80
+ };
81
+ BluxClient.sendRequest = function (request) {
82
+ try {
83
+ var bluxId = LocalStorage_1.LocalStorage.getBluxId();
84
+ var deviceId = LocalStorage_1.LocalStorage.getDeviceId();
85
+ var userId = LocalStorage_1.LocalStorage.getUserId();
86
+ // If either of bluxId or deviceId is not exists, do not send request.
87
+ if (!bluxId || !deviceId) {
88
+ throw new Error("Saved Blux ID and Device ID are not exists. Do not send event request.");
89
+ }
90
+ HTTPClient_1.HTTPClient.sendRequestWithBody(request, { bluxId: bluxId, deviceId: deviceId, userId: userId });
91
+ }
92
+ catch (e) {
93
+ BaseErrorHandler_1.BaseErrorHandler.handle(e);
94
+ }
95
+ };
96
+ BluxClient.sdkInfo = {
97
+ type: "browser",
98
+ version: "0.0.1"
99
+ };
100
+ BluxClient.bluxClientID = null;
101
+ BluxClient.bluxAPIKey = null;
102
+ return BluxClient;
103
+ }());
104
+ exports["default"] = BluxClient;
@@ -0,0 +1,3 @@
1
+ export declare class BaseErrorHandler {
2
+ static handle(error: Error): void;
3
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.BaseErrorHandler = void 0;
4
+ var Logger_1 = require("./Logger");
5
+ var BaseErrorHandler = /** @class */ (function () {
6
+ function BaseErrorHandler() {
7
+ }
8
+ BaseErrorHandler.handle = function (error) {
9
+ Logger_1.Logger.error(error.stack);
10
+ };
11
+ return BaseErrorHandler;
12
+ }());
13
+ exports.BaseErrorHandler = BaseErrorHandler;
@@ -0,0 +1,10 @@
1
+ import { Request } from "../requests/Request";
2
+ export declare class HTTPClient {
3
+ private static COLLECTOR_BASE_URL;
4
+ static sendRequestWithBody<T>(request: Request | Request[], extraIdentifier?: {
5
+ bluxId: string;
6
+ deviceId: string;
7
+ userId: string | null;
8
+ }): Promise<T | undefined>;
9
+ private static generateHeaders;
10
+ }
@@ -0,0 +1,122 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ exports.__esModule = true;
53
+ exports.HTTPClient = void 0;
54
+ var BluxClient_1 = __importDefault(require("../BluxClient"));
55
+ var BaseErrorHandler_1 = require("./BaseErrorHandler");
56
+ var HTTPClient = /** @class */ (function () {
57
+ function HTTPClient() {
58
+ }
59
+ HTTPClient.sendRequestWithBody = function (request, extraIdentifier) {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var clientId, apiKey, requestsArray, method, baseUrl, path, bodyArr, body, response, errorMessage, data, e_1;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ clientId = BluxClient_1["default"].bluxClientID;
66
+ apiKey = BluxClient_1["default"].bluxAPIKey;
67
+ if (!clientId || !apiKey) {
68
+ throw new Error("Client ID and API Key are not initialized. Please initialize BluxClient.");
69
+ }
70
+ requestsArray = Array.isArray(request) ? request : [request];
71
+ method = requestsArray[0].method;
72
+ baseUrl = this.COLLECTOR_BASE_URL;
73
+ path = requestsArray[0].path;
74
+ bodyArr = requestsArray.map(function (req, idx) { return (__assign(__assign(__assign({}, req.getPayload()), { timestamp: req.getTimestamp() + 1e-6 * idx }), (extraIdentifier && {
75
+ user_id: extraIdentifier.userId,
76
+ blux_id: extraIdentifier.bluxId,
77
+ device_id: extraIdentifier.deviceId
78
+ }))); });
79
+ body = bodyArr.length === 1 ? bodyArr[0] : bodyArr;
80
+ _a.label = 1;
81
+ case 1:
82
+ _a.trys.push([1, 6, , 7]);
83
+ return [4 /*yield*/, fetch(baseUrl + path, {
84
+ method: method,
85
+ headers: this.generateHeaders(clientId, apiKey),
86
+ body: JSON.stringify(body)
87
+ })];
88
+ case 2:
89
+ response = _a.sent();
90
+ if (!!response.ok) return [3 /*break*/, 4];
91
+ return [4 /*yield*/, response.text()];
92
+ case 3:
93
+ errorMessage = _a.sent();
94
+ throw new Error("Network API Call failed with status ".concat(response.status, " Error message: ").concat(errorMessage));
95
+ case 4: return [4 /*yield*/, response.json()];
96
+ case 5:
97
+ data = _a.sent();
98
+ return [2 /*return*/, data];
99
+ case 6:
100
+ e_1 = _a.sent();
101
+ BaseErrorHandler_1.BaseErrorHandler.handle(e_1);
102
+ return [2 /*return*/, undefined];
103
+ case 7: return [2 /*return*/];
104
+ }
105
+ });
106
+ });
107
+ };
108
+ HTTPClient.generateHeaders = function (clientId, apiKey) {
109
+ var headers = new Headers();
110
+ headers.append("Content-Type", "application/json;charset=UTF-8");
111
+ headers.append("Accept", "application/json");
112
+ var requestTimestamp = Math.floor(Date.now() / 1000).toString();
113
+ headers.append("X-BLUX-SDK-INFO", "".concat(BluxClient_1["default"].sdkInfo.type, "-").concat(BluxClient_1["default"].sdkInfo.version));
114
+ headers.append("X-BLUX-CLIENT-ID", clientId);
115
+ headers.append("X-BLUX-API-KEY", apiKey);
116
+ headers.append("X-BLUX-TIMESTAMP", requestTimestamp);
117
+ return headers;
118
+ };
119
+ HTTPClient.COLLECTOR_BASE_URL = " https://collector-api-web.blux.ai";
120
+ return HTTPClient;
121
+ }());
122
+ exports.HTTPClient = HTTPClient;
@@ -0,0 +1,13 @@
1
+ export declare class LocalStorage {
2
+ /**
3
+ * Used in BluxClient initialization to dedupe local storage.
4
+ */
5
+ static getLogLevel(): string | null;
6
+ static setLogLevel(loglevel: string): void;
7
+ static getBluxId(): string | null;
8
+ static setBluxId(bluxId: string): void;
9
+ static getDeviceId(): string | null;
10
+ static setDeviceId(deviceId: string): void;
11
+ static getUserId(): string | null;
12
+ static setUserId(userId: string): void;
13
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.LocalStorage = void 0;
4
+ var BlUX_LOGLEVEL = "blux_loglevel";
5
+ var BLUX_ID = "blux_id";
6
+ var BLUX_DEVICE_ID = "blux_deviceId";
7
+ var BLUX_USER_ID = "blux_userId";
8
+ var LocalStorage = /** @class */ (function () {
9
+ function LocalStorage() {
10
+ }
11
+ /**
12
+ * Used in BluxClient initialization to dedupe local storage.
13
+ */
14
+ LocalStorage.getLogLevel = function () {
15
+ return localStorage.getItem(BlUX_LOGLEVEL);
16
+ };
17
+ LocalStorage.setLogLevel = function (loglevel) {
18
+ localStorage.setItem(BlUX_LOGLEVEL, loglevel);
19
+ };
20
+ LocalStorage.getBluxId = function () {
21
+ var bluxId = localStorage.getItem(BLUX_ID);
22
+ return bluxId === "undefined" || (bluxId === null || bluxId === void 0 ? void 0 : bluxId.trim()) == "" ? null : bluxId;
23
+ };
24
+ LocalStorage.setBluxId = function (bluxId) {
25
+ localStorage.setItem(BLUX_ID, bluxId);
26
+ };
27
+ LocalStorage.getDeviceId = function () {
28
+ var deviceId = localStorage.getItem(BLUX_DEVICE_ID);
29
+ return deviceId === "undefined" || (deviceId === null || deviceId === void 0 ? void 0 : deviceId.trim()) == "" ? null : deviceId;
30
+ };
31
+ LocalStorage.setDeviceId = function (deviceId) {
32
+ localStorage.setItem(BLUX_DEVICE_ID, deviceId);
33
+ };
34
+ LocalStorage.getUserId = function () {
35
+ var userId = localStorage.getItem(BLUX_USER_ID);
36
+ return userId === "undefined" || (userId === null || userId === void 0 ? void 0 : userId.trim()) == "" ? null : userId;
37
+ };
38
+ LocalStorage.setUserId = function (userId) {
39
+ localStorage.setItem(BLUX_USER_ID, userId);
40
+ };
41
+ return LocalStorage;
42
+ }());
43
+ exports.LocalStorage = LocalStorage;
@@ -0,0 +1,14 @@
1
+ type ConsoleLog = (message?: unknown, ...optionalParams: unknown[]) => void;
2
+ export declare class Logger {
3
+ static debug: ConsoleLog;
4
+ static trace: ConsoleLog;
5
+ static info: ConsoleLog;
6
+ static warn: ConsoleLog;
7
+ static error: ConsoleLog;
8
+ private static proxyMethodsCreated?;
9
+ private static shouldLog;
10
+ static setLevel(level: string): void;
11
+ private static wrapWithPrefix;
12
+ static createProxyMethods(): void;
13
+ }
14
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ exports.__esModule = true;
12
+ exports.Logger = void 0;
13
+ var LocalStorage_1 = require("./LocalStorage");
14
+ var Logger = /** @class */ (function () {
15
+ function Logger() {
16
+ }
17
+ Logger.shouldLog = function () {
18
+ try {
19
+ if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
20
+ return false;
21
+ }
22
+ var level = LocalStorage_1.LocalStorage.getLogLevel();
23
+ if (level && level.toLowerCase() === "trace") {
24
+ return true;
25
+ }
26
+ else {
27
+ return false;
28
+ }
29
+ }
30
+ catch (e) {
31
+ /* LocalStorage may not be accessible on browser profiles that restrict 3rd party cookies */
32
+ return false;
33
+ }
34
+ };
35
+ Logger.setLevel = function (level) {
36
+ if (typeof window === "undefined" || typeof window.localStorage === "undefined") {
37
+ return;
38
+ }
39
+ try {
40
+ LocalStorage_1.LocalStorage.setLogLevel(level);
41
+ Logger.proxyMethodsCreated = undefined;
42
+ Logger.createProxyMethods();
43
+ }
44
+ catch (e) {
45
+ /* LocalStorage may not be accessible on browser profiles that restrict 3rd party cookies */
46
+ return;
47
+ }
48
+ };
49
+ Logger.wrapWithPrefix = function (method) {
50
+ return function (message) {
51
+ var optionalParams = [];
52
+ for (var _i = 1; _i < arguments.length; _i++) {
53
+ optionalParams[_i - 1] = arguments[_i];
54
+ }
55
+ method.apply(void 0, __spreadArray(["[BluxClient] ".concat(message)], optionalParams, false));
56
+ };
57
+ };
58
+ Logger.createProxyMethods = function () {
59
+ if (typeof Logger.proxyMethodsCreated !== "undefined") {
60
+ return;
61
+ }
62
+ else {
63
+ Logger.proxyMethodsCreated = true;
64
+ }
65
+ var methods = {
66
+ log: "debug",
67
+ trace: "trace",
68
+ info: "info",
69
+ warn: "warn",
70
+ error: "error"
71
+ };
72
+ for (var _i = 0, _a = Object.keys(methods); _i < _a.length; _i++) {
73
+ var nativeMethod = _a[_i];
74
+ var nativeMethodExists = typeof console[nativeMethod] !== "undefined";
75
+ var methodToMapTo = methods[nativeMethod];
76
+ var shouldMap = nativeMethodExists && (Logger.shouldLog() || methodToMapTo === "error");
77
+ if (shouldMap) {
78
+ Logger[methodToMapTo] = Logger.wrapWithPrefix(console[nativeMethod].bind(console));
79
+ }
80
+ else {
81
+ // We want to skip logging, so this is internally an empty function.
82
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
83
+ Logger[methodToMapTo] = function () { };
84
+ }
85
+ }
86
+ };
87
+ return Logger;
88
+ }());
89
+ exports.Logger = Logger;
90
+ Logger.createProxyMethods();
@@ -0,0 +1,4 @@
1
+ import BluxClient from "./BluxClient";
2
+ import { AddProductDetailViewEvent, AddLikeEvent, AddCartaddEvent, AddPurchaseEvent, AddPageViewEvent, AddRateEvent, AddRecommendationViewEvent, AddCustomEvent, UpdateUserProperties } from "./requests";
3
+ export { AddProductDetailViewEvent, AddLikeEvent, AddCartaddEvent, AddPurchaseEvent, AddRateEvent, AddPageViewEvent, AddRecommendationViewEvent, AddCustomEvent, UpdateUserProperties, };
4
+ export default BluxClient;
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.UpdateUserProperties = exports.AddCustomEvent = exports.AddRecommendationViewEvent = exports.AddPageViewEvent = exports.AddRateEvent = exports.AddPurchaseEvent = exports.AddCartaddEvent = exports.AddLikeEvent = exports.AddProductDetailViewEvent = void 0;
7
+ var BluxClient_1 = __importDefault(require("./BluxClient"));
8
+ var requests_1 = require("./requests");
9
+ exports.AddProductDetailViewEvent = requests_1.AddProductDetailViewEvent;
10
+ exports.AddLikeEvent = requests_1.AddLikeEvent;
11
+ exports.AddCartaddEvent = requests_1.AddCartaddEvent;
12
+ exports.AddPurchaseEvent = requests_1.AddPurchaseEvent;
13
+ exports.AddPageViewEvent = requests_1.AddPageViewEvent;
14
+ exports.AddRateEvent = requests_1.AddRateEvent;
15
+ exports.AddRecommendationViewEvent = requests_1.AddRecommendationViewEvent;
16
+ exports.AddCustomEvent = requests_1.AddCustomEvent;
17
+ exports.UpdateUserProperties = requests_1.UpdateUserProperties;
18
+ exports["default"] = BluxClient_1["default"];
@@ -0,0 +1,8 @@
1
+ import { Request } from "../Request";
2
+ export declare class ActivateDevice extends Request {
3
+ protected bluxId: string;
4
+ protected deviceId: string;
5
+ protected lastActiveAt: string | null;
6
+ constructor(bluxId: string, deviceId: string);
7
+ getPayload(): object;
8
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ exports.__esModule = true;
18
+ exports.ActivateDevice = void 0;
19
+ var Request_1 = require("../Request");
20
+ var ActivateDevice = /** @class */ (function (_super) {
21
+ __extends(ActivateDevice, _super);
22
+ function ActivateDevice(bluxId, deviceId) {
23
+ var _this = _super.call(this, "PATCH", "/devices") || this;
24
+ _this.bluxId = bluxId;
25
+ _this.deviceId = deviceId;
26
+ _this.lastActiveAt = new Date().toISOString();
27
+ return _this;
28
+ }
29
+ ActivateDevice.prototype.getPayload = function () {
30
+ var payload = {
31
+ blux_id: this.bluxId,
32
+ device_id: this.deviceId,
33
+ last_active_at: this.lastActiveAt
34
+ };
35
+ return payload;
36
+ };
37
+ return ActivateDevice;
38
+ }(Request_1.Request));
39
+ exports.ActivateDevice = ActivateDevice;
@@ -0,0 +1,14 @@
1
+ import { Request } from "../Request";
2
+ export declare class CreateDevice extends Request {
3
+ protected platform: string | null;
4
+ protected deviceModel: string | null;
5
+ protected osVersion: string | null;
6
+ protected sdkVersion: string | null;
7
+ protected sdkType: string | null;
8
+ protected timezone: string | null;
9
+ protected languageCode: string | null;
10
+ protected countryCode: string | null;
11
+ protected lastActiveAt: string | null;
12
+ constructor();
13
+ getPayload(): object;
14
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ exports.__esModule = true;
21
+ exports.CreateDevice = void 0;
22
+ var BluxClient_1 = __importDefault(require("../../BluxClient"));
23
+ var Request_1 = require("../Request");
24
+ var CreateDevice = /** @class */ (function (_super) {
25
+ __extends(CreateDevice, _super);
26
+ function CreateDevice() {
27
+ var _this = _super.call(this, "POST", "/devices") || this;
28
+ _this.platform = "typescript";
29
+ _this.deviceModel = navigator.userAgent; // 기기 모델;
30
+ _this.osVersion = navigator.userAgent; // OS 버전 (navigator.userAgent를 통해 확인);
31
+ _this.sdkVersion = BluxClient_1["default"].sdkInfo.version;
32
+ _this.sdkType = BluxClient_1["default"].sdkInfo.type;
33
+ _this.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
34
+ _this.languageCode = navigator.language.split("-")[0];
35
+ _this.countryCode = navigator.language.split("-")[1];
36
+ _this.lastActiveAt = new Date().toISOString();
37
+ return _this;
38
+ }
39
+ CreateDevice.prototype.getPayload = function () {
40
+ return {
41
+ platform: this.platform,
42
+ device_model: this.deviceModel,
43
+ os_version: this.osVersion,
44
+ sdk_version: this.sdkVersion,
45
+ sdk_type: this.sdkType,
46
+ timezone: this.timezone,
47
+ language_code: this.languageCode,
48
+ country_code: this.countryCode,
49
+ last_active_at: this.lastActiveAt
50
+ };
51
+ };
52
+ return CreateDevice;
53
+ }(Request_1.Request));
54
+ exports.CreateDevice = CreateDevice;
@@ -0,0 +1,17 @@
1
+ import { Request } from "../Request";
2
+ export declare class UpdateDevice extends Request {
3
+ protected bluxId: string;
4
+ protected deviceId: string;
5
+ protected userId?: string | null;
6
+ protected platform: string | null;
7
+ protected deviceModel: string | null;
8
+ protected osVersion: string | null;
9
+ protected sdkVersion: string | null;
10
+ protected sdkType: string | null;
11
+ protected timezone: string | null;
12
+ protected languageCode: string | null;
13
+ protected countryCode: string | null;
14
+ protected lastActiveAt: string | null;
15
+ constructor(bluxId: string, deviceId: string, userId?: string | null);
16
+ getPayload(): object;
17
+ }