@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,197 +0,0 @@
1
- import { APIResource } from "../../resource";
2
- import type { ResourceManifest } from "../../types/metadata";
3
-
4
- export interface CreatePipelineParams {
5
- name: string;
6
- isDefault?: boolean;
7
- stages?: any[]; // Typically an array of stage objects
8
- }
9
-
10
- export interface PipelineStageParams {
11
- name: string;
12
- color?: string;
13
- probability?: number;
14
- }
15
-
16
- export class Pipelines extends APIResource {
17
- /**
18
- * List all CRM pipelines and their configured stages.
19
- *
20
- * @returns Array of pipeline objects with nested stages.
21
- * @example
22
- * ```typescript
23
- * const pipelines = await erixClient.crm.pipelines.list();
24
- * ```
25
- */
26
- async list<T = any>() {
27
- return this.get<T>("/api/crm/pipelines");
28
- }
29
-
30
- /**
31
- * Introspect a pipeline and provide a manifest of its stages.
32
- *
33
- * Returns metadata about stage colors, probabilities, and order.
34
- * Erix React uses this to build kanban boards and stage pickers.
35
- *
36
- * @param pipelineId - The unique ID of the pipeline.
37
- */
38
- async getStageManifest(pipelineId: string): Promise<ResourceManifest> {
39
- const pipeline: any = await this.retrieve(pipelineId);
40
- const stages = Array.isArray(pipeline.data?.stages) ? pipeline.data.stages : [];
41
-
42
- return {
43
- name: `Pipeline: ${pipeline.data?.name || pipelineId}`,
44
- fields: stages.map((s: any) => ({
45
- key: s._id,
46
- label: s.name,
47
- type: "string", // Labels are strings
48
- required: true,
49
- options: [{ label: s.name, value: s._id }],
50
- group: "Stages",
51
- uiHints: {
52
- color: s.color || "#cbd5e1",
53
- probability: s.probability,
54
- },
55
- })) as any,
56
- uiHints: {
57
- icon: "Columns",
58
- primaryColor: "#6366f1",
59
- },
60
- };
61
- }
62
-
63
- /**
64
- * Create a new CRM sales or support pipeline.
65
- *
66
- * @param payload - Pipeline details (name and array of stage names).
67
- * @returns The created pipeline record.
68
- * @example
69
- * ```typescript
70
- * await erixClient.crm.pipelines.create({
71
- * name: "Sales Pipeline",
72
- * stages: ["Lead", "Contacted", "Proposal", "Negotiation", "Closed"]
73
- * });
74
- * ```
75
- */
76
- async create<T = any>(payload: { name: string; stages: string[] }) {
77
- return this.post<T>("/api/crm/pipelines", payload);
78
- }
79
-
80
- /**
81
- * Retrieve a single pipeline configuration by ID.
82
- *
83
- * @param pipelineId - The unique ID of the pipeline.
84
- * @example
85
- * ```typescript
86
- * const pipeline = await erixClient.crm.pipelines.retrieve("pipe_123");
87
- * ```
88
- */
89
- async retrieve<T = any>(pipelineId: string) {
90
- return this.get<T>(`/api/crm/pipelines/${pipelineId}`);
91
- }
92
-
93
- /**
94
- * Update an existing pipeline.
95
- */
96
- async update<T = any>(pipelineId: string, payload: Partial<{ name: string; stages: string[] }>) {
97
- return this.patch<T>(`/api/crm/pipelines/${pipelineId}`, payload as any);
98
- }
99
-
100
- /**
101
- * Set pipeline as the tenant's default.
102
- */
103
- async setDefault<T = any>(pipelineId: string) {
104
- return this.patch<T>(`/api/crm/pipelines/${pipelineId}/default`, {});
105
- }
106
-
107
- /**
108
- * Duplicate a pipeline with a new name.
109
- */
110
- async duplicate<T = any>(pipelineId: string, newName: string) {
111
- return this.post<T>(`/api/crm/pipelines/${pipelineId}/duplicate`, {
112
- newName,
113
- });
114
- }
115
-
116
- /**
117
- * Archive a pipeline.
118
- */
119
- async archive<T = any>(pipelineId: string) {
120
- return this.patch<T>(`/api/crm/pipelines/${pipelineId}/archive`, {});
121
- }
122
-
123
- /**
124
- * Delete a pipeline permanently.
125
- */
126
- async delete(pipelineId: string) {
127
- return this.deleteRequest(`/api/crm/pipelines/${pipelineId}`);
128
- }
129
-
130
- /**
131
- * Retrieve a Kanban-style board representation of the pipeline with leads nested.
132
- *
133
- * @param pipelineId - The unique ID of the pipeline.
134
- * @example
135
- * ```typescript
136
- * const board = await erixClient.crm.pipelines.board("pipe_123");
137
- * ```
138
- */
139
- async board<T = any>(pipelineId: string) {
140
- return this.get<T>(`/api/crm/pipelines/${pipelineId}/board`);
141
- }
142
-
143
- /**
144
- * Retrieve a revenue forecast based on stage probabilities for a pipeline.
145
- */
146
- async forecast<T = any>(pipelineId: string) {
147
- return this.get<T>(`/api/crm/pipelines/${pipelineId}/forecast`);
148
- }
149
-
150
- // --- Stage Management ---
151
-
152
- /**
153
- * Add a new stage to the pipeline.
154
- *
155
- * @param pipelineId - The unique ID of the pipeline.
156
- * @param params - Stage details (name, color, probability).
157
- * @example
158
- * ```typescript
159
- * await erixClient.crm.pipelines.addStage("pipe_123", {
160
- * name: "Decision Maker Bought In",
161
- * color: "#FF5733",
162
- * probability: 80
163
- * });
164
- * ```
165
- */
166
- async addStage<T = any>(pipelineId: string, params: PipelineStageParams) {
167
- return this.post<T>(`/api/crm/pipelines/${pipelineId}/stages`, params);
168
- }
169
-
170
- /**
171
- * Change the order of stages inside the pipeline.
172
- */
173
- async reorderStages<T = any>(pipelineId: string, orderArray: string[]) {
174
- return this.patch<T>(`/api/crm/pipelines/${pipelineId}/stages/reorder`, {
175
- order: orderArray,
176
- });
177
- }
178
-
179
- /**
180
- * Update a specific stage.
181
- */
182
- async updateStage<T = any>(stageId: string, params: Partial<PipelineStageParams>) {
183
- return this.patch<T>(`/api/crm/stages/${stageId}`, params);
184
- }
185
-
186
- /**
187
- * Delete a stage permanently.
188
- *
189
- * @param stageId - The unique ID of the stage to delete.
190
- * @param moveLeadsToStageId - Optional fallback stageId to move active leads to before deletion.
191
- */
192
- async deleteStage(stageId: string, moveLeadsToStageId?: string) {
193
- return this.deleteRequest(`/api/crm/stages/${stageId}`, {
194
- data: moveLeadsToStageId ? { moveLeadsToStageId } : undefined,
195
- });
196
- }
197
- }
@@ -1,46 +0,0 @@
1
- import { APIResource } from "../../resource";
2
-
3
- export interface ScoringConfig {
4
- decayDays: number;
5
- thresholds: {
6
- hot: number;
7
- warm: number;
8
- };
9
- rules: any[]; // Specific rule shapes
10
- }
11
-
12
- export class Scoring extends APIResource {
13
- /**
14
- * Retrieve the tenant's global lead scoring configuration (rules, decay, thresholds).
15
- *
16
- * @returns The scoring configuration object.
17
- * @example
18
- * ```typescript
19
- * const config = await erixClient.crm.scoring.getConfig();
20
- * ```
21
- */
22
- async getConfig<T = any>() {
23
- return this.get<T>("/api/crm/scoring");
24
- }
25
-
26
- /**
27
- * Update scoring configuration.
28
- */
29
- async updateConfig<T = any>(payload: Partial<ScoringConfig>) {
30
- return this.patch<T>("/api/crm/scoring", payload as any);
31
- }
32
-
33
- /**
34
- * Force an immediate score recalculation for a specific lead.
35
- * Useful when profile data changes significantly.
36
- *
37
- * @param leadId - The unique ID of the lead.
38
- * @example
39
- * ```typescript
40
- * await erixClient.crm.scoring.recalculate("lead_123");
41
- * ```
42
- */
43
- async recalculate<T = any>(leadId: string) {
44
- return this.post<T>(`/api/crm/scoring/${leadId}/recalculate`, {});
45
- }
46
- }
@@ -1,51 +0,0 @@
1
- import { APIResource } from "../../resource";
2
-
3
- export class Sequences extends APIResource {
4
- /**
5
- * Manually enroll a lead into a specific automation drip sequence (Workflow).
6
- *
7
- * @param payload - Enrollment details (leadId, ruleId, and custom variables).
8
- * @example
9
- * ```typescript
10
- * await erixClient.crm.sequences.enroll({
11
- * leadId: "lead_123",
12
- * ruleId: "rule_456",
13
- * variables: { start_date: "2026-05-01" }
14
- * });
15
- * ```
16
- */
17
- async enroll<T = any>(payload: {
18
- leadId: string;
19
- ruleId: string;
20
- variables?: Record<string, any>;
21
- }) {
22
- return this.post<T>("/api/crm/sequences/enroll", payload);
23
- }
24
-
25
- /**
26
- * Unenroll a lead from a currently running automation sequence.
27
- *
28
- * @param enrollmentId - The unique ID of the sequence enrollment.
29
- * @example
30
- * ```typescript
31
- * await erixClient.crm.sequences.unenroll("enroll_123");
32
- * ```
33
- */
34
- async unenroll<T = any>(enrollmentId: string) {
35
- return this.deleteRequest(`/api/crm/sequences/unenroll/${enrollmentId}`);
36
- }
37
-
38
- /**
39
- * List all active and completed sequence enrollments for a specific lead.
40
- *
41
- * @param leadId - The unique ID of the lead.
42
- * @returns Array of enrollment records.
43
- * @example
44
- * ```typescript
45
- * const enrollments = await erixClient.crm.sequences.listForLead("lead_123");
46
- * ```
47
- */
48
- async listForLead<T = any>(leadId: string) {
49
- return this.get<T>(`/api/crm/sequences/lead/${leadId}`);
50
- }
51
- }
@@ -1,142 +0,0 @@
1
- import { APIResource } from "../resource";
2
-
3
- /**
4
- * Payload to send a high-throughput email campaign.
5
- */
6
- export interface SendCampaignPayload {
7
- /** Array of recipient email addresses. */
8
- recipients: string[];
9
- /** Subject line of the email. */
10
- subject: string;
11
- /** HTML body of the email. */
12
- html: string;
13
- }
14
-
15
- /**
16
- * Interface representing the result of a campaign dispatch.
17
- */
18
- export interface CampaignResult {
19
- success: boolean;
20
- message?: string;
21
- [key: string]: any;
22
- }
23
-
24
- export interface EmailTemplate {
25
- id: string;
26
- name: string;
27
- description?: string;
28
- subject: string;
29
- preheader?: string;
30
- htmlBody: string;
31
- textBody?: string;
32
- category: "marketing" | "transactional" | "sequence";
33
- status: "draft" | "published" | "archived";
34
- type: "standard" | "layout";
35
- layoutId?: string;
36
- thumbnail?: string;
37
- variableMapping?: any[];
38
- createdAt: string;
39
- updatedAt: string;
40
- }
41
-
42
- export interface CreateTemplateDTO {
43
- name: string;
44
- subject: string;
45
- htmlBody: string;
46
- description?: string;
47
- category?: "marketing" | "transactional" | "sequence";
48
- status?: "draft" | "published" | "archived";
49
- variableMapping?: any[];
50
- }
51
-
52
- export interface TemplatePreviewResponse {
53
- success: boolean;
54
- data: {
55
- subject: string;
56
- html: string;
57
- text?: string;
58
- };
59
- }
60
-
61
- /**
62
- * Outbound email marketing engine and template management.
63
- *
64
- * Access via `ecod.email`.
65
- */
66
- export class Email extends APIResource {
67
- /**
68
- * Send an HTML email campaign to a list of recipients.
69
- */
70
- async sendCampaign(payload: SendCampaignPayload): Promise<CampaignResult> {
71
- return this.post<CampaignResult>("/api/saas/emails/campaign", payload);
72
- }
73
-
74
- /**
75
- * Send a system test email to validate your current SMTP configuration.
76
- */
77
- async sendTest(to: string): Promise<CampaignResult> {
78
- return this.post<CampaignResult>("/api/saas/emails/test", { to });
79
- }
80
-
81
- // --- Template Management ---
82
-
83
- /**
84
- * List all email templates.
85
- */
86
- async listTemplates(query?: any): Promise<{ success: boolean; data: EmailTemplate[] }> {
87
- return this.get<{ success: boolean; data: EmailTemplate[] }>("/api/saas/mail/templates", {
88
- params: query,
89
- });
90
- }
91
-
92
- /**
93
- * Get a single email template by ID.
94
- */
95
- async getTemplate(id: string): Promise<{ success: boolean; data: EmailTemplate }> {
96
- return this.get<{ success: boolean; data: EmailTemplate }>(`/api/saas/mail/templates/${id}`);
97
- }
98
-
99
- /**
100
- * Create a new email template.
101
- */
102
- async createTemplate(
103
- data: CreateTemplateDTO,
104
- ): Promise<{ success: boolean; data: EmailTemplate }> {
105
- return this.post<{ success: boolean; data: EmailTemplate }>("/api/saas/mail/templates", data);
106
- }
107
-
108
- /**
109
- * Update an existing email template.
110
- */
111
- async updateTemplate(
112
- id: string,
113
- data: Partial<CreateTemplateDTO>,
114
- ): Promise<{ success: boolean; data: EmailTemplate }> {
115
- return this.put<{ success: boolean; data: EmailTemplate }>(
116
- `/api/saas/mail/templates/${id}`,
117
- data,
118
- );
119
- }
120
-
121
- /**
122
- * Delete an email template.
123
- */
124
- async deleteTemplate(id: string, force = false): Promise<{ success: boolean }> {
125
- return this.deleteRequest<{ success: boolean }>(`/api/saas/mail/templates/${id}`, {
126
- params: { force },
127
- });
128
- }
129
-
130
- /**
131
- * Preview a template with dynamic variable resolution.
132
- */
133
- async previewTemplate(
134
- id: string,
135
- params: { leadId?: string; variables?: Record<string, any> },
136
- ): Promise<TemplatePreviewResponse> {
137
- return this.post<TemplatePreviewResponse>(`/api/saas/mail/templates/${id}/preview`, params);
138
- }
139
- }
140
-
141
- /** @deprecated Use Email instead */
142
- export class EmailResource extends Email {}
@@ -1,189 +0,0 @@
1
- import type { AxiosInstance } from "axios";
2
- import { APIResource } from "../resource";
3
-
4
- /**
5
- * Event definition representing an entry point capable of triggering automations.
6
- */
7
- export interface EventDefinition {
8
- name: string;
9
- displayName: string;
10
- description?: string;
11
- pipelineId?: string;
12
- stageId?: string;
13
- defaultSource?: string;
14
- [key: string]: any;
15
- }
16
-
17
- /**
18
- * Payload to register/assign a new custom event definition.
19
- */
20
- export interface AssignEventPayload {
21
- /** The internal machine-readable name of the event (e.g. "webinar_joined") */
22
- name: string;
23
- /** Human-readable display name */
24
- displayName: string;
25
- /** Event description */
26
- description?: string;
27
- /** ID of the pipeline to associate with matching leads */
28
- pipelineId?: string;
29
- /** ID of the stage within the pipeline */
30
- stageId?: string;
31
- /** Default source tag for leads created via this event */
32
- defaultSource?: string;
33
- }
34
-
35
- /**
36
- * Payload to programmatically trigger an event/workflow.
37
- */
38
- export interface TriggerPayload {
39
- /** The name of the event to fire (e.g., "webinar_joined") */
40
- trigger: string;
41
- /** Phone number of the lead (E.164 format) */
42
- phone: string;
43
- /** Email of the lead */
44
- email?: string;
45
- /** Key-value pairs for string templates */
46
- variables?: Record<string, string>;
47
- /** Deep payload data mapping to the event */
48
- data?: any;
49
- /** URL to receive an acknowledgment callback when processing completes */
50
- callbackUrl?: string;
51
- /** Secret metadata passed back to the callback URL */
52
- callbackMetadata?: any;
53
- /** Auto-create lead if phone does not exist in CRM */
54
- createLeadIfMissing?: boolean;
55
- /** Pre-fill data if creating a new lead */
56
- leadData?: {
57
- firstName?: string;
58
- lastName?: string;
59
- source?: string;
60
- };
61
- /** Delay execution of matched workflows (in seconds) */
62
- delaySeconds?: number;
63
- /** Delay execution of matched workflows (in minutes) */
64
- delayMinutes?: number;
65
- /** Explicit ISO timestamp to trigger the workflow run */
66
- runAt?: string;
67
- /** Automatically generate a Google Meet appointment if matched actions require it */
68
- requiresMeet?: boolean;
69
- /** Configuration details for the generated Google Meet appointment */
70
- meetConfig?: {
71
- summary?: string;
72
- description?: string;
73
- startTime?: string;
74
- duration?: number;
75
- timezone?: string;
76
- attendees?: string[];
77
- };
78
- }
79
-
80
- /**
81
- * Response returned when triggering an event.
82
- */
83
- export interface TriggerResponse {
84
- success: boolean;
85
- data?: {
86
- eventLogId: string;
87
- trigger: string;
88
- leadId: string;
89
- rulesMatched: number;
90
- };
91
- message?: string;
92
- code?: string;
93
- }
94
-
95
- export class EventsResource extends APIResource {
96
- /**
97
- * List all available event definitions (both system and custom) that can trigger automations.
98
- *
99
- * @returns Array of event definitions.
100
- * @example
101
- * ```typescript
102
- * const events = await erixClient.events.list();
103
- * ```
104
- */
105
- async list(): Promise<{ success: boolean; data: EventDefinition[] }> {
106
- return this.get<{ success: boolean; data: EventDefinition[] }>("/api/saas/events");
107
- }
108
-
109
- /**
110
- * Register a new custom event entry point into the CRM automation engine.
111
- * Useful when introducing new granular triggers.
112
- */
113
- async assign(payload: AssignEventPayload): Promise<{ success: boolean; data: EventDefinition }> {
114
- return this.post<{ success: boolean; data: EventDefinition }>(
115
- "/api/saas/events/assign",
116
- payload,
117
- );
118
- }
119
-
120
- /**
121
- * Deactivate a custom event assignment by name.
122
- */
123
- async unassign(name: string): Promise<{ success: boolean; data: any }> {
124
- return this.post<{ success: boolean; data: any }>("/api/saas/events/unassign", { name });
125
- }
126
-
127
- /**
128
- * Deactivate multiple custom event assignments simultaneously.
129
- */
130
- async unassignBulk(names: string[]): Promise<{ success: boolean; message: string }> {
131
- return this.post<{ success: boolean; message: string }>("/api/saas/events/unassign/bulk", {
132
- names,
133
- });
134
- }
135
-
136
- /**
137
- * Programmatically trigger an automation workflow by firing a specific event.
138
- * This matches the event against active Automation Rules and executes linked actions.
139
- *
140
- * @param payload - The trigger details (event name, lead phone/email, variables).
141
- * @returns Trigger response with diagnostic info (eventLogId, matched rules).
142
- * @example
143
- * ```typescript
144
- * await erixClient.events.trigger({
145
- * trigger: "webinar_joined",
146
- * phone: "+919876543210",
147
- * variables: { webinar_name: "AI Masterclass" },
148
- * createLeadIfMissing: true
149
- * });
150
- * ```
151
- */
152
- async trigger(payload: TriggerPayload): Promise<TriggerResponse> {
153
- return this.post<TriggerResponse>("/api/saas/workflows/trigger", payload);
154
- }
155
-
156
- // --- CRM Custom Events ---
157
-
158
- /**
159
- * List all custom event definitions.
160
- */
161
- async listCustomEvents<T = any>() {
162
- return this.get<T>("/api/saas/crm/custom-events");
163
- }
164
-
165
- /**
166
- * Create or upsert a custom event definition.
167
- */
168
- async createCustomEvent<T = any>(payload: {
169
- name: string;
170
- displayName: string;
171
- description?: string;
172
- }) {
173
- return this.post<T>("/api/saas/crm/custom-events", payload);
174
- }
175
-
176
- /**
177
- * Delete a custom event definition.
178
- */
179
- async deleteCustomEvent<T = any>(id: string) {
180
- return this.deleteRequest<T>(`/api/saas/crm/custom-events/${id}`);
181
- }
182
-
183
- /**
184
- * Manually emit a custom event to trigger workflows based on its definition.
185
- */
186
- async emit<T = any>(payload: { eventName: string; leadId: string; data?: any }) {
187
- return this.post<T>("/api/saas/crm/events/emit", payload);
188
- }
189
- }
@@ -1,84 +0,0 @@
1
- import { APIResource } from "../resource";
2
-
3
- export interface SystemHealth {
4
- status: string;
5
- version: string;
6
- env: string;
7
- uptime: number;
8
- db: string;
9
- queueDepth: number;
10
- timestamp: string;
11
- }
12
-
13
- export interface ClientHealth {
14
- clientCode: string;
15
- services: {
16
- whatsapp: "connected" | "not_configured";
17
- email: "configured" | "not_configured";
18
- googleMeet: "configured" | "not_configured";
19
- };
20
- activeAutomations: number;
21
- queueDepth: number;
22
- timestamp: string;
23
- }
24
-
25
- export interface JobStatus {
26
- jobId: string;
27
- status: string;
28
- attempts: number;
29
- maxAttempts: number;
30
- lastError: any;
31
- runAt: string;
32
- completedAt: string | null;
33
- failedAt: string | null;
34
- createdAt: string;
35
- }
36
-
37
- /**
38
- * Platform and tenant-specific health diagnostics.
39
- *
40
- * Access via `ecod.health`.
41
- */
42
- export class Health extends APIResource {
43
- /**
44
- * Perform a global platform health check.
45
- * Verify that the core API, database, and background workers are operational.
46
- */
47
- async system(): Promise<SystemHealth> {
48
- const res = await this.get<{ success: boolean; data: SystemHealth }>("/api/saas/health");
49
- return res.data;
50
- }
51
-
52
- /**
53
- * Tenant-specific health check.
54
- *
55
- * Identifies correctly configured third-party integrations (WhatsApp, SMTP, Google Meet)
56
- * and reports active automation counts.
57
- */
58
- async clientHealth(): Promise<ClientHealth> {
59
- const res = await this.get<{ success: boolean; data: ClientHealth }>("/api/saas/health/client");
60
- return res.data;
61
- }
62
-
63
- /**
64
- * Alias for clientHealth to match diagnostic terminology.
65
- */
66
- async getDiagnosticReport(): Promise<ClientHealth> {
67
- return this.clientHealth();
68
- }
69
-
70
- /**
71
- * Lookup the execution status of a background job.
72
- *
73
- * Use this to poll for completion of long-running tasks like bulk exports
74
- * or campaign dispatches.
75
- *
76
- * @param jobId - The unique ID of the background job.
77
- */
78
- async jobStatus(jobId: string): Promise<JobStatus> {
79
- const res = await this.get<{ success: boolean; data: JobStatus }>(
80
- `/api/saas/jobs/status/${jobId}`,
81
- );
82
- return res.data;
83
- }
84
- }