@rebuy/rebuy 2.0.1 → 2.0.2

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/client.mjs DELETED
@@ -1,115 +0,0 @@
1
- import Api from "./api";
2
- import Identity from "./identity";
3
- import { convertProductToStorefrontFormat } from "./utilities";
4
- const trackEvent = async (config, eventData) => {
5
- if (config.identity && config.identity.visitorId()) {
6
- eventData.uuid = config.identity.visitorId();
7
- }
8
- return await config.api.callEvent("POST", "/api/v1/analytics/event", eventData);
9
- };
10
- const makeShieldCall = async (config, endpoint, params, format, options = {}) => {
11
- return await makeCall(config, endpoint, params, format, { ...options, shield: true });
12
- };
13
- const makeStaticCall = async (config, endpoint, params, format, options = {}) => {
14
- return await makeCall(config, endpoint, params, format, { ...options, static: true });
15
- };
16
- const makeCDNCall = async (config, endpoint, params, format, options = {}) => {
17
- return await makeCall(config, endpoint, params, format, { ...options, cdn: true });
18
- };
19
- const makeCall = async (config, endpoint, params, format, options = {}) => {
20
- const query = {};
21
- if (config.defaultParameters != null) {
22
- Object.assign(query, config.defaultParameters);
23
- }
24
- if (config.contextParameters != null) {
25
- Object.assign(query, config.contextParameters);
26
- }
27
- if (typeof params == "object" && params != null) {
28
- Object.assign(query, params);
29
- }
30
- if (typeof options != "object" || options == null) {
31
- console.warn("Unsupported fetch options provided.", options);
32
- options = {};
33
- }
34
- if (config.identity && config.identity.visitorId()) {
35
- query.uuid = config.identity.visitorId();
36
- }
37
- const source = options.cdn ? "callCdn" : options.shield ? "callShield" : options.static ? "callStatic" : "callApi";
38
- const response = await config.api[source]("GET", endpoint, query, options);
39
- if (response.data && format === "storefront") {
40
- for (let i = 0; i < response.data.length; i++) {
41
- response.data[i] = convertProductToStorefrontFormat(response.data[i]);
42
- }
43
- }
44
- return response;
45
- };
46
- class RebuyClient {
47
- constructor(key, defaultParameters, shop) {
48
- this.config = {
49
- api: null,
50
- contextParameters: null,
51
- defaultParameters: null,
52
- identity: null,
53
- key: null,
54
- shop: null
55
- };
56
- if (typeof key == "string") {
57
- this.config.key = key;
58
- }
59
- if (typeof defaultParameters == "object" && defaultParameters != null) {
60
- this.config.defaultParameters = defaultParameters;
61
- }
62
- if (typeof shop == "string" && shop.endsWith(".myshopify.com")) {
63
- this.config.shop = shop;
64
- }
65
- this.config.api = new Api({ key: this.config.key, shop: this.config.shop });
66
- this.config.identity = new Identity(this.config.key);
67
- }
68
- setDefaultParameters(defaultParameters) {
69
- if (typeof defaultParameters == "object" && defaultParameters != null) {
70
- this.config.defaultParameters = defaultParameters;
71
- }
72
- }
73
- setContextParameters(contextParameters) {
74
- if (typeof contextParameters == "object" && contextParameters != null) {
75
- this.config.contextParameters = contextParameters;
76
- }
77
- }
78
- async getData(endpoint, params, options = {}) {
79
- return await makeCall(this.config, endpoint, params, null, options);
80
- }
81
- async getDataFromCDN(endpoint, params, options = {}) {
82
- return await makeCDNCall(this.config, endpoint, params, null, options);
83
- }
84
- async getShieldedAsset(endpoint, params, options = {}) {
85
- return await makeShieldCall(this.config, endpoint, params, null, options);
86
- }
87
- async getStaticAsset(endpoint, params, options = {}) {
88
- return await makeStaticCall(this.config, endpoint, params, null, options);
89
- }
90
- async getStorefrontData(endpoint, params, options = {}) {
91
- return await makeCall(this.config, endpoint, params, "storefront", options);
92
- }
93
- async trackProductViewed(data) {
94
- const requiredKeys = ["shopify_product_id", "shopify_product_handle"];
95
- const defaultData = {
96
- noun: "product",
97
- subject: "user",
98
- verb: "viewed"
99
- };
100
- if (typeof data != "undefined" && data != null) {
101
- const dataKeys = Object.keys(data);
102
- if (dataKeys.some((key) => requiredKeys.includes(key))) {
103
- const payload = Object.assign(data, defaultData);
104
- return await trackEvent(this.config, payload);
105
- }
106
- }
107
- return null;
108
- }
109
- }
110
- var client_default = RebuyClient;
111
- export {
112
- RebuyClient,
113
- client_default as default
114
- };
115
- //# sourceMappingURL=client.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/client.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Api from '~/api';\nimport Identity from '~/identity';\nimport { convertProductToStorefrontFormat } from '~/utilities';\n\ntype Config = {\n api: any;\n contextParameters: Record<string, any> | null;\n defaultParameters: Record<string, any> | null;\n identity: any;\n key: string | null;\n shop: string | null;\n};\n\nconst trackEvent = async (config: Config, eventData: Record<string, any>): Promise<any> => {\n if (config.identity && config.identity.visitorId()) {\n eventData.uuid = config.identity.visitorId();\n }\n\n return await config.api.callEvent('POST', '/api/v1/analytics/event', eventData);\n};\n\nconst makeShieldCall = async (\n config: Config,\n endpoint: string,\n params: Record<string, any>,\n format: string | null,\n options: Record<string, any> = {}\n): Promise<any> => {\n return await makeCall(config, endpoint, params, format, { ...options, shield: true });\n};\n\nconst makeStaticCall = async (\n config: Config,\n endpoint: string,\n params: Record<string, any>,\n format: string | null,\n options: Record<string, any> = {}\n): Promise<any> => {\n return await makeCall(config, endpoint, params, format, { ...options, static: true });\n};\n\nconst makeCDNCall = async (\n config: Config,\n endpoint: string,\n params: Record<string, any>,\n format: string | null,\n options: Record<string, any> = {}\n): Promise<any> => {\n return await makeCall(config, endpoint, params, format, { ...options, cdn: true });\n};\n\nconst makeCall = async (\n config: Config,\n endpoint: string,\n params: Record<string, any>,\n format: string | null,\n options: Record<string, any> = {}\n): Promise<any> => {\n const query: Record<string, any> = {};\n\n if (config.defaultParameters != null) {\n Object.assign(query, config.defaultParameters);\n }\n\n if (config.contextParameters != null) {\n Object.assign(query, config.contextParameters);\n }\n\n if (typeof params == 'object' && params != null) {\n Object.assign(query, params);\n }\n\n if (typeof options != 'object' || options == null) {\n console.warn('Unsupported fetch options provided.', options);\n options = {};\n }\n\n if (config.identity && config.identity.visitorId()) {\n query.uuid = config.identity.visitorId();\n }\n\n // Origin or dedicated edge?\n const source = options.cdn ? 'callCdn' : options.shield ? 'callShield' : options.static ? 'callStatic' : 'callApi';\n const response = await config.api[source]('GET', endpoint, query, options);\n\n if (response.data && format === 'storefront') {\n for (let i = 0; i < response.data.length; i++) {\n response.data[i] = convertProductToStorefrontFormat(response.data[i]);\n }\n }\n\n return response;\n};\n\nexport class RebuyClient {\n private config: Config;\n\n constructor(key: string, defaultParameters?: Record<string, any>, shop?: string) {\n this.config = {\n api: null,\n contextParameters: null,\n defaultParameters: null,\n identity: null,\n key: null,\n shop: null,\n };\n\n if (typeof key == 'string') {\n this.config.key = key;\n }\n\n if (typeof defaultParameters == 'object' && defaultParameters != null) {\n this.config.defaultParameters = defaultParameters;\n }\n\n if (typeof shop == 'string' && shop.endsWith('.myshopify.com')) {\n this.config.shop = shop;\n }\n\n this.config.api = new Api({ key: this.config.key, shop: this.config.shop });\n this.config.identity = new Identity(this.config.key);\n }\n\n setDefaultParameters(defaultParameters: Record<string, any>): void {\n if (typeof defaultParameters == 'object' && defaultParameters != null) {\n this.config.defaultParameters = defaultParameters;\n }\n }\n\n setContextParameters(contextParameters: Record<string, any>): void {\n if (typeof contextParameters == 'object' && contextParameters != null) {\n this.config.contextParameters = contextParameters;\n }\n }\n\n async getData(endpoint: string, params: Record<string, any>, options: Record<string, any> = {}): Promise<any> {\n return await makeCall(this.config, endpoint, params, null, options);\n }\n\n async getDataFromCDN(\n endpoint: string,\n params: Record<string, any>,\n options: Record<string, any> = {}\n ): Promise<any> {\n return await makeCDNCall(this.config, endpoint, params, null, options);\n }\n\n async getShieldedAsset(\n endpoint: string,\n params: Record<string, any>,\n options: Record<string, any> = {}\n ): Promise<any> {\n return await makeShieldCall(this.config, endpoint, params, null, options);\n }\n\n async getStaticAsset(\n endpoint: string,\n params: Record<string, any>,\n options: Record<string, any> = {}\n ): Promise<any> {\n return await makeStaticCall(this.config, endpoint, params, null, options);\n }\n\n async getStorefrontData(\n endpoint: string,\n params: Record<string, any>,\n options: Record<string, any> = {}\n ): Promise<any> {\n return await makeCall(this.config, endpoint, params, 'storefront', options);\n }\n\n async trackProductViewed(data: Record<string, any>): Promise<any> {\n const requiredKeys = ['shopify_product_id', 'shopify_product_handle'];\n\n const defaultData = {\n noun: 'product',\n subject: 'user',\n verb: 'viewed',\n };\n\n if (typeof data != 'undefined' && data != null) {\n const dataKeys = Object.keys(data);\n\n if (dataKeys.some((key) => requiredKeys.includes(key))) {\n const payload = Object.assign(data, defaultData);\n\n return await trackEvent(this.config, payload);\n }\n }\n\n return null;\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default RebuyClient;\n"],
5
- "mappings": "AAEA,OAAO,SAAS;AAChB,OAAO,cAAc;AACrB,SAAS,wCAAwC;AAWjD,MAAM,aAAa,OAAO,QAAgB,cAAiD;AACvF,MAAI,OAAO,YAAY,OAAO,SAAS,UAAU,GAAG;AAChD,cAAU,OAAO,OAAO,SAAS,UAAU;AAAA,EAC/C;AAEA,SAAO,MAAM,OAAO,IAAI,UAAU,QAAQ,2BAA2B,SAAS;AAClF;AAEA,MAAM,iBAAiB,OACnB,QACA,UACA,QACA,QACA,UAA+B,CAAC,MACjB;AACf,SAAO,MAAM,SAAS,QAAQ,UAAU,QAAQ,QAAQ,EAAE,GAAG,SAAS,QAAQ,KAAK,CAAC;AACxF;AAEA,MAAM,iBAAiB,OACnB,QACA,UACA,QACA,QACA,UAA+B,CAAC,MACjB;AACf,SAAO,MAAM,SAAS,QAAQ,UAAU,QAAQ,QAAQ,EAAE,GAAG,SAAS,QAAQ,KAAK,CAAC;AACxF;AAEA,MAAM,cAAc,OAChB,QACA,UACA,QACA,QACA,UAA+B,CAAC,MACjB;AACf,SAAO,MAAM,SAAS,QAAQ,UAAU,QAAQ,QAAQ,EAAE,GAAG,SAAS,KAAK,KAAK,CAAC;AACrF;AAEA,MAAM,WAAW,OACb,QACA,UACA,QACA,QACA,UAA+B,CAAC,MACjB;AACf,QAAM,QAA6B,CAAC;AAEpC,MAAI,OAAO,qBAAqB,MAAM;AAClC,WAAO,OAAO,OAAO,OAAO,iBAAiB;AAAA,EACjD;AAEA,MAAI,OAAO,qBAAqB,MAAM;AAClC,WAA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,aAAa,SAAS,GAAG,CAAC,GAAG;AACpD,cAAM,UAAU,OAAO,OAAO,MAAM,WAAW;AAE/C,eAAO,MAAM,WAAW,KAAK,QAAQ,OAAO;AAAA,MAChD;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;AAGA,IAAO,iBAAQ;",
6
- "names": []
7
- }
package/dist/cookie.js DELETED
@@ -1,139 +0,0 @@
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
@@ -1,7 +0,0 @@
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA4D;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,aAAS,kCAAgB,IAAI,IAAI,OAAO;AAG9C,gBAAQ,+BAAa,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,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,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 DELETED
@@ -1,119 +0,0 @@
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
@@ -1,7 +0,0 @@
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;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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
- }
@@ -1,79 +0,0 @@
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
- class Geolocation {
38
- constructor(key) {
39
- this.config = {
40
- geolocation: null,
41
- geolocationCookie: "_rebuyGeolocation",
42
- geolocationDuration: {
43
- minutes: 30
44
- },
45
- key: null
46
- };
47
- if (typeof document == "undefined" || !document.cookie) {
48
- return;
49
- }
50
- if (typeof key == "string") {
51
- this.config.key = key;
52
- }
53
- this.config.geolocation = import_cookie.default.get(this.config.geolocationCookie);
54
- if (this.config.geolocation === null) {
55
- this._fetchGeolocation();
56
- }
57
- }
58
- async _fetchGeolocation() {
59
- const api = new import_api.default({ key: this.config.key });
60
- const response = await api.callGeo("GET", "/", null);
61
- if (response.data) {
62
- this.config.geolocation = response.data;
63
- const cookieOptions = {
64
- secure: true
65
- };
66
- Object.assign(cookieOptions, this.config.geolocationDuration);
67
- import_cookie.default.set(this.config.geolocationCookie, this.config.geolocation, { ...cookieOptions, encode: false });
68
- }
69
- return this.config.geolocation;
70
- }
71
- async geolocation() {
72
- if (this.config.geolocation == null) {
73
- await this._fetchGeolocation();
74
- }
75
- return this.config.geolocation;
76
- }
77
- }
78
- var geolocation_default = Geolocation;
79
- //# sourceMappingURL=geolocation.js.map
@@ -1,7 +0,0 @@
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\nexport class Geolocation {\n private config: Config;\n\n constructor(key: string | null) {\n this.config = {\n geolocation: null,\n geolocationCookie: '_rebuyGeolocation',\n geolocationDuration: {\n minutes: 30,\n },\n key: null,\n };\n\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n this.config.key = key;\n }\n\n this.config.geolocation = Cookie.get(this.config.geolocationCookie);\n\n // Create a new geolocation (if needed)\n if (this.config.geolocation === null) {\n this._fetchGeolocation();\n }\n }\n\n async _fetchGeolocation(): Promise<any> {\n const api = new Api({ key: this.config.key });\n const response = await api.callGeo('GET', '/', null);\n\n if (response.data) {\n // Update instance config with geolocation\n this.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, this.config.geolocationDuration);\n\n // Write cookie with geolocation\n Cookie.set(this.config.geolocationCookie, this.config.geolocation, { ...cookieOptions, encode: false });\n }\n\n return this.config.geolocation;\n }\n\n async geolocation(): Promise<any> {\n if (this.config.geolocation == null) {\n await this._fetchGeolocation();\n }\n\n return this.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;AAWZ,MAAM,YAAY;AAAA,EAGrB,YAAY,KAAoB;AAC5B,SAAK,SAAS;AAAA,MACV,aAAa;AAAA,MACb,mBAAmB;AAAA,MACnB,qBAAqB;AAAA,QACjB,SAAS;AAAA,MACb;AAAA,MACA,KAAK;AAAA,IACT;AAEA,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,WAAK,OAAO,MAAM;AAAA,IACtB;AAEA,SAAK,OAAO,cAAc,cAAAA,QAAO,IAAI,KAAK,OAAO,iBAAiB;AAGlE,QAAI,KAAK,OAAO,gBAAgB,MAAM;AAClC,WAAK,kBAAkB;AAAA,IAC3B;AAAA,EACJ;AAAA,EAEA,MAAM,oBAAkC;AACpC,UAAM,MAAM,IAAI,WAAAC,QAAI,EAAE,KAAK,KAAK,OAAO,IAAI,CAAC;AAC5C,UAAM,WAAW,MAAM,IAAI,QAAQ,OAAO,KAAK,IAAI;AAEnD,QAAI,SAAS,MAAM;AAEf,WAAK,OAAO,cAAc,SAAS;AAGnC,YAAM,gBAAqC;AAAA,QACvC,QAAQ;AAAA,MACZ;AAGA,aAAO,OAAO,eAAe,KAAK,OAAO,mBAAmB;AAG5D,oBAAAD,QAAO,IAAI,KAAK,OAAO,mBAAmB,KAAK,OAAO,aAAa,EAAE,GAAG,eAAe,QAAQ,MAAM,CAAC;AAAA,IAC1G;AAEA,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,MAAM,cAA4B;AAC9B,QAAI,KAAK,OAAO,eAAe,MAAM;AACjC,YAAM,KAAK,kBAAkB;AAAA,IACjC;AAEA,WAAO,KAAK,OAAO;AAAA,EACvB;AACJ;AAGA,IAAO,sBAAQ;",
6
- "names": ["Cookie", "Api"]
7
- }
@@ -1,49 +0,0 @@
1
- import Api from "./api";
2
- import Cookie from "./cookie";
3
- class Geolocation {
4
- constructor(key) {
5
- this.config = {
6
- geolocation: null,
7
- geolocationCookie: "_rebuyGeolocation",
8
- geolocationDuration: {
9
- minutes: 30
10
- },
11
- key: null
12
- };
13
- if (typeof document == "undefined" || !document.cookie) {
14
- return;
15
- }
16
- if (typeof key == "string") {
17
- this.config.key = key;
18
- }
19
- this.config.geolocation = Cookie.get(this.config.geolocationCookie);
20
- if (this.config.geolocation === null) {
21
- this._fetchGeolocation();
22
- }
23
- }
24
- async _fetchGeolocation() {
25
- const api = new Api({ key: this.config.key });
26
- const response = await api.callGeo("GET", "/", null);
27
- if (response.data) {
28
- this.config.geolocation = response.data;
29
- const cookieOptions = {
30
- secure: true
31
- };
32
- Object.assign(cookieOptions, this.config.geolocationDuration);
33
- Cookie.set(this.config.geolocationCookie, this.config.geolocation, { ...cookieOptions, encode: false });
34
- }
35
- return this.config.geolocation;
36
- }
37
- async geolocation() {
38
- if (this.config.geolocation == null) {
39
- await this._fetchGeolocation();
40
- }
41
- return this.config.geolocation;
42
- }
43
- }
44
- var geolocation_default = Geolocation;
45
- export {
46
- Geolocation,
47
- geolocation_default as default
48
- };
49
- //# sourceMappingURL=geolocation.mjs.map
@@ -1,7 +0,0 @@
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\nexport class Geolocation {\n private config: Config;\n\n constructor(key: string | null) {\n this.config = {\n geolocation: null,\n geolocationCookie: '_rebuyGeolocation',\n geolocationDuration: {\n minutes: 30,\n },\n key: null,\n };\n\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n if (typeof key == 'string') {\n this.config.key = key;\n }\n\n this.config.geolocation = Cookie.get(this.config.geolocationCookie);\n\n // Create a new geolocation (if needed)\n if (this.config.geolocation === null) {\n this._fetchGeolocation();\n }\n }\n\n async _fetchGeolocation(): Promise<any> {\n const api = new Api({ key: this.config.key });\n const response = await api.callGeo('GET', '/', null);\n\n if (response.data) {\n // Update instance config with geolocation\n this.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, this.config.geolocationDuration);\n\n // Write cookie with geolocation\n Cookie.set(this.config.geolocationCookie, this.config.geolocation, { ...cookieOptions, encode: false });\n }\n\n return this.config.geolocation;\n }\n\n async geolocation(): Promise<any> {\n if (this.config.geolocation == null) {\n await this._fetchGeolocation();\n }\n\n return this.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;AAWZ,MAAM,YAAY;AAAA,EAGrB,YAAY,KAAoB;AAC5B,SAAK,SAAS;AAAA,MACV,aAAa;AAAA,MACb,mBAAmB;AAAA,MACnB,qBAAqB;AAAA,QACjB,SAAS;AAAA,MACb;AAAA,MACA,KAAK;AAAA,IACT;AAEA,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,QAAI,OAAO,OAAO,UAAU;AACxB,WAAK,OAAO,MAAM;AAAA,IACtB;AAEA,SAAK,OAAO,cAAc,OAAO,IAAI,KAAK,OAAO,iBAAiB;AAGlE,QAAI,KAAK,OAAO,gBAAgB,MAAM;AAClC,WAAK,kBAAkB;AAAA,IAC3B;AAAA,EACJ;AAAA,EAEA,MAAM,oBAAkC;AACpC,UAAM,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,OAAO,IAAI,CAAC;AAC5C,UAAM,WAAW,MAAM,IAAI,QAAQ,OAAO,KAAK,IAAI;AAEnD,QAAI,SAAS,MAAM;AAEf,WAAK,OAAO,cAAc,SAAS;AAGnC,YAAM,gBAAqC;AAAA,QACvC,QAAQ;AAAA,MACZ;AAGA,aAAO,OAAO,eAAe,KAAK,OAAO,mBAAmB;AAG5D,aAAO,IAAI,KAAK,OAAO,mBAAmB,KAAK,OAAO,aAAa,EAAE,GAAG,eAAe,QAAQ,MAAM,CAAC;AAAA,IAC1G;AAEA,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,MAAM,cAA4B;AAC9B,QAAI,KAAK,OAAO,eAAe,MAAM;AACjC,YAAM,KAAK,kBAAkB;AAAA,IACjC;AAEA,WAAO,KAAK,OAAO;AAAA,EACvB;AACJ;AAGA,IAAO,sBAAQ;",
6
- "names": []
7
- }