@rebuy/rebuy 1.6.0-alpha.2 → 1.6.0-alpha.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.
- package/dist/api.js +131 -0
- package/dist/api.js.map +7 -0
- package/dist/api.mjs +111 -0
- package/dist/api.mjs.map +7 -0
- package/dist/client.js +145 -0
- package/dist/client.js.map +7 -0
- package/dist/client.mjs +115 -0
- package/dist/client.mjs.map +7 -0
- package/dist/cookie.js +139 -0
- package/dist/cookie.js.map +7 -0
- package/dist/cookie.mjs +119 -0
- package/dist/cookie.mjs.map +7 -0
- package/dist/geolocation.js +79 -0
- package/dist/geolocation.js.map +7 -0
- package/dist/geolocation.mjs +49 -0
- package/dist/geolocation.mjs.map +7 -0
- package/dist/identity.js +85 -0
- package/dist/identity.js.map +7 -0
- package/dist/identity.mjs +55 -0
- package/dist/identity.mjs.map +7 -0
- package/dist/index.js +8 -773
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +7 -766
- package/dist/index.mjs.map +4 -4
- package/dist/session.js +72 -0
- package/dist/session.js.map +7 -0
- package/dist/session.mjs +42 -0
- package/dist/session.mjs.map +7 -0
- package/dist/utilities.js +321 -0
- package/dist/utilities.js.map +7 -0
- package/dist/utilities.mjs +301 -0
- package/dist/utilities.mjs.map +7 -0
- package/package.json +14 -1
package/dist/cookie.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cookie_exports = {};
|
|
20
|
+
__export(cookie_exports, {
|
|
21
|
+
default: () => cookie_default,
|
|
22
|
+
destroy: () => destroy,
|
|
23
|
+
enabled: () => enabled,
|
|
24
|
+
find: () => find,
|
|
25
|
+
get: () => get,
|
|
26
|
+
getAll: () => getAll,
|
|
27
|
+
set: () => set
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
30
|
+
var import_utilities = require("~/utilities");
|
|
31
|
+
function get(name) {
|
|
32
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const cookie = document.cookie.match("(^|;) ?" + decodeURIComponent(name) + "=([^;]*)(;|$)");
|
|
36
|
+
let value = null;
|
|
37
|
+
if (cookie != null) {
|
|
38
|
+
const data = decodeURIComponent(cookie[2]);
|
|
39
|
+
const decode = (0, import_utilities.isBase64Encoded)(data) ? true : false;
|
|
40
|
+
value = (0, import_utilities.stringToData)(data, decode);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function getAll() {
|
|
45
|
+
const cookies = {};
|
|
46
|
+
if (document && document.cookie && document.cookie !== "") {
|
|
47
|
+
const split = document.cookie.split(";");
|
|
48
|
+
for (let i = 0; i < split.length; i++) {
|
|
49
|
+
const pairs = split[i].split("=");
|
|
50
|
+
pairs[0] = pairs[0].replace(/^ /, "");
|
|
51
|
+
const key = decodeURIComponent(pairs[0]);
|
|
52
|
+
const value = decodeURIComponent(pairs[1]);
|
|
53
|
+
const decode = (0, import_utilities.isBase64Encoded)(value) ? true : false;
|
|
54
|
+
cookies[key] = (0, import_utilities.stringToData)(value, decode);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return cookies;
|
|
58
|
+
}
|
|
59
|
+
function set(name, value, config) {
|
|
60
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const attributes = ["path", "domain", "maxAge", "expires", "secure", "sameSite"];
|
|
64
|
+
const convenienceTimes = ["seconds", "minutes", "hours", "days", "weeks", "months", "years"];
|
|
65
|
+
const cookieAttributes = {
|
|
66
|
+
path: "/"
|
|
67
|
+
};
|
|
68
|
+
if (typeof config != "undefined" && Number.isInteger(config)) {
|
|
69
|
+
cookieAttributes["max-age"] = config;
|
|
70
|
+
} else if (typeof config === "object" && config !== null) {
|
|
71
|
+
for (const key in config) {
|
|
72
|
+
if (attributes.includes(key)) {
|
|
73
|
+
if (key === "maxAge") {
|
|
74
|
+
cookieAttributes["max-age"] = config[key];
|
|
75
|
+
} else if (key === "sameSite") {
|
|
76
|
+
cookieAttributes["samesite"] = config[key];
|
|
77
|
+
} else if (key === "expires") {
|
|
78
|
+
cookieAttributes[key] = new Date(config[key]).toUTCString();
|
|
79
|
+
} else {
|
|
80
|
+
cookieAttributes[key] = config[key];
|
|
81
|
+
}
|
|
82
|
+
} else if (convenienceTimes.includes(key)) {
|
|
83
|
+
let duration = config[key];
|
|
84
|
+
if (key === "seconds") {
|
|
85
|
+
duration = duration * 1;
|
|
86
|
+
} else if (key === "minutes") {
|
|
87
|
+
duration = duration * 60;
|
|
88
|
+
} else if (key === "hours") {
|
|
89
|
+
duration = duration * 60 * 60;
|
|
90
|
+
} else if (key === "days") {
|
|
91
|
+
duration = duration * 60 * 60 * 24;
|
|
92
|
+
} else if (key === "weeks") {
|
|
93
|
+
duration = duration * 60 * 60 * 24 * 7;
|
|
94
|
+
} else if (key === "months") {
|
|
95
|
+
duration = duration * 60 * 60 * 24 * 30;
|
|
96
|
+
} else if (key === "years") {
|
|
97
|
+
duration = duration * 60 * 60 * 24 * 365;
|
|
98
|
+
}
|
|
99
|
+
cookieAttributes["max-age"] = duration;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
value = (0, import_utilities.dataToString)(value, config?.encode);
|
|
104
|
+
let cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
|
|
105
|
+
for (const key in cookieAttributes) {
|
|
106
|
+
cookie += ";" + key + "=" + cookieAttributes[key];
|
|
107
|
+
}
|
|
108
|
+
document.cookie = cookie;
|
|
109
|
+
}
|
|
110
|
+
function find(name) {
|
|
111
|
+
const matches = [];
|
|
112
|
+
const cookies = getAll();
|
|
113
|
+
for (const key in cookies) {
|
|
114
|
+
if (key.includes(name)) {
|
|
115
|
+
matches.push({
|
|
116
|
+
name: key,
|
|
117
|
+
value: cookies[key]
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return matches;
|
|
122
|
+
}
|
|
123
|
+
function destroy(name) {
|
|
124
|
+
set(name, "", { encode: false, seconds: 0 });
|
|
125
|
+
}
|
|
126
|
+
function enabled() {
|
|
127
|
+
const test = {
|
|
128
|
+
key: "__cookie_test",
|
|
129
|
+
value: 1
|
|
130
|
+
};
|
|
131
|
+
set(test.key, test.value, { encode: false });
|
|
132
|
+
const enabled2 = get(test.key) === test.value ? true : false;
|
|
133
|
+
if (enabled2) {
|
|
134
|
+
destroy(test.key);
|
|
135
|
+
}
|
|
136
|
+
return enabled2;
|
|
137
|
+
}
|
|
138
|
+
var cookie_default = { destroy, enabled, find, get, getAll, set };
|
|
139
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cookie.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { dataToString, isBase64Encoded, stringToData } from '~/utilities';\n\n/**\n * Get a cookie by name\n *\n * @param {string} name - The name of the cookie to get\n *\n * @returns {any} The value of the cookie or null if the cookie is not found\n */\nexport function get(name: string): any | null {\n if (typeof document == 'undefined' || !document.cookie) {\n return null;\n }\n\n // Get cookie\n const cookie = document.cookie.match('(^|;) ?' + decodeURIComponent(name) + '=([^;]*)(;|$)');\n\n let value: any = null;\n\n if (cookie != null) {\n // Get data\n const data = decodeURIComponent(cookie[2]);\n\n // Auto decode\n const decode = isBase64Encoded(data) ? true : false;\n\n // Convert to data object\n value = stringToData(data, decode);\n }\n\n return value;\n}\n\n/**\n * Get all cookies\n *\n * @returns {Record<string, any>} All cookies\n */\nexport function getAll(): Record<string, any> {\n const cookies: Record<string, any> = {};\n\n if (document && document.cookie && document.cookie !== '') {\n const split = document.cookie.split(';');\n\n for (let i = 0; i < split.length; i++) {\n const pairs = split[i].split('=');\n\n pairs[0] = pairs[0].replace(/^ /, '');\n\n const key = decodeURIComponent(pairs[0]);\n const value = decodeURIComponent(pairs[1]);\n\n // Auto decode\n const decode = isBase64Encoded(value) ? true : false;\n\n cookies[key] = stringToData(value, decode);\n }\n }\n\n return cookies;\n}\n\n/**\n * Set a cookie\n *\n * @param {string} name - The name of the cookie\n * @param {any} value - The value of the cookie\n * @param {any} config - The configuration of the cookie\n *\n * @returns {void}\n */\nexport function set(name: string, value: any, config: any): void {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n const attributes = ['path', 'domain', 'maxAge', 'expires', 'secure', 'sameSite'];\n const convenienceTimes = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'];\n\n const cookieAttributes: Record<string, any> = {\n path: '/',\n };\n\n if (typeof config != 'undefined' && Number.isInteger(config)) {\n cookieAttributes['max-age'] = config;\n } else if (typeof config === 'object' && config !== null) {\n for (const key in config) {\n if (attributes.includes(key)) {\n if (key === 'maxAge') {\n cookieAttributes['max-age'] = config[key];\n } else if (key === 'sameSite') {\n cookieAttributes['samesite'] = config[key];\n } else if (key === 'expires') {\n cookieAttributes[key] = new Date(config[key]).toUTCString();\n } else {\n cookieAttributes[key] = config[key];\n }\n } else if (convenienceTimes.includes(key)) {\n let duration = config[key];\n\n if (key === 'seconds') {\n duration = duration * 1;\n } else if (key === 'minutes') {\n duration = duration * 60;\n } else if (key === 'hours') {\n duration = duration * 60 * 60;\n } else if (key === 'days') {\n duration = duration * 60 * 60 * 24;\n } else if (key === 'weeks') {\n duration = duration * 60 * 60 * 24 * 7;\n } else if (key === 'months') {\n duration = duration * 60 * 60 * 24 * 30;\n } else if (key === 'years') {\n duration = duration * 60 * 60 * 24 * 365;\n }\n\n cookieAttributes['max-age'] = duration;\n }\n }\n }\n\n // Convert data to string\n value = dataToString(value, config?.encode);\n\n // Define cookie\n let cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);\n\n // Add optional cookie attributes\n for (const key in cookieAttributes) {\n cookie += ';' + key + '=' + cookieAttributes[key];\n }\n\n // Write cookie\n document.cookie = cookie;\n}\n\n/**\n * Find all cookies that match a name\n *\n * @param {string} name - The name of the cookie to find\n *\n * @returns {Array<{ name: string; value: any }>} All cookies that match the name\n */\nexport function find(name: string): { name: string; value: any }[] {\n const matches: { name: string; value: any }[] = [];\n const cookies = getAll();\n\n for (const key in cookies) {\n if (key.includes(name)) {\n matches.push({\n name: key,\n value: cookies[key],\n });\n }\n }\n\n return matches;\n}\n\n/**\n * Destroy a cookie\n *\n * @param {string} name - The name of the cookie to destroy\n */\nexport function destroy(name: string): void {\n set(name, '', { encode: false, seconds: 0 });\n}\n\n/**\n * Check if cookies are enabled\n *\n * @returns {boolean} True if cookies are enabled, false otherwise\n */\nexport function enabled(): boolean {\n const test = {\n key: '__cookie_test',\n value: 1,\n };\n\n set(test.key, test.value, { encode: false });\n\n const enabled = get(test.key) === test.value ? true : false;\n\n if (enabled) {\n destroy(test.key);\n }\n\n return enabled;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default { destroy, enabled, find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IAAI,IAAI,MAAM,mBAAmB,KAAK;AAGtE,aAAW,OAAO,kBAAkB;AAChC,cAAU,MAAM,MAAM,MAAM,iBAAiB,GAAG;AAAA,EACpD;AAGA,WAAS,SAAS;AACtB;AASO,SAAS,KAAK,MAA8C;AAC/D,QAAM,UAA0C,CAAC;AACjD,QAAM,UAAU,OAAO;AAEvB,aAAW,OAAO,SAAS;AACvB,QAAI,IAAI,SAAS,IAAI,GAAG;AACpB,cAAQ,KAAK;AAAA,QACT,MAAM;AAAA,QACN,OAAO,QAAQ,GAAG;AAAA,MACtB,CAAC;AAAA,IACL;AAAA,EACJ;AAEA,SAAO;AACX;AAOO,SAAS,QAAQ,MAAoB;AACxC,MAAI,MAAM,IAAI,EAAE,QAAQ,OAAO,SAAS,EAAE,CAAC;AAC/C;AAOO,SAAS,UAAmB;AAC/B,QAAM,OAAO;AAAA,IACT,KAAK;AAAA,IACL,OAAO;AAAA,EACX;AAEA,MAAI,KAAK,KAAK,KAAK,OAAO,EAAE,QAAQ,MAAM,CAAC;AAE3C,QAAMA,WAAU,IAAI,KAAK,GAAG,MAAM,KAAK,QAAQ,OAAO;AAEtD,MAAIA,UAAS;AACT,YAAQ,KAAK,GAAG;AAAA,EACpB;AAEA,SAAOA;AACX;AAGA,IAAO,iBAAQ,EAAE,SAAS,SAAS,MAAM,KAAK,QAAQ,IAAI;",
|
|
6
|
+
"names": ["enabled"]
|
|
7
|
+
}
|
package/dist/cookie.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { dataToString, isBase64Encoded, stringToData } from "~/utilities";
|
|
2
|
+
function get(name) {
|
|
3
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const cookie = document.cookie.match("(^|;) ?" + decodeURIComponent(name) + "=([^;]*)(;|$)");
|
|
7
|
+
let value = null;
|
|
8
|
+
if (cookie != null) {
|
|
9
|
+
const data = decodeURIComponent(cookie[2]);
|
|
10
|
+
const decode = isBase64Encoded(data) ? true : false;
|
|
11
|
+
value = stringToData(data, decode);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function getAll() {
|
|
16
|
+
const cookies = {};
|
|
17
|
+
if (document && document.cookie && document.cookie !== "") {
|
|
18
|
+
const split = document.cookie.split(";");
|
|
19
|
+
for (let i = 0; i < split.length; i++) {
|
|
20
|
+
const pairs = split[i].split("=");
|
|
21
|
+
pairs[0] = pairs[0].replace(/^ /, "");
|
|
22
|
+
const key = decodeURIComponent(pairs[0]);
|
|
23
|
+
const value = decodeURIComponent(pairs[1]);
|
|
24
|
+
const decode = isBase64Encoded(value) ? true : false;
|
|
25
|
+
cookies[key] = stringToData(value, decode);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return cookies;
|
|
29
|
+
}
|
|
30
|
+
function set(name, value, config) {
|
|
31
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const attributes = ["path", "domain", "maxAge", "expires", "secure", "sameSite"];
|
|
35
|
+
const convenienceTimes = ["seconds", "minutes", "hours", "days", "weeks", "months", "years"];
|
|
36
|
+
const cookieAttributes = {
|
|
37
|
+
path: "/"
|
|
38
|
+
};
|
|
39
|
+
if (typeof config != "undefined" && Number.isInteger(config)) {
|
|
40
|
+
cookieAttributes["max-age"] = config;
|
|
41
|
+
} else if (typeof config === "object" && config !== null) {
|
|
42
|
+
for (const key in config) {
|
|
43
|
+
if (attributes.includes(key)) {
|
|
44
|
+
if (key === "maxAge") {
|
|
45
|
+
cookieAttributes["max-age"] = config[key];
|
|
46
|
+
} else if (key === "sameSite") {
|
|
47
|
+
cookieAttributes["samesite"] = config[key];
|
|
48
|
+
} else if (key === "expires") {
|
|
49
|
+
cookieAttributes[key] = new Date(config[key]).toUTCString();
|
|
50
|
+
} else {
|
|
51
|
+
cookieAttributes[key] = config[key];
|
|
52
|
+
}
|
|
53
|
+
} else if (convenienceTimes.includes(key)) {
|
|
54
|
+
let duration = config[key];
|
|
55
|
+
if (key === "seconds") {
|
|
56
|
+
duration = duration * 1;
|
|
57
|
+
} else if (key === "minutes") {
|
|
58
|
+
duration = duration * 60;
|
|
59
|
+
} else if (key === "hours") {
|
|
60
|
+
duration = duration * 60 * 60;
|
|
61
|
+
} else if (key === "days") {
|
|
62
|
+
duration = duration * 60 * 60 * 24;
|
|
63
|
+
} else if (key === "weeks") {
|
|
64
|
+
duration = duration * 60 * 60 * 24 * 7;
|
|
65
|
+
} else if (key === "months") {
|
|
66
|
+
duration = duration * 60 * 60 * 24 * 30;
|
|
67
|
+
} else if (key === "years") {
|
|
68
|
+
duration = duration * 60 * 60 * 24 * 365;
|
|
69
|
+
}
|
|
70
|
+
cookieAttributes["max-age"] = duration;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
value = dataToString(value, config?.encode);
|
|
75
|
+
let cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value);
|
|
76
|
+
for (const key in cookieAttributes) {
|
|
77
|
+
cookie += ";" + key + "=" + cookieAttributes[key];
|
|
78
|
+
}
|
|
79
|
+
document.cookie = cookie;
|
|
80
|
+
}
|
|
81
|
+
function find(name) {
|
|
82
|
+
const matches = [];
|
|
83
|
+
const cookies = getAll();
|
|
84
|
+
for (const key in cookies) {
|
|
85
|
+
if (key.includes(name)) {
|
|
86
|
+
matches.push({
|
|
87
|
+
name: key,
|
|
88
|
+
value: cookies[key]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return matches;
|
|
93
|
+
}
|
|
94
|
+
function destroy(name) {
|
|
95
|
+
set(name, "", { encode: false, seconds: 0 });
|
|
96
|
+
}
|
|
97
|
+
function enabled() {
|
|
98
|
+
const test = {
|
|
99
|
+
key: "__cookie_test",
|
|
100
|
+
value: 1
|
|
101
|
+
};
|
|
102
|
+
set(test.key, test.value, { encode: false });
|
|
103
|
+
const enabled2 = get(test.key) === test.value ? true : false;
|
|
104
|
+
if (enabled2) {
|
|
105
|
+
destroy(test.key);
|
|
106
|
+
}
|
|
107
|
+
return enabled2;
|
|
108
|
+
}
|
|
109
|
+
var cookie_default = { destroy, enabled, find, get, getAll, set };
|
|
110
|
+
export {
|
|
111
|
+
cookie_default as default,
|
|
112
|
+
destroy,
|
|
113
|
+
enabled,
|
|
114
|
+
find,
|
|
115
|
+
get,
|
|
116
|
+
getAll,
|
|
117
|
+
set
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=cookie.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cookie.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { dataToString, isBase64Encoded, stringToData } from '~/utilities';\n\n/**\n * Get a cookie by name\n *\n * @param {string} name - The name of the cookie to get\n *\n * @returns {any} The value of the cookie or null if the cookie is not found\n */\nexport function get(name: string): any | null {\n if (typeof document == 'undefined' || !document.cookie) {\n return null;\n }\n\n // Get cookie\n const cookie = document.cookie.match('(^|;) ?' + decodeURIComponent(name) + '=([^;]*)(;|$)');\n\n let value: any = null;\n\n if (cookie != null) {\n // Get data\n const data = decodeURIComponent(cookie[2]);\n\n // Auto decode\n const decode = isBase64Encoded(data) ? true : false;\n\n // Convert to data object\n value = stringToData(data, decode);\n }\n\n return value;\n}\n\n/**\n * Get all cookies\n *\n * @returns {Record<string, any>} All cookies\n */\nexport function getAll(): Record<string, any> {\n const cookies: Record<string, any> = {};\n\n if (document && document.cookie && document.cookie !== '') {\n const split = document.cookie.split(';');\n\n for (let i = 0; i < split.length; i++) {\n const pairs = split[i].split('=');\n\n pairs[0] = pairs[0].replace(/^ /, '');\n\n const key = decodeURIComponent(pairs[0]);\n const value = decodeURIComponent(pairs[1]);\n\n // Auto decode\n const decode = isBase64Encoded(value) ? true : false;\n\n cookies[key] = stringToData(value, decode);\n }\n }\n\n return cookies;\n}\n\n/**\n * Set a cookie\n *\n * @param {string} name - The name of the cookie\n * @param {any} value - The value of the cookie\n * @param {any} config - The configuration of the cookie\n *\n * @returns {void}\n */\nexport function set(name: string, value: any, config: any): void {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n const attributes = ['path', 'domain', 'maxAge', 'expires', 'secure', 'sameSite'];\n const convenienceTimes = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'];\n\n const cookieAttributes: Record<string, any> = {\n path: '/',\n };\n\n if (typeof config != 'undefined' && Number.isInteger(config)) {\n cookieAttributes['max-age'] = config;\n } else if (typeof config === 'object' && config !== null) {\n for (const key in config) {\n if (attributes.includes(key)) {\n if (key === 'maxAge') {\n cookieAttributes['max-age'] = config[key];\n } else if (key === 'sameSite') {\n cookieAttributes['samesite'] = config[key];\n } else if (key === 'expires') {\n cookieAttributes[key] = new Date(config[key]).toUTCString();\n } else {\n cookieAttributes[key] = config[key];\n }\n } else if (convenienceTimes.includes(key)) {\n let duration = config[key];\n\n if (key === 'seconds') {\n duration = duration * 1;\n } else if (key === 'minutes') {\n duration = duration * 60;\n } else if (key === 'hours') {\n duration = duration * 60 * 60;\n } else if (key === 'days') {\n duration = duration * 60 * 60 * 24;\n } else if (key === 'weeks') {\n duration = duration * 60 * 60 * 24 * 7;\n } else if (key === 'months') {\n duration = duration * 60 * 60 * 24 * 30;\n } else if (key === 'years') {\n duration = duration * 60 * 60 * 24 * 365;\n }\n\n cookieAttributes['max-age'] = duration;\n }\n }\n }\n\n // Convert data to string\n value = dataToString(value, config?.encode);\n\n // Define cookie\n let cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value);\n\n // Add optional cookie attributes\n for (const key in cookieAttributes) {\n cookie += ';' + key + '=' + cookieAttributes[key];\n }\n\n // Write cookie\n document.cookie = cookie;\n}\n\n/**\n * Find all cookies that match a name\n *\n * @param {string} name - The name of the cookie to find\n *\n * @returns {Array<{ name: string; value: any }>} All cookies that match the name\n */\nexport function find(name: string): { name: string; value: any }[] {\n const matches: { name: string; value: any }[] = [];\n const cookies = getAll();\n\n for (const key in cookies) {\n if (key.includes(name)) {\n matches.push({\n name: key,\n value: cookies[key],\n });\n }\n }\n\n return matches;\n}\n\n/**\n * Destroy a cookie\n *\n * @param {string} name - The name of the cookie to destroy\n */\nexport function destroy(name: string): void {\n set(name, '', { encode: false, seconds: 0 });\n}\n\n/**\n * Check if cookies are enabled\n *\n * @returns {boolean} True if cookies are enabled, false otherwise\n */\nexport function enabled(): boolean {\n const test = {\n key: '__cookie_test',\n value: 1,\n };\n\n set(test.key, test.value, { encode: false });\n\n const enabled = get(test.key) === test.value ? true : false;\n\n if (enabled) {\n destroy(test.key);\n }\n\n return enabled;\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default { destroy, enabled, find, get, getAll, set };\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,cAAc,iBAAiB,oBAAoB;AASrD,SAAS,IAAI,MAA0B;AAC1C,MAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD,WAAO;AAAA,EACX;AAGA,QAAM,SAAS,SAAS,OAAO,MAAM,YAAY,mBAAmB,IAAI,IAAI,eAAe;AAE3F,MAAI,QAAa;AAEjB,MAAI,UAAU,MAAM;AAEhB,UAAM,OAAO,mBAAmB,OAAO,CAAC,CAAC;AAGzC,UAAM,SAAS,gBAAgB,IAAI,IAAI,OAAO;AAG9C,YAAQ,aAAa,MAAM,MAAM;AAAA,EACrC;AAEA,SAAO;AACX;AAOO,SAAS,SAA8B;AAC1C,QAAM,UAA+B,CAAC;AAEtC,MAAI,YAAY,SAAS,UAAU,SAAS,WAAW,IAAI;AACvD,UAAM,QAAQ,SAAS,OAAO,MAAM,GAAG;AAEvC,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,YAAM,QAAQ,MAAM,CAAC,EAAE,MAAM,GAAG;AAEhC,YAAM,CAAC,IAAI,MAAM,CAAC,EAAE,QAAQ,MA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EAAE,SAAS,SAAS,MAAM,KAAK,QAAQ,IAAI;",
|
|
6
|
+
"names": ["enabled"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var geolocation_exports = {};
|
|
30
|
+
__export(geolocation_exports, {
|
|
31
|
+
Geolocation: () => Geolocation,
|
|
32
|
+
default: () => geolocation_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(geolocation_exports);
|
|
35
|
+
var import_api = __toESM(require("~/api"), 1);
|
|
36
|
+
var import_cookie = __toESM(require("~/cookie"), 1);
|
|
37
|
+
const config = {
|
|
38
|
+
geolocation: null,
|
|
39
|
+
geolocationCookie: "_rebuyGeolocation",
|
|
40
|
+
geolocationDuration: {
|
|
41
|
+
minutes: 30
|
|
42
|
+
},
|
|
43
|
+
key: null
|
|
44
|
+
};
|
|
45
|
+
const getGeolocation = async () => {
|
|
46
|
+
const api = new import_api.default(config.key);
|
|
47
|
+
const response = await api.callGeo("GET", "/", null);
|
|
48
|
+
if (response.data) {
|
|
49
|
+
config.geolocation = response.data;
|
|
50
|
+
const cookieOptions = {
|
|
51
|
+
secure: true
|
|
52
|
+
};
|
|
53
|
+
Object.assign(cookieOptions, config.geolocationDuration);
|
|
54
|
+
import_cookie.default.set(config.geolocationCookie, config.geolocation, { ...cookieOptions, encode: false });
|
|
55
|
+
}
|
|
56
|
+
return config.geolocation;
|
|
57
|
+
};
|
|
58
|
+
class Geolocation {
|
|
59
|
+
constructor(key) {
|
|
60
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof key == "string") {
|
|
64
|
+
config.key = key;
|
|
65
|
+
}
|
|
66
|
+
config.geolocation = import_cookie.default.get(config.geolocationCookie);
|
|
67
|
+
if (config.geolocation === null) {
|
|
68
|
+
getGeolocation();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async geolocation() {
|
|
72
|
+
if (config.geolocation == null) {
|
|
73
|
+
await getGeolocation();
|
|
74
|
+
}
|
|
75
|
+
return config.geolocation;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
var geolocation_default = Geolocation;
|
|
79
|
+
//# sourceMappingURL=geolocation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/geolocation.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Api from '~/api';\nimport Cookie from '~/cookie';\n\ntype Config = {\n geolocation: any;\n geolocationCookie: string;\n geolocationDuration: {\n minutes: number;\n };\n key: string | null;\n};\n\nconst config: Config = {\n geolocation: null,\n geolocationCookie: '_rebuyGeolocation',\n geolocationDuration: {\n minutes: 30,\n },\n key: null,\n};\n\nconst getGeolocation = async (): Promise<any> => {\n const api = new Api(config.key);\n const response = await api.callGeo('GET', '/', null);\n\n if (response.data) {\n // Update config with geolocation\n config.geolocation = response.data;\n\n // Write cookie with geolocation\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with geolocation config\n Object.assign(cookieOptions, config.geolocationDuration);\n\n // Write cookie with geolocation\n Cookie.set(config.geolocationCookie, config.geolocation, { ...cookieOptions, encode: false });\n }\n\n return config.geolocation;\n};\n\nexport class Geolocation {\n constructor(key: string | null) {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n config.key = key;\n }\n\n config.geolocation = Cookie.get(config.geolocationCookie);\n\n // Create a new geolocation (if needed)\n if (config.geolocation === null) {\n getGeolocation();\n }\n }\n\n async geolocation(): Promise<any> {\n if (config.geolocation == null) {\n await getGeolocation();\n }\n\n return config.geolocation;\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Geolocation;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAgB;AAChB,oBAAmB;AAWnB,MAAM,SAAiB;AAAA,EACnB,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,IACjB,SAAS;AAAA,EACb;AAAA,EACA,KAAK;AACT;AAEA,MAAM,iBAAiB,YAA0B;AAC7C,QAAM,MAAM,IAAI,WAAAA,QAAI,OAAO,GAAG;AAC9B,QAAM,WAAW,MAAM,IAAI,QAAQ,OAAO,KAAK,IAAI;AAEnD,MAAI,SAAS,MAAM;AAEf,WAAO,cAAc,SAAS;AAG9B,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,mBAAmB;AAGvD,kBAAAC,QAAO,IAAI,OAAO,mBAAmB,OAAO,aAAa,EAAE,GAAG,eAAe,QAAQ,MAAM,CAAC;AAAA,EAChG;AAEA,SAAO,OAAO;AAClB;AAEO,MAAM,YAAY;AAAA,EACrB,YAAY,KAAoB;AAC5B,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,aAAO,MAAM;AAAA,IACjB;AAEA,WAAO,cAAc,cAAAA,QAAO,IAAI,OAAO,iBAAiB;AAGxD,QAAI,OAAO,gBAAgB,MAAM;AAC7B,qBAAe;AAAA,IACnB;AAAA,EACJ;AAAA,EAEA,MAAM,cAA4B;AAC9B,QAAI,OAAO,eAAe,MAAM;AAC5B,YAAM,eAAe;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAClB;AACJ;AAGA,IAAO,sBAAQ;",
|
|
6
|
+
"names": ["Api", "Cookie"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Api from "~/api";
|
|
2
|
+
import Cookie from "~/cookie";
|
|
3
|
+
const config = {
|
|
4
|
+
geolocation: null,
|
|
5
|
+
geolocationCookie: "_rebuyGeolocation",
|
|
6
|
+
geolocationDuration: {
|
|
7
|
+
minutes: 30
|
|
8
|
+
},
|
|
9
|
+
key: null
|
|
10
|
+
};
|
|
11
|
+
const getGeolocation = async () => {
|
|
12
|
+
const api = new Api(config.key);
|
|
13
|
+
const response = await api.callGeo("GET", "/", null);
|
|
14
|
+
if (response.data) {
|
|
15
|
+
config.geolocation = response.data;
|
|
16
|
+
const cookieOptions = {
|
|
17
|
+
secure: true
|
|
18
|
+
};
|
|
19
|
+
Object.assign(cookieOptions, config.geolocationDuration);
|
|
20
|
+
Cookie.set(config.geolocationCookie, config.geolocation, { ...cookieOptions, encode: false });
|
|
21
|
+
}
|
|
22
|
+
return config.geolocation;
|
|
23
|
+
};
|
|
24
|
+
class Geolocation {
|
|
25
|
+
constructor(key) {
|
|
26
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (typeof key == "string") {
|
|
30
|
+
config.key = key;
|
|
31
|
+
}
|
|
32
|
+
config.geolocation = Cookie.get(config.geolocationCookie);
|
|
33
|
+
if (config.geolocation === null) {
|
|
34
|
+
getGeolocation();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async geolocation() {
|
|
38
|
+
if (config.geolocation == null) {
|
|
39
|
+
await getGeolocation();
|
|
40
|
+
}
|
|
41
|
+
return config.geolocation;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
var geolocation_default = Geolocation;
|
|
45
|
+
export {
|
|
46
|
+
Geolocation,
|
|
47
|
+
geolocation_default as default
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=geolocation.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/geolocation.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Api from '~/api';\nimport Cookie from '~/cookie';\n\ntype Config = {\n geolocation: any;\n geolocationCookie: string;\n geolocationDuration: {\n minutes: number;\n };\n key: string | null;\n};\n\nconst config: Config = {\n geolocation: null,\n geolocationCookie: '_rebuyGeolocation',\n geolocationDuration: {\n minutes: 30,\n },\n key: null,\n};\n\nconst getGeolocation = async (): Promise<any> => {\n const api = new Api(config.key);\n const response = await api.callGeo('GET', '/', null);\n\n if (response.data) {\n // Update config with geolocation\n config.geolocation = response.data;\n\n // Write cookie with geolocation\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with geolocation config\n Object.assign(cookieOptions, config.geolocationDuration);\n\n // Write cookie with geolocation\n Cookie.set(config.geolocationCookie, config.geolocation, { ...cookieOptions, encode: false });\n }\n\n return config.geolocation;\n};\n\nexport class Geolocation {\n constructor(key: string | null) {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n config.key = key;\n }\n\n config.geolocation = Cookie.get(config.geolocationCookie);\n\n // Create a new geolocation (if needed)\n if (config.geolocation === null) {\n getGeolocation();\n }\n }\n\n async geolocation(): Promise<any> {\n if (config.geolocation == null) {\n await getGeolocation();\n }\n\n return config.geolocation;\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Geolocation;\n"],
|
|
5
|
+
"mappings": "AAEA,OAAO,SAAS;AAChB,OAAO,YAAY;AAWnB,MAAM,SAAiB;AAAA,EACnB,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,IACjB,SAAS;AAAA,EACb;AAAA,EACA,KAAK;AACT;AAEA,MAAM,iBAAiB,YAA0B;AAC7C,QAAM,MAAM,IAAI,IAAI,OAAO,GAAG;AAC9B,QAAM,WAAW,MAAM,IAAI,QAAQ,OAAO,KAAK,IAAI;AAEnD,MAAI,SAAS,MAAM;AAEf,WAAO,cAAc,SAAS;AAG9B,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,mBAAmB;AAGvD,WAAO,IAAI,OAAO,mBAAmB,OAAO,aAAa,EAAE,GAAG,eAAe,QAAQ,MAAM,CAAC;AAAA,EAChG;AAEA,SAAO,OAAO;AAClB;AAEO,MAAM,YAAY;AAAA,EACrB,YAAY,KAAoB;AAC5B,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,aAAO,MAAM;AAAA,IACjB;AAEA,WAAO,cAAc,OAAO,IAAI,OAAO,iBAAiB;AAGxD,QAAI,OAAO,gBAAgB,MAAM;AAC7B,qBAAe;AAAA,IACnB;AAAA,EACJ;AAAA,EAEA,MAAM,cAA4B;AAC9B,QAAI,OAAO,eAAe,MAAM;AAC5B,YAAM,eAAe;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAClB;AACJ;AAGA,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var identity_exports = {};
|
|
30
|
+
__export(identity_exports, {
|
|
31
|
+
Identity: () => Identity,
|
|
32
|
+
default: () => identity_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(identity_exports);
|
|
35
|
+
var import_cookie = __toESM(require("~/cookie"), 1);
|
|
36
|
+
var import_geolocation = __toESM(require("~/geolocation"), 1);
|
|
37
|
+
var import_session = __toESM(require("~/session"), 1);
|
|
38
|
+
var import_utilities = require("~/utilities");
|
|
39
|
+
const config = {
|
|
40
|
+
key: null,
|
|
41
|
+
session: null,
|
|
42
|
+
visitorDuration: {
|
|
43
|
+
years: 1
|
|
44
|
+
},
|
|
45
|
+
visitorId: null,
|
|
46
|
+
visitorIdCookie: "_rebuyVisitorId"
|
|
47
|
+
};
|
|
48
|
+
class Identity {
|
|
49
|
+
constructor(key) {
|
|
50
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (typeof key == "string") {
|
|
54
|
+
config.key = key;
|
|
55
|
+
}
|
|
56
|
+
config.visitorId = import_cookie.default.get(config.visitorIdCookie);
|
|
57
|
+
if (config.visitorId === null) {
|
|
58
|
+
config.visitorId = (0, import_utilities.uuid)();
|
|
59
|
+
}
|
|
60
|
+
const cookieOptions = {
|
|
61
|
+
secure: true
|
|
62
|
+
};
|
|
63
|
+
Object.assign(cookieOptions, config.visitorDuration);
|
|
64
|
+
import_cookie.default.set(config.visitorIdCookie, config.visitorId, cookieOptions);
|
|
65
|
+
config.session = new import_session.default();
|
|
66
|
+
config.geolocation = new import_geolocation.default(config.key);
|
|
67
|
+
}
|
|
68
|
+
visitorId() {
|
|
69
|
+
return config.visitorId;
|
|
70
|
+
}
|
|
71
|
+
sessionId() {
|
|
72
|
+
return config.session.sessionId();
|
|
73
|
+
}
|
|
74
|
+
sessionStart() {
|
|
75
|
+
return config.session.sessionStart();
|
|
76
|
+
}
|
|
77
|
+
sessionDuration() {
|
|
78
|
+
return config.session.sessionDuration();
|
|
79
|
+
}
|
|
80
|
+
async geolocation() {
|
|
81
|
+
return await config.geolocation.geolocation();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var identity_default = Identity;
|
|
85
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/identity.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Cookie from '~/cookie';\nimport Geolocation from '~/geolocation';\nimport Session from '~/session';\nimport { uuid } from '~/utilities';\n\ntype Config = {\n geolocation?: any;\n key: string | null;\n session: any;\n visitorDuration: {\n years: number;\n };\n visitorId: string | null;\n visitorIdCookie: string;\n};\n\nconst config: Config = {\n key: null,\n session: null,\n visitorDuration: {\n years: 1,\n },\n visitorId: null,\n visitorIdCookie: '_rebuyVisitorId',\n};\n\nexport class Identity {\n constructor(key: string | null) {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n config.key = key;\n }\n\n config.visitorId = Cookie.get(config.visitorIdCookie);\n\n // Create a new identifier (if needed)\n if (config.visitorId === null) {\n config.visitorId = uuid();\n }\n\n // Write cookie with visitor ID\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with visitor config\n Object.assign(cookieOptions, config.visitorDuration);\n\n // Write cookie with session ID\n Cookie.set(config.visitorIdCookie, config.visitorId, cookieOptions);\n\n // Create visitor session\n config.session = new Session();\n\n // Create visitor geolocation\n config.geolocation = new Geolocation(config.key);\n }\n\n visitorId(): string | null {\n return config.visitorId;\n }\n\n sessionId(): string {\n return config.session.sessionId();\n }\n\n sessionStart(): string {\n return config.session.sessionStart();\n }\n\n sessionDuration(): string {\n return config.session.sessionDuration();\n }\n\n async geolocation(): Promise<any> {\n return await config.geolocation.geolocation();\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Identity;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAmB;AACnB,yBAAwB;AACxB,qBAAoB;AACpB,uBAAqB;AAarB,MAAM,SAAiB;AAAA,EACnB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,iBAAiB;AAAA,IACb,OAAO;AAAA,EACX;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AACrB;AAEO,MAAM,SAAS;AAAA,EAClB,YAAY,KAAoB;AAC5B,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,aAAO,MAAM;AAAA,IACjB;AAEA,WAAO,YAAY,cAAAA,QAAO,IAAI,OAAO,eAAe;AAGpD,QAAI,OAAO,cAAc,MAAM;AAC3B,aAAO,gBAAY,uBAAK;AAAA,IAC5B;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,eAAe;AAGnD,kBAAAA,QAAO,IAAI,OAAO,iBAAiB,OAAO,WAAW,aAAa;AAGlE,WAAO,UAAU,IAAI,eAAAC,QAAQ;AAG7B,WAAO,cAAc,IAAI,mBAAAC,QAAY,OAAO,GAAG;AAAA,EACnD;AAAA,EAEA,YAA2B;AACvB,WAAO,OAAO;AAAA,EAClB;AAAA,EAEA,YAAoB;AAChB,WAAO,OAAO,QAAQ,UAAU;AAAA,EACpC;AAAA,EAEA,eAAuB;AACnB,WAAO,OAAO,QAAQ,aAAa;AAAA,EACvC;AAAA,EAEA,kBAA0B;AACtB,WAAO,OAAO,QAAQ,gBAAgB;AAAA,EAC1C;AAAA,EAEA,MAAM,cAA4B;AAC9B,WAAO,MAAM,OAAO,YAAY,YAAY;AAAA,EAChD;AACJ;AAGA,IAAO,mBAAQ;",
|
|
6
|
+
"names": ["Cookie", "Session", "Geolocation"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Cookie from "~/cookie";
|
|
2
|
+
import Geolocation from "~/geolocation";
|
|
3
|
+
import Session from "~/session";
|
|
4
|
+
import { uuid } from "~/utilities";
|
|
5
|
+
const config = {
|
|
6
|
+
key: null,
|
|
7
|
+
session: null,
|
|
8
|
+
visitorDuration: {
|
|
9
|
+
years: 1
|
|
10
|
+
},
|
|
11
|
+
visitorId: null,
|
|
12
|
+
visitorIdCookie: "_rebuyVisitorId"
|
|
13
|
+
};
|
|
14
|
+
class Identity {
|
|
15
|
+
constructor(key) {
|
|
16
|
+
if (typeof document == "undefined" || !document.cookie) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (typeof key == "string") {
|
|
20
|
+
config.key = key;
|
|
21
|
+
}
|
|
22
|
+
config.visitorId = Cookie.get(config.visitorIdCookie);
|
|
23
|
+
if (config.visitorId === null) {
|
|
24
|
+
config.visitorId = uuid();
|
|
25
|
+
}
|
|
26
|
+
const cookieOptions = {
|
|
27
|
+
secure: true
|
|
28
|
+
};
|
|
29
|
+
Object.assign(cookieOptions, config.visitorDuration);
|
|
30
|
+
Cookie.set(config.visitorIdCookie, config.visitorId, cookieOptions);
|
|
31
|
+
config.session = new Session();
|
|
32
|
+
config.geolocation = new Geolocation(config.key);
|
|
33
|
+
}
|
|
34
|
+
visitorId() {
|
|
35
|
+
return config.visitorId;
|
|
36
|
+
}
|
|
37
|
+
sessionId() {
|
|
38
|
+
return config.session.sessionId();
|
|
39
|
+
}
|
|
40
|
+
sessionStart() {
|
|
41
|
+
return config.session.sessionStart();
|
|
42
|
+
}
|
|
43
|
+
sessionDuration() {
|
|
44
|
+
return config.session.sessionDuration();
|
|
45
|
+
}
|
|
46
|
+
async geolocation() {
|
|
47
|
+
return await config.geolocation.geolocation();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var identity_default = Identity;
|
|
51
|
+
export {
|
|
52
|
+
Identity,
|
|
53
|
+
identity_default as default
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=identity.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/identity.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Cookie from '~/cookie';\nimport Geolocation from '~/geolocation';\nimport Session from '~/session';\nimport { uuid } from '~/utilities';\n\ntype Config = {\n geolocation?: any;\n key: string | null;\n session: any;\n visitorDuration: {\n years: number;\n };\n visitorId: string | null;\n visitorIdCookie: string;\n};\n\nconst config: Config = {\n key: null,\n session: null,\n visitorDuration: {\n years: 1,\n },\n visitorId: null,\n visitorIdCookie: '_rebuyVisitorId',\n};\n\nexport class Identity {\n constructor(key: string | null) {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n config.key = key;\n }\n\n config.visitorId = Cookie.get(config.visitorIdCookie);\n\n // Create a new identifier (if needed)\n if (config.visitorId === null) {\n config.visitorId = uuid();\n }\n\n // Write cookie with visitor ID\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with visitor config\n Object.assign(cookieOptions, config.visitorDuration);\n\n // Write cookie with session ID\n Cookie.set(config.visitorIdCookie, config.visitorId, cookieOptions);\n\n // Create visitor session\n config.session = new Session();\n\n // Create visitor geolocation\n config.geolocation = new Geolocation(config.key);\n }\n\n visitorId(): string | null {\n return config.visitorId;\n }\n\n sessionId(): string {\n return config.session.sessionId();\n }\n\n sessionStart(): string {\n return config.session.sessionStart();\n }\n\n sessionDuration(): string {\n return config.session.sessionDuration();\n }\n\n async geolocation(): Promise<any> {\n return await config.geolocation.geolocation();\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Identity;\n"],
|
|
5
|
+
"mappings": "AAEA,OAAO,YAAY;AACnB,OAAO,iBAAiB;AACxB,OAAO,aAAa;AACpB,SAAS,YAAY;AAarB,MAAM,SAAiB;AAAA,EACnB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,iBAAiB;AAAA,IACb,OAAO;AAAA,EACX;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AACrB;AAEO,MAAM,SAAS;AAAA,EAClB,YAAY,KAAoB;AAC5B,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,aAAO,MAAM;AAAA,IACjB;AAEA,WAAO,YAAY,OAAO,IAAI,OAAO,eAAe;AAGpD,QAAI,OAAO,cAAc,MAAM;AAC3B,aAAO,YAAY,KAAK;AAAA,IAC5B;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,eAAe;AAGnD,WAAO,IAAI,OAAO,iBAAiB,OAAO,WAAW,aAAa;AAGlE,WAAO,UAAU,IAAI,QAAQ;AAG7B,WAAO,cAAc,IAAI,YAAY,OAAO,GAAG;AAAA,EACnD;AAAA,EAEA,YAA2B;AACvB,WAAO,OAAO;AAAA,EAClB;AAAA,EAEA,YAAoB;AAChB,WAAO,OAAO,QAAQ,UAAU;AAAA,EACpC;AAAA,EAEA,eAAuB;AACnB,WAAO,OAAO,QAAQ,aAAa;AAAA,EACvC;AAAA,EAEA,kBAA0B;AACtB,WAAO,OAAO,QAAQ,gBAAgB;AAAA,EAC1C;AAAA,EAEA,MAAM,cAA4B;AAC9B,WAAO,MAAM,OAAO,YAAY,YAAY;AAAA,EAChD;AACJ;AAGA,IAAO,mBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|