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