@opens/gateways 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,47 +1,441 @@
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
+ interface QueueMember {
155
+ id: string;
156
+ memberId: string;
157
+ priority: number;
158
+ permission: string;
159
+ lastAttendance: string;
160
+ lastInvite: string;
161
+ paused: boolean;
162
+ activeChat: number;
163
+ online: boolean;
164
+ companyId: string;
165
+ avatar: string;
166
+ username: string;
167
+ createdAt: string;
168
+ updatedAt: string;
169
+ queueId: string;
170
+ }
171
+ type DistributionType = {
172
+ id: string;
173
+ alias: string;
174
+ description: string;
175
+ createdAt: string;
176
+ updatedAt: string;
177
+ };
178
+ interface Queue {
179
+ id: string;
180
+ distributionTypeId: string;
181
+ companyId: string;
182
+ name: string;
183
+ strategy: 'leastrecent' | 'roundrobin' | 'random';
184
+ defaultQueue: boolean;
185
+ unlimitedService: boolean;
186
+ serviceLimit: number;
187
+ timeLimit: number;
188
+ skipOncallUsers: boolean;
189
+ csat: boolean;
190
+ csatAnswer: string;
191
+ csatTTL: number;
192
+ outsideBusinessHourMessage: string;
193
+ createCallbackOnExpired: boolean;
194
+ createCallbackOnOutsideBusinessHours: boolean;
195
+ archived: boolean;
196
+ isPrivate: boolean;
197
+ createdAt: string;
198
+ updatedAt: string;
199
+ members: QueueMember[];
200
+ distributionType: DistributionType;
201
+ }
202
+
203
+ /**
204
+ * Gateway for interacting with the Chat Config API.
205
+ */
206
+ declare class ChatConfigGateway {
207
+ private readonly httpClient;
208
+ private readonly baseUrl;
209
+ constructor(httpClient: AxiosInstance, baseUrl: string);
210
+ /**
211
+ * Retrieves all available providers.
212
+ * @returns The list of providers.
213
+ */
214
+ getProviders(): Promise<ProviderListResponse>;
215
+ /**
216
+ * Retrieves configurations filtered by provider.
217
+ * @param providerId - The unique identifier of the provider.
218
+ * @param params - Optional query parameters for filtering configurations.
219
+ * @returns The configurations for the given provider.
220
+ */
221
+ getConfigsByProvider(providerId: string, params?: GetConfigsByProviderParams): Promise<ConfigListByProviderResponse>;
222
+ /**
223
+ * Retrieves a queue by its ID.
224
+ * @param queueId - The unique identifier of the queue.
225
+ * @returns The queue data.
226
+ */
227
+ getQueueById(queueId: string): Promise<Queue>;
228
+ }
229
+
230
+ /** Campaign status literals. */
231
+ type CampaignStatus = 'ongoing' | 'finished' | 'paused' | 'scheduled';
232
+ /** Campaign provider literals. */
233
+ type CampaignProvider = 'whatsapp';
234
+ /** WhatsApp template component structure. */
235
+ interface WhatsAppTemplateComponent {
236
+ type: string;
237
+ parameters: {
238
+ type: string;
239
+ text?: string;
240
+ }[];
241
+ }
242
+ /** WhatsApp payload used when dispatching campaign messages. */
243
+ interface WhatsAppPayload {
244
+ template: {
6
245
  name: string;
7
- hostname: string;
8
- crm_code: string;
9
- token: string;
246
+ components: WhatsAppTemplateComponent[];
247
+ language: string;
10
248
  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;
249
+ category: string;
250
+ id: string;
20
251
  };
252
+ templateOptions: {
253
+ buttonsVariablesValues?: (string | null)[] | null;
254
+ bodyVariablesValues?: string[];
255
+ headerVariablesValues?: string[];
256
+ headerFileInfos?: {
257
+ filename: string;
258
+ fileUrl: string;
259
+ parsedFilename: string;
260
+ };
261
+ };
262
+ }
263
+ /** Contact filter applied when adding contacts to a campaign. */
264
+ interface CampaignContactFilter {
265
+ excludeDeclinedMarketing?: boolean;
266
+ }
267
+ /** Schedule configuration for a campaign. */
268
+ interface CampaignSchedule {
269
+ startAt?: string;
270
+ repeat?: {
271
+ delay?: number;
272
+ count?: number;
273
+ until?: string;
274
+ };
275
+ }
276
+ /** Campaign entity returned by the Campaigns API. */
277
+ interface Campaign {
278
+ id: string;
279
+ sid: number;
280
+ companyId: string;
281
+ createdBy: string;
282
+ assignedTo: string;
283
+ name?: string;
284
+ provider: CampaignProvider;
285
+ providerId: number;
286
+ providerConfigId: string;
287
+ associatedRuleId?: string;
288
+ payload: WhatsAppPayload;
289
+ conversionRuleIds: string[];
290
+ status: CampaignStatus;
291
+ expiresAt?: string;
292
+ createdAt: string;
293
+ updatedAt: string;
294
+ failedCampaignAttempts: number;
295
+ queuedCampaignAttempts: number;
296
+ deliveredCampaignAttempts: number;
297
+ convertedCampaignAttempts: number;
298
+ categoryId?: number;
299
+ contactFilter?: CampaignContactFilter;
300
+ schedule?: CampaignSchedule;
301
+ }
302
+ /** Paginated response returned by the Campaigns API for list endpoints. */
303
+ interface CampaignPaginatedResponse {
304
+ total: number;
305
+ limit: number;
306
+ skip: number;
307
+ data: Campaign[];
308
+ }
309
+ /** Request payload for creating a campaign. */
310
+ interface CreateCampaignRequest {
311
+ name: string;
312
+ payload: WhatsAppPayload;
313
+ provider: CampaignProvider;
314
+ companyId: string;
315
+ createdBy: string;
316
+ providerId: number;
317
+ providerConfigId: string;
318
+ schedule: CampaignSchedule;
319
+ associatedRuleId?: string;
320
+ assignedTo?: string;
321
+ expiresAt?: string;
322
+ }
323
+ /** Request payload for updating a campaign. */
324
+ interface PatchCampaignRequest {
325
+ name?: string;
326
+ expiresAt?: string;
327
+ status?: CampaignStatus;
328
+ categoryId?: number;
329
+ contactFilter?: CampaignContactFilter;
330
+ }
331
+ /** Query parameters for listing campaigns. */
332
+ interface CampaignQueryParams {
333
+ companyId?: string;
334
+ status?: CampaignStatus;
335
+ createdBy?: string;
336
+ assignedTo?: string;
337
+ name?: string;
338
+ limit?: number;
339
+ skip?: number;
21
340
  }
