@recursyve/deeplinks-client
Version:
Node.js client for Recursyve's Deeplinks API
74 lines (73 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NiceDeeplinksClient = void 0;
const axios_1 = require("axios");
class NiceDeeplinksClient {
constructor(config) {
this.apiKey = config.apiKey;
this.tenantId = config.tenantId;
this.client = axios_1.default.create({
baseURL: config.baseURL || "https://deeplinks.recursyve.dev",
timeout: config.timeout || 30000,
headers: {
"Content-Type": "application/json"
},
});
this.client.interceptors.request.use((config) => {
if (this.apiKey) {
config.headers["Api-Key"] = this.apiKey;
}
if (this.tenantId) {
config.headers["Tenant-Id"] = this.tenantId;
}
return config;
});
this.client.interceptors.response.use((response) => response, (error) => {
var _a, _b, _c, _d, _e;
const apiError = {
message: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) || error.message,
status: ((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) || 500,
code: ((_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.code) || "UNKNOWN_ERROR",
};
return Promise.reject(apiError);
});
}
/**
* Create a new application
*/
async createApplication(data) {
const response = await this.client.post("/application", data);
return response.data;
}
/**
* Update an application by ID
*/
async updateApplication(id, data) {
const response = await this.client.patch(`/application/${id}`, data);
return response.data;
}
/**
* Create a new domain
*/
async createDomain(data) {
const response = await this.client.post("/domain", data);
return response.data;
}
/**
* Create a new dynamic link
*/
async createDynamicLink(data) {
const response = await this.client.post("/dynamic-link", data);
return response.data;
}
/**
* Fetch dynamic link details by code
*/
async fetchLinkDetails(code, params) {
const response = await this.client.get(`/dynamic-link/${code}`, {
params,
});
return response.data;
}
}
exports.NiceDeeplinksClient = NiceDeeplinksClient;