@rebuy/rebuy 2.0.1-alpha.1 → 2.0.2-alpha.1
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/index.js +774 -8
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +767 -7
- package/dist/index.mjs.map +4 -4
- package/package.json +3 -4
- package/dist/api.js +0 -131
- package/dist/api.js.map +0 -7
- package/dist/api.mjs +0 -111
- package/dist/api.mjs.map +0 -7
- package/dist/client.js +0 -145
- package/dist/client.js.map +0 -7
- package/dist/client.mjs +0 -115
- package/dist/client.mjs.map +0 -7
- package/dist/cookie.js +0 -139
- package/dist/cookie.js.map +0 -7
- package/dist/cookie.mjs +0 -119
- package/dist/cookie.mjs.map +0 -7
- package/dist/geolocation.js +0 -79
- package/dist/geolocation.js.map +0 -7
- package/dist/geolocation.mjs +0 -49
- package/dist/geolocation.mjs.map +0 -7
- package/dist/identity.js +0 -86
- package/dist/identity.js.map +0 -7
- package/dist/identity.mjs +0 -56
- package/dist/identity.mjs.map +0 -7
- package/dist/session.js +0 -72
- package/dist/session.js.map +0 -7
- package/dist/session.mjs +0 -42
- package/dist/session.mjs.map +0 -7
- package/dist/utilities.js +0 -321
- package/dist/utilities.js.map +0 -7
- package/dist/utilities.mjs +0 -301
- package/dist/utilities.mjs.map +0 -7
package/dist/identity.js
DELETED
|
@@ -1,86 +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 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
|
-
class Identity {
|
|
40
|
-
constructor(key) {
|
|
41
|
-
this.config = {
|
|
42
|
-
geolocation: null,
|
|
43
|
-
key: null,
|
|
44
|
-
session: null,
|
|
45
|
-
visitorDuration: {
|
|
46
|
-
years: 1
|
|
47
|
-
},
|
|
48
|
-
visitorId: null,
|
|
49
|
-
visitorIdCookie: "_rebuyVisitorId"
|
|
50
|
-
};
|
|
51
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (typeof key == "string") {
|
|
55
|
-
this.config.key = key;
|
|
56
|
-
}
|
|
57
|
-
this.config.visitorId = import_cookie.default.get(this.config.visitorIdCookie);
|
|
58
|
-
if (this.config.visitorId === null) {
|
|
59
|
-
this.config.visitorId = (0, import_utilities.uuid)();
|
|
60
|
-
}
|
|
61
|
-
const cookieOptions = {
|
|
62
|
-
secure: true
|
|
63
|
-
};
|
|
64
|
-
Object.assign(cookieOptions, this.config.visitorDuration);
|
|
65
|
-
import_cookie.default.set(this.config.visitorIdCookie, this.config.visitorId, cookieOptions);
|
|
66
|
-
this.config.session = new import_session.default();
|
|
67
|
-
this.config.geolocation = new import_geolocation.default(this.config.key);
|
|
68
|
-
}
|
|
69
|
-
visitorId() {
|
|
70
|
-
return this.config.visitorId;
|
|
71
|
-
}
|
|
72
|
-
sessionId() {
|
|
73
|
-
return this.config.session ? this.config.session.sessionId() : null;
|
|
74
|
-
}
|
|
75
|
-
sessionStart() {
|
|
76
|
-
return this.config.session ? this.config.session.sessionStart() : null;
|
|
77
|
-
}
|
|
78
|
-
sessionDuration() {
|
|
79
|
-
return this.config.session ? this.config.session.sessionDuration() : null;
|
|
80
|
-
}
|
|
81
|
-
async geolocation() {
|
|
82
|
-
return this.config.geolocation ? await this.config.geolocation.geolocation() : null;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var identity_default = Identity;
|
|
86
|
-
//# sourceMappingURL=identity.js.map
|
package/dist/identity.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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\nexport class Identity {\n private config: Config;\n\n constructor(key: string | null) {\n this.config = {\n geolocation: null,\n key: null,\n session: null,\n visitorDuration: {\n years: 1,\n },\n visitorId: null,\n visitorIdCookie: '_rebuyVisitorId',\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.visitorId = Cookie.get(this.config.visitorIdCookie);\n\n // Create a new identifier (if needed)\n if (this.config.visitorId === null) {\n this.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, this.config.visitorDuration);\n\n // Write cookie with session ID\n Cookie.set(this.config.visitorIdCookie, this.config.visitorId, cookieOptions);\n\n // Create visitor session\n this.config.session = new Session();\n\n // Create visitor geolocation, passing the key\n this.config.geolocation = new Geolocation(this.config.key);\n }\n\n visitorId(): string | null {\n return this.config.visitorId;\n }\n\n sessionId(): string | null {\n return this.config.session ? this.config.session.sessionId() : null;\n }\n\n sessionStart(): string | null {\n return this.config.session ? this.config.session.sessionStart() : null;\n }\n\n sessionDuration(): string | null {\n return this.config.session ? this.config.session.sessionDuration() : null;\n }\n\n async geolocation(): Promise<any> {\n return this.config.geolocation ? await this.config.geolocation.geolocation() : null;\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;AAad,MAAM,SAAS;AAAA,EAGlB,YAAY,KAAoB;AAC5B,SAAK,SAAS;AAAA,MACV,aAAa;AAAA,MACb,KAAK;AAAA,MACL,SAAS;AAAA,MACT,iBAAiB;AAAA,QACb,OAAO;AAAA,MACX;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACrB;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,YAAY,cAAAA,QAAO,IAAI,KAAK,OAAO,eAAe;AAG9D,QAAI,KAAK,OAAO,cAAc,MAAM;AAChC,WAAK,OAAO,gBAAY,uBAAK;AAAA,IACjC;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,KAAK,OAAO,eAAe;AAGxD,kBAAAA,QAAO,IAAI,KAAK,OAAO,iBAAiB,KAAK,OAAO,WAAW,aAAa;AAG5E,SAAK,OAAO,UAAU,IAAI,eAAAC,QAAQ;AAGlC,SAAK,OAAO,cAAc,IAAI,mBAAAC,QAAY,KAAK,OAAO,GAAG;AAAA,EAC7D;AAAA,EAEA,YAA2B;AACvB,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,YAA2B;AACvB,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,UAAU,IAAI;AAAA,EACnE;AAAA,EAEA,eAA8B;AAC1B,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,aAAa,IAAI;AAAA,EACtE;AAAA,EAEA,kBAAiC;AAC7B,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,gBAAgB,IAAI;AAAA,EACzE;AAAA,EAEA,MAAM,cAA4B;AAC9B,WAAO,KAAK,OAAO,cAAc,MAAM,KAAK,OAAO,YAAY,YAAY,IAAI;AAAA,EACnF;AACJ;AAGA,IAAO,mBAAQ;",
|
|
6
|
-
"names": ["Cookie", "Session", "Geolocation"]
|
|
7
|
-
}
|
package/dist/identity.mjs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import Cookie from "./cookie";
|
|
2
|
-
import Geolocation from "./geolocation";
|
|
3
|
-
import Session from "./session";
|
|
4
|
-
import { uuid } from "./utilities";
|
|
5
|
-
class Identity {
|
|
6
|
-
constructor(key) {
|
|
7
|
-
this.config = {
|
|
8
|
-
geolocation: null,
|
|
9
|
-
key: null,
|
|
10
|
-
session: null,
|
|
11
|
-
visitorDuration: {
|
|
12
|
-
years: 1
|
|
13
|
-
},
|
|
14
|
-
visitorId: null,
|
|
15
|
-
visitorIdCookie: "_rebuyVisitorId"
|
|
16
|
-
};
|
|
17
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (typeof key == "string") {
|
|
21
|
-
this.config.key = key;
|
|
22
|
-
}
|
|
23
|
-
this.config.visitorId = Cookie.get(this.config.visitorIdCookie);
|
|
24
|
-
if (this.config.visitorId === null) {
|
|
25
|
-
this.config.visitorId = uuid();
|
|
26
|
-
}
|
|
27
|
-
const cookieOptions = {
|
|
28
|
-
secure: true
|
|
29
|
-
};
|
|
30
|
-
Object.assign(cookieOptions, this.config.visitorDuration);
|
|
31
|
-
Cookie.set(this.config.visitorIdCookie, this.config.visitorId, cookieOptions);
|
|
32
|
-
this.config.session = new Session();
|
|
33
|
-
this.config.geolocation = new Geolocation(this.config.key);
|
|
34
|
-
}
|
|
35
|
-
visitorId() {
|
|
36
|
-
return this.config.visitorId;
|
|
37
|
-
}
|
|
38
|
-
sessionId() {
|
|
39
|
-
return this.config.session ? this.config.session.sessionId() : null;
|
|
40
|
-
}
|
|
41
|
-
sessionStart() {
|
|
42
|
-
return this.config.session ? this.config.session.sessionStart() : null;
|
|
43
|
-
}
|
|
44
|
-
sessionDuration() {
|
|
45
|
-
return this.config.session ? this.config.session.sessionDuration() : null;
|
|
46
|
-
}
|
|
47
|
-
async geolocation() {
|
|
48
|
-
return this.config.geolocation ? await this.config.geolocation.geolocation() : null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
var identity_default = Identity;
|
|
52
|
-
export {
|
|
53
|
-
Identity,
|
|
54
|
-
identity_default as default
|
|
55
|
-
};
|
|
56
|
-
//# sourceMappingURL=identity.mjs.map
|
package/dist/identity.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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\nexport class Identity {\n private config: Config;\n\n constructor(key: string | null) {\n this.config = {\n geolocation: null,\n key: null,\n session: null,\n visitorDuration: {\n years: 1,\n },\n visitorId: null,\n visitorIdCookie: '_rebuyVisitorId',\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.visitorId = Cookie.get(this.config.visitorIdCookie);\n\n // Create a new identifier (if needed)\n if (this.config.visitorId === null) {\n this.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, this.config.visitorDuration);\n\n // Write cookie with session ID\n Cookie.set(this.config.visitorIdCookie, this.config.visitorId, cookieOptions);\n\n // Create visitor session\n this.config.session = new Session();\n\n // Create visitor geolocation, passing the key\n this.config.geolocation = new Geolocation(this.config.key);\n }\n\n visitorId(): string | null {\n return this.config.visitorId;\n }\n\n sessionId(): string | null {\n return this.config.session ? this.config.session.sessionId() : null;\n }\n\n sessionStart(): string | null {\n return this.config.session ? this.config.session.sessionStart() : null;\n }\n\n sessionDuration(): string | null {\n return this.config.session ? this.config.session.sessionDuration() : null;\n }\n\n async geolocation(): Promise<any> {\n return this.config.geolocation ? await this.config.geolocation.geolocation() : null;\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;AAad,MAAM,SAAS;AAAA,EAGlB,YAAY,KAAoB;AAC5B,SAAK,SAAS;AAAA,MACV,aAAa;AAAA,MACb,KAAK;AAAA,MACL,SAAS;AAAA,MACT,iBAAiB;AAAA,QACb,OAAO;AAAA,MACX;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACrB;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,YAAY,OAAO,IAAI,KAAK,OAAO,eAAe;AAG9D,QAAI,KAAK,OAAO,cAAc,MAAM;AAChC,WAAK,OAAO,YAAY,KAAK;AAAA,IACjC;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,KAAK,OAAO,eAAe;AAGxD,WAAO,IAAI,KAAK,OAAO,iBAAiB,KAAK,OAAO,WAAW,aAAa;AAG5E,SAAK,OAAO,UAAU,IAAI,QAAQ;AAGlC,SAAK,OAAO,cAAc,IAAI,YAAY,KAAK,OAAO,GAAG;AAAA,EAC7D;AAAA,EAEA,YAA2B;AACvB,WAAO,KAAK,OAAO;AAAA,EACvB;AAAA,EAEA,YAA2B;AACvB,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,UAAU,IAAI;AAAA,EACnE;AAAA,EAEA,eAA8B;AAC1B,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,aAAa,IAAI;AAAA,EACtE;AAAA,EAEA,kBAAiC;AAC7B,WAAO,KAAK,OAAO,UAAU,KAAK,OAAO,QAAQ,gBAAgB,IAAI;AAAA,EACzE;AAAA,EAEA,MAAM,cAA4B;AAC9B,WAAO,KAAK,OAAO,cAAc,MAAM,KAAK,OAAO,YAAY,YAAY,IAAI;AAAA,EACnF;AACJ;AAGA,IAAO,mBAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/session.js
DELETED
|
@@ -1,72 +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 session_exports = {};
|
|
30
|
-
__export(session_exports, {
|
|
31
|
-
Session: () => Session,
|
|
32
|
-
default: () => session_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(session_exports);
|
|
35
|
-
var import_cookie = __toESM(require("./cookie"), 1);
|
|
36
|
-
var import_utilities = require("./utilities");
|
|
37
|
-
const config = {
|
|
38
|
-
now: null,
|
|
39
|
-
sessionDuration: {
|
|
40
|
-
minutes: 30
|
|
41
|
-
},
|
|
42
|
-
sessionId: null,
|
|
43
|
-
sessionIdCookie: "_rebuySessionId"
|
|
44
|
-
};
|
|
45
|
-
class Session {
|
|
46
|
-
constructor() {
|
|
47
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
config.now = (/* @__PURE__ */ new Date()).getTime();
|
|
51
|
-
config.sessionId = import_cookie.default.get(config.sessionIdCookie);
|
|
52
|
-
if (config.sessionId === null) {
|
|
53
|
-
config.sessionId = (0, import_utilities.sessionId)();
|
|
54
|
-
}
|
|
55
|
-
const cookieOptions = {
|
|
56
|
-
secure: true
|
|
57
|
-
};
|
|
58
|
-
Object.assign(cookieOptions, config.sessionDuration);
|
|
59
|
-
import_cookie.default.set(config.sessionIdCookie, config.sessionId, cookieOptions);
|
|
60
|
-
}
|
|
61
|
-
sessionId() {
|
|
62
|
-
return config.sessionId;
|
|
63
|
-
}
|
|
64
|
-
sessionStart() {
|
|
65
|
-
return config.sessionId ? Number(config.sessionId.split(".")[1]) : 0;
|
|
66
|
-
}
|
|
67
|
-
sessionDuration() {
|
|
68
|
-
return config.now !== null ? parseInt(((config.now - this.sessionStart()) / 1e3 / 60).toString()) : 0;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
var session_default = Session;
|
|
72
|
-
//# sourceMappingURL=session.js.map
|
package/dist/session.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/session.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Cookie from '~/cookie';\nimport { sessionId } from '~/utilities';\n\ntype Config = {\n now: number | null;\n sessionDuration: {\n minutes: number;\n };\n sessionId: string | null;\n sessionIdCookie: string;\n};\n\nconst config: Config = {\n now: null,\n sessionDuration: {\n minutes: 30,\n },\n sessionId: null,\n sessionIdCookie: '_rebuySessionId',\n};\n\nexport class Session {\n constructor() {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n config.now = new Date().getTime();\n config.sessionId = Cookie.get(config.sessionIdCookie);\n\n // Create a new session (if needed)\n if (config.sessionId === null) {\n config.sessionId = sessionId();\n }\n\n // Write cookie with session ID\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with session config\n Object.assign(cookieOptions, config.sessionDuration);\n\n // Write cookie with session ID\n Cookie.set(config.sessionIdCookie, config.sessionId, cookieOptions);\n }\n\n sessionId(): string | null {\n return config.sessionId;\n }\n\n sessionStart(): number {\n return config.sessionId ? Number(config.sessionId.split('.')[1]) : 0;\n }\n\n sessionDuration(): number {\n return config.now !== null ? parseInt(((config.now - this.sessionStart()) / 1000 / 60).toString()) : 0;\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Session;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAmB;AACnB,uBAA0B;AAW1B,MAAM,SAAiB;AAAA,EACnB,KAAK;AAAA,EACL,iBAAiB;AAAA,IACb,SAAS;AAAA,EACb;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AACrB;AAEO,MAAM,QAAQ;AAAA,EACjB,cAAc;AACV,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,WAAO,OAAM,oBAAI,KAAK,GAAE,QAAQ;AAChC,WAAO,YAAY,cAAAA,QAAO,IAAI,OAAO,eAAe;AAGpD,QAAI,OAAO,cAAc,MAAM;AAC3B,aAAO,gBAAY,4BAAU;AAAA,IACjC;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,eAAe;AAGnD,kBAAAA,QAAO,IAAI,OAAO,iBAAiB,OAAO,WAAW,aAAa;AAAA,EACtE;AAAA,EAEA,YAA2B;AACvB,WAAO,OAAO;AAAA,EAClB;AAAA,EAEA,eAAuB;AACnB,WAAO,OAAO,YAAY,OAAO,OAAO,UAAU,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI;AAAA,EACvE;AAAA,EAEA,kBAA0B;AACtB,WAAO,OAAO,QAAQ,OAAO,WAAW,OAAO,MAAM,KAAK,aAAa,KAAK,MAAO,IAAI,SAAS,CAAC,IAAI;AAAA,EACzG;AACJ;AAGA,IAAO,kBAAQ;",
|
|
6
|
-
"names": ["Cookie"]
|
|
7
|
-
}
|
package/dist/session.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import Cookie from "./cookie";
|
|
2
|
-
import { sessionId } from "./utilities";
|
|
3
|
-
const config = {
|
|
4
|
-
now: null,
|
|
5
|
-
sessionDuration: {
|
|
6
|
-
minutes: 30
|
|
7
|
-
},
|
|
8
|
-
sessionId: null,
|
|
9
|
-
sessionIdCookie: "_rebuySessionId"
|
|
10
|
-
};
|
|
11
|
-
class Session {
|
|
12
|
-
constructor() {
|
|
13
|
-
if (typeof document == "undefined" || !document.cookie) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
config.now = (/* @__PURE__ */ new Date()).getTime();
|
|
17
|
-
config.sessionId = Cookie.get(config.sessionIdCookie);
|
|
18
|
-
if (config.sessionId === null) {
|
|
19
|
-
config.sessionId = sessionId();
|
|
20
|
-
}
|
|
21
|
-
const cookieOptions = {
|
|
22
|
-
secure: true
|
|
23
|
-
};
|
|
24
|
-
Object.assign(cookieOptions, config.sessionDuration);
|
|
25
|
-
Cookie.set(config.sessionIdCookie, config.sessionId, cookieOptions);
|
|
26
|
-
}
|
|
27
|
-
sessionId() {
|
|
28
|
-
return config.sessionId;
|
|
29
|
-
}
|
|
30
|
-
sessionStart() {
|
|
31
|
-
return config.sessionId ? Number(config.sessionId.split(".")[1]) : 0;
|
|
32
|
-
}
|
|
33
|
-
sessionDuration() {
|
|
34
|
-
return config.now !== null ? parseInt(((config.now - this.sessionStart()) / 1e3 / 60).toString()) : 0;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
var session_default = Session;
|
|
38
|
-
export {
|
|
39
|
-
Session,
|
|
40
|
-
session_default as default
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=session.mjs.map
|
package/dist/session.mjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/session.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport Cookie from '~/cookie';\nimport { sessionId } from '~/utilities';\n\ntype Config = {\n now: number | null;\n sessionDuration: {\n minutes: number;\n };\n sessionId: string | null;\n sessionIdCookie: string;\n};\n\nconst config: Config = {\n now: null,\n sessionDuration: {\n minutes: 30,\n },\n sessionId: null,\n sessionIdCookie: '_rebuySessionId',\n};\n\nexport class Session {\n constructor() {\n if (typeof document == 'undefined' || !document.cookie) {\n return;\n }\n\n config.now = new Date().getTime();\n config.sessionId = Cookie.get(config.sessionIdCookie);\n\n // Create a new session (if needed)\n if (config.sessionId === null) {\n config.sessionId = sessionId();\n }\n\n // Write cookie with session ID\n const cookieOptions: Record<string, any> = {\n secure: true,\n };\n\n // Merge cookie options with session config\n Object.assign(cookieOptions, config.sessionDuration);\n\n // Write cookie with session ID\n Cookie.set(config.sessionIdCookie, config.sessionId, cookieOptions);\n }\n\n sessionId(): string | null {\n return config.sessionId;\n }\n\n sessionStart(): number {\n return config.sessionId ? Number(config.sessionId.split('.')[1]) : 0;\n }\n\n sessionDuration(): number {\n return config.now !== null ? parseInt(((config.now - this.sessionStart()) / 1000 / 60).toString()) : 0;\n }\n}\n\n// eslint-disable-next-line import/no-default-export\nexport default Session;\n"],
|
|
5
|
-
"mappings": "AAEA,OAAO,YAAY;AACnB,SAAS,iBAAiB;AAW1B,MAAM,SAAiB;AAAA,EACnB,KAAK;AAAA,EACL,iBAAiB;AAAA,IACb,SAAS;AAAA,EACb;AAAA,EACA,WAAW;AAAA,EACX,iBAAiB;AACrB;AAEO,MAAM,QAAQ;AAAA,EACjB,cAAc;AACV,QAAI,OAAO,YAAY,eAAe,CAAC,SAAS,QAAQ;AACpD;AAAA,IACJ;AAEA,WAAO,OAAM,oBAAI,KAAK,GAAE,QAAQ;AAChC,WAAO,YAAY,OAAO,IAAI,OAAO,eAAe;AAGpD,QAAI,OAAO,cAAc,MAAM;AAC3B,aAAO,YAAY,UAAU;AAAA,IACjC;AAGA,UAAM,gBAAqC;AAAA,MACvC,QAAQ;AAAA,IACZ;AAGA,WAAO,OAAO,eAAe,OAAO,eAAe;AAGnD,WAAO,IAAI,OAAO,iBAAiB,OAAO,WAAW,aAAa;AAAA,EACtE;AAAA,EAEA,YAA2B;AACvB,WAAO,OAAO;AAAA,EAClB;AAAA,EAEA,eAAuB;AACnB,WAAO,OAAO,YAAY,OAAO,OAAO,UAAU,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI;AAAA,EACvE;AAAA,EAEA,kBAA0B;AACtB,WAAO,OAAO,QAAQ,OAAO,WAAW,OAAO,MAAM,KAAK,aAAa,KAAK,MAAO,IAAI,SAAS,CAAC,IAAI;AAAA,EACzG;AACJ;AAGA,IAAO,kBAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/utilities.js
DELETED
|
@@ -1,321 +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 utilities_exports = {};
|
|
20
|
-
__export(utilities_exports, {
|
|
21
|
-
amountToCents: () => amountToCents,
|
|
22
|
-
convertProductToStorefrontFormat: () => convertProductToStorefrontFormat,
|
|
23
|
-
convertToNodes: () => convertToNodes,
|
|
24
|
-
convertVariantToStorefrontFormat: () => convertVariantToStorefrontFormat,
|
|
25
|
-
dataToString: () => dataToString,
|
|
26
|
-
firstAvailableVariant: () => firstAvailableVariant,
|
|
27
|
-
getIdFromGraphUrl: () => getIdFromGraphUrl,
|
|
28
|
-
isBase64Encoded: () => isBase64Encoded,
|
|
29
|
-
productImageObject: () => productImageObject,
|
|
30
|
-
queryStringToObject: () => queryStringToObject,
|
|
31
|
-
selectedVariantOptions: () => selectedVariantOptions,
|
|
32
|
-
serialize: () => serialize,
|
|
33
|
-
sessionId: () => sessionId,
|
|
34
|
-
stringToData: () => stringToData,
|
|
35
|
-
stripHtml: () => stripHtml,
|
|
36
|
-
utmObjectFromString: () => utmObjectFromString,
|
|
37
|
-
uuid: () => uuid,
|
|
38
|
-
variantAvailable: () => variantAvailable,
|
|
39
|
-
variantMinMaxPriceObject: () => variantMinMaxPriceObject,
|
|
40
|
-
variantPriceObject: () => variantPriceObject
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(utilities_exports);
|
|
43
|
-
function isBase64Encoded(str) {
|
|
44
|
-
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
45
|
-
return base64Regex.test(str) ? true : false;
|
|
46
|
-
}
|
|
47
|
-
function stringToData(data, decode) {
|
|
48
|
-
let response = data;
|
|
49
|
-
if (decode === true) {
|
|
50
|
-
response = atob(response);
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
response = JSON.parse(response);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
response = data;
|
|
56
|
-
}
|
|
57
|
-
return response;
|
|
58
|
-
}
|
|
59
|
-
function dataToString(data, encode) {
|
|
60
|
-
let response = data;
|
|
61
|
-
if (typeof response != "string") {
|
|
62
|
-
response = JSON.stringify(response);
|
|
63
|
-
}
|
|
64
|
-
if (encode === true) {
|
|
65
|
-
response = btoa(response);
|
|
66
|
-
}
|
|
67
|
-
return response;
|
|
68
|
-
}
|
|
69
|
-
function stripHtml(str) {
|
|
70
|
-
return str?.replace(/<(.|\n)*?>/g, "") ?? "";
|
|
71
|
-
}
|
|
72
|
-
function getIdFromGraphUrl(graphId, objectType) {
|
|
73
|
-
let id = null;
|
|
74
|
-
const regex = new RegExp(`gid://shopify/${objectType}/(.*)`);
|
|
75
|
-
const matches = graphId.match(regex);
|
|
76
|
-
if (matches != null) {
|
|
77
|
-
const matchedId = matches[1];
|
|
78
|
-
if (!isNaN(Number(matchedId))) {
|
|
79
|
-
id = Number(matchedId);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return id;
|
|
83
|
-
}
|
|
84
|
-
function variantAvailable(variant) {
|
|
85
|
-
return !(variant.inventory_management && variant.inventory_policy === "deny" && variant.inventory_quantity <= 0);
|
|
86
|
-
}
|
|
87
|
-
function firstAvailableVariant(product) {
|
|
88
|
-
let selectedVariant = product.variants[0];
|
|
89
|
-
for (let i = 0; i < product.variants.length; i++) {
|
|
90
|
-
if (variantAvailable(product.variants[i])) {
|
|
91
|
-
selectedVariant = product.variants[i];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return selectedVariant;
|
|
96
|
-
}
|
|
97
|
-
function uuid() {
|
|
98
|
-
let d = (/* @__PURE__ */ new Date()).getTime();
|
|
99
|
-
let d2 = performance && performance.now && performance.now() * 1e3 || 0;
|
|
100
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
101
|
-
let r = Math.random() * 16;
|
|
102
|
-
if (d > 0) {
|
|
103
|
-
r = (d + r) % 16 | 0;
|
|
104
|
-
d = Math.floor(d / 16);
|
|
105
|
-
} else {
|
|
106
|
-
r = (d2 + r) % 16 | 0;
|
|
107
|
-
d2 = Math.floor(d2 / 16);
|
|
108
|
-
}
|
|
109
|
-
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function sessionId() {
|
|
113
|
-
const config = {
|
|
114
|
-
chars: "0123456789",
|
|
115
|
-
length: 12
|
|
116
|
-
};
|
|
117
|
-
let sessionId2 = "";
|
|
118
|
-
const sessionStart = (/* @__PURE__ */ new Date()).getTime();
|
|
119
|
-
for (let i = config.length; i > 0; i--) {
|
|
120
|
-
sessionId2 += config.chars[Math.floor(Math.random() * config.chars.length)];
|
|
121
|
-
}
|
|
122
|
-
return `REBUY.${sessionStart}.${sessionId2}`;
|
|
123
|
-
}
|
|
124
|
-
function convertProductToStorefrontFormat(product) {
|
|
125
|
-
const defaultVariant = firstAvailableVariant(product);
|
|
126
|
-
const minVariantPrice = variantMinMaxPriceObject(product, "price", "min");
|
|
127
|
-
const maxVariantPrice = variantMinMaxPriceObject(product, "price", "max");
|
|
128
|
-
const minVariantCompareAtPrice = variantMinMaxPriceObject(product, "compare_at_price", "min");
|
|
129
|
-
const maxVariantCompareAtPrice = variantMinMaxPriceObject(product, "compare_at_price", "max");
|
|
130
|
-
const selectedOptions = selectedVariantOptions(product, defaultVariant);
|
|
131
|
-
const variants = product.variants.map((variant) => convertVariantToStorefrontFormat(product, variant));
|
|
132
|
-
return {
|
|
133
|
-
collections: null,
|
|
134
|
-
compareAtPriceRange: {
|
|
135
|
-
maxVariantCompareAtPrice,
|
|
136
|
-
minVariantCompareAtPrice
|
|
137
|
-
},
|
|
138
|
-
description: stripHtml(product.body_html),
|
|
139
|
-
descriptionHtml: product.body_html,
|
|
140
|
-
featuredImage: productImageObject(product, null),
|
|
141
|
-
handle: product.handle,
|
|
142
|
-
id: `gid://shopify/Product/${product.id}`,
|
|
143
|
-
images: null,
|
|
144
|
-
media: [],
|
|
145
|
-
metafields: [],
|
|
146
|
-
options: [
|
|
147
|
-
...product.options.map((option) => {
|
|
148
|
-
return { name: option.name, values: option.values };
|
|
149
|
-
})
|
|
150
|
-
],
|
|
151
|
-
priceRange: {
|
|
152
|
-
maxVariantPrice,
|
|
153
|
-
minVariantPrice
|
|
154
|
-
},
|
|
155
|
-
selectedOptions,
|
|
156
|
-
selectedSellingPlan: null,
|
|
157
|
-
selectedSellingPlanAllocation: null,
|
|
158
|
-
sellingPlanGroups: [],
|
|
159
|
-
seo: { description: null, title: null },
|
|
160
|
-
title: product.title,
|
|
161
|
-
variants: convertToNodes(variants),
|
|
162
|
-
vendor: product.vendor
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function convertToNodes(arr) {
|
|
166
|
-
return {
|
|
167
|
-
edges: [
|
|
168
|
-
...arr.map((node) => {
|
|
169
|
-
return { node };
|
|
170
|
-
})
|
|
171
|
-
]
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function convertVariantToStorefrontFormat(product, variant) {
|
|
175
|
-
const selectedOptions = selectedVariantOptions(product, variant);
|
|
176
|
-
const image = productImageObject(product, variant.image_id);
|
|
177
|
-
return {
|
|
178
|
-
availableForSale: variantAvailable(variant),
|
|
179
|
-
compareAtPriceV2: variantPriceObject(variant, "compare_at_price"),
|
|
180
|
-
id: `gid://shopify/ProductVariant/${variant.id}`,
|
|
181
|
-
image,
|
|
182
|
-
priceV2: variantPriceObject(variant, "price"),
|
|
183
|
-
product: {
|
|
184
|
-
handle: product.handle,
|
|
185
|
-
id: product.id,
|
|
186
|
-
title: product.title,
|
|
187
|
-
vendor: product.vendor
|
|
188
|
-
},
|
|
189
|
-
selectedOptions: [selectedOptions],
|
|
190
|
-
sku: variant.sku,
|
|
191
|
-
title: variant.title
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function variantMinMaxPriceObject(product, key = "price", operator = "min") {
|
|
195
|
-
let priceObject = variantPriceObject(product.variants[0], key);
|
|
196
|
-
for (let i = 0; i < product.variants.length; i++) {
|
|
197
|
-
const variantPrice = variantPriceObject(product.variants[i], key);
|
|
198
|
-
if (variantPrice != null) {
|
|
199
|
-
const variantPriceAmount = Number(variantPrice.amount);
|
|
200
|
-
const currentPriceAmount = priceObject != null ? Number(priceObject.amount) : null;
|
|
201
|
-
if (currentPriceAmount == null || operator === "min" && variantPriceAmount < currentPriceAmount || operator === "max" && variantPriceAmount > currentPriceAmount) {
|
|
202
|
-
priceObject = variantPrice;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return priceObject;
|
|
207
|
-
}
|
|
208
|
-
function variantPriceObject(variant, key = "price") {
|
|
209
|
-
if (variant[key] != null) {
|
|
210
|
-
return {
|
|
211
|
-
amount: variant[key],
|
|
212
|
-
currencyCode: "USD"
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
function selectedVariantOptions(product, variant) {
|
|
218
|
-
const selectedOptions = {};
|
|
219
|
-
if (variant.option1 != null) {
|
|
220
|
-
selectedOptions[product.options[0].name] = variant.option1;
|
|
221
|
-
}
|
|
222
|
-
if (variant.option2 != null) {
|
|
223
|
-
selectedOptions[product.options[1].name] = variant.option2;
|
|
224
|
-
}
|
|
225
|
-
if (variant.option3 != null) {
|
|
226
|
-
selectedOptions[product.options[2].name] = variant.option3;
|
|
227
|
-
}
|
|
228
|
-
return selectedOptions;
|
|
229
|
-
}
|
|
230
|
-
function productImageObject(product, id) {
|
|
231
|
-
let image = null;
|
|
232
|
-
if (product.image) {
|
|
233
|
-
image = {
|
|
234
|
-
altText: product.image.alt,
|
|
235
|
-
height: product.image.height,
|
|
236
|
-
id: `gid://shopify/ProductImage/${product.image.id}`,
|
|
237
|
-
url: product.image.src,
|
|
238
|
-
width: product.image.width
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (product.images && product.images.length > 0 && id != null) {
|
|
242
|
-
const matchingImage = product.images.find((i) => i.id === id);
|
|
243
|
-
if (matchingImage) {
|
|
244
|
-
image = {
|
|
245
|
-
altText: matchingImage.alt,
|
|
246
|
-
height: matchingImage.height,
|
|
247
|
-
id: `gid://shopify/ProductImage/${matchingImage.id}`,
|
|
248
|
-
url: matchingImage.src,
|
|
249
|
-
width: matchingImage.width
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return image;
|
|
254
|
-
}
|
|
255
|
-
function queryStringToObject(str) {
|
|
256
|
-
const params = new URLSearchParams(str);
|
|
257
|
-
return Object.fromEntries(params.entries());
|
|
258
|
-
}
|
|
259
|
-
function utmObjectFromString(str) {
|
|
260
|
-
const utmKeys = ["utm_campaign", "utm_medium", "utm_source", "utm_term", "utm_content"];
|
|
261
|
-
const matches = {};
|
|
262
|
-
const url = new URL(str);
|
|
263
|
-
const queryObject = queryStringToObject(url.search);
|
|
264
|
-
for (const [key, value] of Object.entries(queryObject)) {
|
|
265
|
-
if (utmKeys.includes(key)) {
|
|
266
|
-
matches[key] = value;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return Object.keys(matches).length > 0 ? matches : null;
|
|
270
|
-
}
|
|
271
|
-
function amountToCents(amount) {
|
|
272
|
-
let normalizedAmount = 0;
|
|
273
|
-
if (typeof amount === "string") {
|
|
274
|
-
if (amount.indexOf(".") !== -1) {
|
|
275
|
-
normalizedAmount = Math.round(parseFloat(amount) * 100);
|
|
276
|
-
} else {
|
|
277
|
-
normalizedAmount = parseInt(amount, 10);
|
|
278
|
-
}
|
|
279
|
-
} else if (typeof amount === "number") {
|
|
280
|
-
normalizedAmount = Math.round(amount * 100);
|
|
281
|
-
}
|
|
282
|
-
if (isNaN(normalizedAmount)) {
|
|
283
|
-
normalizedAmount = 0;
|
|
284
|
-
}
|
|
285
|
-
return normalizedAmount;
|
|
286
|
-
}
|
|
287
|
-
function serialize(obj) {
|
|
288
|
-
const serialized = [];
|
|
289
|
-
const add = (key, value) => {
|
|
290
|
-
value = typeof value === "function" ? value() : value;
|
|
291
|
-
value = value === null ? "" : value === void 0 ? "" : value;
|
|
292
|
-
serialized[serialized.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
|
|
293
|
-
};
|
|
294
|
-
const buildParameters = (prefix, obj2) => {
|
|
295
|
-
let i, key, len;
|
|
296
|
-
if (prefix) {
|
|
297
|
-
if (Array.isArray(obj2)) {
|
|
298
|
-
for (i = 0, len = obj2.length; i < len; i++) {
|
|
299
|
-
buildParameters(prefix + "[" + (typeof obj2[i] === "object" && obj2[i] ? i : "") + "]", obj2[i]);
|
|
300
|
-
}
|
|
301
|
-
} else if (Object.prototype.toString.call(obj2) === "[object Object]") {
|
|
302
|
-
for (key in obj2) {
|
|
303
|
-
buildParameters(prefix + "[" + key + "]", obj2[key]);
|
|
304
|
-
}
|
|
305
|
-
} else {
|
|
306
|
-
add(prefix, obj2);
|
|
307
|
-
}
|
|
308
|
-
} else if (Array.isArray(obj2)) {
|
|
309
|
-
for (i = 0, len = obj2.length; i < len; i++) {
|
|
310
|
-
add(obj2[i].name, obj2[i].value);
|
|
311
|
-
}
|
|
312
|
-
} else {
|
|
313
|
-
for (key in obj2) {
|
|
314
|
-
buildParameters(key, obj2[key]);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return serialized;
|
|
318
|
-
};
|
|
319
|
-
return buildParameters("", obj).join("&");
|
|
320
|
-
}
|
|
321
|
-
//# sourceMappingURL=utilities.js.map
|