@opens/gateways 1.1.0 → 1.2.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.mts CHANGED
@@ -225,6 +225,9 @@ declare class ChatConfigGateway {
225
225
  * @returns The queue data.
226
226
  */
227
227
  getQueueById(queueId: string): Promise<Queue>;
228
+ getQueues(params: {
229
+ id: string[] | string;
230
+ }): Promise<Queue[]>;
228
231
  }
229
232
 
230
233
  /** Campaign status literals. */
@@ -338,6 +341,10 @@ interface CampaignQueryParams {
338
341
  limit?: number;
339
342
  skip?: number;
340
343
  }
344
+ interface User {
345
+ id: string;
346
+ name: string;
347
+ }
341
348
 
342
349
  /**
343
350
  * Gateway for interacting with the Campaigns API.
@@ -377,6 +384,7 @@ declare class CampaignsGateway {
377
384
  * @returns The removed campaign.
378
385
  */
379
386
  remove(id: string): Promise<Campaign>;
387
+ getUsers(): Promise<User[]>;
380
388
  }
381
389
 
382
390
  /**
@@ -438,4 +446,4 @@ declare const configure: (params: GatewayClientParams) => void;
438
446
  */
439
447
  declare function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];
440
448
 
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 };
449
+ 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 User, type WhatsAppPayload, type WhatsAppTemplateComponent, type WorkGroup, type WorkGroupListResponse, type WorkGroupMember, type WorkGroupMembersResponse, type WorkGroupResponse, configure, gateway };
package/dist/index.d.ts CHANGED
@@ -225,6 +225,9 @@ declare class ChatConfigGateway {
225
225
  * @returns The queue data.
226
226
  */
227
227
  getQueueById(queueId: string): Promise<Queue>;
228
+ getQueues(params: {
229
+ id: string[] | string;
230
+ }): Promise<Queue[]>;
228
231
  }
229
232
 
230
233
  /** Campaign status literals. */
@@ -338,6 +341,10 @@ interface CampaignQueryParams {
338
341
  limit?: number;
339
342
  skip?: number;
340
343
  }
344
+ interface User {
345
+ id: string;
346
+ name: string;
347
+ }
341
348
 
342
349
  /**
343
350
  * Gateway for interacting with the Campaigns API.
@@ -377,6 +384,7 @@ declare class CampaignsGateway {
377
384
  * @returns The removed campaign.
378
385
  */
379
386
  remove(id: string): Promise<Campaign>;
387
+ getUsers(): Promise<User[]>;
380
388
  }
381
389
 
382
390
  /**
@@ -438,4 +446,4 @@ declare const configure: (params: GatewayClientParams) => void;
438
446
  */
439
447
  declare function gateway<T extends keyof GatewayMap>(service: T): GatewayMap[T];
440
448
 
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 };
449
+ 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 User, type WhatsAppPayload, type WhatsAppTemplateComponent, type WorkGroup, type WorkGroupListResponse, type WorkGroupMember, type WorkGroupMembersResponse, type WorkGroupResponse, configure, gateway };
package/dist/index.js CHANGED
@@ -125,6 +125,10 @@ var ChatConfigGateway = class {
125
125
  const { data } = await this.httpClient.get(`${this.baseUrl}/queue/${queueId}`);
126
126
  return data;
127
127
  }
128
+ async getQueues(params) {
129
+ const { data } = await this.httpClient.get(`${this.baseUrl}/queues`, { params });
130
+ return data;
131
+ }
128
132
  };
129
133
 
130
134
  // src/campaigns/index.ts
@@ -183,6 +187,10 @@ var CampaignsGateway = class {
183
187
  const { data } = await this.httpClient.delete(`${this.baseUrl}/campaigns/${id}`);
184
188
  return data;
185
189
  }
190
+ async getUsers() {
191
+ const { data } = await this.httpClient.get(`${this.baseUrl}/users`);
192
+ return data;
193
+ }
186
194
  };
187
195
 
