@saturation-api/js
Version:
TypeScript SDK for the Saturation API
618 lines • 19.4 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Saturation = void 0;
const index_js_1 = require("./generated/client/index.js");
const sdk = __importStar(require("./generated/sdk.gen.js"));
class Saturation {
client;
constructor(options) {
const headers = 'apiKey' in options
? {
'X-API-Key': options.apiKey,
}
: {
Authorization: `Bearer ${options.authToken}`,
'X-Workspace-Id': options.workspaceId,
};
const config = {
baseUrl: options.baseURL || 'https://api.saturation.io/api/v1',
headers: {
...headers,
},
// Custom query serializer to handle arrays with bracket notation
querySerializer: (queryParams) => {
const search = [];
if (queryParams && typeof queryParams === 'object') {
for (const name in queryParams) {
const value = queryParams[name];
if (value === undefined || value === null) {
continue;
}
if (Array.isArray(value)) {
// Use bracket notation for arrays (e.g., expands[]=value1&expands[]=value2)
for (const item of value) {
search.push(`${name}[]=${encodeURIComponent(String(item))}`);
}
}
else if (typeof value === 'object') {
// Handle nested objects (deepObject style)
const obj = value;
for (const key in obj) {
if (obj[key] !== undefined && obj[key] !== null) {
search.push(`${name}[${key}]=${encodeURIComponent(String(obj[key]))}`);
}
}
}
else {
// Handle primitive values
search.push(`${name}=${encodeURIComponent(String(value))}`);
}
}
}
return search.join('&');
},
};
this.client = (0, index_js_1.createClient)(config);
}
// Projects
async listProjects(params) {
const result = await sdk.listProjects({
client: this.client,
query: params,
});
return result.data;
}
async getProject(projectId) {
const result = await sdk.getProject({
client: this.client,
path: { projectId },
});
return result.data;
}
async createProject(data) {
const result = await sdk.createProject({
client: this.client,
body: data,
});
return result.data;
}
async updateProject(projectId, data) {
const result = await sdk.updateProject({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async deleteProject(projectId) {
await sdk.deleteProject({
client: this.client,
path: { projectId },
});
}
// Budget
async getBudget(projectId, params) {
const result = await sdk.getBudget({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
async createBudgetLines(projectId, data) {
const result = await sdk.createBudgetLines({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async getBudgetLine(projectId, lineId, params) {
const result = await sdk.getBudgetLine({
client: this.client,
path: { projectId, lineId },
query: params,
});
return result.data;
}
async updateBudgetLine(projectId, lineId, data) {
const result = await sdk.updateBudgetLine({
client: this.client,
path: { projectId, lineId },
body: data,
});
return result.data;
}
async deleteBudgetLine(projectId, lineId, idMode) {
await sdk.deleteBudgetLine({
client: this.client,
path: { projectId, lineId },
query: { idMode },
});
}
async listBudgetAccounts(projectId, params) {
const result = await sdk.listBudgetAccounts({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
// Actuals
async listActuals(projectId, params) {
const result = await sdk.listActuals({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
async getActual(projectId, actualId, params) {
const result = await sdk.getActual({
client: this.client,
path: { projectId, actualId },
query: params,
});
return result.data;
}
async createActual(projectId, actualId, data) {
const result = await sdk.createActual({
client: this.client,
path: { projectId, actualId },
body: data,
});
return result.data;
}
async updateActual(projectId, actualId, data) {
const result = await sdk.updateActual({
client: this.client,
path: { projectId, actualId },
body: data,
});
return result.data;
}
async deleteActual(projectId, actualId) {
await sdk.deleteActual({
client: this.client,
path: { projectId, actualId },
});
}
async uploadActualAttachment(projectId, actualId, file) {
const result = await sdk.uploadActualAttachment({
client: this.client,
path: { projectId, actualId },
body: { file },
});
return result.data;
}
// Purchase Orders
async listPurchaseOrders(projectId, params) {
const result = await sdk.listPurchaseOrders({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
async getPurchaseOrder(projectId, purchaseOrderId, params) {
const result = await sdk.getPurchaseOrder({
client: this.client,
path: { projectId, purchaseOrderId },
query: params,
});
return result.data;
}
async createPurchaseOrder(projectId, purchaseOrderId, data) {
const result = await sdk.createPurchaseOrder({
client: this.client,
path: { projectId, purchaseOrderId },
body: data,
});
return result.data;
}
async updatePurchaseOrder(projectId, purchaseOrderId, data) {
const result = await sdk.updatePurchaseOrder({
client: this.client,
path: { projectId, purchaseOrderId },
body: data,
});
return result.data;
}
async deletePurchaseOrder(projectId, purchaseOrderId) {
await sdk.deletePurchaseOrder({
client: this.client,
path: { projectId, purchaseOrderId },
});
}
async uploadPurchaseOrderAttachment(projectId, purchaseOrderId, file) {
const result = await sdk.uploadPurchaseOrderAttachment({
client: this.client,
path: { projectId, purchaseOrderId },
body: { file },
});
return result.data;
}
// Budget Phases
async listBudgetPhases(projectId, idMode) {
const result = await sdk.listBudgetPhases({
client: this.client,
path: { projectId },
query: { idMode },
});
return result.data;
}
async getBudgetPhase(projectId, phaseId, idMode) {
const result = await sdk.getBudgetPhase({
client: this.client,
path: { projectId, phaseId },
query: { idMode },
});
return result.data;
}
async createBudgetPhase(projectId, data) {
const result = await sdk.createBudgetPhase({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async updateBudgetPhase(projectId, phaseId, data) {
const result = await sdk.updateBudgetPhase({
client: this.client,
path: { projectId, phaseId },
body: data,
});
return result.data;
}
async deleteBudgetPhase(projectId, phaseId) {
await sdk.deleteBudgetPhase({
client: this.client,
path: { projectId, phaseId },
});
}
// Budget Fringes
async listBudgetFringes(projectId, idMode) {
const result = await sdk.listBudgetFringes({
client: this.client,
path: { projectId },
query: { idMode },
});
return result.data;
}
async getBudgetFringe(projectId, fringeId, idMode) {
const result = await sdk.getBudgetFringe({
client: this.client,
path: { projectId, fringeId },
query: { idMode },
});
return result.data;
}
async createBudgetFringe(projectId, data) {
const result = await sdk.createBudgetFringe({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async updateBudgetFringe(projectId, fringeId, data) {
const result = await sdk.updateBudgetFringe({
client: this.client,
path: { projectId, fringeId },
body: data,
});
return result.data;
}
async deleteBudgetFringe(projectId, fringeId) {
await sdk.deleteBudgetFringe({
client: this.client,
path: { projectId, fringeId },
});
}
// Budget Globals
async listBudgetGlobals(projectId, idMode) {
const result = await sdk.listBudgetGlobals({
client: this.client,
path: { projectId },
query: { idMode },
});
return result.data;
}
async getBudgetGlobal(projectId, globalId, idMode) {
const result = await sdk.getBudgetGlobal({
client: this.client,
path: { projectId, globalId },
query: { idMode },
});
return result.data;
}
async createBudgetGlobal(projectId, data) {
const result = await sdk.createBudgetGlobal({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async updateBudgetGlobal(projectId, globalId, data) {
const result = await sdk.updateBudgetGlobal({
client: this.client,
path: { projectId, globalId },
body: data,
});
return result.data;
}
async deleteBudgetGlobal(projectId, globalId) {
await sdk.deleteBudgetGlobal({
client: this.client,
path: { projectId, globalId },
});
}
// Project Tags
async listTags(projectId, params) {
const result = await sdk.listTags({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
async getTag(projectId, tagId, idMode) {
const result = await sdk.getTag({
client: this.client,
path: { projectId, tagId },
query: { idMode },
});
return result.data;
}
async createTag(projectId, data) {
const result = await sdk.createTag({
client: this.client,
path: { projectId },
body: data,
});
return result.data;
}
async updateTag(projectId, tagId, data) {
const result = await sdk.updateTag({
client: this.client,
path: { projectId, tagId },
body: data,
});
return result.data;
}
async deleteTag(projectId, tagId) {
await sdk.deleteTag({
client: this.client,
path: { projectId, tagId },
});
}
// Contacts
async listContacts(params) {
const result = await sdk.listContacts({
client: this.client,
query: params,
});
return result.data;
}
async getContact(contactId, params) {
const result = await sdk.getContact({
client: this.client,
path: { contactId },
query: params,
});
return result.data;
}
async createContact(data) {
const result = await sdk.createContact({
client: this.client,
body: data,
});
return result.data;
}
async updateContact(contactId, data) {
const result = await sdk.updateContact({
client: this.client,
path: { contactId },
body: data,
});
return result.data;
}
// Spaces
async listSpaces(params) {
const result = await sdk.listSpaces({
client: this.client,
query: params,
});
return result.data;
}
async getSpace(spaceId, params) {
const result = await sdk.getSpace({
client: this.client,
path: { spaceId },
query: params,
});
return result.data;
}
async createSpace(data) {
const result = await sdk.createSpace({
client: this.client,
body: data,
});
return result.data;
}
async updateSpace(spaceId, data) {
const result = await sdk.updateSpace({
client: this.client,
path: { spaceId },
body: data,
});
return result.data;
}
async deleteSpace(spaceId) {
await sdk.deleteSpace({
client: this.client,
path: { spaceId },
});
}
// Files
async uploadFile(file, projectId, type) {
const result = await sdk.uploadFile({
client: this.client,
body: { file, projectId, type },
});
return result.data;
}
async downloadFile(fileId) {
const result = await sdk.downloadFile({
client: this.client,
path: { fileId },
});
return result.data;
}
async deleteFile(fileId) {
await sdk.deleteFile({
client: this.client,
path: { fileId },
});
}
// Comments
async listComments(projectId, params) {
const result = await sdk.listComments({
client: this.client,
path: { projectId },
query: params,
});
return result.data;
}
// Workspace Rates
async listWorkspaceRates(params) {
const result = await sdk.listWorkspaceRates({
client: this.client,
query: params,
});
return result.data;
}
async createWorkspaceRate(data) {
const result = await sdk.createWorkspaceRate({
client: this.client,
body: data,
});
return result.data;
}
async deleteWorkspaceRate(rateId) {
await sdk.deleteWorkspaceRate({
client: this.client,
path: { rateId },
});
}
async updateWorkspaceRate(rateId, data) {
const result = await sdk.updateWorkspaceRate({
client: this.client,
path: { rateId },
body: data,
});
return result.data;
}
// Public Rates
async listPublicRatepacks(params) {
const result = await sdk.listPublicRatepacks({
client: this.client,
query: params,
});
return result.data;
}
async getPublicRates(ratepackId, params) {
const result = await sdk.getPublicRates({
client: this.client,
path: { ratepackId },
query: params,
});
return result.data;
}
// Transactions
async listTransactions(params) {
const result = await sdk.listTransactions({
client: this.client,
query: params,
});
return result.data;
}
async getTransaction(transactionId, params) {
const result = await sdk.getTransaction({
client: this.client,
path: { transactionId },
query: params,
});
return result.data;
}
async updateTransaction(transactionId, data) {
const result = await sdk.updateTransaction({
client: this.client,
path: { transactionId },
body: data,
});
return result.data;
}
async uploadTransactionAttachment(transactionId, file) {
const result = await sdk.uploadTransactionAttachment({
client: this.client,
path: { transactionId },
body: { file },
});
return result.data;
}
// Contact Attachments
async uploadContactTaxDocument(contactId, file) {
const result = await sdk.uploadContactTaxDocument({
client: this.client,
path: { contactId },
body: { file },
});
return result.data;
}
async uploadContactAttachment(contactId, file) {
const result = await sdk.uploadContactAttachment({
client: this.client,
path: { contactId },
body: { file },
});
return result.data;
}
}
exports.Saturation = Saturation;
//# sourceMappingURL=client.js.map