@heymantle/core-api-client 0.1.10 → 0.1.12
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 +199 -13
- package/dist/index.d.ts +199 -13
- package/dist/index.js +168 -2
- package/dist/index.mjs +166 -1
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1815,11 +1815,30 @@ interface AgentResponse {
|
|
|
1815
1815
|
/**
|
|
1816
1816
|
* Task status
|
|
1817
1817
|
*/
|
|
1818
|
-
type TaskStatus = '
|
|
1818
|
+
type TaskStatus = 'new' | 'in_progress' | 'complete';
|
|
1819
1819
|
/**
|
|
1820
1820
|
* Task priority
|
|
1821
1821
|
*/
|
|
1822
|
-
type TaskPriority = 'low' | 'medium' | 'high'
|
|
1822
|
+
type TaskPriority = 'low' | 'medium' | 'high';
|
|
1823
|
+
/**
|
|
1824
|
+
* Task todo item entity
|
|
1825
|
+
*/
|
|
1826
|
+
interface TodoItem {
|
|
1827
|
+
id: string;
|
|
1828
|
+
content: string;
|
|
1829
|
+
completed: boolean;
|
|
1830
|
+
completedAt?: string | null;
|
|
1831
|
+
displayOrder: number;
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Parameters for creating a todo item (used in task creation/update)
|
|
1835
|
+
*/
|
|
1836
|
+
interface TodoItemInput {
|
|
1837
|
+
id?: string;
|
|
1838
|
+
content: string;
|
|
1839
|
+
completed?: boolean;
|
|
1840
|
+
displayOrder?: number;
|
|
1841
|
+
}
|
|
1823
1842
|
/**
|
|
1824
1843
|
* Task entity
|
|
1825
1844
|
*/
|
|
@@ -1831,6 +1850,7 @@ interface Task {
|
|
|
1831
1850
|
priority: TaskPriority;
|
|
1832
1851
|
status: TaskStatus;
|
|
1833
1852
|
dueDate?: string;
|
|
1853
|
+
completedAt?: string | null;
|
|
1834
1854
|
assigneeId?: string;
|
|
1835
1855
|
customerId?: string;
|
|
1836
1856
|
contactId?: string;
|
|
@@ -1844,19 +1864,33 @@ interface Task {
|
|
|
1844
1864
|
id: string;
|
|
1845
1865
|
name?: string;
|
|
1846
1866
|
email?: string;
|
|
1847
|
-
};
|
|
1867
|
+
} | null;
|
|
1868
|
+
createdBy?: {
|
|
1869
|
+
id: string;
|
|
1870
|
+
name?: string;
|
|
1871
|
+
email?: string;
|
|
1872
|
+
} | null;
|
|
1848
1873
|
customer?: {
|
|
1849
1874
|
id: string;
|
|
1850
1875
|
name?: string;
|
|
1851
|
-
};
|
|
1876
|
+
} | null;
|
|
1852
1877
|
contact?: {
|
|
1853
1878
|
id: string;
|
|
1854
1879
|
name?: string;
|
|
1855
|
-
};
|
|
1880
|
+
} | null;
|
|
1856
1881
|
deal?: {
|
|
1857
1882
|
id: string;
|
|
1858
1883
|
name?: string;
|
|
1859
|
-
|
|
1884
|
+
dealStage?: {
|
|
1885
|
+
id: string;
|
|
1886
|
+
name?: string;
|
|
1887
|
+
} | null;
|
|
1888
|
+
} | null;
|
|
1889
|
+
dealActivity?: {
|
|
1890
|
+
id: string;
|
|
1891
|
+
name?: string;
|
|
1892
|
+
} | null;
|
|
1893
|
+
todoItems?: TodoItem[];
|
|
1860
1894
|
}
|
|
1861
1895
|
/**
|
|
1862
1896
|
* Parameters for listing tasks
|
|
@@ -1891,12 +1925,59 @@ interface TaskCreateParams {
|
|
|
1891
1925
|
dealActivityId?: string;
|
|
1892
1926
|
appInstallationId?: string;
|
|
1893
1927
|
tags?: string[];
|
|
1928
|
+
todoItems?: TodoItemInput[];
|
|
1894
1929
|
}
|
|
1895
1930
|
/**
|
|
1896
1931
|
* Parameters for updating a task
|
|
1897
1932
|
*/
|
|
1898
1933
|
interface TaskUpdateParams extends Partial<TaskCreateParams> {
|
|
1899
1934
|
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Response from listing todo items
|
|
1937
|
+
*/
|
|
1938
|
+
interface TodoItemListResponse {
|
|
1939
|
+
items: TodoItem[];
|
|
1940
|
+
total: number;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Deal progression information returned when a task update triggers deal stage change
|
|
1944
|
+
*/
|
|
1945
|
+
interface DealProgression {
|
|
1946
|
+
dealId: string;
|
|
1947
|
+
dealName: string;
|
|
1948
|
+
previousStage: {
|
|
1949
|
+
id: string;
|
|
1950
|
+
name: string;
|
|
1951
|
+
} | null;
|
|
1952
|
+
nextStage: {
|
|
1953
|
+
id: string;
|
|
1954
|
+
name: string;
|
|
1955
|
+
} | null;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Response from updating a task
|
|
1959
|
+
*/
|
|
1960
|
+
interface TaskUpdateResponse {
|
|
1961
|
+
task: Task;
|
|
1962
|
+
dealProgressed: boolean;
|
|
1963
|
+
dealProgression: DealProgression | null;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Parameters for creating a todo item via the dedicated endpoint
|
|
1967
|
+
*/
|
|
1968
|
+
interface TodoItemCreateParams {
|
|
1969
|
+
content: string;
|
|
1970
|
+
completed?: boolean;
|
|
1971
|
+
displayOrder?: number;
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Parameters for updating a todo item
|
|
1975
|
+
*/
|
|
1976
|
+
interface TodoItemUpdateParams {
|
|
1977
|
+
content?: string;
|
|
1978
|
+
completed?: boolean;
|
|
1979
|
+
displayOrder?: number;
|
|
1980
|
+
}
|
|
1900
1981
|
|
|
1901
1982
|
/**
|
|
1902
1983
|
* Company entity
|
|
@@ -2771,19 +2852,41 @@ declare class TasksResource extends BaseResource {
|
|
|
2771
2852
|
/**
|
|
2772
2853
|
* Create a new task
|
|
2773
2854
|
*/
|
|
2774
|
-
create(data: TaskCreateParams): Promise<
|
|
2775
|
-
task: Task;
|
|
2776
|
-
}>;
|
|
2855
|
+
create(data: TaskCreateParams): Promise<Task>;
|
|
2777
2856
|
/**
|
|
2778
2857
|
* Update an existing task
|
|
2779
2858
|
*/
|
|
2780
|
-
update(taskId: string, data: TaskUpdateParams): Promise<
|
|
2781
|
-
task: Task;
|
|
2782
|
-
}>;
|
|
2859
|
+
update(taskId: string, data: TaskUpdateParams): Promise<TaskUpdateResponse>;
|
|
2783
2860
|
/**
|
|
2784
2861
|
* Delete a task
|
|
2785
2862
|
*/
|
|
2786
2863
|
del(taskId: string): Promise<DeleteResponse>;
|
|
2864
|
+
/**
|
|
2865
|
+
* List todo items for a task
|
|
2866
|
+
*/
|
|
2867
|
+
listTodoItems(taskId: string): Promise<TodoItemListResponse>;
|
|
2868
|
+
/**
|
|
2869
|
+
* Retrieve a single todo item
|
|
2870
|
+
*/
|
|
2871
|
+
retrieveTodoItem(taskId: string, itemId: string): Promise<{
|
|
2872
|
+
item: TodoItem;
|
|
2873
|
+
}>;
|
|
2874
|
+
/**
|
|
2875
|
+
* Create a todo item for a task
|
|
2876
|
+
*/
|
|
2877
|
+
createTodoItem(taskId: string, data: TodoItemCreateParams): Promise<{
|
|
2878
|
+
item: TodoItem;
|
|
2879
|
+
}>;
|
|
2880
|
+
/**
|
|
2881
|
+
* Update a todo item
|
|
2882
|
+
*/
|
|
2883
|
+
updateTodoItem(taskId: string, itemId: string, data: TodoItemUpdateParams): Promise<{
|
|
2884
|
+
item: TodoItem;
|
|
2885
|
+
}>;
|
|
2886
|
+
/**
|
|
2887
|
+
* Delete a todo item
|
|
2888
|
+
*/
|
|
2889
|
+
deleteTodoItem(taskId: string, itemId: string): Promise<DeleteResponse>;
|
|
2787
2890
|
}
|
|
2788
2891
|
|
|
2789
2892
|
/**
|
|
@@ -3571,4 +3674,87 @@ interface AuthRefreshOptions {
|
|
|
3571
3674
|
*/
|
|
3572
3675
|
declare function createAuthRefreshMiddleware(options: AuthRefreshOptions): Middleware;
|
|
3573
3676
|
|
|
3574
|
-
|
|
3677
|
+
/**
|
|
3678
|
+
* Options for the rate limit middleware
|
|
3679
|
+
*/
|
|
3680
|
+
interface RateLimitOptions {
|
|
3681
|
+
/**
|
|
3682
|
+
* Enable automatic retry on 429 responses
|
|
3683
|
+
* @default false
|
|
3684
|
+
*/
|
|
3685
|
+
enableRetry?: boolean;
|
|
3686
|
+
/**
|
|
3687
|
+
* Enable preemptive throttling to avoid hitting rate limits
|
|
3688
|
+
* @default false
|
|
3689
|
+
*/
|
|
3690
|
+
enableThrottle?: boolean;
|
|
3691
|
+
/**
|
|
3692
|
+
* Maximum number of retry attempts
|
|
3693
|
+
* @default 3
|
|
3694
|
+
*/
|
|
3695
|
+
maxRetries?: number;
|
|
3696
|
+
/**
|
|
3697
|
+
* Base delay in milliseconds for retries when no retryAfter is provided
|
|
3698
|
+
* @default 1000
|
|
3699
|
+
*/
|
|
3700
|
+
baseDelay?: number;
|
|
3701
|
+
/**
|
|
3702
|
+
* Use exponential backoff for retries
|
|
3703
|
+
* @default true
|
|
3704
|
+
*/
|
|
3705
|
+
exponentialBackoff?: boolean;
|
|
3706
|
+
/**
|
|
3707
|
+
* Add random jitter to retry delays to prevent thundering herd
|
|
3708
|
+
* @default true
|
|
3709
|
+
*/
|
|
3710
|
+
jitter?: boolean;
|
|
3711
|
+
/**
|
|
3712
|
+
* Maximum requests per minute (primary limit)
|
|
3713
|
+
* @default 1000
|
|
3714
|
+
*/
|
|
3715
|
+
requestsPerMinute?: number;
|
|
3716
|
+
/**
|
|
3717
|
+
* Maximum requests per burst window
|
|
3718
|
+
* @default 5000
|
|
3719
|
+
*/
|
|
3720
|
+
burstLimit?: number;
|
|
3721
|
+
/**
|
|
3722
|
+
* Burst window in milliseconds
|
|
3723
|
+
* @default 300000 (5 minutes)
|
|
3724
|
+
*/
|
|
3725
|
+
burstWindowMs?: number;
|
|
3726
|
+
/**
|
|
3727
|
+
* Start throttling when usage reaches this percentage of the limit (0-1)
|
|
3728
|
+
* @default 0.9
|
|
3729
|
+
*/
|
|
3730
|
+
throttleThreshold?: number;
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Creates a middleware that handles rate limiting with optional retry and throttling
|
|
3734
|
+
*
|
|
3735
|
+
* @example
|
|
3736
|
+
* ```typescript
|
|
3737
|
+
* const client = new MantleCoreClient({ ... });
|
|
3738
|
+
*
|
|
3739
|
+
* // Enable retry on 429 responses
|
|
3740
|
+
* client.use(createRateLimitMiddleware({
|
|
3741
|
+
* enableRetry: true,
|
|
3742
|
+
* }));
|
|
3743
|
+
*
|
|
3744
|
+
* // Enable preemptive throttling
|
|
3745
|
+
* client.use(createRateLimitMiddleware({
|
|
3746
|
+
* enableThrottle: true,
|
|
3747
|
+
* }));
|
|
3748
|
+
*
|
|
3749
|
+
* // Enable both features
|
|
3750
|
+
* client.use(createRateLimitMiddleware({
|
|
3751
|
+
* enableRetry: true,
|
|
3752
|
+
* enableThrottle: true,
|
|
3753
|
+
* maxRetries: 5,
|
|
3754
|
+
* requestsPerMinute: 500,
|
|
3755
|
+
* }));
|
|
3756
|
+
* ```
|
|
3757
|
+
*/
|
|
3758
|
+
declare function createRateLimitMiddleware(options?: RateLimitOptions): Middleware;
|
|
3759
|
+
|
|
3760
|
+
export { type AccountOwner, type AccountOwnersListResponse, type Affiliate, type AffiliateCommission, type AffiliateCommissionListParams, type AffiliateCommissionListResponse, AffiliateCommissionsResource, type AffiliateListParams, type AffiliateListResponse, type AffiliatePayout, type AffiliatePayoutListParams, type AffiliatePayoutListResponse, AffiliatePayoutsResource, type AffiliateProgram, type AffiliateProgramCreateParams, type AffiliateProgramUpdateParams, AffiliateProgramsResource, type AffiliateReferral, type AffiliateReferralListParams, type AffiliateReferralListResponse, AffiliateReferralsResource, type AffiliateUpdateParams, AffiliatesResource, type Agent, type AgentCreateParams, type AgentListResponse, type AgentResponse, AgentsResource, type App, type AppEvent, type AppEventListParams, type AppEventListResponse, type AppInstallation, type AppInstallationParams, type AppListParams, AppsResource, type AuthRefreshOptions, BaseResource, type Channel, type ChannelCreateParams, type ChannelListParams, ChannelsResource, type Charge, type ChargeListParams, type ChargeListResponse, ChargesResource, CompaniesResource, type Company, type CompanyCreateParams, type CompanyListParams, type CompanyListResponse, type CompanyUpdateParams, type Contact, type ContactCreateParams, type ContactEntity, type ContactListParams, type ContactListResponse, type ContactUpdateParams, ContactsResource, type CustomDataDeleteParams, type CustomDataGetParams, CustomDataResource, type CustomDataResourceType, type CustomDataResponse, type CustomDataSetParams, type CustomField, type CustomFieldCreateParams, type CustomFieldUpdateParams, type Customer, type CustomerCreateParams, type CustomerEntity, type CustomerListParams, type CustomerListResponse, type CustomerRetrieveParams, type CustomerSegment, type CustomerSegmentListParams, type CustomerSegmentListResponse, CustomerSegmentsResource, type CustomerUpdateParams, CustomersResource, type DateRangeType, type Deal, DealActivitiesResource, type DealActivity, type DealActivityCreateParams, type DealActivityUpdateParams, type DealContactInput, type DealCreateParams, type DealCustomerInput, type DealEvent, type DealEventCreateParams, type DealEventCreateResponse, type DealEventListResponse, type DealFlow, type DealFlowCreateParams, type DealFlowUpdateParams, DealFlowsResource, type DealListParams, type DealListResponse, type DealProgression, type DealStage, type DealUpdateParams, DealsResource, type DeleteResponse, type DocCollection, type DocCollectionCreateParams, type DocCollectionUpdateParams, type DocGroup, type DocGroupCreateParams, type DocGroupUpdateParams, type DocPage, type DocPageCreateParams, type DocPageListParams, type DocPageListResponse, type DocPageStatus, type DocPageUpdateParams, type DocTreeNode, type DocTreeResponse, DocsResource, EntitiesResource, type EntitiesSearchParams, type EntitiesSearchResponse, type Entity, type EntityType, type Feature, type FeatureCreateParams, type FeatureUpdateParams, type Flow, type FlowCreateParams, type FlowListParams, type FlowListResponse, type FlowStatus, type FlowUpdateParams, FlowsResource, type HttpMethod, type ListParams, MantleAPIError, MantleAuthenticationError, MantleCoreClient, type MantleCoreClientConfig, MantleNotFoundError, MantlePermissionError, MantleRateLimitError, MantleValidationError, MeResource, type MeResponse, type MessageAttachment, type MetricDataPoint, type MetricType, type MetricsBaseParams, type MetricsGetParams, MetricsResource, type MetricsResponse, type Middleware, type MiddlewareContext, MiddlewareManager, type MiddlewareOptions, type MiddlewareRequest, type MiddlewareResponse, type NextFunction, type Organization, OrganizationResource, type PaginatedResponse, type Plan, type PlanCreateParams, type PlanFeature, type PlanListParams, type PlanListResponse, type PlanUpdateParams, type PlanUsageCharge, type RateLimitOptions, type RequestOptions, type Review, type ReviewCreateParams, type ReviewUpdateParams, type SocialProfile, type SocialProfileType, type Subscription, type SubscriptionListParams, type SubscriptionListResponse, SubscriptionsResource, type Task, type TaskCreateParams, type TaskListParams, type TaskListResponse, type TaskPriority, type TaskStatus, type TaskUpdateParams, type TaskUpdateResponse, TasksResource, type Ticket, type TicketContactData, type TicketCreateParams, type TicketListParams, type TicketListResponse, type TicketMessage, type TicketMessageCreateParams, type TicketMessageUpdateParams, type TicketUpdateParams, TicketsResource, type TimelineEvent, type TimelineListParams, type TimelineListResponse, type TodoItem, type TodoItemCreateParams, type TodoItemInput, type TodoItemListResponse, type TodoItemUpdateParams, type Transaction, type TransactionListParams, type TransactionListResponse, TransactionsResource, type UsageEvent, type UsageEventCreateData, type UsageEventCreateParams, type UsageEventCreateResponse, type UsageEventListParams, type UsageEventListResponse, type UsageEventMetricsParams, UsageEventsResource, type UsageMetric, type UsageMetricCreateParams, type UsageMetricParams, type UsageMetricUpdateParams, type User, type UserListParams, type UserListResponse, UsersResource, type Webhook, type WebhookCreateParams, type WebhookFilter, type WebhookListResponse, type WebhookTopic, type WebhookUpdateParams, WebhooksResource, createAuthRefreshMiddleware, createRateLimitMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -1815,11 +1815,30 @@ interface AgentResponse {
|
|
|
1815
1815
|
/**
|
|
1816
1816
|
* Task status
|
|
1817
1817
|
*/
|
|
1818
|
-
type TaskStatus = '
|
|
1818
|
+
type TaskStatus = 'new' | 'in_progress' | 'complete';
|
|
1819
1819
|
/**
|
|
1820
1820
|
* Task priority
|
|
1821
1821
|
*/
|
|
1822
|
-
type TaskPriority = 'low' | 'medium' | 'high'
|
|
1822
|
+
type TaskPriority = 'low' | 'medium' | 'high';
|
|
1823
|
+
/**
|
|
1824
|
+
* Task todo item entity
|
|
1825
|
+
*/
|
|
1826
|
+
interface TodoItem {
|
|
1827
|
+
id: string;
|
|
1828
|
+
content: string;
|
|
1829
|
+
completed: boolean;
|
|
1830
|
+
completedAt?: string | null;
|
|
1831
|
+
displayOrder: number;
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Parameters for creating a todo item (used in task creation/update)
|
|
1835
|
+
*/
|
|
1836
|
+
interface TodoItemInput {
|
|
1837
|
+
id?: string;
|
|
1838
|
+
content: string;
|
|
1839
|
+
completed?: boolean;
|
|
1840
|
+
displayOrder?: number;
|
|
1841
|
+
}
|
|
1823
1842
|
/**
|
|
1824
1843
|
* Task entity
|
|
1825
1844
|
*/
|
|
@@ -1831,6 +1850,7 @@ interface Task {
|
|
|
1831
1850
|
priority: TaskPriority;
|
|
1832
1851
|
status: TaskStatus;
|
|
1833
1852
|
dueDate?: string;
|
|
1853
|
+
completedAt?: string | null;
|
|
1834
1854
|
assigneeId?: string;
|
|
1835
1855
|
customerId?: string;
|
|
1836
1856
|
contactId?: string;
|
|
@@ -1844,19 +1864,33 @@ interface Task {
|
|
|
1844
1864
|
id: string;
|
|
1845
1865
|
name?: string;
|
|
1846
1866
|
email?: string;
|
|
1847
|
-
};
|
|
1867
|
+
} | null;
|
|
1868
|
+
createdBy?: {
|
|
1869
|
+
id: string;
|
|
1870
|
+
name?: string;
|
|
1871
|
+
email?: string;
|
|
1872
|
+
} | null;
|
|
1848
1873
|
customer?: {
|
|
1849
1874
|
id: string;
|
|
1850
1875
|
name?: string;
|
|
1851
|
-
};
|
|
1876
|
+
} | null;
|
|
1852
1877
|
contact?: {
|
|
1853
1878
|
id: string;
|
|
1854
1879
|
name?: string;
|
|
1855
|
-
};
|
|
1880
|
+
} | null;
|
|
1856
1881
|
deal?: {
|
|
1857
1882
|
id: string;
|
|
1858
1883
|
name?: string;
|
|
1859
|
-
|
|
1884
|
+
dealStage?: {
|
|
1885
|
+
id: string;
|
|
1886
|
+
name?: string;
|
|
1887
|
+
} | null;
|
|
1888
|
+
} | null;
|
|
1889
|
+
dealActivity?: {
|
|
1890
|
+
id: string;
|
|
1891
|
+
name?: string;
|
|
1892
|
+
} | null;
|
|
1893
|
+
todoItems?: TodoItem[];
|
|
1860
1894
|
}
|
|
1861
1895
|
/**
|
|
1862
1896
|
* Parameters for listing tasks
|
|
@@ -1891,12 +1925,59 @@ interface TaskCreateParams {
|
|
|
1891
1925
|
dealActivityId?: string;
|
|
1892
1926
|
appInstallationId?: string;
|
|
1893
1927
|
tags?: string[];
|
|
1928
|
+
todoItems?: TodoItemInput[];
|
|
1894
1929
|
}
|
|
1895
1930
|
/**
|
|
1896
1931
|
* Parameters for updating a task
|
|
1897
1932
|
*/
|
|
1898
1933
|
interface TaskUpdateParams extends Partial<TaskCreateParams> {
|
|
1899
1934
|
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Response from listing todo items
|
|
1937
|
+
*/
|
|
1938
|
+
interface TodoItemListResponse {
|
|
1939
|
+
items: TodoItem[];
|
|
1940
|
+
total: number;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Deal progression information returned when a task update triggers deal stage change
|
|
1944
|
+
*/
|
|
1945
|
+
interface DealProgression {
|
|
1946
|
+
dealId: string;
|
|
1947
|
+
dealName: string;
|
|
1948
|
+
previousStage: {
|
|
1949
|
+
id: string;
|
|
1950
|
+
name: string;
|
|
1951
|
+
} | null;
|
|
1952
|
+
nextStage: {
|
|
1953
|
+
id: string;
|
|
1954
|
+
name: string;
|
|
1955
|
+
} | null;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Response from updating a task
|
|
1959
|
+
*/
|
|
1960
|
+
interface TaskUpdateResponse {
|
|
1961
|
+
task: Task;
|
|
1962
|
+
dealProgressed: boolean;
|
|
1963
|
+
dealProgression: DealProgression | null;
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Parameters for creating a todo item via the dedicated endpoint
|
|
1967
|
+
*/
|
|
1968
|
+
interface TodoItemCreateParams {
|
|
1969
|
+
content: string;
|
|
1970
|
+
completed?: boolean;
|
|
1971
|
+
displayOrder?: number;
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Parameters for updating a todo item
|
|
1975
|
+
*/
|
|
1976
|
+
interface TodoItemUpdateParams {
|
|
1977
|
+
content?: string;
|
|
1978
|
+
completed?: boolean;
|
|
1979
|
+
displayOrder?: number;
|
|
1980
|
+
}
|
|
1900
1981
|
|
|
1901
1982
|
/**
|
|
1902
1983
|
* Company entity
|
|
@@ -2771,19 +2852,41 @@ declare class TasksResource extends BaseResource {
|
|
|
2771
2852
|
/**
|
|
2772
2853
|
* Create a new task
|
|
2773
2854
|
*/
|
|
2774
|
-
create(data: TaskCreateParams): Promise<
|
|
2775
|
-
task: Task;
|
|
2776
|
-
}>;
|
|
2855
|
+
create(data: TaskCreateParams): Promise<Task>;
|
|
2777
2856
|
/**
|
|
2778
2857
|
* Update an existing task
|
|
2779
2858
|
*/
|
|
2780
|
-
update(taskId: string, data: TaskUpdateParams): Promise<
|
|
2781
|
-
task: Task;
|
|
2782
|
-
}>;
|
|
2859
|
+
update(taskId: string, data: TaskUpdateParams): Promise<TaskUpdateResponse>;
|
|
2783
2860
|
/**
|
|
2784
2861
|
* Delete a task
|
|
2785
2862
|
*/
|
|
2786
2863
|
del(taskId: string): Promise<DeleteResponse>;
|
|
2864
|
+
/**
|
|
2865
|
+
* List todo items for a task
|
|
2866
|
+
*/
|
|
2867
|
+
listTodoItems(taskId: string): Promise<TodoItemListResponse>;
|
|
2868
|
+
/**
|
|
2869
|
+
* Retrieve a single todo item
|
|
2870
|
+
*/
|
|
2871
|
+
retrieveTodoItem(taskId: string, itemId: string): Promise<{
|
|
2872
|
+
item: TodoItem;
|
|
2873
|
+
}>;
|
|
2874
|
+
/**
|
|
2875
|
+
* Create a todo item for a task
|
|
2876
|
+
*/
|
|
2877
|
+
createTodoItem(taskId: string, data: TodoItemCreateParams): Promise<{
|
|
2878
|
+
item: TodoItem;
|
|
2879
|
+
}>;
|
|
2880
|
+
/**
|
|
2881
|
+
* Update a todo item
|
|
2882
|
+
*/
|
|
2883
|
+
updateTodoItem(taskId: string, itemId: string, data: TodoItemUpdateParams): Promise<{
|
|
2884
|
+
item: TodoItem;
|
|
2885
|
+
}>;
|
|
2886
|
+
/**
|
|
2887
|
+
* Delete a todo item
|
|
2888
|
+
*/
|
|
2889
|
+
deleteTodoItem(taskId: string, itemId: string): Promise<DeleteResponse>;
|
|
2787
2890
|
}
|
|
2788
2891
|
|
|
2789
2892
|
/**
|
|
@@ -3571,4 +3674,87 @@ interface AuthRefreshOptions {
|
|
|
3571
3674
|
*/
|
|
3572
3675
|
declare function createAuthRefreshMiddleware(options: AuthRefreshOptions): Middleware;
|
|
3573
3676
|
|
|
3574
|
-
|
|
3677
|
+
/**
|
|
3678
|
+
* Options for the rate limit middleware
|
|
3679
|
+
*/
|
|
3680
|
+
interface RateLimitOptions {
|
|
3681
|
+
/**
|
|
3682
|
+
* Enable automatic retry on 429 responses
|
|
3683
|
+
* @default false
|
|
3684
|
+
*/
|
|
3685
|
+
enableRetry?: boolean;
|
|
3686
|
+
/**
|
|
3687
|
+
* Enable preemptive throttling to avoid hitting rate limits
|
|
3688
|
+
* @default false
|
|
3689
|
+
*/
|
|
3690
|
+
enableThrottle?: boolean;
|
|
3691
|
+
/**
|
|
3692
|
+
* Maximum number of retry attempts
|
|
3693
|
+
* @default 3
|
|
3694
|
+
*/
|
|
3695
|
+
maxRetries?: number;
|
|
3696
|
+
/**
|
|
3697
|
+
* Base delay in milliseconds for retries when no retryAfter is provided
|
|
3698
|
+
* @default 1000
|
|
3699
|
+
*/
|
|
3700
|
+
baseDelay?: number;
|
|
3701
|
+
/**
|
|
3702
|
+
* Use exponential backoff for retries
|
|
3703
|
+
* @default true
|
|
3704
|
+
*/
|
|
3705
|
+
exponentialBackoff?: boolean;
|
|
3706
|
+
/**
|
|
3707
|
+
* Add random jitter to retry delays to prevent thundering herd
|
|
3708
|
+
* @default true
|
|
3709
|
+
*/
|
|
3710
|
+
jitter?: boolean;
|
|
3711
|
+
/**
|
|
3712
|
+
* Maximum requests per minute (primary limit)
|
|
3713
|
+
* @default 1000
|
|
3714
|
+
*/
|
|
3715
|
+
requestsPerMinute?: number;
|
|
3716
|
+
/**
|
|
3717
|
+
* Maximum requests per burst window
|
|
3718
|
+
* @default 5000
|
|
3719
|
+
*/
|
|
3720
|
+
burstLimit?: number;
|
|
3721
|
+
/**
|
|
3722
|
+
* Burst window in milliseconds
|
|
3723
|
+
* @default 300000 (5 minutes)
|
|
3724
|
+
*/
|
|
3725
|
+
burstWindowMs?: number;
|
|
3726
|
+
/**
|
|
3727
|
+
* Start throttling when usage reaches this percentage of the limit (0-1)
|
|
3728
|
+
* @default 0.9
|
|
3729
|
+
*/
|
|
3730
|
+
throttleThreshold?: number;
|
|
3731
|
+
}
|
|
3732
|
+
/**
|
|
3733
|
+
* Creates a middleware that handles rate limiting with optional retry and throttling
|
|
3734
|
+
*
|
|
3735
|
+
* @example
|
|
3736
|
+
* ```typescript
|
|
3737
|
+
* const client = new MantleCoreClient({ ... });
|
|
3738
|
+
*
|
|
3739
|
+
* // Enable retry on 429 responses
|
|
3740
|
+
* client.use(createRateLimitMiddleware({
|
|
3741
|
+
* enableRetry: true,
|
|
3742
|
+
* }));
|
|
3743
|
+
*
|
|
3744
|
+
* // Enable preemptive throttling
|
|
3745
|
+
* client.use(createRateLimitMiddleware({
|
|
3746
|
+
* enableThrottle: true,
|
|
3747
|
+
* }));
|
|
3748
|
+
*
|
|
3749
|
+
* // Enable both features
|
|
3750
|
+
* client.use(createRateLimitMiddleware({
|
|
3751
|
+
* enableRetry: true,
|
|
3752
|
+
* enableThrottle: true,
|
|
3753
|
+
* maxRetries: 5,
|
|
3754
|
+
* requestsPerMinute: 500,
|
|
3755
|
+
* }));
|
|
3756
|
+
* ```
|
|
3757
|
+
*/
|
|
3758
|
+
declare function createRateLimitMiddleware(options?: RateLimitOptions): Middleware;
|
|
3759
|
+
|
|
3760
|
+
export { type AccountOwner, type AccountOwnersListResponse, type Affiliate, type AffiliateCommission, type AffiliateCommissionListParams, type AffiliateCommissionListResponse, AffiliateCommissionsResource, type AffiliateListParams, type AffiliateListResponse, type AffiliatePayout, type AffiliatePayoutListParams, type AffiliatePayoutListResponse, AffiliatePayoutsResource, type AffiliateProgram, type AffiliateProgramCreateParams, type AffiliateProgramUpdateParams, AffiliateProgramsResource, type AffiliateReferral, type AffiliateReferralListParams, type AffiliateReferralListResponse, AffiliateReferralsResource, type AffiliateUpdateParams, AffiliatesResource, type Agent, type AgentCreateParams, type AgentListResponse, type AgentResponse, AgentsResource, type App, type AppEvent, type AppEventListParams, type AppEventListResponse, type AppInstallation, type AppInstallationParams, type AppListParams, AppsResource, type AuthRefreshOptions, BaseResource, type Channel, type ChannelCreateParams, type ChannelListParams, ChannelsResource, type Charge, type ChargeListParams, type ChargeListResponse, ChargesResource, CompaniesResource, type Company, type CompanyCreateParams, type CompanyListParams, type CompanyListResponse, type CompanyUpdateParams, type Contact, type ContactCreateParams, type ContactEntity, type ContactListParams, type ContactListResponse, type ContactUpdateParams, ContactsResource, type CustomDataDeleteParams, type CustomDataGetParams, CustomDataResource, type CustomDataResourceType, type CustomDataResponse, type CustomDataSetParams, type CustomField, type CustomFieldCreateParams, type CustomFieldUpdateParams, type Customer, type CustomerCreateParams, type CustomerEntity, type CustomerListParams, type CustomerListResponse, type CustomerRetrieveParams, type CustomerSegment, type CustomerSegmentListParams, type CustomerSegmentListResponse, CustomerSegmentsResource, type CustomerUpdateParams, CustomersResource, type DateRangeType, type Deal, DealActivitiesResource, type DealActivity, type DealActivityCreateParams, type DealActivityUpdateParams, type DealContactInput, type DealCreateParams, type DealCustomerInput, type DealEvent, type DealEventCreateParams, type DealEventCreateResponse, type DealEventListResponse, type DealFlow, type DealFlowCreateParams, type DealFlowUpdateParams, DealFlowsResource, type DealListParams, type DealListResponse, type DealProgression, type DealStage, type DealUpdateParams, DealsResource, type DeleteResponse, type DocCollection, type DocCollectionCreateParams, type DocCollectionUpdateParams, type DocGroup, type DocGroupCreateParams, type DocGroupUpdateParams, type DocPage, type DocPageCreateParams, type DocPageListParams, type DocPageListResponse, type DocPageStatus, type DocPageUpdateParams, type DocTreeNode, type DocTreeResponse, DocsResource, EntitiesResource, type EntitiesSearchParams, type EntitiesSearchResponse, type Entity, type EntityType, type Feature, type FeatureCreateParams, type FeatureUpdateParams, type Flow, type FlowCreateParams, type FlowListParams, type FlowListResponse, type FlowStatus, type FlowUpdateParams, FlowsResource, type HttpMethod, type ListParams, MantleAPIError, MantleAuthenticationError, MantleCoreClient, type MantleCoreClientConfig, MantleNotFoundError, MantlePermissionError, MantleRateLimitError, MantleValidationError, MeResource, type MeResponse, type MessageAttachment, type MetricDataPoint, type MetricType, type MetricsBaseParams, type MetricsGetParams, MetricsResource, type MetricsResponse, type Middleware, type MiddlewareContext, MiddlewareManager, type MiddlewareOptions, type MiddlewareRequest, type MiddlewareResponse, type NextFunction, type Organization, OrganizationResource, type PaginatedResponse, type Plan, type PlanCreateParams, type PlanFeature, type PlanListParams, type PlanListResponse, type PlanUpdateParams, type PlanUsageCharge, type RateLimitOptions, type RequestOptions, type Review, type ReviewCreateParams, type ReviewUpdateParams, type SocialProfile, type SocialProfileType, type Subscription, type SubscriptionListParams, type SubscriptionListResponse, SubscriptionsResource, type Task, type TaskCreateParams, type TaskListParams, type TaskListResponse, type TaskPriority, type TaskStatus, type TaskUpdateParams, type TaskUpdateResponse, TasksResource, type Ticket, type TicketContactData, type TicketCreateParams, type TicketListParams, type TicketListResponse, type TicketMessage, type TicketMessageCreateParams, type TicketMessageUpdateParams, type TicketUpdateParams, TicketsResource, type TimelineEvent, type TimelineListParams, type TimelineListResponse, type TodoItem, type TodoItemCreateParams, type TodoItemInput, type TodoItemListResponse, type TodoItemUpdateParams, type Transaction, type TransactionListParams, type TransactionListResponse, TransactionsResource, type UsageEvent, type UsageEventCreateData, type UsageEventCreateParams, type UsageEventCreateResponse, type UsageEventListParams, type UsageEventListResponse, type UsageEventMetricsParams, UsageEventsResource, type UsageMetric, type UsageMetricCreateParams, type UsageMetricParams, type UsageMetricUpdateParams, type User, type UserListParams, type UserListResponse, UsersResource, type Webhook, type WebhookCreateParams, type WebhookFilter, type WebhookListResponse, type WebhookTopic, type WebhookUpdateParams, WebhooksResource, createAuthRefreshMiddleware, createRateLimitMiddleware };
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,8 @@ __export(index_exports, {
|
|
|
59
59
|
UsageEventsResource: () => UsageEventsResource,
|
|
60
60
|
UsersResource: () => UsersResource,
|
|
61
61
|
WebhooksResource: () => WebhooksResource,
|
|
62
|
-
createAuthRefreshMiddleware: () => createAuthRefreshMiddleware
|
|
62
|
+
createAuthRefreshMiddleware: () => createAuthRefreshMiddleware,
|
|
63
|
+
createRateLimitMiddleware: () => createRateLimitMiddleware
|
|
63
64
|
});
|
|
64
65
|
module.exports = __toCommonJS(index_exports);
|
|
65
66
|
|
|
@@ -1154,6 +1155,40 @@ var TasksResource = class extends BaseResource {
|
|
|
1154
1155
|
async del(taskId) {
|
|
1155
1156
|
return this._delete(`/tasks/${taskId}`);
|
|
1156
1157
|
}
|
|
1158
|
+
// ========== Todo Items ==========
|
|
1159
|
+
/**
|
|
1160
|
+
* List todo items for a task
|
|
1161
|
+
*/
|
|
1162
|
+
async listTodoItems(taskId) {
|
|
1163
|
+
return this.get(`/tasks/${taskId}/todo-items`);
|
|
1164
|
+
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Retrieve a single todo item
|
|
1167
|
+
*/
|
|
1168
|
+
async retrieveTodoItem(taskId, itemId) {
|
|
1169
|
+
return this.get(`/tasks/${taskId}/todo-items/${itemId}`);
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Create a todo item for a task
|
|
1173
|
+
*/
|
|
1174
|
+
async createTodoItem(taskId, data) {
|
|
1175
|
+
return this.post(`/tasks/${taskId}/todo-items`, data);
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Update a todo item
|
|
1179
|
+
*/
|
|
1180
|
+
async updateTodoItem(taskId, itemId, data) {
|
|
1181
|
+
return this.put(
|
|
1182
|
+
`/tasks/${taskId}/todo-items/${itemId}`,
|
|
1183
|
+
data
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Delete a todo item
|
|
1188
|
+
*/
|
|
1189
|
+
async deleteTodoItem(taskId, itemId) {
|
|
1190
|
+
return this._delete(`/tasks/${taskId}/todo-items/${itemId}`);
|
|
1191
|
+
}
|
|
1157
1192
|
};
|
|
1158
1193
|
|
|
1159
1194
|
// src/resources/webhooks.ts
|
|
@@ -2254,6 +2289,136 @@ function createAuthRefreshMiddleware(options) {
|
|
|
2254
2289
|
}
|
|
2255
2290
|
};
|
|
2256
2291
|
}
|
|
2292
|
+
|
|
2293
|
+
// src/middleware/rate-limit.ts
|
|
2294
|
+
var RateLimiter = class {
|
|
2295
|
+
constructor(options) {
|
|
2296
|
+
this.timestamps = [];
|
|
2297
|
+
this.requestsPerMinute = options.requestsPerMinute;
|
|
2298
|
+
this.burstLimit = options.burstLimit;
|
|
2299
|
+
this.burstWindowMs = options.burstWindowMs;
|
|
2300
|
+
this.throttleThreshold = options.throttleThreshold;
|
|
2301
|
+
}
|
|
2302
|
+
/**
|
|
2303
|
+
* Prune timestamps older than the burst window
|
|
2304
|
+
*/
|
|
2305
|
+
prune() {
|
|
2306
|
+
const now = Date.now();
|
|
2307
|
+
const cutoff = now - this.burstWindowMs;
|
|
2308
|
+
this.timestamps = this.timestamps.filter((ts) => ts > cutoff);
|
|
2309
|
+
}
|
|
2310
|
+
/**
|
|
2311
|
+
* Get current usage statistics
|
|
2312
|
+
*/
|
|
2313
|
+
getUsage() {
|
|
2314
|
+
this.prune();
|
|
2315
|
+
const now = Date.now();
|
|
2316
|
+
const oneMinuteAgo = now - 6e4;
|
|
2317
|
+
const minuteUsage = this.timestamps.filter((ts) => ts > oneMinuteAgo).length;
|
|
2318
|
+
const burstUsage = this.timestamps.length;
|
|
2319
|
+
return { minuteUsage, burstUsage };
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Calculate the delay needed before the next request can be made
|
|
2323
|
+
* Returns 0 if no delay is needed
|
|
2324
|
+
*/
|
|
2325
|
+
getDelay() {
|
|
2326
|
+
const { minuteUsage, burstUsage } = this.getUsage();
|
|
2327
|
+
const minuteThreshold = Math.floor(this.requestsPerMinute * this.throttleThreshold);
|
|
2328
|
+
const burstThreshold = Math.floor(this.burstLimit * this.throttleThreshold);
|
|
2329
|
+
if (minuteUsage >= minuteThreshold) {
|
|
2330
|
+
const now = Date.now();
|
|
2331
|
+
const oneMinuteAgo = now - 6e4;
|
|
2332
|
+
const oldestInMinute = this.timestamps.find((ts) => ts > oneMinuteAgo);
|
|
2333
|
+
if (oldestInMinute) {
|
|
2334
|
+
const delay = oldestInMinute + 6e4 - now;
|
|
2335
|
+
if (delay > 0) {
|
|
2336
|
+
return delay;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
if (burstUsage >= burstThreshold) {
|
|
2341
|
+
const now = Date.now();
|
|
2342
|
+
const burstCutoff = now - this.burstWindowMs;
|
|
2343
|
+
const oldestInBurst = this.timestamps.find((ts) => ts > burstCutoff);
|
|
2344
|
+
if (oldestInBurst) {
|
|
2345
|
+
const delay = oldestInBurst + this.burstWindowMs - now;
|
|
2346
|
+
if (delay > 0) {
|
|
2347
|
+
return delay;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
return 0;
|
|
2352
|
+
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Record a request timestamp
|
|
2355
|
+
*/
|
|
2356
|
+
recordRequest() {
|
|
2357
|
+
this.timestamps.push(Date.now());
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
function calculateRetryDelay(retryAfter, retryCount, options) {
|
|
2361
|
+
let delay;
|
|
2362
|
+
if (retryAfter !== void 0 && retryAfter > 0) {
|
|
2363
|
+
return retryAfter * 1e3;
|
|
2364
|
+
} else if (options.exponentialBackoff) {
|
|
2365
|
+
delay = options.baseDelay * Math.pow(2, retryCount);
|
|
2366
|
+
} else {
|
|
2367
|
+
delay = options.baseDelay;
|
|
2368
|
+
}
|
|
2369
|
+
if (options.jitter) {
|
|
2370
|
+
const jitterFactor = 0.75 + Math.random() * 0.5;
|
|
2371
|
+
delay = Math.floor(delay * jitterFactor);
|
|
2372
|
+
}
|
|
2373
|
+
return delay;
|
|
2374
|
+
}
|
|
2375
|
+
function createRateLimitMiddleware(options = {}) {
|
|
2376
|
+
const {
|
|
2377
|
+
enableRetry = false,
|
|
2378
|
+
enableThrottle = false,
|
|
2379
|
+
maxRetries = 3,
|
|
2380
|
+
baseDelay = 1e3,
|
|
2381
|
+
exponentialBackoff = true,
|
|
2382
|
+
jitter = true,
|
|
2383
|
+
requestsPerMinute = 1e3,
|
|
2384
|
+
burstLimit = 5e3,
|
|
2385
|
+
burstWindowMs = 3e5,
|
|
2386
|
+
throttleThreshold = 0.9
|
|
2387
|
+
} = options;
|
|
2388
|
+
const rateLimiter = enableThrottle ? new RateLimiter({
|
|
2389
|
+
requestsPerMinute,
|
|
2390
|
+
burstLimit,
|
|
2391
|
+
burstWindowMs,
|
|
2392
|
+
throttleThreshold
|
|
2393
|
+
}) : null;
|
|
2394
|
+
return async (ctx, next) => {
|
|
2395
|
+
if (rateLimiter) {
|
|
2396
|
+
const delay = rateLimiter.getDelay();
|
|
2397
|
+
if (delay > 0) {
|
|
2398
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
try {
|
|
2402
|
+
await next();
|
|
2403
|
+
rateLimiter?.recordRequest();
|
|
2404
|
+
} catch (error) {
|
|
2405
|
+
rateLimiter?.recordRequest();
|
|
2406
|
+
if (enableRetry && error instanceof MantleRateLimitError) {
|
|
2407
|
+
if (ctx.retryCount < maxRetries) {
|
|
2408
|
+
const delay = calculateRetryDelay(error.retryAfter, ctx.retryCount, {
|
|
2409
|
+
baseDelay,
|
|
2410
|
+
exponentialBackoff,
|
|
2411
|
+
jitter
|
|
2412
|
+
});
|
|
2413
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2414
|
+
ctx.retry = true;
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
throw error;
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2257
2422
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2258
2423
|
0 && (module.exports = {
|
|
2259
2424
|
AffiliateCommissionsResource,
|
|
@@ -2295,5 +2460,6 @@ function createAuthRefreshMiddleware(options) {
|
|
|
2295
2460
|
UsageEventsResource,
|
|
2296
2461
|
UsersResource,
|
|
2297
2462
|
WebhooksResource,
|
|
2298
|
-
createAuthRefreshMiddleware
|
|
2463
|
+
createAuthRefreshMiddleware,
|
|
2464
|
+
createRateLimitMiddleware
|
|
2299
2465
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1089,6 +1089,40 @@ var TasksResource = class extends BaseResource {
|
|
|
1089
1089
|
async del(taskId) {
|
|
1090
1090
|
return this._delete(`/tasks/${taskId}`);
|
|
1091
1091
|
}
|
|
1092
|
+
// ========== Todo Items ==========
|
|
1093
|
+
/**
|
|
1094
|
+
* List todo items for a task
|
|
1095
|
+
*/
|
|
1096
|
+
async listTodoItems(taskId) {
|
|
1097
|
+
return this.get(`/tasks/${taskId}/todo-items`);
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Retrieve a single todo item
|
|
1101
|
+
*/
|
|
1102
|
+
async retrieveTodoItem(taskId, itemId) {
|
|
1103
|
+
return this.get(`/tasks/${taskId}/todo-items/${itemId}`);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Create a todo item for a task
|
|
1107
|
+
*/
|
|
1108
|
+
async createTodoItem(taskId, data) {
|
|
1109
|
+
return this.post(`/tasks/${taskId}/todo-items`, data);
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Update a todo item
|
|
1113
|
+
*/
|
|
1114
|
+
async updateTodoItem(taskId, itemId, data) {
|
|
1115
|
+
return this.put(
|
|
1116
|
+
`/tasks/${taskId}/todo-items/${itemId}`,
|
|
1117
|
+
data
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Delete a todo item
|
|
1122
|
+
*/
|
|
1123
|
+
async deleteTodoItem(taskId, itemId) {
|
|
1124
|
+
return this._delete(`/tasks/${taskId}/todo-items/${itemId}`);
|
|
1125
|
+
}
|
|
1092
1126
|
};
|
|
1093
1127
|
|
|
1094
1128
|
// src/resources/webhooks.ts
|
|
@@ -2189,6 +2223,136 @@ function createAuthRefreshMiddleware(options) {
|
|
|
2189
2223
|
}
|
|
2190
2224
|
};
|
|
2191
2225
|
}
|
|
2226
|
+
|
|
2227
|
+
// src/middleware/rate-limit.ts
|
|
2228
|
+
var RateLimiter = class {
|
|
2229
|
+
constructor(options) {
|
|
2230
|
+
this.timestamps = [];
|
|
2231
|
+
this.requestsPerMinute = options.requestsPerMinute;
|
|
2232
|
+
this.burstLimit = options.burstLimit;
|
|
2233
|
+
this.burstWindowMs = options.burstWindowMs;
|
|
2234
|
+
this.throttleThreshold = options.throttleThreshold;
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Prune timestamps older than the burst window
|
|
2238
|
+
*/
|
|
2239
|
+
prune() {
|
|
2240
|
+
const now = Date.now();
|
|
2241
|
+
const cutoff = now - this.burstWindowMs;
|
|
2242
|
+
this.timestamps = this.timestamps.filter((ts) => ts > cutoff);
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Get current usage statistics
|
|
2246
|
+
*/
|
|
2247
|
+
getUsage() {
|
|
2248
|
+
this.prune();
|
|
2249
|
+
const now = Date.now();
|
|
2250
|
+
const oneMinuteAgo = now - 6e4;
|
|
2251
|
+
const minuteUsage = this.timestamps.filter((ts) => ts > oneMinuteAgo).length;
|
|
2252
|
+
const burstUsage = this.timestamps.length;
|
|
2253
|
+
return { minuteUsage, burstUsage };
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Calculate the delay needed before the next request can be made
|
|
2257
|
+
* Returns 0 if no delay is needed
|
|
2258
|
+
*/
|
|
2259
|
+
getDelay() {
|
|
2260
|
+
const { minuteUsage, burstUsage } = this.getUsage();
|
|
2261
|
+
const minuteThreshold = Math.floor(this.requestsPerMinute * this.throttleThreshold);
|
|
2262
|
+
const burstThreshold = Math.floor(this.burstLimit * this.throttleThreshold);
|
|
2263
|
+
if (minuteUsage >= minuteThreshold) {
|
|
2264
|
+
const now = Date.now();
|
|
2265
|
+
const oneMinuteAgo = now - 6e4;
|
|
2266
|
+
const oldestInMinute = this.timestamps.find((ts) => ts > oneMinuteAgo);
|
|
2267
|
+
if (oldestInMinute) {
|
|
2268
|
+
const delay = oldestInMinute + 6e4 - now;
|
|
2269
|
+
if (delay > 0) {
|
|
2270
|
+
return delay;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
if (burstUsage >= burstThreshold) {
|
|
2275
|
+
const now = Date.now();
|
|
2276
|
+
const burstCutoff = now - this.burstWindowMs;
|
|
2277
|
+
const oldestInBurst = this.timestamps.find((ts) => ts > burstCutoff);
|
|
2278
|
+
if (oldestInBurst) {
|
|
2279
|
+
const delay = oldestInBurst + this.burstWindowMs - now;
|
|
2280
|
+
if (delay > 0) {
|
|
2281
|
+
return delay;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
return 0;
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Record a request timestamp
|
|
2289
|
+
*/
|
|
2290
|
+
recordRequest() {
|
|
2291
|
+
this.timestamps.push(Date.now());
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
function calculateRetryDelay(retryAfter, retryCount, options) {
|
|
2295
|
+
let delay;
|
|
2296
|
+
if (retryAfter !== void 0 && retryAfter > 0) {
|
|
2297
|
+
return retryAfter * 1e3;
|
|
2298
|
+
} else if (options.exponentialBackoff) {
|
|
2299
|
+
delay = options.baseDelay * Math.pow(2, retryCount);
|
|
2300
|
+
} else {
|
|
2301
|
+
delay = options.baseDelay;
|
|
2302
|
+
}
|
|
2303
|
+
if (options.jitter) {
|
|
2304
|
+
const jitterFactor = 0.75 + Math.random() * 0.5;
|
|
2305
|
+
delay = Math.floor(delay * jitterFactor);
|
|
2306
|
+
}
|
|
2307
|
+
return delay;
|
|
2308
|
+
}
|
|
2309
|
+
function createRateLimitMiddleware(options = {}) {
|
|
2310
|
+
const {
|
|
2311
|
+
enableRetry = false,
|
|
2312
|
+
enableThrottle = false,
|
|
2313
|
+
maxRetries = 3,
|
|
2314
|
+
baseDelay = 1e3,
|
|
2315
|
+
exponentialBackoff = true,
|
|
2316
|
+
jitter = true,
|
|
2317
|
+
requestsPerMinute = 1e3,
|
|
2318
|
+
burstLimit = 5e3,
|
|
2319
|
+
burstWindowMs = 3e5,
|
|
2320
|
+
throttleThreshold = 0.9
|
|
2321
|
+
} = options;
|
|
2322
|
+
const rateLimiter = enableThrottle ? new RateLimiter({
|
|
2323
|
+
requestsPerMinute,
|
|
2324
|
+
burstLimit,
|
|
2325
|
+
burstWindowMs,
|
|
2326
|
+
throttleThreshold
|
|
2327
|
+
}) : null;
|
|
2328
|
+
return async (ctx, next) => {
|
|
2329
|
+
if (rateLimiter) {
|
|
2330
|
+
const delay = rateLimiter.getDelay();
|
|
2331
|
+
if (delay > 0) {
|
|
2332
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
try {
|
|
2336
|
+
await next();
|
|
2337
|
+
rateLimiter?.recordRequest();
|
|
2338
|
+
} catch (error) {
|
|
2339
|
+
rateLimiter?.recordRequest();
|
|
2340
|
+
if (enableRetry && error instanceof MantleRateLimitError) {
|
|
2341
|
+
if (ctx.retryCount < maxRetries) {
|
|
2342
|
+
const delay = calculateRetryDelay(error.retryAfter, ctx.retryCount, {
|
|
2343
|
+
baseDelay,
|
|
2344
|
+
exponentialBackoff,
|
|
2345
|
+
jitter
|
|
2346
|
+
});
|
|
2347
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2348
|
+
ctx.retry = true;
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
throw error;
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2192
2356
|
export {
|
|
2193
2357
|
AffiliateCommissionsResource,
|
|
2194
2358
|
AffiliatePayoutsResource,
|
|
@@ -2229,5 +2393,6 @@ export {
|
|
|
2229
2393
|
UsageEventsResource,
|
|
2230
2394
|
UsersResource,
|
|
2231
2395
|
WebhooksResource,
|
|
2232
|
-
createAuthRefreshMiddleware
|
|
2396
|
+
createAuthRefreshMiddleware,
|
|
2397
|
+
createRateLimitMiddleware
|
|
2233
2398
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heymantle/core-api-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "TypeScript SDK for the Mantle Core API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
20
20
|
"test": "vitest run",
|
|
21
21
|
"test:watch": "vitest",
|
|
22
|
+
"test:ui": "vitest --ui",
|
|
22
23
|
"test:coverage": "vitest run --coverage",
|
|
23
24
|
"typecheck": "tsc --noEmit",
|
|
24
25
|
"build-and-publish": "npm install && npm run build && npm publish"
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@types/node": "^20.11.0",
|
|
48
49
|
"@vitest/coverage-v8": "^1.2.0",
|
|
50
|
+
"@vitest/ui": "^1.2.0",
|
|
49
51
|
"tsup": "^8.0.2",
|
|
50
52
|
"typescript": "^5.4.3",
|
|
51
53
|
"vitest": "^1.2.0"
|