@warriorteam/redai-zalo-sdk
Version:
Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account v3.0, ZNS with Full Type Safety, Consultation Service, Broadcast Service, Group Messaging with List APIs, Social APIs, Enhanced Article Management, Promotion Service v3.0 with Multip
120 lines • 3.66 kB
JavaScript
;
/**
* Main Zalo API client
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZaloClient = void 0;
const base_client_1 = require("./base-client");
/**
* Zalo API client for making HTTP requests
*/
class ZaloClient extends base_client_1.BaseClient {
constructor(config) {
super(config);
}
/**
* Make authenticated GET request to Zalo API
*/
async apiGet(endpoint, accessToken, params) {
return this.get(endpoint, accessToken, params);
}
/**
* Make GET request with custom headers
*/
async apiGetWithHeaders(endpoint, headers) {
return this.request({
method: "GET",
url: endpoint,
headers,
});
}
/**
* Make authenticated POST request to Zalo API
*/
async apiPost(endpoint, accessToken, data, params) {
return this.post(endpoint, accessToken, data, params);
}
/**
* Make authenticated PUT request to Zalo API
*/
async apiPut(endpoint, accessToken, data, params) {
return this.put(endpoint, accessToken, data, params);
}
/**
* Make authenticated DELETE request to Zalo API
*/
async apiDelete(endpoint, accessToken, params) {
return this.delete(endpoint, accessToken, params);
}
/**
* Upload file to Zalo API
*/
async apiUploadFile(endpoint, accessToken, file, filename, additionalFields) {
return this.uploadFile(endpoint, accessToken, file, filename, additionalFields);
}
/**
* Make POST request with FormData (for file uploads)
*/
async apiPostFormData(endpoint, accessToken, formData) {
return this.request({
method: "POST",
url: endpoint,
headers: {
access_token: accessToken,
// Don't set Content-Type header, let the browser set it with boundary
},
data: formData,
});
}
/**
* Make request to OAuth endpoints (without access token)
*/
async oauthRequest(method, endpoint, data, headers) {
const config = {
method,
url: endpoint,
headers,
data,
};
if (method === "GET") {
config.data = undefined;
return this.get(endpoint, undefined, data);
}
else {
return this.post(endpoint, undefined, data);
}
}
/**
* Make request to ZNS API (different base URL)
*/
async znsRequest(method, endpoint, accessToken, data, params) {
const znsBaseUrl = "https://business.openapi.zalo.me";
const fullUrl = `${znsBaseUrl}${endpoint}`;
switch (method) {
case "GET":
return this.get(fullUrl, accessToken, params);
case "POST":
return this.post(fullUrl, accessToken, data, params);
case "PUT":
return this.put(fullUrl, accessToken, data, params);
case "DELETE":
return this.delete(fullUrl, accessToken, params);
default:
throw new Error(`Unsupported HTTP method: ${method}`);
}
}
/**
* Make request to OAuth endpoints with custom base URL
*/
async oauthRequestWithUrl(method, url, data, headers) {
return this.request({
method,
url,
headers: headers || {},
data: method === "POST" ? data : undefined,
params: method === "GET" ? data : undefined,
});
}
}
exports.ZaloClient = ZaloClient;
//# sourceMappingURL=zalo-client.js.map