@zthun/helpful-internet 3.0.0 → 3.2.0

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.
@@ -84,9 +84,6 @@ export declare class ZCookieBuilder {
84
84
  /**
85
85
  * Sets the cookie expiration date to one day from the moment this is invoked.
86
86
  *
87
- * @param val -
88
- * The value to set.
89
- *
90
87
  * @returns
91
88
  * This object.
92
89
  */
@@ -1,4 +1,4 @@
1
- import { IZEmailContact } from './email-contact';
1
+ import { IZEmailContact } from './email-contact.mjs';
2
2
  /**
3
3
  * Represents a builder that will build a comma separated
4
4
  * list of addresses for an email message.
@@ -1,4 +1,4 @@
1
- import { IZEmailContact } from './email-contact';
1
+ import { IZEmailContact } from './email-contact.mjs';
2
2
  /**
3
3
  * Represents an email envelope of information about who the email is from and where it's going to.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { IZEmailEnvelope } from './email-envelope';
1
+ import { IZEmailEnvelope } from './email-envelope.mjs';
2
2
  /**
3
3
  * Represents an email message.
4
4
  */
package/dist/index.cjs ADDED
@@ -0,0 +1,637 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const _ZCookieBuilder = class _ZCookieBuilder {
4
+ /**
5
+ * Initializes a new instance of this object.
6
+ */
7
+ constructor() {
8
+ this.immortal = this.expires.bind(this, void 0);
9
+ this.lax = this.sameSite.bind(this, "lax");
10
+ this.strict = this.sameSite.bind(this, "strict");
11
+ this._cookie = {
12
+ name: "",
13
+ value: ""
14
+ };
15
+ }
16
+ /**
17
+ * Sets the cookie name.
18
+ *
19
+ * @param val -
20
+ * The value to set.
21
+ *
22
+ * @returns
23
+ * This object.
24
+ */
25
+ name(val) {
26
+ this._cookie.name = val;
27
+ return this;
28
+ }
29
+ /**
30
+ * Sets the cookie value.
31
+ *
32
+ * @param val -
33
+ * The value to set.
34
+ *
35
+ * @returns
36
+ * This object.
37
+ */
38
+ value(val) {
39
+ this._cookie.value = val;
40
+ return this;
41
+ }
42
+ /**
43
+ * Sets the cookie domain.
44
+ *
45
+ * @param val -
46
+ * The value to set.
47
+ *
48
+ * @returns
49
+ * This object.
50
+ */
51
+ domain(val) {
52
+ this._cookie.domain = val;
53
+ return this;
54
+ }
55
+ /**
56
+ * Sets the cookie expiration date.
57
+ *
58
+ * @param val -
59
+ * The value to set.
60
+ *
61
+ * @returns
62
+ * This object.
63
+ */
64
+ expires(val) {
65
+ if (val == null) {
66
+ delete this._cookie.expires;
67
+ return this;
68
+ }
69
+ this._cookie.expires = typeof val === "string" ? val : val.toJSON();
70
+ return this;
71
+ }
72
+ /**
73
+ * Sets the cookie expiration date to one day from the moment this is invoked.
74
+ *
75
+ * @returns
76
+ * This object.
77
+ */
78
+ expiresTomorrow() {
79
+ return this.expires(new Date(Date.now() + _ZCookieBuilder.MillisecondsOneDay));
80
+ }
81
+ /**
82
+ * Sets the cookie secure flag.
83
+ *
84
+ * @param val -
85
+ * The value to set.
86
+ *
87
+ * @returns
88
+ * This object.
89
+ */
90
+ secure(val = true) {
91
+ this._cookie.secure = val;
92
+ return this;
93
+ }
94
+ /**
95
+ * Sets the cookie same site policy.
96
+ *
97
+ * @param val -
98
+ * The value to set.
99
+ *
100
+ * @returns
101
+ * This object.
102
+ */
103
+ sameSite(val) {
104
+ this._cookie.sameSite = val;
105
+ return this;
106
+ }
107
+ /**
108
+ * Sets the same site policy to 'none' and turns on the secure flag.
109
+ *
110
+ * @returns
111
+ * This object.
112
+ */
113
+ allowCrossSite() {
114
+ return this.secure().sameSite("none");
115
+ }
116
+ /**
117
+ * Sets the cookie http only flag.
118
+ *
119
+ * @param val -
120
+ * The value to set.
121
+ *
122
+ * @returns
123
+ * This object.
124
+ */
125
+ httpOnly(val = true) {
126
+ this._cookie.httpOnly = val;
127
+ return this;
128
+ }
129
+ /**
130
+ * Creates a token based authentication cookie.
131
+ *
132
+ * @param token -
133
+ * The token value for the cookie. You
134
+ * can leave this as undefined to set it
135
+ * later.
136
+ *
137
+ * @returns
138
+ * This object.
139
+ */
140
+ authentication(token) {
141
+ const builder = this.name("Authentication").expiresTomorrow().secure().httpOnly();
142
+ return token == null ? builder : builder.value(token);
143
+ }
144
+ /**
145
+ * Returns a copy of the built instance of the cookie.
146
+ *
147
+ * @returns
148
+ * A shallow copy of the current cookie object.
149
+ */
150
+ build() {
151
+ return { ...this._cookie };
152
+ }
153
+ };
154
+ _ZCookieBuilder.MillisecondsOneDay = 864e5;
155
+ let ZCookieBuilder = _ZCookieBuilder;
156
+ class ZEmailContactAddressBuilder {
157
+ constructor() {
158
+ this._addresses = [];
159
+ this._delimiter = ", ";
160
+ }
161
+ /**
162
+ * Adds an address to the list to builder.
163
+ *
164
+ * @param val -
165
+ * The address to add. This can be the empty string,
166
+ * null, or undefined.
167
+ *
168
+ * @returns
169
+ * This object.
170
+ */
171
+ address(val) {
172
+ this._addresses.push(val);
173
+ return this;
174
+ }
175
+ /**
176
+ * Sets the addresses to build from.
177
+ *
178
+ * @param val -
179
+ * The address to set.
180
+ *
181
+ * @returns
182
+ * This object.
183
+ */
184
+ addresses(val) {
185
+ this._addresses = val.slice();
186
+ return this;
187
+ }
188
+ /**
189
+ * Sets the delimiter to split the addresses with.
190
+ *
191
+ * The default is a comma with a space.
192
+ *
193
+ * @param val -
194
+ * The delimiter to set.
195
+ *
196
+ * @returns
197
+ * This object.
198
+ */
199
+ delimiter(val) {
200
+ this._delimiter = val;
201
+ return this;
202
+ }
203
+ /**
204
+ * Builds the delimiters separated list of addresses.
205
+ *
206
+ * @returns
207
+ * The delimited separated list of addresses.
208
+ */
209
+ build() {
210
+ const addr = (ct) => {
211
+ if (!ct) {
212
+ return void 0;
213
+ }
214
+ return typeof ct === "string" ? ct : ct.address;
215
+ };
216
+ const truthy = (ct) => {
217
+ return !!ct;
218
+ };
219
+ return this._addresses.map(addr).filter(truthy).join(this._delimiter);
220
+ }
221
+ }
222
+ class ZEmailContactBuilder {
223
+ /**
224
+ * Initializes a new instance of this object.
225
+ */
226
+ constructor() {
227
+ this._contact = {
228
+ address: ""
229
+ };
230
+ }
231
+ /**
232
+ * Sets the address of the contact.
233
+ *
234
+ * @param val -
235
+ * The value to set.
236
+ *
237
+ * @returns
238
+ * This object.
239
+ */
240
+ address(val) {
241
+ this._contact.address = val;
242
+ return this;
243
+ }
244
+ /**
245
+ * Sets the type of the contact.
246
+ *
247
+ * @param val -
248
+ * The value to set.
249
+ *
250
+ * @returns
251
+ * This object.
252
+ */
253
+ type(val) {
254
+ this._contact.type = val;
255
+ return this;
256
+ }
257
+ /**
258
+ * Sets the display of the contact.
259
+ *
260
+ * @param val -
261
+ * The value to set.
262
+ *
263
+ * @returns
264
+ * This object.
265
+ */
266
+ display(val) {
267
+ this._contact.display = val;
268
+ return this;
269
+ }
270
+ /**
271
+ * Assigns the values in other to this object.
272
+ *
273
+ * @param other -
274
+ * The value to partial copy.
275
+ *
276
+ * @returns
277
+ * This object.
278
+ */
279
+ assign(other) {
280
+ this._contact = Object.assign({}, this._contact, other);
281
+ this._contact = JSON.parse(JSON.stringify(this._contact));
282
+ return this;
283
+ }
284
+ /**
285
+ * Copies another object.
286
+ *
287
+ * @param other -
288
+ * The value to copy.
289
+ *
290
+ * @returns
291
+ * This object.
292
+ */
293
+ copy(other) {
294
+ this._contact = JSON.parse(JSON.stringify(other));
295
+ return this;
296
+ }
297
+ /**
298
+ * Returns a copy of the built object.
299
+ *
300
+ * @returns
301
+ * A copy of the built email contact.
302
+ */
303
+ build() {
304
+ return JSON.parse(JSON.stringify(this._contact));
305
+ }
306
+ }
307
+ class ZEmailEnvelopeBuilder {
308
+ /**
309
+ * Initializes a new instance of this object.
310
+ */
311
+ constructor() {
312
+ this._envelope = {
313
+ from: ""
314
+ };
315
+ }
316
+ /**
317
+ * Sets the from field.
318
+ *
319
+ * @param val -
320
+ * The value to set.
321
+ *
322
+ * @returns
323
+ * This object.
324
+ */
325
+ from(val) {
326
+ this._envelope.from = val;
327
+ return this;
328
+ }
329
+ /**
330
+ * Adds a value to the 'to' field.
331
+ *
332
+ * @param val -
333
+ * The value to add.
334
+ *
335
+ * @returns
336
+ * This object.
337
+ */
338
+ to(val) {
339
+ this._envelope.to = this._envelope.to || [];
340
+ this._envelope.to.push(val);
341
+ return this;
342
+ }
343
+ /**
344
+ * Sets the to field.
345
+ *
346
+ * @param val -
347
+ * The value to set.
348
+ *
349
+ * @returns
350
+ * This object.
351
+ */
352
+ tos(val) {
353
+ this._envelope.to = val;
354
+ return this;
355
+ }
356
+ /**
357
+ * Adds a value to the cc field.
358
+ *
359
+ * @param val -
360
+ * The value to add.
361
+ *
362
+ * @returns
363
+ * This object.
364
+ */
365
+ cc(val) {
366
+ this._envelope.cc = this._envelope.cc || [];
367
+ this._envelope.cc.push(val);
368
+ return this;
369
+ }
370
+ /**
371
+ * Sets the cc field.
372
+ *
373
+ * @param val -
374
+ * The value to set.
375
+ *
376
+ * @returns
377
+ * This object.
378
+ */
379
+ ccs(val) {
380
+ this._envelope.cc = val;
381
+ return this;
382
+ }
383
+ /**
384
+ * Adds a value to the bcc field.
385
+ *
386
+ * @param val -
387
+ * The value to add.
388
+ *
389
+ * @returns
390
+ * This object.
391
+ */
392
+ bcc(val) {
393
+ this._envelope.bcc = this._envelope.bcc || [];
394
+ this._envelope.bcc.push(val);
395
+ return this;
396
+ }
397
+ /**
398
+ * Sets the bcc field.
399
+ *
400
+ * @param val -
401
+ * The value to set.
402
+ *
403
+ * @returns
404
+ * This object.
405
+ */
406
+ bccs(val) {
407
+ this._envelope.bcc = val;
408
+ return this;
409
+ }
410
+ /**
411
+ * Assigns another partial email envelope to this object.
412
+ *
413
+ * @param other -
414
+ * The value to partial copy.
415
+ *
416
+ * @returns
417
+ * This object.
418
+ */
419
+ assign(other) {
420
+ this._envelope = Object.assign({}, this._envelope, other);
421
+ this._envelope = JSON.parse(JSON.stringify(this._envelope));
422
+ return this;
423
+ }
424
+ /**
425
+ * Copies another email envelope to this object.
426
+ *
427
+ * @param other -
428
+ * The value to copy.
429
+ *
430
+ * @returns
431
+ * This object.
432
+ */
433
+ copy(other) {
434
+ this._envelope = JSON.parse(JSON.stringify(other));
435
+ return this;
436
+ }
437
+ /**
438
+ * Returns a copy of the built envelope.
439
+ *
440
+ * @returns
441
+ * A copy of the currently built up envelope object.
442
+ */
443
+ build() {
444
+ return JSON.parse(JSON.stringify(this._envelope));
445
+ }
446
+ }
447
+ class ZEmailBuilder {
448
+ /**
449
+ * Initializes a new instance of this object.
450
+ */
451
+ constructor() {
452
+ this._email = {
453
+ envelope: new ZEmailEnvelopeBuilder().build()
454
+ };
455
+ }
456
+ /**
457
+ * Sets the envelope of where the email is going.
458
+ *
459
+ * @param val -
460
+ * The value to set.
461
+ *
462
+ * @returns
463
+ * This object.
464
+ */
465
+ envelope(val) {
466
+ this._email.envelope = val;
467
+ return this;
468
+ }
469
+ /**
470
+ * Sets the subject line of the email.
471
+ *
472
+ * @param val -
473
+ * The value to set.
474
+ *
475
+ * @returns
476
+ * This object.
477
+ */
478
+ subject(val) {
479
+ this._email.subject = val;
480
+ return this;
481
+ }
482
+ /**
483
+ * Sets the message of the email.
484
+ *
485
+ * The message can be raw text or html.
486
+ *
487
+ * @param val -
488
+ * A html enabled formatted message to set.
489
+ *
490
+ * @returns
491
+ * This object.
492
+ */
493
+ message(val) {
494
+ this._email.message = val;
495
+ return this;
496
+ }
497
+ /**
498
+ * Assigns the other object to the current email object.
499
+ *
500
+ * @param other -
501
+ * The object to copy.
502
+ *
503
+ * @returns
504
+ * This object.
505
+ */
506
+ assign(other) {
507
+ this._email = Object.assign(this._email, other);
508
+ this._email = JSON.parse(JSON.stringify(this._email));
509
+ return this;
510
+ }
511
+ /**
512
+ * Copies another email into the builder.
513
+ *
514
+ * @param other -
515
+ * The object to copy.
516
+ *
517
+ * @returns
518
+ * This object.
519
+ */
520
+ copy(other) {
521
+ this._email = JSON.parse(JSON.stringify(other));
522
+ return this;
523
+ }
524
+ /**
525
+ * Returns a copy of the built object.
526
+ *
527
+ * @returns
528
+ * A copy of the built object.
529
+ */
530
+ build() {
531
+ return JSON.parse(JSON.stringify(this._email));
532
+ }
533
+ }
534
+ class ZServerBuilder {
535
+ /**
536
+ * Initializes a new instance of this object.
537
+ */
538
+ constructor() {
539
+ this._server = {
540
+ address: ""
541
+ };
542
+ }
543
+ /**
544
+ * The server ip address or hostname.
545
+ *
546
+ * @param val -
547
+ * The value to set.
548
+ *
549
+ * @returns
550
+ * This object.
551
+ */
552
+ address(val) {
553
+ this._server.address = val;
554
+ return this;
555
+ }
556
+ /**
557
+ * Sets the optional port to connect on.
558
+ *
559
+ * @param val -
560
+ * The value to set.
561
+ *
562
+ * @returns
563
+ * This object.
564
+ */
565
+ port(val) {
566
+ this._server.port = val;
567
+ return this;
568
+ }
569
+ /**
570
+ * Sets the optional username to connect on.
571
+ *
572
+ * @param val -
573
+ * The value to set.
574
+ *
575
+ * @returns
576
+ * This object.
577
+ */
578
+ username(val) {
579
+ this._server.username = val;
580
+ return this;
581
+ }
582
+ /**
583
+ * Sets the password to connect on.
584
+ *
585
+ * @param val -
586
+ * The value to set.
587
+ *
588
+ * @returns
589
+ * This object.
590
+ */
591
+ password(val) {
592
+ this._server.password = val;
593
+ return this;
594
+ }
595
+ /**
596
+ * Assigns all truthy properties in other to this object.
597
+ *
598
+ * @param other -
599
+ * The server object to copy.
600
+ *
601
+ * @returns
602
+ * This object.
603
+ */
604
+ assign(other) {
605
+ this._server = Object.assign({}, this._server, other);
606
+ return this;
607
+ }
608
+ /**
609
+ * Copies all properties in other to this object.
610
+ *
611
+ * @param other -
612
+ * The server object to copy.
613
+ *
614
+ * @returns
615
+ * This object.
616
+ */
617
+ copy(other) {
618
+ this._server = JSON.parse(JSON.stringify(other));
619
+ return this;
620
+ }
621
+ /**
622
+ * Returns a copy of the built object.
623
+ *
624
+ * @returns
625
+ * A copy of the built object.
626
+ */
627
+ build() {
628
+ return JSON.parse(JSON.stringify(this._server));
629
+ }
630
+ }
631
+ exports.ZCookieBuilder = ZCookieBuilder;
632
+ exports.ZEmailBuilder = ZEmailBuilder;
633
+ exports.ZEmailContactAddressBuilder = ZEmailContactAddressBuilder;
634
+ exports.ZEmailContactBuilder = ZEmailContactBuilder;
635
+ exports.ZEmailEnvelopeBuilder = ZEmailEnvelopeBuilder;
636
+ exports.ZServerBuilder = ZServerBuilder;
637
+ //# sourceMappingURL=index.cjs.map