@sendly/node 3.8.2 → 3.10.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/dist/index.d.mts CHANGED
@@ -842,6 +842,206 @@ declare const SANDBOX_TEST_NUMBERS: {
842
842
  /** Fails with carrier_violation error */
843
843
  readonly CARRIER_VIOLATION: "+15005550006";
844
844
  };
845
+ /**
846
+ * Verification status
847
+ */
848
+ type VerificationStatus = "pending" | "verified" | "invalid" | "expired" | "failed";
849
+ /**
850
+ * Verification delivery status
851
+ */
852
+ type VerificationDeliveryStatus = "queued" | "sent" | "delivered" | "failed";
853
+ /**
854
+ * Request to send a verification code
855
+ */
856
+ interface SendVerificationRequest {
857
+ /** Destination phone number in E.164 format */
858
+ to: string;
859
+ /** Template ID to use (defaults to preset OTP template) */
860
+ templateId?: string;
861
+ /** Verify profile ID for custom settings */
862
+ profileId?: string;
863
+ /** App name to display in message (defaults to business name) */
864
+ appName?: string;
865
+ /** Code validity in seconds (60-3600, default: 300) */
866
+ timeoutSecs?: number;
867
+ /** OTP code length (4-10, default: 6) */
868
+ codeLength?: number;
869
+ }
870
+ /**
871
+ * Response from sending a verification
872
+ */
873
+ interface SendVerificationResponse {
874
+ /** Verification ID */
875
+ id: string;
876
+ /** Status (always "pending" initially) */
877
+ status: VerificationStatus;
878
+ /** Phone number */
879
+ phone: string;
880
+ /** When the code expires (ISO 8601) */
881
+ expiresAt: string;
882
+ /** Whether sent in sandbox mode */
883
+ sandbox: boolean;
884
+ /** OTP code (only in sandbox mode for testing) */
885
+ sandboxCode?: string;
886
+ /** Message about sandbox mode */
887
+ message?: string;
888
+ }
889
+ /**
890
+ * Request to check a verification code
891
+ */
892
+ interface CheckVerificationRequest {
893
+ /** The OTP code entered by the user */
894
+ code: string;
895
+ }
896
+ /**
897
+ * Response from checking a verification
898
+ */
899
+ interface CheckVerificationResponse {
900
+ /** Verification ID */
901
+ id: string;
902
+ /** Status after check */
903
+ status: VerificationStatus;
904
+ /** Phone number */
905
+ phone: string;
906
+ /** When verified (ISO 8601) */
907
+ verifiedAt?: string;
908
+ /** Remaining attempts (if invalid) */
909
+ remainingAttempts?: number;
910
+ }
911
+ /**
912
+ * A verification record
913
+ */
914
+ interface Verification {
915
+ /** Verification ID */
916
+ id: string;
917
+ /** Status */
918
+ status: VerificationStatus;
919
+ /** Phone number */
920
+ phone: string;
921
+ /** Delivery status */
922
+ deliveryStatus: VerificationDeliveryStatus;
923
+ /** Number of check attempts */
924
+ attempts: number;
925
+ /** Maximum attempts allowed */
926
+ maxAttempts: number;
927
+ /** When the code expires (ISO 8601) */
928
+ expiresAt: string;
929
+ /** When verified (ISO 8601) */
930
+ verifiedAt?: string | null;
931
+ /** When created (ISO 8601) */
932
+ createdAt: string;
933
+ /** Whether sandbox mode */
934
+ sandbox: boolean;
935
+ /** App name used */
936
+ appName?: string;
937
+ /** Template ID used */
938
+ templateId?: string;
939
+ /** Profile ID used */
940
+ profileId?: string;
941
+ }
942
+ /**
943
+ * Options for listing verifications
944
+ */
945
+ interface ListVerificationsOptions {
946
+ /** Maximum number to return (1-100, default: 20) */
947
+ limit?: number;
948
+ /** Filter by status */
949
+ status?: VerificationStatus;
950
+ }
951
+ /**
952
+ * Response from listing verifications
953
+ */
954
+ interface VerificationListResponse {
955
+ /** Array of verifications */
956
+ verifications: Verification[];
957
+ /** Pagination info */
958
+ pagination: {
959
+ limit: number;
960
+ hasMore: boolean;
961
+ };
962
+ }
963
+ /**
964
+ * Template variable definition
965
+ */
966
+ interface TemplateVariable {
967
+ /** Variable key (e.g., "code", "app_name") */
968
+ key: string;
969
+ /** Variable type */
970
+ type: "string" | "number";
971
+ /** Default fallback value */
972
+ fallback?: string;
973
+ }
974
+ /**
975
+ * Template status
976
+ */
977
+ type TemplateStatus = "draft" | "published";
978
+ /**
979
+ * An SMS template
980
+ */
981
+ interface Template {
982
+ /** Template ID */
983
+ id: string;
984
+ /** Template name */
985
+ name: string;
986
+ /** Message text with {{variables}} */
987
+ text: string;
988
+ /** Variables detected in the template */
989
+ variables: TemplateVariable[];
990
+ /** Whether this is a preset template */
991
+ isPreset: boolean;
992
+ /** Preset slug (e.g., "otp", "2fa") */
993
+ presetSlug?: string | null;
994
+ /** Template status */
995
+ status: TemplateStatus;
996
+ /** Version number */
997
+ version: number;
998
+ /** When published (ISO 8601) */
999
+ publishedAt?: string | null;
1000
+ /** When created (ISO 8601) */
1001
+ createdAt: string;
1002
+ /** When updated (ISO 8601) */
1003
+ updatedAt: string;
1004
+ }
1005
+ /**
1006
+ * Request to create a template
1007
+ */
1008
+ interface CreateTemplateRequest {
1009
+ /** Template name */
1010
+ name: string;
1011
+ /** Message text (use {{code}} and {{app_name}} variables) */
1012
+ text: string;
1013
+ }
1014
+ /**
1015
+ * Request to update a template
1016
+ */
1017
+ interface UpdateTemplateRequest {
1018
+ /** New template name */
1019
+ name?: string;
1020
+ /** New message text */
1021
+ text?: string;
1022
+ }
1023
+ /**
1024
+ * Response from listing templates
1025
+ */
1026
+ interface TemplateListResponse {
1027
+ /** Array of templates */
1028
+ templates: Template[];
1029
+ }
1030
+ /**
1031
+ * Template preview with interpolated text
1032
+ */
1033
+ interface TemplatePreview {
1034
+ /** Template ID */
1035
+ id: string;
1036
+ /** Template name */
1037
+ name: string;
1038
+ /** Original text with variables */
1039
+ originalText: string;
1040
+ /** Interpolated text with sample values */
1041
+ previewText: string;
1042
+ /** Variables detected */
1043
+ variables: TemplateVariable[];
1044
+ }
845
1045
 
