@intelligence-cloud/sdk 0.2.0 → 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.
- package/CHANGELOG.md +47 -0
- package/README.md +290 -48
- package/dist/index.cjs +1610 -871
- package/dist/index.d.cts +682 -5128
- package/dist/index.d.ts +682 -5128
- package/dist/index.js +1608 -872
- package/dist/testing.cjs +1271 -0
- package/dist/testing.d.cts +209 -0
- package/dist/testing.d.ts +209 -0
- package/dist/testing.js +1263 -0
- package/package.json +19 -2
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/generated/spec.ts
|
|
4
|
-
var OPERATIONS = { "login": { "method": "POST", "path": "/auth/login", "tag": "Authentication", "role": "frontline_user", "query": [], "pathParams": [], "headers": [], "hasBody": true, "bodyRequired": true, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "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, "response": { "o": { "data": { "o": { "success": "v", "http_status": "v", "response_time_ms": "v" } } } }, "summary": "Send a test After Call event" } };
|
|
4
|
+
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" } };
|
|
5
5
|
var WEBHOOK_SHAPES = { "afterCallSummary": { "o": { "version": "v", "type": "v", "is_test": "v", "location_id": "v", "timestamp": "v", "call": { "o": { "id": "v", "caller_name": "v", "caller_number": "v", "callee_name": "v", "callee_number": "v", "call_type": "v", "duration_seconds": "v", "call_date": "v", "platform": "v" } }, "summary": { "o": { "text": "v", "sentiment": "v", "key_points": { "a": "v" }, "action_items": { "a": "v" } } }, "location": { "o": { "id": "v", "company_id": "v", "connector_id": "v" } } } }};
|
|
6
6
|
|
|
7
7
|
// src/errors.ts
|
|
8
|
+
var brandOf = (name) => /* @__PURE__ */ Symbol.for(`intelligence-cloud.error.${name}`);
|
|
8
9
|
var IntelligenceCloudError = class extends Error {
|
|
10
|
+
static [Symbol.hasInstance](value) {
|
|
11
|
+
if (value === null || typeof value !== "object") return false;
|
|
12
|
+
if (value[brandOf(this.name)] === true) return true;
|
|
13
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
14
|
+
}
|
|
9
15
|
constructor(message, options) {
|
|
10
16
|
super(message, options);
|
|
11
17
|
this.name = new.target.name;
|
|
@@ -45,6 +51,18 @@ var PasswordExpiredError = class extends AuthError {
|
|
|
45
51
|
super(200, "password_expired", "The password has expired. Change it in the app, then sign in again.");
|
|
46
52
|
}
|
|
47
53
|
};
|
|
54
|
+
var NetworkError = class extends ApiError {
|
|
55
|
+
kind;
|
|
56
|
+
requestSent;
|
|
57
|
+
constructor(kind, detail, requestSent = true) {
|
|
58
|
+
const code = kind === "timeout" ? "timeout" : "network_error";
|
|
59
|
+
super(0, code, apiErrorText(0, code, null, `the request did not complete (${detail})`), {
|
|
60
|
+
serverMessage: "The request did not complete."
|
|
61
|
+
});
|
|
62
|
+
this.kind = kind;
|
|
63
|
+
this.requestSent = requestSent;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
48
66
|
var NotFoundError = class extends ApiError {
|
|
49
67
|
};
|
|
50
68
|
var ConflictError = class extends ApiError {
|
|
@@ -85,24 +103,13 @@ var ConnectorError = class extends IntelligenceCloudError {
|
|
|
85
103
|
this.statusMessage = typeof c.status_message === "string" ? c.status_message : null;
|
|
86
104
|
}
|
|
87
105
|
};
|
|
88
|
-
var ConnectorTimeoutError = class extends
|
|
89
|
-
|
|
90
|
-
status;
|
|
106
|
+
var ConnectorTimeoutError = class extends ConnectorError {
|
|
107
|
+
waited;
|
|
91
108
|
constructor(connector, waitedSeconds) {
|
|
109
|
+
super(connector);
|
|
92
110
|
const c = connector ?? {};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.connector = connector;
|
|
96
|
-
this.status = status;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var FrontlineRequiredError = class extends IntelligenceCloudError {
|
|
100
|
-
role;
|
|
101
|
-
constructor(role) {
|
|
102
|
-
super(
|
|
103
|
-
`This login has role "${role ?? "unknown"}". Conversation data endpoints return empty lists to admin logins: sign in with a frontline integration user.`
|
|
104
|
-
);
|
|
105
|
-
this.role = role;
|
|
111
|
+
this.message = `Connector ${typeof c.id === "string" ? c.id : "unknown"} still "${this.status ?? "unknown"}" after ${Math.round(waitedSeconds)} s`;
|
|
112
|
+
this.waited = waitedSeconds;
|
|
106
113
|
}
|
|
107
114
|
};
|
|
108
115
|
var AccountError = class extends IntelligenceCloudError {
|
|
@@ -114,6 +121,21 @@ var AccountError = class extends IntelligenceCloudError {
|
|
|
114
121
|
this.step = step;
|
|
115
122
|
this.result = result;
|
|
116
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* The first error of `type` in the cause chain (`cause`, its `cause` ...), or undefined. A line another
|
|
126
|
+
* location holds arrives as AccountError, then ExtensionMappingError, then ConflictError:
|
|
127
|
+
* `err.find(ConflictError)` returns the ConflictError.
|
|
128
|
+
*/
|
|
129
|
+
find(type) {
|
|
130
|
+
const seen = /* @__PURE__ */ new Set();
|
|
131
|
+
let err = this.cause;
|
|
132
|
+
while (err !== void 0 && err !== null && !seen.has(err)) {
|
|
133
|
+
seen.add(err);
|
|
134
|
+
if (err instanceof type) return err;
|
|
135
|
+
err = typeof err === "object" ? err.cause : void 0;
|
|
136
|
+
}
|
|
137
|
+
return void 0;
|
|
138
|
+
}
|
|
117
139
|
};
|
|
118
140
|
var WrongLoginError = class extends IntelligenceCloudError {
|
|
119
141
|
role;
|
|
@@ -126,6 +148,12 @@ var WrongLoginError = class extends IntelligenceCloudError {
|
|
|
126
148
|
this.needed = needed;
|
|
127
149
|
}
|
|
128
150
|
};
|
|
151
|
+
var FrontlineRequiredError = class extends WrongLoginError {
|
|
152
|
+
constructor(role) {
|
|
153
|
+
super(role, "user");
|
|
154
|
+
this.message = `This login has role "${role ?? "unknown"}". Conversation data (calls, alerts, tasks, insights) needs a frontline_user login; admin logins get empty lists.`;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
129
157
|
var ExtensionMappingError = class extends IntelligenceCloudError {
|
|
130
158
|
userId;
|
|
131
159
|
constructor(userId, cause) {
|
|
@@ -141,6 +169,29 @@ var WebhookPayloadError = class extends IntelligenceCloudError {
|
|
|
141
169
|
var PayloadTooLargeError = class extends WebhookPayloadError {
|
|
142
170
|
};
|
|
143
171
|
var EXTENSION_CONFLICT_MESSAGE = "Extension is already monitored at another location.";
|
|
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
|
+
}
|
|
144
195
|
|
|
145
196
|
// src/filters.ts
|
|
146
197
|
var RFC3339 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/i;
|
|
@@ -271,6 +322,100 @@ function buildQuery(operationId, rules, options) {
|
|
|
271
322
|
return out;
|
|
272
323
|
}
|
|
273
324
|
|
|
325
|
+
// src/util.ts
|
|
326
|
+
async function uuid4() {
|
|
327
|
+
const c = globalThis.crypto;
|
|
328
|
+
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
329
|
+
let bytes;
|
|
330
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
331
|
+
bytes = c.getRandomValues(new Uint8Array(16));
|
|
332
|
+
} else {
|
|
333
|
+
const nodeCrypto = await import('crypto');
|
|
334
|
+
bytes = new Uint8Array(nodeCrypto.randomBytes(16));
|
|
335
|
+
}
|
|
336
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
337
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
338
|
+
const h = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
339
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
340
|
+
}
|
|
341
|
+
function numbersFor(mappings, connectorId) {
|
|
342
|
+
const out = [];
|
|
343
|
+
for (const m of mappings ?? []) if (m.connector_id === connectorId) out.push(...m.monitored_numbers ?? []);
|
|
344
|
+
return [...new Set(out)];
|
|
345
|
+
}
|
|
346
|
+
function mergeMappings(current, connectorId, add = [], remove = []) {
|
|
347
|
+
const byConnector = /* @__PURE__ */ new Map();
|
|
348
|
+
for (const m of current ?? []) {
|
|
349
|
+
if (!m.connector_id) continue;
|
|
350
|
+
const list3 = byConnector.get(m.connector_id) ?? [];
|
|
351
|
+
list3.push(...m.monitored_numbers ?? []);
|
|
352
|
+
byConnector.set(m.connector_id, list3);
|
|
353
|
+
}
|
|
354
|
+
const drop = new Set(remove);
|
|
355
|
+
const mine = (byConnector.get(connectorId) ?? []).filter((n) => !drop.has(n));
|
|
356
|
+
for (const n of add) if (!mine.includes(n)) mine.push(n);
|
|
357
|
+
byConnector.set(connectorId, mine);
|
|
358
|
+
const out = [];
|
|
359
|
+
for (const [connector_id, nums] of byConnector) {
|
|
360
|
+
const uniq3 = [...new Set(nums)];
|
|
361
|
+
if (uniq3.length) out.push({ connector_id, monitored_numbers: uniq3 });
|
|
362
|
+
}
|
|
363
|
+
return out;
|
|
364
|
+
}
|
|
365
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
366
|
+
function isUuid(value) {
|
|
367
|
+
return typeof value === "string" && UUID_RE.test(value);
|
|
368
|
+
}
|
|
369
|
+
function pathArg(value, name = "id") {
|
|
370
|
+
if (typeof value !== "string" || value === "" || value === "." || value === ".." || [...value].length > 128 || // code points, not UTF-16 units
|
|
371
|
+
/[\/\\?#%\s\u0000-\u001f\u007f-\u009f\ufeff]/.test(value)) {
|
|
372
|
+
throw new InvalidRequestError(`${name}: an id of at most 128 characters without "/", "?", "#", "%", whitespace (also at the ends: nothing is trimmed), control characters, and not "." or ".."`);
|
|
373
|
+
}
|
|
374
|
+
return value;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/bodycheck.ts
|
|
378
|
+
var typeOk = (t, v) => {
|
|
379
|
+
switch (t) {
|
|
380
|
+
case "string":
|
|
381
|
+
return typeof v === "string";
|
|
382
|
+
case "integer":
|
|
383
|
+
return typeof v === "number" && Number.isInteger(v);
|
|
384
|
+
case "number":
|
|
385
|
+
return typeof v === "number" && Number.isFinite(v);
|
|
386
|
+
case "boolean":
|
|
387
|
+
return typeof v === "boolean";
|
|
388
|
+
case "array":
|
|
389
|
+
return Array.isArray(v);
|
|
390
|
+
case "object":
|
|
391
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
392
|
+
default:
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
function problem(rule, value, items = false) {
|
|
397
|
+
if (!rule) return null;
|
|
398
|
+
const types = rule.type === void 0 ? [] : typeof rule.type === "string" ? [rule.type] : [...rule.type];
|
|
399
|
+
if (value === null) return !types.length || types.includes("null") ? null : "must not be null";
|
|
400
|
+
if (types.length && !types.some((t) => t !== "null" && typeOk(t, value))) return `must be ${types.filter((t) => t !== "null").join(" or ")}`;
|
|
401
|
+
if (items && Array.isArray(value) && rule.items) {
|
|
402
|
+
for (const v of value) {
|
|
403
|
+
const p = problem(rule.items, v);
|
|
404
|
+
if (p) return `an item ${p}`;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
function checkBody(operationId, rule, body) {
|
|
410
|
+
if (!rule || body === void 0 || body === null) return;
|
|
411
|
+
if (typeof body !== "object" || Array.isArray(body)) throw new InvalidRequestError(`${operationId}: the body must be an object`);
|
|
412
|
+
for (const [name, value] of Object.entries(body)) {
|
|
413
|
+
if (value === void 0) continue;
|
|
414
|
+
const p = problem(rule.properties[name], value, true);
|
|
415
|
+
if (p) throw new InvalidRequestError(`${operationId}: ${name} ${p}`);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
274
419
|
// src/projection.ts
|
|
275
420
|
function project(value, shape) {
|
|
276
421
|
if (shape === null || shape === void 0 || shape === "*") return value;
|
|
@@ -405,10 +550,45 @@ var FileTokenStore = class {
|
|
|
405
550
|
|
|
406
551
|
// src/core.ts
|
|
407
552
|
var DEFAULT_BASE_URL = "https://app.intelligence.cloud/api/v1";
|
|
408
|
-
var SDK_VERSION = "0.
|
|
553
|
+
var SDK_VERSION = "0.3.0";
|
|
409
554
|
var SUPPRESS_ERROR_TEXT = /* @__PURE__ */ new Set(["testConnector", "testAfterCallWebhook", "testFirstAlertWebhook"]);
|
|
410
555
|
var NUMBER_MAPPING_OPS = /* @__PURE__ */ new Set(["setUserNumberMappings", "updateUserAfterCallSettings"]);
|
|
411
556
|
var LOGIN_RATE_LIMIT_WAIT_S = 60;
|
|
557
|
+
var DEFAULT_DEADLINE_S = 120;
|
|
558
|
+
var RETRY_METHODS = /* @__PURE__ */ new Set(["GET", "PUT", "PATCH", "DELETE"]);
|
|
559
|
+
var NOT_SENT_ERRNO = /* @__PURE__ */ new Set(["ENOTFOUND", "EAI_AGAIN", "EAI_FAIL", "EAI_NODATA", "ECONNREFUSED", "ENETUNREACH", "EHOSTUNREACH", "ETIMEDOUT"]);
|
|
560
|
+
var NOT_SENT_ALWAYS = /* @__PURE__ */ new Set([
|
|
561
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
562
|
+
"ERR_INVALID_URL",
|
|
563
|
+
"ERR_INVALID_PROTOCOL",
|
|
564
|
+
"ERR_UNSUPPORTED_PROTOCOL",
|
|
565
|
+
"CERT_HAS_EXPIRED",
|
|
566
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
567
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
568
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
569
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
570
|
+
"ERR_TLS_CERT_ALTNAME_INVALID",
|
|
571
|
+
"CERT_NOT_YET_VALID"
|
|
572
|
+
]);
|
|
573
|
+
var TIMEOUT_CODES = /* @__PURE__ */ new Set(["UND_ERR_CONNECT_TIMEOUT", "UND_ERR_HEADERS_TIMEOUT", "UND_ERR_BODY_TIMEOUT", "ETIMEDOUT"]);
|
|
574
|
+
function failureEntries(err, out = [], depth = 0) {
|
|
575
|
+
if (!err || typeof err !== "object" || depth > 6) return out;
|
|
576
|
+
const e = err;
|
|
577
|
+
const children = Array.isArray(e.errors) && e.errors.length > 0;
|
|
578
|
+
if (typeof e.code === "string" && !children) out.push({ code: e.code, syscall: typeof e.syscall === "string" ? e.syscall : void 0 });
|
|
579
|
+
if (children) for (const x of e.errors) failureEntries(x, out, depth + 1);
|
|
580
|
+
if (e.cause) failureEntries(e.cause, out, depth + 1);
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
var neverLeft = (f) => NOT_SENT_ALWAYS.has(f.code) || NOT_SENT_ERRNO.has(f.code) && (f.syscall === "connect" || f.syscall === "getaddrinfo");
|
|
584
|
+
function classifyFetchFailure(err, aborted = false) {
|
|
585
|
+
const entries = failureEntries(err);
|
|
586
|
+
const codes = entries.map((f) => f.code);
|
|
587
|
+
const name = err && typeof err === "object" ? String(err.name ?? "Error") : "Error";
|
|
588
|
+
const timeout = aborted || name === "AbortError" || name === "TimeoutError" || codes.some((c) => TIMEOUT_CODES.has(c));
|
|
589
|
+
const sent = !(entries.length > 0 && entries.every(neverLeft));
|
|
590
|
+
return { kind: timeout ? "timeout" : "transport", sent, detail: codes[0] ?? (aborted ? "timed out" : name) };
|
|
591
|
+
}
|
|
412
592
|
var RENEW_MARGIN_MS = 3e4;
|
|
413
593
|
var MAX_RETRY_AFTER_MS = 6e4;
|
|
414
594
|
var ALWAYS_PROJECT = /* @__PURE__ */ new Set([
|
|
@@ -451,6 +631,9 @@ var Core = class {
|
|
|
451
631
|
random;
|
|
452
632
|
now;
|
|
453
633
|
renewing = null;
|
|
634
|
+
clock;
|
|
635
|
+
deadlineMs;
|
|
636
|
+
spentRefresh = /* @__PURE__ */ new Set();
|
|
454
637
|
/** Write requests (anything but GET) attempted by this client. Account helpers use it to tell a clean stop from a partial one. */
|
|
455
638
|
writes = 0;
|
|
456
639
|
constructor(opts) {
|
|
@@ -461,7 +644,13 @@ var Core = class {
|
|
|
461
644
|
this.email = opts.email;
|
|
462
645
|
this.password = opts.password;
|
|
463
646
|
this.store = opts.tokenStore ?? new MemoryTokenStore();
|
|
464
|
-
|
|
647
|
+
const timeout = opts.timeout ?? 30;
|
|
648
|
+
const deadline = opts.deadline ?? DEFAULT_DEADLINE_S;
|
|
649
|
+
if (typeof timeout !== "number" || !(timeout > 0)) throw new InvalidRequestError("timeout: a number of seconds above 0");
|
|
650
|
+
if (typeof deadline !== "number" || !(deadline > 0)) throw new InvalidRequestError("deadline: a number of seconds above 0");
|
|
651
|
+
this.timeoutMs = timeout * 1e3;
|
|
652
|
+
this.deadlineMs = deadline * 1e3;
|
|
653
|
+
this.clock = opts.clock ?? (() => performance.now());
|
|
465
654
|
this.maxRetries = opts.maxRetries ?? 3;
|
|
466
655
|
this.loginWaitS = opts.loginRateLimitWait ?? LOGIN_RATE_LIMIT_WAIT_S;
|
|
467
656
|
this.keepUnknown = opts.keepUnknownFields ?? false;
|
|
@@ -479,13 +668,15 @@ var Core = class {
|
|
|
479
668
|
const op = OPERATIONS[operationId];
|
|
480
669
|
const query = buildQuery(operationId, op.query, opts.query ?? {});
|
|
481
670
|
const url = this.url(op, pathArgs, query);
|
|
671
|
+
if (op.hasBody) checkBody(operationId, op.body, opts.body);
|
|
482
672
|
if (op.method !== "GET") this.writes++;
|
|
483
673
|
const res = await this.send(op.method, url, {
|
|
484
674
|
body: op.hasBody ? opts.body ?? {} : void 0,
|
|
485
675
|
headers: opts.headers,
|
|
486
676
|
idempotencyKey: opts.idempotencyKey,
|
|
487
677
|
auth: true,
|
|
488
|
-
operationId
|
|
678
|
+
operationId,
|
|
679
|
+
budget: this.newBudget()
|
|
489
680
|
});
|
|
490
681
|
if (res.status < 200 || res.status >= 300) throw this.toError(res, operationId, op.hasBody ? opts.body : void 0);
|
|
491
682
|
if (res.status === 204 || res.text === "") return void 0;
|
|
@@ -527,7 +718,7 @@ var Core = class {
|
|
|
527
718
|
async logout() {
|
|
528
719
|
const t = await this.store.get();
|
|
529
720
|
if (t && t.accessToken) {
|
|
530
|
-
const res = await this.send("POST", `${this.baseUrl}/auth/logout`, { auth: true, operationId: "logout", body: {} });
|
|
721
|
+
const res = await this.send("POST", `${this.baseUrl}/auth/logout`, { auth: true, operationId: "logout", body: {}, budget: this.newBudget() });
|
|
531
722
|
if (res.status >= 300 && res.status !== 401) throw this.toError(res, "logout");
|
|
532
723
|
}
|
|
533
724
|
await this.store.set(null);
|
|
@@ -536,11 +727,31 @@ var Core = class {
|
|
|
536
727
|
async close() {
|
|
537
728
|
await this.store.set(null);
|
|
538
729
|
}
|
|
730
|
+
// -------------------------------------------------------------- the deadline
|
|
731
|
+
newBudget() {
|
|
732
|
+
return { at: this.clock() + this.deadlineMs };
|
|
733
|
+
}
|
|
734
|
+
remainingS(b) {
|
|
735
|
+
return (b.at - this.clock()) / 1e3;
|
|
736
|
+
}
|
|
737
|
+
/** Sleep `seconds` if the deadline leaves room; otherwise return false without sleeping. */
|
|
738
|
+
async wait(b, seconds) {
|
|
739
|
+
if (seconds > this.remainingS(b)) return false;
|
|
740
|
+
await this.sleep(seconds * 1e3);
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
/** Seconds to wait before the next try, or null when Retry-After asks for more than 60 seconds. */
|
|
744
|
+
backoff(attempt, retryAfter) {
|
|
745
|
+
const w = parseRetryAfter(retryAfter);
|
|
746
|
+
if (w !== null) return w > MAX_RETRY_AFTER_MS / 1e3 ? null : w;
|
|
747
|
+
const base = Math.min(8, 0.5 * 2 ** attempt);
|
|
748
|
+
return base + this.random() * (base / 2);
|
|
749
|
+
}
|
|
539
750
|
// -------------------------------------------------------------- auth
|
|
540
|
-
async accessToken() {
|
|
751
|
+
async accessToken(b) {
|
|
541
752
|
const t = await this.store.get();
|
|
542
|
-
if (!t || !t.accessToken) return (await this.renew(null)).accessToken;
|
|
543
|
-
if (t.expiresAt - this.now() < RENEW_MARGIN_MS) return (await this.renew(t.accessToken)).accessToken;
|
|
753
|
+
if (!t || !t.accessToken) return (await this.renew(null, b)).accessToken;
|
|
754
|
+
if (t.expiresAt - this.now() < RENEW_MARGIN_MS) return (await this.renew(t.accessToken, b)).accessToken;
|
|
544
755
|
return t.accessToken;
|
|
545
756
|
}
|
|
546
757
|
/**
|
|
@@ -548,26 +759,26 @@ var Core = class {
|
|
|
548
759
|
* `failed` is the access token that was rejected (null = none yet); if another caller has
|
|
549
760
|
* already replaced it, the new tokens are reused.
|
|
550
761
|
*/
|
|
551
|
-
renew(failed) {
|
|
762
|
+
renew(failed, b) {
|
|
552
763
|
if (this.renewing) return this.renewing;
|
|
553
764
|
const work = async () => {
|
|
554
765
|
const cur = await this.store.get();
|
|
555
766
|
if (cur && cur.accessToken && cur.accessToken !== failed && cur.expiresAt - this.now() >= RENEW_MARGIN_MS) {
|
|
556
767
|
return cur;
|
|
557
768
|
}
|
|
558
|
-
if (cur && cur.refreshToken) {
|
|
769
|
+
if (cur && cur.refreshToken && !this.spentRefresh.has(cur.refreshToken)) {
|
|
559
770
|
const spent = cur.refreshToken;
|
|
560
771
|
await this.store.set({ ...cur, refreshToken: "" });
|
|
561
772
|
let fresh;
|
|
562
773
|
try {
|
|
563
|
-
fresh = await this.refreshWith(spent);
|
|
774
|
+
fresh = await this.refreshWith(spent, b);
|
|
564
775
|
} catch (err) {
|
|
565
776
|
if (err instanceof RateLimitError) await this.store.set(cur);
|
|
566
777
|
throw err;
|
|
567
778
|
}
|
|
568
779
|
if (fresh) return fresh;
|
|
569
780
|
}
|
|
570
|
-
return await this.login();
|
|
781
|
+
return await this.login(b);
|
|
571
782
|
};
|
|
572
783
|
this.renewing = (async () => {
|
|
573
784
|
try {
|
|
@@ -579,48 +790,70 @@ var Core = class {
|
|
|
579
790
|
return this.renewing;
|
|
580
791
|
}
|
|
581
792
|
/**
|
|
582
|
-
* Swap a refresh token for a new pair.
|
|
583
|
-
*
|
|
584
|
-
*
|
|
793
|
+
* Swap a refresh token for a new pair. A refresh token is used once, and sending a used one ends every
|
|
794
|
+
* session of the login. It is sent again only after a 429 (the server did not use it) or after a
|
|
795
|
+
* failure where the request provably never left this machine. After a 5xx, a failure after the
|
|
796
|
+
* request left, or an unreadable answer it is never sent again: this returns null and the caller
|
|
797
|
+
* signs in instead.
|
|
585
798
|
*/
|
|
586
|
-
async refreshWith(refreshToken) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
799
|
+
async refreshWith(refreshToken, b) {
|
|
800
|
+
let attempt = 0;
|
|
801
|
+
let res;
|
|
802
|
+
for (; ; ) {
|
|
803
|
+
try {
|
|
804
|
+
res = await this.send("POST", `${this.baseUrl}/auth/refresh`, {
|
|
805
|
+
body: { refresh_token: refreshToken },
|
|
806
|
+
auth: false,
|
|
807
|
+
operationId: "refresh",
|
|
808
|
+
budget: b,
|
|
809
|
+
retry429: false,
|
|
810
|
+
retryFailures: true,
|
|
811
|
+
onlyUnsent: true
|
|
812
|
+
});
|
|
813
|
+
} catch (err) {
|
|
814
|
+
if (!(err instanceof NetworkError)) throw err;
|
|
815
|
+
res = null;
|
|
599
816
|
}
|
|
600
|
-
if (res.status !==
|
|
601
|
-
|
|
817
|
+
if (res === null || res.status !== 429) break;
|
|
818
|
+
const wait = this.backoff(attempt, res.headers.get("retry-after"));
|
|
819
|
+
if (attempt >= this.maxRetries || wait === null || !await this.wait(b, wait)) throw this.toError(res, "refresh");
|
|
820
|
+
attempt++;
|
|
821
|
+
}
|
|
822
|
+
this.spentRefresh.add(refreshToken);
|
|
823
|
+
if (res && res.status === 200) {
|
|
824
|
+
const j = res.json;
|
|
825
|
+
if (j && typeof j.access_token === "string" && typeof j.refresh_token === "string") return this.saveTokens(j);
|
|
602
826
|
}
|
|
827
|
+
return null;
|
|
603
828
|
}
|
|
604
|
-
async login() {
|
|
829
|
+
async login(b) {
|
|
605
830
|
let waited = false;
|
|
831
|
+
let res;
|
|
606
832
|
for (; ; ) {
|
|
607
|
-
|
|
833
|
+
res = await this.send("POST", `${this.baseUrl}/auth/login`, {
|
|
608
834
|
body: { email: this.email, password: this.password },
|
|
609
835
|
auth: false,
|
|
610
836
|
operationId: "login",
|
|
611
|
-
|
|
837
|
+
budget: b,
|
|
838
|
+
retry429: false,
|
|
839
|
+
retryFailures: true,
|
|
840
|
+
networkUnsentOnly: true
|
|
612
841
|
});
|
|
613
842
|
if (res.status === 429 && !waited && this.loginWaitS > 0) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
843
|
+
const ra = retryAfterMs(res.headers);
|
|
844
|
+
if (ra === null || ra / 1e3 <= this.loginWaitS) {
|
|
845
|
+
waited = true;
|
|
846
|
+
if (!await this.wait(b, ra !== null ? ra / 1e3 : this.loginWaitS)) break;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
617
849
|
}
|
|
618
|
-
|
|
619
|
-
const body = res.json;
|
|
620
|
-
if (body && body.status === "mfa_required") throw new MfaRequiredError();
|
|
621
|
-
if (body && body.password_expired === true) throw new PasswordExpiredError();
|
|
622
|
-
return this.saveTokens(body);
|
|
850
|
+
break;
|
|
623
851
|
}
|
|
852
|
+
if (res.status !== 200) throw this.toError(res, "login");
|
|
853
|
+
const body = res.json;
|
|
854
|
+
if (body && body.status === "mfa_required") throw new MfaRequiredError();
|
|
855
|
+
if (body && body.password_expired === true) throw new PasswordExpiredError();
|
|
856
|
+
return this.saveTokens(body);
|
|
624
857
|
}
|
|
625
858
|
async saveTokens(body) {
|
|
626
859
|
const b = body ?? {};
|
|
@@ -639,19 +872,25 @@ var Core = class {
|
|
|
639
872
|
url(op, pathArgs, query) {
|
|
640
873
|
let i = 0;
|
|
641
874
|
const path = op.path.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
642
|
-
|
|
643
|
-
if (typeof v !== "string" || v.trim() === "") {
|
|
644
|
-
throw new TypeError(`Missing path parameter "${name}".`);
|
|
645
|
-
}
|
|
646
|
-
return encodeURIComponent(v);
|
|
875
|
+
return encodeURIComponent(pathArg(pathArgs[i++], `path parameter "${name}"`));
|
|
647
876
|
});
|
|
648
877
|
const qs = new URLSearchParams(query).toString();
|
|
649
878
|
return `${this.baseUrl}${path}${qs ? `?${qs}` : ""}`;
|
|
650
879
|
}
|
|
880
|
+
/**
|
|
881
|
+
* Send with the retry policy (README "Retries"). Network failures and 5xx are retried up to
|
|
882
|
+
* `maxRetries` with backoff for idempotent requests (reads, updates, deletes, user create with its
|
|
883
|
+
* idempotency key) and for sign-in and token renewal (`retryFailures`; renewal retries a network
|
|
884
|
+
* failure only when the request never left, `onlyUnsent`, so a refresh token is never sent twice).
|
|
885
|
+
* 429 honours Retry-After up to 60 seconds; a longer one is returned at once. The deadline caps the
|
|
886
|
+
* whole call, sign-in and renewal included.
|
|
887
|
+
*/
|
|
651
888
|
async send(method, url, o) {
|
|
889
|
+
let idempotent = RETRY_METHODS.has(method) || Boolean(o.idempotencyKey);
|
|
890
|
+
if (o.retryFailures !== void 0) idempotent = o.retryFailures;
|
|
891
|
+
const retry429 = o.retry429 ?? true;
|
|
652
892
|
let attempt = 0;
|
|
653
|
-
let
|
|
654
|
-
const safeToRepeat = method !== "POST" || Boolean(o.idempotencyKey);
|
|
893
|
+
let refreshed = false;
|
|
655
894
|
for (; ; ) {
|
|
656
895
|
const headers = {
|
|
657
896
|
Accept: "application/json",
|
|
@@ -663,50 +902,64 @@ var Core = class {
|
|
|
663
902
|
if (attempt > 0 && o.idempotencyKey) headers["Accept-Encoding"] = "identity";
|
|
664
903
|
let token = null;
|
|
665
904
|
if (o.auth) {
|
|
666
|
-
token = await this.accessToken();
|
|
905
|
+
token = await this.accessToken(o.budget);
|
|
667
906
|
headers.Authorization = `Bearer ${token}`;
|
|
668
907
|
}
|
|
669
908
|
let res;
|
|
670
909
|
try {
|
|
671
|
-
res = await this.fetchOnce(method, url, headers, o.body);
|
|
910
|
+
res = await this.fetchOnce(method, url, headers, o.body, o.budget);
|
|
672
911
|
} catch (err) {
|
|
673
|
-
if (
|
|
912
|
+
if (err instanceof NetworkError && err.kind !== "decoding" && idempotent && attempt < this.maxRetries && !((o.onlyUnsent || o.networkUnsentOnly) && err.requestSent)) {
|
|
913
|
+
if (!await this.wait(o.budget, this.backoff(attempt, null) ?? 0)) {
|
|
914
|
+
throw new NetworkError("timeout", "deadline reached", err.requestSent);
|
|
915
|
+
}
|
|
674
916
|
attempt++;
|
|
675
|
-
await this.sleep(this.backoff(attempt, null));
|
|
676
917
|
continue;
|
|
677
918
|
}
|
|
678
919
|
throw err;
|
|
679
920
|
}
|
|
680
|
-
if (res.status === 401 && o.auth && !
|
|
681
|
-
|
|
682
|
-
await this.renew(token);
|
|
921
|
+
if (res.status === 401 && o.auth && !refreshed) {
|
|
922
|
+
refreshed = true;
|
|
923
|
+
await this.renew(token, o.budget);
|
|
683
924
|
continue;
|
|
684
925
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
if (
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
continue;
|
|
692
|
-
}
|
|
926
|
+
const retryable = res.status === 429 && retry429 || res.status >= 500 && idempotent && !o.onlyUnsent;
|
|
927
|
+
if (retryable && attempt < this.maxRetries) {
|
|
928
|
+
const wait = this.backoff(attempt, res.headers?.get?.("retry-after"));
|
|
929
|
+
if (wait === null || !await this.wait(o.budget, wait)) return res;
|
|
930
|
+
attempt++;
|
|
931
|
+
continue;
|
|
693
932
|
}
|
|
694
933
|
return res;
|
|
695
934
|
}
|
|
696
935
|
}
|
|
697
|
-
async fetchOnce(method, url, headers, body) {
|
|
936
|
+
async fetchOnce(method, url, headers, body, budget) {
|
|
937
|
+
const remaining = this.remainingS(budget);
|
|
938
|
+
if (remaining < 5e-3) throw new NetworkError("timeout", "deadline reached", false);
|
|
698
939
|
const ctrl = new AbortController();
|
|
699
|
-
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
940
|
+
const timer = setTimeout(() => ctrl.abort(), Math.min(this.timeoutMs, remaining * 1e3));
|
|
941
|
+
let r;
|
|
700
942
|
try {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
943
|
+
try {
|
|
944
|
+
r = await this.fetchImpl(url, {
|
|
945
|
+
method,
|
|
946
|
+
headers,
|
|
947
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
948
|
+
signal: ctrl.signal,
|
|
949
|
+
redirect: "manual",
|
|
950
|
+
cache: "no-store"
|
|
951
|
+
});
|
|
952
|
+
} catch (err) {
|
|
953
|
+
const f = classifyFetchFailure(err, ctrl.signal.aborted);
|
|
954
|
+
throw new NetworkError(f.kind, f.detail, f.sent);
|
|
955
|
+
}
|
|
956
|
+
let text;
|
|
957
|
+
try {
|
|
958
|
+
text = await r.text();
|
|
959
|
+
} catch (err) {
|
|
960
|
+
const f = classifyFetchFailure(err, ctrl.signal.aborted);
|
|
961
|
+
throw new NetworkError(f.kind === "timeout" ? "timeout" : "decoding", f.detail, true);
|
|
962
|
+
}
|
|
710
963
|
let json = null;
|
|
711
964
|
if (text) {
|
|
712
965
|
try {
|
|
@@ -716,20 +969,10 @@ var Core = class {
|
|
|
716
969
|
}
|
|
717
970
|
}
|
|
718
971
|
return { status: r.status, headers: r.headers, json, text };
|
|
719
|
-
} catch (err) {
|
|
720
|
-
const aborted = err?.name === "AbortError";
|
|
721
|
-
throw new ApiError(0, aborted ? "timeout" : "network_error", aborted ? "Request timed out." : "Network error.", {
|
|
722
|
-
cause: err
|
|
723
|
-
});
|
|
724
972
|
} finally {
|
|
725
973
|
clearTimeout(timer);
|
|
726
974
|
}
|
|
727
975
|
}
|
|
728
|
-
backoff(attempt, retryAfter) {
|
|
729
|
-
const base = Math.min(8e3, 500 * 2 ** (attempt - 1));
|
|
730
|
-
const jittered = base / 2 + this.random() * (base / 2);
|
|
731
|
-
return Math.max(jittered, retryAfter ?? 0);
|
|
732
|
-
}
|
|
733
976
|
// -------------------------------------------------------------- errors
|
|
734
977
|
toError(res, operationId, requestBody) {
|
|
735
978
|
const { code, message: serverText, requestId, hint } = normaliseErrorBody(res);
|
|
@@ -815,13 +1058,13 @@ function normaliseErrorBody(res) {
|
|
|
815
1058
|
function str(v) {
|
|
816
1059
|
return typeof v === "string" && v !== "" ? v : null;
|
|
817
1060
|
}
|
|
1061
|
+
function parseRetryAfter(value) {
|
|
1062
|
+
if (typeof value !== "string" || !/^[0-9]{1,9}(\.[0-9]+)?$/.test(value)) return null;
|
|
1063
|
+
return Number(value);
|
|
1064
|
+
}
|
|
818
1065
|
function retryAfterMs(h) {
|
|
819
|
-
const
|
|
820
|
-
|
|
821
|
-
const n = Number(v);
|
|
822
|
-
if (Number.isFinite(n)) return Math.max(0, n * 1e3);
|
|
823
|
-
const t = Date.parse(v);
|
|
824
|
-
return Number.isFinite(t) ? Math.max(0, t - Date.now()) : null;
|
|
1066
|
+
const s = parseRetryAfter(h?.get?.("retry-after"));
|
|
1067
|
+
return s === null ? null : s * 1e3;
|
|
825
1068
|
}
|
|
826
1069
|
function secondsOrNull(ms) {
|
|
827
1070
|
return ms === null ? null : Math.round(ms / 1e3);
|
|
@@ -1226,6 +1469,17 @@ var Intelligence = class {
|
|
|
1226
1469
|
}
|
|
1227
1470
|
return this.roleCheck;
|
|
1228
1471
|
}
|
|
1472
|
+
/** Checks a query against the operation's published filters, before the role check or any request. */
|
|
1473
|
+
check(operationId, query) {
|
|
1474
|
+
for (const key of ["search", "keyword", "topic"]) {
|
|
1475
|
+
const v = query[key];
|
|
1476
|
+
if (typeof v === "string" && v.length > 200) throw new InvalidRequestError(`${key}: at most 200 characters`);
|
|
1477
|
+
}
|
|
1478
|
+
if (Array.isArray(query.numbers) && query.numbers.some((n) => typeof n === "string" && n.length > 200)) {
|
|
1479
|
+
throw new InvalidRequestError("numbers: at most 200 characters each");
|
|
1480
|
+
}
|
|
1481
|
+
buildQuery(operationId, OPERATIONS[operationId].query, query);
|
|
1482
|
+
}
|
|
1229
1483
|
async frontline() {
|
|
1230
1484
|
if (this.checkRole) await this.requireFrontline();
|
|
1231
1485
|
}
|
|
@@ -1252,6 +1506,7 @@ var Intelligence = class {
|
|
|
1252
1506
|
/** One page of calls, newest first, with totals for the whole filter in `summary`. */
|
|
1253
1507
|
async searchCalls(filters = {}) {
|
|
1254
1508
|
const q = this.callQuery(filters);
|
|
1509
|
+
this.check("listCalls", q);
|
|
1255
1510
|
await this.frontline();
|
|
1256
1511
|
const page = await this.c.calls.listCalls(q);
|
|
1257
1512
|
return { ...page, summary: page.raw.data?.summary ?? {} };
|
|
@@ -1260,16 +1515,19 @@ var Intelligence = class {
|
|
|
1260
1515
|
async *iterCalls(filters = {}) {
|
|
1261
1516
|
const { maxItems, ...f } = filters;
|
|
1262
1517
|
const q = this.callQuery(f);
|
|
1518
|
+
this.check("listCalls", q);
|
|
1263
1519
|
await this.frontline();
|
|
1264
1520
|
yield* this.c.calls.iterCalls({ ...q, maxItems });
|
|
1265
1521
|
}
|
|
1266
1522
|
/** Full detail of one call. NotFoundError when the call is outside this login's view. */
|
|
1267
1523
|
async getCall(callId) {
|
|
1524
|
+
pathArg(callId, "callId");
|
|
1268
1525
|
await this.frontline();
|
|
1269
1526
|
return (await this.c.calls.getCall(callId)).data ?? {};
|
|
1270
1527
|
}
|
|
1271
1528
|
/** Transcript lines in order ("Speaker 1" … "Speaker N"; `name` when known). */
|
|
1272
1529
|
async getTranscript(callId) {
|
|
1530
|
+
pathArg(callId, "callId");
|
|
1273
1531
|
await this.frontline();
|
|
1274
1532
|
return (await this.c.calls.getCallTranscript(callId)).data?.transcript ?? [];
|
|
1275
1533
|
}
|
|
@@ -1281,6 +1539,7 @@ var Intelligence = class {
|
|
|
1281
1539
|
* no recording.
|
|
1282
1540
|
*/
|
|
1283
1541
|
async getRecordingUrl(callId) {
|
|
1542
|
+
pathArg(callId, "callId");
|
|
1284
1543
|
const call = await this.getCall(callId);
|
|
1285
1544
|
const v = call.vcon;
|
|
1286
1545
|
return new RecordingLink(v?.recording_url ?? null, v?.recording_url_expires_at ?? null);
|
|
@@ -1305,12 +1564,14 @@ var Intelligence = class {
|
|
|
1305
1564
|
/** One page of First Alert hits, newest first. `total` counts every match. */
|
|
1306
1565
|
async searchAlerts(filters = {}) {
|
|
1307
1566
|
const q = this.alertQuery(filters);
|
|
1567
|
+
this.check("listAlerts", q);
|
|
1308
1568
|
await this.frontline();
|
|
1309
1569
|
return this.c.alerts.listAlerts(q);
|
|
1310
1570
|
}
|
|
1311
1571
|
async *iterAlerts(filters = {}) {
|
|
1312
1572
|
const { maxItems, ...f } = filters;
|
|
1313
1573
|
const q = this.alertQuery(f);
|
|
1574
|
+
this.check("listAlerts", q);
|
|
1314
1575
|
await this.frontline();
|
|
1315
1576
|
yield* this.c.alerts.iterAlerts({ ...q, maxItems });
|
|
1316
1577
|
}
|
|
@@ -1319,6 +1580,7 @@ var Intelligence = class {
|
|
|
1319
1580
|
* Returns null when the alert is not visible. With `withCall: true` the call detail is added as `call`.
|
|
1320
1581
|
*/
|
|
1321
1582
|
async getAlert(alertId, options = {}) {
|
|
1583
|
+
if (typeof alertId !== "string") throw new InvalidRequestError("alertId must be a UUID.");
|
|
1322
1584
|
const id = alertId.trim().toLowerCase();
|
|
1323
1585
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(id)) {
|
|
1324
1586
|
throw new InvalidRequestError("alertId must be a UUID.");
|
|
@@ -1332,6 +1594,7 @@ var Intelligence = class {
|
|
|
1332
1594
|
/** Alert totals for a window (default: 00:00 UTC seven days ago until now). */
|
|
1333
1595
|
async getAlertsDashboard(filters = {}) {
|
|
1334
1596
|
only(filters, ["dateFrom", "dateTo", "locationIds", "companyId"], "getAlertsDashboard");
|
|
1597
|
+
this.check("getAlertsDashboard", renameLocationIds(filters));
|
|
1335
1598
|
await this.frontline();
|
|
1336
1599
|
return (await this.c.alerts.getAlertsDashboard(renameLocationIds(filters))).data ?? {};
|
|
1337
1600
|
}
|
|
@@ -1339,6 +1602,7 @@ var Intelligence = class {
|
|
|
1339
1602
|
/** One page of follow-up tasks, newest first. No default date window. */
|
|
1340
1603
|
async listTasks(filters = {}) {
|
|
1341
1604
|
only(filters, TASK_FILTERS, "listTasks");
|
|
1605
|
+
this.check("listTasks", renameLocationIds(filters));
|
|
1342
1606
|
await this.frontline();
|
|
1343
1607
|
const page = await this.c.tasks.listTasks(renameLocationIds(filters));
|
|
1344
1608
|
return { ...page, summary: page.raw.summary ?? {} };
|
|
@@ -1346,6 +1610,7 @@ var Intelligence = class {
|
|
|
1346
1610
|
async *iterTasks(filters = {}) {
|
|
1347
1611
|
const { maxItems, ...f } = filters;
|
|
1348
1612
|
only(f, TASK_FILTERS, "iterTasks");
|
|
1613
|
+
this.check("listTasks", renameLocationIds(f));
|
|
1349
1614
|
await this.frontline();
|
|
1350
1615
|
yield* this.c.tasks.iterTasks({ ...renameLocationIds(f), maxItems });
|
|
1351
1616
|
}
|
|
@@ -1353,18 +1618,23 @@ var Intelligence = class {
|
|
|
1353
1618
|
/** Insights Hub dashboard for a window. `start` and `end` are required. */
|
|
1354
1619
|
async getInsightsDashboard(filters) {
|
|
1355
1620
|
only(filters, ["start", "end", "trendingLimit", "locationIds", "companyId"], "getInsightsDashboard");
|
|
1621
|
+
this.check("getInsightsDashboard", renameLocationIds(filters));
|
|
1356
1622
|
await this.frontline();
|
|
1357
1623
|
return (await this.c.insights.getInsightsDashboard(renameLocationIds(filters))).data ?? {};
|
|
1358
1624
|
}
|
|
1359
1625
|
/** One page of calls for a topic slug (from the dashboard's `topic_call_volumes`). */
|
|
1360
1626
|
async listTopicCalls(slug, filters = {}) {
|
|
1627
|
+
pathArg(slug, "slug");
|
|
1361
1628
|
only(filters, TOPIC_FILTERS, "listTopicCalls");
|
|
1629
|
+
this.check("listTopicCalls", renameLocationIds(filters));
|
|
1362
1630
|
await this.frontline();
|
|
1363
1631
|
return this.c.insights.listTopicCalls(slug, renameLocationIds(filters));
|
|
1364
1632
|
}
|
|
1365
1633
|
async *iterTopicCalls(slug, filters = {}) {
|
|
1366
1634
|
const { maxItems, ...f } = filters;
|
|
1635
|
+
pathArg(slug, "slug");
|
|
1367
1636
|
only(f, TOPIC_FILTERS, "iterTopicCalls");
|
|
1637
|
+
this.check("listTopicCalls", renameLocationIds(f));
|
|
1368
1638
|
await this.frontline();
|
|
1369
1639
|
yield* this.c.insights.iterTopicCalls(slug, { ...renameLocationIds(f), maxItems });
|
|
1370
1640
|
}
|
|
@@ -1378,7 +1648,8 @@ var Intelligence = class {
|
|
|
1378
1648
|
* whatever users' number mappings say. `enabled: false` pauses it (there is no delete).
|
|
1379
1649
|
*/
|
|
1380
1650
|
async setAfterCallWebhook(locationId, url, enabled = true) {
|
|
1381
|
-
|
|
1651
|
+
pathArg(locationId, "locationId");
|
|
1652
|
+
if (typeof url !== "string" || !/^https:\/\//i.test(url)) throw new InvalidRequestError("The webhook URL must use HTTPS.");
|
|
1382
1653
|
const r = await this.c.webhooks.saveAfterCallWebhook(locationId, { webhook_url: url, enabled });
|
|
1383
1654
|
return r.data ?? {};
|
|
1384
1655
|
}
|
|
@@ -1396,7 +1667,8 @@ var Intelligence = class {
|
|
|
1396
1667
|
* configuration PUT would otherwise clear the monitored numbers.
|
|
1397
1668
|
*/
|
|
1398
1669
|
async setFirstAlertWebhook(locationId, url) {
|
|
1399
|
-
|
|
1670
|
+
pathArg(locationId, "locationId");
|
|
1671
|
+
if (url !== null && (typeof url !== "string" || !/^https:\/\//i.test(url))) throw new InvalidRequestError("The webhook URL must use HTTPS.");
|
|
1400
1672
|
return (await this.c.firstAlert.setWebhookUrl(locationId, url)).data ?? {};
|
|
1401
1673
|
}
|
|
1402
1674
|
/** Send a test request to `url` (default: the saved URL). Returns only success and your endpoint's status. */
|
|
@@ -1408,51 +1680,6 @@ var Intelligence = class {
|
|
|
1408
1680
|
}
|
|
1409
1681
|
};
|
|
1410
1682
|
|
|
1411
|
-
// src/util.ts
|
|
1412
|
-
async function uuid4() {
|
|
1413
|
-
const c = globalThis.crypto;
|
|
1414
|
-
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
1415
|
-
let bytes;
|
|
1416
|
-
if (c && typeof c.getRandomValues === "function") {
|
|
1417
|
-
bytes = c.getRandomValues(new Uint8Array(16));
|
|
1418
|
-
} else {
|
|
1419
|
-
const nodeCrypto = await import('crypto');
|
|
1420
|
-
bytes = new Uint8Array(nodeCrypto.randomBytes(16));
|
|
1421
|
-
}
|
|
1422
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
1423
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
1424
|
-
const h = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1425
|
-
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
1426
|
-
}
|
|
1427
|
-
function numbersFor(mappings, connectorId) {
|
|
1428
|
-
const out = [];
|
|
1429
|
-
for (const m of mappings ?? []) if (m.connector_id === connectorId) out.push(...m.monitored_numbers ?? []);
|
|
1430
|
-
return [...new Set(out)];
|
|
1431
|
-
}
|
|
1432
|
-
function mergeMappings(current, connectorId, add = [], remove = []) {
|
|
1433
|
-
const byConnector = /* @__PURE__ */ new Map();
|
|
1434
|
-
for (const m of current ?? []) {
|
|
1435
|
-
if (!m.connector_id) continue;
|
|
1436
|
-
const list2 = byConnector.get(m.connector_id) ?? [];
|
|
1437
|
-
list2.push(...m.monitored_numbers ?? []);
|
|
1438
|
-
byConnector.set(m.connector_id, list2);
|
|
1439
|
-
}
|
|
1440
|
-
const drop = new Set(remove);
|
|
1441
|
-
const mine = (byConnector.get(connectorId) ?? []).filter((n) => !drop.has(n));
|
|
1442
|
-
for (const n of add) if (!mine.includes(n)) mine.push(n);
|
|
1443
|
-
byConnector.set(connectorId, mine);
|
|
1444
|
-
const out = [];
|
|
1445
|
-
for (const [connector_id, nums] of byConnector) {
|
|
1446
|
-
const uniq3 = [...new Set(nums)];
|
|
1447
|
-
if (uniq3.length) out.push({ connector_id, monitored_numbers: uniq3 });
|
|
1448
|
-
}
|
|
1449
|
-
return out;
|
|
1450
|
-
}
|
|
1451
|
-
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1452
|
-
function isUuid(value) {
|
|
1453
|
-
return typeof value === "string" && UUID_RE.test(value);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
1683
|
// src/secrets.ts
|
|
1457
1684
|
var SECRET_WORDS = ["key", "secret", "token", "password", "passwd", "pwd", "credential", "auth"];
|
|
1458
1685
|
var INSPECT = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
@@ -1625,10 +1852,12 @@ async function all(gen) {
|
|
|
1625
1852
|
for await (const x of gen) out.push(x);
|
|
1626
1853
|
return out;
|
|
1627
1854
|
}
|
|
1855
|
+
var LINE_RE = /^\+?[0-9*#]{1,32}$/;
|
|
1628
1856
|
function line(value, name = "line") {
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1857
|
+
if (typeof value !== "string" || !LINE_RE.test(value)) {
|
|
1858
|
+
throw new InvalidRequestError(`${name}: an extension or number of 1 to 32 digits, * or # (an optional leading +), with no spaces or other characters`);
|
|
1859
|
+
}
|
|
1860
|
+
return value;
|
|
1632
1861
|
}
|
|
1633
1862
|
function numbersOf(mappings, connectorId) {
|
|
1634
1863
|
const out = [];
|
|
@@ -1650,8 +1879,25 @@ function sameMappings(a, b) {
|
|
|
1650
1879
|
};
|
|
1651
1880
|
return deepEqual(norm(a), norm(b));
|
|
1652
1881
|
}
|
|
1882
|
+
function str2(value, name, required = true, max = 200) {
|
|
1883
|
+
if ((value === void 0 || value === null) && !required) return null;
|
|
1884
|
+
if (typeof value !== "string") throw new InvalidRequestError(`${name}: a string${required ? "" : " or null"}`);
|
|
1885
|
+
const v = value.trim();
|
|
1886
|
+
if (required && !v) throw new InvalidRequestError(`${name} is required`);
|
|
1887
|
+
if (v.length > max) throw new InvalidRequestError(`${name}: at most ${max} characters`);
|
|
1888
|
+
return v;
|
|
1889
|
+
}
|
|
1890
|
+
function list2(value, name) {
|
|
1891
|
+
if (value === void 0 || value === null || typeof value === "string" || typeof value[Symbol.iterator] !== "function") {
|
|
1892
|
+
throw new InvalidRequestError(`${name}: a list`);
|
|
1893
|
+
}
|
|
1894
|
+
return [...value];
|
|
1895
|
+
}
|
|
1896
|
+
function bool(value, name) {
|
|
1897
|
+
if (value !== void 0 && typeof value !== "boolean") throw new InvalidRequestError(`${name}: true or false`);
|
|
1898
|
+
}
|
|
1653
1899
|
function checkSetting(key, s) {
|
|
1654
|
-
if (s === null || s === void 0) return;
|
|
1900
|
+
if (s === null || s === void 0) return null;
|
|
1655
1901
|
if (typeof s !== "object") throw new InvalidRequestError(`alerts.${key} must be an AlertSetting`);
|
|
1656
1902
|
if (s.sentimentBelow !== void 0 && s.sentimentBelow !== null) {
|
|
1657
1903
|
const lvl = s.sentimentBelow;
|
|
@@ -1659,24 +1905,72 @@ function checkSetting(key, s) {
|
|
|
1659
1905
|
throw new InvalidRequestError(`alerts.${key}.sentimentBelow: a whole number from -100 to -1`);
|
|
1660
1906
|
}
|
|
1661
1907
|
}
|
|
1908
|
+
let phrases = null;
|
|
1662
1909
|
if (s.phrases !== void 0 && s.phrases !== null) {
|
|
1663
1910
|
if (!RULES[key].hasPhrases) throw new InvalidRequestError(`alerts.${key} has no phrases; set sentimentBelow only`);
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
if (!s.phrases.some((p) => p.trim())) {
|
|
1911
|
+
phrases = list2(s.phrases, `alerts.${key}.phrases`);
|
|
1912
|
+
if (!phrases.every((p) => typeof p === "string")) throw new InvalidRequestError(`alerts.${key}.phrases must be a list of strings`);
|
|
1913
|
+
if (!phrases.some((p) => p.trim())) {
|
|
1668
1914
|
throw new InvalidRequestError(`alerts.${key}.phrases is empty; pass null to keep the current phrases`);
|
|
1669
1915
|
}
|
|
1670
1916
|
}
|
|
1917
|
+
return { phrases, sentimentBelow: s.sentimentBelow ?? null };
|
|
1671
1918
|
}
|
|
1672
1919
|
function checkAlerts(alerts) {
|
|
1673
|
-
if (alerts === null || alerts === void 0) return;
|
|
1920
|
+
if (alerts === null || alerts === void 0) return null;
|
|
1674
1921
|
if (typeof alerts !== "object") throw new InvalidRequestError("alerts must be an AlertSettings");
|
|
1675
|
-
|
|
1922
|
+
const out = {};
|
|
1923
|
+
for (const key of RULE_FIELDS) out[key] = checkSetting(key, alerts[key]);
|
|
1924
|
+
return out;
|
|
1925
|
+
}
|
|
1926
|
+
function checkConnectorLocal(cs, required = false) {
|
|
1927
|
+
if (cs === null || cs === void 0) {
|
|
1928
|
+
if (required) throw new InvalidRequestError("A connector is required: pass a ConnectorSpec");
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
if (!isConnectorSpec(cs)) throw new InvalidRequestError("connector must be a ConnectorSpec");
|
|
1932
|
+
str2(cs.type, "connector.type");
|
|
1933
|
+
str2(cs.name, "connector.name", false);
|
|
1934
|
+
if (typeof cs.timeout !== "number" || !(cs.timeout >= 0)) throw new InvalidRequestError("connector.timeout: a number of seconds");
|
|
1935
|
+
}
|
|
1936
|
+
var isCustomerObject = (v) => v !== null && typeof v === "object" && "companyId" in v;
|
|
1937
|
+
var isTeamObject = (v) => v !== null && typeof v === "object" && typeof v.locationId === "string";
|
|
1938
|
+
function checkCustomerRef(customer) {
|
|
1939
|
+
if (isCustomerObject(customer)) {
|
|
1940
|
+
pathArg(customer.companyId, "customer.companyId");
|
|
1941
|
+
for (const t of [...customer.management ? [customer.management] : [], ...Array.isArray(customer.teams) ? customer.teams : []]) {
|
|
1942
|
+
if (!isTeamObject(t)) throw new InvalidRequestError("customer: every team needs a string locationId");
|
|
1943
|
+
pathArg(t.locationId, "team.locationId");
|
|
1944
|
+
}
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
if (typeof customer !== "string") throw new InvalidRequestError("customer: a Customer or a company id");
|
|
1948
|
+
pathArg(customer, "customer");
|
|
1949
|
+
}
|
|
1950
|
+
function checkTeamRef(team, required = true) {
|
|
1951
|
+
if ((team === void 0 || team === null) && !required) return;
|
|
1952
|
+
if (isTeamObject(team)) return;
|
|
1953
|
+
if (typeof team !== "string" || !team.trim() || team.length > 200) throw new InvalidRequestError("team: a Team, its location id or its name");
|
|
1954
|
+
}
|
|
1955
|
+
function checkPerson(person) {
|
|
1956
|
+
if (!person || typeof person !== "object") throw new InvalidRequestError("person must be a PersonSpec");
|
|
1957
|
+
const p = person;
|
|
1958
|
+
if (!str2(p.email, "person.email").includes("@")) throw new InvalidRequestError("person.email: an email address");
|
|
1959
|
+
str2(p.firstName, "person.firstName");
|
|
1960
|
+
str2(p.lastName, "person.lastName");
|
|
1961
|
+
str2(p.phoneNumber, "person.phoneNumber", false);
|
|
1962
|
+
if (p.authMethod !== void 0 && p.authMethod !== "password" && p.authMethod !== "sso") {
|
|
1963
|
+
throw new InvalidRequestError('person.authMethod: "password" or "sso"');
|
|
1964
|
+
}
|
|
1676
1965
|
}
|
|
1966
|
+
function checkTeamSpec(team) {
|
|
1967
|
+
if (!team || typeof team !== "object" || isTeamObject(team)) throw new InvalidRequestError("team must be a TeamSpec");
|
|
1968
|
+
for (const f of ["name", "street", "city", "state", "country", "zipcode", "vertical"]) str2(team[f], `team.${f}`);
|
|
1969
|
+
}
|
|
1970
|
+
var checkUserId = (id) => void pathArg(id, "userId");
|
|
1677
1971
|
function cleanPhrases(phrases) {
|
|
1678
1972
|
if (phrases === null || phrases === void 0) return null;
|
|
1679
|
-
return uniq(phrases.filter((p) => p && p.trim()).map((p) => p.trim()));
|
|
1973
|
+
return uniq([...phrases].filter((p) => p && p.trim()).map((p) => p.trim()));
|
|
1680
1974
|
}
|
|
1681
1975
|
function ruleSettings(rule) {
|
|
1682
1976
|
let phrases = null;
|
|
@@ -1774,44 +2068,28 @@ var Accounts = class _Accounts {
|
|
|
1774
2068
|
constructor(c) {
|
|
1775
2069
|
this.c = c;
|
|
1776
2070
|
this.rawConnectors = makeConnectors(c.core);
|
|
1777
|
-
const writers = [
|
|
1778
|
-
"createCustomer",
|
|
1779
|
-
"addTeam",
|
|
1780
|
-
"setAlerts",
|
|
1781
|
-
"setConnector",
|
|
1782
|
-
"activateAlerts",
|
|
1783
|
-
"addBaseUser",
|
|
1784
|
-
"addBaseManager",
|
|
1785
|
-
"addIntegrationUser",
|
|
1786
|
-
"changeLicense",
|
|
1787
|
-
"moveUser",
|
|
1788
|
-
"changeLine",
|
|
1789
|
-
"removeUser",
|
|
1790
|
-
"sendInvitations",
|
|
1791
|
-
"syncLines",
|
|
1792
|
-
"offboardCustomer"
|
|
1793
|
-
];
|
|
1794
|
-
for (const name of writers) {
|
|
1795
|
-
const original = this[name].bind(this);
|
|
1796
|
-
this[name] = (...args) => {
|
|
1797
|
-
const run = this.tail.then(
|
|
1798
|
-
() => original(...args),
|
|
1799
|
-
() => original(...args)
|
|
1800
|
-
);
|
|
1801
|
-
this.tail = run.then(
|
|
1802
|
-
() => void 0,
|
|
1803
|
-
() => void 0
|
|
1804
|
-
);
|
|
1805
|
-
return run;
|
|
1806
|
-
};
|
|
1807
|
-
}
|
|
1808
2071
|
}
|
|
1809
2072
|
c;
|
|
1810
2073
|
me = null;
|
|
1811
2074
|
verticals = null;
|
|
1812
|
-
|
|
2075
|
+
/** Teams whose groups and rules were read in the current helper call: a live listing is not repeated for them. */
|
|
2076
|
+
readNow = /* @__PURE__ */ new WeakSet();
|
|
2077
|
+
lastIndex = null;
|
|
1813
2078
|
rawConnectors;
|
|
1814
2079
|
tail = Promise.resolve();
|
|
2080
|
+
/**
|
|
2081
|
+
* Runs `fn` after every earlier writing helper of this client has finished (lists are read, merged and
|
|
2082
|
+
* written back, so two helpers at once would lose each other's lines). A failed helper does not fail the
|
|
2083
|
+
* next one. Arguments are checked before a helper gets here, so a bad argument is refused at once.
|
|
2084
|
+
*/
|
|
2085
|
+
exclusive(fn) {
|
|
2086
|
+
const run = this.tail.then(fn, fn);
|
|
2087
|
+
this.tail = run.then(
|
|
2088
|
+
() => void 0,
|
|
2089
|
+
() => void 0
|
|
2090
|
+
);
|
|
2091
|
+
return run;
|
|
2092
|
+
}
|
|
1815
2093
|
// ------------------------------------------------------------------ plumbing
|
|
1816
2094
|
async requireAdmin() {
|
|
1817
2095
|
if (this.me === null) this.me = unwrap(await this.c.account.getMe()) ?? {};
|
|
@@ -1827,10 +2105,66 @@ var Accounts = class _Accounts {
|
|
|
1827
2105
|
if (exc instanceof AccountError || this.c.core.writes === run.start) throw exc;
|
|
1828
2106
|
throw new AccountError(run.step, run.result, exc);
|
|
1829
2107
|
}
|
|
2108
|
+
/**
|
|
2109
|
+
* The customer to work on. A company id is read live. A Customer object may be stale (a team added or
|
|
2110
|
+
* stopped elsewhere): one cheap live read, the company's location list, is compared with the object's
|
|
2111
|
+
* teams and Management by id and active state; if anything differs the full layout is read again and the
|
|
2112
|
+
* object is updated in place. A Customer that carries a location that is not in its company is refused.
|
|
2113
|
+
*/
|
|
1830
2114
|
async resolve(customer) {
|
|
1831
|
-
if (customer &&
|
|
1832
|
-
if (typeof customer
|
|
1833
|
-
|
|
2115
|
+
if (typeof customer === "string" && customer !== "") return this.getCustomer(customer);
|
|
2116
|
+
if (!customer || typeof customer !== "object") throw new InvalidRequestError("customer: a Customer or a company id");
|
|
2117
|
+
for (const t of this.locationsOf(customer)) this.readNow.delete(t);
|
|
2118
|
+
let locs;
|
|
2119
|
+
try {
|
|
2120
|
+
locs = await all(this.c.locations.iterCompanyLocations(customer.companyId));
|
|
2121
|
+
} catch (exc) {
|
|
2122
|
+
if (exc instanceof NotFoundError) throw new InvalidRequestError("This Customer's company is not visible to this login");
|
|
2123
|
+
throw exc;
|
|
2124
|
+
}
|
|
2125
|
+
const known = new Set(locs.map((l) => l.id));
|
|
2126
|
+
const active = new Set(locs.filter((l) => l.is_active ?? true).map((l) => l.id));
|
|
2127
|
+
const mine = this.locationsOf(customer).map((t) => t.locationId);
|
|
2128
|
+
if (mine.some((id) => !known.has(id))) {
|
|
2129
|
+
throw new InvalidRequestError("The Customer carries a location that is not in its company: read it again with getCustomer");
|
|
2130
|
+
}
|
|
2131
|
+
if (mine.length !== active.size || !mine.every((id) => active.has(id))) {
|
|
2132
|
+
const fresh = await this.getCustomer(customer.companyId);
|
|
2133
|
+
const byId = new Map(this.locationsOf(customer).map((t) => [t.locationId, t]));
|
|
2134
|
+
const keep = (t) => {
|
|
2135
|
+
const old = byId.get(t.locationId);
|
|
2136
|
+
const kept = old ? Object.assign(old, t) : t;
|
|
2137
|
+
this.readNow.add(kept);
|
|
2138
|
+
return kept;
|
|
2139
|
+
};
|
|
2140
|
+
customer.management = fresh.management ? keep(fresh.management) : null;
|
|
2141
|
+
customer.teams.splice(0, customer.teams.length, ...fresh.teams.map(keep));
|
|
2142
|
+
customer.pending = fresh.pending;
|
|
2143
|
+
customer.ssoDomainId = fresh.ssoDomainId;
|
|
2144
|
+
customer.ssoTxtRecord = fresh.ssoTxtRecord;
|
|
2145
|
+
}
|
|
2146
|
+
customer.refreshedAt = /* @__PURE__ */ new Date();
|
|
2147
|
+
return customer;
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Group and rule ids of these teams from a live listing made now, never from the object (a company id
|
|
2151
|
+
* included: the layout read does not list groups and rules again). A group in `need` that is missing is
|
|
2152
|
+
* refused before any write.
|
|
2153
|
+
*/
|
|
2154
|
+
async live(teams, need = []) {
|
|
2155
|
+
for (const t of teams) {
|
|
2156
|
+
if (!this.readNow.has(t)) {
|
|
2157
|
+
const [groups, rules] = await this.readGroupsRules(t.locationId);
|
|
2158
|
+
Object.assign(t.groups, groups);
|
|
2159
|
+
Object.assign(t.rules, rules);
|
|
2160
|
+
this.readNow.add(t);
|
|
2161
|
+
}
|
|
2162
|
+
const wanted = t.kind === "team" ? need : need.filter((f) => f === "weeklyReports");
|
|
2163
|
+
const missing = wanted.filter((f) => t.groups[f] === null).map((f) => TEAM_GROUPS[f]);
|
|
2164
|
+
if (missing.length) {
|
|
2165
|
+
throw new InvalidRequestError(`${t.name}: group ${missing.join(", ")} is missing; run createCustomer (or addTeam) again to restore the layout`);
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
1834
2168
|
}
|
|
1835
2169
|
teamOf(cust, team) {
|
|
1836
2170
|
if (typeof team === "object" && team !== null) {
|
|
@@ -1854,18 +2188,9 @@ var Accounts = class _Accounts {
|
|
|
1854
2188
|
for (const v of this.verticals) if (vertical === v.key || vertical === v.name) return v.id;
|
|
1855
2189
|
throw new InvalidRequestError(`Unknown vertical "${vertical}": use an id or key from listVerticals()`);
|
|
1856
2190
|
}
|
|
2191
|
+
/** The local checks only: the type's value is the platform's to judge (any type is passed through, no list read first). */
|
|
1857
2192
|
async checkConnector(cs, required = false) {
|
|
1858
|
-
|
|
1859
|
-
if (required) throw new InvalidRequestError("A connector is required: pass a ConnectorSpec");
|
|
1860
|
-
return;
|
|
1861
|
-
}
|
|
1862
|
-
if (!isConnectorSpec(cs)) throw new InvalidRequestError("connector must be a ConnectorSpec");
|
|
1863
|
-
if (this.connectorTypes === null) {
|
|
1864
|
-
this.connectorTypes = rowsOf(await this.c.connectors.listConnectorTypes()).map((r) => r?.key).filter((k) => typeof k === "string" && !!k);
|
|
1865
|
-
}
|
|
1866
|
-
if (!this.connectorTypes.includes(cs.type)) {
|
|
1867
|
-
throw new InvalidRequestError(`Unknown connector type "${cs.type}": one of ${JSON.stringify(this.connectorTypes)}`);
|
|
1868
|
-
}
|
|
2193
|
+
checkConnectorLocal(cs, required);
|
|
1869
2194
|
}
|
|
1870
2195
|
// ------------------------------------------------------------------ reading the layout
|
|
1871
2196
|
/**
|
|
@@ -1874,6 +2199,7 @@ var Accounts = class _Accounts {
|
|
|
1874
2199
|
* what is missing listed in `pending`.
|
|
1875
2200
|
*/
|
|
1876
2201
|
async getCustomer(companyId) {
|
|
2202
|
+
checkCustomerRef(companyId);
|
|
1877
2203
|
await this.requireAdmin();
|
|
1878
2204
|
const c = this.c;
|
|
1879
2205
|
const company = unwrap(await c.companies.getCompany(companyId)) ?? {};
|
|
@@ -1886,7 +2212,7 @@ var Accounts = class _Accounts {
|
|
|
1886
2212
|
const [b1, b2] = key(b);
|
|
1887
2213
|
return a1 < b1 ? -1 : a1 > b1 ? 1 : a2 < b2 ? -1 : a2 > b2 ? 1 : 0;
|
|
1888
2214
|
});
|
|
1889
|
-
const cust = { companyId, management: null, teams: [], pending: [], ssoDomainId: null, ssoTxtRecord: null, created: [], existing: [] };
|
|
2215
|
+
const cust = { companyId, management: null, teams: [], pending: [], ssoDomainId: null, ssoTxtRecord: null, created: [], existing: [], refreshedAt: null };
|
|
1890
2216
|
for (const loc of locs) {
|
|
1891
2217
|
const kind = loc.location_name === mgmtName ? "management" : "team";
|
|
1892
2218
|
const team = await this.readTeam(loc.id, loc.location_name ?? "", kind);
|
|
@@ -1894,6 +2220,7 @@ var Accounts = class _Accounts {
|
|
|
1894
2220
|
else cust.teams.push(team);
|
|
1895
2221
|
}
|
|
1896
2222
|
cust.pending = this.pendingOf(cust);
|
|
2223
|
+
cust.refreshedAt = /* @__PURE__ */ new Date();
|
|
1897
2224
|
for (const dom of rowsOf(await c.sso.listCompanyDomains(companyId))) {
|
|
1898
2225
|
cust.ssoDomainId = dom.id ?? null;
|
|
1899
2226
|
const ver = dom.verification ?? {};
|
|
@@ -1903,16 +2230,24 @@ var Accounts = class _Accounts {
|
|
|
1903
2230
|
return cust;
|
|
1904
2231
|
}
|
|
1905
2232
|
async readTeam(locationId, name, kind) {
|
|
1906
|
-
const c = this.c;
|
|
1907
2233
|
const team = newTeam(locationId, name, kind);
|
|
2234
|
+
const [groups, rules] = await this.readGroupsRules(locationId);
|
|
2235
|
+
Object.assign(team.groups, groups);
|
|
2236
|
+
Object.assign(team.rules, rules);
|
|
2237
|
+
await this.readConnector(team);
|
|
2238
|
+
this.readNow.add(team);
|
|
2239
|
+
return team;
|
|
2240
|
+
}
|
|
2241
|
+
async readGroupsRules(locationId) {
|
|
2242
|
+
const c = this.c;
|
|
2243
|
+
const probe = newTeam(locationId, "", "team");
|
|
1908
2244
|
const byName = /* @__PURE__ */ new Map();
|
|
1909
2245
|
for (const g of await all(c.groups.iterUserGroups(locationId))) byName.set(g.group_name, g.id);
|
|
1910
|
-
for (const f of GROUP_FIELDS)
|
|
2246
|
+
for (const f of GROUP_FIELDS) probe.groups[f] = byName.get(TEAM_GROUPS[f]) ?? null;
|
|
1911
2247
|
const rules = /* @__PURE__ */ new Map();
|
|
1912
2248
|
for (const r of await all(c.firstAlert.iterAlertRules(locationId))) rules.set(r.name, r.id);
|
|
1913
|
-
for (const key of RULE_FIELDS)
|
|
1914
|
-
|
|
1915
|
-
return team;
|
|
2249
|
+
for (const key of RULE_FIELDS) probe.rules[key] = rules.get(RULES[key].name) ?? null;
|
|
2250
|
+
return [probe.groups, probe.rules];
|
|
1916
2251
|
}
|
|
1917
2252
|
async readConnector(team) {
|
|
1918
2253
|
const conns = (await all(this.c.connectors.iterLocationConnectors(team.locationId))).sort((a, b) => rank(a.status) - rank(b.status));
|
|
@@ -1950,90 +2285,100 @@ var Accounts = class _Accounts {
|
|
|
1950
2285
|
* `companyId` and pass it on later runs: a company is never adopted by its name alone.
|
|
1951
2286
|
*/
|
|
1952
2287
|
async createCustomer(spec) {
|
|
1953
|
-
const me = await this.requireAdmin();
|
|
1954
2288
|
const c = this.c;
|
|
1955
|
-
if (!spec || typeof spec !== "object"
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2289
|
+
if (!spec || typeof spec !== "object") throw new InvalidRequestError("spec must be a CustomerSpec");
|
|
2290
|
+
str2(spec.companyName, "companyName");
|
|
2291
|
+
checkPerson(spec.admin);
|
|
2292
|
+
str2(spec.admin.phoneNumber, "admin.phoneNumber");
|
|
2293
|
+
checkTeamSpec(spec.team);
|
|
2294
|
+
const alerts = checkAlerts(spec.alerts);
|
|
2295
|
+
checkConnectorLocal(spec.connector);
|
|
2296
|
+
for (const f of ["resellerId", "companyCode", "companyId", "ssoDomain"]) str2(spec[f], f, false);
|
|
2297
|
+
bool(spec.mfaOff, "mfaOff");
|
|
2298
|
+
bool(spec.reactivate, "reactivate");
|
|
1961
2299
|
const mgmtName = spec.companyName + MANAGEMENT_SUFFIX;
|
|
1962
2300
|
if (spec.team.name === mgmtName) throw new InvalidRequestError(`"${mgmtName}" is the Management location; name the team differently`);
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2301
|
+
return this.exclusive(async () => {
|
|
2302
|
+
const me = await this.requireAdmin();
|
|
2303
|
+
await this.checkConnector(spec.connector);
|
|
2304
|
+
const resellerId = spec.resellerId || me.reseller_id;
|
|
2305
|
+
if (!resellerId) throw new InvalidRequestError("resellerId is required (this login has none)");
|
|
2306
|
+
await this.verticalId(spec.team.vertical);
|
|
2307
|
+
const result = { companyId: "", management: null, teams: [], pending: [], ssoDomainId: null, ssoTxtRecord: null, created: [], existing: [], refreshedAt: null };
|
|
2308
|
+
const failures = [];
|
|
2309
|
+
const run = this.run(result);
|
|
2310
|
+
try {
|
|
2311
|
+
run.step = "company";
|
|
2312
|
+
let company = await this.findCompany(resellerId, spec);
|
|
2313
|
+
if (company === null) {
|
|
2314
|
+
const body = {
|
|
2315
|
+
company_name: spec.companyName,
|
|
2316
|
+
primary_admin_contact_name: `${spec.admin.firstName} ${spec.admin.lastName}`.trim(),
|
|
2317
|
+
primary_admin_contact_email: spec.admin.email,
|
|
2318
|
+
primary_admin_contact_phone: spec.admin.phoneNumber,
|
|
2319
|
+
enabled_products: [...PRODUCT_KEYS]
|
|
2320
|
+
};
|
|
2321
|
+
if (spec.companyCode) body.company_code = spec.companyCode;
|
|
2322
|
+
company = unwrap(await c.companies.createCompany(resellerId, body));
|
|
2323
|
+
result.created.push("company");
|
|
2324
|
+
} else {
|
|
2325
|
+
result.existing.push("company");
|
|
2326
|
+
if (!(company.is_active ?? true)) {
|
|
2327
|
+
if (!spec.reactivate) {
|
|
2328
|
+
throw new InvalidRequestError(`Company "${spec.companyName}" exists but is inactive (set reactivate: true to reactivate it)`);
|
|
2329
|
+
}
|
|
2330
|
+
await c.companies.reactivateCompany(company.id);
|
|
1986
2331
|
}
|
|
1987
|
-
await c.companies.reactivateCompany(company.id);
|
|
1988
2332
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2333
|
+
const companyId = result.companyId = company.id;
|
|
2334
|
+
run.step = "mfa";
|
|
2335
|
+
if (spec.mfaOff) {
|
|
2336
|
+
const current2 = unwrap(await c.companies.getCompany(companyId)) ?? {};
|
|
2337
|
+
if (current2.mfa_enforced) {
|
|
2338
|
+
await c.companies.updateCompany(companyId, { mfa_enforced: false });
|
|
2339
|
+
if ((unwrap(await c.companies.getCompany(companyId)) ?? {}).mfa_enforced) {
|
|
2340
|
+
const text = "MFA is still on for the company after the update";
|
|
2341
|
+
throw new ApiError(200, null, text, {});
|
|
2342
|
+
}
|
|
1999
2343
|
}
|
|
2000
2344
|
}
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2345
|
+
run.step = "sso";
|
|
2346
|
+
if (spec.ssoDomain) await this.ensureDomain(companyId, spec.ssoDomain, result);
|
|
2347
|
+
run.step = "products";
|
|
2348
|
+
const current = unwrap(await c.companies.getCompany(companyId)) ?? {};
|
|
2349
|
+
const have = current.enabled_products ?? [];
|
|
2350
|
+
if (!PRODUCT_KEYS.every((k) => have.includes(k))) await c.companies.addProducts(companyId, [...PRODUCT_KEYS]);
|
|
2351
|
+
run.step = "locations";
|
|
2352
|
+
const team = await this.ensureLocation(companyId, spec.team.name, spec.team, "team", !!spec.reactivate, result);
|
|
2353
|
+
const mgmt = await this.ensureLocation(companyId, mgmtName, spec.team, "management", !!spec.reactivate, result);
|
|
2354
|
+
result.teams = [team];
|
|
2355
|
+
result.management = mgmt;
|
|
2356
|
+
run.step = "connectors";
|
|
2357
|
+
if (spec.connector) {
|
|
2358
|
+
for (const t of [team, mgmt]) {
|
|
2359
|
+
const failure = await this.ensureConnector(t, spec.connector, result);
|
|
2360
|
+
if (failure) failures.push(failure);
|
|
2361
|
+
}
|
|
2362
|
+
} else {
|
|
2363
|
+
await this.readConnector(team);
|
|
2364
|
+
await this.readConnector(mgmt);
|
|
2018
2365
|
}
|
|
2019
|
-
|
|
2020
|
-
await this.
|
|
2021
|
-
await this.
|
|
2366
|
+
run.step = "groups";
|
|
2367
|
+
await this.ensureGroups(team, result);
|
|
2368
|
+
await this.ensureGroups(mgmt, result);
|
|
2369
|
+
run.step = "rules";
|
|
2370
|
+
await this.ensureRules(team, this.settingsFrom(alerts), result);
|
|
2371
|
+
run.step = "insights_hub";
|
|
2372
|
+
await this.ensureInsightsHub(team);
|
|
2373
|
+
await this.monitorAllOff(mgmt.locationId);
|
|
2374
|
+
result.pending = this.pendingOf(result);
|
|
2375
|
+
result.refreshedAt = /* @__PURE__ */ new Date();
|
|
2376
|
+
} catch (exc) {
|
|
2377
|
+
this.stop(run, exc);
|
|
2022
2378
|
}
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
run.step = "rules";
|
|
2027
|
-
await this.ensureRules(team, this.settingsFrom(spec.alerts), result);
|
|
2028
|
-
run.step = "insights_hub";
|
|
2029
|
-
await this.ensureInsightsHub(team);
|
|
2030
|
-
await this.monitorAllOff(mgmt.locationId);
|
|
2031
|
-
result.pending = this.pendingOf(result);
|
|
2032
|
-
} catch (exc) {
|
|
2033
|
-
this.stop(run, exc);
|
|
2034
|
-
}
|
|
2035
|
-
raiseConnectorFailure(failures, result);
|
|
2036
|
-
return result;
|
|
2379
|
+
raiseConnectorFailure(failures, result);
|
|
2380
|
+
return result;
|
|
2381
|
+
});
|
|
2037
2382
|
}
|
|
2038
2383
|
/**
|
|
2039
2384
|
* `spec.companyId`, or the one company with this exact name whose primary contact email is
|
|
@@ -2216,18 +2561,42 @@ var Accounts = class _Accounts {
|
|
|
2216
2561
|
const label = `connector:${team.name}`;
|
|
2217
2562
|
if (found !== null) {
|
|
2218
2563
|
const unchanged = _Accounts.unchanged(found, name, config);
|
|
2219
|
-
if (
|
|
2564
|
+
if (RUNNING.includes(found.status) && unchanged) {
|
|
2220
2565
|
result?.existing.push(label);
|
|
2221
2566
|
this.setConn(team, found);
|
|
2222
2567
|
return null;
|
|
2223
2568
|
}
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2569
|
+
if (found.status === "connecting" && unchanged) {
|
|
2570
|
+
result?.existing.push(label);
|
|
2571
|
+
try {
|
|
2572
|
+
let settled;
|
|
2573
|
+
try {
|
|
2574
|
+
settled = await conns.waitForStatus(team.locationId, found.id, [...RUNNING, "error"], { timeout: cs.timeout, raiseOnError: false });
|
|
2575
|
+
} catch (exc) {
|
|
2576
|
+
if (!(exc instanceof ConnectorTimeoutError)) throw exc;
|
|
2577
|
+
settled = { status: "connecting" };
|
|
2578
|
+
}
|
|
2579
|
+
if (!RUNNING.includes(settled.status)) {
|
|
2580
|
+
await conns.deactivateConnector(team.locationId, found.id, { timeout: cs.timeout });
|
|
2581
|
+
settled = unwrap(await conns.reactivateConnector(team.locationId, found.id, { timeout: cs.timeout })) ?? {};
|
|
2582
|
+
}
|
|
2583
|
+
this.setConn(team, settled);
|
|
2584
|
+
return null;
|
|
2585
|
+
} catch (exc) {
|
|
2586
|
+
if (exc instanceof ConnectorError || exc instanceof ConnectorTimeoutError) {
|
|
2587
|
+
this.setConn(team, exc.connector ?? {});
|
|
2588
|
+
return exc;
|
|
2589
|
+
}
|
|
2590
|
+
throw exc;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
let conn;
|
|
2595
|
+
try {
|
|
2596
|
+
if (found !== null) {
|
|
2597
|
+
if (result) result.existing.push(label, label + ":updated");
|
|
2598
|
+
await this.rawConnectors.updateConnector(team.locationId, found.id, { name, config });
|
|
2599
|
+
if (found.status === "inactive") {
|
|
2231
2600
|
conn = unwrap(await conns.reactivateConnector(team.locationId, found.id, { timeout: cs.timeout }));
|
|
2232
2601
|
} else {
|
|
2233
2602
|
conn = await conns.waitForStatus(team.locationId, found.id, [...RUNNING, "error"], { timeout: cs.timeout, raiseOnError: false });
|
|
@@ -2263,52 +2632,58 @@ var Accounts = class _Accounts {
|
|
|
2263
2632
|
* and Insights Hub setup. The rules are created switched off.
|
|
2264
2633
|
*/
|
|
2265
2634
|
async addTeam(customer, team, connector, options = {}) {
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
checkAlerts(options
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2635
|
+
checkCustomerRef(customer);
|
|
2636
|
+
checkTeamSpec(team);
|
|
2637
|
+
checkConnectorLocal(connector, true);
|
|
2638
|
+
const alerts = checkAlerts(options?.alerts);
|
|
2639
|
+
bool(options?.reactivate, "reactivate");
|
|
2640
|
+
return this.exclusive(async () => {
|
|
2641
|
+
await this.requireAdmin();
|
|
2642
|
+
await this.checkConnector(connector, true);
|
|
2643
|
+
const cust = await this.resolve(customer);
|
|
2644
|
+
if (cust.management !== null && team.name === cust.management.name) {
|
|
2645
|
+
throw new InvalidRequestError("That name is the Management location; name the team differently");
|
|
2646
|
+
}
|
|
2647
|
+
await this.verticalId(team.vertical);
|
|
2648
|
+
const settings = this.settingsFrom(alerts);
|
|
2649
|
+
const first = cust.teams.find((t) => t.name !== team.name);
|
|
2650
|
+
if (first !== void 0) await this.live([first]);
|
|
2651
|
+
const made = newTeam("", team.name);
|
|
2652
|
+
let failure = null;
|
|
2653
|
+
const run = this.run(made);
|
|
2654
|
+
try {
|
|
2655
|
+
run.step = "copy_alerts";
|
|
2656
|
+
if (first !== void 0) {
|
|
2657
|
+
for (const key of RULE_FIELDS) {
|
|
2658
|
+
const d = RULES[key];
|
|
2659
|
+
const rid = first.rules[key];
|
|
2660
|
+
if (rid === null) continue;
|
|
2661
|
+
const [phr, lvl] = ruleSettings(unwrap(await this.c.firstAlert.getAlertRule(first.locationId, rid)) ?? {});
|
|
2662
|
+
const [givenPhr, givenLvl] = settings[key];
|
|
2663
|
+
settings[key] = [givenPhr !== null ? givenPhr : d.hasPhrases ? phr : null, givenLvl !== null ? givenLvl : lvl];
|
|
2664
|
+
}
|
|
2290
2665
|
}
|
|
2666
|
+
run.step = "location";
|
|
2667
|
+
const loc = await this.ensureLocation(cust.companyId, team.name, team, "team", !!options?.reactivate, cust);
|
|
2668
|
+
made.locationId = loc.locationId;
|
|
2669
|
+
run.step = "connector";
|
|
2670
|
+
failure = await this.ensureConnector(made, connector, cust);
|
|
2671
|
+
run.step = "groups";
|
|
2672
|
+
await this.ensureGroups(made, cust);
|
|
2673
|
+
run.step = "rules";
|
|
2674
|
+
await this.ensureRules(made, settings, cust);
|
|
2675
|
+
run.step = "insights_hub";
|
|
2676
|
+
await this.ensureInsightsHub(made);
|
|
2677
|
+
const existing = cust.teams.findIndex((t) => t.locationId === made.locationId);
|
|
2678
|
+
if (existing < 0) cust.teams.push(made);
|
|
2679
|
+
else cust.teams[existing] = made;
|
|
2680
|
+
cust.pending = this.pendingOf(cust);
|
|
2681
|
+
} catch (exc) {
|
|
2682
|
+
this.stop(run, exc);
|
|
2291
2683
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
run.step = "connector";
|
|
2296
|
-
failure = await this.ensureConnector(made, connector, cust);
|
|
2297
|
-
run.step = "groups";
|
|
2298
|
-
await this.ensureGroups(made, cust);
|
|
2299
|
-
run.step = "rules";
|
|
2300
|
-
await this.ensureRules(made, settings, cust);
|
|
2301
|
-
run.step = "insights_hub";
|
|
2302
|
-
await this.ensureInsightsHub(made);
|
|
2303
|
-
const existing = cust.teams.findIndex((t) => t.locationId === made.locationId);
|
|
2304
|
-
if (existing < 0) cust.teams.push(made);
|
|
2305
|
-
else cust.teams[existing] = made;
|
|
2306
|
-
cust.pending = this.pendingOf(cust);
|
|
2307
|
-
} catch (exc) {
|
|
2308
|
-
this.stop(run, exc);
|
|
2309
|
-
}
|
|
2310
|
-
raiseConnectorFailure(failure ? [failure] : [], made);
|
|
2311
|
-
return made;
|
|
2684
|
+
raiseConnectorFailure(failure ? [failure] : [], made);
|
|
2685
|
+
return made;
|
|
2686
|
+
});
|
|
2312
2687
|
}
|
|
2313
2688
|
/**
|
|
2314
2689
|
* Create or update the three rules' phrases and sentiment levels on one team or on every team.
|
|
@@ -2317,24 +2692,33 @@ var Accounts = class _Accounts {
|
|
|
2317
2692
|
* ids of the rules created or changed.
|
|
2318
2693
|
*/
|
|
2319
2694
|
async setAlerts(customer, alerts, options = {}) {
|
|
2320
|
-
|
|
2321
|
-
|
|
2695
|
+
checkCustomerRef(customer);
|
|
2696
|
+
checkTeamRef(options?.team, false);
|
|
2322
2697
|
if (alerts === null || alerts === void 0) throw new InvalidRequestError("alerts is required");
|
|
2323
|
-
const
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
const changed = [];
|
|
2327
|
-
const run = this.run(changed);
|
|
2328
|
-
try {
|
|
2329
|
-
for (const t of teams) {
|
|
2330
|
-
run.step = `rules:${t.name}`;
|
|
2331
|
-
changed.push(...await this.ensureRules(t, settings, null));
|
|
2332
|
-
}
|
|
2333
|
-
cust.pending = this.pendingOf(cust);
|
|
2334
|
-
} catch (exc) {
|
|
2335
|
-
this.stop(run, exc);
|
|
2698
|
+
const checked = checkAlerts(alerts);
|
|
2699
|
+
if (RULE_FIELDS.every((k) => checked[k] === null || checked[k] === void 0)) {
|
|
2700
|
+
throw new InvalidRequestError("alerts sets nothing: give at least one AlertSetting");
|
|
2336
2701
|
}
|
|
2337
|
-
|
|
2702
|
+
if (isCustomerObject(customer) && options?.team !== void 0 && options.team !== null) this.teamOf(customer, options.team);
|
|
2703
|
+
return this.exclusive(async () => {
|
|
2704
|
+
await this.requireAdmin();
|
|
2705
|
+
const cust = await this.resolve(customer);
|
|
2706
|
+
const teams = this.teamsOf(cust, options?.team);
|
|
2707
|
+
await this.live(teams, ALERT_GROUPS);
|
|
2708
|
+
const settings = this.settingsFrom(checked);
|
|
2709
|
+
const changed = [];
|
|
2710
|
+
const run = this.run(changed);
|
|
2711
|
+
try {
|
|
2712
|
+
for (const t of teams) {
|
|
2713
|
+
run.step = `rules:${t.name}`;
|
|
2714
|
+
changed.push(...await this.ensureRules(t, settings, null));
|
|
2715
|
+
}
|
|
2716
|
+
cust.pending = this.pendingOf(cust);
|
|
2717
|
+
} catch (exc) {
|
|
2718
|
+
this.stop(run, exc);
|
|
2719
|
+
}
|
|
2720
|
+
return changed;
|
|
2721
|
+
});
|
|
2338
2722
|
}
|
|
2339
2723
|
/**
|
|
2340
2724
|
* Attach a phone system to a customer created without one: the named team, or the first team and
|
|
@@ -2342,84 +2726,97 @@ var Accounts = class _Accounts {
|
|
|
2342
2726
|
* Returns the teams it attached.
|
|
2343
2727
|
*/
|
|
2344
2728
|
async setConnector(customer, connector, options = {}) {
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
targets
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
const active = (await all(this.c.connectors.iterLocationConnectors(t.locationId))).filter((x) => RUNNING.includes(x.status));
|
|
2360
|
-
const same = found !== null && RUNNING.includes(found.status) && Object.entries(plainConfig(connector.config)).every(
|
|
2361
|
-
([k, v]) => !(k in (found.config ?? {})) || isSecretName(k) || deepEqual(found.config[k], v)
|
|
2362
|
-
);
|
|
2363
|
-
if (active.length && !same) throw new InvalidRequestError(`${t.name} already has an active connector`);
|
|
2364
|
-
if (same) {
|
|
2365
|
-
this.setConn(t, found);
|
|
2366
|
-
continue;
|
|
2729
|
+
checkCustomerRef(customer);
|
|
2730
|
+
checkTeamRef(options?.team, false);
|
|
2731
|
+
checkConnectorLocal(connector, true);
|
|
2732
|
+
if (isCustomerObject(customer) && options?.team !== void 0 && options.team !== null) this.teamOf(customer, options.team);
|
|
2733
|
+
return this.exclusive(async () => {
|
|
2734
|
+
await this.requireAdmin();
|
|
2735
|
+
await this.checkConnector(connector, true);
|
|
2736
|
+
const cust = await this.resolve(customer);
|
|
2737
|
+
let targets;
|
|
2738
|
+
if (options?.team !== void 0 && options.team !== null) {
|
|
2739
|
+
targets = [this.teamOf(cust, options.team)];
|
|
2740
|
+
} else {
|
|
2741
|
+
if (!cust.teams.length) throw new InvalidRequestError("This customer has no team");
|
|
2742
|
+
targets = [cust.teams[0], ...cust.management ? [cust.management] : []];
|
|
2367
2743
|
}
|
|
2368
|
-
todo
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
if (
|
|
2744
|
+
const todo = [];
|
|
2745
|
+
for (const t of targets) {
|
|
2746
|
+
const name = connector.name || `${t.name} phone system`;
|
|
2747
|
+
const found = await this.findConnector(t.locationId, connector, name);
|
|
2748
|
+
const active = (await all(this.c.connectors.iterLocationConnectors(t.locationId))).filter((x) => RUNNING.includes(x.status));
|
|
2749
|
+
const same = found !== null && RUNNING.includes(found.status) && Object.entries(plainConfig(connector.config)).every(
|
|
2750
|
+
([k, v]) => !(k in (found.config ?? {})) || isSecretName(k) || deepEqual(found.config[k], v)
|
|
2751
|
+
);
|
|
2752
|
+
if (active.length && !same) throw new InvalidRequestError(`${t.name} already has an active connector`);
|
|
2753
|
+
if (same) {
|
|
2754
|
+
this.setConn(t, found);
|
|
2755
|
+
continue;
|
|
2756
|
+
}
|
|
2757
|
+
todo.push(t);
|
|
2377
2758
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2759
|
+
const run = this.run(targets);
|
|
2760
|
+
const failures = [];
|
|
2761
|
+
try {
|
|
2762
|
+
for (const t of todo) {
|
|
2763
|
+
run.step = `connector:${t.name}`;
|
|
2764
|
+
const failure = await this.ensureConnector(t, connector, cust);
|
|
2765
|
+
if (failure) failures.push(failure);
|
|
2766
|
+
}
|
|
2767
|
+
} catch (exc) {
|
|
2768
|
+
this.stop(run, exc);
|
|
2769
|
+
}
|
|
2770
|
+
raiseConnectorFailure(failures, targets);
|
|
2771
|
+
return targets;
|
|
2772
|
+
});
|
|
2383
2773
|
}
|
|
2384
2774
|
/**
|
|
2385
2775
|
* Switch the rules on for every team. A team does not need a manager: its alerts then show in the app
|
|
2386
2776
|
* only, and the team is listed under `noManager` with the alert groups that have none.
|
|
2387
2777
|
*/
|
|
2388
2778
|
async activateAlerts(customer, options = {}) {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2779
|
+
checkCustomerRef(customer);
|
|
2780
|
+
checkTeamRef(options?.team, false);
|
|
2781
|
+
if (isCustomerObject(customer) && options?.team !== void 0 && options.team !== null) this.teamOf(customer, options.team);
|
|
2782
|
+
return this.exclusive(async () => {
|
|
2783
|
+
await this.requireAdmin();
|
|
2784
|
+
const cust = await this.resolve(customer);
|
|
2785
|
+
const out = { switchedOn: [], noManager: [] };
|
|
2786
|
+
const people = await this.index(cust);
|
|
2787
|
+
const managers = new Set([...people.values()].filter((p) => p.license === "base_manager").map((p) => p.id));
|
|
2788
|
+
const run = this.run(out);
|
|
2789
|
+
try {
|
|
2790
|
+
const wanted = this.teamsOf(cust, options?.team);
|
|
2791
|
+
await this.live(wanted);
|
|
2792
|
+
for (const t of wanted) {
|
|
2793
|
+
run.step = `activate:${t.name}`;
|
|
2794
|
+
const missing = [];
|
|
2795
|
+
for (const f of ALERT_GROUPS) {
|
|
2796
|
+
const gid = t.groups[f];
|
|
2797
|
+
let members = /* @__PURE__ */ new Set();
|
|
2798
|
+
if (gid) {
|
|
2799
|
+
const grp = unwrap(await this.c.groups.getUserGroup(t.locationId, gid)) ?? {};
|
|
2800
|
+
members = new Set((grp.members ?? []).map((m) => m.id));
|
|
2801
|
+
}
|
|
2802
|
+
if (![...members].some((m) => managers.has(m))) missing.push(TEAM_GROUPS[f]);
|
|
2405
2803
|
}
|
|
2406
|
-
if (
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
out.switchedOn.push(rid);
|
|
2804
|
+
if (missing.length) out.noManager.push({ locationId: t.locationId, team: t.name, missing });
|
|
2805
|
+
for (const key of RULE_FIELDS) {
|
|
2806
|
+
const rid = t.rules[key];
|
|
2807
|
+
if (!rid) continue;
|
|
2808
|
+
const rule = unwrap(await this.c.firstAlert.getAlertRule(t.locationId, rid)) ?? {};
|
|
2809
|
+
if (!rule.enabled) {
|
|
2810
|
+
await this.c.firstAlert.updateAlertRule(t.locationId, rid, { enabled: true });
|
|
2811
|
+
out.switchedOn.push(rid);
|
|
2812
|
+
}
|
|
2416
2813
|
}
|
|
2417
2814
|
}
|
|
2815
|
+
} catch (exc) {
|
|
2816
|
+
this.stop(run, exc);
|
|
2418
2817
|
}
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
}
|
|
2422
|
-
return out;
|
|
2818
|
+
return out;
|
|
2819
|
+
});
|
|
2423
2820
|
}
|
|
2424
2821
|
// ------------------------------------------------------------------ people: reading
|
|
2425
2822
|
/** Everyone at the customer's locations, with products and groups per location, lines and license. */
|
|
@@ -2450,8 +2847,14 @@ var Accounts = class _Accounts {
|
|
|
2450
2847
|
if (p.active) p.mappings = unwrapMappings(await c.users.getUserNumberMappings(cust.companyId, p.id));
|
|
2451
2848
|
this.classify(cust, p);
|
|
2452
2849
|
}
|
|
2850
|
+
this.lastIndex = people;
|
|
2453
2851
|
return people;
|
|
2454
2852
|
}
|
|
2853
|
+
/** All of the person's teams as the latest read saw them. */
|
|
2854
|
+
currentTeams(uid, fallback) {
|
|
2855
|
+
const p = this.lastIndex?.get(uid);
|
|
2856
|
+
return p ? [...p.teams] : fallback;
|
|
2857
|
+
}
|
|
2455
2858
|
classify(cust, p) {
|
|
2456
2859
|
const teamIds = cust.teams.map((t) => t.locationId);
|
|
2457
2860
|
const mgmt = cust.management ? cust.management.locationId : null;
|
|
@@ -2573,11 +2976,16 @@ var Accounts = class _Accounts {
|
|
|
2573
2976
|
* so it can be corrected.
|
|
2574
2977
|
*/
|
|
2575
2978
|
async listMembers(customer, options = {}) {
|
|
2576
|
-
|
|
2577
|
-
|
|
2979
|
+
checkCustomerRef(customer);
|
|
2980
|
+
checkTeamRef(options?.team, false);
|
|
2981
|
+
const license = options?.license ?? null;
|
|
2578
2982
|
if (license !== null && !LICENSES.includes(license)) throw new InvalidRequestError(`license: one of ${JSON.stringify(LICENSES)}`);
|
|
2579
|
-
|
|
2580
|
-
|
|
2983
|
+
if (isCustomerObject(customer) && options?.team !== void 0 && options.team !== null) this.teamOf(customer, options.team);
|
|
2984
|
+
await this.requireAdmin();
|
|
2985
|
+
return this.membersOf(await this.resolve(customer), license, options?.team);
|
|
2986
|
+
}
|
|
2987
|
+
async membersOf(cust, license, team) {
|
|
2988
|
+
const lid = team !== void 0 && team !== null ? this.teamOf(cust, team).locationId : null;
|
|
2581
2989
|
const out = [];
|
|
2582
2990
|
for (const p of (await this.index(cust)).values()) {
|
|
2583
2991
|
if (license !== null && p.license !== license) continue;
|
|
@@ -2588,8 +2996,10 @@ var Accounts = class _Accounts {
|
|
|
2588
2996
|
}
|
|
2589
2997
|
/** People by license and the number of teams (Management not counted). */
|
|
2590
2998
|
async licenseReport(customer) {
|
|
2999
|
+
checkCustomerRef(customer);
|
|
3000
|
+
await this.requireAdmin();
|
|
2591
3001
|
const cust = await this.resolve(customer);
|
|
2592
|
-
const members = await this.
|
|
3002
|
+
const members = await this.membersOf(cust, null);
|
|
2593
3003
|
const by = { baseUser: [], baseManager: [], integration: [], other: [] };
|
|
2594
3004
|
for (const m of members) {
|
|
2595
3005
|
if (m.license === "base_user") by.baseUser.push(m);
|
|
@@ -2786,35 +3196,43 @@ var Accounts = class _Accounts {
|
|
|
2786
3196
|
* AccountError (cause ExtensionMappingError) is thrown and no invitation is sent.
|
|
2787
3197
|
*/
|
|
2788
3198
|
async addBaseUser(customer, person, options) {
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
const ln = line(options
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
const
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
3199
|
+
checkCustomerRef(customer);
|
|
3200
|
+
checkPerson(person);
|
|
3201
|
+
checkTeamRef(options?.team);
|
|
3202
|
+
const ln = line(options?.line);
|
|
3203
|
+
bool(options?.invite, "invite");
|
|
3204
|
+
if (isCustomerObject(customer)) this.teamOf(customer, options.team);
|
|
3205
|
+
return this.exclusive(async () => {
|
|
3206
|
+
await this.requireAdmin();
|
|
3207
|
+
const cust = await this.resolve(customer);
|
|
3208
|
+
const t = this.teamOf(cust, options.team);
|
|
3209
|
+
this.needConnector(t);
|
|
3210
|
+
await this.checkExisting(cust, person.email, "base_user");
|
|
3211
|
+
const result = newMember("", person.email, "base_user", [t.locationId], [ln]);
|
|
3212
|
+
const run = this.run(result);
|
|
3213
|
+
try {
|
|
3214
|
+
run.step = "monitor_all";
|
|
3215
|
+
await this.monitorAllOff(t.locationId);
|
|
3216
|
+
run.step = "user";
|
|
3217
|
+
const [uid, created, detail] = await this.ensureUser(cust, person, [t.locationId]);
|
|
3218
|
+
result.userId = uid;
|
|
3219
|
+
result.created = created;
|
|
3220
|
+
run.step = "products";
|
|
3221
|
+
await this.productsOn(t.locationId, uid, [AFTER_CALL]);
|
|
3222
|
+
run.step = "alert_email";
|
|
3223
|
+
await this.emailOff(t.locationId, uid, created, detail.status);
|
|
3224
|
+
run.step = "line";
|
|
3225
|
+
await this.map(cust, uid, t.connectorId, [ln]);
|
|
3226
|
+
run.step = "team_lines";
|
|
3227
|
+
await this.attachLine(cust, t, ln, await this.index(cust), [uid]);
|
|
3228
|
+
run.step = "invitation";
|
|
3229
|
+
result.invited = await this.invite(cust, uid, options.invite ?? true);
|
|
3230
|
+
result.teams = this.currentTeams(uid, result.teams);
|
|
3231
|
+
} catch (exc) {
|
|
3232
|
+
this.stop(run, exc);
|
|
3233
|
+
}
|
|
3234
|
+
return result;
|
|
3235
|
+
});
|
|
2818
3236
|
}
|
|
2819
3237
|
/**
|
|
2820
3238
|
* Add a Base Manager on each team and on Management: all three products; their own line at
|
|
@@ -2823,31 +3241,42 @@ var Accounts = class _Accounts {
|
|
|
2823
3241
|
* with `companyReports: true`); alert email off. The invitation is sent last.
|
|
2824
3242
|
*/
|
|
2825
3243
|
async addBaseManager(customer, person, options) {
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
const teams = options?.teams;
|
|
2829
|
-
if (!
|
|
2830
|
-
const
|
|
2831
|
-
if (cust.management === null) throw new InvalidRequestError("This customer has no Management location: run createCustomer again");
|
|
3244
|
+
checkCustomerRef(customer);
|
|
3245
|
+
checkPerson(person);
|
|
3246
|
+
const teams = list2(options?.teams, "teams");
|
|
3247
|
+
if (!teams.length) throw new InvalidRequestError("teams: a list of one or more teams");
|
|
3248
|
+
for (const x of teams) checkTeamRef(x);
|
|
2832
3249
|
const own = options.line !== void 0 && options.line !== null ? line(options.line) : null;
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
3250
|
+
bool(options.invite, "invite");
|
|
3251
|
+
bool(options.companyReports, "companyReports");
|
|
3252
|
+
if (isCustomerObject(customer)) for (const x of teams) this.teamOf(customer, x);
|
|
3253
|
+
return this.exclusive(async () => {
|
|
3254
|
+
await this.requireAdmin();
|
|
3255
|
+
const cust = await this.resolve(customer);
|
|
3256
|
+
const ts = dedupeTeams(teams.map((x) => this.teamOf(cust, x)));
|
|
3257
|
+
await this.live(ts, GROUP_FIELDS);
|
|
3258
|
+
if (options.companyReports && cust.management) await this.live([cust.management], ["weeklyReports"]);
|
|
3259
|
+
if (cust.management === null) throw new InvalidRequestError("This customer has no Management location: run createCustomer again");
|
|
3260
|
+
if (own) this.needConnector(cust.management);
|
|
3261
|
+
await this.checkExisting(cust, person.email, "base_manager");
|
|
3262
|
+
const result = newMember("", person.email, "base_manager", ts.map((t) => t.locationId));
|
|
3263
|
+
const run = this.run(result);
|
|
3264
|
+
try {
|
|
3265
|
+
run.step = "monitor_all";
|
|
3266
|
+
for (const t of ts) await this.monitorAllOff(t.locationId);
|
|
3267
|
+
run.step = "user";
|
|
3268
|
+
const [uid, created, detail] = await this.ensureUser(cust, person, [...ts.map((t) => t.locationId), cust.management.locationId]);
|
|
3269
|
+
result.userId = uid;
|
|
3270
|
+
result.created = created;
|
|
3271
|
+
result.lines = await this.managerSetup(cust, uid, ts, own, !!options.companyReports, created, detail.status, run);
|
|
3272
|
+
result.teams = this.currentTeams(uid, result.teams);
|
|
3273
|
+
run.step = "invitation";
|
|
3274
|
+
result.invited = await this.invite(cust, uid, options.invite ?? true);
|
|
3275
|
+
} catch (exc) {
|
|
3276
|
+
this.stop(run, exc);
|
|
3277
|
+
}
|
|
3278
|
+
return result;
|
|
3279
|
+
});
|
|
2851
3280
|
}
|
|
2852
3281
|
/**
|
|
2853
3282
|
* Add the customer's integration (data-reading) user across every team: password sign-in, tagged
|
|
@@ -2856,46 +3285,52 @@ var Accounts = class _Accounts {
|
|
|
2856
3285
|
* (`CustomerSpec.mfaOff`) for it to sign in.
|
|
2857
3286
|
*/
|
|
2858
3287
|
async addIntegrationUser(customer, person, options = {}) {
|
|
2859
|
-
|
|
3288
|
+
checkCustomerRef(customer);
|
|
3289
|
+
checkPerson(person);
|
|
2860
3290
|
if ((person.authMethod ?? "password") !== "password") {
|
|
2861
3291
|
throw new InvalidRequestError('An integration user signs in with a password: set authMethod: "password"');
|
|
2862
3292
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
const
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
3293
|
+
bool(options?.invite, "invite");
|
|
3294
|
+
return this.exclusive(async () => {
|
|
3295
|
+
await this.requireAdmin();
|
|
3296
|
+
const cust = await this.resolve(customer);
|
|
3297
|
+
if (!cust.teams.length) throw new InvalidRequestError("This customer has no team");
|
|
3298
|
+
await this.live(cust.teams, [...ALERT_GROUPS, "insightsHubAccess"]);
|
|
3299
|
+
await this.checkExisting(cust, person.email, "integration");
|
|
3300
|
+
const result = newMember("", person.email, "integration", cust.teams.map((t) => t.locationId));
|
|
3301
|
+
const run = this.run(result);
|
|
3302
|
+
try {
|
|
3303
|
+
run.step = "user";
|
|
3304
|
+
const [uid, created] = await this.ensureUser(cust, person, cust.teams.map((t) => t.locationId));
|
|
3305
|
+
result.userId = uid;
|
|
3306
|
+
result.created = created;
|
|
3307
|
+
run.step = "tag";
|
|
3308
|
+
const detail = unwrap(await this.c.users.getCompanyUser(cust.companyId, uid)) ?? {};
|
|
3309
|
+
if (!isIntegration(detail)) await this.c.users.updateCompanyUser(cust.companyId, uid, { department: INTEGRATION_DEPARTMENT });
|
|
3310
|
+
run.step = "products";
|
|
3311
|
+
for (const t of cust.teams) await this.productsOn(t.locationId, uid, PRODUCT_KEYS);
|
|
3312
|
+
run.step = "groups";
|
|
3313
|
+
for (const t of cust.teams) {
|
|
3314
|
+
await this.joinGroups(t.locationId, uid, [...ALERT_GROUPS, "insightsHubAccess"].map((f) => t.groups[f]));
|
|
3315
|
+
}
|
|
3316
|
+
run.step = "alert_email";
|
|
3317
|
+
for (const t of cust.teams) await this.emailOff(t.locationId, uid, created, detail.status);
|
|
3318
|
+
run.step = "lines";
|
|
3319
|
+
const people = await this.index(cust);
|
|
3320
|
+
const current = people.get(uid)?.mappings ?? [];
|
|
3321
|
+
let mappings = current.map((m) => ({ ...m }));
|
|
3322
|
+
for (const t of cust.teams) {
|
|
3323
|
+
if (t.connectorId) mappings = mergeMappings(mappings, t.connectorId, this.teamLines(t, people, [uid]));
|
|
3324
|
+
}
|
|
3325
|
+
if (!sameMappings(mappings, current)) await this.setMappings(cust, uid, mappings);
|
|
3326
|
+
result.lines = numbersOf(mappings);
|
|
3327
|
+
run.step = "invitation";
|
|
3328
|
+
result.invited = await this.invite(cust, uid, options.invite ?? true);
|
|
3329
|
+
} catch (exc) {
|
|
3330
|
+
this.stop(run, exc);
|
|
2890
3331
|
}
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
run.step = "invitation";
|
|
2894
|
-
result.invited = await this.invite(cust, uid, options.invite ?? true);
|
|
2895
|
-
} catch (exc) {
|
|
2896
|
-
this.stop(run, exc);
|
|
2897
|
-
}
|
|
2898
|
-
return result;
|
|
3332
|
+
return result;
|
|
3333
|
+
});
|
|
2899
3334
|
}
|
|
2900
3335
|
/**
|
|
2901
3336
|
* Base User to Base Manager (`to: "base_manager"`): their own line moves to Management and they get
|
|
@@ -2910,28 +3345,41 @@ var Accounts = class _Accounts {
|
|
|
2910
3345
|
* person had before.
|
|
2911
3346
|
*/
|
|
2912
3347
|
async changeLicense(customer, userId, to, options = {}) {
|
|
2913
|
-
|
|
3348
|
+
checkCustomerRef(customer);
|
|
3349
|
+
checkUserId(userId);
|
|
2914
3350
|
if (to !== "base_user" && to !== "base_manager") throw new InvalidRequestError('to: "base_user" or "base_manager"');
|
|
2915
|
-
|
|
2916
|
-
if (
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
const ts = options.teams?.length ? dedupeTeams(options.teams.map((x) => this.teamOf(cust, x))) : cust.teams.filter((t) => p.teams.includes(t.locationId));
|
|
2922
|
-
if (!ts.length) throw new InvalidRequestError("teams: the person is on no team; pass teams");
|
|
2923
|
-
const result = this.member(p);
|
|
2924
|
-
const run = this.run(result);
|
|
2925
|
-
try {
|
|
2926
|
-
if (to === "base_manager") await this.toManager(cust, p, people, ts, options.line ?? null, run, result);
|
|
2927
|
-
else await this.toUser(cust, p, people, ts[0], options.line ?? null, run, result);
|
|
2928
|
-
} catch (exc) {
|
|
2929
|
-
this.stop(run, exc);
|
|
3351
|
+
let teamList = null;
|
|
3352
|
+
if (options?.teams !== void 0 && options.teams !== null) {
|
|
3353
|
+
teamList = list2(options.teams, "teams");
|
|
3354
|
+
if (!teamList.length) throw new InvalidRequestError("teams: a list of one or more teams");
|
|
3355
|
+
for (const x of teamList) checkTeamRef(x);
|
|
3356
|
+
if (isCustomerObject(customer)) for (const x of teamList) this.teamOf(customer, x);
|
|
2930
3357
|
}
|
|
2931
|
-
|
|
3358
|
+
if (options?.line !== void 0 && options.line !== null) line(options.line);
|
|
3359
|
+
return this.exclusive(async () => {
|
|
3360
|
+
await this.requireAdmin();
|
|
3361
|
+
const cust = await this.resolve(customer);
|
|
3362
|
+
if (cust.management === null) throw new InvalidRequestError("This customer has no Management location: run createCustomer again");
|
|
3363
|
+
const [p, people] = await this.person(cust, userId);
|
|
3364
|
+
if (p.license !== "base_user" && p.license !== "base_manager" && p.license !== "other") {
|
|
3365
|
+
throw new InvalidRequestError(`User ${userId} is "${p.license}"; only Base Users and Base Managers change license`);
|
|
3366
|
+
}
|
|
3367
|
+
const ts = teamList?.length ? dedupeTeams(teamList.map((x) => this.teamOf(cust, x))) : cust.teams.filter((t) => p.teams.includes(t.locationId));
|
|
3368
|
+
if (!ts.length) throw new InvalidRequestError("teams: the person is on no team; pass teams");
|
|
3369
|
+
const result = this.member(p);
|
|
3370
|
+
const run = this.run(result);
|
|
3371
|
+
try {
|
|
3372
|
+
if (to === "base_manager") await this.toManager(cust, p, people, ts, options.line ?? null, run, result);
|
|
3373
|
+
else await this.toUser(cust, p, people, ts[0], options.line ?? null, run, result);
|
|
3374
|
+
} catch (exc) {
|
|
3375
|
+
this.stop(run, exc);
|
|
3376
|
+
}
|
|
3377
|
+
return result;
|
|
3378
|
+
});
|
|
2932
3379
|
}
|
|
2933
3380
|
async toManager(cust, p, people, ts, lineArg, run, result) {
|
|
2934
3381
|
const mgmt = cust.management;
|
|
3382
|
+
await this.live(ts, GROUP_FIELDS);
|
|
2935
3383
|
const stray = [];
|
|
2936
3384
|
for (const t of cust.teams) {
|
|
2937
3385
|
if (t.connectorId) {
|
|
@@ -3008,55 +3456,66 @@ var Accounts = class _Accounts {
|
|
|
3008
3456
|
* run again, also after an AccountError: the move continues.
|
|
3009
3457
|
*/
|
|
3010
3458
|
async moveUser(customer, userId, options) {
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
const
|
|
3016
|
-
if (
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
const result = this.member(p);
|
|
3020
|
-
result.notes.push(note);
|
|
3021
|
-
if (!p.teams.includes(src.locationId) && p.teams.includes(dst.locationId)) return result;
|
|
3022
|
-
if (!p.teams.includes(src.locationId)) throw new InvalidRequestError(`User ${userId} is not on ${src.name}`);
|
|
3023
|
-
if (p.license === "integration") throw new InvalidRequestError(`User ${userId} is an integration user; it is on every team already`);
|
|
3024
|
-
const run = this.run(result);
|
|
3025
|
-
try {
|
|
3026
|
-
if (p.license === "base_manager") {
|
|
3027
|
-
await this.moveManager(cust, p, people, src, dst, run, result);
|
|
3028
|
-
} else {
|
|
3029
|
-
this.needConnector(dst);
|
|
3030
|
-
const nums = uniq([...src.connectorId ? p.numbers(src.connectorId) : [], ...p.numbers(dst.connectorId)]);
|
|
3031
|
-
if (nums.length !== 1) throw new InvalidRequestError("A Base User holds exactly one line; fix it with changeLine first");
|
|
3032
|
-
const ln = nums[0];
|
|
3033
|
-
run.step = "monitor_all";
|
|
3034
|
-
for (const t of [src, dst]) await this.monitorAllOff(t.locationId);
|
|
3035
|
-
run.step = "release_line";
|
|
3036
|
-
await this.releaseLine(cust, src, ln, people, p.id);
|
|
3037
|
-
run.step = "locations";
|
|
3038
|
-
await this.addLocations(cust, p.id, [dst.locationId]);
|
|
3039
|
-
run.step = "products";
|
|
3040
|
-
await this.productsOn(dst.locationId, p.id, [AFTER_CALL]);
|
|
3041
|
-
run.step = "alert_email";
|
|
3042
|
-
const status = (unwrap(await this.c.users.getCompanyUser(cust.companyId, p.id)) ?? {}).status;
|
|
3043
|
-
await this.emailOff(dst.locationId, p.id, false, status);
|
|
3044
|
-
run.step = "line";
|
|
3045
|
-
const target = mergeMappings(p.mappings.filter((m) => m.connector_id !== src.connectorId), dst.connectorId, [ln]);
|
|
3046
|
-
if (!sameMappings(target, p.mappings)) await this.setMappings(cust, p.id, target);
|
|
3047
|
-
run.step = "team_lines";
|
|
3048
|
-
await this.attachLine(cust, dst, ln, await this.index(cust), [p.id]);
|
|
3049
|
-
run.step = "leave_team";
|
|
3050
|
-
await this.removeLocations(cust, p.id, [src.locationId]);
|
|
3051
|
-
result.teams = [dst.locationId];
|
|
3052
|
-
result.lines = [ln];
|
|
3053
|
-
}
|
|
3054
|
-
} catch (exc) {
|
|
3055
|
-
this.stop(run, exc);
|
|
3459
|
+
checkCustomerRef(customer);
|
|
3460
|
+
checkUserId(userId);
|
|
3461
|
+
checkTeamRef(options?.fromTeam);
|
|
3462
|
+
checkTeamRef(options?.toTeam);
|
|
3463
|
+
const idOf = (t) => isTeamObject(t) ? t.locationId : t;
|
|
3464
|
+
if (idOf(options.fromTeam) === idOf(options.toTeam)) throw new InvalidRequestError("fromTeam and toTeam are the same team");
|
|
3465
|
+
if (isCustomerObject(customer) && this.teamOf(customer, options.fromTeam).locationId === this.teamOf(customer, options.toTeam).locationId) {
|
|
3466
|
+
throw new InvalidRequestError("fromTeam and toTeam are the same team");
|
|
3056
3467
|
}
|
|
3057
|
-
return
|
|
3468
|
+
return this.exclusive(async () => {
|
|
3469
|
+
await this.requireAdmin();
|
|
3470
|
+
const cust = await this.resolve(customer);
|
|
3471
|
+
const src = this.teamOf(cust, options.fromTeam);
|
|
3472
|
+
const dst = this.teamOf(cust, options.toTeam);
|
|
3473
|
+
if (src.locationId === dst.locationId) throw new InvalidRequestError("fromTeam and toTeam are the same team");
|
|
3474
|
+
const [p, people] = await this.person(cust, userId);
|
|
3475
|
+
const note = `Call history stays with ${src.name}: calls captured before the move remain there.`;
|
|
3476
|
+
const result = this.member(p);
|
|
3477
|
+
result.notes.push(note);
|
|
3478
|
+
if (!p.teams.includes(src.locationId) && p.teams.includes(dst.locationId)) return result;
|
|
3479
|
+
if (!p.teams.includes(src.locationId)) throw new InvalidRequestError(`User ${userId} is not on ${src.name}`);
|
|
3480
|
+
if (p.license === "integration") throw new InvalidRequestError(`User ${userId} is an integration user; it is on every team already`);
|
|
3481
|
+
const run = this.run(result);
|
|
3482
|
+
try {
|
|
3483
|
+
if (p.license === "base_manager") {
|
|
3484
|
+
await this.moveManager(cust, p, people, src, dst, run, result);
|
|
3485
|
+
} else {
|
|
3486
|
+
this.needConnector(dst);
|
|
3487
|
+
const nums = uniq([...src.connectorId ? p.numbers(src.connectorId) : [], ...p.numbers(dst.connectorId)]);
|
|
3488
|
+
if (nums.length !== 1) throw new InvalidRequestError("A Base User holds exactly one line; fix it with changeLine first");
|
|
3489
|
+
const ln = nums[0];
|
|
3490
|
+
run.step = "monitor_all";
|
|
3491
|
+
for (const t of [src, dst]) await this.monitorAllOff(t.locationId);
|
|
3492
|
+
run.step = "release_line";
|
|
3493
|
+
await this.releaseLine(cust, src, ln, people, p.id);
|
|
3494
|
+
run.step = "locations";
|
|
3495
|
+
await this.addLocations(cust, p.id, [dst.locationId]);
|
|
3496
|
+
run.step = "products";
|
|
3497
|
+
await this.productsOn(dst.locationId, p.id, [AFTER_CALL]);
|
|
3498
|
+
run.step = "alert_email";
|
|
3499
|
+
const status = (unwrap(await this.c.users.getCompanyUser(cust.companyId, p.id)) ?? {}).status;
|
|
3500
|
+
await this.emailOff(dst.locationId, p.id, false, status);
|
|
3501
|
+
run.step = "line";
|
|
3502
|
+
const target = mergeMappings(p.mappings.filter((m) => m.connector_id !== src.connectorId), dst.connectorId, [ln]);
|
|
3503
|
+
if (!sameMappings(target, p.mappings)) await this.setMappings(cust, p.id, target);
|
|
3504
|
+
run.step = "team_lines";
|
|
3505
|
+
await this.attachLine(cust, dst, ln, await this.index(cust), [p.id]);
|
|
3506
|
+
run.step = "leave_team";
|
|
3507
|
+
await this.removeLocations(cust, p.id, [src.locationId]);
|
|
3508
|
+
result.teams = [dst.locationId];
|
|
3509
|
+
result.lines = [ln];
|
|
3510
|
+
}
|
|
3511
|
+
} catch (exc) {
|
|
3512
|
+
this.stop(run, exc);
|
|
3513
|
+
}
|
|
3514
|
+
return result;
|
|
3515
|
+
});
|
|
3058
3516
|
}
|
|
3059
3517
|
async moveManager(cust, p, people, src, dst, run, result) {
|
|
3518
|
+
await this.live([dst], GROUP_FIELDS);
|
|
3060
3519
|
const notes = this.emptiedGroups(cust, people, p.id, [src.locationId]);
|
|
3061
3520
|
run.step = "locations";
|
|
3062
3521
|
await this.addLocations(cust, p.id, [dst.locationId]);
|
|
@@ -3089,68 +3548,73 @@ var Accounts = class _Accounts {
|
|
|
3089
3548
|
* the manager's own line.
|
|
3090
3549
|
*/
|
|
3091
3550
|
async changeLine(customer, userId, oldLine, newLine) {
|
|
3092
|
-
|
|
3551
|
+
checkCustomerRef(customer);
|
|
3552
|
+
checkUserId(userId);
|
|
3093
3553
|
const old = line(oldLine, "old");
|
|
3094
3554
|
const nw = line(newLine, "new");
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
const
|
|
3102
|
-
if (
|
|
3103
|
-
|
|
3555
|
+
if (old === nw) throw new InvalidRequestError("old and new are the same line");
|
|
3556
|
+
return this.exclusive(async () => {
|
|
3557
|
+
await this.requireAdmin();
|
|
3558
|
+
const cust = await this.resolve(customer);
|
|
3559
|
+
const [p, people] = await this.person(cust, userId);
|
|
3560
|
+
const result = this.member(p);
|
|
3561
|
+
const mgmt = cust.management;
|
|
3562
|
+
if (p.license === "integration") throw new InvalidRequestError("An integration user holds every line; it has no line of its own");
|
|
3563
|
+
if (p.license === "base_manager") {
|
|
3564
|
+
const mine = mgmt && mgmt.connectorId ? p.numbers(mgmt.connectorId) : [];
|
|
3565
|
+
if (!mine.includes(old) && !mine.includes(nw)) {
|
|
3566
|
+
throw new InvalidRequestError(`${old} is not this manager's own line; a team line changes with the Base User who holds it`);
|
|
3567
|
+
}
|
|
3568
|
+
const run2 = this.run(result);
|
|
3569
|
+
try {
|
|
3570
|
+
run2.step = "line";
|
|
3571
|
+
if (mine.includes(old)) {
|
|
3572
|
+
await this.map(cust, p.id, mgmt.connectorId, uniq(mine.map((n) => n === old ? nw : n)), p.mappings);
|
|
3573
|
+
result.lines = result.lines.map((n) => n === old ? nw : n);
|
|
3574
|
+
}
|
|
3575
|
+
} catch (exc) {
|
|
3576
|
+
this.stop(run2, exc);
|
|
3577
|
+
}
|
|
3578
|
+
return result;
|
|
3104
3579
|
}
|
|
3105
|
-
const
|
|
3580
|
+
const team = cust.teams.find(
|
|
3581
|
+
(t) => t.connectorId && p.teams.includes(t.locationId) && (p.numbers(t.connectorId).includes(old) || p.numbers(t.connectorId).includes(nw))
|
|
3582
|
+
);
|
|
3583
|
+
if (team === void 0) throw new InvalidRequestError(`${old} is not one of this person's lines`);
|
|
3584
|
+
const cid = team.connectorId;
|
|
3585
|
+
const shared = [...this.owners(team, people, [p.id]).values()].includes(old);
|
|
3586
|
+
const run = this.run(result);
|
|
3587
|
+
const swap = (have) => {
|
|
3588
|
+
const out = shared ? [...have] : have.filter((n) => n !== old);
|
|
3589
|
+
return out.includes(nw) ? out : [...out, nw];
|
|
3590
|
+
};
|
|
3106
3591
|
try {
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3592
|
+
run.step = "monitor_all";
|
|
3593
|
+
await this.monitorAllOff(team.locationId);
|
|
3594
|
+
run.step = "line";
|
|
3595
|
+
const nums = p.numbers(cid);
|
|
3596
|
+
if (nums.includes(old)) {
|
|
3597
|
+
await this.map(cust, p.id, cid, uniq(nums.map((n) => n === old ? nw : n)), p.mappings);
|
|
3598
|
+
result.lines = uniq(result.lines.map((n) => n === old ? nw : n));
|
|
3599
|
+
}
|
|
3600
|
+
run.step = "team_lines";
|
|
3601
|
+
for (const h of this.holders(team, people, [p.id])) {
|
|
3602
|
+
const have = h.numbers(cid);
|
|
3603
|
+
if (!deepEqual(swap(have), have)) await this.map(cust, h.id, cid, swap(have), h.mappings);
|
|
3604
|
+
}
|
|
3605
|
+
const targets = [
|
|
3606
|
+
[() => this.faNumbers(team), (n) => this.c.firstAlert.setMonitoredNumbers(team.locationId, cid, n)],
|
|
3607
|
+
[() => this.ihNumbers(team), (n) => this.c.insightsHub.setNumbers(team.locationId, cid, n)]
|
|
3608
|
+
];
|
|
3609
|
+
for (const [getter, setter] of targets) {
|
|
3610
|
+
const have = await getter();
|
|
3611
|
+
if (!deepEqual(swap(have), have)) await setter(swap(have));
|
|
3111
3612
|
}
|
|
3112
3613
|
} catch (exc) {
|
|
3113
|
-
this.stop(
|
|
3614
|
+
this.stop(run, exc);
|
|
3114
3615
|
}
|
|
3115
3616
|
return result;
|
|
3116
|
-
}
|
|
3117
|
-
const team = cust.teams.find(
|
|
3118
|
-
(t) => t.connectorId && p.teams.includes(t.locationId) && (p.numbers(t.connectorId).includes(old) || p.numbers(t.connectorId).includes(nw))
|
|
3119
|
-
);
|
|
3120
|
-
if (team === void 0) throw new InvalidRequestError(`${old} is not one of this person's lines`);
|
|
3121
|
-
const cid = team.connectorId;
|
|
3122
|
-
const shared = [...this.owners(team, people, [p.id]).values()].includes(old);
|
|
3123
|
-
const run = this.run(result);
|
|
3124
|
-
const swap = (have) => {
|
|
3125
|
-
const out = shared ? [...have] : have.filter((n) => n !== old);
|
|
3126
|
-
return out.includes(nw) ? out : [...out, nw];
|
|
3127
|
-
};
|
|
3128
|
-
try {
|
|
3129
|
-
run.step = "monitor_all";
|
|
3130
|
-
await this.monitorAllOff(team.locationId);
|
|
3131
|
-
run.step = "line";
|
|
3132
|
-
const nums = p.numbers(cid);
|
|
3133
|
-
if (nums.includes(old)) {
|
|
3134
|
-
await this.map(cust, p.id, cid, uniq(nums.map((n) => n === old ? nw : n)), p.mappings);
|
|
3135
|
-
result.lines = uniq(result.lines.map((n) => n === old ? nw : n));
|
|
3136
|
-
}
|
|
3137
|
-
run.step = "team_lines";
|
|
3138
|
-
for (const h of this.holders(team, people, [p.id])) {
|
|
3139
|
-
const have = h.numbers(cid);
|
|
3140
|
-
if (!deepEqual(swap(have), have)) await this.map(cust, h.id, cid, swap(have), h.mappings);
|
|
3141
|
-
}
|
|
3142
|
-
const targets = [
|
|
3143
|
-
[() => this.faNumbers(team), (n) => this.c.firstAlert.setMonitoredNumbers(team.locationId, cid, n)],
|
|
3144
|
-
[() => this.ihNumbers(team), (n) => this.c.insightsHub.setNumbers(team.locationId, cid, n)]
|
|
3145
|
-
];
|
|
3146
|
-
for (const [getter, setter] of targets) {
|
|
3147
|
-
const have = await getter();
|
|
3148
|
-
if (!deepEqual(swap(have), have)) await setter(swap(have));
|
|
3149
|
-
}
|
|
3150
|
-
} catch (exc) {
|
|
3151
|
-
this.stop(run, exc);
|
|
3152
|
-
}
|
|
3153
|
-
return result;
|
|
3617
|
+
});
|
|
3154
3618
|
}
|
|
3155
3619
|
/**
|
|
3156
3620
|
* Take the person out of every group, release a Base User's line (unless `keepLines`, and only when
|
|
@@ -3159,49 +3623,54 @@ var Accounts = class _Accounts {
|
|
|
3159
3623
|
* alert groups are left with no Base Manager (its alerts are not changed).
|
|
3160
3624
|
*/
|
|
3161
3625
|
async removeUser(customer, userId, options = {}) {
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
this.
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
run
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3626
|
+
checkCustomerRef(customer);
|
|
3627
|
+
checkUserId(userId);
|
|
3628
|
+
bool(options?.keepLines, "keepLines");
|
|
3629
|
+
return this.exclusive(async () => {
|
|
3630
|
+
await this.requireAdmin();
|
|
3631
|
+
const cust = await this.resolve(customer);
|
|
3632
|
+
const [p, people] = await this.person(cust, userId, true);
|
|
3633
|
+
if (!p.active) {
|
|
3634
|
+
p.mappings = unwrapMappings(await this.c.users.getUserNumberMappings(cust.companyId, p.id));
|
|
3635
|
+
this.classify(cust, p);
|
|
3636
|
+
}
|
|
3637
|
+
const out = {
|
|
3638
|
+
userId,
|
|
3639
|
+
license: p.license,
|
|
3640
|
+
releasedLines: [],
|
|
3641
|
+
deactivated: false,
|
|
3642
|
+
notes: p.active ? this.emptiedGroups(cust, people, p.id, p.teams) : []
|
|
3643
|
+
};
|
|
3644
|
+
const run = this.run(out);
|
|
3645
|
+
try {
|
|
3646
|
+
run.step = "groups";
|
|
3647
|
+
for (const t of this.locationsOf(cust)) if (p.locs.has(t.locationId)) await this.leaveGroups(t.locationId, p.id);
|
|
3648
|
+
run.step = "release_lines";
|
|
3649
|
+
if (p.license === "base_user" && !options.keepLines) {
|
|
3650
|
+
for (const t of cust.teams) {
|
|
3651
|
+
if (p.teams.includes(t.locationId) && t.connectorId) {
|
|
3652
|
+
for (const n of p.numbers(t.connectorId)) {
|
|
3653
|
+
if (await this.releaseLine(cust, t, n, people, p.id)) out.releasedLines.push(n);
|
|
3654
|
+
}
|
|
3186
3655
|
}
|
|
3187
3656
|
}
|
|
3188
3657
|
}
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3658
|
+
run.step = "lines";
|
|
3659
|
+
if (p.mappings.length) await this.setMappings(cust, p.id, []);
|
|
3660
|
+
run.step = "deactivate";
|
|
3661
|
+
if (p.active) {
|
|
3662
|
+
try {
|
|
3663
|
+
await this.c.users.deactivateCompanyUser(cust.companyId, p.id);
|
|
3664
|
+
out.deactivated = true;
|
|
3665
|
+
} catch (exc) {
|
|
3666
|
+
if (!(exc instanceof ConflictError)) throw exc;
|
|
3667
|
+
}
|
|
3199
3668
|
}
|
|
3669
|
+
} catch (exc) {
|
|
3670
|
+
this.stop(run, exc);
|
|
3200
3671
|
}
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
}
|
|
3204
|
-
return out;
|
|
3672
|
+
return out;
|
|
3673
|
+
});
|
|
3205
3674
|
}
|
|
3206
3675
|
/**
|
|
3207
3676
|
* Email invitations to people who have not signed in. Without `userIds`: everyone who was never
|
|
@@ -3209,28 +3678,36 @@ var Accounts = class _Accounts {
|
|
|
3209
3678
|
* signed in. Returns the ids invited.
|
|
3210
3679
|
*/
|
|
3211
3680
|
async sendInvitations(customer, options = {}) {
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3681
|
+
checkCustomerRef(customer);
|
|
3682
|
+
let ids = null;
|
|
3683
|
+
if (options?.userIds !== void 0 && options.userIds !== null) {
|
|
3684
|
+
ids = list2(options.userIds, "userIds");
|
|
3685
|
+
for (const u of ids) checkUserId(u);
|
|
3686
|
+
}
|
|
3687
|
+
return this.exclusive(async () => {
|
|
3688
|
+
await this.requireAdmin();
|
|
3689
|
+
const cust = await this.resolve(customer);
|
|
3690
|
+
const now = /* @__PURE__ */ new Date();
|
|
3691
|
+
const wanted = ids ? new Set(ids) : null;
|
|
3692
|
+
const sent = [];
|
|
3693
|
+
const run = this.run(sent);
|
|
3694
|
+
try {
|
|
3695
|
+
for (const p of (await this.index(cust)).values()) {
|
|
3696
|
+
if (p.status !== "invited") continue;
|
|
3697
|
+
if (wanted !== null) {
|
|
3698
|
+
if (!wanted.has(p.id)) continue;
|
|
3699
|
+
} else if (p.invitedAt && !expired(p.inviteExpiresAt, now)) {
|
|
3700
|
+
continue;
|
|
3701
|
+
}
|
|
3702
|
+
run.step = `invite:${p.id}`;
|
|
3703
|
+
await this.c.users.resendInvitation(cust.companyId, p.id);
|
|
3704
|
+
sent.push(p.id);
|
|
3225
3705
|
}
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
sent.push(p.id);
|
|
3706
|
+
} catch (exc) {
|
|
3707
|
+
this.stop(run, exc);
|
|
3229
3708
|
}
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
}
|
|
3233
|
-
return sent;
|
|
3709
|
+
return sent;
|
|
3710
|
+
});
|
|
3234
3711
|
}
|
|
3235
3712
|
// ------------------------------------------------------------------ lines
|
|
3236
3713
|
/**
|
|
@@ -3243,49 +3720,53 @@ var Accounts = class _Accounts {
|
|
|
3243
3720
|
* read back as "other" (listed under `other`): their line is never released.
|
|
3244
3721
|
*/
|
|
3245
3722
|
async syncLines(customer, options = {}) {
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
const
|
|
3254
|
-
const
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
const
|
|
3269
|
-
|
|
3723
|
+
checkCustomerRef(customer);
|
|
3724
|
+
bool(options?.dryRun, "dryRun");
|
|
3725
|
+
return this.exclusive(async () => {
|
|
3726
|
+
await this.requireAdmin();
|
|
3727
|
+
const cust = await this.resolve(customer);
|
|
3728
|
+
const people = await this.index(cust);
|
|
3729
|
+
const diff = { teams: {}, applied: false };
|
|
3730
|
+
const plans = [];
|
|
3731
|
+
for (const t of cust.teams) {
|
|
3732
|
+
if (!t.connectorId) continue;
|
|
3733
|
+
const owners = this.owners(t, people);
|
|
3734
|
+
const lines = uniq(owners.values());
|
|
3735
|
+
const fa = await this.faNumbers(t);
|
|
3736
|
+
const ih = await this.ihNumbers(t);
|
|
3737
|
+
const d = {
|
|
3738
|
+
team: t.name,
|
|
3739
|
+
lines,
|
|
3740
|
+
other: [...owners.keys()].filter((uid) => people.get(uid).license === "other"),
|
|
3741
|
+
firstAlert: { add: lines.filter((n) => !fa.includes(n)), remove: fa.filter((n) => !lines.includes(n)) },
|
|
3742
|
+
insightsHub: { add: lines.filter((n) => !ih.includes(n)), remove: ih.filter((n) => !lines.includes(n)) },
|
|
3743
|
+
holders: {}
|
|
3744
|
+
};
|
|
3745
|
+
for (const h of this.holders(t, people)) {
|
|
3746
|
+
const have = h.numbers(t.connectorId);
|
|
3747
|
+
const add = lines.filter((n) => !have.includes(n));
|
|
3748
|
+
const remove = have.filter((n) => !lines.includes(n));
|
|
3749
|
+
if (add.length || remove.length) d.holders[h.id] = { add, remove };
|
|
3750
|
+
}
|
|
3751
|
+
diff.teams[t.locationId] = d;
|
|
3752
|
+
plans.push([t, lines, d]);
|
|
3270
3753
|
}
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3754
|
+
if (options.dryRun) return diff;
|
|
3755
|
+
const run = this.run(diff);
|
|
3756
|
+
try {
|
|
3757
|
+
for (const [t, lines, d] of plans) {
|
|
3758
|
+
run.step = `sync:${t.name}`;
|
|
3759
|
+
await this.monitorAllOff(t.locationId);
|
|
3760
|
+
for (const uid of Object.keys(d.holders)) await this.map(cust, uid, t.connectorId, lines, people.get(uid).mappings);
|
|
3761
|
+
if (d.firstAlert.add.length || d.firstAlert.remove.length) await this.c.firstAlert.setMonitoredNumbers(t.locationId, t.connectorId, lines);
|
|
3762
|
+
if (d.insightsHub.add.length || d.insightsHub.remove.length) await this.c.insightsHub.setNumbers(t.locationId, t.connectorId, lines);
|
|
3763
|
+
}
|
|
3764
|
+
} catch (exc) {
|
|
3765
|
+
this.stop(run, exc);
|
|
3283
3766
|
}
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
}
|
|
3287
|
-
diff.applied = true;
|
|
3288
|
-
return diff;
|
|
3767
|
+
diff.applied = true;
|
|
3768
|
+
return diff;
|
|
3769
|
+
});
|
|
3289
3770
|
}
|
|
3290
3771
|
// ------------------------------------------------------------------ offboarding
|
|
3291
3772
|
/**
|
|
@@ -3295,71 +3776,75 @@ var Accounts = class _Accounts {
|
|
|
3295
3776
|
* deactivate the company. Ask your Tresic contact about retention of the customer's data.
|
|
3296
3777
|
*/
|
|
3297
3778
|
async offboardCustomer(customer, options = {}) {
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
run
|
|
3312
|
-
|
|
3313
|
-
const
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3779
|
+
checkCustomerRef(customer);
|
|
3780
|
+
bool(options?.deactivateCompany, "deactivateCompany");
|
|
3781
|
+
return this.exclusive(async () => {
|
|
3782
|
+
await this.requireAdmin();
|
|
3783
|
+
const cust = await this.resolve(customer);
|
|
3784
|
+
const c = this.c;
|
|
3785
|
+
const out = {
|
|
3786
|
+
webhooksPaused: [],
|
|
3787
|
+
firstAlertWebhooksCleared: [],
|
|
3788
|
+
connectorsDeactivated: [],
|
|
3789
|
+
integrationUsersDeactivated: [],
|
|
3790
|
+
companyDeactivated: false
|
|
3791
|
+
};
|
|
3792
|
+
const run = this.run(out);
|
|
3793
|
+
try {
|
|
3794
|
+
const locs = this.locationsOf(cust);
|
|
3795
|
+
run.step = "webhooks";
|
|
3796
|
+
for (const t of locs) {
|
|
3797
|
+
const hook = await c.intelligence.getAfterCallWebhook(t.locationId) ?? {};
|
|
3798
|
+
if (hook.webhook_url && hook.enabled) {
|
|
3799
|
+
await c.intelligence.setAfterCallWebhook(t.locationId, hook.webhook_url, false);
|
|
3800
|
+
out.webhooksPaused.push(t.locationId);
|
|
3801
|
+
}
|
|
3802
|
+
if (await c.intelligence.getFirstAlertWebhook(t.locationId)) {
|
|
3803
|
+
await c.intelligence.setFirstAlertWebhook(t.locationId, null);
|
|
3804
|
+
out.firstAlertWebhooksCleared.push(t.locationId);
|
|
3805
|
+
}
|
|
3317
3806
|
}
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3807
|
+
run.step = "connectors";
|
|
3808
|
+
for (const t of locs) {
|
|
3809
|
+
for (const row of await all(c.connectors.iterLocationConnectors(t.locationId))) {
|
|
3810
|
+
if (row.status === "inactive" || row.status === "deactivating") continue;
|
|
3811
|
+
try {
|
|
3812
|
+
await c.connectors.deactivateConnector(t.locationId, row.id);
|
|
3813
|
+
} catch (exc) {
|
|
3814
|
+
if (exc instanceof ConflictError) continue;
|
|
3815
|
+
throw exc;
|
|
3816
|
+
}
|
|
3817
|
+
out.connectorsDeactivated.push(row.id);
|
|
3818
|
+
}
|
|
3321
3819
|
}
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
for (const row of await all(c.connectors.iterLocationConnectors(t.locationId))) {
|
|
3326
|
-
if (row.status === "inactive" || row.status === "deactivating") continue;
|
|
3820
|
+
run.step = "integration_users";
|
|
3821
|
+
for (const p of (await this.index(cust)).values()) {
|
|
3822
|
+
if (p.license !== "integration") continue;
|
|
3327
3823
|
try {
|
|
3328
|
-
await c.
|
|
3824
|
+
await c.users.deactivateCompanyUser(cust.companyId, p.id);
|
|
3329
3825
|
} catch (exc) {
|
|
3330
3826
|
if (exc instanceof ConflictError) continue;
|
|
3331
3827
|
throw exc;
|
|
3332
3828
|
}
|
|
3333
|
-
out.
|
|
3334
|
-
}
|
|
3335
|
-
}
|
|
3336
|
-
run.step = "integration_users";
|
|
3337
|
-
for (const p of (await this.index(cust)).values()) {
|
|
3338
|
-
if (p.license !== "integration") continue;
|
|
3339
|
-
try {
|
|
3340
|
-
await c.users.deactivateCompanyUser(cust.companyId, p.id);
|
|
3341
|
-
} catch (exc) {
|
|
3342
|
-
if (exc instanceof ConflictError) continue;
|
|
3343
|
-
throw exc;
|
|
3829
|
+
out.integrationUsersDeactivated.push(p.id);
|
|
3344
3830
|
}
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
if (!(exc instanceof ConflictError)) throw exc;
|
|
3831
|
+
run.step = "company";
|
|
3832
|
+
if (options.deactivateCompany ?? true) {
|
|
3833
|
+
const company = unwrap(await c.companies.getCompany(cust.companyId)) ?? {};
|
|
3834
|
+
if (company.is_active ?? true) {
|
|
3835
|
+
try {
|
|
3836
|
+
await c.companies.deactivateCompany(cust.companyId);
|
|
3837
|
+
out.companyDeactivated = true;
|
|
3838
|
+
} catch (exc) {
|
|
3839
|
+
if (!(exc instanceof ConflictError)) throw exc;
|
|
3840
|
+
}
|
|
3356
3841
|
}
|
|
3357
3842
|
}
|
|
3843
|
+
} catch (exc) {
|
|
3844
|
+
this.stop(run, exc);
|
|
3358
3845
|
}
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
}
|
|
3362
|
-
return out;
|
|
3846
|
+
return out;
|
|
3847
|
+
});
|
|
3363
3848
|
}
|
|
3364
3849
|
};
|
|
3365
3850
|
function unwrapMappings(body) {
|
|
@@ -3373,20 +3858,7 @@ function isUnknownEvent(e) {
|
|
|
3373
3858
|
return e.kind === "unknown";
|
|
3374
3859
|
}
|
|
3375
3860
|
function parseAfterCallEvent(body, options = {}) {
|
|
3376
|
-
const
|
|
3377
|
-
let obj = body;
|
|
3378
|
-
if (typeof body === "string" || body instanceof Uint8Array || body instanceof ArrayBuffer) {
|
|
3379
|
-
const size = typeof body === "string" ? new TextEncoder().encode(body).byteLength : body.byteLength;
|
|
3380
|
-
if (size > maxBytes) throw new PayloadTooLargeError(`Body is larger than ${maxBytes} bytes.`);
|
|
3381
|
-
const text = typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
3382
|
-
try {
|
|
3383
|
-
obj = JSON.parse(text);
|
|
3384
|
-
} catch {
|
|
3385
|
-
throw new WebhookPayloadError("Body is not JSON.");
|
|
3386
|
-
}
|
|
3387
|
-
}
|
|
3388
|
-
if (!obj || typeof obj !== "object" || Array.isArray(obj)) throw new WebhookPayloadError("Body is not a JSON object.");
|
|
3389
|
-
const o = obj;
|
|
3861
|
+
const o = loadBody(body, options.maxBytes ?? MAX_EVENT_BYTES);
|
|
3390
3862
|
if (o.type !== "end_of_call_summary") {
|
|
3391
3863
|
return {
|
|
3392
3864
|
kind: "unknown",
|
|
@@ -3395,15 +3867,40 @@ function parseAfterCallEvent(body, options = {}) {
|
|
|
3395
3867
|
raw: o
|
|
3396
3868
|
};
|
|
3397
3869
|
}
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3870
|
+
const data = projectEvent(o, WEBHOOK_SHAPES.afterCallSummary);
|
|
3871
|
+
const need = (obj, key, ok, where) => {
|
|
3872
|
+
if (!(key in obj)) throw new WebhookPayloadError(`${where}.${key} is missing.`);
|
|
3873
|
+
if (!ok(obj[key])) throw new WebhookPayloadError(`${where}.${key} has the wrong type.`);
|
|
3874
|
+
return obj[key];
|
|
3875
|
+
};
|
|
3876
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
3877
|
+
const isStr = (v) => typeof v === "string";
|
|
3878
|
+
const call = need(data, "call", isObj, "event");
|
|
3879
|
+
need(data, "location", isObj, "event");
|
|
3880
|
+
need(call, "call_date", isStr, "call");
|
|
3881
|
+
need(data, "version", isStr, "event");
|
|
3882
|
+
need(data, "is_test", (v) => typeof v === "boolean", "event");
|
|
3883
|
+
need(data, "location_id", isStr, "event");
|
|
3884
|
+
need(data, "timestamp", isStr, "event");
|
|
3885
|
+
const plain = (v, where) => {
|
|
3886
|
+
if (typeof v !== "string" || !ID_RE.test(v)) throw new WebhookPayloadError(`${where} is not a plain id (letters, digits, "-" and "_", at most 128).`);
|
|
3887
|
+
};
|
|
3888
|
+
plain(call.id ?? need(call, "id", isStr, "call"), "call.id");
|
|
3889
|
+
plain(data.location_id, "location_id");
|
|
3890
|
+
need(call, "call_type", isStr, "call");
|
|
3891
|
+
need(call, "duration_seconds", (v) => typeof v === "number" && Number.isInteger(v), "call");
|
|
3892
|
+
return data;
|
|
3893
|
+
}
|
|
3894
|
+
function projectEvent(value, shape) {
|
|
3895
|
+
if (shape === null || shape === void 0 || shape === "*" || shape === "v") return value;
|
|
3896
|
+
if (value === null || typeof value !== "object") return value;
|
|
3897
|
+
if ("a" in shape) return Array.isArray(value) ? value.map((v) => projectEvent(v, shape.a)) : value;
|
|
3898
|
+
if (Array.isArray(value)) return value;
|
|
3899
|
+
const out = {};
|
|
3900
|
+
for (const [k, sub] of Object.entries(shape.o)) {
|
|
3901
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) out[k] = projectEvent(value[k], sub);
|
|
3403
3902
|
}
|
|
3404
|
-
|
|
3405
|
-
const event = project(o, WEBHOOK_SHAPES.afterCallSummary);
|
|
3406
|
-
return { ...event, is_test: o.is_test === true };
|
|
3903
|
+
return out;
|
|
3407
3904
|
}
|
|
3408
3905
|
var INSPECT2 = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
3409
3906
|
var iso = (d) => d.toISOString().replace(/\.000Z$/, "Z");
|
|
@@ -3440,35 +3937,123 @@ var FirstAlertEvent = class {
|
|
|
3440
3937
|
return this.toString();
|
|
3441
3938
|
}
|
|
3442
3939
|
};
|
|
3940
|
+
var ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
3443
3941
|
function firstStr(...values) {
|
|
3444
3942
|
for (const v of values) if (typeof v === "string" && v.trim()) return v.trim();
|
|
3445
3943
|
return null;
|
|
3446
3944
|
}
|
|
3447
|
-
function
|
|
3448
|
-
return v !== null &&
|
|
3945
|
+
function plainId(v) {
|
|
3946
|
+
return v !== null && ID_RE.test(v) ? v : null;
|
|
3449
3947
|
}
|
|
3450
|
-
|
|
3451
|
-
const
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
const
|
|
3455
|
-
if (
|
|
3456
|
-
|
|
3948
|
+
var wellFormed = (t) => {
|
|
3949
|
+
const w = t;
|
|
3950
|
+
if (typeof w.isWellFormed === "function") return w.isWellFormed();
|
|
3951
|
+
for (let i = 0; i < t.length; i++) {
|
|
3952
|
+
const c = t.charCodeAt(i);
|
|
3953
|
+
if (c >= 55296 && c <= 56319) {
|
|
3954
|
+
const n = t.charCodeAt(i + 1);
|
|
3955
|
+
if (!(n >= 56320 && n <= 57343)) return false;
|
|
3956
|
+
i++;
|
|
3957
|
+
} else if (c >= 56320 && c <= 57343) return false;
|
|
3958
|
+
}
|
|
3959
|
+
return true;
|
|
3960
|
+
};
|
|
3961
|
+
var MAX_DEPTH = 64;
|
|
3962
|
+
function assertNoRepeatedKeys(text) {
|
|
3963
|
+
const stack = [];
|
|
3964
|
+
let i = 0;
|
|
3965
|
+
while (i < text.length) {
|
|
3966
|
+
const ch = text[i];
|
|
3967
|
+
if (ch === '"') {
|
|
3968
|
+
let j = i + 1;
|
|
3969
|
+
while (j < text.length && text[j] !== '"') j += text[j] === "\\" ? 2 : 1;
|
|
3970
|
+
const top = stack[stack.length - 1];
|
|
3971
|
+
if (top && top !== "array" && top.expectKey) {
|
|
3972
|
+
const key = JSON.parse(text.slice(i, j + 1));
|
|
3973
|
+
if (top.keys.has(key)) throw new WebhookPayloadError("Body repeats a key inside one object.");
|
|
3974
|
+
top.keys.add(key);
|
|
3975
|
+
top.expectKey = false;
|
|
3976
|
+
}
|
|
3977
|
+
i = j + 1;
|
|
3978
|
+
continue;
|
|
3979
|
+
}
|
|
3980
|
+
if (ch === "{" || ch === "[") {
|
|
3981
|
+
if (stack.length >= MAX_DEPTH) throw new WebhookPayloadError(`Body is nested more than ${MAX_DEPTH} levels deep.`);
|
|
3982
|
+
stack.push(ch === "{" ? { keys: /* @__PURE__ */ new Set(), expectKey: true } : "array");
|
|
3983
|
+
} else if (ch === "}" || ch === "]") stack.pop();
|
|
3984
|
+
else if (ch === ",") {
|
|
3985
|
+
const top = stack[stack.length - 1];
|
|
3986
|
+
if (top && top !== "array") top.expectKey = true;
|
|
3987
|
+
}
|
|
3988
|
+
i++;
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
function assertCleanValue(v, depth = 0) {
|
|
3992
|
+
if (depth > MAX_DEPTH) throw new WebhookPayloadError(`Body is nested more than ${MAX_DEPTH} levels deep.`);
|
|
3993
|
+
if (typeof v === "string") {
|
|
3994
|
+
if (!wellFormed(v)) throw new WebhookPayloadError("Body holds a lone surrogate (not valid Unicode).");
|
|
3995
|
+
} else if (typeof v === "number") {
|
|
3996
|
+
if (!Number.isFinite(v)) throw new WebhookPayloadError("Body holds a number that is not finite.");
|
|
3997
|
+
} else if (Array.isArray(v)) {
|
|
3998
|
+
for (const x of v) assertCleanValue(x, depth + 1);
|
|
3999
|
+
} else if (v !== null && typeof v === "object") {
|
|
4000
|
+
for (const [k, x] of Object.entries(v)) {
|
|
4001
|
+
if (!wellFormed(k)) throw new WebhookPayloadError("Body holds a lone surrogate (not valid Unicode).");
|
|
4002
|
+
assertCleanValue(x, depth + 1);
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
function parseIJson(input) {
|
|
4007
|
+
let text;
|
|
4008
|
+
if (typeof input === "string") {
|
|
4009
|
+
if (!wellFormed(input)) throw new WebhookPayloadError("Body holds a lone surrogate (not valid Unicode).");
|
|
4010
|
+
text = input;
|
|
4011
|
+
} else {
|
|
3457
4012
|
try {
|
|
3458
|
-
|
|
4013
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(input);
|
|
3459
4014
|
} catch {
|
|
3460
|
-
throw new WebhookPayloadError("Body is not
|
|
4015
|
+
throw new WebhookPayloadError("Body is not valid UTF-8.");
|
|
3461
4016
|
}
|
|
3462
4017
|
}
|
|
4018
|
+
if (text.charCodeAt(0) === 65279) text = text.slice(1);
|
|
4019
|
+
try {
|
|
4020
|
+
assertNoRepeatedKeys(text);
|
|
4021
|
+
} catch (e) {
|
|
4022
|
+
if (e instanceof WebhookPayloadError) throw e;
|
|
4023
|
+
throw new WebhookPayloadError("Body is not JSON.");
|
|
4024
|
+
}
|
|
4025
|
+
let value;
|
|
4026
|
+
try {
|
|
4027
|
+
value = JSON.parse(text);
|
|
4028
|
+
} catch {
|
|
4029
|
+
throw new WebhookPayloadError("Body is not JSON.");
|
|
4030
|
+
}
|
|
4031
|
+
assertCleanValue(value);
|
|
4032
|
+
return value;
|
|
4033
|
+
}
|
|
4034
|
+
function loadBody(body, maxBytes) {
|
|
4035
|
+
let obj = body;
|
|
4036
|
+
if (typeof body === "string" || body instanceof Uint8Array || body instanceof ArrayBuffer) {
|
|
4037
|
+
const size = typeof body === "string" ? new TextEncoder().encode(body).byteLength : body.byteLength;
|
|
4038
|
+
if (maxBytes && size > maxBytes) throw new PayloadTooLargeError(`Body is larger than ${maxBytes} bytes.`);
|
|
4039
|
+
obj = parseIJson(body);
|
|
4040
|
+
}
|
|
3463
4041
|
if (!obj || typeof obj !== "object" || Array.isArray(obj)) throw new WebhookPayloadError("Body is not a JSON object.");
|
|
3464
|
-
|
|
4042
|
+
assertCleanValue(obj);
|
|
4043
|
+
return obj;
|
|
4044
|
+
}
|
|
4045
|
+
function parseFirstAlertEvent(body, options = {}) {
|
|
4046
|
+
const data = loadBody(body, options.maxBytes ?? MAX_EVENT_BYTES);
|
|
3465
4047
|
const sub = (k) => data[k] && typeof data[k] === "object" && !Array.isArray(data[k]) ? data[k] : {};
|
|
3466
4048
|
const alert = sub("alert");
|
|
3467
4049
|
const rule = sub("rule");
|
|
3468
4050
|
const call = sub("call");
|
|
3469
4051
|
const loc = sub("location");
|
|
3470
|
-
const
|
|
3471
|
-
|
|
4052
|
+
const rawId = "alert_id" in data ? data.alert_id : "id" in alert ? alert.id : data.id;
|
|
4053
|
+
const alertId = typeof rawId === "string" ? rawId : null;
|
|
4054
|
+
if (!alertId || !ID_RE.test(alertId)) {
|
|
4055
|
+
throw new WebhookPayloadError("Event has no valid alert id (letters, digits, '-' and '_', at most 128).");
|
|
4056
|
+
}
|
|
3472
4057
|
const stamp = firstStr(data.timestamp, data.fired_at, data.created_at, alert.created_at);
|
|
3473
4058
|
let when = null;
|
|
3474
4059
|
if (stamp) {
|
|
@@ -3478,45 +4063,159 @@ function parseFirstAlertEvent(body, options = {}) {
|
|
|
3478
4063
|
return new FirstAlertEvent({
|
|
3479
4064
|
alertId,
|
|
3480
4065
|
rule: firstStr(data.rule_name, rule.name, typeof data.rule === "string" ? data.rule : null, data.alert_name, alert.rule_name, alert.name),
|
|
3481
|
-
locationId:
|
|
3482
|
-
callId:
|
|
4066
|
+
locationId: plainId(firstStr(data.location_id, loc.id, alert.location_id)),
|
|
4067
|
+
callId: plainId(firstStr(data.call_id, call.id, alert.call_id)),
|
|
3483
4068
|
timestamp: when,
|
|
3484
4069
|
isTest: data.is_test === true,
|
|
3485
4070
|
raw: { ...data }
|
|
3486
4071
|
});
|
|
3487
4072
|
}
|
|
4073
|
+
function canonicalJson(v) {
|
|
4074
|
+
if (v === null) return "null";
|
|
4075
|
+
switch (typeof v) {
|
|
4076
|
+
case "boolean":
|
|
4077
|
+
return v ? "true" : "false";
|
|
4078
|
+
case "number":
|
|
4079
|
+
if (!Number.isFinite(v)) throw new WebhookPayloadError("A number that is not finite cannot be hashed.");
|
|
4080
|
+
return JSON.stringify(v);
|
|
4081
|
+
case "string":
|
|
4082
|
+
if (!wellFormed(v)) throw new WebhookPayloadError("A lone surrogate cannot be hashed.");
|
|
4083
|
+
return JSON.stringify(v);
|
|
4084
|
+
case "object": {
|
|
4085
|
+
if (Array.isArray(v)) return "[" + v.map((x) => canonicalJson(x === void 0 ? null : x)).join(",") + "]";
|
|
4086
|
+
const o = v;
|
|
4087
|
+
const keys = Object.keys(o).filter((k) => o[k] !== void 0).sort();
|
|
4088
|
+
return "{" + keys.map((k) => canonicalJson(k) + ":" + canonicalJson(o[k])).join(",") + "}";
|
|
4089
|
+
}
|
|
4090
|
+
default:
|
|
4091
|
+
throw new WebhookPayloadError("A value that is not JSON cannot be hashed.");
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
async function sha256Hex(text) {
|
|
4095
|
+
const data = new TextEncoder().encode(text);
|
|
4096
|
+
const subtle = globalThis.crypto?.subtle;
|
|
4097
|
+
if (subtle) {
|
|
4098
|
+
const buf = await subtle.digest("SHA-256", data);
|
|
4099
|
+
return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4100
|
+
}
|
|
4101
|
+
const nodeCrypto = await import('crypto');
|
|
4102
|
+
return nodeCrypto.createHash("sha256").update(data).digest("hex");
|
|
4103
|
+
}
|
|
4104
|
+
function asEvent(item) {
|
|
4105
|
+
if (isFirstAlertEvent(item)) return { kind: "first_alert", event: item };
|
|
4106
|
+
if (item && typeof item === "object" && item.kind === "unknown" && "raw" in item) {
|
|
4107
|
+
const u = item;
|
|
4108
|
+
return { kind: "unknown", type: u.type, raw: u.raw };
|
|
4109
|
+
}
|
|
4110
|
+
const body = loadBody(item, MAX_EVENT_BYTES);
|
|
4111
|
+
const ev = parseAfterCallEvent(body);
|
|
4112
|
+
if (isUnknownEvent(ev)) {
|
|
4113
|
+
try {
|
|
4114
|
+
return { kind: "first_alert", event: parseFirstAlertEvent(body) };
|
|
4115
|
+
} catch (e) {
|
|
4116
|
+
if (e instanceof WebhookPayloadError && !Object.prototype.hasOwnProperty.call(body, "alert_id")) return { kind: "unknown", type: ev.type, raw: ev.raw };
|
|
4117
|
+
throw e;
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
return { kind: "after_call", event: ev };
|
|
4121
|
+
}
|
|
4122
|
+
function upsertKey(event) {
|
|
4123
|
+
const ev = asEvent(event);
|
|
4124
|
+
if (ev.kind === "after_call") return ev.event.call.id;
|
|
4125
|
+
if (ev.kind === "first_alert") return ev.event.alertId;
|
|
4126
|
+
throw new WebhookPayloadError("Not an After Call or First Alert event.");
|
|
4127
|
+
}
|
|
4128
|
+
var RFC33392 = /^(\d{4}-\d{2}-\d{2})[Tt ](\d{2}:\d{2}:\d{2})(?:\.(\d+))?([Zz]|[+-]\d{2}:\d{2})$/;
|
|
4129
|
+
function stampOf(value) {
|
|
4130
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : [value.getTime(), "000"];
|
|
4131
|
+
if (typeof value !== "string") return null;
|
|
4132
|
+
const m = RFC33392.exec(value.trim());
|
|
4133
|
+
if (!m) return null;
|
|
4134
|
+
const frac = (m[3] ?? "").padEnd(3, "0");
|
|
4135
|
+
const t = (/* @__PURE__ */ new Date(`${m[1]}T${m[2]}.${frac.slice(0, 3)}${m[4].toUpperCase()}`)).getTime();
|
|
4136
|
+
return Number.isNaN(t) ? null : [t, frac.slice(3).padEnd(3, "0")];
|
|
4137
|
+
}
|
|
4138
|
+
function eventTime(value) {
|
|
4139
|
+
if (value === null || value === void 0) return null;
|
|
4140
|
+
if (value instanceof Date) return stampOf(value);
|
|
4141
|
+
if (typeof value === "string" && !value.replace(/^[\ufeff \t\r\n]+/, "").startsWith("{")) return stampOf(value);
|
|
4142
|
+
let ev;
|
|
4143
|
+
try {
|
|
4144
|
+
ev = asEvent(value);
|
|
4145
|
+
} catch {
|
|
4146
|
+
return null;
|
|
4147
|
+
}
|
|
4148
|
+
if (ev.kind === "after_call") return stampOf(ev.event.timestamp);
|
|
4149
|
+
if (ev.kind === "first_alert") return stampOf(ev.event.timestamp);
|
|
4150
|
+
return null;
|
|
4151
|
+
}
|
|
4152
|
+
function isOlder(event, stored) {
|
|
4153
|
+
const a = eventTime(event);
|
|
4154
|
+
const b = eventTime(stored);
|
|
4155
|
+
if (a === null || b === null) return false;
|
|
4156
|
+
return a[0] < b[0] || a[0] === b[0] && a[1] < b[1];
|
|
4157
|
+
}
|
|
4158
|
+
async function deliveryKey(event) {
|
|
4159
|
+
if (typeof event === "string" && !event.replace(/^[\ufeff \t\r\n]+/, "").startsWith("{")) {
|
|
4160
|
+
throw new InvalidRequestError(
|
|
4161
|
+
"seen(event) and remember(event) take the event, its parsed body or the raw request body, not an id: an id alone cannot tell newer data apart"
|
|
4162
|
+
);
|
|
4163
|
+
}
|
|
4164
|
+
const ev = asEvent(event);
|
|
4165
|
+
if (ev.kind === "after_call") {
|
|
4166
|
+
const e = ev.event;
|
|
4167
|
+
return `${e.type}:${e.location_id}:${e.call.id}:${await sha256Hex(canonicalJson(e))}`;
|
|
4168
|
+
}
|
|
4169
|
+
if (ev.kind === "first_alert") return `first_alert:${ev.event.alertId}:${await sha256Hex(canonicalJson(ev.event.raw))}`;
|
|
4170
|
+
return `${typeof ev.type === "string" ? ev.type : "unknown"}:${await sha256Hex(canonicalJson(ev.raw))}`;
|
|
4171
|
+
}
|
|
3488
4172
|
var MemoryDedupStore = class {
|
|
3489
4173
|
constructor(maxSize = 1e4) {
|
|
3490
4174
|
this.maxSize = maxSize;
|
|
3491
4175
|
}
|
|
3492
4176
|
maxSize;
|
|
3493
4177
|
keys = /* @__PURE__ */ new Map();
|
|
3494
|
-
|
|
3495
|
-
if (this.keys.has(key))
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
4178
|
+
has(key) {
|
|
4179
|
+
if (!this.keys.has(key)) return false;
|
|
4180
|
+
this.keys.delete(key);
|
|
4181
|
+
this.keys.set(key, true);
|
|
4182
|
+
return true;
|
|
4183
|
+
}
|
|
4184
|
+
add(key) {
|
|
4185
|
+
this.keys.delete(key);
|
|
3500
4186
|
this.keys.set(key, true);
|
|
3501
4187
|
if (this.keys.size > this.maxSize) {
|
|
3502
4188
|
const oldest = this.keys.keys().next().value;
|
|
3503
4189
|
if (oldest !== void 0) this.keys.delete(oldest);
|
|
3504
4190
|
}
|
|
3505
|
-
return false;
|
|
3506
4191
|
}
|
|
3507
4192
|
};
|
|
4193
|
+
function present(event) {
|
|
4194
|
+
if (event === void 0 || event === null || event === "" || event instanceof Uint8Array && event.byteLength === 0) {
|
|
4195
|
+
throw new InvalidRequestError("an event is required");
|
|
4196
|
+
}
|
|
4197
|
+
return event;
|
|
4198
|
+
}
|
|
3508
4199
|
var Deduplicator = class {
|
|
3509
4200
|
store;
|
|
3510
4201
|
constructor(options = {}) {
|
|
3511
4202
|
this.store = options.store ?? new MemoryDedupStore(options.maxSize ?? 1e4);
|
|
3512
4203
|
}
|
|
3513
|
-
/** True
|
|
3514
|
-
async
|
|
3515
|
-
return Boolean(await this.store.
|
|
4204
|
+
/** True when this exact delivery was remembered before. Records nothing. */
|
|
4205
|
+
async seen(event) {
|
|
4206
|
+
return Boolean(await this.store.has(await deliveryKey(present(event))));
|
|
4207
|
+
}
|
|
4208
|
+
/** Record this delivery. Call it after your durable write succeeded. */
|
|
4209
|
+
async remember(event) {
|
|
4210
|
+
await this.store.add(await deliveryKey(present(event)));
|
|
3516
4211
|
}
|
|
3517
|
-
/**
|
|
3518
|
-
|
|
3519
|
-
return
|
|
4212
|
+
/** The call id (After Call) or alert id (First Alert) to store the delivery under. */
|
|
4213
|
+
static upsertKey(event) {
|
|
4214
|
+
return upsertKey(event);
|
|
4215
|
+
}
|
|
4216
|
+
/** The call id (After Call) or alert id (First Alert) to store the delivery under. */
|
|
4217
|
+
upsertKey(event) {
|
|
4218
|
+
return upsertKey(event);
|
|
3520
4219
|
}
|
|
3521
4220
|
};
|
|
3522
4221
|
|
|
@@ -3553,7 +4252,7 @@ function localMidnight(y, m, d) {
|
|
|
3553
4252
|
return new Date(y, m - 1, d, 0, 0, 0, 0);
|
|
3554
4253
|
}
|
|
3555
4254
|
var DATE_ONLY2 = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3556
|
-
var
|
|
4255
|
+
var RFC33393 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/i;
|
|
3557
4256
|
function camelKey(k) {
|
|
3558
4257
|
return k.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
3559
4258
|
}
|
|
@@ -3656,6 +4355,24 @@ var AlertBrief = class {
|
|
|
3656
4355
|
return this.toString();
|
|
3657
4356
|
}
|
|
3658
4357
|
};
|
|
4358
|
+
var idArg = (value, name) => pathArg(value, name);
|
|
4359
|
+
function checkTeam(team) {
|
|
4360
|
+
if (team === void 0 || team === null) return;
|
|
4361
|
+
if (typeof team === "object" && typeof team.locationId === "string") return;
|
|
4362
|
+
if (typeof team !== "string" || !team.trim() || team.length > 200) throw new InvalidRequestError("team: a TeamRef, a location id or a team name");
|
|
4363
|
+
}
|
|
4364
|
+
function checkDue(due) {
|
|
4365
|
+
if (due === void 0 || due === null) return;
|
|
4366
|
+
if (due instanceof Date && !Number.isNaN(due.getTime())) return;
|
|
4367
|
+
if (typeof due === "string") {
|
|
4368
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(due);
|
|
4369
|
+
if (m) {
|
|
4370
|
+
const d = new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
|
|
4371
|
+
if (d.getUTCMonth() === Number(m[2]) - 1 && d.getUTCDate() === Number(m[3])) return;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4374
|
+
throw new InvalidRequestError("due: a date (YYYY-MM-DD)");
|
|
4375
|
+
}
|
|
3659
4376
|
var Conversations = class _Conversations {
|
|
3660
4377
|
constructor(c) {
|
|
3661
4378
|
this.c = c;
|
|
@@ -3675,7 +4392,7 @@ var Conversations = class _Conversations {
|
|
|
3675
4392
|
return (this.c.maskNumbers ? maskName(n) : n) ?? null;
|
|
3676
4393
|
}
|
|
3677
4394
|
link(kind, id) {
|
|
3678
|
-
if (!id) return null;
|
|
4395
|
+
if (typeof id !== "string" || !ID_RE.test(id)) return null;
|
|
3679
4396
|
const page = kind === "call" ? "after-call-copilot/calls" : "first-alert-copilot/alerts";
|
|
3680
4397
|
return `${this.c.appUrl}/${page}/${encodeURIComponent(id)}`;
|
|
3681
4398
|
}
|
|
@@ -3687,13 +4404,13 @@ var Conversations = class _Conversations {
|
|
|
3687
4404
|
}
|
|
3688
4405
|
static when(value, name) {
|
|
3689
4406
|
if (typeof value === "string") {
|
|
3690
|
-
if (!
|
|
4407
|
+
if (!RFC33393.test(value.trim())) throw new InvalidRequestError(`${name}: an RFC 3339 date-time with a time zone`);
|
|
3691
4408
|
return new Date(value.trim());
|
|
3692
4409
|
}
|
|
3693
4410
|
if (!(value instanceof Date) || Number.isNaN(value.getTime())) throw new InvalidRequestError(`${name}: a Date or an RFC 3339 date-time`);
|
|
3694
4411
|
return value;
|
|
3695
4412
|
}
|
|
3696
|
-
/** (start, end). Default: today (local time), or the last `defaultDays` days. At most 31 days. */
|
|
4413
|
+
/** @internal (start, end). Default: today (local time), or the last `defaultDays` days. At most 31 days. */
|
|
3697
4414
|
window(day, since, until, defaultDays) {
|
|
3698
4415
|
const has = (v) => v !== void 0 && v !== null;
|
|
3699
4416
|
if (has(day) && (has(since) || has(until))) throw new InvalidRequestError("Pass day, or since/until, not both");
|
|
@@ -3735,7 +4452,9 @@ var Conversations = class _Conversations {
|
|
|
3735
4452
|
}
|
|
3736
4453
|
const term = phone ?? text;
|
|
3737
4454
|
if (term === void 0 || term === null) return void 0;
|
|
3738
|
-
|
|
4455
|
+
if (typeof term !== "string") throw new InvalidRequestError("number and search: a string");
|
|
4456
|
+
const t = term.trim();
|
|
4457
|
+
if (t.length > 200) throw new InvalidRequestError("number and search: at most 200 characters");
|
|
3739
4458
|
if (t.length < 2) throw new InvalidRequestError("search terms need at least 2 characters (shorter ones are ignored by the API)");
|
|
3740
4459
|
return t;
|
|
3741
4460
|
}
|
|
@@ -3811,7 +4530,10 @@ var Conversations = class _Conversations {
|
|
|
3811
4530
|
lines: null
|
|
3812
4531
|
};
|
|
3813
4532
|
}
|
|
3814
|
-
/**
|
|
4533
|
+
/**
|
|
4534
|
+
* The teams (locations) this person can see: those with `kind === "team"` first, in name order, then Management
|
|
4535
|
+
* (`kind === "management"`) last. Pick "my team" by `kind === "team"`.
|
|
4536
|
+
*/
|
|
3815
4537
|
async teams() {
|
|
3816
4538
|
await this.requireUser();
|
|
3817
4539
|
const out = [];
|
|
@@ -3819,7 +4541,8 @@ var Conversations = class _Conversations {
|
|
|
3819
4541
|
const name = loc.location_name ?? "";
|
|
3820
4542
|
out.push({ locationId: loc.id ?? "", name, kind: name.endsWith(" - Management") ? "management" : "team" });
|
|
3821
4543
|
}
|
|
3822
|
-
|
|
4544
|
+
const rank2 = (t) => t.kind === "team" ? 0 : 1;
|
|
4545
|
+
return out.sort((a, b) => rank2(a) - rank2(b) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
3823
4546
|
}
|
|
3824
4547
|
// ------------------------------------------------------------------ calls
|
|
3825
4548
|
/**
|
|
@@ -3827,11 +4550,12 @@ var Conversations = class _Conversations {
|
|
|
3827
4550
|
* 200. `number` and `search` share the API's one search field: pass one or the other.
|
|
3828
4551
|
*/
|
|
3829
4552
|
async calls(options = {}) {
|
|
4553
|
+
const limit = _Conversations.limit(options?.limit ?? 50, MAX_LIMIT);
|
|
4554
|
+
const [start, end] = this.window(options?.day, options?.since, options?.until);
|
|
4555
|
+
const term = _Conversations.searchTerm(options?.number, options?.search);
|
|
4556
|
+
checkTeam(options?.team);
|
|
3830
4557
|
await this.requireUser();
|
|
3831
|
-
const
|
|
3832
|
-
const [start, end] = this.window(options.day, options.since, options.until);
|
|
3833
|
-
const term = _Conversations.searchTerm(options.number, options.search);
|
|
3834
|
-
const lid = await this.teamId(options.team);
|
|
4558
|
+
const lid = await this.teamId(options?.team);
|
|
3835
4559
|
const rows = await this.pages(
|
|
3836
4560
|
(n, cursor) => this.c.calls.listCalls({ dateFrom: start, dateTo: end, search: term, locationId: lid ?? void 0, limit: n, cursor }),
|
|
3837
4561
|
limit
|
|
@@ -3843,6 +4567,7 @@ var Conversations = class _Conversations {
|
|
|
3843
4567
|
* it raised. No transcript and no recording.
|
|
3844
4568
|
*/
|
|
3845
4569
|
async brief(callId) {
|
|
4570
|
+
callId = idArg(callId, "callId");
|
|
3846
4571
|
await this.requireUser();
|
|
3847
4572
|
const data = unwrap2(await this.c.calls.getCall(callId)) ?? {};
|
|
3848
4573
|
const b = this.briefFromRow(data);
|
|
@@ -3870,6 +4595,7 @@ var Conversations = class _Conversations {
|
|
|
3870
4595
|
}
|
|
3871
4596
|
/** The transcript of one call: segments with `time`, `speaker`, `name` and `text`. */
|
|
3872
4597
|
async transcript(callId) {
|
|
4598
|
+
callId = idArg(callId, "callId");
|
|
3873
4599
|
await this.requireUser();
|
|
3874
4600
|
const data = unwrap2(await this.c.calls.getCallTranscript(callId)) ?? {};
|
|
3875
4601
|
return data.transcript ?? [];
|
|
@@ -3879,26 +4605,30 @@ var Conversations = class _Conversations {
|
|
|
3879
4605
|
* downloads the audio. Treat the link as a secret: never log or store it.
|
|
3880
4606
|
*/
|
|
3881
4607
|
async recordingLink(callId) {
|
|
4608
|
+
callId = idArg(callId, "callId");
|
|
3882
4609
|
await this.requireUser();
|
|
3883
4610
|
const link = await this.c.intelligence.getRecordingUrl(callId);
|
|
3884
4611
|
return link.url ? link : null;
|
|
3885
4612
|
}
|
|
3886
4613
|
/** Recent briefs for one caller (the last 31 days), for use before a callback. `limit` at most 50. */
|
|
3887
4614
|
async callerHistory(number, options = {}) {
|
|
3888
|
-
|
|
3889
|
-
|
|
4615
|
+
const limit = _Conversations.limit(options?.limit ?? 10, MAX_HISTORY);
|
|
4616
|
+
if (typeof number !== "string" || !number.trim()) throw new InvalidRequestError("number: a non-empty string");
|
|
3890
4617
|
const term = _Conversations.searchTerm(number, null);
|
|
3891
4618
|
const [start, end] = this.window(null, null, null, MAX_WINDOW_DAYS);
|
|
4619
|
+
await this.requireUser();
|
|
3892
4620
|
const rows = await this.pages((n, cursor) => this.c.calls.listCalls({ dateFrom: start, dateTo: end, search: term, limit: n, cursor }), limit);
|
|
3893
4621
|
return rows.map((r) => this.briefFromRow(r));
|
|
3894
4622
|
}
|
|
3895
4623
|
// ------------------------------------------------------------------ tasks and alerts
|
|
3896
4624
|
/** Open tasks (up to 200), each with the id of the call it came from. `due`: only tasks due that day. */
|
|
3897
4625
|
async openTasks(options = {}) {
|
|
4626
|
+
checkDue(options?.due);
|
|
4627
|
+
checkTeam(options?.team);
|
|
3898
4628
|
await this.requireUser();
|
|
3899
|
-
const lid = await this.teamId(options
|
|
4629
|
+
const lid = await this.teamId(options?.team);
|
|
3900
4630
|
const rows = await this.pages(
|
|
3901
|
-
(n, cursor) => this.c.tasks.listTasks({ status: "open", dueOn: options
|
|
4631
|
+
(n, cursor) => this.c.tasks.listTasks({ status: "open", dueOn: options?.due ?? void 0, locationId: lid ?? void 0, limit: n, cursor }),
|
|
3902
4632
|
MAX_LIMIT
|
|
3903
4633
|
);
|
|
3904
4634
|
return rows.map((r) => _Conversations.taskFromRow(r));
|
|
@@ -3908,13 +4638,14 @@ var Conversations = class _Conversations {
|
|
|
3908
4638
|
* `status` is refused: the API has no alert status filter yet.
|
|
3909
4639
|
*/
|
|
3910
4640
|
async alerts(options = {}) {
|
|
3911
|
-
|
|
3912
|
-
if (options.status !== void 0 && options.status !== null) {
|
|
4641
|
+
if (options?.status !== void 0 && options.status !== null) {
|
|
3913
4642
|
throw new InvalidRequestError("status: the API has no alert status filter yet");
|
|
3914
4643
|
}
|
|
3915
|
-
const limit = _Conversations.limit(options
|
|
3916
|
-
const [start, end] = this.window(null, options
|
|
3917
|
-
|
|
4644
|
+
const limit = _Conversations.limit(options?.limit ?? 50, MAX_LIMIT);
|
|
4645
|
+
const [start, end] = this.window(null, options?.since, options?.until);
|
|
4646
|
+
checkTeam(options?.team);
|
|
4647
|
+
await this.requireUser();
|
|
4648
|
+
const lid = await this.teamId(options?.team);
|
|
3918
4649
|
const rows = await this.pages(
|
|
3919
4650
|
(n, cursor) => this.c.alerts.listAlerts({ dateFrom: start, dateTo: end, locationId: lid ?? void 0, limit: n, cursor }),
|
|
3920
4651
|
limit
|
|
@@ -3923,8 +4654,8 @@ var Conversations = class _Conversations {
|
|
|
3923
4654
|
}
|
|
3924
4655
|
/** One alert with its call brief, or null when this login cannot see it. */
|
|
3925
4656
|
async alert(alertId) {
|
|
4657
|
+
const aid = idArg(alertId, "alertId").toLowerCase();
|
|
3926
4658
|
await this.requireUser();
|
|
3927
|
-
const aid = String(alertId).trim().toLowerCase();
|
|
3928
4659
|
const page = await this.c.alerts.listAlerts({ search: aid, limit: 10 });
|
|
3929
4660
|
const row = page.items.find((a) => a.id === aid);
|
|
3930
4661
|
if (row === void 0) return null;
|
|
@@ -3937,10 +4668,11 @@ var Conversations = class _Conversations {
|
|
|
3937
4668
|
* at most 31 days. Default: today.
|
|
3938
4669
|
*/
|
|
3939
4670
|
async teamView(team, options = {}) {
|
|
4671
|
+
if (team === void 0 || team === null) throw new InvalidRequestError("team is required");
|
|
4672
|
+
checkTeam(team);
|
|
4673
|
+
const [start, end] = this.window(options?.day, options?.since, options?.until);
|
|
3940
4674
|
await this.requireUser();
|
|
3941
4675
|
const lid = await this.teamId(team);
|
|
3942
|
-
if (lid === null) throw new InvalidRequestError("team is required");
|
|
3943
|
-
const [start, end] = this.window(options.day, options.since, options.until);
|
|
3944
4676
|
const first = await this.c.calls.listCalls({ dateFrom: start, dateTo: end, locationId: lid, limit: PAGE });
|
|
3945
4677
|
let rows = [...first.items];
|
|
3946
4678
|
if (first.hasMore && first.nextCursor) {
|
|
@@ -3967,9 +4699,10 @@ var Conversations = class _Conversations {
|
|
|
3967
4699
|
* Needs Insights Hub access.
|
|
3968
4700
|
*/
|
|
3969
4701
|
async topics(options = {}) {
|
|
4702
|
+
const [start, end] = this.window(null, options?.since, options?.until, 7);
|
|
4703
|
+
checkTeam(options?.team);
|
|
3970
4704
|
await this.requireUser();
|
|
3971
|
-
const
|
|
3972
|
-
const lid = await this.teamId(options.team);
|
|
4705
|
+
const lid = await this.teamId(options?.team);
|
|
3973
4706
|
const data = unwrap2(await this.c.insights.getInsightsDashboard({ start, end, locationId: lid ?? void 0 })) ?? {};
|
|
3974
4707
|
const stats = data.stats ?? {};
|
|
3975
4708
|
const rising = (data.trending_topics ?? []).filter((t) => (t.percentage_change ?? 0) > 0).map((t) => {
|
|
@@ -3995,8 +4728,9 @@ var Conversations = class _Conversations {
|
|
|
3995
4728
|
if (brand(callOrAlert, CALL_BRAND)) [kind, id] = ["call", callOrAlert.id];
|
|
3996
4729
|
else if (brand(callOrAlert, ALERT_BRAND)) [kind, id] = ["alert", callOrAlert.id];
|
|
3997
4730
|
else if (isFirstAlertEvent(callOrAlert)) [kind, id] = ["alert", callOrAlert.alertId];
|
|
3998
|
-
else if (typeof callOrAlert === "string" && callOrAlert
|
|
4731
|
+
else if (typeof callOrAlert === "string" && callOrAlert !== "") [kind, id] = ["call", callOrAlert];
|
|
3999
4732
|
else throw new InvalidRequestError("reference: a CallBrief, an AlertBrief, a FirstAlertEvent or a call id");
|
|
4733
|
+
if (typeof id !== "string" || !ID_RE.test(id)) throw new InvalidRequestError("reference: an id of letters, digits, '-' and '_' (at most 128)");
|
|
4000
4734
|
return { kind, id, link: this.link(kind, id) };
|
|
4001
4735
|
}
|
|
4002
4736
|
/** A typed First Alert event, beside `parseAfterCallEvent`. See `parseFirstAlertEvent`. */
|
|
@@ -4167,7 +4901,9 @@ var Client = class {
|
|
|
4167
4901
|
const connectors = makeConnectors(c);
|
|
4168
4902
|
const waitForStatus = async (locationId, connectorId, final, o = {}) => {
|
|
4169
4903
|
const start = c.now();
|
|
4170
|
-
const
|
|
4904
|
+
const timeout = o.timeout ?? 600;
|
|
4905
|
+
const interval = o.checkInterval ?? 10;
|
|
4906
|
+
let checks = 0;
|
|
4171
4907
|
for (; ; ) {
|
|
4172
4908
|
const conn = (await connectors.getConnector(locationId, connectorId)).data ?? {};
|
|
4173
4909
|
const st = conn.status ?? null;
|
|
@@ -4175,10 +4911,10 @@ var Client = class {
|
|
|
4175
4911
|
throw new ConnectorError(conn);
|
|
4176
4912
|
}
|
|
4177
4913
|
if (st && final.includes(st)) return conn;
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4914
|
+
const waited = Math.max((c.now() - start) / 1e3, checks * interval);
|
|
4915
|
+
if (waited >= timeout) throw new ConnectorTimeoutError(conn, waited);
|
|
4916
|
+
await c.sleep(interval * 1e3);
|
|
4917
|
+
checks++;
|
|
4182
4918
|
}
|
|
4183
4919
|
};
|
|
4184
4920
|
const settle = async (locationId, first, final, o, raiseOnError = true) => {
|
|
@@ -4466,6 +5202,7 @@ exports.MAX_WINDOW_DAYS = MAX_WINDOW_DAYS;
|
|
|
4466
5202
|
exports.MemoryDedupStore = MemoryDedupStore;
|
|
4467
5203
|
exports.MemoryTokenStore = MemoryTokenStore;
|
|
4468
5204
|
exports.MfaRequiredError = MfaRequiredError;
|
|
5205
|
+
exports.NetworkError = NetworkError;
|
|
4469
5206
|
exports.NotFoundError = NotFoundError;
|
|
4470
5207
|
exports.PRODUCT_KEYS = PRODUCT_KEYS;
|
|
4471
5208
|
exports.PasswordExpiredError = PasswordExpiredError;
|
|
@@ -4480,9 +5217,11 @@ exports.WebhookPayloadError = WebhookPayloadError;
|
|
|
4480
5217
|
exports.WrongLoginError = WrongLoginError;
|
|
4481
5218
|
exports.alertNumber = alertNumber;
|
|
4482
5219
|
exports.digitsOnly = digitsOnly;
|
|
5220
|
+
exports.isOlder = isOlder;
|
|
4483
5221
|
exports.isUnknownEvent = isUnknownEvent;
|
|
4484
5222
|
exports.maskName = maskName;
|
|
4485
5223
|
exports.maskNumber = maskNumber;
|
|
4486
5224
|
exports.parseAfterCallEvent = parseAfterCallEvent;
|
|
4487
5225
|
exports.parseFirstAlertEvent = parseFirstAlertEvent;
|
|
4488
5226
|
exports.toRfc3339 = toRfc3339;
|
|
5227
|
+
exports.upsertKey = upsertKey;
|