@sendly/node 3.8.1 → 3.9.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/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/SendlyHQ/sendly-node/main/.github/header.svg" alt="Sendly Node.js SDK" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/@sendly/node"><img src="https://img.shields.io/npm/v/@sendly/node.svg?style=flat-square" alt="npm version" /></a>
7
+ <a href="https://github.com/SendlyHQ/sendly-node/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@sendly/node.svg?style=flat-square" alt="license" /></a>
8
+ </p>
9
+
1
10
  # @sendly/node
2
11
 
3
12
  Official Node.js SDK for the [Sendly](https://sendly.live) SMS API.
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,266 @@ 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
+ * Check/verify an OTP code
1796
+ *
1797
+ * @param id - Verification ID
1798
+ * @param request - The code to verify
1799
+ * @returns Verification result
1800
+ *
1801
+ * @example
1802
+ * ```typescript
1803
+ * const result = await sendly.verify.check('ver_xxx', {
1804
+ * code: '123456'
1805
+ * });
1806
+ *
1807
+ * if (result.status === 'verified') {
1808
+ * // User is verified
1809
+ * } else if (result.remainingAttempts !== undefined) {
1810
+ * console.log(`Wrong code. ${result.remainingAttempts} attempts remaining`);
1811
+ * }
1812
+ * ```
1813
+ */
1814
+ check(id: string, request: CheckVerificationRequest): Promise<CheckVerificationResponse>;
1815
+ /**
1816
+ * Get a verification by ID
1817
+ *
1818
+ * @param id - Verification ID
1819
+ * @returns The verification record
1820
+ *
1821
+ * @example
1822
+ * ```typescript
1823
+ * const verification = await sendly.verify.get('ver_xxx');
1824
+ * console.log(verification.status); // 'pending', 'verified', 'expired', etc.
1825
+ * ```
1826
+ */
1827
+ get(id: string): Promise<Verification>;
1828
+ /**
1829
+ * List recent verifications
1830
+ *
1831
+ * @param options - Filter and pagination options
1832
+ * @returns List of verifications
1833
+ *
1834
+ * @example
1835
+ * ```typescript
1836
+ * // List recent verifications
1837
+ * const { verifications } = await sendly.verify.list({ limit: 10 });
1838
+ *
1839
+ * // Filter by status
1840
+ * const { verifications } = await sendly.verify.list({
1841
+ * status: 'verified'
1842
+ * });
1843
+ * ```
1844
+ */
1845
+ list(options?: ListVerificationsOptions): Promise<VerificationListResponse>;
1846
+ }
1847
+
1848
+ /**
1849
+ * Templates Resource - SMS Template Management
1850
+ * @packageDocumentation
1851
+ */
1852
+
1853
+ /**
1854
+ * Templates API resource for managing SMS templates
1855
+ *
1856
+ * @example
1857
+ * ```typescript
1858
+ * // List available templates
1859
+ * const { templates } = await sendly.templates.list();
1860
+ *
1861
+ * // Create a custom template
1862
+ * const template = await sendly.templates.create({
1863
+ * name: 'My OTP',
1864
+ * text: 'Your {{app_name}} code is {{code}}'
1865
+ * });
1866
+ *
1867
+ * // Publish for use
1868
+ * await sendly.templates.publish(template.id);
1869
+ * ```
1870
+ */
1871
+ declare class TemplatesResource {
1872
+ private readonly http;
1873
+ constructor(http: HttpClient);
1874
+ /**
1875
+ * List all templates (presets + custom)
1876
+ *
1877
+ * @returns List of templates
1878
+ *
1879
+ * @example
1880
+ * ```typescript
1881
+ * const { templates } = await sendly.templates.list();
1882
+ * templates.forEach(t => {
1883
+ * console.log(`${t.name}: ${t.isPreset ? 'preset' : t.status}`);
1884
+ * });
1885
+ * ```
1886
+ */
1887
+ list(): Promise<TemplateListResponse>;
1888
+ /**
1889
+ * List preset templates only (no auth required)
1890
+ *
1891
+ * @returns List of preset templates
1892
+ *
1893
+ * @example
1894
+ * ```typescript
1895
+ * const { templates } = await sendly.templates.presets();
1896
+ * // Returns: otp, 2fa, login, signup, reset, generic
1897
+ * ```
1898
+ */
1899
+ presets(): Promise<TemplateListResponse>;
1900
+ /**
1901
+ * Get a template by ID
1902
+ *
1903
+ * @param id - Template ID
1904
+ * @returns The template
1905
+ *
1906
+ * @example
1907
+ * ```typescript
1908
+ * const template = await sendly.templates.get('tpl_preset_otp');
1909
+ * console.log(template.text); // "Your {{app_name}} code is {{code}}"
1910
+ * ```
1911
+ */
1912
+ get(id: string): Promise<Template>;
1913
+ /**
1914
+ * Create a new template
1915
+ *
1916
+ * @param request - Template details
1917
+ * @returns The created template (as draft)
1918
+ *
1919
+ * @example
1920
+ * ```typescript
1921
+ * const template = await sendly.templates.create({
1922
+ * name: 'Password Reset',
1923
+ * text: '{{app_name}}: Your password reset code is {{code}}. Valid for 10 minutes.'
1924
+ * });
1925
+ *
1926
+ * // Template is created as draft, publish when ready
1927
+ * await sendly.templates.publish(template.id);
1928
+ * ```
1929
+ */
1930
+ create(request: CreateTemplateRequest): Promise<Template>;
1931
+ /**
1932
+ * Update a template
1933
+ *
1934
+ * Note: Updating a published template creates a new draft version.
1935
+ *
1936
+ * @param id - Template ID
1937
+ * @param request - Fields to update
1938
+ * @returns The updated template
1939
+ *
1940
+ * @example
1941
+ * ```typescript
1942
+ * const template = await sendly.templates.update('tpl_xxx', {
1943
+ * text: 'New message text with {{code}}'
1944
+ * });
1945
+ * ```
1946
+ */
1947
+ update(id: string, request: UpdateTemplateRequest): Promise<Template>;
1948
+ /**
1949
+ * Publish a draft template
1950
+ *
1951
+ * Published templates are locked and can be used with the Verify API.
1952
+ *
1953
+ * @param id - Template ID
1954
+ * @returns The published template
1955
+ *
1956
+ * @example
1957
+ * ```typescript
1958
+ * const template = await sendly.templates.publish('tpl_xxx');
1959
+ * console.log(template.status); // 'published'
1960
+ * ```
1961
+ */
1962
+ publish(id: string): Promise<Template>;
1963
+ /**
1964
+ * Preview a template with sample values
1965
+ *
1966
+ * @param id - Template ID
1967
+ * @param variables - Optional custom variable values
1968
+ * @returns Template with interpolated preview text
1969
+ *
1970
+ * @example
1971
+ * ```typescript
1972
+ * const preview = await sendly.templates.preview('tpl_preset_otp', {
1973
+ * app_name: 'MyApp',
1974
+ * code: '123456'
1975
+ * });
1976
+ * console.log(preview.previewText);
1977
+ * // "Your MyApp code is 123456"
1978
+ * ```
1979
+ */
1980
+ preview(id: string, variables?: Record<string, string>): Promise<TemplatePreview>;
1981
+ /**
1982
+ * Delete a template
1983
+ *
1984
+ * Note: Preset templates cannot be deleted.
1985
+ *
1986
+ * @param id - Template ID
1987
+ *
1988
+ * @example
1989
+ * ```typescript
1990
+ * await sendly.templates.delete('tpl_xxx');
1991
+ * ```
1992
+ */
1993
+ delete(id: string): Promise<void>;
1994
+ private transformTemplate;
1995
+ }
1996
+
1537
1997
  /**
1538
1998
  * Sendly Client
1539
1999
  * @packageDocumentation
@@ -1622,6 +2082,47 @@ declare class Sendly {
1622
2082
  * ```
1623
2083
  */