846
1046
  /**
847
1047
  * HTTP Client Utility
@@ -1534,6 +1734,280 @@ declare class AccountResource {
1534
1734
  revokeApiKey(id: string): Promise<void>;
1535
1735
  }
1536
1736
 
1737
+ /**
1738
+ * Verify Resource - OTP Verification API
1739
+ * @packageDocumentation
1740
+ */
1741
+
1742
+ /**
1743
+ * Verify API resource for OTP verification
1744
+ *
1745
+ * @example
1746
+ * ```typescript
1747
+ * // Send an OTP
1748
+ * const verification = await sendly.verify.send({
1749
+ * to: '+15551234567',
1750
+ * appName: 'MyApp'
1751
+ * });
1752
+ *
1753
+ * // Check the OTP
1754
+ * const result = await sendly.verify.check(verification.id, {
1755
+ * code: '123456'
1756
+ * });
1757
+ *
1758
+ * if (result.status === 'verified') {
1759
+ * console.log('Phone verified!');
1760
+ * }
1761
+ * ```
1762
+ */
1763
+ declare class VerifyResource {
1764
+ private readonly http;
1765
+ constructor(http: HttpClient);
1766
+ /**
1767
+ * Send an OTP verification code
1768
+ *
1769
+ * @param request - Verification request details
1770
+ * @returns The created verification with ID and expiry
1771
+ *
1772
+ * @example
1773
+ * ```typescript
1774
+ * // Basic usage
1775
+ * const verification = await sendly.verify.send({
1776
+ * to: '+15551234567'
1777
+ * });
1778
+ *
1779
+ * // With custom options
1780
+ * const verification = await sendly.verify.send({
1781
+ * to: '+15551234567',
1782
+ * appName: 'MyApp',
1783
+ * codeLength: 8,
1784
+ * timeoutSecs: 600
1785
+ * });
1786
+ *
1787
+ * // In sandbox mode, the code is returned for testing
1788
+ * if (verification.sandboxCode) {
1789
+ * console.log('Test code:', verification.sandboxCode);
1790
+ * }
1791
+ * ```
1792
+ */
1793
+ send(request: SendVerificationRequest): Promise<SendVerificationResponse>;
1794
+ /**
1795
+ * Resend an OTP verification code
1796
+ *
1797
+ * @param id - Verification ID
1798
+ * @returns Updated verification with new expiry
1799
+ *
1800
+ * @example
1801
+ * ```typescript
1802
+ * // Resend when delivery failed or code expired
1803
+ * const result = await sendly.verify.resend('ver_xxx');
1804
+ * console.log('New code expires at:', result.expiresAt);
1805
+ * ```
1806
+ */
1807
+ resend(id: string): Promise<SendVerificationResponse>;
1808
+ /**
1809
+ * Check/verify an OTP code
1810
+ *
1811
+ * @param id - Verification ID
1812
+ * @param request - The code to verify
1813
+ * @returns Verification result
1814
+ *
1815
+ * @example
1816
+ * ```typescript
1817
+ * const result = await sendly.verify.check('ver_xxx', {
1818
+ * code: '123456'
1819
+ * });
1820
+ *
1821
+ * if (result.status === 'verified') {
1822
+ * // User is verified
1823
+ * } else if (result.remainingAttempts !== undefined) {
1824
+ * console.log(`Wrong code. ${result.remainingAttempts} attempts remaining`);
1825
+ * }
1826
+ * ```
1827
+ */
1828
+ check(id: string, request: CheckVerificationRequest): Promise<CheckVerificationResponse>;
1829
+ /**
1830
+ * Get a verification by ID
1831
+ *
1832
+ * @param id - Verification ID
1833
+ * @returns The verification record
1834
+ *
1835
+ * @example
1836
+ * ```typescript
1837
+ * const verification = await sendly.verify.get('ver_xxx');
1838
+ * console.log(verification.status); // 'pending', 'verified', 'expired', etc.
1839
+ * ```
1840
+ */
1841
+ get(id: string): Promise<Verification>;
1842
+ /**
1843
+ * List recent verifications
1844
+ *
1845
+ * @param options - Filter and pagination options
1846
+ * @returns List of verifications
1847
+ *
1848
+ * @example
1849
+ * ```typescript
1850
+ * // List recent verifications
1851
+ * const { verifications } = await sendly.verify.list({ limit: 10 });
1852
+ *
1853
+ * // Filter by status
1854
+ * const { verifications } = await sendly.verify.list({
1855
+ * status: 'verified'
1856
+ * });
1857
+ * ```
1858
+ */
1859
+ list(options?: ListVerificationsOptions): Promise<VerificationListResponse>;
1860
+ }
1861
+
1862
+ /**
1863
+ * Templates Resource - SMS Template Management
1864
+ * @packageDocumentation
1865
+ */
1866
+
1867
+ /**
1868
+ * Templates API resource for managing SMS templates
1869
+ *
1870
+ * @example
1871
+ * ```typescript
1872
+ * // List available templates
1873
+ * const { templates } = await sendly.templates.list();
1874
+ *
1875
+ * // Create a custom template
1876
+ * const template = await sendly.templates.create({
1877
+ * name: 'My OTP',
1878
+ * text: 'Your {{app_name}} code is {{code}}'
1879
+ * });
1880
+ *
1881
+ * // Publish for use
1882
+ * await sendly.templates.publish(template.id);
1883
+ * ```
1884
+ */
1885
+ declare class TemplatesResource {
1886
+ private readonly http;
1887
+ constructor(http: HttpClient);
1888
+ /**
1889
+ * List all templates (presets + custom)
1890
+ *
1891
+ * @returns List of templates
1892
+ *
1893
+ * @example
1894
+ * ```typescript
1895
+ * const { templates } = await sendly.templates.list();
1896
+ * templates.forEach(t => {
1897
+ * console.log(`${t.name}: ${t.isPreset ? 'preset' : t.status}`);
1898
+ * });
1899
+ * ```
1900
+ */
1901
+ list(): Promise<TemplateListResponse>;
1902
+ /**
1903
+ * List preset templates only (no auth required)
1904
+ *
1905
+ * @returns List of preset templates
1906
+ *
1907
+ * @example
1908
+ * ```typescript
1909
+ * const { templates } = await sendly.templates.presets();
1910
+ * // Returns: otp, 2fa, login, signup, reset, generic
1911
+ * ```
1912
+ */
1913
+ presets(): Promise<TemplateListResponse>;
1914
+ /**
1915
+ * Get a template by ID
1916
+ *
1917
+ * @param id - Template ID
1918
+ * @returns The template
1919
+ *
1920
+ * @example
1921
+ * ```typescript
1922
+ * const template = await sendly.templates.get('tpl_preset_otp');
1923
+ * console.log(template.text); // "Your {{app_name}} code is {{code}}"
1924
+ * ```
1925
+ */
1926
+ get(id: string): Promise<Template>;
1927
+ /**
1928
+ * Create a new template
1929
+ *
1930
+ * @param request - Template details
1931
+ * @returns The created template (as draft)
1932
+ *
1933
+ * @example
1934
+ * ```typescript
1935
+ * const template = await sendly.templates.create({
1936
+ * name: 'Password Reset',
1937
+ * text: '{{app_name}}: Your password reset code is {{code}}. Valid for 10 minutes.'
1938
+ * });
1939
+ *
1940
+ * // Template is created as draft, publish when ready
1941
+ * await sendly.templates.publish(template.id);
1942
+ * ```
1943
+ */
1944
+ create(request: CreateTemplateRequest): Promise<Template>;
1945
+ /**
1946
+ * Update a template
1947
+ *
1948
+ * Note: Updating a published template creates a new draft version.
1949
+ *
1950
+ * @param id - Template ID
1951
+ * @param request - Fields to update
1952
+ * @returns The updated template
1953
+ *
1954
+ * @example
1955
+ * ```typescript
1956
+ * const template = await sendly.templates.update('tpl_xxx', {
1957
+ * text: 'New message text with {{code}}'
1958
+ * });
1959
+ * ```
1960
+ */
1961
+ update(id: string, request: UpdateTemplateRequest): Promise<Template>;
1962
+ /**
1963
+ * Publish a draft template
1964
+ *
1965
+ * Published templates are locked and can be used with the Verify API.
1966
+ *
1967
+ * @param id - Template ID
1968
+ * @returns The published template
1969
+ *
1970
+ * @example
1971
+ * ```typescript
1972
+ * const template = await sendly.templates.publish('tpl_xxx');
1973
+ * console.log(template.status); // 'published'
1974
+ * ```
1975
+ */
1976
+ publish(id: string): Promise<Template>;
1977
+ /**
1978
+ * Preview a template with sample values
1979
+ *
1980
+ * @param id - Template ID
1981
+ * @param variables - Optional custom variable values
1982
+ * @returns Template with interpolated preview text
1983
+ *
1984
+ * @example
1985
+ * ```typescript
1986
+ * const preview = await sendly.templates.preview('tpl_preset_otp', {
1987
+ * app_name: 'MyApp',
1988
+ * code: '123456'
1989
+ * });
1990
+ * console.log(preview.previewText);
1991
+ * // "Your MyApp code is 123456"
1992
+ * ```
1993
+ */
1994
+ preview(id: string, variables?: Record<string, string>): Promise<TemplatePreview>;
1995
+ /**
1996
+ * Delete a template
1997
+ *
1998
+ * Note: Preset templates cannot be deleted.
1999
+ *
2000
+ * @param id - Template ID
2001
+ *
2002
+ * @example
2003
+ * ```typescript
2004
+ * await sendly.templates.delete('tpl_xxx');
2005
+ * ```
2006
+ */
2007
+ delete(id: string): Promise<void>;
2008
+ private transformTemplate;
2009
+ }
2010
+
1537
2011
  /**
1538
2012
  * Sendly Client
1539
2013
  * @packageDocumentation
@@ -1622,6 +2096,47 @@ declare class Sendly {
1622
2096
  * ```
1623
2097
  */
