@intelligence-cloud/sdk 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1263 @@
1
+ import { InvalidRequestError as InvalidRequestError$1, Client, ConnectorSpec } from '@intelligence-cloud/sdk';
2
+
3
+ // src/testing/index.ts
4
+
5
+ // src/generated/spec.ts
6
+ var OPERATIONS = { "login": { "method": "POST", "path": "/auth/login", "tag": "Authentication", "role": "frontline_user", "query": [], "pathParams": [], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["email", "password"], "properties": { "email": { "type": "string", "format": "email" }, "password": { "type": "string", "format": "password" } } }, "response": { "o": { "access_token": "v", "refresh_token": "v", "token_type": "v", "expires_in": "v", "user": { "o": { "id": "v", "user_type": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "role": "v", "scopes": { "a": "v" } } }, "password_expired": "v", "status": "v" } }, "summary": "Sign in" }, "refresh": { "method": "POST", "path": "/auth/refresh", "tag": "Authentication", "role": "frontline_user", "query": [], "pathParams": [], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["refresh_token"], "properties": { "refresh_token": { "type": "string" } } }, "response": { "o": { "access_token": "v", "refresh_token": "v", "token_type": "v", "expires_in": "v", "user": { "o": { "id": "v", "user_type": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "role": "v", "scopes": { "a": "v" } } }, "password_expired": "v" } }, "summary": "Renew the access token" }, "logout": { "method": "POST", "path": "/auth/logout", "tag": "Authentication", "role": "frontline_user", "query": [], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "message": "v" } }, "summary": "Sign out" }, "getResellerBranding": { "method": "GET", "path": "/resellers/{resellerId}/branding", "tag": "Resellers", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "reseller_id": "v", "display_name": "v", "primary_accent_color": "v", "secondary_accent_color": "v", "support_email": "v", "support_portal_url": "v", "privacy_policy_url": "v", "terms_of_service_url": "v", "copyright_text": "v", "main_logo_url": "v", "favicon_url": "v", "email_logo_url": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read reseller branding" }, "updateResellerBranding": { "method": "PATCH", "path": "/resellers/{resellerId}/branding", "tag": "Resellers", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "display_name": { "type": "string" }, "primary_accent_color": { "type": "string" }, "secondary_accent_color": { "type": "string" }, "support_email": { "type": "string", "format": "email" }, "support_portal_url": { "type": "string", "format": "uri" }, "privacy_policy_url": { "type": "string", "format": "uri" }, "terms_of_service_url": { "type": "string", "format": "uri" }, "copyright_text": { "type": "string" } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "reseller_id": "v", "display_name": "v", "primary_accent_color": "v", "secondary_accent_color": "v", "support_email": "v", "support_portal_url": "v", "privacy_policy_url": "v", "terms_of_service_url": "v", "copyright_text": "v", "main_logo_url": "v", "favicon_url": "v", "email_logo_url": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update reseller branding" }, "getResellerSmtpSettings": { "method": "GET", "path": "/resellers/{resellerId}/smtp-settings", "tag": "Resellers", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "reseller_id": "v", "smtp_host": "v", "smtp_port": "v", "smtp_username": "v", "smtp_password": "v", "sender_name": "v", "sender_email": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read outbound email (SMTP) settings" }, "saveResellerSmtpSettings": { "method": "PATCH", "path": "/resellers/{resellerId}/smtp-settings", "tag": "Resellers", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["smtp_host", "smtp_port", "sender_name", "sender_email"], "properties": { "smtp_host": { "type": "string" }, "smtp_port": { "type": "integer" }, "smtp_username": { "type": "string" }, "smtp_password": { "type": "string", "format": "password" }, "sender_name": { "type": "string" }, "sender_email": { "type": "string", "format": "email" } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "reseller_id": "v", "smtp_host": "v", "smtp_port": "v", "smtp_username": "v", "smtp_password": "v", "sender_name": "v", "sender_email": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Save outbound email (SMTP) settings" }, "deleteResellerSmtpSettings": { "method": "DELETE", "path": "/resellers/{resellerId}/smtp-settings", "tag": "Resellers", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": null, "summary": "Remove outbound email (SMTP) settings" }, "listCompanies": { "method": "GET", "path": "/resellers/{resellerId}/companies", "tag": "Companies", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "is_active", "in": "query", "type": "boolean" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["resellerId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } }, "has_more": "v", "next_cursor": "v", "total_count": "v" } }, "summary": "List customer companies" }, "createCompany": { "method": "POST", "path": "/resellers/{resellerId}/companies", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["company_name", "primary_admin_contact_name", "primary_admin_contact_email", "primary_admin_contact_phone"], "properties": { "company_name": { "type": "string" }, "company_code": { "type": "string" }, "primary_admin_contact_name": { "type": "string" }, "primary_admin_contact_email": { "type": "string", "format": "email" }, "primary_admin_contact_phone": { "type": "string" }, "enabled_products": { "type": "array", "items": { "type": "string", "enum": ["after-call-copilot", "first-alert-copilot", "insights-hub"] } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } }, "invited_user": { "o": { "id": "v", "email": "v", "display_name": "v", "status": "v", "role": "v", "invited_at": "v", "invite_expires_at": "v" } } } }, "summary": "Create a customer company" }, "getCompaniesMfaSummary": { "method": "GET", "path": "/resellers/{resellerId}/companies/mfa", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["resellerId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "total_active": "v", "with_mfa_required": "v", "companies_mfa_default": "v", "mfa_available": "v" } } } }, "summary": "Read the MFA default for new companies" }, "getCompany": { "method": "GET", "path": "/companies/{companyId}", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read a company" }, "updateCompany": { "method": "PATCH", "path": "/companies/{companyId}", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "company_name": { "type": "string" }, "company_code": { "type": "string" }, "primary_admin_contact_name": { "type": "string" }, "primary_admin_contact_email": { "type": "string", "format": "email" }, "primary_admin_contact_phone": { "type": "string" }, "enabled_products": { "type": "array", "items": { "type": "string", "enum": ["after-call-copilot", "first-alert-copilot", "insights-hub"] } }, "vertical": { "type": "string" }, "address": { "type": "string" }, "mfa_enforced": { "type": "boolean" } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update a company" }, "deactivateCompany": { "method": "POST", "path": "/companies/{companyId}/deactivate", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Deactivate a company" }, "reactivateCompany": { "method": "POST", "path": "/companies/{companyId}/reactivate", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "reseller_id": "v", "reseller_name": "v", "company_name": "v", "company_code": "v", "vertical": "v", "address": "v", "primary_admin_contact_name": "v", "primary_admin_contact_email": "v", "primary_admin_contact_phone": "v", "enabled_products": { "a": "v" }, "is_active": "v", "mfa_enforced": "v", "mfa_available": "v", "location_count": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Reactivate a company" }, "getCompanySecuritySettings": { "method": "GET", "path": "/companies/{companyId}/security-settings", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "min_password_length": "v", "require_uppercase": "v", "require_numbers": "v", "require_special_chars": "v", "password_expiry_days": "v", "session_timeout_minutes": "v", "allowed_ip_ranges": { "a": "v" }, "password_policy_source": "v", "password_policy_inherited_fields": { "a": "v" } } } } }, "summary": "Read a company's security settings" }, "getCompanyBranding": { "method": "GET", "path": "/companies/{companyId}/branding", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "company_id": "v", "display_name": "v", "primary_accent_color": "v", "secondary_accent_color": "v", "support_email": "v", "privacy_policy_url": "v", "terms_of_service_url": "v", "copyright_text": "v", "company_logo_url": "v", "favicon_url": "v", "email_header_logo_url": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read company branding overrides" }, "updateCompanyBranding": { "method": "PATCH", "path": "/companies/{companyId}/branding", "tag": "Companies", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "display_name": { "type": "string" }, "primary_accent_color": { "type": "string" }, "secondary_accent_color": { "type": "string" }, "support_email": { "type": "string", "format": "email" }, "privacy_policy_url": { "type": "string", "format": "uri" }, "terms_of_service_url": { "type": "string", "format": "uri" }, "copyright_text": { "type": "string" } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "company_id": "v", "display_name": "v", "primary_accent_color": "v", "secondary_accent_color": "v", "support_email": "v", "privacy_policy_url": "v", "terms_of_service_url": "v", "copyright_text": "v", "company_logo_url": "v", "favicon_url": "v", "email_header_logo_url": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update company branding overrides" }, "listCompanyDomains": { "method": "GET", "path": "/companies/{companyId}/domains", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "domain": "v", "status": "v", "verification": { "o": { "type": "v", "name": "v", "value": "v" } }, "verified_at": "v", "last_checked_at": "v", "last_failure_reason": "v" } } } } }, "summary": "List claimed domains" }, "claimCompanyDomain": { "method": "POST", "path": "/companies/{companyId}/domains", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["domain"], "properties": { "domain": { "type": "string" } } }, "response": { "o": { "data": { "o": { "id": "v", "domain": "v", "status": "v", "verification": { "o": { "type": "v", "name": "v", "value": "v" } }, "verified_at": "v", "last_checked_at": "v", "last_failure_reason": "v" } } } }, "summary": "Claim a domain" }, "removeCompanyDomain": { "method": "DELETE", "path": "/companies/{companyId}/domains/{domainId}", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "domainId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": null, "summary": "Remove a domain claim" }, "listDomainVerifications": { "method": "GET", "path": "/companies/{companyId}/domains/{domainId}/verifications", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "domainId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "checked_at": "v", "status": "v", "failure_reason": "v" } } } } }, "summary": "List verification attempts" }, "verifyDomain": { "method": "POST", "path": "/companies/{companyId}/domains/{domainId}/verifications", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "domainId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "checked_at": "v", "status": "v", "failure_reason": "v" } } } }, "summary": "Check the TXT record now" }, "getIdentityProvider": { "method": "GET", "path": "/companies/{companyId}/identity-provider", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "display_name": "v", "type": "v", "is_active": "v", "issuer": "v", "well_known_endpoint": "v", "client_id": "v", "client_auth_method": "v", "supported_client_auth_methods": { "a": "v" }, "secret_held": "v", "link_callback_uri": "v", "instructions": { "a": "v" }, "created_at": "v" } } } }, "summary": "Read the identity provider connection" }, "connectIdentityProvider": { "method": "POST", "path": "/companies/{companyId}/identity-provider", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["type", "display_name", "issuer", "well_known_endpoint", "client_id", "acknowledgement"], "properties": { "type": { "type": "string" }, "display_name": { "type": "string" }, "issuer": { "type": "string" }, "well_known_endpoint": { "type": "string", "format": "uri" }, "client_id": { "type": "string" }, "client_auth_method": { "type": "string", "enum": ["client_secret", "none"] }, "client_secret": { "type": "string", "format": "password" }, "secret_expires_at": { "type": "string", "format": "date-time" }, "acknowledgement": { "type": "string", "enum": ["true", "yes", "acknowledged", "1"] } } }, "response": { "o": { "data": { "o": { "id": "v", "display_name": "v", "type": "v", "is_active": "v", "issuer": "v", "well_known_endpoint": "v", "client_id": "v", "client_auth_method": "v", "supported_client_auth_methods": { "a": "v" }, "secret_held": "v", "link_callback_uri": "v", "instructions": { "a": "v" }, "created_at": "v" } } } }, "summary": "Connect an OpenID Connect provider" }, "disconnectIdentityProvider": { "method": "DELETE", "path": "/companies/{companyId}/identity-provider", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": null, "summary": "Disconnect the identity provider" }, "testIdentityProvider": { "method": "POST", "path": "/companies/{companyId}/identity-provider/test", "tag": "Single sign-on", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "reachable": "v", "checks": { "a": { "o": { "name": "v", "outcome": "v", "detail": "v" } } } } } } }, "summary": "Test the identity provider connection" }, "listProducts": { "method": "GET", "path": "/products", "tag": "Products", "role": "reseller_admin", "query": [], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "key": "v", "name": "v" } } } } }, "summary": "List products" }, "listCompanyProducts": { "method": "GET", "path": "/companies/{companyId}/products", "tag": "Products", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "product_key": "v", "name": "v", "enabled": "v", "enabled_at": "v", "enabled_by": "v" } } } } }, "summary": "Company products" }, "listUserProducts": { "method": "GET", "path": "/companies/{companyId}/users/{userId}/products", "tag": "Products", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "product_key": "v", "name": "v", "enabled": "v", "enabled_at": "v", "enabled_by": "v" } } } } }, "summary": "A user's products" }, "enableUserProduct": { "method": "POST", "path": "/locations/{locationId}/users/{userId}/products/{productKey}/enable", "tag": "Products", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId", "productKey"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "product_key": "v", "name": "v", "enabled": "v", "enabled_at": "v", "enabled_by": "v" } } } }, "summary": "Turn a product on for a user" }, "disableUserProduct": { "method": "POST", "path": "/locations/{locationId}/users/{userId}/products/{productKey}/disable", "tag": "Products", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId", "productKey"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "product_key": "v", "name": "v", "enabled": "v", "enabled_at": "v", "enabled_by": "v" } } } }, "summary": "Turn a product off for a user" }, "listVerticals": { "method": "GET", "path": "/verticals", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "key": "v", "name": "v", "description": "v", "is_active": "v", "display_order": "v" } } } } }, "summary": "List industries" }, "listCompanyLocations": { "method": "GET", "path": "/companies/{companyId}/locations", "tag": "Locations", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "is_active", "in": "query", "type": "boolean" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "offset", "in": "query", "type": "integer", "minimum": 0 }], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a company's locations" }, "createLocation": { "method": "POST", "path": "/companies/{companyId}/locations", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["location_name", "street", "city", "state", "country", "zipcode", "vertical_id"], "properties": { "location_name": { "type": "string" }, "street": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" }, "country": { "type": "string" }, "zipcode": { "type": "string" }, "vertical_id": { "type": "string", "format": "uuid" }, "enabled_products": { "type": "array", "items": { "type": "string", "enum": ["after-call-copilot", "first-alert-copilot", "insights-hub"] } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Create a location" }, "getLocation": { "method": "GET", "path": "/companies/{companyId}/locations/{locationId}", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read a location" }, "updateLocation": { "method": "PATCH", "path": "/companies/{companyId}/locations/{locationId}", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "location_name": { "type": "string" }, "street": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" }, "country": { "type": "string" }, "zipcode": { "type": "string" }, "vertical_id": { "type": "string", "format": "uuid" }, "enabled_products": { "type": "array", "items": { "type": "string", "enum": ["after-call-copilot", "first-alert-copilot", "insights-hub"] } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update a location" }, "deactivateLocation": { "method": "POST", "path": "/companies/{companyId}/locations/{locationId}/deactivate", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Deactivate a location" }, "reactivateLocation": { "method": "POST", "path": "/companies/{companyId}/locations/{locationId}/reactivate", "tag": "Locations", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Reactivate a location" }, "listUserGroups": { "method": "GET", "path": "/locations/{locationId}/user-groups", "tag": "User groups", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "group_name": "v", "user_count": "v", "members": { "a": { "o": { "id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a location's groups" }, "createUserGroup": { "method": "POST", "path": "/locations/{locationId}/user-groups", "tag": "User groups", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["group_name"], "properties": { "group_name": { "type": "string" }, "member_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "group_name": "v", "user_count": "v", "members": { "a": { "o": { "id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Create a group" }, "getUserGroup": { "method": "GET", "path": "/locations/{locationId}/user-groups/{groupId}", "tag": "User groups", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "groupId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "group_name": "v", "user_count": "v", "members": { "a": { "o": { "id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read a group with its members" }, "updateUserGroup": { "method": "PATCH", "path": "/locations/{locationId}/user-groups/{groupId}", "tag": "User groups", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "groupId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "group_name": { "type": "string" }, "member_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "group_name": "v", "user_count": "v", "members": { "a": { "o": { "id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Rename a group or set its members" }, "deleteUserGroup": { "method": "DELETE", "path": "/locations/{locationId}/user-groups/{groupId}", "tag": "User groups", "role": "reseller_admin", "query": [{ "name": "force", "in": "query", "type": "boolean" }], "pathParams": ["locationId", "groupId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": null, "summary": "Delete a group" }, "getUserGroupMembership": { "method": "GET", "path": "/locations/{locationId}/users/{userId}/group-membership", "tag": "User groups", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "name": "v", "is_member": "v", "product_keys": { "a": "v" } } } } } }, "summary": "A user's groups at a location" }, "setUserGroupMembership": { "method": "PUT", "path": "/locations/{locationId}/users/{userId}/group-membership", "tag": "User groups", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["group_ids"], "properties": { "group_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "a": { "o": { "id": "v", "name": "v", "is_member": "v", "product_keys": { "a": "v" } } } } } }, "summary": "Set a user's groups at a location" }, "listConnectorTypes": { "method": "GET", "path": "/connector-types", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "key": "v", "name": "v" } } } } }, "summary": "List connector types" }, "testConnector": { "method": "POST", "path": "/locations/{locationId}/connectors/test", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["type", "config"], "properties": { "type": { "type": "string", "enum": ["netsapiens"] }, "config": { "type": "object" }, "connector_id": { "type": "string", "format": "uuid" } } }, "response": { "o": { "data": { "o": { "success": "v" } } } }, "summary": "Dry-run a connector" }, "listLocationConnectors": { "method": "GET", "path": "/locations/{locationId}/connectors", "tag": "Connectors", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "status", "in": "query", "type": "string", "enum": ["connecting", "active", "connected", "error", "deactivating", "inactive"] }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "location_id": "v", "location_name": "v", "name": "v", "type": "v", "type_display_name": "v", "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a location's connectors" }, "createConnector": { "method": "POST", "path": "/locations/{locationId}/connectors", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["name", "type", "config"], "properties": { "name": { "type": "string" }, "type": { "type": "string", "enum": ["netsapiens"] }, "config": { "type": "object" } } }, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "name": "v", "type": "v", "type_display_name": "v", "config": { "o": { "api_url": "v", "domain": "v" } }, "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Create a connector" }, "getConnector": { "method": "GET", "path": "/locations/{locationId}/connectors/{connectorId}", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "connectorId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "name": "v", "type": "v", "type_display_name": "v", "config": { "o": { "api_url": "v", "domain": "v" } }, "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Read a connector" }, "updateConnector": { "method": "PATCH", "path": "/locations/{locationId}/connectors/{connectorId}", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "connectorId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "name": { "type": "string" }, "config": { "type": "object" } } }, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "name": "v", "type": "v", "type_display_name": "v", "config": { "o": { "api_url": "v", "domain": "v" } }, "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Update a connector" }, "deactivateConnector": { "method": "POST", "path": "/locations/{locationId}/connectors/{connectorId}/deactivate", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "connectorId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "name": "v", "type": "v", "type_display_name": "v", "config": { "o": { "api_url": "v", "domain": "v" } }, "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Stop a connector" }, "reactivateConnector": { "method": "POST", "path": "/locations/{locationId}/connectors/{connectorId}/reactivate", "tag": "Connectors", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "connectorId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "name": "v", "type": "v", "type_display_name": "v", "config": { "o": { "api_url": "v", "domain": "v" } }, "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Restart a connector" }, "listCompanyConnectors": { "method": "GET", "path": "/companies/{companyId}/connectors", "tag": "Connectors", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "status", "in": "query", "type": "string", "enum": ["connecting", "active", "connected", "error", "deactivating", "inactive"] }, { "name": "type", "in": "query", "type": "string", "enum": ["netsapiens"] }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "location_id": "v", "location_name": "v", "name": "v", "type": "v", "type_display_name": "v", "status": "v", "status_display": "v", "status_message": "v", "state_reason": "v", "last_synced_at": "v", "created_at": "v", "updated_at": "v" } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } }, "errors": { "a": { "o": { "id": "v", "name": "v", "type": "v", "location_name": "v", "status_message": "v" } } } } }, "summary": "List a company's connectors" }, "listAlertRules": { "method": "GET", "path": "/locations/{locationId}/first-alert/rules", "tag": "First Alert", "role": "reseller_admin", "query": [{ "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "name": "v", "priority": "v", "match_logic": "v", "enabled": "v", "is_default": "v", "triggers": { "a": { "o": { "id": "v", "trigger_type": "v", "config": { "o": { "operator": "v", "threshold": "v", "keywords": { "a": "v" }, "match_logic": "v", "topics": { "a": "v" } } } } } }, "trigger_types": { "a": "v" }, "groups": { "a": { "o": { "id": "v", "group_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a location's alert rules" }, "createAlertRule": { "method": "POST", "path": "/locations/{locationId}/first-alert/rules", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["name", "priority", "triggers"], "properties": { "name": { "type": "string" }, "priority": { "type": "string", "enum": ["critical", "high", "medium", "low"] }, "match_logic": { "type": "string", "enum": ["any", "all"] }, "enabled": { "type": "boolean" }, "triggers": { "type": "array", "items": { "type": "object" } }, "group_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "name": "v", "priority": "v", "match_logic": "v", "enabled": "v", "is_default": "v", "triggers": { "a": { "o": { "id": "v", "trigger_type": "v", "config": { "o": { "operator": "v", "threshold": "v", "keywords": { "a": "v" }, "match_logic": "v", "topics": { "a": "v" } } } } } }, "trigger_types": { "a": "v" }, "groups": { "a": { "o": { "id": "v", "group_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Create an alert rule" }, "getAlertRule": { "method": "GET", "path": "/locations/{locationId}/first-alert/rules/{ruleId}", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "ruleId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "name": "v", "priority": "v", "match_logic": "v", "enabled": "v", "is_default": "v", "triggers": { "a": { "o": { "id": "v", "trigger_type": "v", "config": { "o": { "operator": "v", "threshold": "v", "keywords": { "a": "v" }, "match_logic": "v", "topics": { "a": "v" } } } } } }, "trigger_types": { "a": "v" }, "groups": { "a": { "o": { "id": "v", "group_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read an alert rule" }, "updateAlertRule": { "method": "PATCH", "path": "/locations/{locationId}/first-alert/rules/{ruleId}", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "ruleId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "name": { "type": "string" }, "priority": { "type": "string", "enum": ["critical", "high", "medium", "low"] }, "match_logic": { "type": "string", "enum": ["any", "all"] }, "enabled": { "type": "boolean" }, "triggers": { "type": "array", "items": { "type": "object" } }, "group_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "name": "v", "priority": "v", "match_logic": "v", "enabled": "v", "is_default": "v", "triggers": { "a": { "o": { "id": "v", "trigger_type": "v", "config": { "o": { "operator": "v", "threshold": "v", "keywords": { "a": "v" }, "match_logic": "v", "topics": { "a": "v" } } } } } }, "trigger_types": { "a": "v" }, "groups": { "a": { "o": { "id": "v", "group_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update an alert rule" }, "deleteAlertRule": { "method": "DELETE", "path": "/locations/{locationId}/first-alert/rules/{ruleId}", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "ruleId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": null, "summary": "Delete an alert rule" }, "duplicateAlertRule": { "method": "POST", "path": "/locations/{locationId}/first-alert/rules/{ruleId}/duplicate", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "ruleId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "location_id": "v", "name": "v", "priority": "v", "match_logic": "v", "enabled": "v", "is_default": "v", "triggers": { "a": { "o": { "id": "v", "trigger_type": "v", "config": { "o": { "operator": "v", "threshold": "v", "keywords": { "a": "v" }, "match_logic": "v", "topics": { "a": "v" } } } } } }, "trigger_types": { "a": "v" }, "groups": { "a": { "o": { "id": "v", "group_name": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Copy an alert rule" }, "getFirstAlertConfig": { "method": "GET", "path": "/locations/{locationId}/first-alert/config", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "webhook_url": "v", "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" }, "id": "v" } } } } } } }, "summary": "Read monitored numbers and the alert webhook" }, "saveFirstAlertConfig": { "method": "PUT", "path": "/locations/{locationId}/first-alert/config", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["connector_mappings"], "properties": { "webhook_url": { "type": ["string", "null"], "format": "uri" }, "connector_mappings": { "type": "array", "items": { "type": "object" } } } }, "response": { "o": { "data": { "o": { "webhook_url": "v", "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" }, "id": "v" } } } } } } }, "summary": "Set monitored numbers and the alert webhook" }, "testFirstAlertWebhook": { "method": "POST", "path": "/locations/{locationId}/first-alert/config/test-webhook", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["url"], "properties": { "url": { "type": "string", "format": "uri" } } }, "response": { "o": { "data": { "o": { "success": "v", "status_code": "v" } } } }, "summary": "Test the alert webhook" }, "getAlertNotificationPreferences": { "method": "GET", "path": "/locations/{locationId}/users/{userId}/first-alert/notification-preferences", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "emailNotifications": { "o": { "masterEnabled": "v", "alerts": { "a": { "o": { "alertId": "v", "alertName": "v", "trigger": "v", "severity": "v", "description": "v", "emailEnabled": "v" } } } } }, "digest": { "o": { "enabled": "v", "frequency": "v", "sendTime": "v", "timezone": "v", "timeFormat": "v" } } } }, "summary": "Read a user's alert email and digest" }, "setAlertEmailPreferences": { "method": "PUT", "path": "/locations/{locationId}/users/{userId}/first-alert/email-preferences", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["masterEnabled"], "properties": { "masterEnabled": { "type": "boolean" }, "alerts": { "type": "array", "items": { "type": "object" } } } }, "response": { "o": { "emailNotifications": { "o": { "masterEnabled": "v", "alerts": { "a": { "o": { "alertId": "v", "alertName": "v", "trigger": "v", "severity": "v", "description": "v", "emailEnabled": "v" } } } } }, "digest": { "o": { "enabled": "v", "frequency": "v", "sendTime": "v", "timezone": "v", "timeFormat": "v" } } } }, "summary": "Set a user's alert email" }, "setAlertDigestPreferences": { "method": "PUT", "path": "/locations/{locationId}/users/{userId}/first-alert/digest-preferences", "tag": "First Alert", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["enabled", "frequency", "sendTime", "timezone"], "properties": { "enabled": { "type": "boolean" }, "frequency": { "type": "string", "enum": ["daily", "weekly", "both", "never"] }, "sendTime": { "type": "string" }, "timezone": { "type": "string" }, "timeFormat": { "type": "string", "enum": ["12h", "24h"] } } }, "response": { "o": { "emailNotifications": { "o": { "masterEnabled": "v", "alerts": { "a": { "o": { "alertId": "v", "alertName": "v", "trigger": "v", "severity": "v", "description": "v", "emailEnabled": "v" } } } } }, "digest": { "o": { "enabled": "v", "frequency": "v", "sendTime": "v", "timezone": "v", "timeFormat": "v" } } } }, "summary": "Set a user's alert digest" }, "getInsightsHubSetup": { "method": "GET", "path": "/locations/{locationId}/insights-hub/setup", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" } } } }, "group_access": { "a": "v" }, "available_connectors": { "a": { "o": { "id": "v", "name": "v", "type": "v" } } }, "groups": { "a": { "o": { "id": "v", "group_name": "v", "has_access": "v" } } } } } } } } }, "summary": "Read Insights Hub setup" }, "saveInsightsHubSetup": { "method": "POST", "path": "/locations/{locationId}/insights-hub/setup", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["connector_mappings", "group_access"], "properties": { "connector_mappings": { "type": "array", "items": { "type": "object" } }, "group_access": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" } } } }, "group_access": { "a": "v" }, "available_connectors": { "a": { "o": { "id": "v", "name": "v", "type": "v" } } }, "groups": { "a": { "o": { "id": "v", "group_name": "v", "has_access": "v" } } } } } } } } }, "summary": "Save Insights Hub setup" }, "updateInsightsHubSetup": { "method": "PATCH", "path": "/locations/{locationId}/insights-hub/setup", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "connector_mappings": { "type": "array", "items": { "type": "object" } }, "group_access": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" } } } }, "group_access": { "a": "v" }, "available_connectors": { "a": { "o": { "id": "v", "name": "v", "type": "v" } } }, "groups": { "a": { "o": { "id": "v", "group_name": "v", "has_access": "v" } } } } } } } } }, "summary": "Update Insights Hub setup" }, "getInsightsHubConfig": { "method": "GET", "path": "/locations/{locationId}/insights-hub/config", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "monitor_all_numbers": "v" } } } } } }, "summary": "Read Insights Hub coverage" }, "updateInsightsHubConfig": { "method": "PATCH", "path": "/locations/{locationId}/insights-hub/config", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["monitor_all_numbers"], "properties": { "monitor_all_numbers": { "type": "boolean" } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "monitor_all_numbers": "v" } } } } } }, "summary": "Set Insights Hub coverage" }, "getUserInsightsHubAccess": { "method": "GET", "path": "/locations/{locationId}/users/{userId}/insights-hub/access", "tag": "Insights Hub", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "enabled": "v", "group_name": "v" } } } } } }, "summary": "Check a user's Insights Hub access" }, "listCompanyUsers": { "method": "GET", "path": "/companies/{companyId}/users", "tag": "Users", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "status", "in": "query", "type": "string", "enum": ["invited", "active", "deactivated"] }, { "name": "role", "in": "query", "type": "string", "enum": ["customer_admin", "frontline_user"] }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["companyId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a company's users" }, "createCompanyUser": { "method": "POST", "path": "/companies/{companyId}/users", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId"], "headers": ["Idempotency-Key"], "hasBody": true, "bodyRequired": true, "body": { "required": ["email", "first_name", "last_name", "role"], "properties": { "email": { "type": "string", "format": "email" }, "first_name": { "type": "string" }, "last_name": { "type": "string" }, "phone_number": { "type": "string" }, "role": { "type": "string", "enum": ["customer_admin", "frontline_user"] }, "location_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } }, "send_invitation": { "type": "boolean" }, "auth_method": { "type": "string", "enum": ["password", "sso"] } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Create a user" }, "getCompanyUser": { "method": "GET", "path": "/companies/{companyId}/users/{userId}", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Read a user" }, "updateCompanyUser": { "method": "PATCH", "path": "/companies/{companyId}/users/{userId}", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" }, "phone_number": { "type": "string" }, "department": { "type": "string" }, "role": { "type": "string", "enum": ["customer_admin", "frontline_user"] }, "location_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } } } }, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Update a user, role or locations" }, "deactivateCompanyUser": { "method": "POST", "path": "/companies/{companyId}/users/{userId}/deactivate", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Deactivate a user" }, "reactivateCompanyUser": { "method": "POST", "path": "/companies/{companyId}/users/{userId}/reactivate", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "reseller_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "department": "v", "status": "v", "role": "v", "auth_method": "v", "invited_at": "v", "invite_expires_at": "v", "activated_at": "v", "last_login_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "created_at": "v", "updated_at": "v" } } } } } }, "summary": "Reactivate a user" }, "resendInvitation": { "method": "POST", "path": "/companies/{companyId}/users/{userId}/resend-invitation", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "user_id": "v", "email": "v", "invite_expires_at": "v", "message": "v" } } } } } }, "summary": "Resend the invitation email" }, "resetPassword": { "method": "POST", "path": "/companies/{companyId}/users/{userId}/reset-password", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "user_id": "v", "email": "v", "message": "v" } } } } } }, "summary": "Send a password reset email" }, "getUserNumberMappings": { "method": "GET", "path": "/companies/{companyId}/users/{userId}/connector-mappings", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" } } } } } }, "summary": "Read a user's numbers" }, "setUserNumberMappings": { "method": "PUT", "path": "/companies/{companyId}/users/{userId}/connector-mappings", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["companyId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["mappings"], "properties": { "mappings": { "type": "array", "items": { "type": "object" } } } }, "response": { "o": { "data": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_type": "v", "monitored_numbers": { "a": "v" } } } } } }, "summary": "Set a user's numbers" }, "listLocationUsers": { "method": "GET", "path": "/locations/{locationId}/users", "tag": "Users", "role": "reseller_admin", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "status", "in": "query", "type": "string", "enum": ["invited", "active", "deactivated"] }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "role": "v", "status": "v", "invited_at": "v", "created_at": "v", "location_id": "v", "location_name": "v", "assigned_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "groups": { "a": "v" }, "enabled_products": { "a": "v" } } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "List a location's users with products and groups" }, "getLocationUser": { "method": "GET", "path": "/locations/{locationId}/users/{userId}", "tag": "Users", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "phone_number": "v", "role": "v", "status": "v", "invited_at": "v", "created_at": "v", "location_id": "v", "location_name": "v", "assigned_at": "v", "locations": { "a": { "o": { "location_id": "v", "assigned_at": "v" } } }, "groups": { "a": "v" }, "enabled_products": { "a": "v" } } } } } } }, "summary": "Read a user at a location" }, "getUserAfterCallSettings": { "method": "GET", "path": "/locations/{locationId}/users/{userId}/after-call-settings", "tag": "After Call settings", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "user_id": "v", "eoc_enabled": "v", "eod_enabled": "v", "eod_timezone": "v", "eod_time": "v", "digest_frequency": "v", "digest_time_format": "v", "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_status": "v", "monitored_numbers": { "a": "v" } } } }, "last_changed_by": "v", "last_changed_at": "v" } } } }, "summary": "Read a user's After Call settings" }, "updateUserAfterCallSettings": { "method": "PATCH", "path": "/locations/{locationId}/users/{userId}/after-call-settings", "tag": "After Call settings", "role": "reseller_admin", "query": [], "pathParams": ["locationId", "userId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": [], "properties": { "eoc_enabled": { "type": "boolean" }, "eod_enabled": { "type": "boolean" }, "eod_time": { "type": "string" }, "eod_timezone": { "type": "string" }, "digest_frequency": { "type": "string", "enum": ["daily", "weekly", "both", "never"] }, "digest_time_format": { "type": "string", "enum": ["12h", "24h"] }, "connector_mappings": { "type": "array", "items": { "type": "object" } } } }, "response": { "o": { "data": { "o": { "user_id": "v", "eoc_enabled": "v", "eod_enabled": "v", "eod_timezone": "v", "eod_time": "v", "digest_frequency": "v", "digest_time_format": "v", "connector_mappings": { "a": { "o": { "connector_id": "v", "connector_name": "v", "connector_status": "v", "monitored_numbers": { "a": "v" } } } }, "last_changed_by": "v", "last_changed_at": "v" } } } }, "summary": "Update a user's After Call settings" }, "getMe": { "method": "GET", "path": "/me", "tag": "Account", "role": "frontline_user", "query": [], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "email": "v", "first_name": "v", "last_name": "v", "display_name": "v", "user_type": "v", "role": "v", "status": "v", "scopes": { "a": "v" }, "reseller_id": "v", "company_id": "v", "location_ids": { "a": "v" }, "enabled_products": { "a": "v" }, "mfa_available": "v" } } } }, "summary": "Who is signed in" }, "listVisibleLocations": { "method": "GET", "path": "/locations", "tag": "Account", "role": "frontline_user", "query": [{ "name": "search", "in": "query", "type": "string" }, { "name": "is_active", "in": "query", "type": "boolean" }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "offset", "in": "query", "type": "integer", "minimum": 0 }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "type": "v", "attributes": { "o": { "id": "v", "company_id": "v", "company_name": "v", "reseller_name": "v", "location_name": "v", "street": "v", "city": "v", "state": "v", "country": "v", "zipcode": "v", "support_contact_name": "v", "support_contact_email": "v", "support_contact_phone": "v", "vertical_id": "v", "vertical_name": "v", "enabled_products": { "a": "v" }, "is_active": "v", "user_count": "v", "created_at": "v", "updated_at": "v" } } } } }, "pagination": { "o": { "has_more": "v", "next_cursor": "v", "total_count": "v" } } } }, "summary": "Locations this login can see" }, "listCalls": { "method": "GET", "path": "/calls", "tag": "Calls", "role": "frontline_user", "query": [{ "name": "date_from", "in": "query", "type": "string", "format": "date-time" }, { "name": "date_to", "in": "query", "type": "string", "format": "date-time" }, { "name": "status", "in": "query", "type": "string", "enum": ["completed", "missed", "voicemail", "failed", "cancelled"] }, { "name": "sentiment", "in": "query", "type": "string", "enum": ["crisis", "very_negative", "negative", "mildly_negative", "below_neutral", "neutral", "positive", "none"] }, { "name": "has_open_tasks", "in": "query", "type": "string", "enum": ["true"] }, { "name": "multi_leg", "in": "query", "type": "boolean" }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "search", "in": "query", "type": "string", "minLength": 2 }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "summary": { "o": { "total_calls": "v", "completed_calls": "v", "missed_calls": "v", "total_duration": "v", "tasks_done": "v", "pending": "v", "total_tasks": "v" } }, "calls": { "a": { "o": { "id": "v", "location_id": "v", "call_date": "v", "caller_timezone": "v", "caller_name": "v", "caller_number": "v", "callee_name": "v", "callee_number": "v", "call_type": "v", "status": "v", "sentiment": "v", "sentiment_score": "v", "sentiment_label": "v", "summary": "v", "top_highlight": "v", "highlights": { "a": "v" }, "duration": "v", "leg_count": "v", "task_count": "v", "completed_task_count": "v" } } } } }, "meta": { "o": { "has_more": "v", "next_cursor": "v", "limit": "v" } } } }, "summary": "List calls" }, "getCall": { "method": "GET", "path": "/calls/{callId}", "tag": "Calls", "role": "frontline_user", "query": [], "pathParams": ["callId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "call_date": "v", "caller_timezone": "v", "caller_name": "v", "caller_number": "v", "callee_name": "v", "callee_number": "v", "call_type": "v", "call_outcome": "v", "duration": "v", "leg_count": "v", "platform": "v", "sentiment": "v", "sentiment_score": "v", "sentiment_label": "v", "summary": "v", "analysis": { "o": { "summary": { "o": { "text": "v", "key_points": { "a": "v" }, "action_items": { "a": "v" } } }, "sentiment": { "o": { "overall": "v" } }, "topics": { "a": { "o": { "name": "v" } } } } }, "vcon": { "o": { "recording_url": "v", "recording_url_expires_at": "v", "recording_mime_type": "v" } }, "tasks": { "a": { "o": { "id": "v", "title": "v", "description": "v", "status": "v", "source": "v", "assignee_user": { "o": { "id": "v", "display_name": "v", "email": "v" } }, "due_date": "v" } } }, "task_count": "v", "has_more_tasks": "v" } } } }, "summary": "Read a call" }, "getCallTranscript": { "method": "GET", "path": "/calls/{callId}/transcript", "tag": "Calls", "role": "frontline_user", "query": [], "pathParams": ["callId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "transcript": { "a": { "o": { "time": "v", "speaker": "v", "name": "v", "text": "v" } } } } } } }, "summary": "Read a call's transcript" }, "listAlerts": { "method": "GET", "path": "/alerts", "tag": "Alerts", "role": "frontline_user", "query": [{ "name": "date_from", "in": "query", "type": "string", "format": "date-time" }, { "name": "date_to", "in": "query", "type": "string", "format": "date-time" }, { "name": "keyword", "in": "query", "type": "string" }, { "name": "topic", "in": "query", "type": "string" }, { "name": "numbers", "in": "query", "type": "array", "maxItems": 25, "items": { "type": "string", "pattern": "^[A-Za-z0-9@#]+$" } }, { "name": "sentiment", "in": "query", "type": "string", "enum": ["crisis", "very_negative", "negative", "mildly_negative", "below_neutral", "neutral", "positive", "none"] }, { "name": "search", "in": "query", "type": "string" }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "summary": { "o": { "total": "v" } }, "alerts": { "a": { "o": { "id": "v", "call_id": "v", "call_date": "v", "caller_timezone": "v", "caller_name": "v", "caller_number": "v", "callee_name": "v", "callee_number": "v", "summary": "v", "sentiment": "v", "sentiment_score": "v", "sentiment_label": "v", "keywords": { "a": "v" }, "topics": { "a": "v" } } } } } }, "meta": { "o": { "has_more": "v", "next_cursor": "v", "limit": "v" } } } }, "summary": "List alerts" }, "getAlertsDashboard": { "method": "GET", "path": "/alerts/dashboard", "tag": "Alerts", "role": "frontline_user", "query": [{ "name": "date_from", "in": "query", "type": "string", "format": "date-time" }, { "name": "date_to", "in": "query", "type": "string", "format": "date-time" }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "kpis": { "o": { "new_alerts": "v", "monitored": "v", "alert_rate": "v" } }, "top_triggered": { "a": { "o": { "keyword": "v", "count": "v" } } }, "recent_alerts": { "a": { "o": { "id": "v", "call_id": "v", "call_date": "v", "caller_timezone": "v", "caller_name": "v", "caller_number": "v", "callee_name": "v", "callee_number": "v", "summary": "v", "sentiment": "v", "sentiment_score": "v", "sentiment_label": "v", "keywords": { "a": "v" }, "topics": { "a": "v" } } } } } } } }, "summary": "Alert totals" }, "listTasks": { "method": "GET", "path": "/tasks", "tag": "Tasks", "role": "frontline_user", "query": [{ "name": "status", "in": "query", "type": "string", "enum": ["pending", "in_progress", "done", "overdue", "open"] }, { "name": "today_start", "in": "query", "type": "string", "format": "date-time" }, { "name": "call_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "task_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "due_on", "in": "query", "type": "string", "format": "date" }, { "name": "date_from", "in": "query", "type": "string", "format": "date-time" }, { "name": "date_to", "in": "query", "type": "string", "format": "date-time" }, { "name": "search", "in": "query", "type": "string" }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "call_id": "v", "company_id": "v", "location_id": "v", "title": "v", "description": "v", "status": "v", "source": "v", "assignee_user": { "o": { "id": "v", "display_name": "v", "email": "v" } }, "due_date": "v", "completed_at": "v", "created_at": "v", "updated_at": "v" } } }, "meta": { "o": { "has_more": "v", "next_cursor": "v", "limit": "v" } }, "summary": { "o": { "total": "v", "done": "v", "in_progress": "v", "pending": "v", "overdue": "v" } } } }, "summary": "List tasks" }, "getInsightsDashboard": { "method": "GET", "path": "/insights/dashboard", "tag": "Insights", "role": "frontline_user", "query": [{ "name": "start", "in": "query", "type": "string", "required": true, "format": "date-time" }, { "name": "end", "in": "query", "type": "string", "required": true, "format": "date-time" }, { "name": "trending_limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 10 }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }], "pathParams": [], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "stats": { "o": { "total_calls": "v", "answered_calls": "v", "unanswered_calls": "v" } }, "trending_topics": { "a": { "o": { "slug": "v", "name": "v", "call_count": "v", "previous_call_count": "v", "percentage_change": "v", "trend_data": { "a": { "o": { "day": "v", "current": "v", "previous": "v" } } } } } }, "topic_call_volumes": { "a": { "o": { "slug": "v", "name": "v", "call_count": "v" } } } } } } }, "summary": "Insights Hub dashboard" }, "listTopicCalls": { "method": "GET", "path": "/insights/topics/{slug}/calls", "tag": "Insights", "role": "frontline_user", "query": [{ "name": "date_from", "in": "query", "type": "string", "format": "date-time" }, { "name": "date_to", "in": "query", "type": "string", "format": "date-time" }, { "name": "sentiment", "in": "query", "type": "string", "enum": ["positive", "neutral", "negative"] }, { "name": "outcome", "in": "query", "type": "string", "enum": ["completed", "missed", "pending"] }, { "name": "search", "in": "query", "type": "string" }, { "name": "location_id", "in": "query", "type": "array", "maxItems": 100, "items": { "type": "string", "format": "uuid" } }, { "name": "company_id", "in": "query", "type": "string", "format": "uuid" }, { "name": "cursor", "in": "query", "type": "string" }, { "name": "limit", "in": "query", "type": "integer", "minimum": 1, "maximum": 100 }], "pathParams": ["slug"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "a": { "o": { "id": "v", "date": "v", "caller_name": "v", "summary": "v", "phone_number": "v", "sentiment": "v", "sentiment_label": "v", "outcome": "v" } } }, "meta": { "o": { "total": "v", "has_more": "v", "next_cursor": "v" } } } }, "summary": "Calls for one topic" }, "getAfterCallWebhook": { "method": "GET", "path": "/locations/{locationId}/after-call/automation", "tag": "Events and webhooks", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "webhook_url": "v", "enabled": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Read the After Call webhook" }, "saveAfterCallWebhook": { "method": "PUT", "path": "/locations/{locationId}/after-call/automation", "tag": "Events and webhooks", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": true, "bodyRequired": true, "body": { "required": ["webhook_url"], "properties": { "webhook_url": { "type": "string", "format": "uri" }, "enabled": { "type": "boolean" } } }, "response": { "o": { "data": { "o": { "id": "v", "location_id": "v", "webhook_url": "v", "enabled": "v", "created_at": "v", "updated_at": "v" } } } }, "summary": "Set the After Call webhook" }, "testAfterCallWebhook": { "method": "POST", "path": "/locations/{locationId}/after-call/automation/test", "tag": "Events and webhooks", "role": "reseller_admin", "query": [], "pathParams": ["locationId"], "headers": [], "hasBody": false, "bodyRequired": false, "body": null, "response": { "o": { "data": { "o": { "success": "v", "http_status": "v", "response_time_ms": "v" } } } }, "summary": "Send a test After Call event" } };
7
+
8
+ // src/errors.ts
9
+ var brandOf = (name) => /* @__PURE__ */ Symbol.for(`intelligence-cloud.error.${name}`);
10
+ var IntelligenceCloudError = class extends Error {
11
+ static [Symbol.hasInstance](value) {
12
+ if (value === null || typeof value !== "object") return false;
13
+ if (value[brandOf(this.name)] === true) return true;
14
+ return Function.prototype[Symbol.hasInstance].call(this, value);
15
+ }
16
+ constructor(message, options) {
17
+ super(message, options);
18
+ this.name = new.target.name;
19
+ }
20
+ };
21
+ var ApiError = class extends IntelligenceCloudError {
22
+ status;
23
+ code;
24
+ requestId;
25
+ operationId;
26
+ /** The server's error text, when it sent one. May contain customer data: don't log it. */
27
+ serverMessage;
28
+ constructor(status, code, message, extra = {}) {
29
+ super(message, extra.cause !== void 0 ? { cause: extra.cause } : void 0);
30
+ this.status = status;
31
+ this.code = code;
32
+ this.requestId = extra.requestId ?? null;
33
+ this.operationId = extra.operationId ?? null;
34
+ this.serverMessage = extra.serverMessage ?? null;
35
+ }
36
+ };
37
+ function apiErrorText(status, code, requestId, hint) {
38
+ let text = `HTTP ${status}${` ${code}` }`;
39
+ if (hint) text += `: ${hint}`;
40
+ return text;
41
+ }
42
+ var AuthError = class extends ApiError {
43
+ };
44
+ var MfaRequiredError = class extends AuthError {
45
+ constructor() {
46
+ super(200, "mfa_required", "Integration users need MFA off for their company. API keys arrive in December 2026.");
47
+ }
48
+ };
49
+ var PasswordExpiredError = class extends AuthError {
50
+ constructor() {
51
+ super(200, "password_expired", "The password has expired. Change it in the app, then sign in again.");
52
+ }
53
+ };
54
+ var NetworkError = class extends ApiError {
55
+ kind;
56
+ requestSent;
57
+ constructor(kind, detail, requestSent = true) {
58
+ const code = kind === "timeout" ? "timeout" : "network_error";
59
+ super(0, code, apiErrorText(0, code, null, `the request did not complete (${detail})`), {
60
+ serverMessage: "The request did not complete."
61
+ });
62
+ this.kind = kind;
63
+ this.requestSent = requestSent;
64
+ }
65
+ };
66
+ var NotFoundError = class extends ApiError {
67
+ };
68
+ var ConflictError = class extends ApiError {
69
+ /** On an extension conflict: the requested extensions the API refused. Empty otherwise. */
70
+ extensions;
71
+ constructor(status, code, message, extra = {}) {
72
+ super(status, code, message, extra);
73
+ this.extensions = extra.extensions ?? [];
74
+ }
75
+ };
76
+ var ValidationError = class extends ApiError {
77
+ };
78
+ var RateLimitError = class extends ApiError {
79
+ retryAfter;
80
+ constructor(status, code, message, retryAfter, extra = {}) {
81
+ super(status, code, message, extra);
82
+ this.retryAfter = retryAfter;
83
+ }
84
+ };
85
+ var InvalidRequestError = class extends IntelligenceCloudError {
86
+ };
87
+ var ConnectorError = class extends IntelligenceCloudError {
88
+ connectorId;
89
+ stateReason;
90
+ statusMessage;
91
+ status;
92
+ connector;
93
+ constructor(connector) {
94
+ const c = connector ?? {};
95
+ const id = typeof c.id === "string" ? c.id : null;
96
+ const reason = typeof c.state_reason === "string" ? c.state_reason : null;
97
+ super(`Connector ${id ?? "unknown"} is in error: ${reason ?? "unknown reason"}`);
98
+ this.connector = connector;
99
+ this.connectorId = id;
100
+ this.status = typeof c.status === "string" ? c.status : null;
101
+ this.stateReason = reason;
102
+ this.statusMessage = typeof c.status_message === "string" ? c.status_message : null;
103
+ }
104
+ };
105
+ var ConnectorTimeoutError = class extends ConnectorError {
106
+ waited;
107
+ constructor(connector, waitedSeconds) {
108
+ super(connector);
109
+ const c = connector ?? {};
110
+ this.message = `Connector ${typeof c.id === "string" ? c.id : "unknown"} still "${this.status ?? "unknown"}" after ${Math.round(waitedSeconds)} s`;
111
+ this.waited = waitedSeconds;
112
+ }
113
+ };
114
+ var AccountError = class extends IntelligenceCloudError {
115
+ step;
116
+ result;
117
+ constructor(step, result, cause) {
118
+ const why = cause instanceof Error ? cause.message : String(cause);
119
+ super(`Stopped at step "${step}": ${why}. Run the helper again to continue.`, { cause });
120
+ this.step = step;
121
+ this.result = result;
122
+ }
123
+ /**
124
+ * The first error of `type` in the cause chain (`cause`, its `cause` ...), or undefined. A line another
125
+ * location holds arrives as AccountError, then ExtensionMappingError, then ConflictError:
126
+ * `err.find(ConflictError)` returns the ConflictError.
127
+ */
128
+ find(type) {
129
+ const seen = /* @__PURE__ */ new Set();
130
+ let err = this.cause;
131
+ while (err !== void 0 && err !== null && !seen.has(err)) {
132
+ seen.add(err);
133
+ if (err instanceof type) return err;
134
+ err = typeof err === "object" ? err.cause : void 0;
135
+ }
136
+ return void 0;
137
+ }
138
+ };
139
+ var WrongLoginError = class extends IntelligenceCloudError {
140
+ role;
141
+ needed;
142
+ constructor(role, needed) {
143
+ super(
144
+ needed === "admin" ? `This login has role "${role ?? "unknown"}". Account helpers need an administrator login: create the client with an administrator's email and password.` : `This login has role "${role ?? "unknown"}". Conversation helpers need a user login: sign in as the person whose calls, tasks and alerts you want.`
145
+ );
146
+ this.role = role;
147
+ this.needed = needed;
148
+ }
149
+ };
150
+ var FrontlineRequiredError = class extends WrongLoginError {
151
+ constructor(role) {
152
+ super(role, "user");
153
+ this.message = `This login has role "${role ?? "unknown"}". Conversation data (calls, alerts, tasks, insights) needs a frontline_user login; admin logins get empty lists.`;
154
+ }
155
+ };
156
+ var ExtensionMappingError = class extends IntelligenceCloudError {
157
+ userId;
158
+ constructor(userId, cause) {
159
+ super(
160
+ `User ${userId ?? "unknown"}: numbers not mapped (${cause instanceof Error ? cause.message : String(cause)}). Number mappings need an active connector and extensions no other location monitors.`,
161
+ { cause }
162
+ );
163
+ this.userId = userId;
164
+ }
165
+ };
166
+ var WebhookPayloadError = class extends IntelligenceCloudError {
167
+ };
168
+ var PayloadTooLargeError = class extends WebhookPayloadError {
169
+ };
170
+ for (const cls of [
171
+ IntelligenceCloudError,
172
+ ApiError,
173
+ AuthError,
174
+ MfaRequiredError,
175
+ PasswordExpiredError,
176
+ NotFoundError,
177
+ ConflictError,
178
+ ValidationError,
179
+ RateLimitError,
180
+ NetworkError,
181
+ InvalidRequestError,
182
+ ConnectorError,
183
+ ConnectorTimeoutError,
184
+ AccountError,
185
+ WrongLoginError,
186
+ FrontlineRequiredError,
187
+ ExtensionMappingError,
188
+ WebhookPayloadError,
189
+ PayloadTooLargeError
190
+ ]) {
191
+ Object.defineProperty(cls.prototype, brandOf(cls.name), { value: true, enumerable: false });
192
+ }
193
+
194
+ // src/secrets.ts
195
+ var SECRET_WORDS = ["key", "secret", "token", "password", "passwd", "pwd", "credential", "auth"];
196
+ function isSecretName(name) {
197
+ const low = String(name).toLowerCase();
198
+ return SECRET_WORDS.some((w) => low.includes(w));
199
+ }
200
+ function isPlainObject(v) {
201
+ if (v === null || typeof v !== "object") return false;
202
+ const proto = Object.getPrototypeOf(v);
203
+ return proto === Object.prototype || proto === null;
204
+ }
205
+ function maskedConfig(value) {
206
+ if (Array.isArray(value)) return value.map(maskedConfig);
207
+ if (isPlainObject(value)) {
208
+ const out = {};
209
+ for (const k of Object.keys(value)) out[k] = isSecretName(k) ? "***" : maskedConfig(value[k]);
210
+ return out;
211
+ }
212
+ return value;
213
+ }
214
+
215
+ // src/testing/index.ts
216
+ var RESELLER = "00000000-0000-4000-8000-0000000000aa";
217
+ var VERTICAL = "00000000-0000-4000-8000-0000000000bb";
218
+ var CONNECTOR_TYPES = [{ key: "netsapiens", name: "Documented phone system" }, { key: "examplepbx", name: "Example PBX" }];
219
+ var SECRET_WORDS2 = ["key", "secret", "token", "password"];
220
+ var ROLES = { admin: "reseller_admin", user: "frontline_user" };
221
+ var CONNECTOR_OUTCOMES = ["active", "connected", "error", "stuck"];
222
+ var NETWORK_FAILURES = ["connect", "read_timeout", "write_timeout", "undecodable", "reset"];
223
+ var SIGN_IN_OUTCOMES = ["mfa_required", "password_expired", "invalid_credentials"];
224
+ var counter = 0;
225
+ function newId() {
226
+ counter++;
227
+ const n = counter.toString(16).padStart(12, "0");
228
+ const r = Math.floor(Math.random() * 65535).toString(16).padStart(4, "0");
229
+ return `0193b6c2-${r}-7000-8000-${n}`;
230
+ }
231
+ function maskUrl(v) {
232
+ const m = /^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^/?#]*)(.*)$/s.exec(v);
233
+ return m ? m[1] + (m[2] ? "/***" : "") : "***";
234
+ }
235
+ function logBody(v, key = "") {
236
+ if (Array.isArray(v)) return v.map((x) => logBody(x, key));
237
+ if (v !== null && typeof v === "object") {
238
+ const base = maskedConfig(v);
239
+ return Object.fromEntries(Object.entries(base).map(([k, x]) => [k, x === "***" ? x : logBody(v[k], k)]));
240
+ }
241
+ if (typeof v === "string" && (key === "url" || key.endsWith("_url"))) return maskUrl(v);
242
+ return v;
243
+ }
244
+ function topLevelNumbers(text) {
245
+ const out = /* @__PURE__ */ new Map();
246
+ let depth = 0;
247
+ let key = null;
248
+ for (let i = 0; i < text.length; i++) {
249
+ const ch = text[i];
250
+ if (ch === '"') {
251
+ let j = i + 1;
252
+ while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
253
+ if (depth === 1 && key === null) key = JSON.parse(text.slice(i, j + 1));
254
+ else if (depth === 1) key = null;
255
+ i = j;
256
+ } else if (ch === "{" || ch === "[") depth++;
257
+ else if (ch === "}" || ch === "]") depth--;
258
+ else if (ch === "," && depth === 1) key = null;
259
+ else if (depth === 1 && key !== null && /[-0-9]/.test(ch)) {
260
+ const m = /^-?[0-9][0-9.eE+-]*/.exec(text.slice(i));
261
+ if (m) out.set(key, m[0]);
262
+ i += (m?.[0].length ?? 1) - 1;
263
+ key = null;
264
+ }
265
+ }
266
+ return out;
267
+ }
268
+ var res = (type, attrs) => ({ data: { type, attributes: attrs } });
269
+ var page = (rows, type) => ({
270
+ data: type ? rows.map((r) => ({ type, attributes: r })) : rows,
271
+ pagination: { has_more: false, next_cursor: null, total_count: rows.length }
272
+ });
273
+ var errorResponse = (status, code, message) => new Response(JSON.stringify({ error: { code, message, request_id: "req-fake" } }), { status, headers: { "content-type": "application/json" } });
274
+ var json = (status, body, headers = {}) => new Response(status === 204 || body === void 0 ? null : JSON.stringify(body), { status, headers: { "content-type": "application/json", ...headers } });
275
+ var opTable = () => {
276
+ const rows = Object.entries(OPERATIONS).map(([id, op]) => ({
277
+ params: (op.path.match(/\{/g) ?? []).length,
278
+ len: op.path.length,
279
+ method: op.method,
280
+ rx: new RegExp("^" + op.path.replace(/\{[^}]+\}/g, "[^/]+") + "$"),
281
+ id
282
+ }));
283
+ rows.sort((a, b) => a.params - b.params || b.len - a.len);
284
+ return rows;
285
+ };
286
+ var UUID_RE = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})$/;
287
+ var INTEGER_RE = /^-?(0|[1-9][0-9]*)$/;
288
+ var DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
289
+ var DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-])(\d{2}):(\d{2}))$/;
290
+ function realDate(y, m, d) {
291
+ const t = new Date(Date.UTC(y, m - 1, d));
292
+ return t.getUTCFullYear() === y && t.getUTCMonth() === m - 1 && t.getUTCDate() === d;
293
+ }
294
+ function formatProblem(fmt, value) {
295
+ if (fmt === "uuid" && !UUID_RE.test(value)) return "not a UUID";
296
+ if (fmt === "date-time") {
297
+ const m = DATE_TIME_RE.exec(value);
298
+ if (!m) return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$/.test(value) ? "a date-time needs a time zone" : "not an RFC 3339 date-time";
299
+ const [y, mo, d, h, mi, se] = [m[1], m[2], m[3], m[4], m[5], m[6]].map(Number);
300
+ const offOk = m[8] === "Z" || Number(m[10]) <= 23 && Number(m[11]) <= 59;
301
+ if (!realDate(y, mo, d) || h > 23 || mi > 59 || se > 59 || !offOk) return "not an RFC 3339 date-time";
302
+ }
303
+ if (fmt === "date") {
304
+ const m = DATE_RE.exec(value);
305
+ if (!m || !realDate(Number(m[1]), Number(m[2]), Number(m[3]))) return "not a date (YYYY-MM-DD)";
306
+ }
307
+ return null;
308
+ }
309
+ function typeOk(t, v) {
310
+ if (t === "string") return typeof v === "string";
311
+ if (t === "integer") return typeof v === "number" && Number.isInteger(v);
312
+ if (t === "number") return typeof v === "number";
313
+ if (t === "boolean") return typeof v === "boolean";
314
+ if (t === "array") return Array.isArray(v);
315
+ if (t === "object") return v !== null && typeof v === "object" && !Array.isArray(v);
316
+ return true;
317
+ }
318
+ function valueProblem(rule, value, items = false) {
319
+ if (!rule || Object.keys(rule).length === 0) return null;
320
+ const types = rule.type === void 0 ? [] : typeof rule.type === "string" ? [rule.type] : [...rule.type];
321
+ if (value === null) return !types.length || types.includes("null") ? null : "must not be null";
322
+ if (types.length && !types.some((t) => t !== "null" && typeOk(t, value))) {
323
+ return `must be ${types.filter((t) => t !== "null").join(" or ")}`;
324
+ }
325
+ if (rule.enum && !rule.enum.includes(value)) return `must be one of ${JSON.stringify(rule.enum)}`;
326
+ if (typeof value === "string") {
327
+ const p = formatProblem(rule.format, value);
328
+ if (p) return p;
329
+ }
330
+ if (items && Array.isArray(value) && rule.items) {
331
+ for (const v of value) {
332
+ const p = valueProblem(rule.items, v);
333
+ if (p) return `item ${JSON.stringify(v)}: ${p}`;
334
+ }
335
+ }
336
+ return null;
337
+ }
338
+ function queryProblem(q, raw) {
339
+ const isArray = q.type === "array";
340
+ const values = isArray ? raw.split(",") : [raw];
341
+ const item = isArray ? q.items ?? {} : q;
342
+ for (const v of values) {
343
+ if (item.type === "integer") {
344
+ if (!INTEGER_RE.test(v)) return "must be a whole number";
345
+ const n = Number(v);
346
+ if (item.minimum !== void 0 && n < item.minimum || item.maximum !== void 0 && n > item.maximum) {
347
+ return `must be from ${item.minimum} to ${item.maximum}`;
348
+ }
349
+ continue;
350
+ }
351
+ if (item.type === "boolean" && v !== "true" && v !== "false") return 'must be "true" or "false"';
352
+ if (item.enum && !item.enum.includes(v)) return `must be one of ${JSON.stringify(item.enum)}`;
353
+ const p = formatProblem(item.format, v);
354
+ if (p) return p;
355
+ }
356
+ return null;
357
+ }
358
+ var FakeAPI = class {
359
+ /** Every request so far, oldest first, with what answered it (sign-in and token renewal are in `authLog`). */
360
+ requests = [];
361
+ /** What a new connector turns into: `active`, `connected`, `error`, or `stuck` (never settles). */
362
+ connectorOutcome;
363
+ /** @internal */
364
+ _authLog = [];
365
+ /** @internal */
366
+ _companies = /* @__PURE__ */ new Map();
367
+ /** @internal */
368
+ _locations = /* @__PURE__ */ new Map();
369
+ /** @internal */
370
+ _groups = /* @__PURE__ */ new Map();
371
+ /** @internal */
372
+ _rules = /* @__PURE__ */ new Map();
373
+ /** @internal */
374
+ _connectors = /* @__PURE__ */ new Map();
375
+ /** @internal */
376
+ _ihSetup = /* @__PURE__ */ new Map();
377
+ /** @internal */
378
+ _ihConfig = /* @__PURE__ */ new Map();
379
+ /** @internal */
380
+ _faConfig = /* @__PURE__ */ new Map();
381
+ /** @internal */
382
+ _users = /* @__PURE__ */ new Map();
383
+ /** @internal */
384
+ _mappings = /* @__PURE__ */ new Map();
385
+ /** @internal */
386
+ _emailPrefs = /* @__PURE__ */ new Map();
387
+ /** @internal */
388
+ _invitations = [];
389
+ /** @internal */
390
+ _afterCallHooks = /* @__PURE__ */ new Map();
391
+ /** @internal */
392
+ _domains = /* @__PURE__ */ new Map();
393
+ /** @internal */
394
+ _secretsSent = [];
395
+ /** @internal */
396
+ _meExtra = {};
397
+ /** @internal */
398
+ _visibleLocations = [];
399
+ /** @internal */
400
+ _callRows = [];
401
+ /** @internal */
402
+ _callDetails = /* @__PURE__ */ new Map();
403
+ /** @internal */
404
+ _alertRows = [];
405
+ /** @internal */
406
+ _taskRows = [];
407
+ /** @internal */
408
+ _insights = {};
409
+ /** @internal */
410
+ _role;
411
+ _strict;
412
+ _clockN = 0;
413
+ _access = /* @__PURE__ */ new Map();
414
+ // live access token -> [role, email]
415
+ _refresh = /* @__PURE__ */ new Map();
416
+ // unused refresh token -> [role, email]
417
+ _usedRefresh = /* @__PURE__ */ new Map();
418
+ // used refresh token -> email
419
+ _logins = /* @__PURE__ */ new Map();
420
+ // email -> role
421
+ _tokenN = 0;
422
+ _requestRole;
423
+ _requestEmail = null;
424
+ _failAt = null;
425
+ // [writes left before the failing one, status]
426
+ _nextFailures = [];
427
+ _down = false;
428
+ _limited = [0, 0];
429
+ _ops = opTable();
430
+ _routes = [];
431
+ constructor(options = {}) {
432
+ const outcome = options.connectorOutcome ?? "active";
433
+ if (![...CONNECTOR_OUTCOMES, "connecting"].includes(outcome)) {
434
+ throw new InvalidRequestError$1(`connectorOutcome: one of ${JSON.stringify(CONNECTOR_OUTCOMES)}`);
435
+ }
436
+ this.connectorOutcome = outcome;
437
+ this._role = ROLES[options.role ?? "admin"] ?? options.role ?? "reseller_admin";
438
+ this._requestRole = this._role;
439
+ this._strict = options.strict ?? true;
440
+ this._register();
441
+ }
442
+ /** The fake holds connector keys and passwords in its state: it prints as a summary, never as that state. */
443
+ toJSON() {
444
+ return { fake: "FakeAPI", requests: this.requests.length, users: this._users.size, connectors: this._connectors.size };
445
+ }
446
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
447
+ return `FakeAPI ${JSON.stringify(this.toJSON())}`;
448
+ }
449
+ // ------------------------------------------------------------------ public surface
450
+ /**
451
+ * A real Client wired to this fake. `role`: "admin" (an administrator login) or "user" (a person's own
452
+ * login); default the role given to FakeAPI. `asUser` (with role "user"): the user id or email of a person
453
+ * `seedCustomer` created; the client signs in as them, so the calls, alerts, tasks and Insights Hub it sees
454
+ * follow their license and teams. Clients for the same person share that login's sessions. Other options go to Client, for example `maskNumbers: false`.
455
+ * Waits (retries, connector checks) do not sleep unless you pass `sleep`.
456
+ */
457
+ client(options = {}) {
458
+ const { role, asUser, ...rest } = options;
459
+ if ("fetch" in rest) throw new InvalidRequestError$1("FakeAPI.client() wires the fake as fetch: do not pass fetch");
460
+ if (role !== void 0 && !(role in ROLES) && !Object.values(ROLES).includes(role)) {
461
+ throw new InvalidRequestError$1('role: "admin" or "user"');
462
+ }
463
+ const r = role ? ROLES[role] ?? role : this._role;
464
+ let email = `${r === "reseller_admin" ? "admin" : "user"}.${this._logins.size + 1}@example.com`;
465
+ if (asUser !== void 0) {
466
+ if (r !== "frontline_user") throw new InvalidRequestError$1('asUser needs role: "user"');
467
+ const user = [...this._users.values()].find((u) => u.id === asUser || u.email === asUser);
468
+ if (!user) throw new InvalidRequestError$1("asUser: the user id or email of a person seedCustomer created");
469
+ email = user.email;
470
+ }
471
+ this._logins.set(email, r);
472
+ return new Client({ sleep: async () => {
473
+ }, random: () => 0.5, ...rest, email, password: "fake-password", fetch: this.fetch });
474
+ }
475
+ /** Every write request so far as `[method, path]`, oldest first. */
476
+ get writes() {
477
+ return this.writesSince(0);
478
+ }
479
+ /** The writes after `start` (an index into `requests`, e.g. `api.requests.length`). */
480
+ writesSince(start = 0) {
481
+ return this.requests.slice(start).filter((r) => r.method !== "GET").map((r) => [r.method, r.path]);
482
+ }
483
+ /**
484
+ * Sign-in and token renewal, oldest first: `["login" | "refresh" | "refresh_reused", email]`.
485
+ * "refresh_reused" means a used refresh token was sent again and every session of that login ended.
486
+ */
487
+ get authLog() {
488
+ return [...this._authLog];
489
+ }
490
+ /** How many requests matched `method` and the path pattern (a regex without /api/v1, anchored). */
491
+ count(method, pattern) {
492
+ const rx = typeof pattern === "string" ? new RegExp("^" + pattern + "$") : pattern;
493
+ return this.requests.filter((r) => r.method === method && rx.test(r.path)).length;
494
+ }
495
+ /** Forget the request log and the auth log (state is kept). */
496
+ resetLog() {
497
+ this.requests.length = 0;
498
+ this._authLog.length = 0;
499
+ }
500
+ /** Make the `nth` write from now (1 = the next one) fail once with `status`. */
501
+ failWrite(nth = 1, status = 400) {
502
+ if (!Number.isInteger(nth) || nth < 1) throw new InvalidRequestError$1("nth: 1 or more");
503
+ this._failAt = [nth - 1, status];
504
+ }
505
+ /**
506
+ * Make the next request that matches `method` and the path pattern `path` (without /api/v1; sign-in is
507
+ * "/auth/login", renewal "/auth/refresh") fail once: with HTTP `status`, or with a `network` failure:
508
+ * "connect" (never left), "read_timeout", "write_timeout" or "reset" (left, no answer), or "undecodable" (an
509
+ * answer that cannot be read). A status answers before the platform acts (a renewal's token is
510
+ * not used); with `afterProcessing: true` it answers after the token was rotated, as a gateway error would. A
511
+ * renewal that fails with a network failure other than "connect" has used its refresh token.
512
+ * `signIn`: the next sign-in answers "mfa_required" (MfaRequiredError), "password_expired"
513
+ * (PasswordExpiredError) or "invalid_credentials" (AuthError, 401).
514
+ */
515
+ failNext(options) {
516
+ const { status, network, signIn, retryAfter, afterProcessing } = options ?? {};
517
+ let { method, path } = options ?? {};
518
+ if (afterProcessing !== void 0 && typeof afterProcessing !== "boolean") throw new InvalidRequestError$1("afterProcessing: true or false");
519
+ if ([status, network, signIn].filter((x) => x !== void 0).length !== 1) throw new InvalidRequestError$1("failNext: give one of status, network or signIn");
520
+ if (network !== void 0 && !NETWORK_FAILURES.includes(network)) {
521
+ throw new InvalidRequestError$1(`network: one of ${JSON.stringify(NETWORK_FAILURES)}`);
522
+ }
523
+ if (signIn !== void 0) {
524
+ if (!SIGN_IN_OUTCOMES.includes(signIn)) throw new InvalidRequestError$1(`signIn: one of ${JSON.stringify(SIGN_IN_OUTCOMES)}`);
525
+ method = "POST";
526
+ path = "/auth/login";
527
+ }
528
+ this._nextFailures.push({ status, network, signIn, method, path: path ? new RegExp("^" + path + "$") : void 0, retryAfter, after: afterProcessing === true });
529
+ }
530
+ /** Every request fails as if there were no network (the client throws NetworkError). */
531
+ networkDown(down = true) {
532
+ this._down = down;
533
+ }
534
+ /** The next `count` requests (sign-in included) answer 429 with `Retry-After`. */
535
+ rateLimit(count = 1, retryAfter = 1) {
536
+ this._limited = [count, retryAfter];
537
+ }
538
+ /**
539
+ * Settle connectors that are waiting ("connecting"): the one with this id, or every waiting one at this
540
+ * location. `outcome`: "active", "connected" or "error". Returns how many were settled.
541
+ */
542
+ settleConnector(connectorOrLocation, outcome = "active") {
543
+ if (!["active", "connected", "error"].includes(outcome)) throw new InvalidRequestError$1('outcome: "active", "connected" or "error"');
544
+ let n = 0;
545
+ for (const c of this._connectors.values()) {
546
+ if ((c.id === connectorOrLocation || c.location_id === connectorOrLocation) && c.status === "connecting") {
547
+ c.status = outcome;
548
+ c._outcome = outcome;
549
+ if (outcome === "error") c.state_reason = "invalid_permissions";
550
+ n++;
551
+ }
552
+ }
553
+ return n;
554
+ }
555
+ /** Every access token stops working, as when they expire: the next call renews its token. */
556
+ expireAccessTokens() {
557
+ this._access.clear();
558
+ }
559
+ // ------------------------------------------------------------------ plumbing
560
+ _on(method, pattern, fn) {
561
+ this._routes.push([method, new RegExp("^" + pattern.replace(/\{\}/g, "([^/]+)") + "$"), fn]);
562
+ }
563
+ _operation(method, path) {
564
+ for (const o of this._ops) if (o.method === method && o.rx.test(path)) return o.id;
565
+ return null;
566
+ }
567
+ _checkStrict(opId, method, path, query, body, numbers = /* @__PURE__ */ new Map()) {
568
+ if (opId === null) return errorResponse(404, "NOT_FOUND", `${method} ${path} is not in the published API`);
569
+ const op = OPERATIONS[opId];
570
+ const rules = new Map(op.query.map((q) => [q.name, q]));
571
+ const unknown = [...new Set(query.keys())].filter((k) => !rules.has(k)).sort();
572
+ if (unknown.length) return errorResponse(400, "VALIDATION_ERROR", `Unknown query parameter(s): ${unknown.join(", ")}`);
573
+ for (const [name, value] of query.entries()) {
574
+ const p = queryProblem(rules.get(name), value);
575
+ if (p) return errorResponse(400, "VALIDATION_ERROR", `${name}: ${p}`);
576
+ }
577
+ if (op.hasBody) {
578
+ if (body === void 0 || body === null) {
579
+ if (op.bodyRequired) return errorResponse(422, "VALIDATION_ERROR", "A request body is required");
580
+ } else {
581
+ if (typeof body !== "object" || Array.isArray(body)) return errorResponse(422, "VALIDATION_ERROR", "The body must be a JSON object");
582
+ const rule = op.body;
583
+ if (rule) {
584
+ const missing = rule.required.filter((k) => !(k in body));
585
+ if (missing.length) return errorResponse(422, "VALIDATION_ERROR", `Missing required field(s): ${missing.join(", ")}`);
586
+ const props = rule.properties;
587
+ const extra = Object.keys(props).length ? Object.keys(body).filter((k) => !(k in props)).sort() : [];
588
+ if (extra.length) return errorResponse(422, "VALIDATION_ERROR", `Unknown field(s): ${extra.join(", ")}`);
589
+ for (const [name, value] of Object.entries(body)) {
590
+ const raw = numbers.get(name);
591
+ const p = raw !== void 0 && /[.eE]/.test(raw) && [props[name]?.type ?? []].flat().includes("integer") ? "must be integer" : valueProblem(props[name], value, true);
592
+ if (p) return errorResponse(422, "VALIDATION_ERROR", `${name}: ${p}`);
593
+ }
594
+ }
595
+ }
596
+ }
597
+ return null;
598
+ }
599
+ /** @internal */
600
+ _issue(role, email) {
601
+ this._tokenN++;
602
+ const access = `fake-access-${this._tokenN}`;
603
+ const refresh = `fake-refresh-${this._tokenN}`;
604
+ this._access.set(access, [role, email]);
605
+ this._refresh.set(refresh, [role, email]);
606
+ return { access_token: access, refresh_token: refresh, token_type: "Bearer", expires_in: 899, user: { id: newId(), role } };
607
+ }
608
+ _endSessions(email) {
609
+ for (const table of [this._access, this._refresh]) for (const [t, [, e]] of [...table]) if (e === email) table.delete(t);
610
+ }
611
+ /** Use a refresh token once. A second use ends every session of its login. */
612
+ _useRefresh(token) {
613
+ const t = String(token);
614
+ const owner = this._refresh.get(t);
615
+ if (owner) {
616
+ this._refresh.delete(t);
617
+ this._usedRefresh.set(t, owner[1]);
618
+ return owner;
619
+ }
620
+ const email = this._usedRefresh.get(t);
621
+ if (email !== void 0) this._endSessions(email);
622
+ return null;
623
+ }
624
+ _takeFailure(method, path) {
625
+ const i = this._nextFailures.findIndex((f) => (!f.method || f.method === method) && (!f.path || f.path.test(path)));
626
+ return i < 0 ? null : this._nextFailures.splice(i, 1)[0];
627
+ }
628
+ /** A network failure, with the shape Node's fetch (undici) gives: TypeError "fetch failed" whose cause is the underlying error. */
629
+ _net(rec, kind) {
630
+ if (rec) rec.answer = `network:${kind}`;
631
+ if (kind === "undecodable") return new Response(new ReadableStream({ start: (c) => c.error(new TypeError("terminated")) }), { status: 200 });
632
+ const fail = (name, code, message, extra = {}) => {
633
+ const cause = Object.assign(new Error(message), { name, code, ...extra });
634
+ throw Object.assign(new TypeError("fetch failed"), { cause });
635
+ };
636
+ if (kind === "connect") fail("Error", "ECONNREFUSED", "connect ECONNREFUSED 127.0.0.1:443", { errno: -111, syscall: "connect", address: "127.0.0.1", port: 443 });
637
+ if (kind === "read_timeout") fail("HeadersTimeoutError", "UND_ERR_HEADERS_TIMEOUT", "Headers Timeout Error");
638
+ if (kind === "write_timeout") fail("SocketError", "UND_ERR_SOCKET", "other side closed");
639
+ return fail("Error", "ECONNRESET", "read ECONNRESET", { errno: -104, syscall: "read" });
640
+ }
641
+ _failureResponse(rec, f) {
642
+ if (f.network !== void 0) return this._net(rec, f.network);
643
+ if (f.signIn === "mfa_required") return json(200, { status: "mfa_required" });
644
+ if (f.signIn === "password_expired") return json(200, { ...this._issue(this._role, "expired@example.com"), password_expired: true });
645
+ if (f.signIn === "invalid_credentials") return errorResponse(401, "UNAUTHORIZED", "Invalid email or password");
646
+ const headers = f.retryAfter !== void 0 ? { "retry-after": String(f.retryAfter) } : {};
647
+ return json(f.status, { error: { code: "FAKE_FAILURE", message: "Failed on purpose by FakeAPI.failNext", request_id: "req-fake" } }, headers);
648
+ }
649
+ /** The fetch the client uses. @internal */
650
+ fetch = async (input, init = {}) => {
651
+ const ctx = { rec: null };
652
+ const r = await this._serve(input, init, ctx);
653
+ if (ctx.rec && ctx.rec.answer === null) ctx.rec.answer = r.status;
654
+ return r;
655
+ };
656
+ async _serve(input, init, ctx) {
657
+ const url = new URL(String(input));
658
+ const method = init.method ?? "GET";
659
+ const full = url.pathname;
660
+ const path = full.startsWith("/api/v1") ? full.slice("/api/v1".length) : full;
661
+ let body;
662
+ let badJson = false;
663
+ try {
664
+ body = init.body ? JSON.parse(String(init.body)) : void 0;
665
+ } catch {
666
+ badJson = true;
667
+ }
668
+ const headers = new Headers(init.headers);
669
+ const opId = this._operation(method, path);
670
+ let authAt = -1;
671
+ if (path === "/auth/login" || path === "/auth/refresh") {
672
+ let who2;
673
+ if (path === "/auth/login") who2 = body?.email;
674
+ else who2 = this._refresh.get(String(body?.refresh_token))?.[1] ?? this._usedRefresh.get(String(body?.refresh_token));
675
+ this._authLog.push([path === "/auth/login" ? "login" : "refresh", String(who2)]);
676
+ authAt = this._authLog.length - 1;
677
+ } else if (path !== "/auth/logout") {
678
+ const query = {};
679
+ url.searchParams.forEach((v, k) => query[k] = v);
680
+ ctx.rec = { method, path, query, body: logBody(body), operation: opId, answer: null };
681
+ this.requests.push(ctx.rec);
682
+ }
683
+ const rec = ctx.rec;
684
+ if (this._down) return this._net(rec, "connect");
685
+ const [count, retryAfter] = this._limited;
686
+ if (count > 0) {
687
+ this._limited = [count - 1, retryAfter];
688
+ return json(429, { error: { code: "RATE_LIMITED", message: "Too many requests" } }, { "retry-after": String(retryAfter) });
689
+ }
690
+ const failure = this._takeFailure(method, path);
691
+ if (failure && failure.network === "connect") return this._net(rec, "connect");
692
+ if (badJson) return errorResponse(400, "VALIDATION_ERROR", "The body is not JSON");
693
+ if (this._strict) {
694
+ const refused = this._checkStrict(opId, method, path, url.searchParams, body, init.body ? topLevelNumbers(String(init.body)) : void 0);
695
+ if (refused) return refused;
696
+ } else if (opId === null) {
697
+ return errorResponse(501, "NOT_IMPLEMENTED", `${method} ${path} is not served by this fake`);
698
+ }
699
+ const afterByKind = path === "/auth/refresh" && failure?.network !== void 0;
700
+ if (failure && !failure.after && !afterByKind) return this._failureResponse(rec, failure);
701
+ if (path === "/auth/login") {
702
+ const email = String(body?.email);
703
+ return json(200, this._issue(this._logins.get(email) ?? this._role, email));
704
+ }
705
+ if (path === "/auth/refresh") {
706
+ const token2 = String(body?.refresh_token);
707
+ const reused = this._usedRefresh.has(token2);
708
+ const owner = this._useRefresh(token2);
709
+ if (reused) this._authLog[authAt] = ["refresh_reused", this._usedRefresh.get(token2)];
710
+ const issued = owner ? this._issue(owner[0], owner[1]) : null;
711
+ if (failure) return this._failureResponse(null, failure);
712
+ if (!issued) return errorResponse(401, "UNAUTHORIZED", "Invalid refresh token");
713
+ return json(200, issued);
714
+ }
715
+ if (path === "/auth/logout") return json(204, void 0);
716
+ const token = (headers.get("authorization") ?? "").replace("Bearer ", "");
717
+ const who = this._access.get(token);
718
+ if (!who) return errorResponse(401, "UNAUTHORIZED", "The access token is not valid");
719
+ [this._requestRole, this._requestEmail] = who;
720
+ if (method !== "GET" && this._failAt) {
721
+ const [left, status] = this._failAt;
722
+ if (left === 0) {
723
+ this._failAt = null;
724
+ return errorResponse(status, "FAKE_FAILURE", "Failed on purpose by FakeAPI.failWrite");
725
+ }
726
+ this._failAt = [left - 1, status];
727
+ }
728
+ const req = { method, path, query: url.searchParams, headers, body };
729
+ for (const [m, rx, fn] of this._routes) {
730
+ const hit = rx.exec(path);
731
+ if (hit && m === method) {
732
+ let out;
733
+ try {
734
+ out = fn(req, body, ...hit.slice(1));
735
+ } catch (e) {
736
+ if (e instanceof TypeError) return errorResponse(404, "NOT_FOUND", "Not found");
737
+ throw e;
738
+ }
739
+ if (failure) return this._failureResponse(rec, failure);
740
+ if (out instanceof Response) return out;
741
+ return json(out[0], out[1]);
742
+ }
743
+ }
744
+ return errorResponse(501, "NOT_IMPLEMENTED", `${opId ?? path} is published but this fake does not serve it yet`);
745
+ }
746
+ // ------------------------------------------------------------------ seed data (fictional)
747
+ /**
748
+ * Build "Riverbend Auto Group" through the account layer: `teams` teams with connectors, the Management
749
+ * location, groups and the Low Sentiment alert (the phrase alerts stay pending: the fake holds no phrase
750
+ * lists). With `people`, two Base Users per team and one Base Manager on every team. The request log is
751
+ * cleared afterwards.
752
+ */
753
+ async seedCustomer(options = {}) {
754
+ const teams = options.teams ?? 1;
755
+ const people = options.people ?? true;
756
+ const outcome = this.connectorOutcome;
757
+ this.connectorOutcome = "active";
758
+ try {
759
+ const acc = this.client({ role: "admin" }).accounts;
760
+ const teamSpec = (i) => ({
761
+ name: i === 0 ? "Riverbend - Main" : `Riverbend - Team ${i + 1}`,
762
+ street: `${100 + i} River Rd`,
763
+ city: "Springfield",
764
+ state: "IL",
765
+ country: "US",
766
+ zipcode: "62701",
767
+ vertical: "service-providers"
768
+ });
769
+ const conn = async (i) => ConnectorSpec.netsapiens("https://pbx.example.com/ns-api/v2", `riverbend${i + 1}.example.com`, "example-key");
770
+ const cust = await acc.createCustomer({
771
+ companyName: "Riverbend Auto Group",
772
+ admin: { email: "pat.lee@example.com", firstName: "Pat", lastName: "Lee", phoneNumber: "+15555550100" },
773
+ team: teamSpec(0),
774
+ connector: await conn(0),
775
+ mfaOff: true
776
+ });
777
+ for (let i = 1; i < teams; i++) await acc.addTeam(cust, teamSpec(i), await conn(i));
778
+ const seeded = { customer: cust, companyId: cust.companyId, baseUsers: {}, managers: {}, people: [] };
779
+ if (people) {
780
+ for (const [i, t] of cust.teams.entries()) {
781
+ for (const j of [1, 2]) {
782
+ const email = `base.user${i + 1}${j}@example.com`;
783
+ const m = await acc.addBaseUser(cust, { email, firstName: "Base", lastName: `User ${i + 1}${j}` }, { team: t, line: `2${String(i + 1).padStart(2, "0")}${j}`, invite: false });
784
+ seeded.baseUsers[email] = m.userId;
785
+ seeded.people.push({ userId: m.userId, email, license: "base_user", teams: [t.locationId], lines: [`2${String(i + 1).padStart(2, "0")}${j}`] });
786
+ }
787
+ }
788
+ const mgr = await acc.addBaseManager(cust, { email: "dana.cho@example.com", firstName: "Dana", lastName: "Cho" }, { teams: [...cust.teams], line: "2001", invite: false });
789
+ seeded.managers["dana.cho@example.com"] = mgr.userId;
790
+ seeded.people.push({ userId: mgr.userId, email: "dana.cho@example.com", license: "base_manager", teams: cust.teams.map((t) => t.locationId), lines: ["2001"] });
791
+ }
792
+ this._visibleLocations = [...cust.management ? [cust.management] : [], ...cust.teams].map((t) => ({ id: t.locationId, location_name: t.name }));
793
+ return seeded;
794
+ } finally {
795
+ this.connectorOutcome = outcome;
796
+ this.resetLog();
797
+ }
798
+ }
799
+ /**
800
+ * Add `n` fictional calls (today, or on `day`) for user logins to read, each with a detail record, an
801
+ * open task and, for every other call, an "Upset Customer" alert. Callers use 555-01xx numbers; each call
802
+ * reaches a seeded Base User's line at that location in turn (so a person signed in with `asUser` sees
803
+ * their own). `recording`: each call has a recording link (an example.com https address that expires in
804
+ * two hours). `topics`: topic volumes and rising topics for `topics()` and the Insights Hub dashboard.
805
+ * Returns the call ids, newest first.
806
+ */
807
+ seedCalls(n = 3, options = {}) {
808
+ const { alerts = true, tasks = true, recording = false, topics = false } = options;
809
+ const names = ["Morgan Diaz", "Riley Park", "Avery Lane", "Jamie Fox", "Quinn Hale"];
810
+ const lid = options.locationId ?? this._visibleLocations[this._visibleLocations.length - 1]?.id ?? newId();
811
+ if (!this._visibleLocations.length) this._visibleLocations = [{ id: lid, location_name: "Riverbend - Main" }];
812
+ let base;
813
+ if (options.day === void 0) base = new Date(Date.now() - 5 * 6e4);
814
+ else {
815
+ const d = typeof options.day === "string" ? options.day.split("-").map(Number) : [options.day.getFullYear(), options.day.getMonth() + 1, options.day.getDate()];
816
+ base = new Date(d[0], d[1] - 1, d[2], 12, 0, 0);
817
+ }
818
+ const lines = [...this._users.values()].filter((u) => u._locations.includes(lid)).flatMap((u) => (this._mappings.get(u.id) ?? []).filter((m) => this._connectors.get(m.connector_id)?.location_id === lid).filter(() => {
819
+ const pr = u._products.get(lid);
820
+ return pr !== void 0 && pr.size === 1 && pr.has("after-call-copilot");
821
+ }).flatMap((m) => m.monitored_numbers));
822
+ if (!lines.length) lines.push("2101");
823
+ const expires = new Date(Date.now() + 2 * 36e5).toISOString().replace(/\.\d+Z$/, "Z");
824
+ const ids = [];
825
+ const newCalls = [];
826
+ const newTasks = [];
827
+ const newAlerts = [];
828
+ for (let i = 0; i < n; i++) {
829
+ const cid = newId();
830
+ const when = new Date(base.getTime() - i * 6e4).toISOString().replace(/\.\d+Z$/, "Z");
831
+ const row = {
832
+ id: cid,
833
+ call_date: when,
834
+ call_type: "inbound",
835
+ status: "completed",
836
+ duration: 120 + i,
837
+ caller_name: names[i % names.length],
838
+ caller_number: `+1555555${String(100 + i % 100).padStart(4, "0")}`,
839
+ callee_name: "Riverbend front desk",
840
+ callee_number: lines[i % lines.length],
841
+ location_id: lid,
842
+ summary: "The caller asked about a service appointment.",
843
+ sentiment: "neutral",
844
+ sentiment_score: 0,
845
+ task_count: tasks ? 1 : 0
846
+ };
847
+ newCalls.push(row);
848
+ this._callDetails.set(cid, {
849
+ ...row,
850
+ ...recording ? { vcon: { recording_url: `https://media.example.com/recordings/${cid}.wav?sig=example`, recording_url_expires_at: expires, recording_mime_type: "audio/wav" } } : {},
851
+ analysis: { summary: { text: row.summary, key_points: ["Asked about an appointment"], action_items: ["Call back"] }, sentiment: { overall: "neutral" }, topics: [{ name: "Service" }] },
852
+ tasks: tasks ? [{ id: newId(), title: "Call back", status: "pending", due_date: null }] : []
853
+ });
854
+ if (tasks) newTasks.push({ id: newId(), title: "Call back", status: "pending", due_date: null, call_id: cid, location_id: lid });
855
+ if (alerts && i % 2 === 0) {
856
+ newAlerts.push({
857
+ id: newId(),
858
+ call_id: cid,
859
+ call_date: when,
860
+ caller_name: row.caller_name,
861
+ caller_number: row.caller_number,
862
+ callee_name: row.callee_name,
863
+ callee_number: row.callee_number,
864
+ summary: row.summary,
865
+ sentiment: "negative",
866
+ sentiment_score: -30,
867
+ keywords: ["Upset Customer"],
868
+ topics: []
869
+ });
870
+ }
871
+ ids.push(cid);
872
+ }
873
+ this._callRows.unshift(...newCalls);
874
+ if (topics) {
875
+ this._insights = {
876
+ stats: { total_calls: this._callRows.length, answered_calls: this._callRows.length, unanswered_calls: 0 },
877
+ topic_call_volumes: [{ name: "Service", slug: "service", call_count: n }, { name: "Billing", slug: "billing", call_count: Math.max(1, Math.floor(n / 2)) }],
878
+ trending_topics: [
879
+ { name: "Service", slug: "service", call_count: n, previous_call_count: 1, percentage_change: 100, trend_data: [] },
880
+ { name: "Hours", slug: "hours", call_count: 1, previous_call_count: 2, percentage_change: -50, trend_data: [] }
881
+ ]
882
+ };
883
+ }
884
+ this._taskRows.unshift(...newTasks);
885
+ this._alertRows.unshift(...newAlerts);
886
+ return ids;
887
+ }
888
+ // ------------------------------------------------------------------ state readers (for assertions)
889
+ /** @internal */
890
+ _tick() {
891
+ this._clockN++;
892
+ return `2026-11-01T00:00:${String(this._clockN).padStart(2, "0")}Z`;
893
+ }
894
+ _locationUsers(lid) {
895
+ return [...this._users.values()].filter((u) => u._locations.includes(lid));
896
+ }
897
+ /** The products a user has at a location. */
898
+ products(uid, lid) {
899
+ const u = this._users.get(uid);
900
+ if (!u._products.has(lid)) u._products.set(lid, /* @__PURE__ */ new Set());
901
+ return u._products.get(lid);
902
+ }
903
+ /** The numbers mapped to a user (on one connector, or on all). */
904
+ numbers(uid, connectorId) {
905
+ return (this._mappings.get(uid) ?? []).filter((m) => connectorId === void 0 || m.connector_id === connectorId).flatMap((m) => m.monitored_numbers);
906
+ }
907
+ /** The lines First Alert watches at a location. */
908
+ faNumbers(lid) {
909
+ return (this._faConfig.get(lid)?.connector_mappings ?? []).flatMap((m) => m.monitored_numbers);
910
+ }
911
+ /** The lines Insights Hub covers at a location. */
912
+ ihNumbers(lid) {
913
+ return (this._ihSetup.get(lid)?.connector_mappings ?? []).flatMap((m) => m.monitored_numbers);
914
+ }
915
+ /** The user ids in the named group at a location. */
916
+ groupMembers(lid, name) {
917
+ return [...this._groups.values()].find((g) => g.location_id === lid && g.group_name === name)?.members ?? [];
918
+ }
919
+ // ------------------------------------------------------------------ routes
920
+ /** The seeded person this request signed in as (`client({ asUser })`), or null for a generic login. */
921
+ _viewer() {
922
+ if (this._requestRole !== "frontline_user" || !this._requestEmail) return null;
923
+ return [...this._users.values()].find((u) => u.email === this._requestEmail) ?? null;
924
+ }
925
+ /** Locations where the person is in an alert group (a manager of that team). */
926
+ _alertLocations(viewer) {
927
+ const names = ["Customer Threats", "Upset Customers", "Low Sentiment Calls"];
928
+ return new Set([...this._groups.values()].filter((g) => names.includes(g.group_name) && g.members.includes(viewer.id)).map((g) => g.location_id));
929
+ }
930
+ /** What the platform shows a person: a manager their teams' calls, a Base User their own lines' calls. */
931
+ _inScope(row) {
932
+ const viewer = this._viewer();
933
+ if (!viewer) return true;
934
+ if (this._alertLocations(viewer).has(row.location_id)) return true;
935
+ const lines = new Set((this._mappings.get(viewer.id) ?? []).flatMap((m) => m.monitored_numbers));
936
+ return (lines.has(row.callee_number) || lines.has(row.caller_number)) && viewer._locations.includes(row.location_id);
937
+ }
938
+ _alertInScope(alert) {
939
+ const viewer = this._viewer();
940
+ if (!viewer) return true;
941
+ return this._alertLocations(viewer).has(this._callDetails.get(alert.call_id)?.location_id);
942
+ }
943
+ _paged(req, rows, key, summary) {
944
+ const limit = Number(req.query.get("limit") || 50);
945
+ const start = Number(req.query.get("cursor") || 0);
946
+ const more = start + limit < rows.length;
947
+ return [200, { data: { [key]: rows.slice(start, start + limit), summary }, meta: { has_more: more, next_cursor: more ? String(start + limit) : null, limit } }];
948
+ }
949
+ _userAttrs(u) {
950
+ return {
951
+ id: u.id,
952
+ company_id: u.company_id,
953
+ email: u.email,
954
+ role: u.role,
955
+ status: u.status,
956
+ first_name: u.first_name,
957
+ last_name: u.last_name,
958
+ locations: u._locations.map((x) => ({ location_id: x })),
959
+ invited_at: u.invited_at ?? null,
960
+ ...u.department ? { department: u.department } : {}
961
+ };
962
+ }
963
+ _locUser(u, lid) {
964
+ return {
965
+ id: u.id,
966
+ email: u.email,
967
+ role: u.role,
968
+ status: u.status,
969
+ location_id: lid,
970
+ enabled_products: [...u._products.get(lid) ?? []].sort(),
971
+ groups: [...this._groups.values()].filter((g) => g.location_id === lid && g.members.includes(u.id)).map((g) => g.group_name)
972
+ };
973
+ }
974
+ _register() {
975
+ const api = this;
976
+ const miss = () => {
977
+ throw new TypeError("missing record");
978
+ };
979
+ const get = (m, k) => m.get(k) ?? miss();
980
+ const conflict = (message) => [409, { error: { code: "CONFLICT", message } }];
981
+ this._on("GET", "/me", () => {
982
+ const viewer = api._viewer();
983
+ if (viewer) {
984
+ return [200, { data: { id: viewer.id, role: api._requestRole, email: viewer.email, first_name: viewer.first_name ?? null, last_name: viewer.last_name ?? null, company_id: viewer.company_id, location_ids: [...viewer._locations], enabled_products: [...new Set([...viewer._products.values()].flatMap((x) => [...x]))].sort(), user_type: "company_user" } }];
985
+ }
986
+ return meGeneric();
987
+ });
988
+ const meGeneric = () => [200, { data: { id: newId(), role: api._requestRole, reseller_id: api._requestRole !== "frontline_user" ? RESELLER : null, user_type: api._requestRole !== "frontline_user" ? "reseller_user" : "company_user", unexpected_field: "redacted", ...api._meExtra } }];
989
+ this._on("GET", "/connector-types", () => [200, { data: CONNECTOR_TYPES }]);
990
+ this._on("GET", "/verticals", () => [200, { data: [{ id: VERTICAL, key: "service-providers", name: "Service providers" }] }]);
991
+ this._on("GET", "/resellers/{}/companies", (req) => {
992
+ const q = (req.query.get("search") ?? "").toLowerCase();
993
+ const rows = [...api._companies.values()].filter((c) => c.company_name.toLowerCase().startsWith(q));
994
+ return [200, { data: rows.map((c) => ({ type: "company", attributes: c })), has_more: false, next_cursor: null, total_count: rows.length }];
995
+ });
996
+ this._on("POST", "/resellers/{}/companies", (_r, body, rid) => {
997
+ const cid = newId();
998
+ const c = { ...body, id: cid, reseller_id: rid, is_active: true, mfa_enforced: true };
999
+ api._companies.set(cid, c);
1000
+ return [201, { data: { type: "company", attributes: c }, invited_user: { id: newId(), email: body.primary_admin_contact_email } }];
1001
+ });
1002
+ this._on("GET", "/companies/{}", (_r, _b, cid) => api._companies.has(cid) ? [200, res("company", api._companies.get(cid))] : [404, { error: {} }]);
1003
+ this._on("PATCH", "/companies/{}", (_r, body, cid) => {
1004
+ Object.assign(get(api._companies, cid), body);
1005
+ return [200, res("company", api._companies.get(cid))];
1006
+ });
1007
+ this._on("POST", "/companies/{}/deactivate", (_r, _b, cid) => {
1008
+ const c = get(api._companies, cid);
1009
+ if (!c.is_active) return conflict("Company is already inactive");
1010
+ c.is_active = false;
1011
+ return [200, res("company", c)];
1012
+ });
1013
+ this._on("POST", "/companies/{}/reactivate", (_r, _b, cid) => {
1014
+ const c = get(api._companies, cid);
1015
+ c.is_active = true;
1016
+ return [200, res("company", c)];
1017
+ });
1018
+ this._on("GET", "/locations/{}/after-call/automation", (_r, _b, lid) => [200, { data: api._afterCallHooks.get(lid) ?? null }]);
1019
+ this._on("PUT", "/locations/{}/after-call/automation", (_r, body, lid) => {
1020
+ api._afterCallHooks.set(lid, { webhook_url: body.webhook_url, enabled: body.enabled ?? true });
1021
+ return [200, { data: api._afterCallHooks.get(lid) }];
1022
+ });
1023
+ this._on("POST", "/companies/{}/domains", (_r, body, cid) => {
1024
+ const d = { id: "dom-1", domain: body.domain, status: "pending", verification: { type: "TXT", name: "_ic-verify." + body.domain, value: "abc" } };
1025
+ api._domains.set(cid, [...api._domains.get(cid) ?? [], d]);
1026
+ return [201, { data: d }];
1027
+ });
1028
+ this._on("GET", "/companies/{}/domains", (_r, _b, cid) => [200, { data: api._domains.get(cid) ?? [] }]);
1029
+ this._on("GET", "/companies/{}/locations", (req, _b, cid) => {
1030
+ const q = (req.query.get("search") ?? "").toLowerCase();
1031
+ return [200, page([...api._locations.values()].filter((x) => x.company_id === cid && x.location_name.toLowerCase().includes(q)), "location")];
1032
+ });
1033
+ this._on("POST", "/companies/{}/locations", (_r, body, cid) => {
1034
+ const lid = newId();
1035
+ api._locations.set(lid, { ...body, id: lid, company_id: cid, is_active: true, created_at: api._tick() });
1036
+ return [201, res("location", api._locations.get(lid))];
1037
+ });
1038
+ this._on("GET", "/companies/{}/locations/{}", (_r, _b, _c, lid) => [200, res("location", get(api._locations, lid))]);
1039
+ this._on("PATCH", "/companies/{}/locations/{}", (_r, body, _c, lid) => {
1040
+ Object.assign(get(api._locations, lid), body);
1041
+ return [200, res("location", api._locations.get(lid))];
1042
+ });
1043
+ this._on("GET", "/locations/{}/user-groups", (req, _b, lid) => {
1044
+ const q = (req.query.get("search") ?? "").toLowerCase();
1045
+ const rows = [...api._groups.values()].filter((g) => g.location_id === lid && g.group_name.toLowerCase().includes(q)).map(({ members: _m, ...g }) => g);
1046
+ return [200, page(rows, "user_group")];
1047
+ });
1048
+ this._on("POST", "/locations/{}/user-groups", (_r, body, lid) => {
1049
+ const gid = newId();
1050
+ api._groups.set(gid, { id: gid, location_id: lid, group_name: body.group_name, members: [] });
1051
+ return [201, res("user_group", api._groups.get(gid))];
1052
+ });
1053
+ this._on("GET", "/locations/{}/user-groups/{}", (_r, _b, _l, gid) => {
1054
+ const g = get(api._groups, gid);
1055
+ return [200, res("user_group", { ...g, members: g.members.map((m) => ({ id: m })) })];
1056
+ });
1057
+ const membership = (lid, uid) => [
1058
+ 200,
1059
+ { data: [...api._groups.values()].filter((g) => g.location_id === lid).map((g) => ({ id: g.id, name: g.group_name, is_member: g.members.includes(uid) })) }
1060
+ ];
1061
+ this._on("GET", "/locations/{}/users/{}/group-membership", (_r, _b, lid, uid) => membership(lid, uid));
1062
+ this._on("PUT", "/locations/{}/users/{}/group-membership", (_r, body, lid, uid) => {
1063
+ for (const g of api._groups.values()) {
1064
+ if (g.location_id !== lid) continue;
1065
+ const want = body.group_ids.includes(g.id);
1066
+ if (want && !g.members.includes(uid)) g.members.push(uid);
1067
+ if (!want && g.members.includes(uid)) g.members.splice(g.members.indexOf(uid), 1);
1068
+ }
1069
+ return membership(lid, uid);
1070
+ });
1071
+ this._on("GET", "/locations/{}/first-alert/rules", (_r, _b, lid) => [200, page([...api._rules.values()].filter((r) => r.location_id === lid).map(({ triggers: _t, ...r }) => r), "first_alert_rule")]);
1072
+ this._on("POST", "/locations/{}/first-alert/rules", (_r, body, lid) => {
1073
+ const rid = newId();
1074
+ const { group_ids, ...rest } = body;
1075
+ api._rules.set(rid, { ...rest, id: rid, location_id: lid, groups: (group_ids ?? []).map((g) => ({ id: g })) });
1076
+ return [201, res("first_alert_rule", api._rules.get(rid))];
1077
+ });
1078
+ this._on("GET", "/locations/{}/first-alert/rules/{}", (_r, _b, _l, rid) => [200, res("first_alert_rule", get(api._rules, rid))]);
1079
+ this._on("PATCH", "/locations/{}/first-alert/rules/{}", (_r, body, _l, rid) => {
1080
+ const r = get(api._rules, rid);
1081
+ const { group_ids, ...rest } = body;
1082
+ if (group_ids) r.groups = group_ids.map((g) => ({ id: g }));
1083
+ Object.assign(r, rest);
1084
+ return [200, res("first_alert_rule", r)];
1085
+ });
1086
+ this._on("GET", "/locations/{}/connectors", (_r, _b, lid) => [200, page([...api._connectors.values()].filter((c) => c.location_id === lid).map(({ config: _c, ...c }) => c))]);
1087
+ this._on("POST", "/locations/{}/connectors", (_r, body, lid) => {
1088
+ const cid = newId();
1089
+ api._secretsSent.push({ ...body.config });
1090
+ const pub = Object.fromEntries(Object.entries(body.config).filter(([k]) => !SECRET_WORDS2.some((w) => k.toLowerCase().includes(w))));
1091
+ api._connectors.set(cid, { id: cid, location_id: lid, name: body.name, type: body.type, status: "connecting", _polls: 0, _outcome: api.connectorOutcome, config: { ...pub, unexpected_field: "redacted" } });
1092
+ return [202, { data: api._connectors.get(cid) }];
1093
+ });
1094
+ this._on("GET", "/locations/{}/connectors/{}", (_r, _b, _l, cid) => {
1095
+ const c = get(api._connectors, cid);
1096
+ c._polls++;
1097
+ const outcome = c._outcome ?? api.connectorOutcome;
1098
+ if (c.status === "connecting" && c._polls >= 2 && outcome !== "stuck" && outcome !== "connecting") {
1099
+ c.status = outcome;
1100
+ if (c.status === "error") {
1101
+ c.state_reason = "invalid_permissions";
1102
+ c.status_message = "The key was refused.";
1103
+ }
1104
+ }
1105
+ if (c.status === "deactivating") c.status = "inactive";
1106
+ return [200, { data: c }];
1107
+ });
1108
+ this._on("PATCH", "/locations/{}/connectors/{}", (_r, body, _l, cid) => {
1109
+ const c = get(api._connectors, cid);
1110
+ if ("name" in body) c.name = body.name;
1111
+ if ("config" in body) {
1112
+ api._secretsSent.push({ ...body.config });
1113
+ Object.assign(c.config, Object.fromEntries(Object.entries(body.config).filter(([k]) => !SECRET_WORDS2.some((w) => k.toLowerCase().includes(w)))));
1114
+ c._key = body.config.api_key;
1115
+ }
1116
+ return [200, { data: c }];
1117
+ });
1118
+ this._on("POST", "/locations/{}/connectors/{}/deactivate", (_r, _b, _l, cid) => {
1119
+ get(api._connectors, cid).status = "deactivating";
1120
+ return [202, { data: api._connectors.get(cid) }];
1121
+ });
1122
+ this._on("POST", "/locations/{}/connectors/{}/reactivate", (_r, _b, _l, cid) => {
1123
+ Object.assign(get(api._connectors, cid), { status: "connecting", _polls: 0, _outcome: api.connectorOutcome });
1124
+ return [202, { data: api._connectors.get(cid) }];
1125
+ });
1126
+ const emptySetup = () => ({ connector_mappings: [], group_access: [] });
1127
+ this._on("GET", "/locations/{}/insights-hub/setup", (_r, _b, lid) => [200, { data: { type: "insights_hub_setup", attributes: api._ihSetup.get(lid) ?? emptySetup() } }]);
1128
+ this._on("POST", "/locations/{}/insights-hub/setup", (_r, body, lid) => {
1129
+ api._ihSetup.set(lid, { connector_mappings: body.connector_mappings, group_access: body.group_access });
1130
+ return [201, { data: { type: "insights_hub_setup", attributes: api._ihSetup.get(lid) } }];
1131
+ });
1132
+ this._on("PATCH", "/locations/{}/insights-hub/setup", (_r, body, lid) => {
1133
+ api._ihSetup.set(lid, { ...api._ihSetup.get(lid) ?? emptySetup(), ...body });
1134
+ return [200, { data: { type: "insights_hub_setup", attributes: api._ihSetup.get(lid) } }];
1135
+ });
1136
+ const ihConfig = (lid) => [200, { data: { type: "insights_hub_config", attributes: { monitor_all_numbers: api._ihConfig.get(lid) ?? false } } }];
1137
+ this._on("GET", "/locations/{}/insights-hub/config", (_r, _b, lid) => ihConfig(lid));
1138
+ this._on("PATCH", "/locations/{}/insights-hub/config", (_r, body, lid) => {
1139
+ api._ihConfig.set(lid, body.monitor_all_numbers);
1140
+ return ihConfig(lid);
1141
+ });
1142
+ const faConfig = (lid) => [200, { data: api._faConfig.get(lid) ?? { webhook_url: null, connector_mappings: [] } }];
1143
+ this._on("GET", "/locations/{}/first-alert/config", (_r, _b, lid) => faConfig(lid));
1144
+ this._on("PUT", "/locations/{}/first-alert/config", (_r, body, lid) => {
1145
+ api._faConfig.set(lid, { webhook_url: body.webhook_url ?? null, connector_mappings: body.connector_mappings.map((m) => ({ ...m, id: newId() })) });
1146
+ return faConfig(lid);
1147
+ });
1148
+ this._on("GET", "/companies/{}/users", (req, _b, cid) => {
1149
+ const q = (req.query.get("search") ?? "").toLowerCase();
1150
+ const lid = req.query.get("location_id");
1151
+ return [200, page([...api._users.values()].filter((u) => u.company_id === cid && u.email.toLowerCase().includes(q) && (!lid || u._locations.includes(lid))).map((u) => api._userAttrs(u)), "company_user")];
1152
+ });
1153
+ this._on("POST", "/companies/{}/users", (req, body, cid) => {
1154
+ if (!req.headers.get("idempotency-key")) return [400, { error: { code: "VALIDATION_ERROR", message: "Idempotency-Key header is required" } }];
1155
+ if ([...api._users.values()].some((u) => u.email.toLowerCase() === String(body.email).toLowerCase())) return conflict("A user with this email already exists");
1156
+ const uid = newId();
1157
+ api._users.set(uid, { id: uid, company_id: cid, email: body.email, role: body.role, first_name: body.first_name, last_name: body.last_name, status: "invited", _locations: [...body.location_ids ?? []], _products: /* @__PURE__ */ new Map(), invited_at: null });
1158
+ if (body.send_invitation) {
1159
+ api._invitations.push(uid);
1160
+ api._users.get(uid).invited_at = api._tick();
1161
+ }
1162
+ return [201, { data: { type: "company_user", attributes: api._userAttrs(api._users.get(uid)) }, meta: { invitation_link: "https://app.example.com/accept?token=SECRET" } }];
1163
+ });
1164
+ const getUser = (uid) => [200, { data: { type: "company_user", attributes: api._userAttrs(get(api._users, uid)) } }];
1165
+ this._on("GET", "/companies/{}/users/{}", (_r, _b, _c, uid) => getUser(uid));
1166
+ this._on("PATCH", "/companies/{}/users/{}", (_r, body, _c, uid) => {
1167
+ const u = get(api._users, uid);
1168
+ if ("location_ids" in body) u._locations = [...body.location_ids];
1169
+ if ("department" in body) u.department = body.department;
1170
+ return getUser(uid);
1171
+ });
1172
+ this._on("POST", "/companies/{}/users/{}/deactivate", (_r, _b, _c, uid) => {
1173
+ const u = get(api._users, uid);
1174
+ if (u.status === "deactivated") return conflict("User is already deactivated");
1175
+ u.status = "deactivated";
1176
+ return getUser(uid);
1177
+ });
1178
+ this._on("POST", "/companies/{}/users/{}/resend-invitation", (_r, _b, _c, uid) => {
1179
+ const u = get(api._users, uid);
1180
+ if (u.status !== "invited") return conflict("User does not have a pending invitation");
1181
+ api._invitations.push(uid);
1182
+ u.invited_at = api._tick();
1183
+ return [202, { data: { type: "invitation_resend", attributes: { user_id: uid, email: u.email } } }];
1184
+ });
1185
+ this._on("POST", "/companies/{}/users/{}/reactivate", (_r, _b, _c, uid) => {
1186
+ get(api._users, uid).status = "active";
1187
+ return getUser(uid);
1188
+ });
1189
+ this._on("GET", "/companies/{}/users/{}/connector-mappings", (_r, _b, _c, uid) => [200, { data: api._mappings.get(uid) ?? [] }]);
1190
+ this._on("PUT", "/companies/{}/users/{}/connector-mappings", (_r, body, _c, uid) => {
1191
+ for (const m of body.mappings) {
1192
+ if (!["active", "connected"].includes(api._connectors.get(m.connector_id)?.status)) {
1193
+ return [422, { error: { code: "VALIDATION_ERROR", message: "connector not found or inactive" } }];
1194
+ }
1195
+ }
1196
+ for (const m of body.mappings) {
1197
+ const lid = api._connectors.get(m.connector_id).location_id;
1198
+ for (const [other, maps] of api._mappings) {
1199
+ if (other === uid) continue;
1200
+ for (const om of maps) {
1201
+ const olid = api._connectors.get(om.connector_id)?.location_id;
1202
+ const clash = om.monitored_numbers.filter((n) => m.monitored_numbers.includes(n)).sort();
1203
+ if (olid !== lid && clash.length) return conflict(`Extension ${clash[0]} is monitored at another location`);
1204
+ }
1205
+ }
1206
+ }
1207
+ api._mappings.set(uid, body.mappings);
1208
+ return [200, { data: body.mappings }];
1209
+ });
1210
+ this._on("GET", "/locations/{}/users", (_r, _b, lid) => [200, page(api._locationUsers(lid).map((u) => api._locUser(u, lid)), "location_user")]);
1211
+ this._on("GET", "/locations/{}/users/{}", (_r, _b, lid, uid) => [200, { data: { type: "location_user", attributes: api._locUser(get(api._users, uid), lid) } }]);
1212
+ this._on("POST", "/locations/{}/users/{}/products/{}/enable", (_r, _b, lid, uid, key) => {
1213
+ api.products(uid, lid).add(key);
1214
+ return [200, { data: { product_key: key, enabled: true } }];
1215
+ });
1216
+ this._on("POST", "/locations/{}/users/{}/products/{}/disable", (_r, _b, lid, uid, key) => {
1217
+ api.products(uid, lid).delete(key);
1218
+ return [200, { data: { product_key: key, enabled: false } }];
1219
+ });
1220
+ this._on("PUT", "/locations/{}/users/{}/first-alert/email-preferences", (_r, body, lid, uid) => {
1221
+ api._emailPrefs.set(`${lid}:${uid}`, body);
1222
+ return [200, { emailNotifications: { masterEnabled: body.masterEnabled, alerts: [] } }];
1223
+ });
1224
+ this._on("GET", "/locations/{}/users/{}/first-alert/notification-preferences", (_r, _b, lid, uid) => {
1225
+ const master = api._emailPrefs.get(`${lid}:${uid}`)?.masterEnabled ?? true;
1226
+ const alerts = [...api._rules.values()].filter((r) => r.location_id === lid).map((r) => ({ alertId: r.id, alertName: r.name, emailEnabled: master }));
1227
+ return [200, { emailNotifications: { masterEnabled: master, alerts }, digest: { enabled: false }, webhook: { url: null } }];
1228
+ });
1229
+ this._on("GET", "/locations", () => {
1230
+ const viewer = api._viewer();
1231
+ if (viewer) return [200, page(viewer._locations.filter((l) => api._locations.has(l)).map((l) => ({ id: l, location_name: api._locations.get(l).location_name })), "location")];
1232
+ return [200, page(api._visibleLocations, "location")];
1233
+ });
1234
+ this._on("GET", "/calls", (req) => {
1235
+ if (api._requestRole !== "frontline_user") return api._paged(req, [], "calls", { total_calls: 0, missed_calls: 0 });
1236
+ const lid = req.query.get("location_id");
1237
+ const q = req.query.get("search");
1238
+ const rows = api._callRows.filter((r) => api._inScope(r) && (!lid || lid.split(",").includes(r.location_id)) && (!q || ((r.caller_number ?? "") + (r.summary ?? "")).includes(q)));
1239
+ return api._paged(req, rows, "calls", { total_calls: rows.length, missed_calls: 0 });
1240
+ });
1241
+ this._on("GET", "/calls/{}", (_r, _b, cid) => api._callDetails.has(cid) && api._inScope(api._callDetails.get(cid)) ? [200, { data: api._callDetails.get(cid) }] : [404, { error: { code: "NOT_FOUND", message: "not found" } }]);
1242
+ this._on("GET", "/calls/{}/transcript", () => [200, { data: { transcript: [{ time: 0, speaker: "Speaker 1", name: "Sam", text: "Hello" }] } }]);
1243
+ this._on("GET", "/alerts", (req) => {
1244
+ if (api._requestRole !== "frontline_user") return api._paged(req, [], "alerts", { total: 0 });
1245
+ const q = (req.query.get("search") ?? "").toLowerCase();
1246
+ const fields = ["caller_name", "caller_number", "callee_name", "callee_number", "summary"];
1247
+ const rows = api._alertRows.filter((a) => api._alertInScope(a) && (!q || a.id === q || fields.some((f) => String(a[f] ?? "").toLowerCase().includes(q))));
1248
+ return api._paged(req, rows, "alerts", { total: rows.length });
1249
+ });
1250
+ this._on("GET", "/tasks", (req) => {
1251
+ if (api._requestRole !== "frontline_user") return [200, { data: [], meta: { has_more: false, next_cursor: null } }];
1252
+ const open = req.query.get("status") === "open";
1253
+ return [200, { data: api._taskRows.filter((t) => (!open || ["pending", "in_progress", "overdue"].includes(t.status)) && api._inScope(api._callDetails.get(t.call_id) ?? { location_id: t.location_id })), meta: { has_more: false, next_cursor: null } }];
1254
+ });
1255
+ this._on("GET", "/insights/dashboard", () => {
1256
+ const viewer = api._viewer();
1257
+ if (viewer && ![...viewer._products.values()].some((p) => p.has("insights-hub"))) return [403, { error: { code: "FORBIDDEN", message: "Insights Hub access is needed" } }];
1258
+ return [200, { data: api._insights }];
1259
+ });
1260
+ }
1261
+ };
1262
+
1263
+ export { CONNECTOR_OUTCOMES, FakeAPI, NETWORK_FAILURES, RESELLER, SIGN_IN_OUTCOMES, VERTICAL, newId };