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 CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,183 +1,226 @@
1
- function l(n) {
2
- const e = { ...n }, t = Object.getPrototypeOf(n);
3
- return Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([r, s]) => {
4
- typeof s.get == "function" && (e[r] = n[r]);
5
- }), e;
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 h {
11
+ class EC4W_Validator {
8
12
  /** @type {SentRequest[]} */
9
- #t = [];
13
+ #requestList = [];
10
14
  /** @param {SentRequest[]} requestList */
11
- constructor(e) {
12
- this.#t = e;
15
+ constructor(requestList) {
16
+ this.#requestList = requestList;
13
17
  }
14
18
  /** @returns {EC4W_Result} */
15
19
  conclude() {
16
- const e = [];
17
- for (const r of this.#t) {
18
- if (!r.url) continue;
19
- const s = new URL(r.url);
20
- u.canBe(r.method, s) ? e.push(new u(r.method, s)) : c.canBe(r.method, s) && e.push(new c(r.method, s));
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 (e.length < 1) throw new Error("no ( sentRequest ) detected");
23
- const t = [];
30
+ if (sentRequests.length < 1) throw new Error("no ( sentRequest ) detected");
31
+ const EC4W_list = [];
24
32
  {
25
- let r = null;
26
- for (const s of e)
27
- s instanceof u ? r = s : s instanceof c && t.push(new m(r, s));
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 (t.length < 1) throw new Error("no ( UPDE | EC4w ) requests detected");
30
- return new g(t);
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(e) {
34
- if (!e || e.startsWith("tv.1") === !1 || e === "tv.1" || /^tv\.1~e[0-9]/.test(e)) return !1;
35
- const t = e.split("~"), r = t.length;
36
- if (r < 2) return !1;
37
- for (let s = 1; s < r; ++s) {
38
- if (t[s] === "") return !1;
39
- const [f, d] = t[s].split(".");
40
- if (!f || !d) return !1;
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 !0;
60
+ return true;
43
61
  }
44
62
  toJSON() {
45
- return l(this);
63
+ return _toJSON(this);
46
64
  }
47
65
  }
48
- const a = Object.freeze({
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
- }), o = Object.freeze({
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 m {
59
- #t = null;
60
- #e;
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(e, t) {
65
- this.#t = e, this.#e = t;
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
- return !this.#t && !this.#e ? new i(!1, o.noEC4W_request) : this.#s() === !1 ? new i(!1, o.ecsid_mismatch) : this.#r();
69
- }
70
- #s() {
71
- return this.#e === null ? !1 : this.#t === null ? !0 : !(!this.#t.ecsid || !this.#e.ecsid || this.#t.ecsid !== this.#e.ecsid);
72
- }
73
- #r() {
74
- if (this.#e === null)
75
- return new i(!1, o.em_invalidInConversion);
76
- if (this.#t === null) {
77
- const t = this.#e.emIsValid();
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.#e.em === null) {
81
- const t = this.#t.emIsValid();
82
- return t ? new i(t, a.em_validInUPDE) : new i(t, o.em_invalidInUPDE);
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
- const e = this.#e.emIsValid();
85
- return e ? new i(e, a.em_validInConversion) : new i(e, o.em_invalidInConversion);
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 l(this);
122
+ return _toJSON(this);
89
123
  }
90
124
  }
91
- class i {
92
- #t;
125
+ class Result {
126
+ #isGood;
93
127
  get isGood() {
94
- return this.#t;
128
+ return this.#isGood;
95
129
  }
96
- #e;
130
+ #message;
97
131
  get message() {
98
- return this.#e;
132
+ return this.#message;
99
133
  }
100
134
  /** @param {boolean} isGood
101
135
  * @param {string} message */
102
- constructor(e, t) {
103
- this.#t = e, this.#e = t;
136
+ constructor(isGood, message) {
137
+ this.#isGood = isGood;
138
+ this.#message = message;
104
139
  }
105
140
  toJSON() {
106
141
  return {
107
- isGood: this.#t,
108
- message: this.#e
142
+ isGood: this.#isGood,
143
+ message: this.#message
109
144
  };
110
145
  }
111
146
  }
112
- class u {
147
+ class UPDE_Request {
113
148
  /**
114
149
  * @param {string} method
115
150
  * @param {URL} Url */
116
- static canBe(e, t) {
117
- return !(e !== "GET" || t.toString().startsWith("https://www.google.com/ccm/form-data/") === !1 || t.searchParams.get("em") === null);
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
- #t;
157
+ #method;
120
158
  get method() {
121
- return this.#t;
159
+ return this.#method;
122
160
  }
123
- #e;
161
+ #Url;
124
162
  get url() {
125
- return this.#e.toString();
163
+ return this.#Url.toString();
126
164
  }
127
165
  /**
128
166
  * @param {string} method
129
167
  * @param {URL} Url */
130
- constructor(e, t) {
131
- this.#t = e, this.#e = t;
168
+ constructor(method, Url) {
169
+ this.#method = method;
170
+ this.#Url = Url;
132
171
  }
133
172
  get em() {
134
- return this.#e.searchParams.get("em");
173
+ return this.#Url.searchParams.get("em");
135
174
  }
136
175
  get ecsid() {
137
- return this.#e.searchParams.get("ecsid");
176
+ return this.#Url.searchParams.get("ecsid");
138
177
  }
139
178
  emIsValid() {
140
- return h.emIsValid(this.em);
179
+ return EC4W_Validator.emIsValid(this.em);
141
180
  }
142
181
  toJSON() {
143
- return l(this);
182
+ return _toJSON(this);
144
183
  }
145
184
  }
146
- class c {
185
+ class Conversion_Request {
147
186
  /**
148
187
  * @param {string} method
149
188
  * @param {URL} Url */
150
- static canBe(e, t) {
151
- return !(e !== "GET" || t.toString().startsWith("https://www.googleadservices.com/ccm/conversion/") === !1 || t.searchParams.get("label") === null);
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
- #t;
195
+ #method;
154
196
  get method() {
155
- return this.#t;
197
+ return this.#method;
156
198
  }
157
- #e;
199
+ #Url;
158
200
  get url() {
159
- return this.#e.toString();
201
+ return this.#Url.toString();
160
202
  }
161
203
  /**
162
204
  * @param {string} method
163
205
  * @param {URL} Url */
164
- constructor(e, t) {
165
- this.#t = e, this.#e = t;
206
+ constructor(method, Url) {
207
+ this.#method = method;
208
+ this.#Url = Url;
166
209
  }
167
210
  get em() {
168
- return this.#e.searchParams.get("em");
211
+ return this.#Url.searchParams.get("em");
169
212
  }
170
213
  get ecsid() {
171
- return this.#e.searchParams.get("ecsid");
214
+ return this.#Url.searchParams.get("ecsid");
172
215
  }
173
216
  emIsValid() {
174
- return h.emIsValid(this.em);
217
+ return EC4W_Validator.emIsValid(this.em);
175
218
  }
176
219
  toJSON() {
177
- return l(this);
220
+ return _toJSON(this);
178
221
  }
179
222
  }
180
- class g {
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(e) {
189
- if (!e || e.length < 1) throw new Error("no requests detected");
190
- this.EC4W_Requests = e;
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 e of this.EC4W_Requests)
194
- if (e.result.isGood === !1) return e;
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 e of this.EC4W_Requests)
199
- if (e.result.isGood) return e;
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 l(this);
258
+ return _toJSON(this);
214
259
  }
215
260
  }
216
- class v {
261
+ class SentRequest {
217
262
  url = "https://";
218
263
  method = "GET";
219
- constructor(e, t) {
220
- this.url = e, this.method = t;
264
+ constructor(url, method) {
265
+ this.url = url;
266
+ this.method = method;
221
267
  }
222
268
  toJSON() {
223
- return l(this);
269
+ return _toJSON(this);
224
270
  }
225
271
  }
226
272
  export {
227
- c as Conversion_Request,
228
- o as EC4W_ErrorMessages,
229
- m as EC4W_Request,
230
- g as EC4W_Result,
231
- a as EC4W_ValidMessages,
232
- h as EC4W_Validator,
233
- v as SentRequest,
234
- u as UPDE_Request
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
  };
@@ -1 +1,285 @@
1
- (function(r,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(r=typeof globalThis<"u"?globalThis:r||self,i(r.fafafa={}))})(this,(function(r){"use strict";function i(o){const e={...o},t=Object.getPrototypeOf(o);return Object.entries(Object.getOwnPropertyDescriptors(t)).forEach(([n,s])=>{typeof s.get=="function"&&(e[n]=o[n])}),e}class d{#t=[];constructor(e){this.#t=e}conclude(){const e=[];for(const n of this.#t){if(!n.url)continue;const s=new URL(n.url);c.canBe(n.method,s)?e.push(new c(n.method,s)):f.canBe(n.method,s)&&e.push(new f(n.method,s))}if(e.length<1)throw new Error("no ( sentRequest ) detected");const t=[];{let n=null;for(const s of e)s instanceof c?n=s:s instanceof f&&t.push(new h(n,s))}if(t.length<1)throw new Error("no ( UPDE | EC4w ) requests detected");return new m(t)}static emIsValid(e){if(!e||e.startsWith("tv.1")===!1||e==="tv.1"||/^tv\.1~e[0-9]/.test(e))return!1;const t=e.split("~"),n=t.length;if(n<2)return!1;for(let s=1;s<n;++s){if(t[s]==="")return!1;const[v,E]=t[s].split(".");if(!v||!E)return!1}return!0}toJSON(){return i(this)}}const u=Object.freeze({em_validInConversion:"valid `em` in Conversion payload",em_validInUPDE:"valid `em` in UPDE payload"}),l=Object.freeze({em_invalidInConversion:"invalid `em` in Conversion payload",em_invalidInUPDE:"invalid `em` in UPDE payload",ecsid_mismatch:"mismatch `ecsid` between UPDE and Conversion payload",conversionId_mismatch:"mismatch `Conversion ID` between UPDE and Conversion payload",noEC4W_request:"no valid EC4W requests detected at all"});class h{#t=null;#e;constructor(e,t){this.#t=e,this.#e=t}get result(){return!this.#t&&!this.#e?new a(!1,l.noEC4W_request):this.#s()===!1?new a(!1,l.ecsid_mismatch):this.#n()}#s(){return this.#e===null?!1:this.#t===null?!0:!(!this.#t.ecsid||!this.#e.ecsid||this.#t.ecsid!==this.#e.ecsid)}#n(){if(this.#e===null)return new a(!1,l.em_invalidInConversion);if(this.#t===null){const t=this.#e.emIsValid();return t?new a(t,u.em_validInConversion):new a(t,l.em_invalidInConversion)}if(this.#e.em===null){const t=this.#t.emIsValid();return t?new a(t,u.em_validInUPDE):new a(t,l.em_invalidInUPDE)}const e=this.#e.emIsValid();return e?new a(e,u.em_validInConversion):new a(e,l.em_invalidInConversion)}toJSON(){return i(this)}}class a{#t;get isGood(){return this.#t}#e;get message(){return this.#e}constructor(e,t){this.#t=e,this.#e=t}toJSON(){return{isGood:this.#t,message:this.#e}}}class c{static canBe(e,t){return!(e!=="GET"||t.toString().startsWith("https://www.google.com/ccm/form-data/")===!1||t.searchParams.get("em")===null)}#t;get method(){return this.#t}#e;get url(){return this.#e.toString()}constructor(e,t){this.#t=e,this.#e=t}get em(){return this.#e.searchParams.get("em")}get ecsid(){return this.#e.searchParams.get("ecsid")}emIsValid(){return d.emIsValid(this.em)}toJSON(){return i(this)}}class f{static canBe(e,t){return!(e!=="GET"||t.toString().startsWith("https://www.googleadservices.com/ccm/conversion/")===!1||t.searchParams.get("label")===null)}#t;get method(){return this.#t}#e;get url(){return this.#e.toString()}constructor(e,t){this.#t=e,this.#e=t}get em(){return this.#e.searchParams.get("em")}get ecsid(){return this.#e.searchParams.get("ecsid")}emIsValid(){return d.emIsValid(this.em)}toJSON(){return i(this)}}class m{EC4W_Requests=[];messages=[];constructor(e){if(!e||e.length<1)throw new Error("no requests detected");this.EC4W_Requests=e}get invalidRequest(){for(const e of this.EC4W_Requests)if(e.result.isGood===!1)return e;return null}get validRequest(){for(const e of this.EC4W_Requests)if(e.result.isGood)return e;return null}toJSON(){return i(this)}}class g{url="https://";method="GET";constructor(e,t){this.url=e,this.method=t}toJSON(){return i(this)}}r.Conversion_Request=f,r.EC4W_ErrorMessages=l,r.EC4W_Request=h,r.EC4W_Result=m,r.EC4W_ValidMessages=u,r.EC4W_Validator=d,r.SentRequest=g,r.UPDE_Request=c,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
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.1001111223",
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
- "vite-plugin-dts": "^4.5.4",
33
- "vitest": "^4.0.18"
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 { }