1624
2098
  readonly account: AccountResource;
2099
+ /**
2100
+ * Verify API resource - OTP verification
2101
+ *
2102
+ * @example
2103
+ * ```typescript
2104
+ * // Send an OTP
2105
+ * const verification = await sendly.verify.send({
2106
+ * to: '+15551234567',
2107
+ * appName: 'MyApp'
2108
+ * });
2109
+ *
2110
+ * // Check the OTP (user enters code)
2111
+ * const result = await sendly.verify.check(verification.id, {
2112
+ * code: '123456'
2113
+ * });
2114
+ *
2115
+ * if (result.status === 'verified') {
2116
+ * console.log('Phone verified!');
2117
+ * }
2118
+ * ```
2119
+ */
2120
+ readonly verify: VerifyResource;
2121
+ /**
2122
+ * Templates API resource - SMS template management
2123
+ *
2124
+ * @example
2125
+ * ```typescript
2126
+ * // List preset templates
2127
+ * const { templates } = await sendly.templates.presets();
2128
+ *
2129
+ * // Create a custom template
2130
+ * const template = await sendly.templates.create({
2131
+ * name: 'My OTP',
2132
+ * text: 'Your {{app_name}} code is {{code}}'
2133
+ * });
2134
+ *
2135
+ * // Publish for use
2136
+ * await sendly.templates.publish(template.id);
2137
+ * ```
2138
+ */
2139
+ readonly templates: TemplatesResource;
1625
2140
  private readonly http;
