@opens/gateways 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,47 +1,386 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
 
3
+ /** Shared company data fields returned by the Customer Service API. */
4
+ interface CompanyData {
5
+ id: string;
6
+ name: string;
7
+ hostname: string;
8
+ crm_code: string;
9
+ token: string;
10
+ status: string;
11
+ timezone: string;
12
+ utc: string;
13
+ check_bad_password: boolean;
14
+ limit_bad_password: number;
15
+ watching: boolean;
16
+ trial: boolean;
17
+ support_widget_id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ }
21
+ /** Response returned by the Customer Service API when fetching a company. */
3
22
  interface CompanyResponse {
4
- company: {
5
- id: string;
23
+ company: CompanyData;
24
+ }
25
+
26
+ /** A work group entity nested within {@link WorkGroupListResponse} and {@link WorkGroupResponse}. */
27
+ interface WorkGroup {
28
+ id: string;
29
+ name: string;
30
+ description: string | null;
31
+ type: 'default' | 'user';
32
+ company_id: string;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }
36
+ /** Response returned by the Customer Service API when fetching the work groups list. */
37
+ interface WorkGroupListResponse extends CompanyData {
38
+ workgroups: WorkGroup[];
39
+ }
40
+ /** A user membership entity nested within {@link WorkGroupResponse}. */
41
+ interface WorkGroupMember {
42
+ id: string;
43
+ username: string;
44
+ email: string;
45
+ profile: 'p_admin' | 'p_manager' | 'p_corporative' | 'p_agent';
46
+ status: 'new' | 'activated' | 'disabled';
47
+ avatar: string | null;
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ }
51
+ /** Response returned by the Customer Service API when fetching a single work group. */
52
+ interface WorkGroupResponse {
53
+ id: string;
54
+ name: string;
55
+ description: string | null;
56
+ type: 'default' | 'user';
57
+ company_id: string;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ workgroups_users: WorkGroupMember[];
61
+ }
62
+ /** Response returned by the Customer Service API when fetching members of a work group. */
63
+ type WorkGroupMembersResponse = WorkGroupMember[];
64
+
65
+ /**
66
+ * Gateway for interacting with the Customer Service API.
67
+ */
68
+ declare class CustomerServiceGateway {
69
+ private readonly httpClient;
70
+ private readonly baseUrl;
71
+ constructor(httpClient: AxiosInstance, baseUrl: string);
72
+ /**
73
+ * Retrieves a company by its unique identifier.
74
+ * @param companyId - The unique identifier of the company.
75
+ * @returns The company data wrapped in a {@link CompanyResponse}.
76
+ */
77
+ getCompanyById(companyId: string): Promise<CompanyResponse>;
78
+ /**
79
+ * Retrieves all work groups for a company.
80
+ * @param companyId - The unique identifier of the company.
81
+ * @returns The work groups for the given company.
82
+ */
83
+ getWorkGroups(companyId: string): Promise<WorkGroupListResponse>;
84
+ /**
85
+ * Retrieves a work group by its unique identifier.
86
+ * @param workGroupId - The unique identifier of the work group.
87
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
88
+ * @returns The work group data wrapped in a {@link WorkGroupResponse}.
89
+ */
90
+ getWorkGroupById(workGroupId: string, companyId?: string): Promise<WorkGroupResponse>;
91
+ /**
92
+ * Retrieves the members of a work group by its identifier.
93
+ * @param groupId - The unique identifier of the work group.
94
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
95
+ * @param profile - Filter members by profile (optional).
96
+ * @returns The members of the work group.
97
+ */
98
+ getWorkGroupMembers(groupId: string, companyId?: string, profile?: string[]): Promise<WorkGroupMembersResponse>;
99
+ }
100
+
101
+ /** A provider entity returned by the Chat Config API. */
102
+ interface Provider {
103
+ id: string;
104
+ name: string;
105
+ configurationsSchema: Record<string, unknown> | null;
106
+ defaultSession: number;
107
+ type: string;
108
+ createdAt: string;
109
+ updatedAt: string;
110
+ }
111
+ /** Response returned by the Chat Config API when listing providers. */
112
+ type ProviderListResponse = Provider[];
113
+
114
+ /** A provider entity nested within a configuration response. */
115
+ interface ConfigProvider {
116
+ id: string;
117
+ name: string;
118
+ type: string;
119
+ defaultSession: number;
120
+ configurationsSchema: Record<string, unknown> | null;
121
+ createdAt: string;
122
+ updatedAt: string;
123
+ }
124
+ /** A configuration entity returned by the Chat Config API. */
125
+ interface Config {
126
+ id: string;
127
+ isAssistanceEnabled: boolean;
128
+ rewind: number | null;
129
+ companyId: string;
130
+ active: boolean;
131
+ configurations: Record<string, unknown>;
132
+ priority: number | null;
133
+ inbound: boolean;
134
+ outbound: boolean;
135
+ deletedAt: string | null;
136
+ providers: ConfigProvider;
137
+ }
138
+ /** Response returned by the Chat Config API when listing configurations by provider. */
139
+ interface ConfigListByProviderResponse {
140
+ configurations: Config[];
141
+ }
142
+ /** Query parameters for filtering configurations by provider. */
143
+ interface GetConfigsByProviderParams {
144
+ isAssistanceEnabled?: boolean;
145
+ rewind?: number;
146
+ active?: boolean;
147
+ priority?: number;
148
+ inbound?: boolean;
149
+ outbound?: boolean;
150
+ providerType?: string;
151
+ providerName?: string;
152
+ }
153
+
154
+ /**
155
+ * Gateway for interacting with the Chat Config API.
156
+ */
157
+ declare class ChatConfigGateway {
158
+ private readonly httpClient;
159
+ private readonly baseUrl;
160
+ constructor(httpClient: AxiosInstance, baseUrl: string);
161
+ /**
162
+ * Retrieves all available providers.
163
+ * @returns The list of providers.
164
+ */
165
+ getProviders(): Promise<ProviderListResponse>;
166
+ /**
167
+ * Retrieves configurations filtered by provider.
168
+ * @param providerId - The unique identifier of the provider.
169
+ * @param params - Optional query parameters for filtering configurations.
170
+ * @returns The configurations for the given provider.
171
+ */
172
+ getConfigsByProvider(providerId: string, params?: GetConfigsByProviderParams): Promise<ConfigListByProviderResponse>;
173
+ }
174
+
175
+ /** Campaign status literals. */
176
+ type CampaignStatus = 'ongoing' | 'finished' | 'paused' | 'scheduled';
177
+ /** Campaign provider literals. */
178
+ type CampaignProvider = 'whatsapp';
179
+ /** WhatsApp template component structure. */
180
+ interface WhatsAppTemplateComponent {
181
+ type: string;
182
+ parameters: {
183
+ type: string;
184
+ text?: string;
185
+ }[];
186
+ }
187
+ /** WhatsApp payload used when dispatching campaign messages. */
188
+ interface WhatsAppPayload {
189
+ template: {
6
190
  name: string;
7
- hostname: string;
8
- crm_code: string;
9
- token: string;
191
+ components: WhatsAppTemplateComponent[];
192
+ language: string;
10
193
  status: string;
11
- timezone: string;
12
- utc: string;
13
- check_bad_password: boolean;
14
- limit_bad_password: number;
15
- watching: boolean;
16
- trial: boolean;
17
- support_widget_id: string;
18
- createdAt: string;
19
- updatedAt: string;
194
+ category: string;
195
+ id: string;
20
196
  };
197
+ templateOptions: {
198
+ buttonsVariablesValues?: (string | null)[] | null;
199
+ bodyVariablesValues?: string[];
200
+ headerVariablesValues?: string[];
201
+ headerFileInfos?: {
202
+ filename: string;
203
+ fileUrl: string;
204
+ parsedFilename: string;
205
+ };
206
+ };
207
+ }
208
+ /** Contact filter applied when adding contacts to a campaign. */
209
+ interface CampaignContactFilter {
210
+ excludeDeclinedMarketing?: boolean;
211
+ }
212
+ /** Schedule configuration for a campaign. */
213
+ interface CampaignSchedule {
214
+ startAt?: string;
215
+ repeat?: {
216
+ delay?: number;
217
+ count?: number;
218
+ until?: string;
219
+ };
220
+ }
221
+ /** Campaign entity returned by the Campaigns API. */
222
+ interface Campaign {
223
+ id: string;
224
+ sid: number;
225
+ companyId: string;
226
+ createdBy: string;
227
+ assignedTo: string;
228
+ name?: string;
229
+ provider: CampaignProvider;
230
+ providerId: number;
231
+ providerConfigId: string;
232
+ associatedRuleId?: string;
233
+ payload: WhatsAppPayload;
234
+ conversionRuleIds: string[];
235
+ status: CampaignStatus;
236
+ expiresAt?: string;
237
+ createdAt: string;
238
+ updatedAt: string;
239
+ failedCampaignAttempts: number;
240
+ queuedCampaignAttempts: number;
241
+ deliveredCampaignAttempts: number;
242
+ convertedCampaignAttempts: number;
243
+ categoryId?: number;
244
+ contactFilter?: CampaignContactFilter;
245
+ schedule?: CampaignSchedule;
246
+ }
247
+ /** Paginated response returned by the Campaigns API for list endpoints. */
248
+ interface CampaignPaginatedResponse {
249
+ total: number;
250
+ limit: number;
251
+ skip: number;
252
+ data: Campaign[];
253
+ }
254
+ /** Request payload for creating a campaign. */
255
+ interface CreateCampaignRequest {
256
+ name: string;
257
+ payload: WhatsAppPayload;
258
+ provider: CampaignProvider;
259
+ companyId: string;
260
+ createdBy: string;
261
+ providerId: number;
262
+ providerConfigId: string;
263
+ schedule: CampaignSchedule;
264
+ associatedRuleId?: string;
265
+ assignedTo?: string;
266
+ expiresAt?: string;
267
+ }
268
+ /** Request payload for updating a campaign. */
269
+ interface PatchCampaignRequest {
270
+ name?: string;
271
+ expiresAt?: string;
272
+ status?: CampaignStatus;
273
+ categoryId?: number;
274
+ contactFilter?: CampaignContactFilter;
275
+ }
276
+ /** Query parameters for listing campaigns. */
277
+ interface CampaignQueryParams {
278
+ companyId?: string;
279
+ status?: CampaignStatus;
280
+ createdBy?: string;
281
+ assignedTo?: string;
282
+ name?: string;
283
+ limit?: number;
284
+ skip?: number;
21
285
  }
22
286
 
23
- declare class CustomerServiceGateway {
287
+ /**
288
+ * Gateway for interacting with the Campaigns API.
289
+ */
290
+ declare class CampaignsGateway {
24
291
  private readonly httpClient;
25
292
  private readonly baseUrl;
26
293
  constructor(httpClient: AxiosInstance, baseUrl: string);
27
- getCompanyById(companyId: string): Promise<CompanyResponse>;
294
+ /**
295
+ * Retrieves a paginated list of campaigns.
296
+ * @param query - Optional query parameters for filtering and pagination.
297
+ * @returns The paginated campaigns response.
298
+ */
299
+ find(query?: CampaignQueryParams): Promise<CampaignPaginatedResponse>;
300
+ /**
301
+ * Retrieves a campaign by its unique identifier.
302
+ * @param id - The unique identifier of the campaign.
303
+ * @returns The campaign data.
304
+ */
305
+ get(id: string): Promise<Campaign>;
306
+ /**
307
+ * Creates a new campaign.
308
+ * @param payload - The campaign data to create.
309
+ * @returns The created campaign.
310
+ */
311
+ create(payload: CreateCampaignRequest): Promise<Campaign>;
312
+ /**
313
+ * Partially updates an existing campaign.
314
+ * @param id - The unique identifier of the campaign.
315
+ * @param payload - The fields to update.
316
+ * @returns The updated campaign.
317
+ */
318
+ patch(id: string, payload: PatchCampaignRequest): Promise<Campaign>;
319
+ /**
320
+ * Removes a campaign by its unique identifier.
321
+ * @param id - The unique identifier of the campaign.
322
+ * @returns The removed campaign.
323
+ */
324
+ remove(id: string): Promise<Campaign>;
28
325
  }
29
326
 
327
+ /**
328
+ * Maps service identifiers to their corresponding gateway types.
329
+ * Used by the `gateway()` function to infer the correct return type
330
+ * based on the service name passed as argument.
331
+ *
332
+ * When adding a new service, add an entry here with the service
333
+ * identifier as the key and the gateway class as the value.
334
+ */
335
+ type GatewayMap = {
336
+ 'customer-service': CustomerServiceGateway;
337
+ 'chat-config': ChatConfigGateway;
338
+ 'campaigns': CampaignsGateway;
339
+ };
340
+ /**
341
+ * Parameters required to configure the SDK client.
342
+ * Each service configuration is optional, only provide the services you need.
343
+ */
30
344
  interface GatewayClientParams {
345
+ /** An Axios instance used as the HTTP client for all gateway requests. */
31
346
  axiosClient: AxiosInstance;
347
+ /** API token used for authentication across all services. */
32
348
  apiToken: string;
349
+ /** Configuration for each service gateway. Only the services you configure will be available. */
33
350
  services: {
34
- customerService: {
351
+ customerService?: {
352
+ baseUrl: string;
353
+ };
354
+ chatConfig?: {
355
+ baseUrl: string;
356
+ };
357
+ campaigns?: {
35
358
  baseUrl: string;
36
359
  };
37
360
  };
38
361
  }
39
362
 
40
- declare enum SERVICE_GATEWAYS {
41
- CUSTOMER_SERVICE = "customer-service"
42
- }
43
-
363
+ /**
364
+ * Initializes the SDK with the required configuration parameters.
365
+ * Must be called before using {@link gateway}.
366
+ */
44
367
  declare const configure: (params: GatewayClientParams) => void;
45
- declare const gateway: (service: SERVICE_GATEWAYS) => CustomerServiceGateway;
368
+ /**
369
+ * Returns the gateway instance for the specified service.
370
+ *
371
+ * @typeParam T - A service identifier key from {@link GatewayMap}.
372
+ * @param service - The service identifier (e.g. `SERVICE_GATEWAYS.CUSTOMER_SERVICE`).
373
+ * @returns The corresponding gateway instance with all its methods.
374
+ * @throws {Error} If the SDK has not been configured via {@link configure}.
375
+ * @throws {Error} If an unknown service identifier is provided.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * configure({ axiosClient, apiToken: '...', services: { customerService: { baseUrl: '...' } } });
380
+ * const customer = gateway('customer-service');
381
+ * const company = await customer.getCompanyById('123');
382
+ * ```
383
+ */
384
+ declare function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];
46
385
 
47
386
  export { configure, gateway };
package/dist/index.d.ts CHANGED
@@ -1,47 +1,386 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
 
3
+ /** Shared company data fields returned by the Customer Service API. */
4
+ interface CompanyData {
5
+ id: string;
6
+ name: string;
7
+ hostname: string;
8
+ crm_code: string;
9
+ token: string;
10
+ status: string;
11
+ timezone: string;
12
+ utc: string;
13
+ check_bad_password: boolean;
14
+ limit_bad_password: number;
15
+ watching: boolean;
16
+ trial: boolean;
17
+ support_widget_id: string;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ }
21
+ /** Response returned by the Customer Service API when fetching a company. */
3
22
  interface CompanyResponse {
4
- company: {
5
- id: string;
23
+ company: CompanyData;
24
+ }
25
+
26
+ /** A work group entity nested within {@link WorkGroupListResponse} and {@link WorkGroupResponse}. */
27
+ interface WorkGroup {
28
+ id: string;
29
+ name: string;
30
+ description: string | null;
31
+ type: 'default' | 'user';
32
+ company_id: string;
33
+ createdAt: string;
34
+ updatedAt: string;
35
+ }
36
+ /** Response returned by the Customer Service API when fetching the work groups list. */
37
+ interface WorkGroupListResponse extends CompanyData {
38
+ workgroups: WorkGroup[];
39
+ }
40
+ /** A user membership entity nested within {@link WorkGroupResponse}. */
41
+ interface WorkGroupMember {
42
+ id: string;
43
+ username: string;
44
+ email: string;
45
+ profile: 'p_admin' | 'p_manager' | 'p_corporative' | 'p_agent';
46
+ status: 'new' | 'activated' | 'disabled';
47
+ avatar: string | null;
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ }
51
+ /** Response returned by the Customer Service API when fetching a single work group. */
52
+ interface WorkGroupResponse {
53
+ id: string;
54
+ name: string;
55
+ description: string | null;
56
+ type: 'default' | 'user';
57
+ company_id: string;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ workgroups_users: WorkGroupMember[];
61
+ }
62
+ /** Response returned by the Customer Service API when fetching members of a work group. */
63
+ type WorkGroupMembersResponse = WorkGroupMember[];
64
+
65
+ /**
66
+ * Gateway for interacting with the Customer Service API.
67
+ */
68
+ declare class CustomerServiceGateway {
69
+ private readonly httpClient;
70
+ private readonly baseUrl;
71
+ constructor(httpClient: AxiosInstance, baseUrl: string);
72
+ /**
73
+ * Retrieves a company by its unique identifier.
74
+ * @param companyId - The unique identifier of the company.
75
+ * @returns The company data wrapped in a {@link CompanyResponse}.
76
+ */
77
+ getCompanyById(companyId: string): Promise<CompanyResponse>;
78
+ /**
79
+ * Retrieves all work groups for a company.
80
+ * @param companyId - The unique identifier of the company.
81
+ * @returns The work groups for the given company.
82
+ */
83
+ getWorkGroups(companyId: string): Promise<WorkGroupListResponse>;
84
+ /**
85
+ * Retrieves a work group by its unique identifier.
86
+ * @param workGroupId - The unique identifier of the work group.
87
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
88
+ * @returns The work group data wrapped in a {@link WorkGroupResponse}.
89
+ */
90
+ getWorkGroupById(workGroupId: string, companyId?: string): Promise<WorkGroupResponse>;
91
+ /**
92
+ * Retrieves the members of a work group by its identifier.
93
+ * @param groupId - The unique identifier of the work group.
94
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
95
+ * @param profile - Filter members by profile (optional).
96
+ * @returns The members of the work group.
97
+ */
98
+ getWorkGroupMembers(groupId: string, companyId?: string, profile?: string[]): Promise<WorkGroupMembersResponse>;
99
+ }
100
+
101
+ /** A provider entity returned by the Chat Config API. */
102
+ interface Provider {
103
+ id: string;
104
+ name: string;
105
+ configurationsSchema: Record<string, unknown> | null;
106
+ defaultSession: number;
107
+ type: string;
108
+ createdAt: string;
109
+ updatedAt: string;
110
+ }
111
+ /** Response returned by the Chat Config API when listing providers. */
112
+ type ProviderListResponse = Provider[];
113
+
114
+ /** A provider entity nested within a configuration response. */
115
+ interface ConfigProvider {
116
+ id: string;
117
+ name: string;
118
+ type: string;
119
+ defaultSession: number;
120
+ configurationsSchema: Record<string, unknown> | null;
121
+ createdAt: string;
122
+ updatedAt: string;
123
+ }
124
+ /** A configuration entity returned by the Chat Config API. */
125
+ interface Config {
126
+ id: string;
127
+ isAssistanceEnabled: boolean;
128
+ rewind: number | null;
129
+ companyId: string;
130
+ active: boolean;
131
+ configurations: Record<string, unknown>;
132
+ priority: number | null;
133
+ inbound: boolean;
134
+ outbound: boolean;
135
+ deletedAt: string | null;
136
+ providers: ConfigProvider;
137
+ }
138
+ /** Response returned by the Chat Config API when listing configurations by provider. */
139
+ interface ConfigListByProviderResponse {
140
+ configurations: Config[];
141
+ }
142
+ /** Query parameters for filtering configurations by provider. */
143
+ interface GetConfigsByProviderParams {
144
+ isAssistanceEnabled?: boolean;
145
+ rewind?: number;
146
+ active?: boolean;
147
+ priority?: number;
148
+ inbound?: boolean;
149
+ outbound?: boolean;
150
+ providerType?: string;
151
+ providerName?: string;
152
+ }
153
+
154
+ /**
155
+ * Gateway for interacting with the Chat Config API.
156
+ */
157
+ declare class ChatConfigGateway {
158
+ private readonly httpClient;
159
+ private readonly baseUrl;
160
+ constructor(httpClient: AxiosInstance, baseUrl: string);
161
+ /**
162
+ * Retrieves all available providers.
163
+ * @returns The list of providers.
164
+ */
165
+ getProviders(): Promise<ProviderListResponse>;
166
+ /**
167
+ * Retrieves configurations filtered by provider.
168
+ * @param providerId - The unique identifier of the provider.
169
+ * @param params - Optional query parameters for filtering configurations.
170
+ * @returns The configurations for the given provider.
171
+ */
172
+ getConfigsByProvider(providerId: string, params?: GetConfigsByProviderParams): Promise<ConfigListByProviderResponse>;
173
+ }
174
+
175
+ /** Campaign status literals. */
176
+ type CampaignStatus = 'ongoing' | 'finished' | 'paused' | 'scheduled';
177
+ /** Campaign provider literals. */
178
+ type CampaignProvider = 'whatsapp';
179
+ /** WhatsApp template component structure. */
180
+ interface WhatsAppTemplateComponent {
181
+ type: string;
182
+ parameters: {
183
+ type: string;
184
+ text?: string;
185
+ }[];
186
+ }
187
+ /** WhatsApp payload used when dispatching campaign messages. */
188
+ interface WhatsAppPayload {
189
+ template: {
6
190
  name: string;
7
- hostname: string;
8
- crm_code: string;
9
- token: string;
191
+ components: WhatsAppTemplateComponent[];
192
+ language: string;
10
193
  status: string;
11
- timezone: string;
12
- utc: string;
13
- check_bad_password: boolean;
14
- limit_bad_password: number;
15
- watching: boolean;
16
- trial: boolean;
17
- support_widget_id: string;
18
- createdAt: string;
19
- updatedAt: string;
194
+ category: string;
195
+ id: string;
20
196
  };
197
+ templateOptions: {
198
+ buttonsVariablesValues?: (string | null)[] | null;
199
+ bodyVariablesValues?: string[];
200
+ headerVariablesValues?: string[];
201
+ headerFileInfos?: {
202
+ filename: string;
203
+ fileUrl: string;
204
+ parsedFilename: string;
205
+ };
206
+ };
207
+ }
208
+ /** Contact filter applied when adding contacts to a campaign. */
209
+ interface CampaignContactFilter {
210
+ excludeDeclinedMarketing?: boolean;
211
+ }
212
+ /** Schedule configuration for a campaign. */
213
+ interface CampaignSchedule {
214
+ startAt?: string;
215
+ repeat?: {
216
+ delay?: number;
217
+ count?: number;
218
+ until?: string;
219
+ };
220
+ }
221
+ /** Campaign entity returned by the Campaigns API. */
222
+ interface Campaign {
223
+ id: string;
224
+ sid: number;
225
+ companyId: string;
226
+ createdBy: string;
227
+ assignedTo: string;
228
+ name?: string;
229
+ provider: CampaignProvider;
230
+ providerId: number;
231
+ providerConfigId: string;
232
+ associatedRuleId?: string;
233
+ payload: WhatsAppPayload;
234
+ conversionRuleIds: string[];
235
+ status: CampaignStatus;
236
+ expiresAt?: string;
237
+ createdAt: string;
238
+ updatedAt: string;
239
+ failedCampaignAttempts: number;
240
+ queuedCampaignAttempts: number;
241
+ deliveredCampaignAttempts: number;
242
+ convertedCampaignAttempts: number;
243
+ categoryId?: number;
244
+ contactFilter?: CampaignContactFilter;
245
+ schedule?: CampaignSchedule;
246
+ }
247
+ /** Paginated response returned by the Campaigns API for list endpoints. */
248
+ interface CampaignPaginatedResponse {
249
+ total: number;
250
+ limit: number;
251
+ skip: number;
252
+ data: Campaign[];
253
+ }
254
+ /** Request payload for creating a campaign. */
255
+ interface CreateCampaignRequest {
256
+ name: string;
257
+ payload: WhatsAppPayload;
258
+ provider: CampaignProvider;
259
+ companyId: string;
260
+ createdBy: string;
261
+ providerId: number;
262
+ providerConfigId: string;
263
+ schedule: CampaignSchedule;
264
+ associatedRuleId?: string;
265
+ assignedTo?: string;
266
+ expiresAt?: string;
267
+ }
268
+ /** Request payload for updating a campaign. */
269
+ interface PatchCampaignRequest {
270
+ name?: string;
271
+ expiresAt?: string;
272
+ status?: CampaignStatus;
273
+ categoryId?: number;
274
+ contactFilter?: CampaignContactFilter;
275
+ }
276
+ /** Query parameters for listing campaigns. */
277
+ interface CampaignQueryParams {
278
+ companyId?: string;
279
+ status?: CampaignStatus;
280
+ createdBy?: string;
281
+ assignedTo?: string;
282
+ name?: string;
283
+ limit?: number;
284
+ skip?: number;
21
285
  }
22
286
 
23
- declare class CustomerServiceGateway {
287
+ /**
288
+ * Gateway for interacting with the Campaigns API.
289
+ */
290
+ declare class CampaignsGateway {
24
291
  private readonly httpClient;
25
292
  private readonly baseUrl;
26
293
  constructor(httpClient: AxiosInstance, baseUrl: string);
27
- getCompanyById(companyId: string): Promise<CompanyResponse>;
294
+ /**
295
+ * Retrieves a paginated list of campaigns.
296
+ * @param query - Optional query parameters for filtering and pagination.
297
+ * @returns The paginated campaigns response.
298
+ */
299
+ find(query?: CampaignQueryParams): Promise<CampaignPaginatedResponse>;
300
+ /**
301
+ * Retrieves a campaign by its unique identifier.
302
+ * @param id - The unique identifier of the campaign.
303
+ * @returns The campaign data.
304
+ */
305
+ get(id: string): Promise<Campaign>;
306
+ /**
307
+ * Creates a new campaign.
308
+ * @param payload - The campaign data to create.
309
+ * @returns The created campaign.
310
+ */
311
+ create(payload: CreateCampaignRequest): Promise<Campaign>;
312
+ /**
313
+ * Partially updates an existing campaign.
314
+ * @param id - The unique identifier of the campaign.
315
+ * @param payload - The fields to update.
316
+ * @returns The updated campaign.
317
+ */
318
+ patch(id: string, payload: PatchCampaignRequest): Promise<Campaign>;
319
+ /**
320
+ * Removes a campaign by its unique identifier.
321
+ * @param id - The unique identifier of the campaign.
322
+ * @returns The removed campaign.
323
+ */
324
+ remove(id: string): Promise<Campaign>;
28
325
  }
29
326
 
327
+ /**
328
+ * Maps service identifiers to their corresponding gateway types.
329
+ * Used by the `gateway()` function to infer the correct return type
330
+ * based on the service name passed as argument.
331
+ *
332
+ * When adding a new service, add an entry here with the service
333
+ * identifier as the key and the gateway class as the value.
334
+ */
335
+ type GatewayMap = {
336
+ 'customer-service': CustomerServiceGateway;
337
+ 'chat-config': ChatConfigGateway;
338
+ 'campaigns': CampaignsGateway;
339
+ };
340
+ /**
341
+ * Parameters required to configure the SDK client.
342
+ * Each service configuration is optional, only provide the services you need.
343
+ */
30
344
  interface GatewayClientParams {
345
+ /** An Axios instance used as the HTTP client for all gateway requests. */
31
346
  axiosClient: AxiosInstance;
347
+ /** API token used for authentication across all services. */
32
348
  apiToken: string;
349
+ /** Configuration for each service gateway. Only the services you configure will be available. */
33
350
  services: {
34
- customerService: {
351
+ customerService?: {
352
+ baseUrl: string;
353
+ };
354
+ chatConfig?: {
355
+ baseUrl: string;
356
+ };
357
+ campaigns?: {
35
358
  baseUrl: string;
36
359
  };
37
360
  };
38
361
  }
39
362
 
40
- declare enum SERVICE_GATEWAYS {
41
- CUSTOMER_SERVICE = "customer-service"
42
- }
43
-
363
+ /**
364
+ * Initializes the SDK with the required configuration parameters.
365
+ * Must be called before using {@link gateway}.
366
+ */
44
367
  declare const configure: (params: GatewayClientParams) => void;
45
- declare const gateway: (service: SERVICE_GATEWAYS) => CustomerServiceGateway;
368
+ /**
369
+ * Returns the gateway instance for the specified service.
370
+ *
371
+ * @typeParam T - A service identifier key from {@link GatewayMap}.
372
+ * @param service - The service identifier (e.g. `SERVICE_GATEWAYS.CUSTOMER_SERVICE`).
373
+ * @returns The corresponding gateway instance with all its methods.
374
+ * @throws {Error} If the SDK has not been configured via {@link configure}.
375
+ * @throws {Error} If an unknown service identifier is provided.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * configure({ axiosClient, apiToken: '...', services: { customerService: { baseUrl: '...' } } });
380
+ * const customer = gateway('customer-service');
381
+ * const company = await customer.getCompanyById('123');
382
+ * ```
383
+ */
384
+ declare function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];
46
385
 
47
386
  export { configure, gateway };
package/dist/index.js CHANGED
@@ -33,25 +33,175 @@ var CustomerServiceGateway = class {
33
33
  }
34
34
  httpClient;
35
35
  baseUrl;
36
+ /**
37
+ * Retrieves a company by its unique identifier.
38
+ * @param companyId - The unique identifier of the company.
39
+ * @returns The company data wrapped in a {@link CompanyResponse}.
40
+ */
36
41
  async getCompanyById(companyId) {
37
42
  const { data } = await this.httpClient.get(`${this.baseUrl}/companies/search/${companyId}`);
38
43
  return data;
39
44
  }
45
+ /**
46
+ * Retrieves all work groups for a company.
47
+ * @param companyId - The unique identifier of the company.
48
+ * @returns The work groups for the given company.
49
+ */
50
+ async getWorkGroups(companyId) {
51
+ const { data } = await this.httpClient.get(
52
+ `${this.baseUrl}/companies/work-groups`,
53
+ { params: { company_id: companyId } }
54
+ );
55
+ return data;
56
+ }
57
+ /**
58
+ * Retrieves a work group by its unique identifier.
59
+ * @param workGroupId - The unique identifier of the work group.
60
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
61
+ * @returns The work group data wrapped in a {@link WorkGroupResponse}.
62
+ */
63
+ async getWorkGroupById(workGroupId, companyId) {
64
+ const params = companyId ? { company_id: companyId } : void 0;
65
+ const { data } = await this.httpClient.get(
66
+ `${this.baseUrl}/companies/work-groups/${workGroupId}`,
67
+ { params }
68
+ );
69
+ return data;
70
+ }
71
+ /**
72
+ * Retrieves the members of a work group by its identifier.
73
+ * @param groupId - The unique identifier of the work group.
74
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
75
+ * @param profile - Filter members by profile (optional).
76
+ * @returns The members of the work group.
77
+ */
78
+ async getWorkGroupMembers(groupId, companyId, profile) {
79
+ const params = {};
80
+ if (companyId) params.company_id = companyId;
81
+ if (profile) params.profile = profile;
82
+ const { data } = await this.httpClient.get(
83
+ `${this.baseUrl}/bonds/work-groups/${groupId}`,
84
+ { params }
85
+ );
86
+ return data;
87
+ }
88
+ };
89
+
90
+ // src/chat-config/index.ts
91
+ var ChatConfigGateway = class {
92
+ constructor(httpClient, baseUrl) {
93
+ this.httpClient = httpClient;
94
+ this.baseUrl = baseUrl;
95
+ }
96
+ httpClient;
97
+ baseUrl;
98
+ /**
99
+ * Retrieves all available providers.
100
+ * @returns The list of providers.
101
+ */
102
+ async getProviders() {
103
+ const { data } = await this.httpClient.get(`${this.baseUrl}/providers`);
104
+ return data;
105
+ }
106
+ /**
107
+ * Retrieves configurations filtered by provider.
108
+ * @param providerId - The unique identifier of the provider.
109
+ * @param params - Optional query parameters for filtering configurations.
110
+ * @returns The configurations for the given provider.
111
+ */
112
+ async getConfigsByProvider(providerId, params) {
113
+ const { data } = await this.httpClient.get(
114
+ `${this.baseUrl}/config/provider/${providerId}`,
115
+ { params }
116
+ );
117
+ return data;
118
+ }
119
+ };
120
+
121
+ // src/campaigns/index.ts
122
+ var CampaignsGateway = class {
123
+ constructor(httpClient, baseUrl) {
124
+ this.httpClient = httpClient;
125
+ this.baseUrl = baseUrl;
126
+ }
127
+ httpClient;
128
+ baseUrl;
129
+ /**
130
+ * Retrieves a paginated list of campaigns.
131
+ * @param query - Optional query parameters for filtering and pagination.
132
+ * @returns The paginated campaigns response.
133
+ */
134
+ async find(query) {
135
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns`, {
136
+ params: query
137
+ });
138
+ return data;
139
+ }
140
+ /**
141
+ * Retrieves a campaign by its unique identifier.
142
+ * @param id - The unique identifier of the campaign.
143
+ * @returns The campaign data.
144
+ */
145
+ async get(id) {
146
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns/${id}`);
147
+ return data;
148
+ }
149
+ /**
150
+ * Creates a new campaign.
151
+ * @param payload - The campaign data to create.
152
+ * @returns The created campaign.
153
+ */
154
+ async create(payload) {
155
+ const { data } = await this.httpClient.post(`${this.baseUrl}/campaigns`, payload);
156
+ return data;
157
+ }
158
+ /**
159
+ * Partially updates an existing campaign.
160
+ * @param id - The unique identifier of the campaign.
161
+ * @param payload - The fields to update.
162
+ * @returns The updated campaign.
163
+ */
164
+ async patch(id, payload) {
165
+ const { data } = await this.httpClient.patch(`${this.baseUrl}/campaigns/${id}`, payload);
166
+ return data;
167
+ }
168
+ /**
169
+ * Removes a campaign by its unique identifier.
170
+ * @param id - The unique identifier of the campaign.
171
+ * @returns The removed campaign.
172
+ */
173
+ async remove(id) {
174
+ const { data } = await this.httpClient.delete(`${this.baseUrl}/campaigns/${id}`);
175
+ return data;
176
+ }
40
177
  };
41
178
 
42
179
  // src/@common/client.ts
43
180
  var SDKGateways = class {
44
181
  customerService;
45
- constructor(customerService) {
182
+ chatConfig;
183
+ campaigns;
184
+ constructor(customerService, chatConfig, campaigns) {
46
185
  this.customerService = customerService;
186
+ this.chatConfig = chatConfig;
187
+ this.campaigns = campaigns;
47
188
  }
48
189
  };
49
190
  function createClient(params) {
50
191
  const httpClient = params.axiosClient;
51
- const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);
52
- return new SDKGateways(customerService);
192
+ const customerService = params.services.customerService ? new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl) : null;
193
+ const chatConfig = params.services.chatConfig ? new ChatConfigGateway(httpClient, params.services.chatConfig.baseUrl) : null;
194
+ const campaigns = params.services.campaigns ? new CampaignsGateway(httpClient, params.services.campaigns.baseUrl) : null;
195
+ return new SDKGateways(customerService, chatConfig, campaigns);
53
196
  }
54
197
 
198
+ // src/@common/enums.ts
199
+ var SERVICE_GATEWAYS = {
200
+ CUSTOMER_SERVICE: "customer-service",
201
+ CHAT_CONFIG: "chat-config",
202
+ CAMPAIGNS: "campaigns"
203
+ };
204
+
55
205
  // src/index.ts
56
206
  var SDK = class {
57
207
  client = null;
@@ -63,18 +213,28 @@ var sdk = new SDK();
63
213
  var configure = (params) => {
64
214
  sdk.configure(params);
65
215
  };
66
- var gateway = (service) => {
216
+ function gateway(service) {
67
217
  if (!sdk.client)
68
218
  throw new Error(
69
219
  "SDK not configured. Please call configure() with the appropriate parameters before using the SDK."
70
220
  );
71
221
  switch (service) {
72
- case "customer-service" /* CUSTOMER_SERVICE */:
222
+ case SERVICE_GATEWAYS.CUSTOMER_SERVICE:
223
+ if (!sdk.client.customerService)
224
+ throw new Error(`Service 'customer-service' is not configured. Provide its baseUrl in configure().`);
73
225
  return sdk.client.customerService;
226
+ case SERVICE_GATEWAYS.CHAT_CONFIG:
227
+ if (!sdk.client.chatConfig)
228
+ throw new Error(`Service 'chat-config' is not configured. Provide its baseUrl in configure().`);
229
+ return sdk.client.chatConfig;
230
+ case SERVICE_GATEWAYS.CAMPAIGNS:
231
+ if (!sdk.client.campaigns)
232
+ throw new Error(`Service 'campaigns' is not configured. Provide its baseUrl in configure().`);
233
+ return sdk.client.campaigns;
74
234
  default:
75
235
  throw new Error(`Unknown service gateway: ${service}`);
76
236
  }
77
- };
237
+ }
78
238
  // Annotate the CommonJS export names for ESM import in node:
79
239
  0 && (module.exports = {
80
240
  configure,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/customer-service/index.ts","../src/@common/client.ts"],"sourcesContent":["import { createClient, SDKGatewaysInterface, GatewayClientParams } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\nexport const gateway = (service: SERVICE_GATEWAYS) => {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n return sdk.client.customerService;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n};\n","import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\n\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n}\n\nexport type { CompanyResponse } from './contracts/company';\n","import { CustomerServiceGateway } from '../customer-service';\nimport { AxiosInstance } from 'axios';\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway;\n constructor(customerService: CustomerServiceGateway) {\n this.customerService = customerService;\n }\n}\n\nexport interface GatewayClientParams {\n axiosClient: AxiosInstance;\n apiToken: string;\n services: {\n customerService: {\n baseUrl: string;\n };\n };\n}\n\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);\n return new SDKGateways(customerService);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGnB,MAAM,eAAe,WAA6C;AAChE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW,IAAqB,GAAG,KAAK,OAAO,qBAAqB,SAAS,EAAE;AAC3G,WAAO;AAAA,EACT;AACF;;;ACNA,IAAM,cAAN,MAAkB;AAAA,EAChB;AAAA,EACA,YAAY,iBAAyC;AACnD,SAAK,kBAAkB;AAAA,EACzB;AACF;AAYO,SAAS,aAAa,QAA6B;AACxD,QAAM,aAAa,OAAO;AAC1B,QAAM,kBAAkB,IAAI,uBAAuB,YAAY,OAAO,SAAS,gBAAgB,OAAO;AACtG,SAAO,IAAI,YAAY,eAAe;AACxC;;;AF1BA,IAAM,MAAN,MAAU;AAAA,EACR,SAAsC;AAAA,EAEtC,UAAU,QAA6B;AACrC,SAAK,SAAS,aAAa,MAAM;AAAA,EACnC;AACF;AACA,IAAM,MAAM,IAAI,IAAI;AAEb,IAAM,YAAY,CAAC,WAAgC;AACxD,MAAI,UAAU,MAAM;AACtB;AAEO,IAAM,UAAU,CAAC,YAA8B;AACpD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,UAAQ,SAAS;AAAA,IACf;AACE,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/customer-service/index.ts","../src/chat-config/index.ts","../src/campaigns/index.ts","../src/@common/client.ts","../src/@common/enums.ts"],"sourcesContent":["import { createClient, SDKGatewaysInterface, GatewayClientParams, GatewayMap } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\n\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\n/**\n * Initializes the SDK with the required configuration parameters.\n * Must be called before using {@link gateway}.\n */\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\n/**\n * Returns the gateway instance for the specified service.\n *\n * @typeParam T - A service identifier key from {@link GatewayMap}.\n * @param service - The service identifier (e.g. `SERVICE_GATEWAYS.CUSTOMER_SERVICE`).\n * @returns The corresponding gateway instance with all its methods.\n * @throws {Error} If the SDK has not been configured via {@link configure}.\n * @throws {Error} If an unknown service identifier is provided.\n *\n * @example\n * ```ts\n * configure({ axiosClient, apiToken: '...', services: { customerService: { baseUrl: '...' } } });\n * const customer = gateway('customer-service');\n * const company = await customer.getCompanyById('123');\n * ```\n */\nexport function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];\nexport function gateway(service: SERVICE_GATEWAYS) {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n if (!sdk.client.customerService)\n throw new Error(`Service 'customer-service' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.customerService;\n case SERVICE_GATEWAYS.CHAT_CONFIG:\n if (!sdk.client.chatConfig)\n throw new Error(`Service 'chat-config' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.chatConfig;\n case SERVICE_GATEWAYS.CAMPAIGNS:\n if (!sdk.client.campaigns)\n throw new Error(`Service 'campaigns' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.campaigns;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n}\n","import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\nimport type { WorkGroupListResponse, WorkGroupMembersResponse, WorkGroupResponse } from './contracts/work-group';\n\n/**\n * Gateway for interacting with the Customer Service API.\n */\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves a company by its unique identifier.\n * @param companyId - The unique identifier of the company.\n * @returns The company data wrapped in a {@link CompanyResponse}.\n */\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n\n /**\n * Retrieves all work groups for a company.\n * @param companyId - The unique identifier of the company.\n * @returns The work groups for the given company.\n */\n async getWorkGroups(companyId: string): Promise<WorkGroupListResponse> {\n const { data } = await this.httpClient.get<WorkGroupListResponse>(\n `${this.baseUrl}/companies/work-groups`,\n { params: { company_id: companyId } },\n );\n return data;\n }\n\n /**\n * Retrieves a work group by its unique identifier.\n * @param workGroupId - The unique identifier of the work group.\n * @param companyId - The unique identifier of the company (optional, sent as query parameter).\n * @returns The work group data wrapped in a {@link WorkGroupResponse}.\n */\n async getWorkGroupById(workGroupId: string, companyId?: string): Promise<WorkGroupResponse> {\n const params = companyId ? { company_id: companyId } : undefined;\n const { data } = await this.httpClient.get<WorkGroupResponse>(\n `${this.baseUrl}/companies/work-groups/${workGroupId}`,\n { params },\n );\n return data;\n }\n\n /**\n * Retrieves the members of a work group by its identifier.\n * @param groupId - The unique identifier of the work group.\n * @param companyId - The unique identifier of the company (optional, sent as query parameter).\n * @param profile - Filter members by profile (optional).\n * @returns The members of the work group.\n */\n async getWorkGroupMembers(groupId: string, companyId?: string, profile?: string[]): Promise<WorkGroupMembersResponse> {\n const params: { company_id?: string; profile?: string[] } = {};\n if (companyId) params.company_id = companyId;\n if (profile) params.profile = profile;\n const { data } = await this.httpClient.get<WorkGroupMembersResponse>(\n `${this.baseUrl}/bonds/work-groups/${groupId}`,\n { params },\n );\n return data;\n }\n}\n\nexport type { CompanyResponse, CompanyData } from './contracts/company';\nexport type { WorkGroup, WorkGroupMember, WorkGroupMembersResponse, WorkGroupListResponse, WorkGroupResponse } from './contracts/work-group';","import type { AxiosInstance } from 'axios';\nimport type { ProviderListResponse } from './contracts/provider';\nimport type { ConfigListByProviderResponse, GetConfigsByProviderParams } from './contracts/config';\n\n/**\n * Gateway for interacting with the Chat Config API.\n */\nexport class ChatConfigGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves all available providers.\n * @returns The list of providers.\n */\n async getProviders(): Promise<ProviderListResponse> {\n const { data } = await this.httpClient.get<ProviderListResponse>(`${this.baseUrl}/providers`);\n return data;\n }\n\n /**\n * Retrieves configurations filtered by provider.\n * @param providerId - The unique identifier of the provider.\n * @param params - Optional query parameters for filtering configurations.\n * @returns The configurations for the given provider.\n */\n async getConfigsByProvider(providerId: string, params?: GetConfigsByProviderParams): Promise<ConfigListByProviderResponse> {\n const { data } = await this.httpClient.get<ConfigListByProviderResponse>(\n `${this.baseUrl}/config/provider/${providerId}`,\n { params },\n );\n return data;\n }\n}\n\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type { ConfigListByProviderResponse, Config, ConfigProvider, GetConfigsByProviderParams } from './contracts/config';","import type { AxiosInstance } from 'axios';\nimport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CreateCampaignRequest,\n PatchCampaignRequest,\n} from './contracts/campaign';\n\n/**\n * Gateway for interacting with the Campaigns API.\n */\nexport class CampaignsGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves a paginated list of campaigns.\n * @param query - Optional query parameters for filtering and pagination.\n * @returns The paginated campaigns response.\n */\n async find(query?: CampaignQueryParams): Promise<CampaignPaginatedResponse> {\n const { data } = await this.httpClient.get<CampaignPaginatedResponse>(`${this.baseUrl}/campaigns`, {\n params: query,\n });\n return data;\n }\n\n /**\n * Retrieves a campaign by its unique identifier.\n * @param id - The unique identifier of the campaign.\n * @returns The campaign data.\n */\n async get(id: string): Promise<Campaign> {\n const { data } = await this.httpClient.get<Campaign>(`${this.baseUrl}/campaigns/${id}`);\n return data;\n }\n\n /**\n * Creates a new campaign.\n * @param payload - The campaign data to create.\n * @returns The created campaign.\n */\n async create(payload: CreateCampaignRequest): Promise<Campaign> {\n const { data } = await this.httpClient.post<Campaign>(`${this.baseUrl}/campaigns`, payload);\n return data;\n }\n\n /**\n * Partially updates an existing campaign.\n * @param id - The unique identifier of the campaign.\n * @param payload - The fields to update.\n * @returns The updated campaign.\n */\n async patch(id: string, payload: PatchCampaignRequest): Promise<Campaign> {\n const { data } = await this.httpClient.patch<Campaign>(`${this.baseUrl}/campaigns/${id}`, payload);\n return data;\n }\n\n /**\n * Removes a campaign by its unique identifier.\n * @param id - The unique identifier of the campaign.\n * @returns The removed campaign.\n */\n async remove(id: string): Promise<Campaign> {\n const { data } = await this.httpClient.delete<Campaign>(`${this.baseUrl}/campaigns/${id}`);\n return data;\n }\n}\n\nexport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CampaignStatus,\n CampaignProvider,\n WhatsAppPayload,\n WhatsAppTemplateComponent,\n CampaignContactFilter,\n CampaignSchedule,\n CreateCampaignRequest,\n PatchCampaignRequest,\n} from './contracts/campaign';","import { CustomerServiceGateway } from '../customer-service';\nimport { ChatConfigGateway } from '../chat-config';\nimport { CampaignsGateway } from '../campaigns';\nimport { AxiosInstance } from 'axios';\n\n/**\n * Maps service identifiers to their corresponding gateway types.\n * Used by the `gateway()` function to infer the correct return type\n * based on the service name passed as argument.\n *\n * When adding a new service, add an entry here with the service\n * identifier as the key and the gateway class as the value.\n */\nexport type GatewayMap = {\n 'customer-service': CustomerServiceGateway;\n 'chat-config': ChatConfigGateway;\n 'campaigns': CampaignsGateway;\n};\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway | null;\n chatConfig: ChatConfigGateway | null;\n campaigns: CampaignsGateway | null;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway | null;\n chatConfig: ChatConfigGateway | null;\n campaigns: CampaignsGateway | null;\n constructor(customerService: CustomerServiceGateway | null, chatConfig: ChatConfigGateway | null, campaigns: CampaignsGateway | null) {\n this.customerService = customerService;\n this.chatConfig = chatConfig;\n this.campaigns = campaigns;\n }\n}\n\n/**\n * Parameters required to configure the SDK client.\n * Each service configuration is optional, only provide the services you need.\n */\nexport interface GatewayClientParams {\n /** An Axios instance used as the HTTP client for all gateway requests. */\n axiosClient: AxiosInstance;\n /** API token used for authentication across all services. */\n apiToken: string;\n /** Configuration for each service gateway. Only the services you configure will be available. */\n services: {\n customerService?: {\n baseUrl: string;\n };\n chatConfig?: {\n baseUrl: string;\n };\n campaigns?: {\n baseUrl: string;\n };\n };\n}\n\n/**\n * Creates an SDKGateways instance with all service gateways initialized\n * using the provided configuration parameters.\n * Services without configuration will be set to null and will throw\n * an error if accessed via `gateway()`.\n */\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = params.services.customerService\n ? new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl)\n : null;\n const chatConfig = params.services.chatConfig\n ? new ChatConfigGateway(httpClient, params.services.chatConfig.baseUrl)\n : null;\n const campaigns = params.services.campaigns\n ? new CampaignsGateway(httpClient, params.services.campaigns.baseUrl)\n : null;\n return new SDKGateways(customerService, chatConfig, campaigns);\n}\n","export const SERVICE_GATEWAYS = {\n CUSTOMER_SERVICE: 'customer-service',\n CHAT_CONFIG: 'chat-config',\n CAMPAIGNS: 'campaigns',\n} as const;\n\nexport type SERVICE_GATEWAYS = (typeof SERVICE_GATEWAYS)[keyof typeof SERVICE_GATEWAYS];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQnB,MAAM,eAAe,WAA6C;AAChE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW,IAAqB,GAAG,KAAK,OAAO,qBAAqB,SAAS,EAAE;AAC3G,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAc,WAAmD;AACrE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW;AAAA,MACrC,GAAG,KAAK,OAAO;AAAA,MACf,EAAE,QAAQ,EAAE,YAAY,UAAU,EAAE;AAAA,IACtC;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AkB,YAAY,OAAO,SAAS,WAAW,OAAO,IACpE;AACJ,QAAM,YAAY,OAAO,SAAS,YAC9B,IAAI,iBAAiB,YAAY,OAAO,SAAS,UAAU,OAAO,IAClE;AACJ,SAAO,IAAI,YAAY,iBAAiB,YAAY,SAAS;AAC/D;;;AC7EO,IAAM,mBAAmB;AAAA,EAC9B,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,WAAW;AACb;;;ALDA,IAAM,MAAN,MAAU;AAAA,EACR,SAAsC;AAAA,EAEtC,UAAU,QAA6B;AACrC,SAAK,SAAS,aAAa,MAAM;AAAA,EACnC;AACF;AACA,IAAM,MAAM,IAAI,IAAI;AAMb,IAAM,YAAY,CAAC,WAAgC;AACxD,MAAI,UAAU,MAAM;AACtB;AAmBO,SAAS,QAAQ,SAA2B;AACjD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,UAAQ,SAAS;AAAA,IACf,KAAK,iBAAiB;AACpB,UAAI,CAAC,IAAI,OAAO;AACd,cAAM,IAAI,MAAM,mFAAmF;AACrG,aAAO,IAAI,OAAO;AAAA,IACpB,KAAK,iBAAiB;AACpB,UAAI,CAAC,IAAI,OAAO;AACd,cAAM,IAAI,MAAM,8EAA8E;AAChG,aAAO,IAAI,OAAO;AAAA,IACpB,KAAK,iBAAiB;AACpB,UAAI,CAAC,IAAI,OAAO;AACd,cAAM,IAAI,MAAM,4EAA4E;AAC9F,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
package/dist/index.mjs CHANGED
@@ -6,25 +6,175 @@ var CustomerServiceGateway = class {
6
6
  }
7
7
  httpClient;
8
8
  baseUrl;
9
+ /**
10
+ * Retrieves a company by its unique identifier.
11
+ * @param companyId - The unique identifier of the company.
12
+ * @returns The company data wrapped in a {@link CompanyResponse}.
13
+ */
9
14
  async getCompanyById(companyId) {
10
15
  const { data } = await this.httpClient.get(`${this.baseUrl}/companies/search/${companyId}`);
11
16
  return data;
12
17
  }
18
+ /**
19
+ * Retrieves all work groups for a company.
20
+ * @param companyId - The unique identifier of the company.
21
+ * @returns The work groups for the given company.
22
+ */
23
+ async getWorkGroups(companyId) {
24
+ const { data } = await this.httpClient.get(
25
+ `${this.baseUrl}/companies/work-groups`,
26
+ { params: { company_id: companyId } }
27
+ );
28
+ return data;
29
+ }
30
+ /**
31
+ * Retrieves a work group by its unique identifier.
32
+ * @param workGroupId - The unique identifier of the work group.
33
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
34
+ * @returns The work group data wrapped in a {@link WorkGroupResponse}.
35
+ */
36
+ async getWorkGroupById(workGroupId, companyId) {
37
+ const params = companyId ? { company_id: companyId } : void 0;
38
+ const { data } = await this.httpClient.get(
39
+ `${this.baseUrl}/companies/work-groups/${workGroupId}`,
40
+ { params }
41
+ );
42
+ return data;
43
+ }
44
+ /**
45
+ * Retrieves the members of a work group by its identifier.
46
+ * @param groupId - The unique identifier of the work group.
47
+ * @param companyId - The unique identifier of the company (optional, sent as query parameter).
48
+ * @param profile - Filter members by profile (optional).
49
+ * @returns The members of the work group.
50
+ */
51
+ async getWorkGroupMembers(groupId, companyId, profile) {
52
+ const params = {};
53
+ if (companyId) params.company_id = companyId;
54
+ if (profile) params.profile = profile;
55
+ const { data } = await this.httpClient.get(
56
+ `${this.baseUrl}/bonds/work-groups/${groupId}`,
57
+ { params }
58
+ );
59
+ return data;
60
+ }
61
+ };
62
+
63
+ // src/chat-config/index.ts
64
+ var ChatConfigGateway = class {
65
+ constructor(httpClient, baseUrl) {
66
+ this.httpClient = httpClient;
67
+ this.baseUrl = baseUrl;
68
+ }
69
+ httpClient;
70
+ baseUrl;
71
+ /**
72
+ * Retrieves all available providers.
73
+ * @returns The list of providers.
74
+ */
75
+ async getProviders() {
76
+ const { data } = await this.httpClient.get(`${this.baseUrl}/providers`);
77
+ return data;
78
+ }
79
+ /**
80
+ * Retrieves configurations filtered by provider.
81
+ * @param providerId - The unique identifier of the provider.
82
+ * @param params - Optional query parameters for filtering configurations.
83
+ * @returns The configurations for the given provider.
84
+ */
85
+ async getConfigsByProvider(providerId, params) {
86
+ const { data } = await this.httpClient.get(
87
+ `${this.baseUrl}/config/provider/${providerId}`,
88
+ { params }
89
+ );
90
+ return data;
91
+ }
92
+ };
93
+
94
+ // src/campaigns/index.ts
95
+ var CampaignsGateway = class {
96
+ constructor(httpClient, baseUrl) {
97
+ this.httpClient = httpClient;
98
+ this.baseUrl = baseUrl;
99
+ }
100
+ httpClient;
101
+ baseUrl;
102
+ /**
103
+ * Retrieves a paginated list of campaigns.
104
+ * @param query - Optional query parameters for filtering and pagination.
105
+ * @returns The paginated campaigns response.
106
+ */
107
+ async find(query) {
108
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns`, {
109
+ params: query
110
+ });
111
+ return data;
112
+ }
113
+ /**
114
+ * Retrieves a campaign by its unique identifier.
115
+ * @param id - The unique identifier of the campaign.
116
+ * @returns The campaign data.
117
+ */
118
+ async get(id) {
119
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns/${id}`);
120
+ return data;
121
+ }
122
+ /**
123
+ * Creates a new campaign.
124
+ * @param payload - The campaign data to create.
125
+ * @returns The created campaign.
126
+ */
127
+ async create(payload) {
128
+ const { data } = await this.httpClient.post(`${this.baseUrl}/campaigns`, payload);
129
+ return data;
130
+ }
131
+ /**
132
+ * Partially updates an existing campaign.
133
+ * @param id - The unique identifier of the campaign.
134
+ * @param payload - The fields to update.
135
+ * @returns The updated campaign.
136
+ */
137
+ async patch(id, payload) {
138
+ const { data } = await this.httpClient.patch(`${this.baseUrl}/campaigns/${id}`, payload);
139
+ return data;
140
+ }
141
+ /**
142
+ * Removes a campaign by its unique identifier.
143
+ * @param id - The unique identifier of the campaign.
144
+ * @returns The removed campaign.
145
+ */
146
+ async remove(id) {
147
+ const { data } = await this.httpClient.delete(`${this.baseUrl}/campaigns/${id}`);
148
+ return data;
149
+ }
13
150
  };
14
151
 
15
152
  // src/@common/client.ts
16
153
  var SDKGateways = class {
17
154
  customerService;
18
- constructor(customerService) {
155
+ chatConfig;
156
+ campaigns;
157
+ constructor(customerService, chatConfig, campaigns) {
19
158
  this.customerService = customerService;
159
+ this.chatConfig = chatConfig;
160
+ this.campaigns = campaigns;
20
161
  }
21
162
  };
22
163
  function createClient(params) {
23
164
  const httpClient = params.axiosClient;
24
- const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);
25
- return new SDKGateways(customerService);
165
+ const customerService = params.services.customerService ? new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl) : null;
166
+ const chatConfig = params.services.chatConfig ? new ChatConfigGateway(httpClient, params.services.chatConfig.baseUrl) : null;
167
+ const campaigns = params.services.campaigns ? new CampaignsGateway(httpClient, params.services.campaigns.baseUrl) : null;
168
+ return new SDKGateways(customerService, chatConfig, campaigns);
26
169
  }
27
170
 
171
+ // src/@common/enums.ts
172
+ var SERVICE_GATEWAYS = {
173
+ CUSTOMER_SERVICE: "customer-service",
174
+ CHAT_CONFIG: "chat-config",
175
+ CAMPAIGNS: "campaigns"
176
+ };
177
+
28
178
  // src/index.ts
29
179
  var SDK = class {
30
180
  client = null;
@@ -36,18 +186,28 @@ var sdk = new SDK();
36
186
  var configure = (params) => {
37
187
  sdk.configure(params);
38
188
  };
39
- var gateway = (service) => {
189
+ function gateway(service) {
40
190
  if (!sdk.client)
41
191
  throw new Error(
42
192
  "SDK not configured. Please call configure() with the appropriate parameters before using the SDK."
43
193
  );
44
194
  switch (service) {
45
- case "customer-service" /* CUSTOMER_SERVICE */:
195
+ case SERVICE_GATEWAYS.CUSTOMER_SERVICE:
196
+ if (!sdk.client.customerService)
197
+ throw new Error(`Service 'customer-service' is not configured. Provide its baseUrl in configure().`);
46
198
  return sdk.client.customerService;
199
+ case SERVICE_GATEWAYS.CHAT_CONFIG:
200
+ if (!sdk.client.chatConfig)
201
+ throw new Error(`Service 'chat-config' is not configured. Provide its baseUrl in configure().`);
202
+ return sdk.client.chatConfig;
203
+ case SERVICE_GATEWAYS.CAMPAIGNS:
204
+ if (!sdk.client.campaigns)
205
+ throw new Error(`Service 'campaigns' is not configured. Provide its baseUrl in configure().`);
206
+ return sdk.client.campaigns;
47
207
  default:
48
208
  throw new Error(`Unknown service gateway: ${service}`);
49
209
  }
50
- };
210
+ }
51
211
  export {
52
212
  configure,
53
213
  gateway
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/customer-service/index.ts","../src/@common/client.ts","../src/index.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\n\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n}\n\nexport type { CompanyResponse } from './contracts/company';\n","import { CustomerServiceGateway } from '../customer-service';\nimport { AxiosInstance } from 'axios';\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway;\n constructor(customerService: CustomerServiceGateway) {\n this.customerService = customerService;\n }\n}\n\nexport interface GatewayClientParams {\n axiosClient: AxiosInstance;\n apiToken: string;\n services: {\n customerService: {\n baseUrl: string;\n };\n };\n}\n\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);\n return new SDKGateways(customerService);\n}\n","import { createClient, SDKGatewaysInterface, GatewayClientParams } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\nexport const gateway = (service: SERVICE_GATEWAYS) => {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n return sdk.client.customerService;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n};\n"],"mappings":";AAGO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA,EAGnB,MAAM,eAAe,WAA6C;AAChE,UAAM,EAAE,KAAK,IAAI,MAAM,KAAK,WAAW,IAAqB,GAAG,KAAK,OAAO,qBAAqB,SAAS,EAAE;AAC3G,WAAO;AAAA,EACT;AACF;;;ACNA,IAAM,cAAN,MAAkB;AAAA,EAChB;AAAA,EACA,YAAY,iBAAyC;AACnD,SAAK,kBAAkB;AAAA,EACzB;AACF;AAYO,SAAS,aAAa,QAA6B;AACxD,QAAM,aAAa,OAAO;AAC1B,QAAM,kBAAkB,IAAI,uBAAuB,YAAY,OAAO,SAAS,gBAAgB,OAAO;AACtG,SAAO,IAAI,YAAY,eAAe;AACxC;;;AC1BA,IAAM,MAAN,MAAU;AAAA,EACR,SAAsC;AAAA,EAEtC,UAAU,QAA6B;AACrC,SAAK,SAAS,aAAa,MAAM;AAAA,EACnC;AACF;AACA,IAAM,MAAM,IAAI,IAAI;AAEb,IAAM,YAAY,CAAC,WAAgC;AACxD,MAAI,UAAU,MAAM;AACtB;AAEO,IAAM,UAAU,CAAC,YAA8B;AACpD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,UAAQ,SAAS;AAAA,IACf;AACE,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/customer-service/index.ts","../src/chat-config/index.ts","../src/campaigns/index.ts","../src/@common/client.ts","../src/@common/enums.ts","../src/index.ts"],"sourcesContent":["import type { AxiosInstance } from 'axios';\nimport type { CompanyResponse } from './contracts/company';\nimport type { WorkGroupListResponse, WorkGroupMembersResponse, WorkGroupResponse } from './contracts/work-group';\n\n/**\n * Gateway for interacting with the Customer Service API.\n */\nexport class CustomerServiceGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves a company by its unique identifier.\n * @param companyId - The unique identifier of the company.\n * @returns The company data wrapped in a {@link CompanyResponse}.\n */\n async getCompanyById(companyId: string): Promise<CompanyResponse> {\n const { data } = await this.httpClient.get<CompanyResponse>(`${this.baseUrl}/companies/search/${companyId}`);\n return data;\n }\n\n /**\n * Retrieves all work groups for a company.\n * @param companyId - The unique identifier of the company.\n * @returns The work groups for the given company.\n */\n async getWorkGroups(companyId: string): Promise<WorkGroupListResponse> {\n const { data } = await this.httpClient.get<WorkGroupListResponse>(\n `${this.baseUrl}/companies/work-groups`,\n { params: { company_id: companyId } },\n );\n return data;\n }\n\n /**\n * Retrieves a work group by its unique identifier.\n * @param workGroupId - The unique identifier of the work group.\n * @param companyId - The unique identifier of the company (optional, sent as query parameter).\n * @returns The work group data wrapped in a {@link WorkGroupResponse}.\n */\n async getWorkGroupById(workGroupId: string, companyId?: string): Promise<WorkGroupResponse> {\n const params = companyId ? { company_id: companyId } : undefined;\n const { data } = await this.httpClient.get<WorkGroupResponse>(\n `${this.baseUrl}/companies/work-groups/${workGroupId}`,\n { params },\n );\n return data;\n }\n\n /**\n * Retrieves the members of a work group by its identifier.\n * @param groupId - The unique identifier of the work group.\n * @param companyId - The unique identifier of the company (optional, sent as query parameter).\n * @param profile - Filter members by profile (optional).\n * @returns The members of the work group.\n */\n async getWorkGroupMembers(groupId: string, companyId?: string, profile?: string[]): Promise<WorkGroupMembersResponse> {\n const params: { company_id?: string; profile?: string[] } = {};\n if (companyId) params.company_id = companyId;\n if (profile) params.profile = profile;\n const { data } = await this.httpClient.get<WorkGroupMembersResponse>(\n `${this.baseUrl}/bonds/work-groups/${groupId}`,\n { params },\n );\n return data;\n }\n}\n\nexport type { CompanyResponse, CompanyData } from './contracts/company';\nexport type { WorkGroup, WorkGroupMember, WorkGroupMembersResponse, WorkGroupListResponse, WorkGroupResponse } from './contracts/work-group';","import type { AxiosInstance } from 'axios';\nimport type { ProviderListResponse } from './contracts/provider';\nimport type { ConfigListByProviderResponse, GetConfigsByProviderParams } from './contracts/config';\n\n/**\n * Gateway for interacting with the Chat Config API.\n */\nexport class ChatConfigGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves all available providers.\n * @returns The list of providers.\n */\n async getProviders(): Promise<ProviderListResponse> {\n const { data } = await this.httpClient.get<ProviderListResponse>(`${this.baseUrl}/providers`);\n return data;\n }\n\n /**\n * Retrieves configurations filtered by provider.\n * @param providerId - The unique identifier of the provider.\n * @param params - Optional query parameters for filtering configurations.\n * @returns The configurations for the given provider.\n */\n async getConfigsByProvider(providerId: string, params?: GetConfigsByProviderParams): Promise<ConfigListByProviderResponse> {\n const { data } = await this.httpClient.get<ConfigListByProviderResponse>(\n `${this.baseUrl}/config/provider/${providerId}`,\n { params },\n );\n return data;\n }\n}\n\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type { ConfigListByProviderResponse, Config, ConfigProvider, GetConfigsByProviderParams } from './contracts/config';","import type { AxiosInstance } from 'axios';\nimport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CreateCampaignRequest,\n PatchCampaignRequest,\n} from './contracts/campaign';\n\n/**\n * Gateway for interacting with the Campaigns API.\n */\nexport class CampaignsGateway {\n constructor(\n private readonly httpClient: AxiosInstance,\n private readonly baseUrl: string,\n ) {}\n\n /**\n * Retrieves a paginated list of campaigns.\n * @param query - Optional query parameters for filtering and pagination.\n * @returns The paginated campaigns response.\n */\n async find(query?: CampaignQueryParams): Promise<CampaignPaginatedResponse> {\n const { data } = await this.httpClient.get<CampaignPaginatedResponse>(`${this.baseUrl}/campaigns`, {\n params: query,\n });\n return data;\n }\n\n /**\n * Retrieves a campaign by its unique identifier.\n * @param id - The unique identifier of the campaign.\n * @returns The campaign data.\n */\n async get(id: string): Promise<Campaign> {\n const { data } = await this.httpClient.get<Campaign>(`${this.baseUrl}/campaigns/${id}`);\n return data;\n }\n\n /**\n * Creates a new campaign.\n * @param payload - The campaign data to create.\n * @returns The created campaign.\n */\n async create(payload: CreateCampaignRequest): Promise<Campaign> {\n const { data } = await this.httpClient.post<Campaign>(`${this.baseUrl}/campaigns`, payload);\n return data;\n }\n\n /**\n * Partially updates an existing campaign.\n * @param id - The unique identifier of the campaign.\n * @param payload - The fields to update.\n * @returns The updated campaign.\n */\n async patch(id: string, payload: PatchCampaignRequest): Promise<Campaign> {\n const { data } = await this.httpClient.patch<Campaign>(`${this.baseUrl}/campaigns/${id}`, payload);\n return data;\n }\n\n /**\n * Removes a campaign by its unique identifier.\n * @param id - The unique identifier of the campaign.\n * @returns The removed campaign.\n */\n async remove(id: string): Promise<Campaign> {\n const { data } = await this.httpClient.delete<Campaign>(`${this.baseUrl}/campaigns/${id}`);\n return data;\n }\n}\n\nexport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CampaignStatus,\n CampaignProvider,\n WhatsAppPayload,\n WhatsAppTemplateComponent,\n CampaignContactFilter,\n CampaignSchedule,\n CreateCampaignRequest,\n PatchCampaignRequest,\n} from './contracts/campaign';","import { CustomerServiceGateway } from '../customer-service';\nimport { ChatConfigGateway } from '../chat-config';\nimport { CampaignsGateway } from '../campaigns';\nimport { AxiosInstance } from 'axios';\n\n/**\n * Maps service identifiers to their corresponding gateway types.\n * Used by the `gateway()` function to infer the correct return type\n * based on the service name passed as argument.\n *\n * When adding a new service, add an entry here with the service\n * identifier as the key and the gateway class as the value.\n */\nexport type GatewayMap = {\n 'customer-service': CustomerServiceGateway;\n 'chat-config': ChatConfigGateway;\n 'campaigns': CampaignsGateway;\n};\n\nexport interface SDKGatewaysInterface {\n customerService: CustomerServiceGateway | null;\n chatConfig: ChatConfigGateway | null;\n campaigns: CampaignsGateway | null;\n}\n\nclass SDKGateways {\n customerService: CustomerServiceGateway | null;\n chatConfig: ChatConfigGateway | null;\n campaigns: CampaignsGateway | null;\n constructor(customerService: CustomerServiceGateway | null, chatConfig: ChatConfigGateway | null, campaigns: CampaignsGateway | null) {\n this.customerService = customerService;\n this.chatConfig = chatConfig;\n this.campaigns = campaigns;\n }\n}\n\n/**\n * Parameters required to configure the SDK client.\n * Each service configuration is optional, only provide the services you need.\n */\nexport interface GatewayClientParams {\n /** An Axios instance used as the HTTP client for all gateway requests. */\n axiosClient: AxiosInstance;\n /** API token used for authentication across all services. */\n apiToken: string;\n /** Configuration for each service gateway. Only the services you configure will be available. */\n services: {\n customerService?: {\n baseUrl: string;\n };\n chatConfig?: {\n baseUrl: string;\n };\n campaigns?: {\n baseUrl: string;\n };\n };\n}\n\n/**\n * Creates an SDKGateways instance with all service gateways initialized\n * using the provided configuration parameters.\n * Services without configuration will be set to null and will throw\n * an error if accessed via `gateway()`.\n */\nexport function createClient(params: GatewayClientParams) {\n const httpClient = params.axiosClient;\n const customerService = params.services.customerService\n ? new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl)\n : null;\n const chatConfig = params.services.chatConfig\n ? new ChatConfigGateway(httpClient, params.services.chatConfig.baseUrl)\n : null;\n const campaigns = params.services.campaigns\n ? new CampaignsGateway(httpClient, params.services.campaigns.baseUrl)\n : null;\n return new SDKGateways(customerService, chatConfig, campaigns);\n}\n","export const SERVICE_GATEWAYS = {\n CUSTOMER_SERVICE: 'customer-service',\n CHAT_CONFIG: 'chat-config',\n CAMPAIGNS: 'campaigns',\n} as const;\n\nexport type SERVICE_GATEWAYS = (typeof SERVICE_GATEWAYS)[keyof typeof SERVICE_GATEWAYS];\n","import { createClient, SDKGatewaysInterface, GatewayClientParams, GatewayMap } from './@common/client';\nimport { SERVICE_GATEWAYS } from './@common/enums';\n\nclass SDK {\n client: SDKGatewaysInterface | null = null;\n\n configure(params: GatewayClientParams) {\n this.client = createClient(params);\n }\n}\nconst sdk = new SDK();\n\n/**\n * Initializes the SDK with the required configuration parameters.\n * Must be called before using {@link gateway}.\n */\nexport const configure = (params: GatewayClientParams) => {\n sdk.configure(params);\n};\n\n/**\n * Returns the gateway instance for the specified service.\n *\n * @typeParam T - A service identifier key from {@link GatewayMap}.\n * @param service - The service identifier (e.g. `SERVICE_GATEWAYS.CUSTOMER_SERVICE`).\n * @returns The corresponding gateway instance with all its methods.\n * @throws {Error} If the SDK has not been configured via {@link configure}.\n * @throws {Error} If an unknown service identifier is provided.\n *\n * @example\n * ```ts\n * configure({ axiosClient, apiToken: '...', services: { customerService: { baseUrl: '...' } } });\n * const customer = gateway('customer-service');\n * const company = await customer.getCompanyById('123');\n * ```\n */\nexport function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];\nexport function gateway(service: SERVICE_GATEWAYS) {\n if (!sdk.client)\n throw new Error(\n 'SDK not configured. Please call configure() with the appropriate parameters before using the SDK.',\n );\n\n switch (service) {\n case SERVICE_GATEWAYS.CUSTOMER_SERVICE:\n if (!sdk.client.customerService)\n throw new Error(`Service 'customer-service' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.customerService;\n case SERVICE_GATEWAYS.CHAT_CONFIG:\n if (!sdk.client.chatConfig)\n throw new Error(`Service 'chat-config' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.chatConfig;\n case SERVICE_GATEWAYS.CAMPAIGNS:\n if (!sdk.client.campaigns)\n throw new Error(`Service 'campaigns' is not configured. Provide its baseUrl in configure().`);\n return sdk.client.campaigns;\n default:\n throw new Error(`Unknown service gateway: ${service}`);\n }\n}\n"],"mappings":";AAOO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YACmB,YACA,SACjB;AAFiB;AACA;AAAA,EAChB;AAAA,EAFgB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AiB;AACpB,UAAI,CAAC,IAAI,OAAO;AACd,cAAM,IAAI,MAAM,4EAA4E;AAC9F,aAAO,IAAI,OAAO;AAAA,IACpB;AACE,YAAM,IAAI,MAAM,4BAA4B,OAAO,EAAE;AAAA,EACzD;AACF;","names":[]}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0",
2
+ "version": "1.0.1",
3
3
  "description": "A simple package to help with some common tasks",
4
4
  "name": "@opens/gateways",
5
5
  "private": false,