@go-avro/avro-js 0.0.4-beta.3 → 0.0.4-beta.31

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 (91) hide show
  1. package/dist/auth/AuthManager.d.ts +2 -2
  2. package/dist/client/QueryClient.d.ts +55 -2
  3. package/dist/client/QueryClient.js +29 -7
  4. package/dist/client/hooks/catalog_items.js +8 -1
  5. package/dist/client/hooks/jobs.js +7 -3
  6. package/dist/client/hooks/prepayments.js +60 -1
  7. package/dist/client/hooks/proposal.js +8 -1
  8. package/dist/client/hooks/routes.js +13 -8
  9. package/dist/client/hooks/users.js +15 -1
  10. package/dist/client/hooks/waivers.d.ts +1 -0
  11. package/dist/client/hooks/waivers.js +123 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/types/api/AdditionalCharge.d.ts +5 -0
  15. package/dist/types/api/AdditionalCharge.js +1 -0
  16. package/dist/types/api/Avro.d.ts +11 -0
  17. package/dist/types/api/Avro.js +1 -0
  18. package/dist/types/api/Bill.d.ts +27 -0
  19. package/dist/types/api/Bill.js +1 -0
  20. package/dist/types/api/BillPayment.d.ts +13 -0
  21. package/dist/types/api/BillPayment.js +1 -0
  22. package/dist/types/api/BillUser.d.ts +11 -0
  23. package/dist/types/api/BillUser.js +1 -0
  24. package/dist/types/api/Break.d.ts +7 -0
  25. package/dist/types/api/Break.js +1 -0
  26. package/dist/types/api/CatalogItem.d.ts +16 -0
  27. package/dist/types/api/CatalogItem.js +1 -0
  28. package/dist/types/api/Chat.d.ts +12 -0
  29. package/dist/types/api/Chat.js +1 -0
  30. package/dist/types/api/Company.d.ts +58 -0
  31. package/dist/types/api/Company.js +1 -0
  32. package/dist/types/api/CustomLineItem.d.ts +4 -0
  33. package/dist/types/api/CustomLineItem.js +1 -0
  34. package/dist/types/api/Email.d.ts +21 -0
  35. package/dist/types/api/Email.js +1 -0
  36. package/dist/types/api/Friendship.d.ts +2 -0
  37. package/dist/types/api/Friendship.js +1 -0
  38. package/dist/types/api/Group.d.ts +12 -0
  39. package/dist/types/api/Group.js +1 -0
  40. package/dist/types/api/Job.d.ts +36 -0
  41. package/dist/types/api/Job.js +22 -0
  42. package/dist/types/api/Label.d.ts +7 -0
  43. package/dist/types/api/Label.js +1 -0
  44. package/dist/types/api/LineItem.d.ts +41 -0
  45. package/dist/types/api/LineItem.js +30 -0
  46. package/dist/types/api/MemberState.d.ts +7 -0
  47. package/dist/types/api/MemberState.js +1 -0
  48. package/dist/types/api/Message.d.ts +13 -0
  49. package/dist/types/api/Message.js +1 -0
  50. package/dist/types/api/PaymentMethod.d.ts +51 -0
  51. package/dist/types/api/PaymentMethod.js +1 -0
  52. package/dist/types/api/PaymentOption.d.ts +9 -0
  53. package/dist/types/api/PaymentOption.js +1 -0
  54. package/dist/types/api/PaymentType.d.ts +5 -0
  55. package/dist/types/api/PaymentType.js +5 -0
  56. package/dist/types/api/Plan.d.ts +13 -0
  57. package/dist/types/api/Plan.js +1 -0
  58. package/dist/types/api/PlanPayment.d.ts +10 -0
  59. package/dist/types/api/PlanPayment.js +1 -0
  60. package/dist/types/api/Prepayment.d.ts +15 -0
  61. package/dist/types/api/Prepayment.js +7 -0
  62. package/dist/types/api/Reaction.d.ts +8 -0
  63. package/dist/types/api/Reaction.js +1 -0
  64. package/dist/types/api/Route.d.ts +37 -0
  65. package/dist/types/api/Route.js +82 -0
  66. package/dist/types/api/RouteJob.d.ts +15 -0
  67. package/dist/types/api/RouteJob.js +5 -0
  68. package/dist/types/api/ServiceMonth.d.ts +7 -0
  69. package/dist/types/api/ServiceMonth.js +1 -0
  70. package/dist/types/api/Session.d.ts +13 -0
  71. package/dist/types/api/Session.js +1 -0
  72. package/dist/types/api/Skill.d.ts +7 -0
  73. package/dist/types/api/Skill.js +1 -0
  74. package/dist/types/api/Subscription.d.ts +8 -0
  75. package/dist/types/api/Subscription.js +1 -0
  76. package/dist/types/api/Task.d.ts +57 -0
  77. package/dist/types/api/Task.js +74 -0
  78. package/dist/types/api/User.d.ts +23 -0
  79. package/dist/types/api/User.js +1 -0
  80. package/dist/types/api/UserCompanyAssociation.d.ts +71 -0
  81. package/dist/types/api/UserCompanyAssociation.js +53 -0
  82. package/dist/types/api/UserEvent.d.ts +13 -0
  83. package/dist/types/api/UserEvent.js +1 -0
  84. package/dist/types/api/Waiver.d.ts +9 -0
  85. package/dist/types/api/Waiver.js +1 -0
  86. package/dist/types/api/_Event.d.ts +19 -0
  87. package/dist/types/api/_Event.js +1 -0
  88. package/dist/types/api.d.ts +43 -587
  89. package/dist/types/api.js +37 -74
  90. package/dist/types/cache.d.ts +2 -2
  91. package/package.json +1 -1
