n8n-nodes-zid
Version:
BETA; n8n custom nodes for integrating with the Zid API (orders, products, customers, etc.)
53 lines (52 loc) • 1.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericZidApi = void 0;
const axios_1 = __importDefault(require("axios"));
class GenericZidApi {
constructor(baseURL, accessToken) {
this.client = axios_1.default.create({
baseURL,
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
});
}
async request(config) {
try {
const response = await this.client.request(config);
return response.data;
}
catch (error) {
if (error.response) {
throw new Error(`Zid API Error: ${error.response.status} ${JSON.stringify(error.response.data)}`);
}
throw new Error(`Zid API Error: ${error.message}`);
}
}
// Example: GET with pagination
async getPaginated(url, params = {}) {
let results = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await this.request({
method: 'GET',
url,
params: { ...params, page },
});
results = results.concat(response.data);
if (response.meta && response.meta.current_page < response.meta.last_page) {
page++;
}
else {
hasMore = false;
}
}
return results;
}
}
exports.GenericZidApi = GenericZidApi;