188
196
  // src/@common/client.ts
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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\nexport * from './campaigns/contracts';\nexport * from './chat-config/contracts';\nexport * from './customer-service/contracts';\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';\nimport { Queue } from './contracts/queues';\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(\n providerId: string,\n params?: GetConfigsByProviderParams,\n ): 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 /**\n * Retrieves a queue by its ID.\n * @param queueId - The unique identifier of the queue.\n * @returns The queue data.\n */\n async getQueueById(queueId: string): Promise<Queue> {\n const { data } = await this.httpClient.get<Queue>(`${this.baseUrl}/queue/${queueId}`);\n return data;\n }\n}\n\nexport type { Queue, QueueMember, DistributionType } from './contracts/queues';\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type {\n ConfigListByProviderResponse,\n Config,\n ConfigProvider,\n GetConfigsByProviderParams,\n} from './contracts/config';\n","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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AI,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":[]}
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\nexport * from './campaigns/contracts';\nexport * from './chat-config/contracts';\nexport * from './customer-service/contracts';\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';\nimport { Queue } from './contracts/queues';\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(\n providerId: string,\n params?: GetConfigsByProviderParams,\n ): 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 /**\n * Retrieves a queue by its ID.\n * @param queueId - The unique identifier of the queue.\n * @returns The queue data.\n */\n async getQueueById(queueId: string): Promise<Queue> {\n const { data } = await this.httpClient.get<Queue>(`${this.baseUrl}/queue/${queueId}`);\n return data;\n }\n\n async getQueues(params: { id: string[] | string }): Promise<Queue[]> {\n const { data } = await this.httpClient.get<Queue[]>(`${this.baseUrl}/queues`, { params });\n return data;\n }\n}\n\nexport type { Queue, QueueMember, DistributionType } from './contracts/queues';\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type {\n ConfigListByProviderResponse,\n Config,\n ConfigProvider,\n GetConfigsByProviderParams,\n} from './contracts/config';\n","import type { AxiosInstance } from 'axios';\nimport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CreateCampaignRequest,\n PatchCampaignRequest,\n User,\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 async getUsers() {\n const { data } = await this.httpClient.get<User[]>(`${this.baseUrl}/users`);\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 User,\n} from './contracts/campaign';\n","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,WA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AC,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
@@ -98,6 +98,10 @@ var ChatConfigGateway = class {
98
98
  const { data } = await this.httpClient.get(`${this.baseUrl}/queue/${queueId}`);
99
99
  return data;
100
100
  }
101
+ async getQueues(params) {
102
+ const { data } = await this.httpClient.get(`${this.baseUrl}/queues`, { params });
103
+ return data;
104
+ }
101
105
  };
102
106
 
103
107
  // src/campaigns/index.ts
@@ -156,6 +160,10 @@ var CampaignsGateway = class {
156
160
  const { data } = await this.httpClient.delete(`${this.baseUrl}/campaigns/${id}`);
157
161
  return data;
158
162
  }
163
+ async getUsers() {
164
+ const { data } = await this.httpClient.get(`${this.baseUrl}/users`);
165
+ return data;
166
+ }
159
167
  };
160
168
 
161
169
  // src/@common/client.ts
@@ -1 +1 @@
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';\nimport { Queue } from './contracts/queues';\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(\n providerId: string,\n params?: GetConfigsByProviderParams,\n ): 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 /**\n * Retrieves a queue by its ID.\n * @param queueId - The unique identifier of the queue.\n * @returns The queue data.\n */\n async getQueueById(queueId: string): Promise<Queue> {\n const { data } = await this.httpClient.get<Queue>(`${this.baseUrl}/queue/${queueId}`);\n return data;\n }\n}\n\nexport type { Queue, QueueMember, DistributionType } from './contracts/queues';\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type {\n ConfigListByProviderResponse,\n Config,\n ConfigProvider,\n GetConfigsByProviderParams,\n} from './contracts/config';\n","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\nexport * from './campaigns/contracts';\nexport * from './chat-config/contracts';\nexport * from './customer-service/contracts';\n"],"mappings":";AAOO,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,EA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A8E;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":[]}
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';\nimport { Queue } from './contracts/queues';\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(\n providerId: string,\n params?: GetConfigsByProviderParams,\n ): 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 /**\n * Retrieves a queue by its ID.\n * @param queueId - The unique identifier of the queue.\n * @returns The queue data.\n */\n async getQueueById(queueId: string): Promise<Queue> {\n const { data } = await this.httpClient.get<Queue>(`${this.baseUrl}/queue/${queueId}`);\n return data;\n }\n\n async getQueues(params: { id: string[] | string }): Promise<Queue[]> {\n const { data } = await this.httpClient.get<Queue[]>(`${this.baseUrl}/queues`, { params });\n return data;\n }\n}\n\nexport type { Queue, QueueMember, DistributionType } from './contracts/queues';\nexport type { ProviderListResponse, Provider } from './contracts/provider';\nexport type {\n ConfigListByProviderResponse,\n Config,\n ConfigProvider,\n GetConfigsByProviderParams,\n} from './contracts/config';\n","import type { AxiosInstance } from 'axios';\nimport type {\n Campaign,\n CampaignPaginatedResponse,\n CampaignQueryParams,\n CreateCampaignRequest,\n PatchCampaignRequest,\n User,\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 async getUsers() {\n const { data } = await this.httpClient.get<User[]>(`${this.baseUrl}/users`);\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 User,\n} from './contracts/campaign';\n","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\nexport * from './campaigns/contracts';\nexport * from './chat-config/contracts';\nexport * from './customer-service/contracts';\n"],"mappings":";AAOO,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;AAAA,EAQA,MAAM,iBAAiB,aAAqB,WAAgD;AAC1F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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.1.0",
2
+ "version": "1.2.0",
3
3
  "description": "A simple package to help with some common tasks",
4
4
  "name": "@opens/gateways",
5
5
  "private": false,