1624
2084
  readonly account: AccountResource;
2085
+ /**
2086
+ * Verify API resource - OTP verification
2087
+ *
2088
+ * @example
2089
+ * ```typescript
2090
+ * // Send an OTP
2091
+ * const verification = await sendly.verify.send({
2092
+ * to: '+15551234567',
2093
+ * appName: 'MyApp'
2094
+ * });
2095
+ *
2096
+ * // Check the OTP (user enters code)
2097
+ * const result = await sendly.verify.check(verification.id, {
2098
+ * code: '123456'
2099
+ * });
2100
+ *
2101
+ * if (result.status === 'verified') {
2102
+ * console.log('Phone verified!');
2103
+ * }
2104
+ * ```
2105
+ */
2106
+ readonly verify: VerifyResource;
2107
+ /**
2108
+ * Templates API resource - SMS template management
2109
+ *
2110
+ * @example
2111
+ * ```typescript
2112
+ * // List preset templates
2113
+ * const { templates } = await sendly.templates.presets();
2114
+ *
2115
+ * // Create a custom template
2116
+ * const template = await sendly.templates.create({
2117
+ * name: 'My OTP',
2118
+ * text: 'Your {{app_name}} code is {{code}}'
2119
+ * });
2120
+ *
2121
+ * // Publish for use
2122
+ * await sendly.templates.publish(template.id);
2123
+ * ```
2124
+ */
2125
+ readonly templates: TemplatesResource;
1625
2126
  private readonly http;
1626
2127
  private readonly config;
1627
2128
  /**
@@ -2072,4 +2573,4 @@ declare class Webhooks {
2072
2573
  */
2073
2574
  type WebhookMessageData = WebhookMessageObject;
2074
2575
 
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 };
2576
+ 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 };