ec4w_validator 0.0.10011111 → 0.0.1001111221

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.
@@ -1,318 +0,0 @@
1
- class EC4W_Validator {
2
- /** @type {SentRequest[]} */
3
- #requestList = [];
4
-
5
- /** @param {SentRequest[]} requestList */
6
- constructor(
7
- requestList
8
- ) {
9
- this.#requestList = requestList;
10
- }
11
-
12
- /**
13
- * @returns {EC4W_Result}
14
- */
15
- conclude() {
16
-
17
- // map // transform
18
- const sentRequests = [];
19
- for (const request of this.#requestList) {
20
- if (!request.url) continue;
21
-
22
- const Url = new URL(request.url);
23
- if (UPDE_Request.canBe(request.method, Url)) {
24
- sentRequests.push(new UPDE_Request(request.method, Url));
25
- }
26
- else if (Conversion_Request.canBe(request.method, Url)) {
27
- sentRequests.push(new Conversion_Request(request.method, Url));
28
- }
29
- else {
30
- // skip
31
- }
32
- }
33
-
34
-
35
- // groupping pairs
36
- const EC4W_list = [];
37
- {
38
- let lastUPDE = null;
39
- for (const ping of sentRequests) {
40
- if (ping instanceof UPDE_Request) {
41
- lastUPDE = ping;
42
- }
43
- else if (ping instanceof Conversion_Request) {
44
- EC4W_list.push(new EC4W_Request(lastUPDE, ping));
45
- }
46
- }
47
- }
48
-
49
- return new EC4W_Result(EC4W_list);
50
- }
51
-
52
- /** @param {string} em */
53
- static emIsValid(em) {
54
- if (!em) return false;
55
- if (em.startsWith('tv.1') === false) return false;
56
- if (em === 'tv.1') return false;
57
- if (/^tv\.1~e[0-9]/.test(em)) return false;
58
- const part = em.split('~');
59
- const len = part.length;
60
- if (len < 2) return false;
61
-
62
- for (let i = 1; i < len; ++i) {
63
- if (part[i] === '') return false;
64
- const [key, value] = part[i].split('.');
65
- if (!key) return false;
66
- if (!value) return false;
67
- }
68
-
69
- return true;
70
- }
71
-
72
- }
73
-
74
- class EC4W_Request {
75
- #UPDE_Request = null;
76
- #Conversion_Request;
77
-
78
- /**
79
- * @param {UPDE_Request?} UPDE_Request
80
- * @param {Conversion_Request} Conversion_Request */
81
- constructor(
82
- UPDE_Request,
83
- Conversion_Request
84
- ) {
85
- this.#UPDE_Request = UPDE_Request;
86
- this.#Conversion_Request = Conversion_Request;
87
- }
88
-
89
- get isValid() {
90
- if (this.#Conversion_Request === null) return false;
91
-
92
- if (this.#UPDE_Request === null) {
93
- return this.#Conversion_Request.emIsValid();
94
- }
95
-
96
- if (this.#Conversion_Request.em === null) {
97
- return this.#UPDE_Request.emIsValid();
98
- }
99
-
100
- return this.#Conversion_Request.emIsValid();
101
- }
102
- }
103
-
104
- class UPDE_Request {
105
- /**
106
- * @param {string} method
107
- * @param {URL} Url */
108
- static canBe(method, Url) {
109
- if (method !== 'GET') return false;
110
- if (false === Url.toString().startsWith('https://www.google.com/ccm/form-data/')) return false;
111
- if (Url.searchParams.get('em') === null) return false;
112
- return true;
113
- }
114
-
115
- #method;
116
- get method() { return this.#method; }
117
- #Url;
118
- get url() { return this.#Url.toString(); };
119
-
120
- /**
121
- * @param {string} method
122
- * @param {URL} Url */
123
- constructor(
124
- method,
125
- Url
126
- ) {
127
- this.#method = method;
128
- this.#Url = Url;
129
- }
130
-
131
- get em() {
132
- return this.#Url.searchParams.get('em');
133
- }
134
-
135
- emIsValid() {
136
- return EC4W_Validator.emIsValid(this.em);
137
- }
138
-
139
- }
140
-
141
- class Conversion_Request {
142
-
143
- /**
144
- * @param {string} method
145
- * @param {URL} Url */
146
- static canBe(method, Url) {
147
- if (method !== 'GET') return false;
148
- if (false === Url.toString().startsWith('https://www.googleadservices.com/ccm/conversion/')) return false;
149
- if (Url.searchParams.get('label') === null) return false;
150
- return true;
151
- }
152
-
153
- #method;
154
- get method() { return this.#method; }
155
- #Url;
156
- get url() { return this.#Url.toString(); };
157
-
158
- /**
159
- * @param {string} method
160
- * @param {URL} Url */
161
- constructor(
162
- method,
163
- Url
164
- ) {
165
- this.#method = method;
166
- this.#Url = Url;
167
- }
168
-
169
- get em() {
170
- return this.#Url.searchParams.get('em');
171
- }
172
-
173
- emIsValid() {
174
- return EC4W_Validator.emIsValid(this.em);
175
- }
176
- }
177
-
178
-
179
- class EC4W_Result {
180
- /** @type {EC4W_Request[]} */
181
- EC4W_Requests = [];
182
- // errors = [];
183
- messages = [];
184
-
185
- /**
186
- * @param {EC4W_Request[]} EC4W_Requests
187
- * */
188
- constructor(
189
- EC4W_Requests
190
- ) {
191
- this.EC4W_Requests = EC4W_Requests;
192
-
193
- }
194
-
195
- get invalidRequest() {
196
- for (const EC4W_Request of this.EC4W_Requests) {
197
- if (EC4W_Request.isValid === false) return EC4W_Request;
198
- }
199
- return null;
200
- }
201
-
202
- get summary() {
203
- const summary = [];
204
- for (const EC4W_Request of this.EC4W_Requests) {
205
- summary.push({
206
- isValid: EC4W_Request.isValid,
207
- em: EC4W_Request.em,
208
- });
209
- }
210
- return summary;
211
- }
212
-
213
- }
214
-
215
-
216
-
217
- class SentRequest {
218
- url = 'https://';
219
- method = 'GET';
220
-
221
- constructor(url, method) {
222
- this.url = url;
223
- this.method = method;
224
- }
225
- }
226
-
227
-
228
-
229
-
230
- (function testmain() { // test
231
-
232
- class fakeUPDE {
233
- constructor(httpMethod, emValue, conversionId) {
234
- this.conversionId = conversionId;
235
- this.emValue = emValue;
236
-
237
- const emParam = `&em=${emValue ? emValue : 'tv.1'}`;
238
- this.url = `https://www.google.com/ccm/form-data/${conversionId}?gtm=45be61r1p3v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&gclaw_src=0_1&npa=0&frm=0&gclgs=12&gclst=63271790&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&gap.plf=4.3&ecsid=1296144687.1769663220${emParam}`
239
- this.method = httpMethod;
240
- }
241
- }
242
-
243
- class fakeConve {
244
- constructor(httpMethod, emValue, conversionId, conversionLabel) {
245
- this.emValue = emValue;
246
- this.conversionId = conversionId;
247
- this.conversionLabel = conversionLabel;
248
-
249
- const emParam = emValue ? `&em=${emValue}` : '';
250
- this.url = `https://www.googleadservices.com/ccm/conversion/${conversionId}/?random=1769663226870&cv=11&fst=1769663226870&fmt=3&bg=ffffff&guid=ON&async=1&en=conversion&gtm=45be61r1v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&u_w=1745&u_h=1090&url=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&ref=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&gclaw_src=2_3&label=yYk9CMf--98YEMmV45Uq&capi=1&gtm_ee=1&frm=0&tiba=Wordpress%20Example&value=1&currency_code=MYR&hn=www.googleadservices.com&npa=0&gclgs=12&gclst=63274872&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&oid=113729285.1769663227&oidsrc=3&ecsid=1296144687.1769663220&_tu=ABA&gcl_ctr=399~0&data=event%3Dconversion&gap.plf=4.3${emParam}`;
251
- this.method = httpMethod;
252
- }
253
- }
254
- const defaultEMvalue = 'tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg';
255
-
256
-
257
- function testValid(testName, inputRequests) {
258
- console.log('==========');
259
- console.log(testName);
260
- try {
261
- const sampleRequests = inputRequests || [
262
- { url: 'https://www.google.com/ccm/form-data/11319954121?gtm=45be61r1p3v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&gclaw_src=0_1&npa=0&frm=0&gclgs=12&gclst=63271790&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&gap.plf=4.3&ecsid=1296144687.1769663220&em=tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg', method: 'GET' }, // form-data
263
- { url: `https://www.googleadservices.com/ccm/conversion/11319954121/?random=1769663226870&cv=11&fst=1769663226870&fmt=3&bg=ffffff&guid=ON&async=1&en=conversion&gtm=45be61r1v9164572194za200zd9164572194xec&gcd=13l3l3l3l1l1&dma=0&tag_exp=103116026~103200004~104527907~104528501~104684208~104684211~115495939~115616985~115938465~115938468~116185181~116185182~116988316~117041587&u_w=1745&u_h=1090&url=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&ref=https%3A%2F%2Fgrcn-sme.github.io%2Fwordpress-example%2F&gclaw_src=2_3&label=yYk9CMf--98YEMmV45Uq&capi=1&gtm_ee=1&frm=0&tiba=Wordpress%20Example&value=1&currency_code=MYR&hn=www.googleadservices.com&npa=0&gclgs=12&gclst=63274872&gcllp=265921241&gclaw=TestingABC-2026-01-28&pscdl=noapi&auid=712372246.1762244434&uaa=x86&uab=64&uafvl=Google%2520Chrome%3B143.0.7499.203%7CChromium%3B143.0.7499.203%7CNot%2520A(Brand%3B24.0.0.0&uamb=0&uam=&uap=Chrome%20OS&uapv=16463.79.0&uaw=0&ec_mode=c&oid=113729285.1769663227&oidsrc=3&ecsid=1296144687.1769663220&_tu=ABA&gcl_ctr=399~0&data=event%3Dconversion&gap.plf=4.3&em=tv.1~em.h5JGBrQTGorO7q6IaFMfu5cSqqB6XTp1aybOD11spnQ~pn.QizoLG_BckrIeAQvfQVWU6temD0YbmFoJqctQ4S2ivg`, method: 'GET' } // form-data
264
- ];
265
-
266
- const sentRequests = [];
267
- for (const req of sampleRequests) {
268
- sentRequests.push(new SentRequest(req.url, req.method));
269
- }
270
- const validator = new EC4W_Validator(sentRequests);
271
- const result = validator.conclude();
272
-
273
- console.log({ result });
274
- const invalid = result.invalidRequest;
275
- console.log({ invalid });
276
- console.assert(invalid === null, result);
277
- // if (invalid) debugger;
278
-
279
- } finally {
280
- // console.groupEnd();
281
- console.log('==========');
282
- }
283
- }
284
-
285
- testValid('defualt');
286
- testValid('good', [
287
- new fakeUPDE('GET', null, '11319954121'),
288
- new fakeUPDE('GET', null, '11319954121'),
289
- new fakeConve('GET', defaultEMvalue, '11319954121', 'xxxxxxxxx'),
290
- ]);
291
-
292
- testValid('bad', [
293
- new fakeUPDE('GET', 'tv.1', '11319954121'),
294
- new fakeUPDE('GET', defaultEMvalue, '11319954121'),
295
- new fakeConve('GET', 'tv.1', '11319954121', 'xxxxxxxxx'),
296
- ]);
297
-
298
- testValid('stitching', [
299
- new fakeUPDE('GET', 'tv.1', '11319954121'),
300
- new fakeUPDE('GET', defaultEMvalue, '11319954121'),
301
- new fakeConve('GET', null, '11319954121', 'xxxxxxxxx'),
302
- ]);
303
-
304
- testValid('stitching: self empty em value', [
305
- new fakeUPDE('GET', 'tv.1', '11319954121'),
306
- new fakeUPDE('GET', 'defaultEMvalue', '11319954121'),
307
- new fakeConve('GET', 'tv.1', '11319954121', 'xxxxxxxxx'),
308
- ]);
309
-
310
- testValid('stitching: invalid prior em', [
311
- new fakeUPDE('GET', 'tv.1', '11319954121'),
312
- new fakeUPDE('GET', defaultEMvalue, '11319954121'),
313
- new fakeUPDE('GET', 'tv.1', '11319954121'),
314
- new fakeConve('GET', null, '11319954121', 'xxxxxxxxx'),
315
- ]);
316
-
317
- console.log('end');
318
- })();