@ecodrix/erix-api 1.2.7 → 1.2.9

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.
@@ -1,97 +0,0 @@
1
- import { APIResource } from "../resource";
2
-
3
- export interface LogPaginationQuery {
4
- page?: number;
5
- limit?: number;
6
- trigger?: string;
7
- status?: "received" | "processing" | "completed" | "partial" | "failed";
8
- from?: string;
9
- to?: string;
10
- }
11
-
12
- export interface EventLog {
13
- id: string;
14
- trigger: string;
15
- phone?: string;
16
- email?: string;
17
- status: "received" | "processing" | "completed" | "partial" | "failed";
18
- rulesMatched: number;
19
- jobsCreated: number;
20
- meetLink?: string;
21
- callbackUrl?: string;
22
- callbackStatus: "not_required" | "sent" | "failed";
23
- payload: any;
24
- error?: string;
25
- idempotencyKey?: string;
26
- processedAt?: string;
27
- createdAt: string;
28
- updatedAt: string;
29
- }
30
-
31
- export interface CallbackLog {
32
- id: string;
33
- callbackUrl: string;
34
- method: string;
35
- payload: any;
36
- jobId?: string;
37
- enrollmentId?: string;
38
- responseStatus: number;
39
- responseBody: string;
40
- status: "sent" | "failed" | "pending_retry";
41
- attempts: number;
42
- lastAttemptAt?: string;
43
- signature?: string;
44
- createdAt: string;
45
- }
46
-
47
- export interface LogResponse<T> {
48
- success: boolean;
49
- data: T[];
50
- pagination: {
51
- total: number;
52
- page: number;
53
- limit: number;
54
- pages: number;
55
- };
56
- }
57
-
58
- /**
59
- * Audit and execution logs for platform events and webhooks.
60
- *
61
- * Access via `ecod.logs`.
62
- */
63
- export class Logs extends APIResource {
64
- /**
65
- * List event execution logs with optional filtering.
66
- *
67
- * Use this to audit automation triggers and debug workflow execution.
68
- */
69
- async listEventLogs(query?: LogPaginationQuery): Promise<LogResponse<EventLog>> {
70
- return this.get<LogResponse<EventLog>>("/api/saas/events/logs", {
71
- params: query,
72
- });
73
- }
74
-
75
- /**
76
- * Get detailed information for a single event execution.
77
- */
78
- async getEventLog(id: string): Promise<{ success: boolean; data: EventLog }> {
79
- return this.get<{ success: boolean; data: EventLog }>(`/api/saas/events/logs/${id}`);
80
- }
81
-
82
- /**
83
- * List webhook callback logs (outbound responses from ECODrIx to your system).
84
- */
85
- async listCallbackLogs(query?: LogPaginationQuery): Promise<LogResponse<CallbackLog>> {
86
- return this.get<LogResponse<CallbackLog>>("/api/saas/callbacks/logs", {
87
- params: query,
88
- });
89
- }
90
-
91
- /**
92
- * Get high-level execution statistics for the tenant.
93
- */
94
- async getStats(): Promise<{ success: boolean; data: any }> {
95
- return this.get<{ success: boolean; data: any }>("/api/saas/events/stats");
96
- }
97
- }
@@ -1,179 +0,0 @@
1
- import { APIResource } from "../resource";
2
-
3
- export interface SendCampaignParams {
4
- recipients: string[];
5
- subject: string;
6
- html: string;
7
- }
8
-
9
- export class Emails extends APIResource {
10
- /**
11
- * Dispatch a bulk email campaign to a list of recipients.
12
- *
13
- * @param params - The campaign details (recipients, subject, html).
14
- * @returns The dispatch result.
15
- * @example
16
- * ```typescript
17
- * await erixClient.marketing.emails.sendCampaign({
18
- * recipients: ["user@example.com"],
19
- * subject: "Special Offer",
20
- * html: "<p>Check out our deal!</p>"
21
- * });
22
- * ```
23
- */
24
- async sendCampaign<T = any>(params: SendCampaignParams) {
25
- return this.post<T>("/api/saas/marketing/emails/campaign", params);
26
- }
27
-
28
- /**
29
- * Send a test verification email (used to verify SMTP functionality).
30
- */
31
- async sendTest<T = any>(to: string) {
32
- return this.post<T>("/api/saas/marketing/emails/test", { to });
33
- }
34
- }
35
- export class Campaigns extends APIResource {
36
- /**
37
- * List all email and SMS marketing campaigns with optional status filtering.
38
- *
39
- * @param params - Optional filters (status, limit).
40
- * @returns Paginated list of campaign objects.
41
- * @example
42
- * ```typescript
43
- * const campaigns = await erixClient.marketing.campaigns.list({ status: "sent" });
44
- * ```
45
- */
46
- async list<T = any>(params?: { status?: string; limit?: number }) {
47
- return this.get<T>("/api/saas/marketing/campaigns", { params } as any);
48
- }
49
-
50
- /**
51
- * Create a new marketing campaign (Email or SMS).
52
- *
53
- * @param payload - Campaign details (name, type, content).
54
- * @returns The created campaign record.
55
- * @example
56
- * ```typescript
57
- * await erixClient.marketing.campaigns.create({
58
- * name: "Spring Sale",
59
- * type: "email",
60
- * subject: "Our Spring Sale is Here!",
61
- * html: "<h1>BIG DEALS!</h1>"
62
- * });
63
- * ```
64
- */
65
- async create<T = any>(payload: {
66
- name: string;
67
- type: string;
68
- subject?: string;
69
- html?: string;
70
- templateId?: string;
71
- recipients?: string[];
72
- }) {
73
- return this.post<T>("/api/saas/marketing/campaigns", payload);
74
- }
75
-
76
- /**
77
- * Retrieve full details for a specific marketing campaign.
78
- *
79
- * @param campaignId - The unique ID of the campaign.
80
- * @example
81
- * ```typescript
82
- * const campaign = await erixClient.marketing.campaigns.retrieve("camp_123");
83
- * ```
84
- */
85
- async retrieve<T = any>(campaignId: string) {
86
- return this.get<T>(`/api/saas/marketing/campaigns/${campaignId}`);
87
- }
88
-
89
- /**
90
- * Update a campaign.
91
- */
92
- async update<T = any>(campaignId: string, payload: any) {
93
- return this.patch<T>(`/api/saas/marketing/campaigns/${campaignId}`, payload);
94
- }
95
-
96
- /**
97
- * Delete a campaign.
98
- */
99
- async delete<T = any>(campaignId: string) {
100
- return this.deleteRequest<T>(`/api/saas/marketing/campaigns/${campaignId}`);
101
- }
102
-
103
- /**
104
- * Send a campaign immediately or schedule it for a later date.
105
- *
106
- * @param campaignId - The ID of the campaign to dispatch.
107
- * @param payload - Optional scheduling information (ISO timestamp).
108
- * @example
109
- * ```typescript
110
- * // Send immediately
111
- * await erixClient.marketing.campaigns.send("camp_123");
112
- *
113
- * // Schedule for tomorrow
114
- * await erixClient.marketing.campaigns.send("camp_123", {
115
- * scheduledAt: "2026-04-10T09:00:00Z"
116
- * });
117
- * ```
118
- */
119
- async send<T = any>(campaignId: string, payload?: { scheduledAt?: string }) {
120
- return this.post<T>(`/api/saas/marketing/campaigns/${campaignId}/send`, payload || {});
121
- }
122
-
123
- /**
124
- * Get detailed delivery and engagement statistics for a campaign.
125
- * Includes opens, clicks, bounces, and delivery failures.
126
- *
127
- * @param campaignId - The ID of the campaign.
128
- * @returns Stats summary object.
129
- * @example
130
- * ```typescript
131
- * const report = await erixClient.marketing.campaigns.stats("camp_123");
132
- * console.log(`Open Rate: ${report.openRate}%`);
133
- * ```
134
- */
135
- async stats<T = any>(campaignId: string) {
136
- return this.get<T>(`/api/saas/marketing/campaigns/${campaignId}/stats`);
137
- }
138
- }
139
-
140
- export class WhatsAppMarketing extends APIResource {
141
- /**
142
- * Dispatch a template-based WhatsApp message with CRM-integrated variable resolution.
143
- *
144
- * Unlike direct WhatsApp sending, this endpoint documentation automatically pulls data from the CRM
145
- * based on the provided variables mapping.
146
- *
147
- * @param params - Template details and recipient phone.
148
- * @example
149
- * ```typescript
150
- * await erixClient.marketing.whatsapp.sendTemplate({
151
- * phone: "+919876543210",
152
- * templateName: "order_update",
153
- * variables: { "1": "Order #123" }
154
- * });
155
- * ```
156
- */
157
- async sendTemplate<T = any>(params: {
158
- phone: string;
159
- templateName: string;
160
- languageCode?: string;
161
- variables?: Record<string, string>;
162
- resolvedVariables?: Record<string, string>;
163
- }) {
164
- return this.post<T>("/api/saas/marketing/whatsapp/send-template", params);
165
- }
166
- }
167
-
168
- export class Marketing extends APIResource {
169
- public emails: Emails;
170
- public campaigns: Campaigns;
171
- public whatsapp: WhatsAppMarketing;
172
-
173
- constructor(client: any) {
174
- super(client);
175
- this.emails = new Emails(client);
176
- this.campaigns = new Campaigns(client);
177
- this.whatsapp = new WhatsAppMarketing(client);
178
- }
179
- }
@@ -1,184 +0,0 @@
1
- import axios from "axios";
2
- import { APIResource } from "../resource";
3
-
4
- /**
5
- * Options for the `upload()` elite helper.
6
- */
7
- export interface UploadOptions {
8
- /**
9
- * The destination folder key in R2.
10
- * @example "customer_documents" | "avatars" | "invoices"
11
- */
12
- folder: string;
13
- /**
14
- * The desired filename, including extension.
15
- * @example "contract.pdf" | "profile.jpg"
16
- */
17
- filename: string;
18
- /**
19
- * The MIME type of the file.
20
- * @example "application/pdf" | "image/jpeg" | "video/mp4"
21
- */
22
- contentType: string;
23
- }
24
-
25
- /**
26
- * Cloudflare R2-backed media resource.
27
- *
28
- * Access via `ecod.media`.
29
- *
30
- * The `upload()` method is the recommended approach. It acts as a client-side
31
- * orchestrator: it fetches a presigned URL from the backend, uploads directly
32
- * to R2 (bypassing the API server), then confirms the upload — all in one call.
33
- *
34
- * @example
35
- * ```typescript
36
- * const { data } = await ecod.media.upload(fileBuffer, {
37
- * folder: "invoices",
38
- * filename: "invoice-001.pdf",
39
- * contentType: "application/pdf",
40
- * });
41
- * console.log(data.url); // → https://cdn.ecodrix.com/invoices/invoice-001.pdf
42
- * ```
43
- */
44
- export class Media extends APIResource {
45
- /**
46
- * Get current storage usage metrics for the tenant.
47
- *
48
- * @returns `{ usedMB, limitMB, fileCount }`
49
- *
50
- * @example
51
- * ```typescript
52
- * const { data } = await ecod.media.getUsage();
53
- * console.log(`${data.usedMB} / ${data.limitMB} MB used`);
54
- * ```
55
- */
56
- async getUsage() {
57
- return this.get("/api/saas/storage/usage");
58
- }
59
-
60
- /**
61
- * Create a new top-level folder in the tenant's R2 bucket.
62
- *
63
- * @param name - Folder name (alphanumeric, hyphens, underscores).
64
- *
65
- * @example
66
- * ```typescript
67
- * await ecod.media.createFolder("patient_records");
68
- * ```
69
- */
70
- async createFolder(name: string) {
71
- return this.post("/api/saas/storage/folders", { name });
72
- }
73
-
74
- /**
75
- * List files within a folder, with optional date / search filtering.
76
- *
77
- * @param folder - The folder name to list, **or `"*"` to fetch all folders**
78
- * for the tenant in a single call (returns a merged flat list with a
79
- * `folder` field on each file so callers can group/filter client-side).
80
- * @param params - Optional `year`, `month`, and keyword search `q` filters.
81
- * @returns `{ data: { files, count, totalSizeBytes } }`.
82
- *
83
- * @example Single folder
84
- * ```typescript
85
- * const { data } = await ecod.media.list("invoices", { q: "contract" });
86
- * // data.files → files only from the "invoices" folder
87
- * ```
88
- *
89
- * @example All folders
90
- * ```typescript
91
- * const { data } = await ecod.media.list("*");
92
- * // data.files → merged files from every folder the tenant has
93
- * // Each file has a `folder` field indicating its source folder
94
- * ```
95
- */
96
- async list(folder: string, params?: { year?: string; month?: string; q?: string }) {
97
- return this.get(`/api/saas/storage/files/${folder}`, { params } as any);
98
- }
99
-
100
- /**
101
- * Delete a file from R2 by its storage key.
102
- *
103
- * @param key - The full storage key of the file (e.g. `"invoices/contract.pdf"`).
104
- *
105
- * @example
106
- * ```typescript
107
- * await ecod.media.delete("invoices/old-contract.pdf");
108
- * ```
109
- */
110
- async delete(key: string) {
111
- return this.deleteRequest("/api/saas/storage/files", { params: { key } });
112
- }
113
-
114
- /**
115
- * Request a temporary presigned download URL for a private file.
116
- *
117
- * @param key - The full storage key of the file.
118
- * @returns `{ url }` — a time-limited download URL.
119
- *
120
- * @example
121
- * ```typescript
122
- * const { data } = await ecod.media.getDownloadUrl("invoices/contract.pdf");
123
- * // → { url: "https://cdn.ecodrix.com/...?token=..." }
124
- * ```
125
- */
126
- async getDownloadUrl(key: string) {
127
- return this.post("/api/saas/storage/download-url", { key });
128
- }
129
-
130
- /**
131
- * **Elite Upload Helper** — uploads a file to Cloudflare R2 in a single call.
132
- *
133
- * This orchestrates 3 steps transparently:
134
- * 1. Fetch a presigned `PUT` URL from the ECODrIx backend.
135
- * 2. Upload the file _directly_ to R2 (no API proxy, maximum throughput).
136
- * 3. Confirm the upload with the backend so it is indexed and tracked.
137
- *
138
- * Works with Node.js `Buffer`, browser `File`/`Blob`, or any stream-like
139
- * object that Axios can PUT.
140
- *
141
- * @param file - The file data to upload.
142
- * @param options - Folder, filename, and content type.
143
- * @returns Confirmed file metadata including `key` and `url`.
144
- *
145
- * @example Node.js
146
- * ```typescript
147
- * import { readFileSync } from "fs";
148
- * const buf = readFileSync("./invoice.pdf");
149
- * const { data } = await ecod.media.upload(buf, {
150
- * folder: "invoices",
151
- * filename: "invoice-001.pdf",
152
- * contentType: "application/pdf",
153
- * });
154
- * ```
155
- *
156
- * @example Browser
157
- * ```typescript
158
- * const file = inputElement.files[0];
159
- * const { data } = await ecod.media.upload(file, {
160
- * folder: "avatars",
161
- * filename: file.name,
162
- * contentType: file.type,
163
- * });
164
- * ```
165
- */
166
- async upload(file: any, options: UploadOptions): Promise<any> {
167
- // Step 1: Get presigned URL
168
- const response = await this.post<any>("/api/saas/storage/upload-url", options);
169
- const { uploadUrl, key } = response.data;
170
-
171
- // Step 2: Upload directly to R2 (bypasses the API server for performance)
172
- await axios.put(uploadUrl, file, {
173
- headers: { "Content-Type": options.contentType },
174
- });
175
-
176
- const sizeBytes = file.size || file.byteLength || 0;
177
-
178
- // Step 3: Confirm with backend
179
- return this.post("/api/saas/storage/confirm-upload", { key, sizeBytes });
180
- }
181
- }
182
-
183
- /** @deprecated Use Media instead */
184
- export class MediaResource extends Media {}
@@ -1,163 +0,0 @@
1
- import { APIResource } from "../resource";
2
-
3
- /**
4
- * Parameters for scheduling a new Google Meet appointment.
5
- */
6
- export interface CreateMeetingParams {
7
- /** The CRM Lead ID this meeting belongs to. */
8
- leadId: string;
9
- /** Full name of the external participant. */
10
- participantName: string;
11
- /** Phone number of the participant in E.164 format. */
12
- participantPhone: string;
13
- /**
14
- * Meeting start time.
15
- * @example new Date("2026-04-10T10:00:00.000Z")
16
- */
17
- startTime: Date | string;
18
- /**
19
- * Meeting end time.
20
- * @example new Date("2026-04-10T10:30:00.000Z")
21
- */
22
- endTime: Date | string;
23
- /** Arbitrary metadata to attach to the meeting record. */
24
- metadata?: Record<string, any>;
25
- }
26
-
27
- /**
28
- * Parameters for updating an existing meeting.
29
- */
30
- export interface UpdateMeetingParams {
31
- /**
32
- * Update the meeting status.
33
- * @example "scheduled" | "completed" | "cancelled"
34
- */
35
- status?: string;
36
- /** Update the payment status for paid consultations. */
37
- paymentStatus?: string;
38
- /** New start time for rescheduling. */
39
- startTime?: Date | string;
40
- /** New end time for rescheduling. */
41
- endTime?: Date | string;
42
- /** Duration in minutes. */
43
- duration?: number;
44
- }
45
-
46
- /**
47
- * Google Meet appointment scheduling resource.
48
- *
49
- * Access via `ecod.meet`.
50
- *
51
- * @example
52
- * ```typescript
53
- * const { data } = await ecod.meet.create({
54
- * leadId: "64abc...",
55
- * participantName: "Alice",
56
- * participantPhone: "+919876543210",
57
- * startTime: "2026-04-10T10:00:00Z",
58
- * endTime: "2026-04-10T10:30:00Z",
59
- * });
60
- * console.log(data.meetLink); // → https://meet.google.com/abc-defg-hij
61
- * ```
62
- */
63
- export class Meetings extends APIResource {
64
- /**
65
- * Schedule a new Google Meet with a lead.
66
- *
67
- * The backend automatically creates a Google Calendar event and generates
68
- * a Meet link, then sends confirmation notifications via WhatsApp.
69
- *
70
- * @param data - Meeting details.
71
- * @returns The created Meeting document including `meetLink`.
72
- *
73
- * @example
74
- * ```typescript
75
- * const { data } = await ecod.meet.create({
76
- * leadId: "64abc...",
77
- * participantName: "Alice",
78
- * participantPhone: "+91...",
79
- * startTime: "2026-04-10T10:00:00Z",
80
- * endTime: "2026-04-10T10:30:00Z",
81
- * });
82
- * ```
83
- */
84
- async create(data: CreateMeetingParams): Promise<any> {
85
- return this.post("/api/saas/meet", data);
86
- }
87
-
88
- /**
89
- * List all meetings for the tenant, with optional filters.
90
- *
91
- * @param params - `leadId` to filter by lead; `status` to filter by state.
92
- * @returns Array of Meeting documents.
93
- *
94
- * @example
95
- * ```typescript
96
- * const { data } = await ecod.meet.list({ status: "scheduled" });
97
- * ```
98
- */
99
- async list(params?: { leadId?: string; status?: string }): Promise<any> {
100
- return this.get("/api/saas/meet", { params } as any);
101
- }
102
-
103
- /**
104
- * Retrieve the full details for a specific meeting.
105
- *
106
- * @param meetingId - The unique meeting ID.
107
- * @returns The Meeting document.
108
- *
109
- * @example
110
- * ```typescript
111
- * const { data } = await ecod.meet.retrieve("meeting_id");
112
- * ```
113
- */
114
- async retrieve(meetingId: string): Promise<any> {
115
- return this.get(`/api/saas/meet/${meetingId}`);
116
- }
117
-
118
- /**
119
- * Update or reschedule an existing meeting.
120
- *
121
- * Partial updates are supported — only supply the fields you wish to change.
122
- *
123
- * @param meetingId - The meeting to update.
124
- * @param data - Fields to update.
125
- * @returns The updated Meeting document.
126
- *
127
- * @example
128
- * ```typescript
129
- * // Reschedule
130
- * await ecod.meet.update("meeting_id", {
131
- * startTime: "2026-04-11T11:00:00Z",
132
- * endTime: "2026-04-11T11:30:00Z",
133
- * });
134
- * ```
135
- */
136
- async update<T = any>(meetingId: string, data: UpdateMeetingParams) {
137
- return this.patch<T>(`/api/saas/meet/${meetingId}`, data);
138
- }
139
-
140
- /**
141
- * Reschedule an existing meeting. Provides explicit method for time modifications.
142
- */
143
- async reschedule<T = any>(
144
- meetingId: string,
145
- params: { startTime: Date | string; endTime: Date | string; duration?: number },
146
- ) {
147
- return this.patch<T>(`/api/saas/meet/${meetingId}`, params);
148
- }
149
-
150
- /**
151
- * Cancel a meeting. This sets the meeting status to `"cancelled"`.
152
- *
153
- * @param meetingId - The meeting to cancel.
154
- *
155
- * @example
156
- * ```typescript
157
- * await ecod.meet.delete("meeting_id");
158
- * ```
159
- */
160
- async delete(meetingId: string): Promise<any> {
161
- return this.update(meetingId, { status: "cancelled" });
162
- }
163
- }