@eliasrrosa/tutorhub-public-assets 0.7.6 → 0.8.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.
Files changed (30) hide show
  1. package/dist/application/dtos/UserTimeSlotDTO.d.ts +11 -0
  2. package/dist/application/dtos/UserTimeSlotDTO.js +2 -0
  3. package/dist/application/helpers/filterAsync.d.ts +1 -0
  4. package/dist/application/helpers/filterAsync.js +18 -0
  5. package/dist/application/helpers/filterAsync.test.d.ts +1 -0
  6. package/dist/application/helpers/filterAsync.test.js +21 -0
  7. package/dist/application/helpers/tryCatch.d.ts +2 -0
  8. package/dist/application/helpers/tryCatch.js +31 -0
  9. package/dist/application/helpers/tryCatch.test.d.ts +1 -0
  10. package/dist/application/helpers/tryCatch.test.js +48 -0
  11. package/dist/domain/entities/Class.d.ts +0 -17
  12. package/dist/domain/entities/Class.js +0 -1
  13. package/dist/domain/entities/ISO8601DateTime.d.ts +36 -31
  14. package/dist/domain/entities/ISO8601DateTime.js +72 -34
  15. package/dist/domain/entities/ISO8601DateTime.test.js +51 -133
  16. package/dist/domain/entities/ISO8601DateValidator.d.ts +2 -1
  17. package/dist/domain/entities/ISO8601DateValidator.js +4 -3
  18. package/dist/domain/entities/ISO8601TimeValidator.d.ts +6 -3
  19. package/dist/domain/entities/ISO8601TimeValidator.js +6 -3
  20. package/dist/domain/entities/TimeUnitConverter.d.ts +20 -0
  21. package/dist/domain/entities/TimeUnitConverter.js +17 -0
  22. package/dist/domain/entities/TimeUnitConverter.test.d.ts +1 -0
  23. package/dist/domain/entities/TimeUnitConverter.test.js +110 -0
  24. package/dist/domain/types/ClassStatus copy.d.ts +4 -0
  25. package/dist/domain/types/ClassStatus copy.js +2 -0
  26. package/dist/index.cjs +98 -101
  27. package/dist/index.d.ts +3 -38
  28. package/dist/index.js +98 -99
  29. package/dist/infrastructure/restful/responses/GetFixedAvailableTimesResponseBody.d.ts +2 -2
  30. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19,32 +19,20 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
 
22
- // src/domain/entities/AsaasCustomer.ts
23
- var AsaasCustomer = class {
24
- constructor(opts) {
25
- this.name = opts.name;
26
- this.cpfCnpj = opts.cpfCnpj;
27
- this.email = opts.email;
28
- this.mobilePhone = opts.mobilePhone;
29
- this.externalReference = opts.externalReference;
30
- }
31
- };
32
-
33
22
  // src/domain/entities/ISO8601DateValidator.ts