1626
2141
  private readonly config;
1627
2142
  /**
@@ -2072,4 +2587,4 @@ declare class Webhooks {
2072
2587
  */
2073
2588
  type WebhookMessageData = WebhookMessageObject;
2074
2589
 
2075
- export { ALL_SUPPORTED_COUNTRIES, type Account, type ApiErrorResponse, type ApiKey, AuthenticationError, type BatchListResponse, type BatchMessageItem, type BatchMessageRequest, type BatchMessageResponse, type BatchMessageResult, type BatchStatus, CREDITS_PER_SMS, type CancelledMessageResponse, type CircuitState, type CreateWebhookOptions, type CreditTransaction, type Credits, type DeliveryStatus, InsufficientCreditsError, type ListBatchesOptions, type ListMessagesOptions, type ListScheduledMessagesOptions, type Message, type MessageListResponse, type MessageStatus, type MessageType, NetworkError, NotFoundError, type PricingTier, RateLimitError, type RateLimitInfo, SANDBOX_TEST_NUMBERS, SUPPORTED_COUNTRIES, type ScheduleMessageRequest, type ScheduledMessage, type ScheduledMessageListResponse, type ScheduledMessageStatus, type SendMessageRequest, type SenderType, Sendly, type SendlyConfig, SendlyError, type SendlyErrorCode, TimeoutError, type UpdateWebhookOptions, ValidationError, type Webhook, type WebhookCreatedResponse, type WebhookDelivery, type WebhookEvent, type WebhookEventType, type WebhookMessageData, type WebhookMessageStatus, type WebhookSecretRotation, WebhookSignatureError, type WebhookTestResult, Webhooks, calculateSegments, Sendly as default, generateWebhookSignature, getCountryFromPhone, isCountrySupported, parseWebhookEvent, validateMessageText, validatePhoneNumber, validateSenderId, verifyWebhookSignature };
2590
+ export { ALL_SUPPORTED_COUNTRIES, type Account, type ApiErrorResponse, type ApiKey, AuthenticationError, type BatchListResponse, type BatchMessageItem, type BatchMessageRequest, type BatchMessageResponse, type BatchMessageResult, type BatchStatus, CREDITS_PER_SMS, type CancelledMessageResponse, type CheckVerificationRequest, type CheckVerificationResponse, type CircuitState, type CreateTemplateRequest, type CreateWebhookOptions, type CreditTransaction, type Credits, type DeliveryStatus, InsufficientCreditsError, type ListBatchesOptions, type ListMessagesOptions, type ListScheduledMessagesOptions, type ListVerificationsOptions, type Message, type MessageListResponse, type MessageStatus, type MessageType, NetworkError, NotFoundError, type PricingTier, RateLimitError, type RateLimitInfo, SANDBOX_TEST_NUMBERS, SUPPORTED_COUNTRIES, type ScheduleMessageRequest, type ScheduledMessage, type ScheduledMessageListResponse, type ScheduledMessageStatus, type SendMessageRequest, type SendVerificationRequest, type SendVerificationResponse, type SenderType, Sendly, type SendlyConfig, SendlyError, type SendlyErrorCode, type Template, type TemplateListResponse, type TemplatePreview, type TemplateStatus, type TemplateVariable, TimeoutError, type UpdateTemplateRequest, type UpdateWebhookOptions, ValidationError, type Verification, type VerificationDeliveryStatus, type VerificationListResponse, type VerificationStatus, type Webhook, type WebhookCreatedResponse, type WebhookDelivery, type WebhookEvent, type WebhookEventType, type WebhookMessageData, type WebhookMessageStatus, type WebhookSecretRotation, WebhookSignatureError, type WebhookTestResult, Webhooks, calculateSegments, Sendly as default, generateWebhookSignature, getCountryFromPhone, isCountrySupported, parseWebhookEvent, validateMessageText, validatePhoneNumber, validateSenderId, verifyWebhookSignature };