autopilot-core-sandbox 0.0.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.
- package/README.md +53 -0
- package/dist/Provider.d.ts +21 -0
- package/dist/Provider.d.ts.map +1 -0
- package/dist/Provider.js +61 -0
- package/dist/Provider.js.map +1 -0
- package/dist/dist/Provider.d.ts +21 -0
- package/dist/dist/Provider.d.ts.map +1 -0
- package/dist/dist/Provider.js +61 -0
- package/dist/dist/Provider.js.map +1 -0
- package/dist/dist/index.d.ts +45 -0
- package/dist/dist/index.d.ts.map +1 -0
- package/dist/dist/index.js +61 -0
- package/dist/dist/index.js.map +1 -0
- package/dist/dist/interfaces/index.d.ts +1238 -0
- package/dist/dist/interfaces/index.d.ts.map +1 -0
- package/dist/dist/interfaces/index.js +3 -0
- package/dist/dist/interfaces/index.js.map +1 -0
- package/dist/dist/migrations/20260608222757_remote_schema.sql +5666 -0
- package/dist/dist/migrations/20260611174826_add_job_item_recurring_id_to_job_item.sql +7 -0
- package/dist/dist/migrations/20260625224612_add_dashboard_guided_tour_dismissed_to_settings_user.sql +5 -0
- package/dist/dist/migrations/20260627031433_support_chat_tables.sql +115 -0
- package/dist/dist/migrations/20260627031434_support_chat_rls.sql +37 -0
- package/dist/dist/migrations/20260704170209_add_estimate_scheduling.sql +121 -0
- package/dist/dist/migrations/20260704170210_add_estimate_scheduling_rls.sql +42 -0
- package/dist/dist/migrations/20260704235034_add_estimate_reminder_settings.sql +11 -0
- package/dist/dist/migrations/20260707003825_blocked_number_table.sql +32 -0
- package/dist/dist/migrations/20260707003826_blocked_number_rls.sql +22 -0
- package/dist/dist/migrations/20260709191055_sms_opt_out_table.sql +38 -0
- package/dist/dist/migrations/20260709191056_sms_opt_out_rls.sql +21 -0
- package/dist/dist/migrations/20260709214507_job_time_entry_table.sql +70 -0
- package/dist/dist/migrations/20260709214508_job_time_entry_rls.sql +21 -0
- package/dist/dist/migrations/20260711185956_phone_call_table.sql +99 -0
- package/dist/dist/migrations/20260711185957_phone_call_rls.sql +25 -0
- package/dist/dist/migrations/20260712014705_ai_voice_assistant_settings.sql +71 -0
- package/dist/dist/migrations/20260712014706_ai_voice_assistant_settings_rls.sql +14 -0
- package/dist/dist/migrations/20260712014707_ai_prompt_templates.sql +28 -0
- package/dist/dist/migrations/20260712014708_ai_prompt_templates_rls.sql +5 -0
- package/dist/dist/migrations/20260712014709_ai_prompt_templates_seed.sql +77 -0
- package/dist/dist/migrations/20260715011550_reminder_dispatch_table.sql +47 -0
- package/dist/dist/migrations/20260715011551_reminder_dispatch_rls.sql +22 -0
- package/dist/dist/migrations/20260715192923_dedup_sequence_contact_add_unique_constraint.sql +27 -0
- package/dist/dist/migrations/20260716194420_add_employee_location_tracking.sql +146 -0
- package/dist/dist/migrations/20260716194421_add_employee_location_tracking_rls.sql +154 -0
- package/dist/dist/migrations/20260716194422_get_client_map_last_completed_jobs.sql +28 -0
- package/dist/dist/migrations/20260717144535_add_blast_email_invalid_skipped_count.sql +2 -0
- package/dist/dist/migrations/20260717162900_create_blast_email_chunk.sql +36 -0
- package/dist/dist/migrations/20260717162901_add_blast_email_chunk_rls.sql +5 -0
- package/dist/dist/migrations/20260717162902_add_blast_email_chunk_progress_columns.sql +3 -0
- package/dist/dist/migrations/20260717162903_add_blast_email_bounce_tracking_columns.sql +4 -0
- package/dist/dist/migrations/20260717162904_create_email_hard_bounced.sql +23 -0
- package/dist/dist/migrations/20260717162905_add_email_hard_bounced_rls.sql +5 -0
- package/dist/dist/migrations/20260717164837_add_sequence_contact_sent_at.sql +19 -0
- package/dist/dist/migrations/20260717170920_add_sequence_contact_claim_index.sql +12 -0
- package/dist/dist/migrations/20260719215139_create_outbound_event.sql +59 -0
- package/dist/dist/migrations/20260719215140_create_outbound_event_rls.sql +16 -0
- package/dist/dist/migrations/20260719215141_create_webhook_delivery.sql +99 -0
- package/dist/dist/migrations/20260719215142_create_webhook_delivery_rls.sql +11 -0
- package/dist/dist/migrations/20260719215143_outbound_event_triggers.sql +219 -0
- package/dist/dist/migrations/20260719215144_create_api_key.sql +34 -0
- package/dist/dist/migrations/20260719215146_create_api_key_rls.sql +12 -0
- package/dist/dist/migrations/20260719215147_webhook_subscription_add_secret_active.sql +28 -0
- package/dist/dist/migrations/20260719215148_api_aggregate_create_functions.sql +479 -0
- package/dist/dist/migrations/20260721174837_webhook_subscription_generic_endpoints.sql +41 -0
- package/dist/dist/migrations/20260721185631_webhook_outbox_retention.sql +87 -0
- package/dist/dist/migrations/20260721190304_create_qb_sync_task.sql +120 -0
- package/dist/dist/migrations/20260721190306_qb_sync_task_rls.sql +8 -0
- package/dist/dist/migrations/20260721190307_qb_mapping_orphan_fks.sql +29 -0
- package/dist/dist/migrations/20260721190308_qb_task_retention.sql +90 -0
- package/dist/dist/migrations/20260721234401_create_permission_role.sql +83 -0
- package/dist/dist/migrations/20260721234402_permission_role_rls.sql +22 -0
- package/dist/dist/migrations/20260721234403_user_role_add_permission_role_id.sql +12 -0
- package/dist/dist/migrations/20260721234404_seed_permission_roles.sql +100 -0
- package/dist/dist/migrations/20260721234405_backfill_user_role_permission_role_id.sql +20 -0
- package/dist/dist/migrations/20260722193800_permission_role_add_manage_employees.sql +56 -0
- package/dist/dist/migrations/20260723025606_staging_new_employee_company_read_rls.sql +10 -0
- package/dist/dist/migrations/20260723134328_create_google_lsa_integration.sql +1016 -0
- package/dist/dist/migrations/20260723134329_google_lsa_integration_rls.sql +205 -0
- package/dist/dist/migrations/20260723150640_google_lsa_hardening.sql +169 -0
- package/dist/dist/migrations/20260723150641_google_lsa_hardening_rls.sql +12 -0
- package/dist/dist/migrations/20260724230721_google_lsa_facebook_exclusivity_attach.sql +104 -0
- package/dist/dist/migrations/20260724230722_google_lsa_facebook_exclusivity_attach_rls.sql +20 -0
- package/dist/dist/migrations/20260725172630_add_message_pagination_and_search.sql +265 -0
- package/dist/dist/migrations/20260725172631_add_message_pagination_and_search_rls.sql +72 -0
- package/dist/dist/migrations/20260725172632_optimize_message_thread_pagination_search.sql +245 -0
- package/dist/dist/migrations/20260725172633_harden_message_search_and_photo_pagination.sql +256 -0
- package/dist/dist/migrations/20260725172634_fix_message_thread_line_filter.sql +250 -0
- package/dist/dist/migrations/20260725174948_google_lsa_attach_bing_exclusivity_guard.sql +23 -0
- package/dist/dist/migrations/20260725200430_client_portal_settings.sql +41 -0
- package/dist/dist/migrations/20260725200431_client_portal_settings_rls.sql +21 -0
- package/dist/dist/migrations/20260725200433_client_portal_auth_tables.sql +81 -0
- package/dist/dist/migrations/20260725200434_client_portal_auth_rls.sql +18 -0
- package/dist/dist/migrations/20260725200435_portal_claim_login_attempt.sql +36 -0
- package/dist/dist/migrations/20260725200436_portal_appointment_request.sql +39 -0
- package/dist/dist/migrations/20260725200437_portal_appointment_request_rls.sql +10 -0
- package/dist/dist/migrations/20260725210000_google_reserve_integration.sql +85 -0
- package/dist/dist/migrations/20260725210001_google_reserve_integration_rls.sql +10 -0
- package/dist/dist/migrations/20260725220000_add_analytics_query_indexes.sql +47 -0
- package/dist/dist/migrations/20260725230000_onboarding_preload_data.sql +1074 -0
- package/dist/dist/migrations/20260725230001_onboarding_preload_data_rls.sql +40 -0
- package/dist/dist/migrations/20260725230002_add_pricebook_query_indexes.sql +13 -0
- package/dist/dist/migrations/20260726000000_facebook_ads_integration.sql +1538 -0
- package/dist/dist/migrations/20260726000001_facebook_ads_integration_rls.sql +356 -0
- package/dist/dist/migrations/20260726000002_facebook_ads_attach_lsa_exclusivity_guard.sql +25 -0
- package/dist/dist/migrations/20260726000003_facebook_ads_attach_bing_exclusivity_guard.sql +22 -0
- package/dist/dist/migrations/20260726010000_create_bing_ads_integration.sql +1112 -0
- package/dist/dist/migrations/20260726010001_bing_ads_integration_rls.sql +227 -0
- package/dist/dist/migrations/20260726220000_add_document_theme_settings.sql +11 -0
- package/dist/dist/migrations/20260726220001_update_document_theme_comments.sql +7 -0
- package/dist/dist/migrations/20260727210319_evolve_tier_for_pricing.sql +68 -0
- package/dist/dist/migrations/20260727210320_create_billing_addon.sql +85 -0
- package/dist/dist/migrations/20260727210321_create_billing_addon_rls.sql +21 -0
- package/dist/dist/migrations/20260728213930_create_usage_metering.sql +189 -0
- package/dist/dist/migrations/20260728213931_create_usage_metering_rls.sql +32 -0
- package/dist/dist/migrations/20260729004305_marketing_charge_txn_functions.sql +242 -0
- package/dist/dist/migrations/20260729004306_marketing_charge_txn_functions_rls.sql +37 -0
- package/dist/dist/migrations/20260729005524_update_deduct_from_balance_errcode.sql +42 -0
- package/dist/dist/migrations/20260730193601_fix_deduct_from_balance_lost_update.sql +46 -0
- package/dist/dist/migrations/20260730193602_add_blast_sms_chunk_reaper_columns.sql +27 -0
- package/dist/dist/migrations/20260731011415_create_google_calendar_connection.sql +84 -0
- package/dist/dist/migrations/20260731011416_google_calendar_connection_rls.sql +23 -0
- package/dist/dist/migrations/20260731011417_create_google_calendar_sync.sql +157 -0
- package/dist/dist/migrations/20260731011418_google_calendar_sync_rls.sql +26 -0
- package/dist/dist/migrations/20260731011419_event_outbound_triggers.sql +28 -0
- package/dist/dist/migrations/20260731011420_add_google_calendar_addon_key.sql +24 -0
- package/dist/dist/migrations/20260731011421_gcal_task_retention.sql +109 -0
- package/dist/dist/migrations/20260731234245_create_estimate_proposal.sql +157 -0
- package/dist/dist/migrations/20260731234247_estimate_proposal_rls.sql +46 -0
- package/dist/dist/migrations/20260731234248_add_proposal_estimate_settings.sql +17 -0
- package/dist/dist/migrations/20260731234249_add_estimate_proposals_addon_key.sql +25 -0
- package/dist/dist/migrations/20260731234250_approve_estimate_proposal_function.sql +133 -0
- package/dist/dist/migrations/20260801010609_save_estimate_proposal_function.sql +154 -0
- package/dist/dist/migrations/20260801173554_add_hide_autopilot_branding_setting.sql +6 -0
- package/dist/dist/migrations/20260806230917_add_client_billing_address_columns.sql +9 -0
- package/dist/dist/migrations/20260806230944_api_create_client_billing_address.sql +93 -0
- package/dist/dist/migrations/20260807014702_create_parent_id_company_id_keys.sql +20 -0
- package/dist/dist/migrations/20260807014703_create_contract_template.sql +30 -0
- package/dist/dist/migrations/20260807014704_create_contract.sql +233 -0
- package/dist/dist/migrations/20260807014705_create_contract_signature.sql +39 -0
- package/dist/dist/migrations/20260807014706_create_item_contract_requirement.sql +38 -0
- package/dist/dist/migrations/20260807014707_create_settings_contract.sql +23 -0
- package/dist/dist/migrations/20260807014708_contract_rls.sql +74 -0
- package/dist/dist/migrations/20260807014709_sign_contract_function.sql +92 -0
- package/dist/dist/migrations/20260807014710_create_settings_rental.sql +34 -0
- package/dist/dist/migrations/20260807014711_create_saved_location.sql +56 -0
- package/dist/dist/migrations/20260807014712_create_rental_task_option.sql +52 -0
- package/dist/dist/migrations/20260807014713_create_asset.sql +90 -0
- package/dist/dist/migrations/20260807014714_add_job_schedule_asset_fkeys.sql +39 -0
- package/dist/dist/migrations/20260807014715_rental_rls.sql +48 -0
- package/dist/dist/migrations/20260807014716_add_job_schedule_any_time.sql +7 -0
- package/dist/dist/migrations/20260807014717_add_job_schedule_target_location.sql +48 -0
- package/dist/dist/migrations/20260807014718_job_schedule_completion_guard.sql +53 -0
- package/dist/dist/migrations/20260807014719_add_job_schedule_list_sort_key.sql +7 -0
- package/dist/dist/migrations/20260807014720_add_item_duration.sql +11 -0
- package/dist/dist/migrations/20260807014721_add_settings_booking_enforce_rental_availability.sql +9 -0
- package/dist/dist/migrations/20260807014722_add_job_unsigned_rental_agreement.sql +10 -0
- package/dist/dist/migrations/20260807014723_add_item_size.sql +12 -0
- package/dist/dist/migrations/20260809193533_add_booking_path_button_labels.sql +11 -0
- package/dist/dist/migrations/20260809231721_add_route_distance_cache.sql +37 -0
- package/dist/dist/migrations/20260809231722_route_distance_cache_rls.sql +15 -0
- package/dist/dist/migrations/20260809231723_apply_rental_route_plan_function.sql +275 -0
- package/dist/dist/migrations/20260810171550_add_settings_job_default_job_types.sql +9 -0
- package/dist/dist/migrations/20260810212430_backfill_rental_task_option_sort_order.sql +61 -0
- package/dist/dist/migrations/20260811224317_add_settings_user_dnd_hint_dismissed.sql +9 -0
- package/dist/dist/migrations/20260813174503_repair_user_role_email_drift.sql +59 -0
- package/dist/dist/migrations/20260813174504_sync_user_role_email_trigger.sql +30 -0
- package/dist/dist/migrations/20260813175210_add_event_list_sort_key.sql +5 -0
- package/dist/dist/migrations/20260814172222_add_client_auto_bill_on_completion.sql +6 -0
- package/dist/dist/migrations/20260816160252_create_automation_rule.sql +99 -0
- package/dist/dist/migrations/20260816160253_automation_rule_rls.sql +19 -0
- package/dist/dist/migrations/20260816160254_create_settings_automation.sql +36 -0
- package/dist/dist/migrations/20260816160255_settings_automation_rls.sql +18 -0
- package/dist/dist/migrations/20260816160256_create_automation_event.sql +71 -0
- package/dist/dist/migrations/20260816160257_automation_event_rls.sql +12 -0
- package/dist/dist/migrations/20260816160258_create_automation_run.sql +129 -0
- package/dist/dist/migrations/20260816160259_automation_run_rls.sql +19 -0
- package/dist/dist/migrations/20260816160300_add_client_created_via.sql +25 -0
- package/dist/dist/migrations/20260816160301_add_estimate_sent_at.sql +39 -0
- package/dist/dist/migrations/20260816160302_add_message_automation_ref.sql +10 -0
- package/dist/dist/migrations/20260816160303_automation_event_triggers.sql +236 -0
- package/dist/dist/migrations/20260816160304_automation_retention.sql +142 -0
- package/dist/dist/migrations/20260816202404_add_automation_center_addon_key.sql +26 -0
- package/dist/dist/migrations/20260816225501_widen_automation_rule_trigger_action_checks.sql +25 -0
- package/dist/dist/migrations/20260816225502_widen_automation_event_type_check.sql +18 -0
- package/dist/dist/migrations/20260816225503_add_invoice_id_to_automation_tables.sql +18 -0
- package/dist/dist/migrations/20260816225504_add_job_rescheduled_capture_trigger.sql +51 -0
- package/dist/dist/migrations/20260816225505_add_lead_converted_capture_trigger.sql +26 -0
- package/dist/dist/migrations/20260816225506_fix_booking_request_import_guard.sql +27 -0
- package/dist/dist/migrations/20260816225507_widen_outbound_event_for_automation.sql +38 -0
- package/dist/dist/migrations/20260817002626_add_user_last_login_platform_columns.sql +14 -0
- package/dist/dist/migrations/20260817221703_create_deletion.sql +34 -0
- package/dist/dist/migrations/20260817221707_deletion_rls.sql +21 -0
- package/dist/dist/migrations/20260817221708_add_soft_delete_columns.sql +82 -0
- package/dist/dist/migrations/20260817221709_trash_functions.sql +434 -0
- package/dist/dist/migrations/20260817221710_outbound_event_soft_delete.sql +55 -0
- package/dist/dist/migrations/20260817221711_automation_soft_delete_events.sql +77 -0
- package/dist/dist/migrations/20260817221712_fix_estimate_address_cascade.sql +14 -0
- package/dist/dist/migrations/20260817232630_trash_batch_function.sql +67 -0
- package/dist/dist/migrations/20260819170204_create_email_spam_complaint.sql +23 -0
- package/dist/dist/migrations/20260819170205_add_email_spam_complaint_rls.sql +5 -0
- package/dist/dist/migrations/20260819170206_email_unsubscribed_upsert_constraints.sql +14 -0
- package/dist/dist/migrations/20260819180151_get_suppressed_emails_function.sql +23 -0
- package/dist/dist/migrations/20260819191143_is_deleted_backfill_guard.sql +29 -0
- package/dist/dist/migrations/20260819191144_trash_functions_no_dual_write.sql +319 -0
- package/dist/dist/migrations/20260819191145_client_map_jobs_deleted_at.sql +33 -0
- package/dist/dist/migrations/20260819191147_booking_declined_deleted_at.sql +28 -0
- package/dist/dist/migrations/20260819191148_onboarding_preload_no_address_is_deleted.sql +1019 -0
- package/dist/dist/migrations/20260820222756_add_settings_job_hide_task_timer.sql +2 -0
- package/dist/dist/migrations/20260824234151_add_blast_chunk_recipients.sql +13 -0
- package/dist/dist/migrations/20260824234152_add_blast_pause_cancel_columns.sql +10 -0
- package/dist/dist/migrations/20260825014725_get_job_ids_in_range.sql +42 -0
- package/dist/dist/migrations/20260825194452_add_failed_job_status.sql +15 -0
- package/dist/dist/migrations/20260825194457_remove_take_to_rental_task_options.sql +24 -0
- package/dist/dist/migrations/20260825194458_remove_take_to_job_schedules.sql +12 -0
- package/dist/dist/migrations/20260825194459_rework_apply_rental_route_plan_no_take_to.sql +168 -0
- package/dist/dist/migrations/20260825194500_drop_job_schedule_target_location.sql +24 -0
- package/dist/dist/migrations/20260825194501_add_job_schedule_size.sql +17 -0
- package/dist/dist/migrations/20260825233001_add_job_schedule_id_company_id_key.sql +11 -0
- package/dist/dist/migrations/20260825233002_create_route_plan.sql +52 -0
- package/dist/dist/migrations/20260825233003_create_route_plan_stop.sql +159 -0
- package/dist/dist/migrations/20260825233004_route_plan_rls.sql +32 -0
- package/dist/dist/migrations/20260825233005_apply_rental_route_plan_v2.sql +351 -0
- package/dist/dist/migrations/20260826150934_facebook_ads_lead_ingestion.sql +1711 -0
- package/dist/dist/migrations/20260826151141_facebook_ads_lead_ingestion_rls_v2.sql +43 -0
- package/dist/dist/migrations/20260826234722_facebook_messenger_ingestion.sql +703 -0
- package/dist/dist/migrations/20260826234723_facebook_messenger_ingestion_rls.sql +80 -0
- package/dist/dist/migrations/20260826234724_widen_automations_messenger.sql +46 -0
- package/dist/dist/migrations/20260827100001_add_route_plan_minutes.sql +10 -0
- package/dist/dist/migrations/20260827100002_add_route_plan_stop_leg_minutes.sql +9 -0
- package/dist/dist/migrations/20260827100003_apply_rental_route_plan_v3.sql +341 -0
- package/dist/dist/migrations/20260827230346_apply_rental_route_plan_v4.sql +366 -0
- package/dist/dist/migrations/20260829090911_create_fleet_schema.sql +3698 -0
- package/dist/dist/migrations/20260829090912_fleet_rls.sql +1011 -0
- package/dist/dist/migrations/20260831102212_add_online_booking_address_display.sql +8 -0
- package/dist/dist/providers/AddressProvider.d.ts +9 -0
- package/dist/dist/providers/AddressProvider.d.ts.map +1 -0
- package/dist/dist/providers/AddressProvider.js +207 -0
- package/dist/dist/providers/AddressProvider.js.map +1 -0
- package/dist/dist/providers/AutomationsProvider.d.ts +11 -0
- package/dist/dist/providers/AutomationsProvider.d.ts.map +1 -0
- package/dist/dist/providers/AutomationsProvider.js +170 -0
- package/dist/dist/providers/AutomationsProvider.js.map +1 -0
- package/dist/dist/providers/BlockedNumbersProvider.d.ts +13 -0
- package/dist/dist/providers/BlockedNumbersProvider.d.ts.map +1 -0
- package/dist/dist/providers/BlockedNumbersProvider.js +71 -0
- package/dist/dist/providers/BlockedNumbersProvider.js.map +1 -0
- package/dist/dist/providers/CategoryProvider.d.ts +8 -0
- package/dist/dist/providers/CategoryProvider.d.ts.map +1 -0
- package/dist/dist/providers/CategoryProvider.js +95 -0
- package/dist/dist/providers/CategoryProvider.js.map +1 -0
- package/dist/dist/providers/ClientProvider.d.ts +39 -0
- package/dist/dist/providers/ClientProvider.d.ts.map +1 -0
- package/dist/dist/providers/ClientProvider.js +253 -0
- package/dist/dist/providers/ClientProvider.js.map +1 -0
- package/dist/dist/providers/CompanyProvider.d.ts +7 -0
- package/dist/dist/providers/CompanyProvider.d.ts.map +1 -0
- package/dist/dist/providers/CompanyProvider.js +114 -0
- package/dist/dist/providers/CompanyProvider.js.map +1 -0
- package/dist/dist/providers/DashboardProvider.d.ts +78 -0
- package/dist/dist/providers/DashboardProvider.d.ts.map +1 -0
- package/dist/dist/providers/DashboardProvider.js +568 -0
- package/dist/dist/providers/DashboardProvider.js.map +1 -0
- package/dist/dist/providers/DiscountProvider.d.ts +8 -0
- package/dist/dist/providers/DiscountProvider.d.ts.map +1 -0
- package/dist/dist/providers/DiscountProvider.js +92 -0
- package/dist/dist/providers/DiscountProvider.js.map +1 -0
- package/dist/dist/providers/EmployeesProvider.d.ts +6 -0
- package/dist/dist/providers/EmployeesProvider.d.ts.map +1 -0
- package/dist/dist/providers/EmployeesProvider.js +185 -0
- package/dist/dist/providers/EmployeesProvider.js.map +1 -0
- package/dist/dist/providers/EstimatesProvider.d.ts +16 -0
- package/dist/dist/providers/EstimatesProvider.d.ts.map +1 -0
- package/dist/dist/providers/EstimatesProvider.js +251 -0
- package/dist/dist/providers/EstimatesProvider.js.map +1 -0
- package/dist/dist/providers/EventsProvider.d.ts +4 -0
- package/dist/dist/providers/EventsProvider.d.ts.map +1 -0
- package/dist/dist/providers/EventsProvider.js +24 -0
- package/dist/dist/providers/EventsProvider.js.map +1 -0
- package/dist/dist/providers/FilesProvider.d.ts +17 -0
- package/dist/dist/providers/FilesProvider.d.ts.map +1 -0
- package/dist/dist/providers/FilesProvider.js +201 -0
- package/dist/dist/providers/FilesProvider.js.map +1 -0
- package/dist/dist/providers/InvoicesProvider.d.ts +13 -0
- package/dist/dist/providers/InvoicesProvider.d.ts.map +1 -0
- package/dist/dist/providers/InvoicesProvider.js +207 -0
- package/dist/dist/providers/InvoicesProvider.js.map +1 -0
- package/dist/dist/providers/ItemProvider.d.ts +9 -0
- package/dist/dist/providers/ItemProvider.d.ts.map +1 -0
- package/dist/dist/providers/ItemProvider.js +201 -0
- package/dist/dist/providers/ItemProvider.js.map +1 -0
- package/dist/dist/providers/JobSourceProvider.d.ts +8 -0
- package/dist/dist/providers/JobSourceProvider.d.ts.map +1 -0
- package/dist/dist/providers/JobSourceProvider.js +75 -0
- package/dist/dist/providers/JobSourceProvider.js.map +1 -0
- package/dist/dist/providers/JobTypeProvider.d.ts +8 -0
- package/dist/dist/providers/JobTypeProvider.d.ts.map +1 -0
- package/dist/dist/providers/JobTypeProvider.js +75 -0
- package/dist/dist/providers/JobTypeProvider.js.map +1 -0
- package/dist/dist/providers/JobsProvider.d.ts +35 -0
- package/dist/dist/providers/JobsProvider.d.ts.map +1 -0
- package/dist/dist/providers/JobsProvider.js +863 -0
- package/dist/dist/providers/JobsProvider.js.map +1 -0
- package/dist/dist/providers/MessagesProvider.d.ts +33 -0
- package/dist/dist/providers/MessagesProvider.d.ts.map +1 -0
- package/dist/dist/providers/MessagesProvider.js +415 -0
- package/dist/dist/providers/MessagesProvider.js.map +1 -0
- package/dist/dist/providers/PaymentProvider.d.ts +9 -0
- package/dist/dist/providers/PaymentProvider.d.ts.map +1 -0
- package/dist/dist/providers/PaymentProvider.js +48 -0
- package/dist/dist/providers/PaymentProvider.js.map +1 -0
- package/dist/dist/providers/PermissionRolesProvider.d.ts +5 -0
- package/dist/dist/providers/PermissionRolesProvider.d.ts.map +1 -0
- package/dist/dist/providers/PermissionRolesProvider.js +30 -0
- package/dist/dist/providers/PermissionRolesProvider.js.map +1 -0
- package/dist/dist/providers/PhoneNumberProvider.d.ts +12 -0
- package/dist/dist/providers/PhoneNumberProvider.d.ts.map +1 -0
- package/dist/dist/providers/PhoneNumberProvider.js +184 -0
- package/dist/dist/providers/PhoneNumberProvider.js.map +1 -0
- package/dist/dist/providers/ProfileProvider.d.ts +6 -0
- package/dist/dist/providers/ProfileProvider.d.ts.map +1 -0
- package/dist/dist/providers/ProfileProvider.js +71 -0
- package/dist/dist/providers/ProfileProvider.js.map +1 -0
- package/dist/dist/providers/RentalsProvider.d.ts +28 -0
- package/dist/dist/providers/RentalsProvider.d.ts.map +1 -0
- package/dist/dist/providers/RentalsProvider.js +438 -0
- package/dist/dist/providers/RentalsProvider.js.map +1 -0
- package/dist/dist/providers/SettingsBookingProvider.d.ts +9 -0
- package/dist/dist/providers/SettingsBookingProvider.d.ts.map +1 -0
- package/dist/dist/providers/SettingsBookingProvider.js +163 -0
- package/dist/dist/providers/SettingsBookingProvider.js.map +1 -0
- package/dist/dist/providers/SettingsProvider.d.ts +8 -0
- package/dist/dist/providers/SettingsProvider.d.ts.map +1 -0
- package/dist/dist/providers/SettingsProvider.js +86 -0
- package/dist/dist/providers/SettingsProvider.js.map +1 -0
- package/dist/dist/providers/TagsProvider.d.ts +12 -0
- package/dist/dist/providers/TagsProvider.d.ts.map +1 -0
- package/dist/dist/providers/TagsProvider.js +210 -0
- package/dist/dist/providers/TagsProvider.js.map +1 -0
- package/dist/dist/providers/TimeCardProvider.d.ts +8 -0
- package/dist/dist/providers/TimeCardProvider.d.ts.map +1 -0
- package/dist/dist/providers/TimeCardProvider.js +93 -0
- package/dist/dist/providers/TimeCardProvider.js.map +1 -0
- package/dist/dist/providers/TrashProvider.d.ts +13 -0
- package/dist/dist/providers/TrashProvider.d.ts.map +1 -0
- package/dist/dist/providers/TrashProvider.js +98 -0
- package/dist/dist/providers/TrashProvider.js.map +1 -0
- package/dist/dist/providers/dashboardAnalytics.d.ts +9 -0
- package/dist/dist/providers/dashboardAnalytics.d.ts.map +1 -0
- package/dist/dist/providers/dashboardAnalytics.js +41 -0
- package/dist/dist/providers/dashboardAnalytics.js.map +1 -0
- package/dist/dist/providers/dashboardAnalytics.test.d.ts +2 -0
- package/dist/dist/providers/dashboardAnalytics.test.d.ts.map +1 -0
- package/dist/dist/providers/dashboardAnalytics.test.js +111 -0
- package/dist/dist/providers/dashboardAnalytics.test.js.map +1 -0
- package/dist/dist/server-safe/BlockedNumberFunctions.d.ts +11 -0
- package/dist/dist/server-safe/BlockedNumberFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/BlockedNumberFunctions.js +16 -0
- package/dist/dist/server-safe/BlockedNumberFunctions.js.map +1 -0
- package/dist/dist/server-safe/EmployeeFunctions.d.ts +14 -0
- package/dist/dist/server-safe/EmployeeFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/EmployeeFunctions.js +70 -0
- package/dist/dist/server-safe/EmployeeFunctions.js.map +1 -0
- package/dist/dist/server-safe/EmployeeLocationFunctions.d.ts +7 -0
- package/dist/dist/server-safe/EmployeeLocationFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/EmployeeLocationFunctions.js +47 -0
- package/dist/dist/server-safe/EmployeeLocationFunctions.js.map +1 -0
- package/dist/dist/server-safe/EstimateFunctions.d.ts +15 -0
- package/dist/dist/server-safe/EstimateFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/EstimateFunctions.js +34 -0
- package/dist/dist/server-safe/EstimateFunctions.js.map +1 -0
- package/dist/dist/server-safe/InvoiceFunctions.d.ts +21 -0
- package/dist/dist/server-safe/InvoiceFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/InvoiceFunctions.js +124 -0
- package/dist/dist/server-safe/InvoiceFunctions.js.map +1 -0
- package/dist/dist/server-safe/JobFunctions.d.ts +15 -0
- package/dist/dist/server-safe/JobFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/JobFunctions.js +56 -0
- package/dist/dist/server-safe/JobFunctions.js.map +1 -0
- package/dist/dist/server-safe/PaymentFunctions.d.ts +16 -0
- package/dist/dist/server-safe/PaymentFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/PaymentFunctions.js +80 -0
- package/dist/dist/server-safe/PaymentFunctions.js.map +1 -0
- package/dist/dist/server-safe/PermissionFunctions.d.ts +7 -0
- package/dist/dist/server-safe/PermissionFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/PermissionFunctions.js +39 -0
- package/dist/dist/server-safe/PermissionFunctions.js.map +1 -0
- package/dist/dist/server-safe/TagFunctions.d.ts +18 -0
- package/dist/dist/server-safe/TagFunctions.d.ts.map +1 -0
- package/dist/dist/server-safe/TagFunctions.js +52 -0
- package/dist/dist/server-safe/TagFunctions.js.map +1 -0
- package/dist/dist/server-safe/autoJobType.d.ts +16 -0
- package/dist/dist/server-safe/autoJobType.d.ts.map +1 -0
- package/dist/dist/server-safe/autoJobType.js +39 -0
- package/dist/dist/server-safe/autoJobType.js.map +1 -0
- package/dist/dist/server-safe/autoJobType.test.d.ts +2 -0
- package/dist/dist/server-safe/autoJobType.test.d.ts.map +1 -0
- package/dist/dist/server-safe/autoJobType.test.js +83 -0
- package/dist/dist/server-safe/autoJobType.test.js.map +1 -0
- package/dist/dist/server-safe/automations.d.ts +197 -0
- package/dist/dist/server-safe/automations.d.ts.map +1 -0
- package/dist/dist/server-safe/automations.js +757 -0
- package/dist/dist/server-safe/automations.js.map +1 -0
- package/dist/dist/server-safe/automations.test.d.ts +2 -0
- package/dist/dist/server-safe/automations.test.d.ts.map +1 -0
- package/dist/dist/server-safe/automations.test.js +441 -0
- package/dist/dist/server-safe/automations.test.js.map +1 -0
- package/dist/dist/server-safe/constants.d.ts +156 -0
- package/dist/dist/server-safe/constants.d.ts.map +1 -0
- package/dist/dist/server-safe/constants.js +186 -0
- package/dist/dist/server-safe/constants.js.map +1 -0
- package/dist/dist/server-safe/contracts.d.ts +3 -0
- package/dist/dist/server-safe/contracts.d.ts.map +1 -0
- package/dist/dist/server-safe/contracts.js +15 -0
- package/dist/dist/server-safe/contracts.js.map +1 -0
- package/dist/dist/server-safe/database.types.d.ts +9510 -0
- package/dist/dist/server-safe/database.types.d.ts.map +1 -0
- package/dist/dist/server-safe/database.types.js +40 -0
- package/dist/dist/server-safe/database.types.js.map +1 -0
- package/dist/dist/server-safe/entitlements.d.ts +99 -0
- package/dist/dist/server-safe/entitlements.d.ts.map +1 -0
- package/dist/dist/server-safe/entitlements.js +487 -0
- package/dist/dist/server-safe/entitlements.js.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeads.d.ts +225 -0
- package/dist/dist/server-safe/facebookAdsLeads.d.ts.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeads.js +376 -0
- package/dist/dist/server-safe/facebookAdsLeads.js.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeads.test.d.ts +2 -0
- package/dist/dist/server-safe/facebookAdsLeads.test.d.ts.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeads.test.js +189 -0
- package/dist/dist/server-safe/facebookAdsLeads.test.js.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeadsSql.test.d.ts +2 -0
- package/dist/dist/server-safe/facebookAdsLeadsSql.test.d.ts.map +1 -0
- package/dist/dist/server-safe/facebookAdsLeadsSql.test.js +32 -0
- package/dist/dist/server-safe/facebookAdsLeadsSql.test.js.map +1 -0
- package/dist/dist/server-safe/facebookMessenger.d.ts +20 -0
- package/dist/dist/server-safe/facebookMessenger.d.ts.map +1 -0
- package/dist/dist/server-safe/facebookMessenger.js +63 -0
- package/dist/dist/server-safe/facebookMessenger.js.map +1 -0
- package/dist/dist/server-safe/facebookMessenger.test.d.ts +2 -0
- package/dist/dist/server-safe/facebookMessenger.test.d.ts.map +1 -0
- package/dist/dist/server-safe/facebookMessenger.test.js +51 -0
- package/dist/dist/server-safe/facebookMessenger.test.js.map +1 -0
- package/dist/dist/server-safe/helpers.d.ts +78 -0
- package/dist/dist/server-safe/helpers.d.ts.map +1 -0
- package/dist/dist/server-safe/helpers.js +569 -0
- package/dist/dist/server-safe/helpers.js.map +1 -0
- package/dist/dist/server-safe/index.d.ts +30 -0
- package/dist/dist/server-safe/index.d.ts.map +1 -0
- package/dist/dist/server-safe/index.js +46 -0
- package/dist/dist/server-safe/index.js.map +1 -0
- package/dist/dist/server-safe/permissions.d.ts +29 -0
- package/dist/dist/server-safe/permissions.d.ts.map +1 -0
- package/dist/dist/server-safe/permissions.js +180 -0
- package/dist/dist/server-safe/permissions.js.map +1 -0
- package/dist/dist/server-safe/proposals.d.ts +6 -0
- package/dist/dist/server-safe/proposals.d.ts.map +1 -0
- package/dist/dist/server-safe/proposals.js +58 -0
- package/dist/dist/server-safe/proposals.js.map +1 -0
- package/dist/dist/server-safe/rentalAvailability.d.ts +56 -0
- package/dist/dist/server-safe/rentalAvailability.d.ts.map +1 -0
- package/dist/dist/server-safe/rentalAvailability.js +124 -0
- package/dist/dist/server-safe/rentalAvailability.js.map +1 -0
- package/dist/dist/server-safe/rentalAvailability.test.d.ts +2 -0
- package/dist/dist/server-safe/rentalAvailability.test.d.ts.map +1 -0
- package/dist/dist/server-safe/rentalAvailability.test.js +290 -0
- package/dist/dist/server-safe/rentalAvailability.test.js.map +1 -0
- package/dist/dist/server-safe/rentals.d.ts +95 -0
- package/dist/dist/server-safe/rentals.d.ts.map +1 -0
- package/dist/dist/server-safe/rentals.js +432 -0
- package/dist/dist/server-safe/rentals.js.map +1 -0
- package/dist/dist/server-safe/rentals.test.d.ts +2 -0
- package/dist/dist/server-safe/rentals.test.d.ts.map +1 -0
- package/dist/dist/server-safe/rentals.test.js +1034 -0
- package/dist/dist/server-safe/rentals.test.js.map +1 -0
- package/dist/dist/server-safe/routeOptimization.d.ts +155 -0
- package/dist/dist/server-safe/routeOptimization.d.ts.map +1 -0
- package/dist/dist/server-safe/routeOptimization.js +120 -0
- package/dist/dist/server-safe/routeOptimization.js.map +1 -0
- package/dist/dist/server-safe/routeOptimization.test.d.ts +2 -0
- package/dist/dist/server-safe/routeOptimization.test.d.ts.map +1 -0
- package/dist/dist/server-safe/routeOptimization.test.js +234 -0
- package/dist/dist/server-safe/routeOptimization.test.js.map +1 -0
- package/dist/dist/server-safe/routePlanFingerprint.d.ts +13 -0
- package/dist/dist/server-safe/routePlanFingerprint.d.ts.map +1 -0
- package/dist/dist/server-safe/routePlanFingerprint.js +49 -0
- package/dist/dist/server-safe/routePlanFingerprint.js.map +1 -0
- package/dist/dist/server-safe/routePlanFingerprint.test.d.ts +2 -0
- package/dist/dist/server-safe/routePlanFingerprint.test.d.ts.map +1 -0
- package/dist/dist/server-safe/routePlanFingerprint.test.js +68 -0
- package/dist/dist/server-safe/routePlanFingerprint.test.js.map +1 -0
- package/dist/dist/server-safe/scheduleListOrder.d.ts +18 -0
- package/dist/dist/server-safe/scheduleListOrder.d.ts.map +1 -0
- package/dist/dist/server-safe/scheduleListOrder.js +92 -0
- package/dist/dist/server-safe/scheduleListOrder.js.map +1 -0
- package/dist/dist/server-safe/scheduleListOrder.test.d.ts +2 -0
- package/dist/dist/server-safe/scheduleListOrder.test.d.ts.map +1 -0
- package/dist/dist/server-safe/scheduleListOrder.test.js +260 -0
- package/dist/dist/server-safe/scheduleListOrder.test.js.map +1 -0
- package/dist/dist/server-safe/serviceMinutes.d.ts +13 -0
- package/dist/dist/server-safe/serviceMinutes.d.ts.map +1 -0
- package/dist/dist/server-safe/serviceMinutes.js +38 -0
- package/dist/dist/server-safe/serviceMinutes.js.map +1 -0
- package/dist/dist/server-safe/serviceMinutes.test.d.ts +2 -0
- package/dist/dist/server-safe/serviceMinutes.test.d.ts.map +1 -0
- package/dist/dist/server-safe/serviceMinutes.test.js +86 -0
- package/dist/dist/server-safe/serviceMinutes.test.js.map +1 -0
- package/dist/dist/server-safe/settingsSearch.d.ts +24 -0
- package/dist/dist/server-safe/settingsSearch.d.ts.map +1 -0
- package/dist/dist/server-safe/settingsSearch.js +8 -0
- package/dist/dist/server-safe/settingsSearch.js.map +1 -0
- package/dist/dist/server-safe/supportChat.d.ts +59 -0
- package/dist/dist/server-safe/supportChat.d.ts.map +1 -0
- package/dist/dist/server-safe/supportChat.js +56 -0
- package/dist/dist/server-safe/supportChat.js.map +1 -0
- package/dist/dist/server-safe/templates.d.ts +15 -0
- package/dist/dist/server-safe/templates.d.ts.map +1 -0
- package/dist/dist/server-safe/templates.js +91 -0
- package/dist/dist/server-safe/templates.js.map +1 -0
- package/dist/dist/server-safe/templates.test.d.ts +2 -0
- package/dist/dist/server-safe/templates.test.d.ts.map +1 -0
- package/dist/dist/server-safe/templates.test.js +62 -0
- package/dist/dist/server-safe/templates.test.js.map +1 -0
- package/dist/dist/server-safe/trash.d.ts +50 -0
- package/dist/dist/server-safe/trash.d.ts.map +1 -0
- package/dist/dist/server-safe/trash.js +100 -0
- package/dist/dist/server-safe/trash.js.map +1 -0
- package/dist/dist/utils/LogHandler.d.ts +3 -0
- package/dist/dist/utils/LogHandler.d.ts.map +1 -0
- package/dist/dist/utils/LogHandler.js +16 -0
- package/dist/dist/utils/LogHandler.js.map +1 -0
- package/dist/dist/utils/convertSupabaseImagesToAssets.d.ts +28 -0
- package/dist/dist/utils/convertSupabaseImagesToAssets.d.ts.map +1 -0
- package/dist/dist/utils/convertSupabaseImagesToAssets.js +14 -0
- package/dist/dist/utils/convertSupabaseImagesToAssets.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +1238 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/providers/AddressProvider.d.ts +9 -0
- package/dist/providers/AddressProvider.d.ts.map +1 -0
- package/dist/providers/AddressProvider.js +207 -0
- package/dist/providers/AddressProvider.js.map +1 -0
- package/dist/providers/AutomationsProvider.d.ts +11 -0
- package/dist/providers/AutomationsProvider.d.ts.map +1 -0
- package/dist/providers/AutomationsProvider.js +170 -0
- package/dist/providers/AutomationsProvider.js.map +1 -0
- package/dist/providers/BlockedNumbersProvider.d.ts +7 -0
- package/dist/providers/BlockedNumbersProvider.d.ts.map +1 -0
- package/dist/providers/BlockedNumbersProvider.js +71 -0
- package/dist/providers/BlockedNumbersProvider.js.map +1 -0
- package/dist/providers/CategoryProvider.d.ts +8 -0
- package/dist/providers/CategoryProvider.d.ts.map +1 -0
- package/dist/providers/CategoryProvider.js +95 -0
- package/dist/providers/CategoryProvider.js.map +1 -0
- package/dist/providers/ClientProvider.d.ts +39 -0
- package/dist/providers/ClientProvider.d.ts.map +1 -0
- package/dist/providers/ClientProvider.js +253 -0
- package/dist/providers/ClientProvider.js.map +1 -0
- package/dist/providers/CompanyProvider.d.ts +7 -0
- package/dist/providers/CompanyProvider.d.ts.map +1 -0
- package/dist/providers/CompanyProvider.js +114 -0
- package/dist/providers/CompanyProvider.js.map +1 -0
- package/dist/providers/DashboardProvider.d.ts +78 -0
- package/dist/providers/DashboardProvider.d.ts.map +1 -0
- package/dist/providers/DashboardProvider.js +568 -0
- package/dist/providers/DashboardProvider.js.map +1 -0
- package/dist/providers/DiscountProvider.d.ts +8 -0
- package/dist/providers/DiscountProvider.d.ts.map +1 -0
- package/dist/providers/DiscountProvider.js +92 -0
- package/dist/providers/DiscountProvider.js.map +1 -0
- package/dist/providers/EmployeesProvider.d.ts +6 -0
- package/dist/providers/EmployeesProvider.d.ts.map +1 -0
- package/dist/providers/EmployeesProvider.js +185 -0
- package/dist/providers/EmployeesProvider.js.map +1 -0
- package/dist/providers/EstimatesProvider.d.ts +16 -0
- package/dist/providers/EstimatesProvider.d.ts.map +1 -0
- package/dist/providers/EstimatesProvider.js +251 -0
- package/dist/providers/EstimatesProvider.js.map +1 -0
- package/dist/providers/EventsProvider.d.ts +4 -0
- package/dist/providers/EventsProvider.d.ts.map +1 -0
- package/dist/providers/EventsProvider.js +24 -0
- package/dist/providers/EventsProvider.js.map +1 -0
- package/dist/providers/FilesProvider.d.ts +17 -0
- package/dist/providers/FilesProvider.d.ts.map +1 -0
- package/dist/providers/FilesProvider.js +201 -0
- package/dist/providers/FilesProvider.js.map +1 -0
- package/dist/providers/InvoicesProvider.d.ts +13 -0
- package/dist/providers/InvoicesProvider.d.ts.map +1 -0
- package/dist/providers/InvoicesProvider.js +207 -0
- package/dist/providers/InvoicesProvider.js.map +1 -0
- package/dist/providers/ItemProvider.d.ts +9 -0
- package/dist/providers/ItemProvider.d.ts.map +1 -0
- package/dist/providers/ItemProvider.js +201 -0
- package/dist/providers/ItemProvider.js.map +1 -0
- package/dist/providers/JobSourceProvider.d.ts +8 -0
- package/dist/providers/JobSourceProvider.d.ts.map +1 -0
- package/dist/providers/JobSourceProvider.js +75 -0
- package/dist/providers/JobSourceProvider.js.map +1 -0
- package/dist/providers/JobTypeProvider.d.ts +8 -0
- package/dist/providers/JobTypeProvider.d.ts.map +1 -0
- package/dist/providers/JobTypeProvider.js +75 -0
- package/dist/providers/JobTypeProvider.js.map +1 -0
- package/dist/providers/JobsProvider.d.ts +20 -0
- package/dist/providers/JobsProvider.d.ts.map +1 -0
- package/dist/providers/JobsProvider.js +863 -0
- package/dist/providers/JobsProvider.js.map +1 -0
- package/dist/providers/MessagesProvider.d.ts +14 -0
- package/dist/providers/MessagesProvider.d.ts.map +1 -0
- package/dist/providers/MessagesProvider.js +415 -0
- package/dist/providers/MessagesProvider.js.map +1 -0
- package/dist/providers/PaymentProvider.d.ts +9 -0
- package/dist/providers/PaymentProvider.d.ts.map +1 -0
- package/dist/providers/PaymentProvider.js +48 -0
- package/dist/providers/PaymentProvider.js.map +1 -0
- package/dist/providers/PermissionRolesProvider.d.ts +5 -0
- package/dist/providers/PermissionRolesProvider.d.ts.map +1 -0
- package/dist/providers/PermissionRolesProvider.js +30 -0
- package/dist/providers/PermissionRolesProvider.js.map +1 -0
- package/dist/providers/PhoneNumberProvider.d.ts +12 -0
- package/dist/providers/PhoneNumberProvider.d.ts.map +1 -0
- package/dist/providers/PhoneNumberProvider.js +184 -0
- package/dist/providers/PhoneNumberProvider.js.map +1 -0
- package/dist/providers/ProfileProvider.d.ts +6 -0
- package/dist/providers/ProfileProvider.d.ts.map +1 -0
- package/dist/providers/ProfileProvider.js +71 -0
- package/dist/providers/ProfileProvider.js.map +1 -0
- package/dist/providers/RentalsProvider.d.ts +28 -0
- package/dist/providers/RentalsProvider.d.ts.map +1 -0
- package/dist/providers/RentalsProvider.js +438 -0
- package/dist/providers/RentalsProvider.js.map +1 -0
- package/dist/providers/SettingsBookingProvider.d.ts +9 -0
- package/dist/providers/SettingsBookingProvider.d.ts.map +1 -0
- package/dist/providers/SettingsBookingProvider.js +163 -0
- package/dist/providers/SettingsBookingProvider.js.map +1 -0
- package/dist/providers/SettingsProvider.d.ts +8 -0
- package/dist/providers/SettingsProvider.d.ts.map +1 -0
- package/dist/providers/SettingsProvider.js +86 -0
- package/dist/providers/SettingsProvider.js.map +1 -0
- package/dist/providers/TagsProvider.d.ts +12 -0
- package/dist/providers/TagsProvider.d.ts.map +1 -0
- package/dist/providers/TagsProvider.js +210 -0
- package/dist/providers/TagsProvider.js.map +1 -0
- package/dist/providers/TimeCardProvider.d.ts +8 -0
- package/dist/providers/TimeCardProvider.d.ts.map +1 -0
- package/dist/providers/TimeCardProvider.js +93 -0
- package/dist/providers/TimeCardProvider.js.map +1 -0
- package/dist/providers/TrashProvider.d.ts +13 -0
- package/dist/providers/TrashProvider.d.ts.map +1 -0
- package/dist/providers/TrashProvider.js +98 -0
- package/dist/providers/TrashProvider.js.map +1 -0
- package/dist/providers/dashboardAnalytics.d.ts +9 -0
- package/dist/providers/dashboardAnalytics.d.ts.map +1 -0
- package/dist/providers/dashboardAnalytics.js +41 -0
- package/dist/providers/dashboardAnalytics.js.map +1 -0
- package/dist/providers/dashboardAnalytics.test.d.ts +2 -0
- package/dist/providers/dashboardAnalytics.test.d.ts.map +1 -0
- package/dist/providers/dashboardAnalytics.test.js +111 -0
- package/dist/providers/dashboardAnalytics.test.js.map +1 -0
- package/dist/server-safe/BlockedNumberFunctions.d.ts +11 -0
- package/dist/server-safe/BlockedNumberFunctions.d.ts.map +1 -0
- package/dist/server-safe/BlockedNumberFunctions.js +16 -0
- package/dist/server-safe/BlockedNumberFunctions.js.map +1 -0
- package/dist/server-safe/EmployeeFunctions.d.ts +14 -0
- package/dist/server-safe/EmployeeFunctions.d.ts.map +1 -0
- package/dist/server-safe/EmployeeFunctions.js +70 -0
- package/dist/server-safe/EmployeeFunctions.js.map +1 -0
- package/dist/server-safe/EmployeeLocationFunctions.d.ts +7 -0
- package/dist/server-safe/EmployeeLocationFunctions.d.ts.map +1 -0
- package/dist/server-safe/EmployeeLocationFunctions.js +47 -0
- package/dist/server-safe/EmployeeLocationFunctions.js.map +1 -0
- package/dist/server-safe/EstimateFunctions.d.ts +15 -0
- package/dist/server-safe/EstimateFunctions.d.ts.map +1 -0
- package/dist/server-safe/EstimateFunctions.js +34 -0
- package/dist/server-safe/EstimateFunctions.js.map +1 -0
- package/dist/server-safe/InvoiceFunctions.d.ts +21 -0
- package/dist/server-safe/InvoiceFunctions.d.ts.map +1 -0
- package/dist/server-safe/InvoiceFunctions.js +124 -0
- package/dist/server-safe/InvoiceFunctions.js.map +1 -0
- package/dist/server-safe/JobFunctions.d.ts +15 -0
- package/dist/server-safe/JobFunctions.d.ts.map +1 -0
- package/dist/server-safe/JobFunctions.js +56 -0
- package/dist/server-safe/JobFunctions.js.map +1 -0
- package/dist/server-safe/PaymentFunctions.d.ts +16 -0
- package/dist/server-safe/PaymentFunctions.d.ts.map +1 -0
- package/dist/server-safe/PaymentFunctions.js +80 -0
- package/dist/server-safe/PaymentFunctions.js.map +1 -0
- package/dist/server-safe/PermissionFunctions.d.ts +7 -0
- package/dist/server-safe/PermissionFunctions.d.ts.map +1 -0
- package/dist/server-safe/PermissionFunctions.js +39 -0
- package/dist/server-safe/PermissionFunctions.js.map +1 -0
- package/dist/server-safe/TagFunctions.d.ts +18 -0
- package/dist/server-safe/TagFunctions.d.ts.map +1 -0
- package/dist/server-safe/TagFunctions.js +52 -0
- package/dist/server-safe/TagFunctions.js.map +1 -0
- package/dist/server-safe/autoJobType.d.ts +16 -0
- package/dist/server-safe/autoJobType.d.ts.map +1 -0
- package/dist/server-safe/autoJobType.js +39 -0
- package/dist/server-safe/autoJobType.js.map +1 -0
- package/dist/server-safe/autoJobType.test.d.ts +2 -0
- package/dist/server-safe/autoJobType.test.d.ts.map +1 -0
- package/dist/server-safe/autoJobType.test.js +83 -0
- package/dist/server-safe/autoJobType.test.js.map +1 -0
- package/dist/server-safe/automations.d.ts +197 -0
- package/dist/server-safe/automations.d.ts.map +1 -0
- package/dist/server-safe/automations.js +757 -0
- package/dist/server-safe/automations.js.map +1 -0
- package/dist/server-safe/automations.test.d.ts +2 -0
- package/dist/server-safe/automations.test.d.ts.map +1 -0
- package/dist/server-safe/automations.test.js +441 -0
- package/dist/server-safe/automations.test.js.map +1 -0
- package/dist/server-safe/constants.d.ts +156 -0
- package/dist/server-safe/constants.d.ts.map +1 -0
- package/dist/server-safe/constants.js +186 -0
- package/dist/server-safe/constants.js.map +1 -0
- package/dist/server-safe/contracts.d.ts +3 -0
- package/dist/server-safe/contracts.d.ts.map +1 -0
- package/dist/server-safe/contracts.js +15 -0
- package/dist/server-safe/contracts.js.map +1 -0
- package/dist/server-safe/database.types.d.ts +9510 -0
- package/dist/server-safe/database.types.d.ts.map +1 -0
- package/dist/server-safe/database.types.js +40 -0
- package/dist/server-safe/database.types.js.map +1 -0
- package/dist/server-safe/entitlements.d.ts +99 -0
- package/dist/server-safe/entitlements.d.ts.map +1 -0
- package/dist/server-safe/entitlements.js +487 -0
- package/dist/server-safe/entitlements.js.map +1 -0
- package/dist/server-safe/helpers.d.ts +78 -0
- package/dist/server-safe/helpers.d.ts.map +1 -0
- package/dist/server-safe/helpers.js +569 -0
- package/dist/server-safe/helpers.js.map +1 -0
- package/dist/server-safe/index.d.ts +30 -0
- package/dist/server-safe/index.d.ts.map +1 -0
- package/dist/server-safe/index.js +46 -0
- package/dist/server-safe/index.js.map +1 -0
- package/dist/server-safe/permissions.d.ts +29 -0
- package/dist/server-safe/permissions.d.ts.map +1 -0
- package/dist/server-safe/permissions.js +180 -0
- package/dist/server-safe/permissions.js.map +1 -0
- package/dist/server-safe/proposals.d.ts +6 -0
- package/dist/server-safe/proposals.d.ts.map +1 -0
- package/dist/server-safe/proposals.js +58 -0
- package/dist/server-safe/proposals.js.map +1 -0
- package/dist/server-safe/rentalAvailability.d.ts +56 -0
- package/dist/server-safe/rentalAvailability.d.ts.map +1 -0
- package/dist/server-safe/rentalAvailability.js +124 -0
- package/dist/server-safe/rentalAvailability.js.map +1 -0
- package/dist/server-safe/rentalAvailability.test.d.ts +2 -0
- package/dist/server-safe/rentalAvailability.test.d.ts.map +1 -0
- package/dist/server-safe/rentalAvailability.test.js +290 -0
- package/dist/server-safe/rentalAvailability.test.js.map +1 -0
- package/dist/server-safe/rentals.d.ts +95 -0
- package/dist/server-safe/rentals.d.ts.map +1 -0
- package/dist/server-safe/rentals.js +432 -0
- package/dist/server-safe/rentals.js.map +1 -0
- package/dist/server-safe/rentals.test.d.ts +2 -0
- package/dist/server-safe/rentals.test.d.ts.map +1 -0
- package/dist/server-safe/rentals.test.js +1034 -0
- package/dist/server-safe/rentals.test.js.map +1 -0
- package/dist/server-safe/routeOptimization.d.ts +155 -0
- package/dist/server-safe/routeOptimization.d.ts.map +1 -0
- package/dist/server-safe/routeOptimization.js +120 -0
- package/dist/server-safe/routeOptimization.js.map +1 -0
- package/dist/server-safe/routeOptimization.test.d.ts +2 -0
- package/dist/server-safe/routeOptimization.test.d.ts.map +1 -0
- package/dist/server-safe/routeOptimization.test.js +234 -0
- package/dist/server-safe/routeOptimization.test.js.map +1 -0
- package/dist/server-safe/routePlanFingerprint.d.ts +13 -0
- package/dist/server-safe/routePlanFingerprint.d.ts.map +1 -0
- package/dist/server-safe/routePlanFingerprint.js +49 -0
- package/dist/server-safe/routePlanFingerprint.js.map +1 -0
- package/dist/server-safe/routePlanFingerprint.test.d.ts +2 -0
- package/dist/server-safe/routePlanFingerprint.test.d.ts.map +1 -0
- package/dist/server-safe/routePlanFingerprint.test.js +68 -0
- package/dist/server-safe/routePlanFingerprint.test.js.map +1 -0
- package/dist/server-safe/scheduleListOrder.d.ts +18 -0
- package/dist/server-safe/scheduleListOrder.d.ts.map +1 -0
- package/dist/server-safe/scheduleListOrder.js +92 -0
- package/dist/server-safe/scheduleListOrder.js.map +1 -0
- package/dist/server-safe/scheduleListOrder.test.d.ts +2 -0
- package/dist/server-safe/scheduleListOrder.test.d.ts.map +1 -0
- package/dist/server-safe/scheduleListOrder.test.js +260 -0
- package/dist/server-safe/scheduleListOrder.test.js.map +1 -0
- package/dist/server-safe/serviceMinutes.d.ts +13 -0
- package/dist/server-safe/serviceMinutes.d.ts.map +1 -0
- package/dist/server-safe/serviceMinutes.js +38 -0
- package/dist/server-safe/serviceMinutes.js.map +1 -0
- package/dist/server-safe/serviceMinutes.test.d.ts +2 -0
- package/dist/server-safe/serviceMinutes.test.d.ts.map +1 -0
- package/dist/server-safe/serviceMinutes.test.js +86 -0
- package/dist/server-safe/serviceMinutes.test.js.map +1 -0
- package/dist/server-safe/settingsSearch.d.ts +24 -0
- package/dist/server-safe/settingsSearch.d.ts.map +1 -0
- package/dist/server-safe/settingsSearch.js +8 -0
- package/dist/server-safe/settingsSearch.js.map +1 -0
- package/dist/server-safe/supportChat.d.ts +59 -0
- package/dist/server-safe/supportChat.d.ts.map +1 -0
- package/dist/server-safe/supportChat.js +56 -0
- package/dist/server-safe/supportChat.js.map +1 -0
- package/dist/server-safe/templates.d.ts +15 -0
- package/dist/server-safe/templates.d.ts.map +1 -0
- package/dist/server-safe/templates.js +91 -0
- package/dist/server-safe/templates.js.map +1 -0
- package/dist/server-safe/templates.test.d.ts +2 -0
- package/dist/server-safe/templates.test.d.ts.map +1 -0
- package/dist/server-safe/templates.test.js +62 -0
- package/dist/server-safe/templates.test.js.map +1 -0
- package/dist/server-safe/trash.d.ts +50 -0
- package/dist/server-safe/trash.d.ts.map +1 -0
- package/dist/server-safe/trash.js +100 -0
- package/dist/server-safe/trash.js.map +1 -0
- package/dist/utils/LogHandler.d.ts +3 -0
- package/dist/utils/LogHandler.d.ts.map +1 -0
- package/dist/utils/LogHandler.js +16 -0
- package/dist/utils/LogHandler.js.map +1 -0
- package/dist/utils/convertSupabaseImagesToAssets.d.ts +28 -0
- package/dist/utils/convertSupabaseImagesToAssets.d.ts.map +1 -0
- package/dist/utils/convertSupabaseImagesToAssets.js +14 -0
- package/dist/utils/convertSupabaseImagesToAssets.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
-- Transactional wallet charging for marketing sends.
|
|
2
|
+
--
|
|
3
|
+
-- chargeMarketingUsage/refundMarketingCharge in autopilot-web previously
|
|
4
|
+
-- performed the claim insert, usage event, balance movement, and status
|
|
5
|
+
-- update as four separate PostgREST calls; any failure between them left a
|
|
6
|
+
-- split state (a claimed key whose money never moved, a completed movement
|
|
7
|
+
-- stuck 'pending', a credited refund whose claim row was already terminal).
|
|
8
|
+
-- These functions make each charge/refund one transaction, so those states
|
|
9
|
+
-- can no longer exist:
|
|
10
|
+
--
|
|
11
|
+
-- - unexpected errors abort the WHOLE transaction: no claim row, no usage
|
|
12
|
+
-- event, no money moved - the caller may safely retry with the same
|
|
13
|
+
-- idempotency key;
|
|
14
|
+
-- - insufficient funds (deduct_from_balance's balance floor) is a business
|
|
15
|
+
-- outcome, not a fault: the charge row COMMITS as status 'failed' with
|
|
16
|
+
-- metadata.failure = 'insufficient_funds', so uncollected post-send
|
|
17
|
+
-- charges stay queryable/collectible, while the money (never moved) and
|
|
18
|
+
-- the row can no longer disagree;
|
|
19
|
+
-- - a lost response after commit is self-correcting: the transaction
|
|
20
|
+
-- committed whole, so a retry hits the idempotency key and no-ops with
|
|
21
|
+
-- 'already_charged' / 'already_refunded'.
|
|
22
|
+
--
|
|
23
|
+
-- Charge quote math (quota, rates, billable remainder) stays in web's
|
|
24
|
+
-- marketingCharging.ts - charge_marketing_usage only owns the write phase.
|
|
25
|
+
-- Refund math is the exception: it derives entirely from the deduction row
|
|
26
|
+
-- being reversed, so it lives in refund_marketing_charge (see below).
|
|
27
|
+
|
|
28
|
+
create or replace function "public"."charge_marketing_usage"(
|
|
29
|
+
"input_company_id" uuid,
|
|
30
|
+
"input_meter" text,
|
|
31
|
+
"input_period_start" date,
|
|
32
|
+
"input_period_end" date,
|
|
33
|
+
"input_quantity_total" integer,
|
|
34
|
+
"input_quantity_included" numeric,
|
|
35
|
+
"input_quantity_charged" numeric,
|
|
36
|
+
"input_unit_rate" numeric,
|
|
37
|
+
"input_amount_cents" integer,
|
|
38
|
+
"input_idempotency_key" text,
|
|
39
|
+
"input_source" text,
|
|
40
|
+
-- Pre-send callers (email) abort the send when the deduction fails, so
|
|
41
|
+
-- the usage event must not survive an insufficient-funds failure;
|
|
42
|
+
-- post-send callers (SMS) keep it - the messages went out.
|
|
43
|
+
"input_release_usage_on_failure" boolean default false
|
|
44
|
+
) returns text
|
|
45
|
+
language plpgsql
|
|
46
|
+
security invoker
|
|
47
|
+
set search_path = public
|
|
48
|
+
as $$
|
|
49
|
+
begin
|
|
50
|
+
insert into "public"."usage_charge" (
|
|
51
|
+
"company_id", "period_start", "period_end", "meter", "kind",
|
|
52
|
+
"quantity_total", "quantity_included", "quantity_charged",
|
|
53
|
+
"unit_rate", "amount_cents", "status", "idempotency_key", "metadata"
|
|
54
|
+
) values (
|
|
55
|
+
input_company_id, input_period_start, input_period_end, input_meter,
|
|
56
|
+
'wallet_deduction',
|
|
57
|
+
input_quantity_total, input_quantity_included, input_quantity_charged,
|
|
58
|
+
input_unit_rate, input_amount_cents,
|
|
59
|
+
case when input_amount_cents > 0 then 'pending' else 'zero' end,
|
|
60
|
+
input_idempotency_key,
|
|
61
|
+
jsonb_build_object('source', input_source)
|
|
62
|
+
)
|
|
63
|
+
on conflict ("idempotency_key") do nothing;
|
|
64
|
+
if not found then
|
|
65
|
+
return 'already_charged';
|
|
66
|
+
end if;
|
|
67
|
+
|
|
68
|
+
if input_quantity_total <> 0 then
|
|
69
|
+
insert into "public"."usage_event"
|
|
70
|
+
("company_id", "meter", "quantity", "source", "ref")
|
|
71
|
+
values
|
|
72
|
+
(input_company_id, input_meter, input_quantity_total,
|
|
73
|
+
input_source, input_idempotency_key)
|
|
74
|
+
on conflict ("company_id", "meter", "ref") where "ref" is not null
|
|
75
|
+
do nothing;
|
|
76
|
+
end if;
|
|
77
|
+
|
|
78
|
+
if input_amount_cents <= 0 then
|
|
79
|
+
return 'zero';
|
|
80
|
+
end if;
|
|
81
|
+
|
|
82
|
+
begin
|
|
83
|
+
perform "public"."deduct_from_balance"(
|
|
84
|
+
input_company_id, input_amount_cents / 100.0
|
|
85
|
+
);
|
|
86
|
+
exception when others then
|
|
87
|
+
-- 'AP402' is deduct_from_balance's stable insufficient-funds
|
|
88
|
+
-- errcode (see the update_deduct_from_balance_errcode migration);
|
|
89
|
+
-- the message match is a belt-and-braces fallback in case a later
|
|
90
|
+
-- hand edit of that function drops the errcode.
|
|
91
|
+
if sqlstate = 'AP402' or sqlerrm like 'Insufficient funds%' then
|
|
92
|
+
update "public"."usage_charge"
|
|
93
|
+
set "status" = 'failed',
|
|
94
|
+
"metadata" = "metadata" || jsonb_build_object(
|
|
95
|
+
'failure', 'insufficient_funds',
|
|
96
|
+
'failure_message', sqlerrm
|
|
97
|
+
)
|
|
98
|
+
where "idempotency_key" = input_idempotency_key;
|
|
99
|
+
if input_release_usage_on_failure then
|
|
100
|
+
delete from "public"."usage_event"
|
|
101
|
+
where "company_id" = input_company_id
|
|
102
|
+
and "meter" = input_meter
|
|
103
|
+
and "ref" = input_idempotency_key;
|
|
104
|
+
end if;
|
|
105
|
+
return 'insufficient_funds';
|
|
106
|
+
end if;
|
|
107
|
+
raise;
|
|
108
|
+
end;
|
|
109
|
+
|
|
110
|
+
update "public"."usage_charge"
|
|
111
|
+
set "status" = 'charged'
|
|
112
|
+
where "idempotency_key" = input_idempotency_key;
|
|
113
|
+
return 'charged';
|
|
114
|
+
end;
|
|
115
|
+
$$;
|
|
116
|
+
|
|
117
|
+
alter function "public"."charge_marketing_usage"(
|
|
118
|
+
uuid, text, date, date, integer, numeric, numeric, numeric, integer,
|
|
119
|
+
text, text, boolean
|
|
120
|
+
) owner to "postgres";
|
|
121
|
+
|
|
122
|
+
-- Refund mirror. Everything money-shaped is derived here from the
|
|
123
|
+
-- deduction row being reversed - the refund's idempotency key is
|
|
124
|
+
-- '<deduction key>:refund', units are capped by what the deduction
|
|
125
|
+
-- recorded, and the rate and meter come from the row - so the caller
|
|
126
|
+
-- supplies no amounts and a malformed request cannot over-credit,
|
|
127
|
+
-- re-credit under a fresh key, or refund a nonexistent deduction. Returns
|
|
128
|
+
-- jsonb (unlike the charge function's text) because the caller needs the
|
|
129
|
+
-- refunded amount computed here.
|
|
130
|
+
--
|
|
131
|
+
-- Free quota is consumed before billed units, so the billed units are the
|
|
132
|
+
-- LAST quantity_charged of the batch - the unsent tail refunds from the
|
|
133
|
+
-- billed portion first. A deduction that never charged (status 'failed' or
|
|
134
|
+
-- 'zero') moves no money, and releases quota only if its usage event is
|
|
135
|
+
-- still recorded - a failed pre-send charge already released it.
|
|
136
|
+
--
|
|
137
|
+
-- add_to_balance has no balance floor, so there is no business-failure
|
|
138
|
+
-- branch: any error aborts the whole transaction (claim row included),
|
|
139
|
+
-- leaving the refund cleanly retryable.
|
|
140
|
+
create or replace function "public"."refund_marketing_charge"(
|
|
141
|
+
"input_company_id" uuid,
|
|
142
|
+
"input_period_start" date,
|
|
143
|
+
"input_period_end" date,
|
|
144
|
+
"input_unsent_units" integer,
|
|
145
|
+
"input_deduction_key" text
|
|
146
|
+
) returns jsonb
|
|
147
|
+
language plpgsql
|
|
148
|
+
security invoker
|
|
149
|
+
set search_path = public
|
|
150
|
+
as $$
|
|
151
|
+
declare
|
|
152
|
+
deduction "public"."usage_charge"%rowtype;
|
|
153
|
+
refund_key text := input_deduction_key || ':refund';
|
|
154
|
+
unsent integer;
|
|
155
|
+
refund_units numeric;
|
|
156
|
+
refund_cents integer;
|
|
157
|
+
begin
|
|
158
|
+
select * into deduction
|
|
159
|
+
from "public"."usage_charge"
|
|
160
|
+
where "idempotency_key" = input_deduction_key
|
|
161
|
+
and "company_id" = input_company_id
|
|
162
|
+
and "kind" = 'wallet_deduction';
|
|
163
|
+
if not found then
|
|
164
|
+
return jsonb_build_object(
|
|
165
|
+
'outcome', 'no_deduction', 'refunded_cents', 0
|
|
166
|
+
);
|
|
167
|
+
end if;
|
|
168
|
+
|
|
169
|
+
unsent := least(
|
|
170
|
+
input_unsent_units::numeric, deduction."quantity_total"
|
|
171
|
+
)::integer;
|
|
172
|
+
if unsent <= 0 then
|
|
173
|
+
return jsonb_build_object('outcome', 'zero', 'refunded_cents', 0);
|
|
174
|
+
end if;
|
|
175
|
+
refund_units := least(unsent::numeric, deduction."quantity_charged");
|
|
176
|
+
refund_cents := case
|
|
177
|
+
when deduction."status" = 'charged'
|
|
178
|
+
then round(refund_units * deduction."unit_rate" * 100)::integer
|
|
179
|
+
else 0
|
|
180
|
+
end;
|
|
181
|
+
|
|
182
|
+
insert into "public"."usage_charge" (
|
|
183
|
+
"company_id", "period_start", "period_end", "meter", "kind",
|
|
184
|
+
"quantity_total", "quantity_included", "quantity_charged",
|
|
185
|
+
"unit_rate", "amount_cents", "status", "idempotency_key", "metadata"
|
|
186
|
+
) values (
|
|
187
|
+
input_company_id, input_period_start, input_period_end,
|
|
188
|
+
deduction."meter",
|
|
189
|
+
'wallet_refund',
|
|
190
|
+
unsent, unsent - refund_units, refund_units,
|
|
191
|
+
deduction."unit_rate", refund_cents,
|
|
192
|
+
case when refund_cents > 0 then 'pending' else 'zero' end,
|
|
193
|
+
refund_key,
|
|
194
|
+
jsonb_build_object('refunds', input_deduction_key)
|
|
195
|
+
)
|
|
196
|
+
on conflict ("idempotency_key") do nothing;
|
|
197
|
+
if not found then
|
|
198
|
+
return jsonb_build_object(
|
|
199
|
+
'outcome', 'already_refunded', 'refunded_cents', 0
|
|
200
|
+
);
|
|
201
|
+
end if;
|
|
202
|
+
|
|
203
|
+
-- Release the unsent units' quota consumption - but only if the
|
|
204
|
+
-- deduction's usage event is still recorded. A pre-send charge that
|
|
205
|
+
-- failed with release_usage_on_failure already deleted its event, so
|
|
206
|
+
-- releasing again here would drive net usage negative and grant quota
|
|
207
|
+
-- the company never consumed.
|
|
208
|
+
if exists (
|
|
209
|
+
select 1 from "public"."usage_event"
|
|
210
|
+
where "company_id" = input_company_id
|
|
211
|
+
and "meter" = deduction."meter"
|
|
212
|
+
and "ref" = input_deduction_key
|
|
213
|
+
) then
|
|
214
|
+
insert into "public"."usage_event"
|
|
215
|
+
("company_id", "meter", "quantity", "source", "ref")
|
|
216
|
+
values
|
|
217
|
+
(input_company_id, deduction."meter", -unsent, 'refund',
|
|
218
|
+
refund_key)
|
|
219
|
+
on conflict ("company_id", "meter", "ref") where "ref" is not null
|
|
220
|
+
do nothing;
|
|
221
|
+
end if;
|
|
222
|
+
|
|
223
|
+
if refund_cents <= 0 then
|
|
224
|
+
return jsonb_build_object('outcome', 'zero', 'refunded_cents', 0);
|
|
225
|
+
end if;
|
|
226
|
+
|
|
227
|
+
perform "public"."add_to_balance"(
|
|
228
|
+
input_company_id, refund_cents / 100.0
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
update "public"."usage_charge"
|
|
232
|
+
set "status" = 'charged'
|
|
233
|
+
where "idempotency_key" = refund_key;
|
|
234
|
+
return jsonb_build_object(
|
|
235
|
+
'outcome', 'refunded', 'refunded_cents', refund_cents
|
|
236
|
+
);
|
|
237
|
+
end;
|
|
238
|
+
$$;
|
|
239
|
+
|
|
240
|
+
alter function "public"."refund_marketing_charge"(
|
|
241
|
+
uuid, date, date, integer, text
|
|
242
|
+
) owner to "postgres";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- Grants for the transactional marketing charge/refund functions.
|
|
2
|
+
--
|
|
3
|
+
-- These move money, so unlike sum_usage_events they are service_role-only:
|
|
4
|
+
-- the web server's admin client is the sole caller. Functions default to
|
|
5
|
+
-- EXECUTE for public on creation, so revoke that and grant service_role
|
|
6
|
+
-- explicitly. security invoker + no authenticated/anon grant means no
|
|
7
|
+
-- privilege escalation path exists through them.
|
|
8
|
+
|
|
9
|
+
revoke all on function "public"."charge_marketing_usage"(
|
|
10
|
+
uuid, text, date, date, integer, numeric, numeric, numeric, integer,
|
|
11
|
+
text, text, boolean
|
|
12
|
+
) from public;
|
|
13
|
+
revoke all on function "public"."charge_marketing_usage"(
|
|
14
|
+
uuid, text, date, date, integer, numeric, numeric, numeric, integer,
|
|
15
|
+
text, text, boolean
|
|
16
|
+
) from "anon";
|
|
17
|
+
revoke all on function "public"."charge_marketing_usage"(
|
|
18
|
+
uuid, text, date, date, integer, numeric, numeric, numeric, integer,
|
|
19
|
+
text, text, boolean
|
|
20
|
+
) from "authenticated";
|
|
21
|
+
grant execute on function "public"."charge_marketing_usage"(
|
|
22
|
+
uuid, text, date, date, integer, numeric, numeric, numeric, integer,
|
|
23
|
+
text, text, boolean
|
|
24
|
+
) to "service_role";
|
|
25
|
+
|
|
26
|
+
revoke all on function "public"."refund_marketing_charge"(
|
|
27
|
+
uuid, date, date, integer, text
|
|
28
|
+
) from public;
|
|
29
|
+
revoke all on function "public"."refund_marketing_charge"(
|
|
30
|
+
uuid, date, date, integer, text
|
|
31
|
+
) from "anon";
|
|
32
|
+
revoke all on function "public"."refund_marketing_charge"(
|
|
33
|
+
uuid, date, date, integer, text
|
|
34
|
+
) from "authenticated";
|
|
35
|
+
grant execute on function "public"."refund_marketing_charge"(
|
|
36
|
+
uuid, date, date, integer, text
|
|
37
|
+
) to "service_role";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
-- Give deduct_from_balance's insufficient-funds rejection a stable,
|
|
2
|
+
-- machine-readable SQLSTATE ('AP402', app-defined "payment required").
|
|
3
|
+
-- charge_marketing_usage branches on this errcode to decide whether a
|
|
4
|
+
-- deduction failure is a business outcome (commit the charge row as
|
|
5
|
+
-- 'failed', collectible later) or an unexpected fault (roll the whole
|
|
6
|
+
-- transaction back); previously the only contract was the message text,
|
|
7
|
+
-- which a wording change would silently break.
|
|
8
|
+
--
|
|
9
|
+
-- Everything else - signature, message, floor, SECURITY DEFINER, grants
|
|
10
|
+
-- (preserved by CREATE OR REPLACE) - is unchanged, so existing callers
|
|
11
|
+
-- are unaffected.
|
|
12
|
+
|
|
13
|
+
CREATE OR REPLACE FUNCTION "public"."deduct_from_balance"("input_company_id" "uuid", "amount_to_deduct" numeric) RETURNS numeric
|
|
14
|
+
LANGUAGE "plpgsql" SECURITY DEFINER
|
|
15
|
+
AS $$
|
|
16
|
+
DECLARE
|
|
17
|
+
current_balance NUMERIC;
|
|
18
|
+
new_balance NUMERIC;
|
|
19
|
+
BEGIN
|
|
20
|
+
-- First, get the current balance
|
|
21
|
+
SELECT balance INTO current_balance
|
|
22
|
+
FROM billing
|
|
23
|
+
WHERE company_id = input_company_id;
|
|
24
|
+
|
|
25
|
+
-- Calculate the new balance
|
|
26
|
+
new_balance := current_balance - amount_to_deduct;
|
|
27
|
+
|
|
28
|
+
-- Check if the new balance would be less than -20.00
|
|
29
|
+
IF new_balance < -20.00 THEN
|
|
30
|
+
RAISE EXCEPTION 'Insufficient funds: Balance cannot go below -20.00'
|
|
31
|
+
USING ERRCODE = 'AP402';
|
|
32
|
+
END IF;
|
|
33
|
+
|
|
34
|
+
-- If we've passed the check, update the balance
|
|
35
|
+
UPDATE billing
|
|
36
|
+
SET balance = new_balance
|
|
37
|
+
WHERE company_id = input_company_id;
|
|
38
|
+
|
|
39
|
+
-- Return the new balance
|
|
40
|
+
RETURN new_balance;
|
|
41
|
+
END;
|
|
42
|
+
$$;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
-- Lock the billing row while deducting. The read was a bare SELECT, so two
|
|
2
|
+
-- concurrent charges (e.g. an SMS blast chunk and a sequence batch) could
|
|
3
|
+
-- both read the same balance, both pass the -20.00 floor, and both write
|
|
4
|
+
-- their own absolute new_balance - the second write silently erases the
|
|
5
|
+
-- first deduction even though both usage_charge rows commit as 'charged'.
|
|
6
|
+
-- FOR UPDATE serializes the read-modify-write per company row, which also
|
|
7
|
+
-- makes the floor enforceable under concurrency. The lock is held to the
|
|
8
|
+
-- end of the caller's transaction (charge_marketing_usage runs this inside
|
|
9
|
+
-- one txn), which is exactly the window that needs protecting.
|
|
10
|
+
--
|
|
11
|
+
-- Everything else - signature, message, floor, ERRCODE 'AP402',
|
|
12
|
+
-- SECURITY DEFINER, grants (preserved by CREATE OR REPLACE) - is unchanged,
|
|
13
|
+
-- so existing callers are unaffected.
|
|
14
|
+
|
|
15
|
+
CREATE OR REPLACE FUNCTION "public"."deduct_from_balance"("input_company_id" "uuid", "amount_to_deduct" numeric) RETURNS numeric
|
|
16
|
+
LANGUAGE "plpgsql" SECURITY DEFINER
|
|
17
|
+
AS $$
|
|
18
|
+
DECLARE
|
|
19
|
+
current_balance NUMERIC;
|
|
20
|
+
new_balance NUMERIC;
|
|
21
|
+
BEGIN
|
|
22
|
+
-- Get the current balance, locking the row so a concurrent deduction
|
|
23
|
+
-- can't read the same starting balance
|
|
24
|
+
SELECT balance INTO current_balance
|
|
25
|
+
FROM billing
|
|
26
|
+
WHERE company_id = input_company_id
|
|
27
|
+
FOR UPDATE;
|
|
28
|
+
|
|
29
|
+
-- Calculate the new balance
|
|
30
|
+
new_balance := current_balance - amount_to_deduct;
|
|
31
|
+
|
|
32
|
+
-- Check if the new balance would be less than -20.00
|
|
33
|
+
IF new_balance < -20.00 THEN
|
|
34
|
+
RAISE EXCEPTION 'Insufficient funds: Balance cannot go below -20.00'
|
|
35
|
+
USING ERRCODE = 'AP402';
|
|
36
|
+
END IF;
|
|
37
|
+
|
|
38
|
+
-- If we've passed the check, update the balance
|
|
39
|
+
UPDATE billing
|
|
40
|
+
SET balance = new_balance
|
|
41
|
+
WHERE company_id = input_company_id;
|
|
42
|
+
|
|
43
|
+
-- Return the new balance
|
|
44
|
+
RETURN new_balance;
|
|
45
|
+
END;
|
|
46
|
+
$$;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Mirror blast_email_chunk (20260717162900): per-chunk delivery outcomes so
|
|
2
|
+
-- blast_sms totals can be derived by aggregating chunk rows (overlapping
|
|
3
|
+
-- chunk workers can't lose each other's increments the way the current
|
|
4
|
+
-- read-modify-write on blast_sms.processed_chunks can), plus the claim
|
|
5
|
+
-- timestamp that lets a retry prove a 'processing' chunk's worker was
|
|
6
|
+
-- hard-killed and reap it - without that, a mid-chunk crash strands the
|
|
7
|
+
-- blast in 'processing' forever.
|
|
8
|
+
--
|
|
9
|
+
-- No per-chunk cost column: blast_sms.actual_cost stays derived from
|
|
10
|
+
-- usage_charge rows keyed 'blast-sms:{blastId}:chunk:%'.
|
|
11
|
+
--
|
|
12
|
+
-- All columns nullable so chunks written by the pre-reaper worker are
|
|
13
|
+
-- unaffected; the worker treats a null claimed_at as not-provably-stale.
|
|
14
|
+
|
|
15
|
+
alter table "public"."blast_sms_chunk"
|
|
16
|
+
add column if not exists "successful_count" integer,
|
|
17
|
+
add column if not exists "failed_count" integer,
|
|
18
|
+
add column if not exists "claimed_at" timestamp with time zone,
|
|
19
|
+
add column if not exists "recipient_count" integer;
|
|
20
|
+
|
|
21
|
+
-- Same access paths as the email worker: aggregate/sweep by blast, claim by
|
|
22
|
+
-- QStash message id.
|
|
23
|
+
create index if not exists "blast_sms_chunk_blast_sms_id_idx"
|
|
24
|
+
on "public"."blast_sms_chunk" ("blast_sms_id");
|
|
25
|
+
|
|
26
|
+
create index if not exists "blast_sms_chunk_qstash_message_id_idx"
|
|
27
|
+
on "public"."blast_sms_chunk" ("qstash_message_id");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
-- Per-USER Google Calendar connection — the first user-scoped integration
|
|
2
|
+
-- (every other *_connection table is one row per company). A user connects
|
|
3
|
+
-- their personal Google account and autopilot-web mirrors the jobs, events,
|
|
4
|
+
-- and estimates they can see onto their primary Google calendar. The refresh
|
|
5
|
+
-- token is AES-256-GCM encrypted by the web layer (v1.<iv>.<tag>.<ct>
|
|
6
|
+
-- format, GOOGLE_CALENDAR_TOKEN_ENCRYPTION_KEY) and, like Bing/Facebook Ads,
|
|
7
|
+
-- exposed only to service-role routes by the companion RLS migration —
|
|
8
|
+
-- clients read connection state through /api/google-calendar/status.
|
|
9
|
+
--
|
|
10
|
+
-- status:
|
|
11
|
+
-- active normal operation
|
|
12
|
+
-- needs_reauth Google reported the grant revoked/expired; sync pauses
|
|
13
|
+
-- until the user reconnects
|
|
14
|
+
-- disconnecting user disconnected; a 'purge' sync task is deleting the
|
|
15
|
+
-- mirrored Google events, after which the worker deletes
|
|
16
|
+
-- this row
|
|
17
|
+
create table if not exists "public"."google_calendar_connection" (
|
|
18
|
+
"id" uuid default gen_random_uuid() not null,
|
|
19
|
+
"created_at" timestamp with time zone default now() not null,
|
|
20
|
+
"updated_at" timestamp with time zone default now() not null,
|
|
21
|
+
"company_id" uuid not null,
|
|
22
|
+
"user_id" uuid not null,
|
|
23
|
+
"google_email" text,
|
|
24
|
+
"refresh_token_encrypted" text not null,
|
|
25
|
+
-- false pauses the mirror without touching the token or the already
|
|
26
|
+
-- synced events; re-enabling runs a full reconcile to catch up
|
|
27
|
+
"sync_enabled" boolean default true not null,
|
|
28
|
+
"status" text default 'active' not null,
|
|
29
|
+
"last_synced_at" timestamp with time zone,
|
|
30
|
+
constraint "google_calendar_connection_pkey" primary key ("id"),
|
|
31
|
+
-- a user working for two companies connects (and mirrors) per company
|
|
32
|
+
constraint "google_calendar_connection_company_user_key"
|
|
33
|
+
unique ("company_id", "user_id"),
|
|
34
|
+
-- These cascades are the LAST-RESORT cleanup, not the purge path: the
|
|
35
|
+
-- refresh token needed to delete the mirrored Google events dies with
|
|
36
|
+
-- this row, so account deletion (delete-own-account-owner, the only flow
|
|
37
|
+
-- that deletes company/user rows) best-effort purges every connection's
|
|
38
|
+
-- events and revokes the grants BEFORE deleting the company. Employee
|
|
39
|
+
-- removal never deletes user rows, so it never hits these.
|
|
40
|
+
constraint "google_calendar_connection_company_id_fkey"
|
|
41
|
+
foreign key ("company_id") references "public"."company"("id") on delete cascade,
|
|
42
|
+
constraint "google_calendar_connection_user_id_fkey"
|
|
43
|
+
foreign key ("user_id") references "public"."user"("id") on delete cascade,
|
|
44
|
+
constraint "google_calendar_connection_status_check"
|
|
45
|
+
check ("status" in ('active', 'needs_reauth', 'disconnecting'))
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
alter table "public"."google_calendar_connection" owner to "postgres";
|
|
49
|
+
|
|
50
|
+
create or replace function "public"."set_google_calendar_connection_updated_at"()
|
|
51
|
+
returns trigger
|
|
52
|
+
language plpgsql
|
|
53
|
+
as $$
|
|
54
|
+
begin
|
|
55
|
+
new."updated_at" = now();
|
|
56
|
+
return new;
|
|
57
|
+
end;
|
|
58
|
+
$$;
|
|
59
|
+
|
|
60
|
+
alter function "public"."set_google_calendar_connection_updated_at"() owner to "postgres";
|
|
61
|
+
|
|
62
|
+
create or replace trigger "set_google_calendar_connection_updated_at_trigger"
|
|
63
|
+
before update on "public"."google_calendar_connection"
|
|
64
|
+
for each row execute function "public"."set_google_calendar_connection_updated_at"();
|
|
65
|
+
|
|
66
|
+
-- DB-stored OAuth CSRF state (the qb_state model, in its own table because
|
|
67
|
+
-- no connection row exists yet at connect time, and because the mobile
|
|
68
|
+
-- in-app-browser flow completes on a sessionless server callback where a
|
|
69
|
+
-- cookie-based state check is impossible). The callback accepts a state only
|
|
70
|
+
-- when younger than 15 minutes and deletes it on use; the connect route
|
|
71
|
+
-- clears the user's stale rows when issuing a new one.
|
|
72
|
+
create table if not exists "public"."google_calendar_oauth_state" (
|
|
73
|
+
"state" uuid default gen_random_uuid() not null,
|
|
74
|
+
"created_at" timestamp with time zone default now() not null,
|
|
75
|
+
"company_id" uuid not null,
|
|
76
|
+
"user_id" uuid not null,
|
|
77
|
+
constraint "google_calendar_oauth_state_pkey" primary key ("state"),
|
|
78
|
+
constraint "google_calendar_oauth_state_company_id_fkey"
|
|
79
|
+
foreign key ("company_id") references "public"."company"("id") on delete cascade,
|
|
80
|
+
constraint "google_calendar_oauth_state_user_id_fkey"
|
|
81
|
+
foreign key ("user_id") references "public"."user"("id") on delete cascade
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
alter table "public"."google_calendar_oauth_state" owner to "postgres";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Google Calendar connections are accessed only by authenticated server
|
|
2
|
+
-- routes using the service role, matching the Bing/Facebook Ads posture. The
|
|
3
|
+
-- browser and mobile app get no direct table access; the encrypted refresh
|
|
4
|
+
-- token in particular must never be readable client-side. Clients read
|
|
5
|
+
-- connection state through /api/google-calendar/status.
|
|
6
|
+
alter table "public"."google_calendar_connection" enable row level security;
|
|
7
|
+
alter table "public"."google_calendar_oauth_state" enable row level security;
|
|
8
|
+
|
|
9
|
+
revoke all on table "public"."google_calendar_connection" from public;
|
|
10
|
+
revoke all on table "public"."google_calendar_connection" from "anon";
|
|
11
|
+
revoke all on table "public"."google_calendar_connection" from "authenticated";
|
|
12
|
+
|
|
13
|
+
revoke all on table "public"."google_calendar_oauth_state" from public;
|
|
14
|
+
revoke all on table "public"."google_calendar_oauth_state" from "anon";
|
|
15
|
+
revoke all on table "public"."google_calendar_oauth_state" from "authenticated";
|
|
16
|
+
|
|
17
|
+
grant all on table "public"."google_calendar_connection" to "service_role";
|
|
18
|
+
grant all on table "public"."google_calendar_oauth_state" to "service_role";
|
|
19
|
+
|
|
20
|
+
revoke all on function "public"."set_google_calendar_connection_updated_at"() from public;
|
|
21
|
+
revoke all on function "public"."set_google_calendar_connection_updated_at"() from "anon";
|
|
22
|
+
revoke all on function "public"."set_google_calendar_connection_updated_at"() from "authenticated";
|
|
23
|
+
grant execute on function "public"."set_google_calendar_connection_updated_at"() to "service_role";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
-- Google Calendar sync bookkeeping: the event map (Autopilot entity →
|
|
2
|
+
-- mirrored Google event ids, per connection) and the per-(user, entity) task
|
|
3
|
+
-- queue. The fan-out pass in autopilot-web (webhook-outbox-cron) converts
|
|
4
|
+
-- job.*/event.*/estimate.* outbound_events into at most one PENDING task per
|
|
5
|
+
-- (connected user, entity); /api/google-calendar/sync-cron claims due tasks
|
|
6
|
+
-- via claim_gcal_sync_tasks, recomputes what that user should see, diffs it
|
|
7
|
+
-- against google_calendar_event_map, and patches the user's primary Google
|
|
8
|
+
-- calendar. Tasks are self-contained (no FK to outbound_event) so the outbox
|
|
9
|
+
-- retention purge never has to consider calendar state.
|
|
10
|
+
|
|
11
|
+
-- One row per mirrored Google event. entity_id is always the PARENT id
|
|
12
|
+
-- (job.id / event.id / estimate.id) — never job_schedule.id, because editing
|
|
13
|
+
-- a job deletes and re-creates its schedule rows with fresh uuids (see
|
|
14
|
+
-- reminder_dispatch), so a multi-block job simply maps to several rows with
|
|
15
|
+
-- the same entity_id. start_time/end_time/content_hash record what was last
|
|
16
|
+
-- pushed to Google: the times give the diff a stable pairing order and let
|
|
17
|
+
-- the worker leave past events frozen (the mirror is future-only), and the
|
|
18
|
+
-- hash lets it skip no-op patches.
|
|
19
|
+
create table if not exists "public"."google_calendar_event_map" (
|
|
20
|
+
"id" uuid default gen_random_uuid() not null,
|
|
21
|
+
"created_at" timestamp with time zone default now() not null,
|
|
22
|
+
"company_id" uuid not null,
|
|
23
|
+
"connection_id" uuid not null,
|
|
24
|
+
"user_id" uuid not null,
|
|
25
|
+
"entity_type" text not null,
|
|
26
|
+
"entity_id" uuid not null,
|
|
27
|
+
"google_event_id" text not null,
|
|
28
|
+
"start_time" timestamp with time zone not null,
|
|
29
|
+
"end_time" timestamp with time zone not null,
|
|
30
|
+
"content_hash" text not null,
|
|
31
|
+
constraint "google_calendar_event_map_pkey" primary key ("id"),
|
|
32
|
+
constraint "google_calendar_event_map_google_event_key"
|
|
33
|
+
unique ("connection_id", "entity_type", "entity_id", "google_event_id"),
|
|
34
|
+
constraint "google_calendar_event_map_connection_id_fkey"
|
|
35
|
+
foreign key ("connection_id") references "public"."google_calendar_connection"("id") on delete cascade,
|
|
36
|
+
constraint "google_calendar_event_map_company_id_fkey"
|
|
37
|
+
foreign key ("company_id") references "public"."company"("id") on delete cascade,
|
|
38
|
+
constraint "google_calendar_event_map_entity_type_check"
|
|
39
|
+
check ("entity_type" in ('job', 'event', 'estimate'))
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
alter table "public"."google_calendar_event_map" owner to "postgres";
|
|
43
|
+
|
|
44
|
+
-- reconcileEntity reads by entity, purge/reconcileAll page by connection
|
|
45
|
+
create index if not exists "google_calendar_event_map_entity_idx"
|
|
46
|
+
on "public"."google_calendar_event_map" ("connection_id", "entity_type", "entity_id");
|
|
47
|
+
|
|
48
|
+
create index if not exists "google_calendar_event_map_company_idx"
|
|
49
|
+
on "public"."google_calendar_event_map" ("company_id");
|
|
50
|
+
|
|
51
|
+
-- entity_type 'reconcile_all' (full rebuild: initial backfill after connect,
|
|
52
|
+
-- re-enable catch-up, nightly drift/role-change safety net) and 'purge'
|
|
53
|
+
-- (disconnect cleanup) address a CONNECTION, so their entity_id is the
|
|
54
|
+
-- google_calendar_connection id; cursor lets those long runs resume across
|
|
55
|
+
-- worker time budgets.
|
|
56
|
+
create table if not exists "public"."google_calendar_sync_task" (
|
|
57
|
+
"id" uuid default gen_random_uuid() not null,
|
|
58
|
+
"created_at" timestamp with time zone default now() not null,
|
|
59
|
+
"company_id" uuid not null,
|
|
60
|
+
"user_id" uuid not null,
|
|
61
|
+
"entity_type" text not null,
|
|
62
|
+
"entity_id" uuid not null,
|
|
63
|
+
-- informational: newest event that (re)enqueued this task. Deliberately
|
|
64
|
+
-- NO foreign key — outbound_event rows are purged after 90 days and a
|
|
65
|
+
-- dangling debug pointer is fine.
|
|
66
|
+
"trigger_event_id" uuid,
|
|
67
|
+
"cursor" jsonb,
|
|
68
|
+
"status" text default 'pending' not null,
|
|
69
|
+
"attempt_count" integer default 0 not null,
|
|
70
|
+
"next_attempt_at" timestamp with time zone default now() not null,
|
|
71
|
+
"last_attempt_at" timestamp with time zone,
|
|
72
|
+
"last_error" text,
|
|
73
|
+
constraint "google_calendar_sync_task_pkey" primary key ("id"),
|
|
74
|
+
constraint "google_calendar_sync_task_company_id_fkey"
|
|
75
|
+
foreign key ("company_id") references "public"."company"("id") on delete cascade,
|
|
76
|
+
constraint "google_calendar_sync_task_entity_type_check"
|
|
77
|
+
check ("entity_type" in ('job', 'event', 'estimate', 'reconcile_all', 'purge')),
|
|
78
|
+
-- pending: waiting for next_attempt_at
|
|
79
|
+
-- processing: claimed by a worker run (stuck rows swept back to pending)
|
|
80
|
+
-- done: reconciled into Google Calendar
|
|
81
|
+
-- skipped: connection missing/paused/needs_reauth, or the company's
|
|
82
|
+
-- google_calendar entitlement lapsed, at process time
|
|
83
|
+
-- dead: exhausted retries; kept for inspection
|
|
84
|
+
constraint "google_calendar_sync_task_status_check"
|
|
85
|
+
check ("status" in ('pending', 'processing', 'done', 'skipped', 'dead'))
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
alter table "public"."google_calendar_sync_task" owner to "postgres";
|
|
89
|
+
|
|
90
|
+
-- At most ONE pending task per (user, entity): any burst of events while a
|
|
91
|
+
-- task is pending collapses into it (the consumer re-reads state at process
|
|
92
|
+
-- time, so intermediate events are pure duplicates). A task already claimed
|
|
93
|
+
-- ('processing') does NOT block a new pending task — a write that lands
|
|
94
|
+
-- mid-flight must trigger another sync afterwards. user_id (not company_id)
|
|
95
|
+
-- leads the key because the same entity fans out to every connected user in
|
|
96
|
+
-- the company.
|
|
97
|
+
create unique index if not exists "google_calendar_sync_task_pending_entity_key"
|
|
98
|
+
on "public"."google_calendar_sync_task" ("user_id", "entity_type", "entity_id")
|
|
99
|
+
where "status" = 'pending';
|
|
100
|
+
|
|
101
|
+
create index if not exists "google_calendar_sync_task_due_idx"
|
|
102
|
+
on "public"."google_calendar_sync_task" ("next_attempt_at")
|
|
103
|
+
where "status" = 'pending';
|
|
104
|
+
|
|
105
|
+
-- FK support for the company cascade + failure-surfacing queries
|
|
106
|
+
create index if not exists "google_calendar_sync_task_company_idx"
|
|
107
|
+
on "public"."google_calendar_sync_task" ("company_id", "created_at");
|
|
108
|
+
|
|
109
|
+
-- Fan-out enqueue. An RPC because ON CONFLICT against a partial unique index
|
|
110
|
+
-- needs the WHERE clause in the arbiter, which supabase-js upsert cannot
|
|
111
|
+
-- express. tasks: [{company_id, user_id, entity_type, entity_id,
|
|
112
|
+
-- trigger_event_id}]
|
|
113
|
+
create or replace function "public"."enqueue_gcal_sync_tasks"("tasks" jsonb)
|
|
114
|
+
returns integer
|
|
115
|
+
language "sql"
|
|
116
|
+
security definer
|
|
117
|
+
set search_path = 'public'
|
|
118
|
+
as $$
|
|
119
|
+
with ins as (
|
|
120
|
+
insert into google_calendar_sync_task (company_id, user_id, entity_type, entity_id, trigger_event_id)
|
|
121
|
+
select distinct
|
|
122
|
+
(t ->> 'company_id')::uuid,
|
|
123
|
+
(t ->> 'user_id')::uuid,
|
|
124
|
+
t ->> 'entity_type',
|
|
125
|
+
(t ->> 'entity_id')::uuid,
|
|
126
|
+
(t ->> 'trigger_event_id')::uuid
|
|
127
|
+
from jsonb_array_elements(tasks) as t
|
|
128
|
+
on conflict ("user_id", "entity_type", "entity_id")
|
|
129
|
+
where "status" = 'pending'
|
|
130
|
+
do nothing
|
|
131
|
+
returning 1
|
|
132
|
+
)
|
|
133
|
+
select count(*)::integer from ins;
|
|
134
|
+
$$;
|
|
135
|
+
|
|
136
|
+
-- Atomic claim, mirroring claim_qb_sync_tasks (SKIP LOCKED is not
|
|
137
|
+
-- expressible through supabase-js; overlapping cron runs must never
|
|
138
|
+
-- double-sync).
|
|
139
|
+
create or replace function "public"."claim_gcal_sync_tasks"("batch_size" integer)
|
|
140
|
+
returns setof "public"."google_calendar_sync_task"
|
|
141
|
+
language "sql"
|
|
142
|
+
security definer
|
|
143
|
+
set search_path = 'public'
|
|
144
|
+
as $$
|
|
145
|
+
update google_calendar_sync_task set
|
|
146
|
+
status = 'processing',
|
|
147
|
+
attempt_count = attempt_count + 1,
|
|
148
|
+
last_attempt_at = now()
|
|
149
|
+
where id in (
|
|
150
|
+
select id from google_calendar_sync_task
|
|
151
|
+
where status = 'pending' and next_attempt_at <= now()
|
|
152
|
+
order by next_attempt_at
|
|
153
|
+
limit least(batch_size, 1000)
|
|
154
|
+
for update skip locked
|
|
155
|
+
)
|
|
156
|
+
returning *;
|
|
157
|
+
$$;
|