22
341
 
23
- declare class CustomerServiceGateway {
342
+ /**
343
+ * Gateway for interacting with the Campaigns API.
344
+ */
345
+ declare class CampaignsGateway {
24
346
  private readonly httpClient;
25
347
  private readonly baseUrl;
26
348
  constructor(httpClient: AxiosInstance, baseUrl: string);
27
- getCompanyById(companyId: string): Promise<CompanyResponse>;
349
+ /**
350
+ * Retrieves a paginated list of campaigns.
351
+ * @param query - Optional query parameters for filtering and pagination.
352
+ * @returns The paginated campaigns response.
353
+ */
354
+ find(query?: CampaignQueryParams): Promise<CampaignPaginatedResponse>;
355
+ /**
356
+ * Retrieves a campaign by its unique identifier.
357
+ * @param id - The unique identifier of the campaign.
358
+ * @returns The campaign data.
359
+ */
360
+ get(id: string): Promise<Campaign>;
361
+ /**
362
+ * Creates a new campaign.
363
+ * @param payload - The campaign data to create.
364
+ * @returns The created campaign.
365
+ */
366
+ create(payload: CreateCampaignRequest): Promise<Campaign>;
367
+ /**
368
+ * Partially updates an existing campaign.
369
+ * @param id - The unique identifier of the campaign.
370
+ * @param payload - The fields to update.
371
+ * @returns The updated campaign.
372
+ */
373
+ patch(id: string, payload: PatchCampaignRequest): Promise<Campaign>;
374
+ /**
375
+ * Removes a campaign by its unique identifier.
376
+ * @param id - The unique identifier of the campaign.
377
+ * @returns The removed campaign.
378
+ */
379
+ remove(id: string): Promise<Campaign>;
28
380
  }
29
381
 
382
+ /**
383
+ * Maps service identifiers to their corresponding gateway types.
384
+ * Used by the `gateway()` function to infer the correct return type
385
+ * based on the service name passed as argument.
386
+ *
387
+ * When adding a new service, add an entry here with the service
388
+ * identifier as the key and the gateway class as the value.
389
+ */
390
+ type GatewayMap = {
391
+ 'customer-service': CustomerServiceGateway;
392
+ 'chat-config': ChatConfigGateway;
393
+ 'campaigns': CampaignsGateway;
394
+ };
395
+ /**
396
+ * Parameters required to configure the SDK client.
397
+ * Each service configuration is optional, only provide the services you need.
398
+ */
30
399
  interface GatewayClientParams {
400
+ /** An Axios instance used as the HTTP client for all gateway requests. */
31
401
  axiosClient: AxiosInstance;
402
+ /** API token used for authentication across all services. */
32
403
  apiToken: string;
404
+ /** Configuration for each service gateway. Only the services you configure will be available. */
33
405
  services: {
34
- customerService: {
406
+ customerService?: {
407
+ baseUrl: string;
408
+ };
409
+ chatConfig?: {
410
+ baseUrl: string;
411
+ };
412
+ campaigns?: {
35
413
  baseUrl: string;
36
414
  };
37
415
  };
38
416
  }
39
417
 
40
- declare enum SERVICE_GATEWAYS {
41
- CUSTOMER_SERVICE = "customer-service"
42
- }
43
-
418
+ /**
419
+ * Initializes the SDK with the required configuration parameters.
420
+ * Must be called before using {@link gateway}.
421
+ */
44
422
  declare const configure: (params: GatewayClientParams) => void;
45
- declare const gateway: (service: SERVICE_GATEWAYS) => CustomerServiceGateway;
423
+ /**
424
+ * Returns the gateway instance for the specified service.
425
+ *
426
+ * @typeParam T - A service identifier key from {@link GatewayMap}.
427
+ * @param service - The service identifier (e.g. `SERVICE_GATEWAYS.CUSTOMER_SERVICE`).
428
+ * @returns The corresponding gateway instance with all its methods.
429
+ * @throws {Error} If the SDK has not been configured via {@link configure}.
430
+ * @throws {Error} If an unknown service identifier is provided.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * configure({ axiosClient, apiToken: '...', services: { customerService: { baseUrl: '...' } } });
435
+ * const customer = gateway('customer-service');
436
+ * const company = await customer.getCompanyById('123');
437
+ * ```
438
+ */
439
+ declare function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];
46
440
 
47
- export { configure, gateway };
441
+ export { type Campaign, type CampaignContactFilter, type CampaignPaginatedResponse, type CampaignProvider, type CampaignQueryParams, type CampaignSchedule, type CampaignStatus, type CompanyData, type CompanyResponse, type Config, type ConfigListByProviderResponse, type ConfigProvider, type CreateCampaignRequest, type DistributionType, type GetConfigsByProviderParams, type PatchCampaignRequest, type Provider, type ProviderListResponse, type Queue, type QueueMember, type WhatsAppPayload, type WhatsAppTemplateComponent, type WorkGroup, type WorkGroupListResponse, type WorkGroupMember, type WorkGroupMembersResponse, type WorkGroupResponse, configure, gateway };
package/dist/index.js CHANGED
@@ -33,25 +33,184 @@ 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
+ * Retrieves a queue by its ID.
121
+ * @param queueId - The unique identifier of the queue.
122
+ * @returns The queue data.
123
+ */
124
+ async getQueueById(queueId) {
125
+ const { data } = await this.httpClient.get(`${this.baseUrl}/queue/${queueId}`);
126
+ return data;
127
+ }
128
+ };
129
+
130
+ // src/campaigns/index.ts
131
+ var CampaignsGateway = class {
132
+ constructor(httpClient, baseUrl) {
133
+ this.httpClient = httpClient;
134
+ this.baseUrl = baseUrl;
135
+ }
136
+ httpClient;
137
+ baseUrl;
138
+ /**
139
+ * Retrieves a paginated list of campaigns.
140
+ * @param query - Optional query parameters for filtering and pagination.
141
+ * @returns The paginated campaigns response.
142
+ */
143
+ async find(query) {
144
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns`, {
145
+ params: query
146
+ });
147
+ return data;
148
+ }
149
+ /**
150
+ * Retrieves a campaign by its unique identifier.
151
+ * @param id - The unique identifier of the campaign.
152
+ * @returns The campaign data.
153
+ */
154
+ async get(id) {
155
+ const { data } = await this.httpClient.get(`${this.baseUrl}/campaigns/${id}`);
156
+ return data;
157
+ }
158
+ /**
159
+ * Creates a new campaign.
160
+ * @param payload - The campaign data to create.
161
+ * @returns The created campaign.
162
+ */
163
+ async create(payload) {
164
+ const { data } = await this.httpClient.post(`${this.baseUrl}/campaigns`, payload);
165
+ return data;
166
+ }
167
+ /**
168
+ * Partially updates an existing campaign.
169
+ * @param id - The unique identifier of the campaign.
170
+ * @param payload - The fields to update.
171
+ * @returns The updated campaign.
172
+ */
173
+ async patch(id, payload) {
174
+ const { data } = await this.httpClient.patch(`${this.baseUrl}/campaigns/${id}`, payload);
175
+ return data;
176
+ }
177
+ /**
178
+ * Removes a campaign by its unique identifier.
179
+ * @param id - The unique identifier of the campaign.
180
+ * @returns The removed campaign.
181
+ */
182
+ async remove(id) {
183
+ const { data } = await this.httpClient.delete(`${this.baseUrl}/campaigns/${id}`);
184
+ return data;
185
+ }
40
186
  };
41
187
 
42
188
  // src/@common/client.ts
43
189
  var SDKGateways = class {
44
190
  customerService;
45
- constructor(customerService) {
191
+ chatConfig;
192
+ campaigns;
193
+ constructor(customerService, chatConfig, campaigns) {
46
194
  this.customerService = customerService;
195
+ this.chatConfig = chatConfig;
196
+ this.campaigns = campaigns;
47
197
  }
48
198
  };
49
199
  function createClient(params) {
50
200
  const httpClient = params.axiosClient;
51
- const customerService = new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl);
52
- return new SDKGateways(customerService);
201
+ const customerService = params.services.customerService ? new CustomerServiceGateway(httpClient, params.services.customerService.baseUrl) : null;
202
+ const chatConfig = params.services.chatConfig ? new ChatConfigGateway(httpClient, params.services.chatConfig.baseUrl) : null;
203
+ const campaigns = params.services.campaigns ? new CampaignsGateway(httpClient, params.services.campaigns.baseUrl) : null;
204
+ return new SDKGateways(customerService, chatConfig, campaigns);
53
205
  }
54
206
 
207
+ // src/@common/enums.ts
208
+ var SERVICE_GATEWAYS = {
209
+ CUSTOMER_SERVICE: "customer-service",
210
+ CHAT_CONFIG: "chat-config",
211
+ CAMPAIGNS: "campaigns"
212
+ };
213
+
55
214
  // src/index.ts
56
215
  var SDK = class {
57
216
  client = null;
@@ -63,18 +222,28 @@ var sdk = new SDK();
63
222
  var configure = (params) => {
64
223
  sdk.configure(params);
65
224
  };
66
- var gateway = (service) => {
225
+ function gateway(service) {
67
226
  if (!sdk.client)
68
227
  throw new Error(
69
228
  "SDK not configured. Please call configure() with the appropriate parameters before using the SDK."
70
229
  );
71
230
  switch (service) {
72
- case "customer-service" /* CUSTOMER_SERVICE */:
231
+ case SERVICE_GATEWAYS.CUSTOMER_SERVICE:
232
+ if (!sdk.client.customerService)
233
+ throw new Error(`Service 'customer-service' is not configured. Provide its baseUrl in configure().`);
73
234
  return sdk.client.customerService;
235
+ case SERVICE_GATEWAYS.CHAT_CONFIG:
236
+ if (!sdk.client.chatConfig)
237
+ throw new Error(`Service 'chat-config' is not configured. Provide its baseUrl in configure().`);
238
+ return sdk.client.chatConfig;
239
+ case SERVICE_GATEWAYS.CAMPAIGNS:
240
+ if (!sdk.client.campaigns)
241
+ throw new Error(`Service 'campaigns' is not configured. Provide its baseUrl in configure().`);
242
+ return sdk.client.campaigns;
74
243
  default:
75
244
  throw new Error(`Unknown service gateway: ${service}`);
76
245
  }
77
- };
246
+ }
78
247
  // Annotate the CommonJS export names for ESM import in node:
79
248
  0 && (module.exports = {
80
249
  configure,