34
23
  var ISO8601DateValidator = class {
35
24
  constructor() {
36
- this.YYYYmmDD = new RegExp(
37
- "^[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])"
38
- );
25
+ this.YYYYmmDDpatternString = "[0-9]{4}-([0][1-9]|[1][0-2])-([0][1-9]|[1-2][0-9]|[3][0-1])";
26
+ this.YYYYmmDDpattern = new RegExp(`^${this.YYYYmmDDpatternString}`);
39
27
  }
40
28
  /**
41
29
  * Accepted format: YYYY-MM-DD
42
30
  */
43
31
  formatIsValid(date) {
44
- return this.YYYYmmDD.test(date);
32
+ return this.YYYYmmDDpattern.test(date);
45
33
  }
46
34
  match(date) {
47
- const matches = date.match(this.YYYYmmDD);
35
+ const matches = date.match(this.YYYYmmDDpattern);
48
36
  if (!matches || matches.length < 1) {
49
37
  return void 0;
50
38
  }
@@ -152,51 +140,6 @@ _ISO8601Date.jsDateTimeToDate = (dateTime, opts) => {
152
140
  };
153
141
  var ISO8601Date = _ISO8601Date;
154
142
 
155
- // src/domain/entities/ISO8601DateTime.ts
156
- var ISO8601DateTime = class _ISO8601DateTime {
157
- constructor(opts) {
158
- this.getJSDateTime = () => {
159
- return new Date(
160
- parseInt(this.date.getYear()),
161
- parseInt(this.date.getMonth()) - 1,
162
- parseInt(this.date.getDay()),
163
- parseInt(this.time.getHoursString()),
164
- parseInt(this.time.getMinutesString()),
165
- parseInt(this.time.getSecondsString())
166
- );
167
- };
168
- this.getBrazilianIsoString = () => {
169
- return this.getIsoString({
170
- timezoneOffsetMinutes: -180
171
- });
172
- };
173
- this.date = opts.date;
174
- this.time = opts.time;
175
- }
176
- getIsoString(opts) {
177
- const padLeft = (n) => String(n).padStart(2, "0");
178
- const newDateTime = new _ISO8601DateTime({
179
- date: (opts == null ? void 0 : opts.newDate) || this.date,
180
- time: (opts == null ? void 0 : opts.newTime) || this.time
181
- });
182
- const jsDate = newDateTime.getJSDateTime();
183
- const year = jsDate.getFullYear();
184
- const month = padLeft(jsDate.getMonth() + 1);
185
- const day = padLeft(jsDate.getDate());
186
- const hour = padLeft(jsDate.getHours());
187
- const minute = padLeft(jsDate.getMinutes());
188
- const second = padLeft(jsDate.getSeconds());
189
- const timezoneOffsetMinutes = (opts == null ? void 0 : opts.timezoneOffsetMinutes) ? opts.timezoneOffsetMinutes : 0;
190
- const sign = timezoneOffsetMinutes == 0 ? void 0 : timezoneOffsetMinutes < 0 ? "-" : "+";
191
- const offsetHours = padLeft(
192
- Math.floor(Math.abs(timezoneOffsetMinutes) / 60)
193
- );
194
- const offsetMinutes = padLeft(Math.abs(timezoneOffsetMinutes) % 60);
195
- const timezone = sign ? `${sign}${offsetHours}:${offsetMinutes}` : ".000Z";
196
- return `${year}-${month}-${day}T${hour}:${minute}:${second}${timezone}`;
197
- }
198
- };
199
-
200
143
  // src/domain/entities/ISO8601TimeValidator.ts
201
144
  var ISO8601TimeValidator = class {
202
145
  constructor() {
@@ -205,22 +148,23 @@ var ISO8601TimeValidator = class {
205
148
  this.upTo11 = "(0[0-9]|1[0-2])";
206
149
  this.upTo13 = "(0[0-9]|1[0-4])";
207
150
  this.numberedTimezonePatternString = `(\\+(${this.upTo11}:${this.upTo59}|12:00)|\\-(${this.upTo13}:${this.upTo59}|14:00))`;
208
- this.numberedTimezonePattern = new RegExp(`^${this.numberedTimezonePatternString}$`);
151
+ this.numberedTimezonePattern = new RegExp(
152
+ `^${this.numberedTimezonePatternString}$`
153
+ );
209
154
  this.zTimezonePatternString = "Z";
210
155
  this.zAndMillisecondsPatternString = `.[0-9]{3}Z`;
211
156
  this.hhMMssPattern = new RegExp(
212
157
  `^${this.upTo23}:${this.upTo59}:${this.upTo59}$`
213
158
  );
214
159
  this.hhMMPattern = new RegExp(`^${this.upTo23}:${this.upTo59}$`);
160
+ this.hhMMssPlusNumberedTimezonePatternString = `${this.upTo23}:${this.upTo59}:${this.upTo59}${this.numberedTimezonePatternString}`;
215
161
  this.hhMMssPlusNumberedTimezonePattern = new RegExp(
216
- `^${this.upTo23}:${this.upTo59}:${this.upTo59}${this.numberedTimezonePatternString}$`
217
- );
218
- this.hhMMssZPattern = new RegExp(
219
- `^${this.upTo23}:${this.upTo59}:${this.upTo59}${this.zTimezonePatternString}$`
220
- );
221
- this.hhMMssSSSZPattern = new RegExp(
222
- `^${this.upTo23}:${this.upTo59}:${this.upTo59}${this.zAndMillisecondsPatternString}$`
162
+ `^${this.hhMMssPlusNumberedTimezonePatternString}$`
223
163
  );
164
+ this.hhMMssZPatternString = `${this.upTo23}:${this.upTo59}:${this.upTo59}${this.zTimezonePatternString}`;
165
+ this.hhMMssZPattern = new RegExp(`^${this.hhMMssZPatternString}$`);
166
+ this.hhMMssSSSZPatternString = `${this.upTo23}:${this.upTo59}:${this.upTo59}${this.zAndMillisecondsPatternString}`;
167
+ this.hhMMssSSSZPattern = new RegExp(`^${this.hhMMssSSSZPatternString}$`);
224
168
  this.isHHmmSSPlusNumberedTimezone = (time) => {
225
169
  return this.hhMMssPlusNumberedTimezonePattern.test(time);
226
170
  };
@@ -373,6 +317,89 @@ var ISO8601TimezoneParser = class {
373
317
  }
374
318
  };
375
319
 
320
+ // src/domain/entities/TimeUnitConverter.ts
321
+ var TimeUnitConverter = class {
322
+ constructor() {
323
+ this.msToSeconds = (n) => n / 1e3;
324
+ this.msToMinutes = (n) => n / (1e3 * 60);
325
+ this.msToHours = (n) => n / (1e3 * 60 * 60);
326
+ this.msToDays = (n) => n / (1e3 * 60 * 60 * 24);
327
+ this.daysToMs = (n) => n * 24 * 60 * 60 * 1e3;
328
+ this.hoursToMs = (n) => n * 60 * 60 * 1e3;
329
+ this.minutesToMs = (n) => n * 60 * 1e3;
330
+ this.secondsToMs = (n) => n * 1e3;
331
+ }
332
+ };
333
+
334
+ // src/domain/entities/ISO8601DateTime.ts
335
+ var ISO8601DateTime = class _ISO8601DateTime {
336
+ constructor(dateString) {
337
+ this.timeFormatValidator = new ISO8601TimeValidator();
338
+ this.dateFormatValidator = new ISO8601DateValidator();
339
+ this.timeUnitConverter = new TimeUnitConverter();
340
+ this.dateTimePattern = new RegExp(
341
+ `^${this.dateFormatValidator.YYYYmmDDpatternString}T(${this.timeFormatValidator.hhMMssPlusNumberedTimezonePatternString}|${this.timeFormatValidator.hhMMssSSSZPatternString}|${this.timeFormatValidator.hhMMssZPatternString})$`
342
+ );
343
+ this.onlyDatePattern = new RegExp(
344
+ `^${this.dateFormatValidator.YYYYmmDDpatternString}$`
345
+ );
346
+ this.getTimeString = () => {
347
+ return `${this.getHoursString()}:${this.getMinutesString()}:${this.getSecondsString()}`;
348
+ };
349
+ this.getHoursString = () => {
350
+ return this.dateString.split("T")[1].slice(0, 8).split(":")[0];
351
+ };
352
+ this.getMinutesString = () => {
353
+ return this.dateString.split("T")[1].slice(0, 8).split(":")[1];
354
+ };
355
+ this.getSecondsString = () => {
356
+ return this.dateString.split("T")[1].slice(0, 8).split(":")[2];
357
+ };
358
+ this.getMilisecondsString = () => {
359
+ return this.dateString.split("T")[1].slice(0, 8).split(":")[3];
360
+ };
361
+ this.getJsDateTime = () => {
362
+ return new Date(this.dateString);
363
+ };
364
+ this.getIsoString = (opts) => {
365
+ if (!opts || !(opts == null ? void 0 : opts.timezone)) return this.getJsDateTime().toISOString();
366
+ const parser = new ISO8601TimezoneParser();
367
+ const validator = new ISO8601TimezoneValidator();
368
+ const timezoneInMinutes = typeof opts.timezone == "string" ? parser.toMinutes(opts.timezone) : opts.timezone;
369
+ const isValid = validator.formatIsValid(timezoneInMinutes);
370
+ if (!isValid) throw new Error("Invalid timezone format.");
371
+ const timezoneInMs = this.timeUnitConverter.minutesToMs(timezoneInMinutes);
372
+ const newDateUtcString = new Date(
373
+ this.getJsDateTime().getTime() + timezoneInMs
374
+ ).toISOString();
375
+ const newDateUtcStringWithoutTimezone = newDateUtcString.split(".")[0];
376
+ const timezoneString = parser.toString(timezoneInMinutes);
377
+ const newDateWithTimezoneString = `${newDateUtcStringWithoutTimezone}${timezoneString}`;
378
+ return newDateWithTimezoneString;
379
+ };
380
+ this.toMidnight = () => {
381
+ const currentTimeString = this.getTimeString();
382
+ const matches = new RegExp(currentTimeString).exec(this.dateString);
383
+ if (!matches || matches.length < 1) throw new Error("Error getting current time string.");
384
+ const datePlusT = this.dateString.slice(0, matches.index);
385
+ const matchedString = matches[0];
386
+ const timezone = this.dateString.slice(matchedString.length + matches.index);
387
+ return new _ISO8601DateTime(`${datePlusT}00:00:00${timezone}`);
388
+ };
389
+ const normalizedDateString = this.normalizeDateString(dateString);
390
+ if (!normalizedDateString) throw new Error("Date time format invalid.");
391
+ this.dateString = normalizedDateString;
392
+ }
393
+ normalizeDateString(dateString) {
394
+ if (this.onlyDatePattern.test(dateString)) {
395
+ return `${dateString}T00:00:00Z`;
396
+ }
397
+ if (this.dateTimePattern.test(dateString)) {
398
+ return dateString;
399
+ }
400
+ }
401
+ };
402
+
376
403
  // src/domain/entities/ISO8601Timezone.ts
377
404
  var ISO8601Timezone = class {
378
405
  constructor(originalTimezoneString) {
@@ -548,32 +575,6 @@ var ClassCreationFormSchema = z2.object({
548
575
  import { z as z3 } from "zod";
549
576
  var ClassCreationRecurrenceRuleSchema = z3.literal("daily").or(z3.literal("weekly")).or(z3.literal("week days"));
550
577
 
551
- // src/domain/entities/UserTimeSlot.ts
552
- var UserTimeSlot = class {
553
- constructor(opts) {
554
- this.getDateTimeSlot = () => {
555
- return {
556
- endDateTime: this.endDateTime,
557
- startDateTime: this.startDateTime
558
- };
559
- };
560
- this.id = opts.id;
561
- this.userId = opts.userId;
562
- this.user = opts.user;
563
- this.groupId = opts.groupId;
564
- this.startDateTime = opts.startDateTime;
565
- this.endDateTime = opts.endDateTime;
566
- this.dayOfTheWeek = this.getDayOfTheWeek();
567
- this.isAvailableTime = opts.isAvailableTime;
568
- this.course = opts.course;
569
- this.courseId = opts.courseId;
570
- this.rescheduleRequests = opts.rescheduleRequests;
571
- }
572
- getDayOfTheWeek() {
573
- return this.startDateTime.getUTCDay();
574
- }
575
- };
576
-
577
578
  // src/domain/entities/FreeTimeSlot.ts
578
579
  var FreeDateTimeSlot = class {
579
580
  constructor(opts) {
@@ -583,7 +584,7 @@ var FreeDateTimeSlot = class {
583
584
  }
584
585
  };
585
586
 
586
- // src/application/helpers/helpers/tryCatch.ts
587
+ // src/application/helpers/tryCatch.ts
587
588
  function tryCatch(callback, fallback) {
588
589
  try {
589
590
  return callback();
@@ -601,7 +602,7 @@ function tryCatchAsync(callback, fallback) {
601
602
  });
602
603
  }
603
604
 
604
- // src/application/helpers/helpers/filterAsync.ts
605
+ // src/application/helpers/filterAsync.ts
605
606
  function filterAsync(arr, predicate) {
606
607
  return __async(this, null, function* () {
607
608
  const results = yield Promise.all(arr.map(predicate));
@@ -609,7 +610,6 @@ function filterAsync(arr, predicate) {
609
610
  });
610
611
  }
611
612
  export {
612
- AsaasCustomer,
613
613
  ClassCreationFormSchema,
614
614
  ClassCreationRecurrenceRuleSchema,
615
615
  ClassStatusSchema,
@@ -619,7 +619,6 @@ export {
619
619
  ISO8601DateValidator,
620
620
  ISO8601Time,
621
621
  ISO8601TimeValidator,
622
- UserTimeSlot,
623
622
  filterAsync,
624
623
  tryCatch,
625
624
  tryCatchAsync
@@ -1,5 +1,5 @@
1
- import { IUserTimeSlot } from "../../../domain/entities/UserTimeSlot";
1
+ import { IUserTimeSlotDTO } from "../../../application/dtos/UserTimeSlotDTO";
2
2
  export type GetFixedAvailableTimeResponseBody = {
3
- fixedAvailableTimes: IUserTimeSlot[];
3
+ fixedAvailableTimes: IUserTimeSlotDTO[];
4
4
  shareableText?: string;
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eliasrrosa/tutorhub-public-assets",
3
- "version": "0.7.6",
3
+ "version": "0.8.1",
4
4
  "description": "Assets, mainly interfaces, to be shared among different Tutorhub apps.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",