ec4w_validator 0.0.1001111223 → 0.0.1001111224
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/README.Docker.md +0 -0
- package/dist/index.js +157 -111
- package/dist/index.umd.cjs +285 -1
- package/dist/vite.svg +0 -0
- package/package.json +34 -35
- package/dist/index.d.ts +0 -1
package/README.Docker.md
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -1,183 +1,226 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function _toJSON(target) {
|
|
2
|
+
const jsonObj = { ...target };
|
|
3
|
+
const proto = Object.getPrototypeOf(target);
|
|
4
|
+
Object.entries(Object.getOwnPropertyDescriptors(proto)).forEach(([key, descriptor]) => {
|
|
5
|
+
if (typeof descriptor.get === "function") {
|
|
6
|
+
jsonObj[key] = target[key];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
return jsonObj;
|
|
6
10
|
}
|
|
7
|
-
class
|
|
11
|
+
class EC4W_Validator {
|
|
8
12
|
/** @type {SentRequest[]} */
|
|
9
|
-
#
|
|
13
|
+
#requestList = [];
|
|
10
14
|
/** @param {SentRequest[]} requestList */
|
|
11
|
-
constructor(
|
|
12
|
-
this.#
|
|
15
|
+
constructor(requestList) {
|
|
16
|
+
this.#requestList = requestList;
|
|
13
17
|
}
|
|
14
18
|
/** @returns {EC4W_Result} */
|
|
15
19
|
conclude() {
|
|
16
|
-
const
|
|
17
|
-
for (const
|
|
18
|
-
if (!
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
const sentRequests = [];
|
|
21
|
+
for (const request of this.#requestList) {
|
|
22
|
+
if (!request.url) continue;
|
|
23
|
+
const Url = new URL(request.url);
|
|
24
|
+
if (UPDE_Request.canBe(request.method, Url)) {
|
|
25
|
+
sentRequests.push(new UPDE_Request(request.method, Url));
|
|
26
|
+
} else if (Conversion_Request.canBe(request.method, Url)) {
|
|
27
|
+
sentRequests.push(new Conversion_Request(request.method, Url));
|
|
28
|
+
} else ;
|
|
21
29
|
}
|
|
22
|
-
if (
|
|
23
|
-
const
|
|
30
|
+
if (sentRequests.length < 1) throw new Error("no ( sentRequest ) detected");
|
|
31
|
+
const EC4W_list = [];
|
|
24
32
|
{
|
|
25
|
-
let
|
|
26
|
-
for (const
|
|
27
|
-
|
|
33
|
+
let lastUPDE = null;
|
|
34
|
+
for (const ping of sentRequests) {
|
|
35
|
+
if (ping instanceof UPDE_Request) {
|
|
36
|
+
lastUPDE = ping;
|
|
37
|
+
} else if (ping instanceof Conversion_Request) {
|
|
38
|
+
EC4W_list.push(new EC4W_Request(lastUPDE, ping));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
28
41
|
}
|
|
29
|
-
if (
|
|
30
|
-
return new
|
|
42
|
+
if (EC4W_list.length < 1) throw new Error("no ( UPDE | EC4w ) requests detected");
|
|
43
|
+
return new EC4W_Result(EC4W_list);
|
|
31
44
|
}
|
|
32
45
|
/** @param {string} em */
|
|
33
|
-
static emIsValid(
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
static emIsValid(em) {
|
|
47
|
+
if (!em) return false;
|
|
48
|
+
if (em.startsWith("tv.1") === false) return false;
|
|
49
|
+
if (em === "tv.1") return false;
|
|
50
|
+
if (/^tv\.1~e[0-9]/.test(em)) return false;
|
|
51
|
+
const part = em.split("~");
|
|
52
|
+
const len = part.length;
|
|
53
|
+
if (len < 2) return false;
|
|
54
|
+
for (let i = 1; i < len; ++i) {
|
|
55
|
+
if (part[i] === "") return false;
|
|
56
|
+
const [key, value] = part[i].split(".");
|
|
57
|
+
if (!key) return false;
|
|
58
|
+
if (!value) return false;
|
|
41
59
|
}
|
|
42
|
-
return
|
|
60
|
+
return true;
|
|
43
61
|
}
|
|
44
62
|
toJSON() {
|
|
45
|
-
return
|
|
63
|
+
return _toJSON(this);
|
|
46
64
|
}
|
|
47
65
|
}
|
|
48
|
-
const
|
|
66
|
+
const EC4W_ValidMessages = Object.freeze({
|
|
49
67
|
em_validInConversion: "valid `em` in Conversion payload",
|
|
50
68
|
em_validInUPDE: "valid `em` in UPDE payload"
|
|
51
|
-
})
|
|
69
|
+
});
|
|
70
|
+
const EC4W_ErrorMessages = Object.freeze({
|
|
52
71
|
em_invalidInConversion: "invalid `em` in Conversion payload",
|
|
53
72
|
em_invalidInUPDE: "invalid `em` in UPDE payload",
|
|
54
73
|
ecsid_mismatch: "mismatch `ecsid` between UPDE and Conversion payload",
|
|
55
74
|
conversionId_mismatch: "mismatch `Conversion ID` between UPDE and Conversion payload",
|
|
56
75
|
noEC4W_request: "no valid EC4W requests detected at all"
|
|
57
76
|
});
|
|
58
|
-
class
|
|
59
|
-
#
|
|
60
|
-
#
|
|
77
|
+
class EC4W_Request {
|
|
78
|
+
#UPDE_Request = null;
|
|
79
|
+
#Conversion_Request;
|
|
61
80
|
/**
|
|
62
81
|
* @param {UPDE_Request?} UPDE_Request
|
|
63
82
|
* @param {Conversion_Request} Conversion_Request */
|
|
64
|
-
constructor(
|
|
65
|
-
this.#
|
|
83
|
+
constructor(UPDE_Request2, Conversion_Request2) {
|
|
84
|
+
this.#UPDE_Request = UPDE_Request2;
|
|
85
|
+
this.#Conversion_Request = Conversion_Request2;
|
|
66
86
|
}
|
|
67
87
|
get result() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (this.#
|
|
77
|
-
|
|
78
|
-
return t ? new i(t, a.em_validInConversion) : new i(t, o.em_invalidInConversion);
|
|
88
|
+
if (!this.#UPDE_Request && !this.#Conversion_Request)
|
|
89
|
+
return new Result(false, EC4W_ErrorMessages.noEC4W_request);
|
|
90
|
+
if (this.#ecsidIsValid() === false)
|
|
91
|
+
return new Result(false, EC4W_ErrorMessages.ecsid_mismatch);
|
|
92
|
+
return this.#emIsValid();
|
|
93
|
+
}
|
|
94
|
+
#ecsidIsValid() {
|
|
95
|
+
if (this.#Conversion_Request === null) return false;
|
|
96
|
+
if (this.#UPDE_Request === null) {
|
|
97
|
+
return true;
|
|
79
98
|
}
|
|
80
|
-
if (this.#
|
|
81
|
-
|
|
82
|
-
|
|
99
|
+
if (!this.#UPDE_Request.ecsid) return false;
|
|
100
|
+
if (!this.#Conversion_Request.ecsid) return false;
|
|
101
|
+
if (this.#UPDE_Request.ecsid !== this.#Conversion_Request.ecsid) return false;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
#emIsValid() {
|
|
105
|
+
if (this.#Conversion_Request === null)
|
|
106
|
+
return new Result(false, EC4W_ErrorMessages.em_invalidInConversion);
|
|
107
|
+
if (this.#UPDE_Request === null) {
|
|
108
|
+
const isValid2 = this.#Conversion_Request.emIsValid();
|
|
109
|
+
if (isValid2) return new Result(isValid2, EC4W_ValidMessages.em_validInConversion);
|
|
110
|
+
else return new Result(isValid2, EC4W_ErrorMessages.em_invalidInConversion);
|
|
83
111
|
}
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
if (this.#Conversion_Request.em === null) {
|
|
113
|
+
const isValid2 = this.#UPDE_Request.emIsValid();
|
|
114
|
+
if (isValid2) return new Result(isValid2, EC4W_ValidMessages.em_validInUPDE);
|
|
115
|
+
else return new Result(isValid2, EC4W_ErrorMessages.em_invalidInUPDE);
|
|
116
|
+
}
|
|
117
|
+
const isValid = this.#Conversion_Request.emIsValid();
|
|
118
|
+
if (isValid) return new Result(isValid, EC4W_ValidMessages.em_validInConversion);
|
|
119
|
+
else return new Result(isValid, EC4W_ErrorMessages.em_invalidInConversion);
|
|
86
120
|
}
|
|
87
121
|
toJSON() {
|
|
88
|
-
return
|
|
122
|
+
return _toJSON(this);
|
|
89
123
|
}
|
|
90
124
|
}
|
|
91
|
-
class
|
|
92
|
-
#
|
|
125
|
+
class Result {
|
|
126
|
+
#isGood;
|
|
93
127
|
get isGood() {
|
|
94
|
-
return this.#
|
|
128
|
+
return this.#isGood;
|
|
95
129
|
}
|
|
96
|
-
#
|
|
130
|
+
#message;
|
|
97
131
|
get message() {
|
|
98
|
-
return this.#
|
|
132
|
+
return this.#message;
|
|
99
133
|
}
|
|
100
134
|
/** @param {boolean} isGood
|
|
101
135
|
* @param {string} message */
|
|
102
|
-
constructor(
|
|
103
|
-
this.#
|
|
136
|
+
constructor(isGood, message) {
|
|
137
|
+
this.#isGood = isGood;
|
|
138
|
+
this.#message = message;
|
|
104
139
|
}
|
|
105
140
|
toJSON() {
|
|
106
141
|
return {
|
|
107
|
-
isGood: this.#
|
|
108
|
-
message: this.#
|
|
142
|
+
isGood: this.#isGood,
|
|
143
|
+
message: this.#message
|
|
109
144
|
};
|
|
110
145
|
}
|
|
111
146
|
}
|
|
112
|
-
class
|
|
147
|
+
class UPDE_Request {
|
|
113
148
|
/**
|
|
114
149
|
* @param {string} method
|
|
115
150
|
* @param {URL} Url */
|
|
116
|
-
static canBe(
|
|
117
|
-
|
|
151
|
+
static canBe(method, Url) {
|
|
152
|
+
if (method !== "GET") return false;
|
|
153
|
+
if (false === Url.toString().startsWith("https://www.google.com/ccm/form-data/")) return false;
|
|
154
|
+
if (Url.searchParams.get("em") === null) return false;
|
|
155
|
+
return true;
|
|
118
156
|
}
|
|
119
|
-
#
|
|
157
|
+
#method;
|
|
120
158
|
get method() {
|
|
121
|
-
return this.#
|
|
159
|
+
return this.#method;
|
|
122
160
|
}
|
|
123
|
-
#
|
|
161
|
+
#Url;
|
|
124
162
|
get url() {
|
|
125
|
-
return this.#
|
|
163
|
+
return this.#Url.toString();
|
|
126
164
|
}
|
|
127
165
|
/**
|
|
128
166
|
* @param {string} method
|
|
129
167
|
* @param {URL} Url */
|
|
130
|
-
constructor(
|
|
131
|
-
this.#
|
|
168
|
+
constructor(method, Url) {
|
|
169
|
+
this.#method = method;
|
|
170
|
+
this.#Url = Url;
|
|
132
171
|
}
|
|
133
172
|
get em() {
|
|
134
|
-
return this.#
|
|
173
|
+
return this.#Url.searchParams.get("em");
|
|
135
174
|
}
|
|
136
175
|
get ecsid() {
|
|
137
|
-
return this.#
|
|
176
|
+
return this.#Url.searchParams.get("ecsid");
|
|
138
177
|
}
|
|
139
178
|
emIsValid() {
|
|
140
|
-
return
|
|
179
|
+
return EC4W_Validator.emIsValid(this.em);
|
|
141
180
|
}
|
|
142
181
|
toJSON() {
|
|
143
|
-
return
|
|
182
|
+
return _toJSON(this);
|
|
144
183
|
}
|
|
145
184
|
}
|
|
146
|
-
class
|
|
185
|
+
class Conversion_Request {
|
|
147
186
|
/**
|
|
148
187
|
* @param {string} method
|
|
149
188
|
* @param {URL} Url */
|
|
150
|
-
static canBe(
|
|
151
|
-
|
|
189
|
+
static canBe(method, Url) {
|
|
190
|
+
if (method !== "GET") return false;
|
|
191
|
+
if (false === Url.toString().startsWith("https://www.googleadservices.com/ccm/conversion/")) return false;
|
|
192
|
+
if (Url.searchParams.get("label") === null) return false;
|
|
193
|
+
return true;
|
|
152
194
|
}
|
|
153
|
-
#
|
|
195
|
+
#method;
|
|
154
196
|
get method() {
|
|
155
|
-
return this.#
|
|
197
|
+
return this.#method;
|
|
156
198
|
}
|
|
157
|
-
#
|
|
199
|
+
#Url;
|
|
158
200
|
get url() {
|
|
159
|
-
return this.#
|
|
201
|
+
return this.#Url.toString();
|
|
160
202
|
}
|
|
161
203
|
/**
|
|
162
204
|
* @param {string} method
|
|
163
205
|
* @param {URL} Url */
|
|
164
|
-
constructor(
|
|
165
|
-
this.#
|
|
206
|
+
constructor(method, Url) {
|
|
207
|
+
this.#method = method;
|
|
208
|
+
this.#Url = Url;
|
|
166
209
|
}
|
|
167
210
|
get em() {
|
|
168
|
-
return this.#
|
|
211
|
+
return this.#Url.searchParams.get("em");
|
|
169
212
|
}
|
|
170
213
|
get ecsid() {
|
|
171
|
-
return this.#
|
|
214
|
+
return this.#Url.searchParams.get("ecsid");
|
|
172
215
|
}
|
|
173
216
|
emIsValid() {
|
|
174
|
-
return
|
|
217
|
+
return EC4W_Validator.emIsValid(this.em);
|
|
175
218
|
}
|
|
176
219
|
toJSON() {
|
|
177
|
-
return
|
|
220
|
+
return _toJSON(this);
|
|
178
221
|
}
|
|
179
222
|
}
|
|
180
|
-
class
|
|
223
|
+
class EC4W_Result {
|
|
181
224
|
/** @type {EC4W_Request[]} */
|
|
182
225
|
EC4W_Requests = [];
|
|
183
226
|
// errors = [];
|
|
@@ -185,18 +228,20 @@ class g {
|
|
|
185
228
|
/**
|
|
186
229
|
* @param {EC4W_Request[]} EC4W_Requests
|
|
187
230
|
* */
|
|
188
|
-
constructor(
|
|
189
|
-
if (!
|
|
190
|
-
this.EC4W_Requests =
|
|
231
|
+
constructor(EC4W_Requests) {
|
|
232
|
+
if (!EC4W_Requests || EC4W_Requests.length < 1) throw new Error("no requests detected");
|
|
233
|
+
this.EC4W_Requests = EC4W_Requests;
|
|
191
234
|
}
|
|
192
235
|
get invalidRequest() {
|
|
193
|
-
for (const
|
|
194
|
-
if (
|
|
236
|
+
for (const EC4W_Request2 of this.EC4W_Requests) {
|
|
237
|
+
if (EC4W_Request2.result.isGood === false) return EC4W_Request2;
|
|
238
|
+
}
|
|
195
239
|
return null;
|
|
196
240
|
}
|
|
197
241
|
get validRequest() {
|
|
198
|
-
for (const
|
|
199
|
-
if (
|
|
242
|
+
for (const EC4W_Request2 of this.EC4W_Requests) {
|
|
243
|
+
if (EC4W_Request2.result.isGood) return EC4W_Request2;
|
|
244
|
+
}
|
|
200
245
|
return null;
|
|
201
246
|
}
|
|
202
247
|
// get summary() {
|
|
@@ -210,26 +255,27 @@ class g {
|
|
|
210
255
|
// return summary;
|
|
211
256
|
// }
|
|
212
257
|
toJSON() {
|
|
213
|
-
return
|
|
258
|
+
return _toJSON(this);
|
|
214
259
|
}
|
|
215
260
|
}
|
|
216
|
-
class
|
|
261
|
+
class SentRequest {
|
|
217
262
|
url = "https://";
|
|
218
263
|
method = "GET";
|
|
219
|
-
constructor(
|
|
220
|
-
this.url =
|
|
264
|
+
constructor(url, method) {
|
|
265
|
+
this.url = url;
|
|
266
|
+
this.method = method;
|
|
221
267
|
}
|
|
222
268
|
toJSON() {
|
|
223
|
-
return
|
|
269
|
+
return _toJSON(this);
|
|
224
270
|
}
|
|
225
271
|
}
|
|
226
272
|
export {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
273
|
+
Conversion_Request,
|
|
274
|
+
EC4W_ErrorMessages,
|
|
275
|
+
EC4W_Request,
|
|
276
|
+
EC4W_Result,
|
|
277
|
+
EC4W_ValidMessages,
|
|
278
|
+
EC4W_Validator,
|
|
279
|
+
SentRequest,
|
|
280
|
+
UPDE_Request
|
|
235
281
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1,285 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.ec4w_validator = {}));
|
|
3
|
+
})(this, (function(exports2) {
|
|
4
|
+
"use strict";
|
|
5
|
+
function _toJSON(target) {
|
|
6
|
+
const jsonObj = { ...target };
|
|
7
|
+
const proto = Object.getPrototypeOf(target);
|
|
8
|
+
Object.entries(Object.getOwnPropertyDescriptors(proto)).forEach(([key, descriptor]) => {
|
|
9
|
+
if (typeof descriptor.get === "function") {
|
|
10
|
+
jsonObj[key] = target[key];
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return jsonObj;
|
|
14
|
+
}
|
|
15
|
+
class EC4W_Validator {
|
|
16
|
+
/** @type {SentRequest[]} */
|
|
17
|
+
#requestList = [];
|
|
18
|
+
/** @param {SentRequest[]} requestList */
|
|
19
|
+
constructor(requestList) {
|
|
20
|
+
this.#requestList = requestList;
|
|
21
|
+
}
|
|
22
|
+
/** @returns {EC4W_Result} */
|
|
23
|
+
conclude() {
|
|
24
|
+
const sentRequests = [];
|
|
25
|
+
for (const request of this.#requestList) {
|
|
26
|
+
if (!request.url) continue;
|
|
27
|
+
const Url = new URL(request.url);
|
|
28
|
+
if (UPDE_Request.canBe(request.method, Url)) {
|
|
29
|
+
sentRequests.push(new UPDE_Request(request.method, Url));
|
|
30
|
+
} else if (Conversion_Request.canBe(request.method, Url)) {
|
|
31
|
+
sentRequests.push(new Conversion_Request(request.method, Url));
|
|
32
|
+
} else ;
|
|
33
|
+
}
|
|
34
|
+
if (sentRequests.length < 1) throw new Error("no ( sentRequest ) detected");
|
|
35
|
+
const EC4W_list = [];
|
|
36
|
+
{
|
|
37
|
+
let lastUPDE = null;
|
|
38
|
+
for (const ping of sentRequests) {
|
|
39
|
+
if (ping instanceof UPDE_Request) {
|
|
40
|
+
lastUPDE = ping;
|
|
41
|
+
} else if (ping instanceof Conversion_Request) {
|
|
42
|
+
EC4W_list.push(new EC4W_Request(lastUPDE, ping));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (EC4W_list.length < 1) throw new Error("no ( UPDE | EC4w ) requests detected");
|
|
47
|
+
return new EC4W_Result(EC4W_list);
|
|
48
|
+
}
|
|
49
|
+
/** @param {string} em */
|
|
50
|
+
static emIsValid(em) {
|
|
51
|
+
if (!em) return false;
|
|
52
|
+
if (em.startsWith("tv.1") === false) return false;
|
|
53
|
+
if (em === "tv.1") return false;
|
|
54
|
+
if (/^tv\.1~e[0-9]/.test(em)) return false;
|
|
55
|
+
const part = em.split("~");
|
|
56
|
+
const len = part.length;
|
|
57
|
+
if (len < 2) return false;
|
|
58
|
+
for (let i = 1; i < len; ++i) {
|
|
59
|
+
if (part[i] === "") return false;
|
|
60
|
+
const [key, value] = part[i].split(".");
|
|
61
|
+
if (!key) return false;
|
|
62
|
+
if (!value) return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
toJSON() {
|
|
67
|
+
return _toJSON(this);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const EC4W_ValidMessages = Object.freeze({
|
|
71
|
+
em_validInConversion: "valid `em` in Conversion payload",
|
|
72
|
+
em_validInUPDE: "valid `em` in UPDE payload"
|
|
73
|
+
});
|
|
74
|
+
const EC4W_ErrorMessages = Object.freeze({
|
|
75
|
+
em_invalidInConversion: "invalid `em` in Conversion payload",
|
|
76
|
+
em_invalidInUPDE: "invalid `em` in UPDE payload",
|
|
77
|
+
ecsid_mismatch: "mismatch `ecsid` between UPDE and Conversion payload",
|
|
78
|
+
conversionId_mismatch: "mismatch `Conversion ID` between UPDE and Conversion payload",
|
|
79
|
+
noEC4W_request: "no valid EC4W requests detected at all"
|
|
80
|
+
});
|
|
81
|
+
class EC4W_Request {
|
|
82
|
+
#UPDE_Request = null;
|
|
83
|
+
#Conversion_Request;
|
|
84
|
+
/**
|
|
85
|
+
* @param {UPDE_Request?} UPDE_Request
|
|
86
|
+
* @param {Conversion_Request} Conversion_Request */
|
|
87
|
+
constructor(UPDE_Request2, Conversion_Request2) {
|
|
88
|
+
this.#UPDE_Request = UPDE_Request2;
|
|
89
|
+
this.#Conversion_Request = Conversion_Request2;
|
|
90
|
+
}
|
|
91
|
+
get result() {
|
|
92
|
+
if (!this.#UPDE_Request && !this.#Conversion_Request)
|
|
93
|
+
return new Result(false, EC4W_ErrorMessages.noEC4W_request);
|
|
94
|
+
if (this.#ecsidIsValid() === false)
|
|
95
|
+
return new Result(false, EC4W_ErrorMessages.ecsid_mismatch);
|
|
96
|
+
return this.#emIsValid();
|
|
97
|
+
}
|
|
98
|
+
#ecsidIsValid() {
|
|
99
|
+
if (this.#Conversion_Request === null) return false;
|
|
100
|
+
if (this.#UPDE_Request === null) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (!this.#UPDE_Request.ecsid) return false;
|
|
104
|
+
if (!this.#Conversion_Request.ecsid) return false;
|
|
105
|
+
if (this.#UPDE_Request.ecsid !== this.#Conversion_Request.ecsid) return false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
#emIsValid() {
|
|
109
|
+
if (this.#Conversion_Request === null)
|
|
110
|
+
return new Result(false, EC4W_ErrorMessages.em_invalidInConversion);
|
|
111
|
+
if (this.#UPDE_Request === null) {
|
|
112
|
+
const isValid2 = this.#Conversion_Request.emIsValid();
|
|
113
|
+
if (isValid2) return new Result(isValid2, EC4W_ValidMessages.em_validInConversion);
|
|
114
|
+
else return new Result(isValid2, EC4W_ErrorMessages.em_invalidInConversion);
|
|
115
|
+
}
|
|
116
|
+
if (this.#Conversion_Request.em === null) {
|
|
117
|
+
const isValid2 = this.#UPDE_Request.emIsValid();
|
|
118
|
+
if (isValid2) return new Result(isValid2, EC4W_ValidMessages.em_validInUPDE);
|
|
119
|
+
else return new Result(isValid2, EC4W_ErrorMessages.em_invalidInUPDE);
|
|
120
|
+
}
|
|
121
|
+
const isValid = this.#Conversion_Request.emIsValid();
|
|
122
|
+
if (isValid) return new Result(isValid, EC4W_ValidMessages.em_validInConversion);
|
|
123
|
+
else return new Result(isValid, EC4W_ErrorMessages.em_invalidInConversion);
|
|
124
|
+
}
|
|
125
|
+
toJSON() {
|
|
126
|
+
return _toJSON(this);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
class Result {
|
|
130
|
+
#isGood;
|
|
131
|
+
get isGood() {
|
|
132
|
+
return this.#isGood;
|
|
133
|
+
}
|
|
134
|
+
#message;
|
|
135
|
+
get message() {
|
|
136
|
+
return this.#message;
|
|
137
|
+
}
|
|
138
|
+
/** @param {boolean} isGood
|
|
139
|
+
* @param {string} message */
|
|
140
|
+
constructor(isGood, message) {
|
|
141
|
+
this.#isGood = isGood;
|
|
142
|
+
this.#message = message;
|
|
143
|
+
}
|
|
144
|
+
toJSON() {
|
|
145
|
+
return {
|
|
146
|
+
isGood: this.#isGood,
|
|
147
|
+
message: this.#message
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
class UPDE_Request {
|
|
152
|
+
/**
|
|
153
|
+
* @param {string} method
|
|
154
|
+
* @param {URL} Url */
|
|
155
|
+
static canBe(method, Url) {
|
|
156
|
+
if (method !== "GET") return false;
|
|
157
|
+
if (false === Url.toString().startsWith("https://www.google.com/ccm/form-data/")) return false;
|
|
158
|
+
if (Url.searchParams.get("em") === null) return false;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
#method;
|
|
162
|
+
get method() {
|
|
163
|
+
return this.#method;
|
|
164
|
+
}
|
|
165
|
+
#Url;
|
|
166
|
+
get url() {
|
|
167
|
+
return this.#Url.toString();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* @param {string} method
|
|
171
|
+
* @param {URL} Url */
|
|
172
|
+
constructor(method, Url) {
|
|
173
|
+
this.#method = method;
|
|
174
|
+
this.#Url = Url;
|
|
175
|
+
}
|
|
176
|
+
get em() {
|
|
177
|
+
return this.#Url.searchParams.get("em");
|
|
178
|
+
}
|
|
179
|
+
get ecsid() {
|
|
180
|
+
return this.#Url.searchParams.get("ecsid");
|
|
181
|
+
}
|
|
182
|
+
emIsValid() {
|
|
183
|
+
return EC4W_Validator.emIsValid(this.em);
|
|
184
|
+
}
|
|
185
|
+
toJSON() {
|
|
186
|
+
return _toJSON(this);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class Conversion_Request {
|
|
190
|
+
/**
|
|
191
|
+
* @param {string} method
|
|
192
|
+
* @param {URL} Url */
|
|
193
|
+
static canBe(method, Url) {
|
|
194
|
+
if (method !== "GET") return false;
|
|
195
|
+
if (false === Url.toString().startsWith("https://www.googleadservices.com/ccm/conversion/")) return false;
|
|
196
|
+
if (Url.searchParams.get("label") === null) return false;
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
#method;
|
|
200
|
+
get method() {
|
|
201
|
+
return this.#method;
|
|
202
|
+
}
|
|
203
|
+
#Url;
|
|
204
|
+
get url() {
|
|
205
|
+
return this.#Url.toString();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @param {string} method
|
|
209
|
+
* @param {URL} Url */
|
|
210
|
+
constructor(method, Url) {
|
|
211
|
+
this.#method = method;
|
|
212
|
+
this.#Url = Url;
|
|
213
|
+
}
|
|
214
|
+
get em() {
|
|
215
|
+
return this.#Url.searchParams.get("em");
|
|
216
|
+
}
|
|
217
|
+
get ecsid() {
|
|
218
|
+
return this.#Url.searchParams.get("ecsid");
|
|
219
|
+
}
|
|
220
|
+
emIsValid() {
|
|
221
|
+
return EC4W_Validator.emIsValid(this.em);
|
|
222
|
+
}
|
|
223
|
+
toJSON() {
|
|
224
|
+
return _toJSON(this);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
class EC4W_Result {
|
|
228
|
+
/** @type {EC4W_Request[]} */
|
|
229
|
+
EC4W_Requests = [];
|
|
230
|
+
// errors = [];
|
|
231
|
+
messages = [];
|
|
232
|
+
/**
|
|
233
|
+
* @param {EC4W_Request[]} EC4W_Requests
|
|
234
|
+
* */
|
|
235
|
+
constructor(EC4W_Requests) {
|
|
236
|
+
if (!EC4W_Requests || EC4W_Requests.length < 1) throw new Error("no requests detected");
|
|
237
|
+
this.EC4W_Requests = EC4W_Requests;
|
|
238
|
+
}
|
|
239
|
+
get invalidRequest() {
|
|
240
|
+
for (const EC4W_Request2 of this.EC4W_Requests) {
|
|
241
|
+
if (EC4W_Request2.result.isGood === false) return EC4W_Request2;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
get validRequest() {
|
|
246
|
+
for (const EC4W_Request2 of this.EC4W_Requests) {
|
|
247
|
+
if (EC4W_Request2.result.isGood) return EC4W_Request2;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
// get summary() {
|
|
252
|
+
// const summary = [], EC4W_Requests = this.EC4W_Requests;
|
|
253
|
+
// for (const EC4W_Request of EC4W_Requests) {
|
|
254
|
+
// summary.push({
|
|
255
|
+
// EC4W_Request: EC4W_Request,
|
|
256
|
+
// result: EC4W_Request.result,
|
|
257
|
+
// });
|
|
258
|
+
// }
|
|
259
|
+
// return summary;
|
|
260
|
+
// }
|
|
261
|
+
toJSON() {
|
|
262
|
+
return _toJSON(this);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
class SentRequest {
|
|
266
|
+
url = "https://";
|
|
267
|
+
method = "GET";
|
|
268
|
+
constructor(url, method) {
|
|
269
|
+
this.url = url;
|
|
270
|
+
this.method = method;
|
|
271
|
+
}
|
|
272
|
+
toJSON() {
|
|
273
|
+
return _toJSON(this);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports2.Conversion_Request = Conversion_Request;
|
|
277
|
+
exports2.EC4W_ErrorMessages = EC4W_ErrorMessages;
|
|
278
|
+
exports2.EC4W_Request = EC4W_Request;
|
|
279
|
+
exports2.EC4W_Result = EC4W_Result;
|
|
280
|
+
exports2.EC4W_ValidMessages = EC4W_ValidMessages;
|
|
281
|
+
exports2.EC4W_Validator = EC4W_Validator;
|
|
282
|
+
exports2.SentRequest = SentRequest;
|
|
283
|
+
exports2.UPDE_Request = UPDE_Request;
|
|
284
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
285
|
+
}));
|
package/dist/vite.svg
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ec4w_validator",
|
|
3
|
-
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "vite build",
|
|
9
|
-
"preview": "vite preview",
|
|
10
|
-
"test": "vitest --run",
|
|
11
|
-
"test-watch": "vitest",
|
|
12
|
-
"test-coverage": "vitest run --coverage"
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"./dist/"
|
|
16
|
-
],
|
|
17
|
-
"main": "./dist/index.umd.cjs",
|
|
18
|
-
"module": "./dist/index.js",
|
|
19
|
-
"exports": {
|
|
20
|
-
".": {
|
|
21
|
-
"import": "./dist/index.js",
|
|
22
|
-
"require": "./dist/index.umd.js"
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@eslint/js": "^9.39.2",
|
|
27
|
-
"@vitest/coverage-v8": "^4.0.18",
|
|
28
|
-
"eslint": "^9.39.2",
|
|
29
|
-
"globals": "^17.2.0",
|
|
30
|
-
"jsdom": "^27.4.0",
|
|
31
|
-
"vite": "^7.2.4",
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ec4w_validator",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.0.1001111224",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"test": "vitest --run",
|
|
11
|
+
"test-watch": "vitest",
|
|
12
|
+
"test-coverage": "vitest run --coverage"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"./dist/"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.umd.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.umd.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@eslint/js": "^9.39.2",
|
|
27
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
28
|
+
"eslint": "^9.39.2",
|
|
29
|
+
"globals": "^17.2.0",
|
|
30
|
+
"jsdom": "^27.4.0",
|
|
31
|
+
"vite": "^7.2.4",
|
|
32
|
+
"vitest": "^4.0.18"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { }
|