@thisispamela/sdk 1.0.3 → 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/README.md +2 -0
- package/dist/chunk-IKGLZFM6.mjs +38 -0
- package/dist/chunk-IKGLZFM6.mjs.map +1 -0
- package/dist/chunk-NQIPPPEL.mjs +50 -0
- package/dist/chunk-NQIPPPEL.mjs.map +1 -0
- package/dist/chunk-WMXO6YYV.mjs +50 -0
- package/dist/chunk-WMXO6YYV.mjs.map +1 -0
- package/dist/errors.d.mts +47 -0
- package/dist/errors.d.ts +8 -6
- package/dist/errors.js +78 -47
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +17 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.ts +19 -67
- package/dist/index.js +315 -193
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +170 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.mts +99 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.js +74 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +7 -0
- package/dist/types.mjs.map +1 -0
- package/dist/webhooks.d.mts +12 -0
- package/dist/webhooks.d.ts +12 -0
- package/dist/webhooks.js +73 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/webhooks.mjs +9 -0
- package/dist/webhooks.mjs.map +1 -0
- package/package.json +28 -4
- package/src/index.ts +17 -82
- package/src/types.ts +126 -0
- package/src/webhooks.ts +55 -0
- package/tsup.config.ts +10 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticationError,
|
|
3
|
+
CallError,
|
|
4
|
+
PamelaError,
|
|
5
|
+
RateLimitError,
|
|
6
|
+
SubscriptionError,
|
|
7
|
+
ValidationError
|
|
8
|
+
} from "./chunk-NQIPPPEL.mjs";
|
|
9
|
+
import {
|
|
10
|
+
ErrorCodes
|
|
11
|
+
} from "./chunk-WMXO6YYV.mjs";
|
|
12
|
+
import {
|
|
13
|
+
parseToolWebhook,
|
|
14
|
+
verifyWebhookSignature
|
|
15
|
+
} from "./chunk-IKGLZFM6.mjs";
|
|
16
|
+
|
|
17
|
+
// src/index.ts
|
|
18
|
+
import axios from "axios";
|
|
19
|
+
var mapAxiosError = (error, endpoint) => {
|
|
20
|
+
const statusCode = error.response?.status;
|
|
21
|
+
const data = error.response?.data;
|
|
22
|
+
let errorCode;
|
|
23
|
+
let message;
|
|
24
|
+
let details;
|
|
25
|
+
if (data && typeof data === "object") {
|
|
26
|
+
const detail = data.detail;
|
|
27
|
+
if (detail && typeof detail === "object") {
|
|
28
|
+
errorCode = detail.error_code ?? detail.error?.code;
|
|
29
|
+
message = detail.message ?? detail.error?.message;
|
|
30
|
+
details = detail.details ?? detail.error?.details;
|
|
31
|
+
} else {
|
|
32
|
+
errorCode = data.error_code ?? data.error?.code;
|
|
33
|
+
message = data.message ?? data.detail;
|
|
34
|
+
details = data.details ?? data.error?.details;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!message) {
|
|
38
|
+
message = error.message || "Request failed";
|
|
39
|
+
}
|
|
40
|
+
const options = { errorCode, details, statusCode };
|
|
41
|
+
if (statusCode === 401) return new AuthenticationError(message, options);
|
|
42
|
+
if (statusCode === 403) return new SubscriptionError(message, options);
|
|
43
|
+
if (statusCode === 429) return new RateLimitError(message, options);
|
|
44
|
+
if (statusCode === 400 || statusCode === 422) return new ValidationError(message, options);
|
|
45
|
+
if (endpoint?.startsWith("/calls")) {
|
|
46
|
+
return new CallError(message, options);
|
|
47
|
+
}
|
|
48
|
+
return new PamelaError(message, options);
|
|
49
|
+
};
|
|
50
|
+
var UsageClient = class {
|
|
51
|
+
constructor(client) {
|
|
52
|
+
this.client = client;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get usage statistics for partner/project.
|
|
56
|
+
*/
|
|
57
|
+
async get(period) {
|
|
58
|
+
const params = period ? { period } : {};
|
|
59
|
+
const response = await this.client.get("/usage", { params });
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var PamelaClient = class {
|
|
64
|
+
constructor(config) {
|
|
65
|
+
this.apiKey = config.apiKey;
|
|
66
|
+
const baseURL = config.baseUrl || "https://api.thisispamela.com";
|
|
67
|
+
this.client = axios.create({
|
|
68
|
+
baseURL: `${baseURL}/api/b2b/v1`,
|
|
69
|
+
headers: {
|
|
70
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
71
|
+
"Content-Type": "application/json"
|
|
72
|
+
},
|
|
73
|
+
timeout: 3e4
|
|
74
|
+
});
|
|
75
|
+
this.usage = new UsageClient(this.client);
|
|
76
|
+
this.client.interceptors.response.use(
|
|
77
|
+
(response) => response,
|
|
78
|
+
async (error) => {
|
|
79
|
+
const config2 = error.config;
|
|
80
|
+
if (!config2 || !config2.retry) {
|
|
81
|
+
config2.retry = 0;
|
|
82
|
+
}
|
|
83
|
+
config2.retry += 1;
|
|
84
|
+
if (config2.retry <= 3 && error.response?.status && error.response.status >= 500) {
|
|
85
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * config2.retry));
|
|
86
|
+
return this.client.request(config2);
|
|
87
|
+
}
|
|
88
|
+
return Promise.reject(mapAxiosError(error, config2?.url));
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a new call.
|
|
94
|
+
*/
|
|
95
|
+
async createCall(request) {
|
|
96
|
+
const response = await this.client.post("/calls", request);
|
|
97
|
+
return response.data;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get call status and details.
|
|
101
|
+
*/
|
|
102
|
+
async getCall(callId) {
|
|
103
|
+
const response = await this.client.get(`/calls/${callId}`);
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* List calls for the authenticated partner/project.
|
|
108
|
+
*/
|
|
109
|
+
async listCalls(params) {
|
|
110
|
+
const normalizedParams = { ...params };
|
|
111
|
+
if (params?.status_filter || params?.status) {
|
|
112
|
+
normalizedParams.status_filter = params?.status_filter ?? params?.status;
|
|
113
|
+
delete normalizedParams.status;
|
|
114
|
+
}
|
|
115
|
+
const response = await this.client.get("/calls", { params: normalizedParams });
|
|
116
|
+
return response.data;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Cancel an in-progress call.
|
|
120
|
+
*/
|
|
121
|
+
async cancelCall(callId) {
|
|
122
|
+
const response = await this.client.post(`/calls/${callId}/cancel`);
|
|
123
|
+
return response.data;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Force hangup an in-progress call.
|
|
127
|
+
*/
|
|
128
|
+
async hangupCall(callId) {
|
|
129
|
+
const response = await this.client.post(`/calls/${callId}/hangup`);
|
|
130
|
+
return response.data;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Register a tool.
|
|
134
|
+
*/
|
|
135
|
+
async registerTool(tool) {
|
|
136
|
+
const response = await this.client.post("/tools", { tool });
|
|
137
|
+
return response.data;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* List all tools for the project.
|
|
141
|
+
*/
|
|
142
|
+
async listTools() {
|
|
143
|
+
const response = await this.client.get("/tools");
|
|
144
|
+
return response.data;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Delete a tool.
|
|
148
|
+
*/
|
|
149
|
+
async deleteTool(toolId) {
|
|
150
|
+
const response = await this.client.delete(`/tools/${toolId}`);
|
|
151
|
+
return response.data;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var index_default = PamelaClient;
|
|
155
|
+
export {
|
|
156
|
+
AuthenticationError,
|
|
157
|
+
CallError,
|
|
158
|
+
ErrorCodes,
|
|
159
|
+
PamelaClient as Pamela,
|
|
160
|
+
PamelaClient,
|
|
161
|
+
PamelaError,
|
|
162
|
+
RateLimitError,
|
|
163
|
+
SubscriptionError,
|
|
164
|
+
UsageClient,
|
|
165
|
+
ValidationError,
|
|
166
|
+
index_default as default,
|
|
167
|
+
parseToolWebhook,
|
|
168
|
+
verifyWebhookSignature
|
|
169
|
+
};
|
|
170
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Pamela Enterprise Voice API SDK for JavaScript/TypeScript\n */\n\nimport axios, { AxiosInstance, AxiosError } from 'axios';\nimport {\n PamelaError,\n AuthenticationError,\n SubscriptionError,\n RateLimitError,\n ValidationError,\n CallError,\n} from './errors';\nimport type {\n PamelaClientConfig,\n CreateCallRequest,\n CallResponse,\n CallStatus,\n ToolDefinition,\n} from './types';\n\nconst mapAxiosError = (error: AxiosError, endpoint?: string): PamelaError => {\n const statusCode = error.response?.status;\n const data = error.response?.data as any;\n let errorCode: number | undefined;\n let message: string | undefined;\n let details: Record<string, any> | undefined;\n\n if (data && typeof data === 'object') {\n const detail = data.detail;\n if (detail && typeof detail === 'object') {\n errorCode = detail.error_code ?? detail.error?.code;\n message = detail.message ?? detail.error?.message;\n details = detail.details ?? detail.error?.details;\n } else {\n errorCode = data.error_code ?? data.error?.code;\n message = data.message ?? data.detail;\n details = data.details ?? data.error?.details;\n }\n }\n\n if (!message) {\n message = error.message || 'Request failed';\n }\n\n const options = { errorCode, details, statusCode };\n if (statusCode === 401) return new AuthenticationError(message, options);\n if (statusCode === 403) return new SubscriptionError(message, options);\n if (statusCode === 429) return new RateLimitError(message, options);\n if (statusCode === 400 || statusCode === 422) return new ValidationError(message, options);\n\n if (endpoint?.startsWith('/calls')) {\n return new CallError(message, options);\n }\n\n return new PamelaError(message, options);\n};\n\nexport class UsageClient {\n private client: AxiosInstance;\n\n constructor(client: AxiosInstance) {\n this.client = client;\n }\n\n /**\n * Get usage statistics for partner/project.\n */\n async get(period?: string): Promise<{\n partner_id: string;\n project_id?: string;\n period: string;\n call_count: number;\n last_updated?: string;\n quota?: {\n partner_limit?: number;\n project_limit?: number;\n };\n }> {\n const params = period ? { period } : {};\n const response = await this.client.get('/usage', { params });\n return response.data;\n }\n}\n\nexport class PamelaClient {\n private client: AxiosInstance;\n private apiKey: string;\n public usage: UsageClient;\n\n constructor(config: PamelaClientConfig) {\n this.apiKey = config.apiKey;\n const baseURL = config.baseUrl || 'https://api.thisispamela.com';\n \n this.client = axios.create({\n baseURL: `${baseURL}/api/b2b/v1`,\n headers: {\n 'Authorization': `Bearer ${this.apiKey}`,\n 'Content-Type': 'application/json',\n },\n timeout: 30000,\n });\n\n // Initialize usage client\n this.usage = new UsageClient(this.client);\n\n // Add retry logic\n this.client.interceptors.response.use(\n (response) => response,\n async (error: AxiosError) => {\n const config = error.config as any;\n if (!config || !config.retry) {\n config.retry = 0;\n }\n config.retry += 1;\n\n if (config.retry <= 3 && error.response?.status && error.response.status >= 500) {\n await new Promise(resolve => setTimeout(resolve, 1000 * config.retry));\n return this.client.request(config);\n }\n\n return Promise.reject(mapAxiosError(error, config?.url));\n }\n );\n }\n\n /**\n * Create a new call.\n */\n async createCall(request: CreateCallRequest): Promise<CallResponse> {\n const response = await this.client.post<CallResponse>('/calls', request);\n return response.data;\n }\n\n /**\n * Get call status and details.\n */\n async getCall(callId: string): Promise<CallStatus> {\n const response = await this.client.get<CallStatus>(`/calls/${callId}`);\n return response.data;\n }\n\n /**\n * List calls for the authenticated partner/project.\n */\n async listCalls(params?: {\n status?: string;\n status_filter?: string;\n limit?: number;\n offset?: number;\n start_date?: string;\n end_date?: string;\n }): Promise<{ items: CallStatus[]; total: number; limit: number; offset: number }> {\n const normalizedParams = { ...params };\n if (params?.status_filter || params?.status) {\n normalizedParams.status_filter = params?.status_filter ?? params?.status;\n delete (normalizedParams as { status?: string }).status;\n }\n const response = await this.client.get('/calls', { params: normalizedParams });\n // Backend returns { items: [...], total, limit, offset }\n return response.data;\n }\n\n /**\n * Cancel an in-progress call.\n */\n async cancelCall(callId: string): Promise<{ success: boolean; call_id: string; status: string }> {\n const response = await this.client.post(`/calls/${callId}/cancel`);\n return response.data;\n }\n\n /**\n * Force hangup an in-progress call.\n */\n async hangupCall(callId: string): Promise<{ success: boolean; call_id: string; status: string }> {\n const response = await this.client.post(`/calls/${callId}/hangup`);\n return response.data;\n }\n\n /**\n * Register a tool.\n */\n async registerTool(tool: ToolDefinition): Promise<{ id: string; project_id: string; name: string; description: string; input_schema: Record<string, any>; output_schema: Record<string, any>; timeout_ms: number; created_at: string }> {\n const response = await this.client.post('/tools', { tool });\n return response.data;\n }\n\n /**\n * List all tools for the project.\n */\n async listTools(): Promise<Array<{ id: string; project_id: string; name: string; description: string; input_schema: Record<string, any>; output_schema: Record<string, any>; timeout_ms: number; created_at: string }>> {\n const response = await this.client.get('/tools');\n return response.data;\n }\n\n /**\n * Delete a tool.\n */\n async deleteTool(toolId: string): Promise<{ success: boolean; tool_id: string }> {\n const response = await this.client.delete(`/tools/${toolId}`);\n return response.data;\n }\n\n}\n\n// Export as both default and named export for flexibility\nexport default PamelaClient;\nexport { PamelaClient as Pamela };\nexport {\n PamelaError,\n AuthenticationError,\n SubscriptionError,\n RateLimitError,\n ValidationError,\n CallError,\n};\nexport * from './types';\nexport * from './webhooks';\n\n"],"mappings":"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","names":["config"]}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
interface PamelaClientConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
interface CreateCallRequest {
|
|
6
|
+
to: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
task: string;
|
|
10
|
+
instructions?: string;
|
|
11
|
+
max_duration_seconds?: number;
|
|
12
|
+
voice?: 'male' | 'female' | 'auto';
|
|
13
|
+
agent_name?: string;
|
|
14
|
+
caller_name?: string;
|
|
15
|
+
end_user_id?: string;
|
|
16
|
+
metadata?: Record<string, any>;
|
|
17
|
+
tools?: Array<Record<string, any>>;
|
|
18
|
+
webhooks?: {
|
|
19
|
+
webhook_url?: string;
|
|
20
|
+
tool_webhook_url?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
type CallStatusValue = 'initiating' | 'queued' | 'ringing' | 'in_progress' | 'completed' | 'failed' | 'cancelled' | 'timeout_terminated' | 'in-progress';
|
|
24
|
+
interface CallResponse {
|
|
25
|
+
id: string;
|
|
26
|
+
status: CallStatusValue | string;
|
|
27
|
+
call_session_id: string;
|
|
28
|
+
created_at: string;
|
|
29
|
+
}
|
|
30
|
+
interface CallStatus {
|
|
31
|
+
id: string;
|
|
32
|
+
status: CallStatusValue | string;
|
|
33
|
+
to: string;
|
|
34
|
+
from_: string;
|
|
35
|
+
country: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
started_at?: string;
|
|
38
|
+
completed_at?: string;
|
|
39
|
+
duration_seconds?: number;
|
|
40
|
+
max_duration_seconds?: number;
|
|
41
|
+
transcript?: Array<Record<string, any>>;
|
|
42
|
+
summary?: string;
|
|
43
|
+
metadata: Record<string, any>;
|
|
44
|
+
end_user_id?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ToolDefinition {
|
|
47
|
+
name: string;
|
|
48
|
+
description: string;
|
|
49
|
+
input_schema: Record<string, any>;
|
|
50
|
+
output_schema?: Record<string, any>;
|
|
51
|
+
timeout_ms?: number;
|
|
52
|
+
}
|
|
53
|
+
interface WebhookPayload {
|
|
54
|
+
event: string;
|
|
55
|
+
call_id: string;
|
|
56
|
+
call_session_id: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
data: Record<string, any>;
|
|
59
|
+
}
|
|
60
|
+
/** Standard error codes (aligned with backend models/errors.py) */
|
|
61
|
+
declare const ErrorCodes: {
|
|
62
|
+
readonly AUTH_REQUIRED: 1001;
|
|
63
|
+
readonly AUTH_INVALID: 1002;
|
|
64
|
+
readonly AUTH_EXPIRED: 1003;
|
|
65
|
+
readonly AUTH_INSUFFICIENT_PERMISSIONS: 1004;
|
|
66
|
+
readonly AUTH_FORBIDDEN: 1005;
|
|
67
|
+
readonly VALIDATION_ERROR: 2001;
|
|
68
|
+
readonly INVALID_PHONE: 2002;
|
|
69
|
+
readonly INVALID_EMAIL: 2003;
|
|
70
|
+
readonly INVALID_PASSWORD: 2004;
|
|
71
|
+
readonly MISSING_REQUIRED_FIELD: 2005;
|
|
72
|
+
readonly INVALID_JSON: 2006;
|
|
73
|
+
readonly INVALID_REQUEST_BODY: 2007;
|
|
74
|
+
readonly NOT_FOUND: 3001;
|
|
75
|
+
readonly USER_NOT_FOUND: 3002;
|
|
76
|
+
readonly CONVERSATION_NOT_FOUND: 3003;
|
|
77
|
+
readonly CALL_SESSION_NOT_FOUND: 3004;
|
|
78
|
+
readonly RESOURCE_NOT_FOUND: 3005;
|
|
79
|
+
readonly MESSAGE_NOT_FOUND: 3006;
|
|
80
|
+
readonly RESOURCE_ALREADY_EXISTS: 4001;
|
|
81
|
+
readonly EMAIL_ALREADY_REGISTERED: 4002;
|
|
82
|
+
readonly ACCOUNT_LINKING_REQUIRED: 4003;
|
|
83
|
+
readonly INTERNAL_ERROR: 5001;
|
|
84
|
+
readonly EXTERNAL_SERVICE_ERROR: 5002;
|
|
85
|
+
readonly DATABASE_ERROR: 5003;
|
|
86
|
+
readonly CONFIGURATION_ERROR: 5004;
|
|
87
|
+
readonly RATE_LIMIT_EXCEEDED: 6001;
|
|
88
|
+
readonly QUOTA_EXCEEDED: 6002;
|
|
89
|
+
readonly B2B_PARTNER_NOT_FOUND: 7001;
|
|
90
|
+
readonly B2B_PROJECT_NOT_FOUND: 7002;
|
|
91
|
+
readonly B2B_CALL_NOT_FOUND: 7003;
|
|
92
|
+
readonly B2B_NO_PHONE_NUMBER: 7004;
|
|
93
|
+
readonly B2B_UNSUPPORTED_COUNTRY: 7005;
|
|
94
|
+
readonly B2B_TOOL_EXECUTION_FAILED: 7006;
|
|
95
|
+
readonly B2B_WEBHOOK_DELIVERY_FAILED: 7007;
|
|
96
|
+
readonly SUBSCRIPTION_EXPIRED: 7008;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export { type CallResponse, type CallStatus, type CallStatusValue, type CreateCallRequest, ErrorCodes, type PamelaClientConfig, type ToolDefinition, type WebhookPayload };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
interface PamelaClientConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
interface CreateCallRequest {
|
|
6
|
+
to: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
locale?: string;
|
|
9
|
+
task: string;
|
|
10
|
+
instructions?: string;
|
|
11
|
+
max_duration_seconds?: number;
|
|
12
|
+
voice?: 'male' | 'female' | 'auto';
|
|
13
|
+
agent_name?: string;
|
|
14
|
+
caller_name?: string;
|
|
15
|
+
end_user_id?: string;
|
|
16
|
+
metadata?: Record<string, any>;
|
|
17
|
+
tools?: Array<Record<string, any>>;
|
|
18
|
+
webhooks?: {
|
|
19
|
+
webhook_url?: string;
|
|
20
|
+
tool_webhook_url?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
type CallStatusValue = 'initiating' | 'queued' | 'ringing' | 'in_progress' | 'completed' | 'failed' | 'cancelled' | 'timeout_terminated' | 'in-progress';
|
|
24
|
+
interface CallResponse {
|
|
25
|
+
id: string;
|
|
26
|
+
status: CallStatusValue | string;
|
|
27
|
+
call_session_id: string;
|
|
28
|
+
created_at: string;
|
|
29
|
+
}
|
|
30
|
+
interface CallStatus {
|
|
31
|
+
id: string;
|
|
32
|
+
status: CallStatusValue | string;
|
|
33
|
+
to: string;
|
|
34
|
+
from_: string;
|
|
35
|
+
country: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
started_at?: string;
|
|
38
|
+
completed_at?: string;
|
|
39
|
+
duration_seconds?: number;
|
|
40
|
+
max_duration_seconds?: number;
|
|
41
|
+
transcript?: Array<Record<string, any>>;
|
|
42
|
+
summary?: string;
|
|
43
|
+
metadata: Record<string, any>;
|
|
44
|
+
end_user_id?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ToolDefinition {
|
|
47
|
+
name: string;
|
|
48
|
+
description: string;
|
|
49
|
+
input_schema: Record<string, any>;
|
|
50
|
+
output_schema?: Record<string, any>;
|
|
51
|
+
timeout_ms?: number;
|
|
52
|
+
}
|
|
53
|
+
interface WebhookPayload {
|
|
54
|
+
event: string;
|
|
55
|
+
call_id: string;
|
|
56
|
+
call_session_id: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
data: Record<string, any>;
|
|
59
|
+
}
|
|
60
|
+
/** Standard error codes (aligned with backend models/errors.py) */
|
|
61
|
+
declare const ErrorCodes: {
|
|
62
|
+
readonly AUTH_REQUIRED: 1001;
|
|
63
|
+
readonly AUTH_INVALID: 1002;
|
|
64
|
+
readonly AUTH_EXPIRED: 1003;
|
|
65
|
+
readonly AUTH_INSUFFICIENT_PERMISSIONS: 1004;
|
|
66
|
+
readonly AUTH_FORBIDDEN: 1005;
|
|
67
|
+
readonly VALIDATION_ERROR: 2001;
|
|
68
|
+
readonly INVALID_PHONE: 2002;
|
|
69
|
+
readonly INVALID_EMAIL: 2003;
|
|
70
|
+
readonly INVALID_PASSWORD: 2004;
|
|
71
|
+
readonly MISSING_REQUIRED_FIELD: 2005;
|
|
72
|
+
readonly INVALID_JSON: 2006;
|
|
73
|
+
readonly INVALID_REQUEST_BODY: 2007;
|
|
74
|
+
readonly NOT_FOUND: 3001;
|
|
75
|
+
readonly USER_NOT_FOUND: 3002;
|
|
76
|
+
readonly CONVERSATION_NOT_FOUND: 3003;
|
|
77
|
+
readonly CALL_SESSION_NOT_FOUND: 3004;
|
|
78
|
+
readonly RESOURCE_NOT_FOUND: 3005;
|
|
79
|
+
readonly MESSAGE_NOT_FOUND: 3006;
|
|
80
|
+
readonly RESOURCE_ALREADY_EXISTS: 4001;
|
|
81
|
+
readonly EMAIL_ALREADY_REGISTERED: 4002;
|
|
82
|
+
readonly ACCOUNT_LINKING_REQUIRED: 4003;
|
|
83
|
+
readonly INTERNAL_ERROR: 5001;
|
|
84
|
+
readonly EXTERNAL_SERVICE_ERROR: 5002;
|
|
85
|
+
readonly DATABASE_ERROR: 5003;
|
|
86
|
+
readonly CONFIGURATION_ERROR: 5004;
|
|
87
|
+
readonly RATE_LIMIT_EXCEEDED: 6001;
|
|
88
|
+
readonly QUOTA_EXCEEDED: 6002;
|
|
89
|
+
readonly B2B_PARTNER_NOT_FOUND: 7001;
|
|
90
|
+
readonly B2B_PROJECT_NOT_FOUND: 7002;
|
|
91
|
+
readonly B2B_CALL_NOT_FOUND: 7003;
|
|
92
|
+
readonly B2B_NO_PHONE_NUMBER: 7004;
|
|
93
|
+
readonly B2B_UNSUPPORTED_COUNTRY: 7005;
|
|
94
|
+
readonly B2B_TOOL_EXECUTION_FAILED: 7006;
|
|
95
|
+
readonly B2B_WEBHOOK_DELIVERY_FAILED: 7007;
|
|
96
|
+
readonly SUBSCRIPTION_EXPIRED: 7008;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export { type CallResponse, type CallStatus, type CallStatusValue, type CreateCallRequest, ErrorCodes, type PamelaClientConfig, type ToolDefinition, type WebhookPayload };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/types.ts
|
|
21
|
+
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
ErrorCodes: () => ErrorCodes
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(types_exports);
|
|
26
|
+
var ErrorCodes = {
|
|
27
|
+
// Auth errors (1000-1999)
|
|
28
|
+
AUTH_REQUIRED: 1001,
|
|
29
|
+
AUTH_INVALID: 1002,
|
|
30
|
+
AUTH_EXPIRED: 1003,
|
|
31
|
+
AUTH_INSUFFICIENT_PERMISSIONS: 1004,
|
|
32
|
+
AUTH_FORBIDDEN: 1005,
|
|
33
|
+
// Validation errors (2000-2999)
|
|
34
|
+
VALIDATION_ERROR: 2001,
|
|
35
|
+
INVALID_PHONE: 2002,
|
|
36
|
+
INVALID_EMAIL: 2003,
|
|
37
|
+
INVALID_PASSWORD: 2004,
|
|
38
|
+
MISSING_REQUIRED_FIELD: 2005,
|
|
39
|
+
INVALID_JSON: 2006,
|
|
40
|
+
INVALID_REQUEST_BODY: 2007,
|
|
41
|
+
// Not found errors (3000-3999)
|
|
42
|
+
NOT_FOUND: 3001,
|
|
43
|
+
USER_NOT_FOUND: 3002,
|
|
44
|
+
CONVERSATION_NOT_FOUND: 3003,
|
|
45
|
+
CALL_SESSION_NOT_FOUND: 3004,
|
|
46
|
+
RESOURCE_NOT_FOUND: 3005,
|
|
47
|
+
MESSAGE_NOT_FOUND: 3006,
|
|
48
|
+
// Conflict errors (4000-4999)
|
|
49
|
+
RESOURCE_ALREADY_EXISTS: 4001,
|
|
50
|
+
EMAIL_ALREADY_REGISTERED: 4002,
|
|
51
|
+
ACCOUNT_LINKING_REQUIRED: 4003,
|
|
52
|
+
// Server errors (5000-5999)
|
|
53
|
+
INTERNAL_ERROR: 5001,
|
|
54
|
+
EXTERNAL_SERVICE_ERROR: 5002,
|
|
55
|
+
DATABASE_ERROR: 5003,
|
|
56
|
+
CONFIGURATION_ERROR: 5004,
|
|
57
|
+
// Rate limiting (6000-6999)
|
|
58
|
+
RATE_LIMIT_EXCEEDED: 6001,
|
|
59
|
+
QUOTA_EXCEEDED: 6002,
|
|
60
|
+
// B2B errors (7000-7999)
|
|
61
|
+
B2B_PARTNER_NOT_FOUND: 7001,
|
|
62
|
+
B2B_PROJECT_NOT_FOUND: 7002,
|
|
63
|
+
B2B_CALL_NOT_FOUND: 7003,
|
|
64
|
+
B2B_NO_PHONE_NUMBER: 7004,
|
|
65
|
+
B2B_UNSUPPORTED_COUNTRY: 7005,
|
|
66
|
+
B2B_TOOL_EXECUTION_FAILED: 7006,
|
|
67
|
+
B2B_WEBHOOK_DELIVERY_FAILED: 7007,
|
|
68
|
+
SUBSCRIPTION_EXPIRED: 7008
|
|
69
|
+
};
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
ErrorCodes
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface PamelaClientConfig {\n apiKey: string;\n baseUrl?: string;\n}\n\nexport interface CreateCallRequest {\n to: string;\n country?: string;\n locale?: string;\n task: string;\n instructions?: string;\n max_duration_seconds?: number;\n voice?: 'male' | 'female' | 'auto';\n agent_name?: string;\n caller_name?: string;\n end_user_id?: string;\n metadata?: Record<string, any>;\n tools?: Array<Record<string, any>>;\n webhooks?: {\n webhook_url?: string;\n tool_webhook_url?: string;\n };\n}\n\nexport type CallStatusValue =\n | 'initiating'\n | 'queued'\n | 'ringing'\n | 'in_progress'\n | 'completed'\n | 'failed'\n | 'cancelled'\n | 'timeout_terminated'\n | 'in-progress';\n\nexport interface CallResponse {\n id: string;\n status: CallStatusValue | string;\n call_session_id: string;\n created_at: string;\n}\n\nexport interface CallStatus {\n id: string;\n status: CallStatusValue | string;\n to: string;\n from_: string; // Backend uses from_ (Python keyword)\n country: string;\n created_at: string;\n started_at?: string;\n completed_at?: string;\n duration_seconds?: number;\n max_duration_seconds?: number;\n transcript?: Array<Record<string, any>>;\n summary?: string;\n metadata: Record<string, any>;\n end_user_id?: string; // Marketplace end-user ID for privacy isolation\n}\n\nexport interface ToolDefinition {\n name: string;\n description: string;\n input_schema: Record<string, any>;\n output_schema?: Record<string, any>;\n timeout_ms?: number;\n}\n\nexport interface WebhookPayload {\n event: string;\n call_id: string;\n call_session_id: string;\n timestamp: string;\n data: Record<string, any>;\n}\n\n/** Standard error codes (aligned with backend models/errors.py) */\nexport const ErrorCodes = {\n // Auth errors (1000-1999)\n AUTH_REQUIRED: 1001,\n AUTH_INVALID: 1002,\n AUTH_EXPIRED: 1003,\n AUTH_INSUFFICIENT_PERMISSIONS: 1004,\n AUTH_FORBIDDEN: 1005,\n\n // Validation errors (2000-2999)\n VALIDATION_ERROR: 2001,\n INVALID_PHONE: 2002,\n INVALID_EMAIL: 2003,\n INVALID_PASSWORD: 2004,\n MISSING_REQUIRED_FIELD: 2005,\n INVALID_JSON: 2006,\n INVALID_REQUEST_BODY: 2007,\n\n // Not found errors (3000-3999)\n NOT_FOUND: 3001,\n USER_NOT_FOUND: 3002,\n CONVERSATION_NOT_FOUND: 3003,\n CALL_SESSION_NOT_FOUND: 3004,\n RESOURCE_NOT_FOUND: 3005,\n MESSAGE_NOT_FOUND: 3006,\n\n // Conflict errors (4000-4999)\n RESOURCE_ALREADY_EXISTS: 4001,\n EMAIL_ALREADY_REGISTERED: 4002,\n ACCOUNT_LINKING_REQUIRED: 4003,\n\n // Server errors (5000-5999)\n INTERNAL_ERROR: 5001,\n EXTERNAL_SERVICE_ERROR: 5002,\n DATABASE_ERROR: 5003,\n CONFIGURATION_ERROR: 5004,\n\n // Rate limiting (6000-6999)\n RATE_LIMIT_EXCEEDED: 6001,\n QUOTA_EXCEEDED: 6002,\n\n // B2B errors (7000-7999)\n B2B_PARTNER_NOT_FOUND: 7001,\n B2B_PROJECT_NOT_FOUND: 7002,\n B2B_CALL_NOT_FOUND: 7003,\n B2B_NO_PHONE_NUMBER: 7004,\n B2B_UNSUPPORTED_COUNTRY: 7005,\n B2B_TOOL_EXECUTION_FAILED: 7006,\n B2B_WEBHOOK_DELIVERY_FAILED: 7007,\n SUBSCRIPTION_EXPIRED: 7008,\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4EO,IAAM,aAAa;AAAA;AAAA,EAExB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,cAAc;AAAA,EACd,+BAA+B;AAAA,EAC/B,gBAAgB;AAAA;AAAA,EAGhB,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,kBAAkB;AAAA,EAClB,wBAAwB;AAAA,EACxB,cAAc;AAAA,EACd,sBAAsB;AAAA;AAAA,EAGtB,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,mBAAmB;AAAA;AAAA,EAGnB,yBAAyB;AAAA,EACzB,0BAA0B;AAAA,EAC1B,0BAA0B;AAAA;AAAA,EAG1B,gBAAgB;AAAA,EAChB,wBAAwB;AAAA,EACxB,gBAAgB;AAAA,EAChB,qBAAqB;AAAA;AAAA,EAGrB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA;AAAA,EAGhB,uBAAuB;AAAA,EACvB,uBAAuB;AAAA,EACvB,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,sBAAsB;AACxB;","names":[]}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const verifyWebhookSignature: (payload: string | object, signature: string | undefined | null, secret: string) => boolean;
|
|
2
|
+
declare const parseToolWebhook: (payload: Record<string, any>) => {
|
|
3
|
+
tool_name: string;
|
|
4
|
+
arguments: Record<string, any>;
|
|
5
|
+
call_id: string;
|
|
6
|
+
correlation_id: string;
|
|
7
|
+
call_session_id?: string;
|
|
8
|
+
partner_id?: string;
|
|
9
|
+
project_id?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { parseToolWebhook, verifyWebhookSignature };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const verifyWebhookSignature: (payload: string | object, signature: string | undefined | null, secret: string) => boolean;
|
|
2
|
+
declare const parseToolWebhook: (payload: Record<string, any>) => {
|
|
3
|
+
tool_name: string;
|
|
4
|
+
arguments: Record<string, any>;
|
|
5
|
+
call_id: string;
|
|
6
|
+
correlation_id: string;
|
|
7
|
+
call_session_id?: string;
|
|
8
|
+
partner_id?: string;
|
|
9
|
+
project_id?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { parseToolWebhook, verifyWebhookSignature };
|
package/dist/webhooks.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/webhooks.ts
|
|
31
|
+
var webhooks_exports = {};
|
|
32
|
+
__export(webhooks_exports, {
|
|
33
|
+
parseToolWebhook: () => parseToolWebhook,
|
|
34
|
+
verifyWebhookSignature: () => verifyWebhookSignature
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(webhooks_exports);
|
|
37
|
+
var crypto = __toESM(require("crypto"));
|
|
38
|
+
var verifyWebhookSignature = (payload, signature, secret) => {
|
|
39
|
+
if (!signature) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (!secret) {
|
|
43
|
+
throw new Error("Webhook secret cannot be empty");
|
|
44
|
+
}
|
|
45
|
+
const payloadString = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
46
|
+
const expectedSignature = crypto.createHmac("sha256", secret).update(payloadString).digest("hex");
|
|
47
|
+
return crypto.timingSafeEqual(
|
|
48
|
+
Buffer.from(signature),
|
|
49
|
+
Buffer.from(expectedSignature)
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
var parseToolWebhook = (payload) => {
|
|
53
|
+
const requiredFields = ["tool_name", "arguments", "call_id", "correlation_id"];
|
|
54
|
+
const missing = requiredFields.filter((field) => !(field in payload));
|
|
55
|
+
if (missing.length > 0) {
|
|
56
|
+
throw new Error(`Missing required fields: ${missing.join(", ")}`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
tool_name: String(payload.tool_name),
|
|
60
|
+
arguments: typeof payload.arguments === "object" && payload.arguments ? payload.arguments : {},
|
|
61
|
+
call_id: String(payload.call_id),
|
|
62
|
+
correlation_id: String(payload.correlation_id),
|
|
63
|
+
call_session_id: payload.call_session_id,
|
|
64
|
+
partner_id: payload.partner_id,
|
|
65
|
+
project_id: payload.project_id
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
parseToolWebhook,
|
|
71
|
+
verifyWebhookSignature
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webhooks.ts"],"sourcesContent":["import * as crypto from 'crypto';\n\nexport const verifyWebhookSignature = (\n payload: string | object,\n signature: string | undefined | null,\n secret: string\n): boolean => {\n if (!signature) {\n return false;\n }\n\n if (!secret) {\n throw new Error('Webhook secret cannot be empty');\n }\n\n const payloadString = typeof payload === 'string' ? payload : JSON.stringify(payload);\n const expectedSignature = crypto\n .createHmac('sha256', secret)\n .update(payloadString)\n .digest('hex');\n\n return crypto.timingSafeEqual(\n Buffer.from(signature),\n Buffer.from(expectedSignature)\n );\n};\n\nexport const parseToolWebhook = (payload: Record<string, any>): {\n tool_name: string;\n arguments: Record<string, any>;\n call_id: string;\n correlation_id: string;\n call_session_id?: string;\n partner_id?: string;\n project_id?: string;\n} => {\n const requiredFields = ['tool_name', 'arguments', 'call_id', 'correlation_id'];\n const missing = requiredFields.filter((field) => !(field in payload));\n\n if (missing.length > 0) {\n throw new Error(`Missing required fields: ${missing.join(', ')}`);\n }\n\n return {\n tool_name: String(payload.tool_name),\n arguments: typeof payload.arguments === 'object' && payload.arguments\n ? payload.arguments\n : {},\n call_id: String(payload.call_id),\n correlation_id: String(payload.correlation_id),\n call_session_id: payload.call_session_id,\n partner_id: payload.partner_id,\n project_id: payload.project_id,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AAEjB,IAAM,yBAAyB,CACpC,SACA,WACA,WACY;AACZ,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,QAAM,gBAAgB,OAAO,YAAY,WAAW,UAAU,KAAK,UAAU,OAAO;AACpF,QAAM,oBACH,kBAAW,UAAU,MAAM,EAC3B,OAAO,aAAa,EACpB,OAAO,KAAK;AAEf,SAAc;AAAA,IACZ,OAAO,KAAK,SAAS;AAAA,IACrB,OAAO,KAAK,iBAAiB;AAAA,EAC/B;AACF;AAEO,IAAM,mBAAmB,CAAC,YAQ5B;AACH,QAAM,iBAAiB,CAAC,aAAa,aAAa,WAAW,gBAAgB;AAC7E,QAAM,UAAU,eAAe,OAAO,CAAC,UAAU,EAAE,SAAS,QAAQ;AAEpE,MAAI,QAAQ,SAAS,GAAG;AACtB,UAAM,IAAI,MAAM,4BAA4B,QAAQ,KAAK,IAAI,CAAC,EAAE;AAAA,EAClE;AAEA,SAAO;AAAA,IACL,WAAW,OAAO,QAAQ,SAAS;AAAA,IACnC,WAAW,OAAO,QAAQ,cAAc,YAAY,QAAQ,YACxD,QAAQ,YACR,CAAC;AAAA,IACL,SAAS,OAAO,QAAQ,OAAO;AAAA,IAC/B,gBAAgB,OAAO,QAAQ,cAAc;AAAA,IAC7C,iBAAiB,QAAQ;AAAA,IACzB,YAAY,QAAQ;AAAA,IACpB,YAAY,QAAQ;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisispamela/sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Pamela Enterprise Voice API SDK for JavaScript/TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./webhooks": {
|
|
15
|
+
"types": "./dist/webhooks.d.ts",
|
|
16
|
+
"import": "./dist/webhooks.mjs",
|
|
17
|
+
"require": "./dist/webhooks.js"
|
|
18
|
+
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"types": "./dist/types.d.ts",
|
|
21
|
+
"import": "./dist/types.mjs",
|
|
22
|
+
"require": "./dist/types.js"
|
|
23
|
+
},
|
|
24
|
+
"./errors": {
|
|
25
|
+
"types": "./dist/errors.d.ts",
|
|
26
|
+
"import": "./dist/errors.mjs",
|
|
27
|
+
"require": "./dist/errors.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
7
30
|
"scripts": {
|
|
8
|
-
"build": "
|
|
31
|
+
"build": "tsup",
|
|
9
32
|
"test": "jest",
|
|
10
33
|
"test:watch": "jest --watch",
|
|
11
34
|
"prepublishOnly": "npm run build"
|
|
@@ -26,8 +49,9 @@
|
|
|
26
49
|
"devDependencies": {
|
|
27
50
|
"@types/node": "^20.0.0",
|
|
28
51
|
"@types/jest": "^29.5.0",
|
|
29
|
-
"typescript": "^5.0.0",
|
|
30
52
|
"jest": "^29.7.0",
|
|
31
|
-
"ts-jest": "^29.1.0"
|
|
53
|
+
"ts-jest": "^29.1.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"typescript": "^5.0.0"
|
|
32
56
|
}
|
|
33
57
|
}
|