@@ -0,0 +1,13 @@
1
+ export interface BillPayment {
2
+ id: string;
3
+ amount: number;
4
+ avro_fees: number;
5
+ stripe_fees: number;
6
+ stripe_pi_id: string;
7
+ bill_user_id: string;
8
+ status: "created" | "processing" | "succeeded" | "failed" | "canceled" | "requires_action";
9
+ type: "us_bank_account" | "card";
10
+ action_required_at: number;
11
+ time_created: number;
12
+ time_updated: number | null;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { BillPayment } from "../../types/api/BillPayment";
2
+ export interface BillUser {
3
+ id: string;
4
+ user_id: string;
5
+ bill_id: string;
6
+ invoice_id: string;
7
+ payment_attempts: BillPayment[];
8
+ time_created: number;
9
+ time_updated: number | null;
10
+ amount: number;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface Break {
2
+ id: string;
3
+ time_started: number;
4
+ time_ended: number;
5
+ company_billable: boolean;
6
+ client_billable: boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { PaymentOption } from "../../types/api/PaymentOption";
2
+ export interface CatalogItem {
3
+ id: string;
4
+ name: string;
5
+ company_id: string;
6
+ description: string;
7
+ industry: string;
8
+ price_format: string;
9
+ payment_options: PaymentOption[];
10
+ recommended_frequency?: number | null;
11
+ recommended_activate_on?: number | null;
12
+ recommended_expire_on?: number | null;
13
+ time_created: number;
14
+ time_updated: number | null;
15
+ skills: string[];
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Message } from "../../types/api/Message";
2
+ import { MemberState } from "../../types/api/MemberState";
3
+ export interface Chat {
4
+ id: string;
5
+ name: string;
6
+ company_id: string;
7
+ time_created: number;
8
+ time_updated: number;
9
+ last_message: Message;
10
+ user_state: MemberState[];
11
+ messages: Message[];
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { Bill } from "../../types/api/Bill";
2
+ import { Email } from "../../types/api/Email";
3
+ import { Group } from "../../types/api/Group";
4
+ import { Label } from "../../types/api/Label";
5
+ import { PaymentMethod } from "../../types/api/PaymentMethod";
6
+ import { PaymentType } from "../../types/api/PaymentType";
7
+ import { Plan } from "../../types/api/Plan";
8
+ import { PlanPayment } from "../../types/api/PlanPayment";
9
+ import { Session } from "../../types/api/Session";
10
+ import { Skill } from "../../types/api/Skill";
11
+ import { UserCompanyAssociation } from "../../types/api/UserCompanyAssociation";
12
+ import { CatalogItem } from "../../types/api/CatalogItem";
13
+ export interface Company {
14
+ id: string;
15
+ name: string;
16
+ email: string;
17
+ emails: Email[];
18
+ skills: Skill[];
19
+ catalog_items: CatalogItem[];
20
+ time_created: number;
21
+ time_updated: number | null;
22
+ users: UserCompanyAssociation[];
23
+ use_client_side_customer_start_billing: boolean;
24
+ use_client_side_customer_stop_billing: boolean;
25
+ use_client_side_employee_start_billing: boolean;
26
+ use_client_side_employee_stop_billing: boolean;
27
+ logo_url: string;
28
+ delay_scalar: number;
29
+ payments: PlanPayment[];
30
+ overdue_threshold: number;
31
+ stripe_account_id: string;
32
+ is_restricted: boolean;
33
+ disabled_reason: string;
34
+ completed_onboarding: boolean;
35
+ restricted_soon: boolean;
36
+ service_email_id: string;
37
+ billing_email_id: string;
38
+ num_events: number;
39
+ num_jobs: number;
40
+ num_routes: number;
41
+ num_teams: number;
42
+ num_skills: number;
43
+ bills: Bill[];
44
+ enabled_payment_methods: PaymentType[];
45
+ sessions: Session[];
46
+ num_sessions: number;
47
+ labels: Label[];
48
+ groups: Group[];
49
+ indicator_lifetime: number;
50
+ available_plans: Plan[];
51
+ last_payment: number;
52
+ last_charged: number;
53
+ balance: number;
54
+ plan_id: string;
55
+ payment_methods: PaymentMethod[];
56
+ intuit_connected: boolean;
57
+ next_payment_due: number | null;
58
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ export interface CustomLineItem extends LineItem {
3
+ line_item_type: "CUSTOM";
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { User } from "../../types/api/User";
2
+ export interface Email {
3
+ id: string;
4
+ company_id: string;
5
+ name: string;
6
+ mail_server: string;
7
+ mail_port: number;
8
+ mail_username: string;
9
+ mail_password: string | null;
10
+ mail_default_sender: string;
11
+ mail_use_tls: boolean;
12
+ mail_use_ssl: boolean;
13
+ mail_api_key: string;
14
+ is_company_wide: boolean;
15
+ users: User[];
16
+ type: "OUTLOOK" | "SMTP" | "GMAIL";
17
+ access_token?: string;
18
+ access_token_expiry?: number;
19
+ refresh_token?: string;
20
+ refresh_token_expiry?: number;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export interface Friendship {
2
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Permission } from "../../types/api/UserCompanyAssociation";
2
+ export interface Group {
3
+ id: string;
4
+ name: string;
5
+ is_active: boolean;
6
+ is_user_type: boolean;
7
+ users: string[];
8
+ permissions: Permission[];
9
+ company_id: string;
10
+ time_created: number;
11
+ time_updated: number;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { Task } from "../../types/api/Task";
2
+ import { _Event } from "../../types/api/_Event";
3
+ import { RouteJob } from "../../types/api/RouteJob";
4
+ import { Subscription } from "../../types/api/Subscription";
5
+ declare module '../../types/api/Job' {
6
+ interface Job {
7
+ address: string;
8
+ company: string;
9
+ description: string;
10
+ id: string;
11
+ is_one_time: boolean;
12
+ autostart_radius: number;
13
+ latitude: number;
14
+ longitude: number;
15
+ name: string;
16
+ internal_notes: string;
17
+ external_notes: string;
18
+ priority: number;
19
+ tasks: Partial<Task>[];
20
+ time_created: number;
21
+ time_updated: number | null;
22
+ routes: RouteJob[];
23
+ subscribers: Subscription[];
24
+ manual_emails: string[][];
25
+ overdue_time: number;
26
+ last_completed_event: _Event | null;
27
+ current_event: _Event | null;
28
+ labels: string[];
29
+ owner: string;
30
+ }
31
+ }
32
+ export declare class Job {
33
+ constructor(init?: Partial<Job>);
34
+ portionDone: (fallback?: Date | null, routeJob?: RouteJob) => number;
35
+ isDone: (fallback?: Date | null, routeJob?: RouteJob) => boolean;
36
+ }
@@ -0,0 +1,22 @@
1
+ import { Task } from "../../types/api/Task";
2
+ import { RouteJob } from "../../types/api/RouteJob";
3
+ export class Job {
4
+ constructor(init) {
5
+ this.portionDone = (fallback, routeJob) => {
6
+ if (!this.tasks || this.tasks.length === 0) {
7
+ return 0;
8
+ }
9
+ return this.tasks.filter(t => t.isDone?.(fallback) && (!routeJob || !t.id || routeJob.tasks.includes(t.id))).length / this.tasks.length;
10
+ };
11
+ this.isDone = (fallback, routeJob) => {
12
+ return this.portionDone(fallback, routeJob) === 1;
13
+ };
14
+ Object.assign(this, init);
15
+ if (init?.tasks) {
16
+ this.tasks = init.tasks.map(t => new Task(t));
17
+ }
18
+ if (init?.routes) {
19
+ this.routes = init.routes.map(r => new RouteJob(r));
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ export interface Label {
2
+ name: string;
3
+ id: string;
4
+ company_id: string;
5
+ color: string;
6
+ jobs: string[];
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ export declare const LineItemStatus: {
2
+ readonly CREATED: "CREATED";
3
+ readonly EXTERNALLY_BILLED: "EXTERNALLY_BILLED";
4
+ readonly BILLED: "BILLED";
5
+ readonly PROCESSING: "PROCESSING";
6
+ readonly EXTERNALLY_PAID: "EXTERNALLY_PAID";
7
+ readonly PREPAID: "PREPAID";
8
+ readonly PAID: "PAID";
9
+ };
10
+ export type LineItemStatus = typeof LineItemStatus[keyof typeof LineItemStatus];
11
+ export declare const LineItemType: {
12
+ readonly CUSTOM: "CUSTOM";
13
+ readonly ADDITIONAL_CHARGE: "ADDITIONAL_CHARGE";
14
+ readonly EVENT: "EVENT";
15
+ readonly SERVICE_MONTH: "SERVICE_MONTH";
16
+ readonly PREPAYMENT: "PREPAYMENT";
17
+ };
18
+ export type LineItemType = typeof LineItemType[keyof typeof LineItemType];
19
+ declare module '../../types/api/LineItem' {
20
+ interface LineItem {
21
+ id: string;
22
+ line_item_type: LineItemType;
23
+ name: string;
24
+ description: string;
25
+ cost: number;
26
+ amount: number;
27
+ status: LineItemStatus;
28
+ job_id: string;
29
+ job_name: string;
30
+ job_address: string;
31
+ job_labels: string[];
32
+ company_id: string;
33
+ time_created: number;
34
+ }
35
+ }
36
+ export declare class LineItem {
37
+ constructor(init?: Partial<LineItem>);
38
+ isPaid: () => boolean;
39
+ isBilled: () => boolean;
40
+ isUnbilled: () => boolean;
41
+ }
@@ -0,0 +1,30 @@
1
+ export const LineItemStatus = {
2
+ CREATED: "CREATED",
3
+ EXTERNALLY_BILLED: "EXTERNALLY_BILLED",
4
+ BILLED: "BILLED",
5
+ PROCESSING: "PROCESSING",
6
+ EXTERNALLY_PAID: "EXTERNALLY_PAID",
7
+ PREPAID: "PREPAID",
8
+ PAID: "PAID",
9
+ };
10
+ export const LineItemType = {
11
+ CUSTOM: "CUSTOM",
12
+ ADDITIONAL_CHARGE: "ADDITIONAL_CHARGE",
13
+ EVENT: "EVENT",
14
+ SERVICE_MONTH: "SERVICE_MONTH",
15
+ PREPAYMENT: "PREPAYMENT",
16
+ };
17
+ export class LineItem {
18
+ constructor(init) {
19
+ this.isPaid = () => {
20
+ return this.status === LineItemStatus.PAID || this.status === LineItemStatus.PREPAID || this.status === LineItemStatus.EXTERNALLY_PAID;
21
+ };
22
+ this.isBilled = () => {
23
+ return this.status === LineItemStatus.BILLED || this.status === LineItemStatus.EXTERNALLY_BILLED;
24
+ };
25
+ this.isUnbilled = () => {
26
+ return !this.isBilled() && !this.isPaid();
27
+ };
28
+ Object.assign(this, init);
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ import { Friendship } from "../../types/api/Friendship";
2
+ export interface MemberState {
3
+ id: string;
4
+ state: string;
5
+ friendship: Friendship | null;
6
+ last_message_read_at: number | null;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Reaction } from "../../types/api/Reaction";
2
+ export interface Message {
3
+ id: string;
4
+ chat_id: string;
5
+ sender_id: string;
6
+ reply_to_id: string;
7
+ content: string;
8
+ reactions: Reaction[];
9
+ time_created: number;
10
+ time_updated: number;
11
+ time_sent: number;
12
+ message: string;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { PaymentType } from "../../types/api/PaymentType";
2
+ export interface PaymentMethod {
3
+ allow_redisplay: string;
4
+ autopay: boolean;
5
+ billing_details: {
6
+ email: string;
7
+ name: string;
8
+ };
9
+ created: number;
10
+ customer: string;
11
+ id: string;
12
+ type: PaymentType;
13
+ us_bank_account: {
14
+ account_holder_type: string;
15
+ account_type: string;
16
+ bank_name: string;
17
+ financial_connections_account: string;
18
+ fingerprint: string;
19
+ last4: string;
20
+ networks: {
21
+ preferred: string;
22
+ supported: string[];
23
+ };
24
+ routing_number: string;
25
+ status_details: object;
26
+ } | null;
27
+ card: {
28
+ brand: string;
29
+ checks: {
30
+ address_line1_check: string;
31
+ address_postal_code_check: string;
32
+ cvc_check: string;
33
+ };
34
+ country: string;
35
+ exp_month: number;
36
+ exp_year: number;
37
+ fingerprint: string;
38
+ funding: string;
39
+ last4: string;
40
+ networks: {
41
+ preferred: string;
42
+ supported: string[];
43
+ };
44
+ three_d_secure_usage: {
45
+ supported: boolean;
46
+ };
47
+ wallet: {
48
+ type: string;
49
+ } | null;
50
+ } | null;
51
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export interface PaymentOption {
2
+ name: string;
3
+ id: string;
4
+ is_prepay: boolean;
5
+ price_under_prepay?: number;
6
+ price: number;
7
+ recommended_prepay_count?: number;
8
+ mode: "MONTH" | "SERVICE";
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export type PaymentType = typeof PaymentType[keyof typeof PaymentType];
2
+ export declare const PaymentType: {
3
+ readonly US_BANK_ACCOUNT: "us_bank_account";
4
+ readonly CARD: "card";
5
+ };
@@ -0,0 +1,5 @@
1
+ // eslint-disable-next-line no-redeclare
2
+ export const PaymentType = {
3
+ US_BANK_ACCOUNT: "us_bank_account",
4
+ CARD: "card",
5
+ };
@@ -0,0 +1,13 @@
1
+ export interface Plan {
2
+ id: string;
3
+ name: string;
4
+ base_rate: number;
5
+ price_per_job: number;
6
+ description: string;
7
+ referral_codes: string[];
8
+ trial_period_days: number;
9
+ time_created: number;
10
+ time_updated: number;
11
+ available_to_new_companies?: boolean;
12
+ available_to?: string[];
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface PlanPayment {
2
+ id: string;
3
+ amount: number;
4
+ stripe_pi_id: string;
5
+ company_id: string;
6
+ plan_id: string;
7
+ status: "created" | "processing" | "succeeded" | "failed" | "canceled";
8
+ time_created: number;
9
+ time_updated: number;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ declare module '../../types/api/Prepayment' {
3
+ interface Prepayment extends LineItem {
4
+ id: string;
5
+ task_id: string | null;
6
+ line_item_type: "PREPAYMENT";
7
+ type: "SERVICE" | "MONTH";
8
+ time_updated: number | null;
9
+ num_events: number;
10
+ num_service_months: number;
11
+ }
12
+ }
13
+ export declare class Prepayment extends LineItem {
14
+ constructor(init?: Partial<Prepayment>);
15
+ }
@@ -0,0 +1,7 @@
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ export class Prepayment extends LineItem {
3
+ constructor(init) {
4
+ super(init);
5
+ Object.assign(this, init);
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ export interface Reaction {
2
+ id: string;
3
+ message_id: string;
4
+ sender_id: string;
5
+ reaction: string;
6
+ time_created: number;
7
+ time_updated: number;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import { RouteJob } from "../../types/api/RouteJob";
2
+ export declare const FrequencyType: {
3
+ readonly ONCE: "ONCE";
4
+ readonly DAILY: "DAILY";
5
+ readonly WEEKLY: "WEEKLY";
6
+ readonly BIWEEKLY: "BIWEEKLY";
7
+ readonly MONTHLY: "MONTHLY";
8
+ readonly YEARLY: "YEARLY";
9
+ };
10
+ export type FrequencyType = typeof FrequencyType[keyof typeof FrequencyType];
11
+ declare module '../../types/api/Route' {
12
+ interface Route {
13
+ company: string;
14
+ id: string;
15
+ is_internal: boolean;
16
+ jobs: RouteJob[];
17
+ name: string;
18
+ time_created: number;
19
+ time_updated: number | null;
20
+ teams: string[];
21
+ polyline: string;
22
+ is_optimized: boolean;
23
+ start_time: number;
24
+ end_time: number;
25
+ start_latitude: number;
26
+ start_longitude: number;
27
+ end_latitude: number;
28
+ end_longitude: number;
29
+ frequency: typeof FrequencyType[keyof typeof FrequencyType];
30
+ }
31
+ }
32
+ export declare class Route {
33
+ constructor(init?: Partial<Route>);
34
+ getNextOccurrences: (count?: number) => (Date | null)[];
35
+ getNextOccurrence: (after?: Date) => Date | null;
36
+ getIndicatorExpiration: () => Date;
37
+ }
@@ -0,0 +1,82 @@
1
+ import { RouteJob } from "../../types/api/RouteJob";
2
+ export const FrequencyType = {
3
+ ONCE: "ONCE",
4
+ DAILY: "DAILY",
5
+ WEEKLY: "WEEKLY",
6
+ BIWEEKLY: "BIWEEKLY",
7
+ MONTHLY: "MONTHLY",
8
+ YEARLY: "YEARLY",
9
+ };
10
+ export class Route {
11
+ constructor(init) {
12
+ this.getNextOccurrences = (count = 1) => {
13
+ let next_occurrences = [];
14
+ for (let i = 0; i < count; i++) {
15
+ next_occurrences.push(this.getNextOccurrence(next_occurrences.length > 0 ? next_occurrences[next_occurrences.length - 1] ?? new Date() : new Date()));
16
+ }
17
+ return next_occurrences;
18
+ };
19
+ this.getNextOccurrence = (after = new Date()) => {
20
+ let next_occurrence = new Date(this.start_time * 1000);
21
+ while (next_occurrence <= after) {
22
+ switch (this.frequency) {
23
+ case FrequencyType.ONCE:
24
+ return null;
25
+ case FrequencyType.DAILY:
26
+ next_occurrence.setDate(next_occurrence.getDate() + 1);
27
+ break;
28
+ case FrequencyType.WEEKLY:
29
+ next_occurrence.setDate(next_occurrence.getDate() + 7);
30
+ break;
31
+ case FrequencyType.BIWEEKLY:
32
+ next_occurrence.setDate(next_occurrence.getDate() + 14);
33
+ break;
34
+ case FrequencyType.MONTHLY:
35
+ next_occurrence.setMonth(next_occurrence.getMonth() + 1);
36
+ break;
37
+ case FrequencyType.YEARLY:
38
+ next_occurrence.setFullYear(next_occurrence.getFullYear() + 1);
39
+ break;
40
+ }
41
+ }
42
+ return next_occurrence;
43
+ };
44
+ this.getIndicatorExpiration = () => {
45
+ const start_time = new Date(this.start_time * 1000);
46
+ if (this.frequency === FrequencyType.ONCE) {
47
+ return start_time;
48
+ }
49
+ // if the route is currently active, return the start time as the indicator expiration
50
+ if (Date.now() > start_time.getTime()) {
51
+ return start_time;
52
+ }
53
+ // else compute the previous occurrence and return that as the indicator expiration
54
+ const prev = new Date(start_time);
55
+ switch (this.frequency) {
56
+ case FrequencyType.DAILY:
57
+ prev.setHours(prev.getHours() - 4);
58
+ prev.setDate(prev.getDate() - 1);
59
+ break;
60
+ case FrequencyType.WEEKLY:
61
+ prev.setDate(prev.getDate() - 8);
62
+ break;
63
+ case FrequencyType.BIWEEKLY:
64
+ prev.setDate(prev.getDate() - 15);
65
+ break;
66
+ case FrequencyType.MONTHLY:
67
+ prev.setDate(prev.getDate() - 1);
68
+ prev.setMonth(prev.getMonth() - 1);
69
+ break;
70
+ case FrequencyType.YEARLY:
71
+ prev.setDate(prev.getDate() - 1);
72
+ prev.setFullYear(prev.getFullYear() - 1);
73
+ break;
74
+ }
75
+ return prev;
76
+ };
77
+ Object.assign(this, init);
78
+ if (init?.jobs) {
79
+ this.jobs = init.jobs.map(j => new RouteJob(j));
80
+ }
81
+ }
82
+ }