UNPKG

ynab

Version:

Official JavaScript client for the YNAB API. API documentation available at https://api.ynab.com. Generated from server specification version 1.85.0

374 lines (373 loc) 20.5 kB
"use strict"; /* tslint:disable */ /* eslint-disable */ /** * YNAB API Endpoints * Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.ynab.com * * Generated by: OpenAPI Generator (https://openapi-generator.tech) */ 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.CategoriesApi = void 0; const runtime = __importStar(require("../runtime")); const index_1 = require("../models/index"); /** * */ class CategoriesApi extends runtime.BaseAPI { /** * Creates a new category * Create a category */ async createCategoryRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling createCategory.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling createCategory.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/categories`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'POST', headers: headerParameters, query: queryParameters, body: (0, index_1.PostCategoryWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveCategoryResponseFromJSON)(jsonValue)); } /** * Creates a new category * Create a category */ async createCategory(planId, data, initOverrides) { const response = await this.createCategoryRaw({ planId: planId, data: data }, initOverrides); return await response.value(); } /** * Creates a new category group * Create a category group */ async createCategoryGroupRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling createCategoryGroup.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling createCategoryGroup.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/category_groups`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'POST', headers: headerParameters, query: queryParameters, body: (0, index_1.PostCategoryGroupWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveCategoryGroupResponseFromJSON)(jsonValue)); } /** * Creates a new category group * Create a category group */ async createCategoryGroup(planId, data, initOverrides) { const response = await this.createCategoryGroupRaw({ planId: planId, data: data }, initOverrides); return await response.value(); } /** * Returns all categories grouped by category group. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get all categories */ async getCategoriesRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getCategories.'); } const queryParameters = {}; if (requestParameters.lastKnowledgeOfServer !== undefined) { queryParameters['last_knowledge_of_server'] = requestParameters.lastKnowledgeOfServer; } const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/categories`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.CategoriesResponseFromJSON)(jsonValue)); } /** * Returns all categories grouped by category group. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get all categories */ async getCategories(planId, lastKnowledgeOfServer, initOverrides) { const response = await this.getCategoriesRaw({ planId: planId, lastKnowledgeOfServer: lastKnowledgeOfServer }, initOverrides); return await response.value(); } /** * Returns a single category. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get a category */ async getCategoryByIdRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getCategoryById.'); } if (requestParameters.categoryId === null || requestParameters.categoryId === undefined) { throw new runtime.RequiredError('categoryId', 'Required parameter requestParameters.categoryId was null or undefined when calling getCategoryById.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/categories/{category_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"category_id"}}`, encodeURIComponent(String(requestParameters.categoryId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.CategoryResponseFromJSON)(jsonValue)); } /** * Returns a single category. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get a category */ async getCategoryById(planId, categoryId, initOverrides) { const response = await this.getCategoryByIdRaw({ planId: planId, categoryId: categoryId }, initOverrides); return await response.value(); } /** * Returns a single category for a specific plan month. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get a category for a specific plan month */ async getMonthCategoryByIdRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling getMonthCategoryById.'); } if (requestParameters.month === null || requestParameters.month === undefined) { throw new runtime.RequiredError('month', 'Required parameter requestParameters.month was null or undefined when calling getMonthCategoryById.'); } if (requestParameters.categoryId === null || requestParameters.categoryId === undefined) { throw new runtime.RequiredError('categoryId', 'Required parameter requestParameters.categoryId was null or undefined when calling getMonthCategoryById.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/months/{month}/categories/{category_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"month"}}`, encodeURIComponent(String(requestParameters.month))).replace(`{${"category_id"}}`, encodeURIComponent(String(requestParameters.categoryId))), method: 'GET', headers: headerParameters, query: queryParameters, }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.CategoryResponseFromJSON)(jsonValue)); } /** * Returns a single category for a specific plan month. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). * Get a category for a specific plan month */ async getMonthCategoryById(planId, month, categoryId, initOverrides) { const response = await this.getMonthCategoryByIdRaw({ planId: planId, month: month, categoryId: categoryId }, initOverrides); return await response.value(); } /** * Update a category * Update a category */ async updateCategoryRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling updateCategory.'); } if (requestParameters.categoryId === null || requestParameters.categoryId === undefined) { throw new runtime.RequiredError('categoryId', 'Required parameter requestParameters.categoryId was null or undefined when calling updateCategory.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling updateCategory.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/categories/{category_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"category_id"}}`, encodeURIComponent(String(requestParameters.categoryId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: (0, index_1.PatchCategoryWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveCategoryResponseFromJSON)(jsonValue)); } /** * Update a category * Update a category */ async updateCategory(planId, categoryId, data, initOverrides) { const response = await this.updateCategoryRaw({ planId: planId, categoryId: categoryId, data: data }, initOverrides); return await response.value(); } /** * Update a category group * Update a category group */ async updateCategoryGroupRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling updateCategoryGroup.'); } if (requestParameters.categoryGroupId === null || requestParameters.categoryGroupId === undefined) { throw new runtime.RequiredError('categoryGroupId', 'Required parameter requestParameters.categoryGroupId was null or undefined when calling updateCategoryGroup.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling updateCategoryGroup.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/category_groups/{category_group_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"category_group_id"}}`, encodeURIComponent(String(requestParameters.categoryGroupId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: (0, index_1.PatchCategoryGroupWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveCategoryGroupResponseFromJSON)(jsonValue)); } /** * Update a category group * Update a category group */ async updateCategoryGroup(planId, categoryGroupId, data, initOverrides) { const response = await this.updateCategoryGroupRaw({ planId: planId, categoryGroupId: categoryGroupId, data: data }, initOverrides); return await response.value(); } /** * Update a category for a specific month. Only `budgeted` (assigned) amount can be updated. * Update a category for a specific month */ async updateMonthCategoryRaw(requestParameters, initOverrides) { if (requestParameters.planId === null || requestParameters.planId === undefined) { throw new runtime.RequiredError('planId', 'Required parameter requestParameters.planId was null or undefined when calling updateMonthCategory.'); } if (requestParameters.month === null || requestParameters.month === undefined) { throw new runtime.RequiredError('month', 'Required parameter requestParameters.month was null or undefined when calling updateMonthCategory.'); } if (requestParameters.categoryId === null || requestParameters.categoryId === undefined) { throw new runtime.RequiredError('categoryId', 'Required parameter requestParameters.categoryId was null or undefined when calling updateMonthCategory.'); } if (requestParameters.data === null || requestParameters.data === undefined) { throw new runtime.RequiredError('data', 'Required parameter requestParameters.data was null or undefined when calling updateMonthCategory.'); } const queryParameters = {}; const headerParameters = {}; headerParameters['Accept'] = 'application/json'; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/plans/{plan_id}/months/{month}/categories/{category_id}`.replace(`{${"plan_id"}}`, encodeURIComponent(String(requestParameters.planId))).replace(`{${"month"}}`, encodeURIComponent(String(requestParameters.month))).replace(`{${"category_id"}}`, encodeURIComponent(String(requestParameters.categoryId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: (0, index_1.PatchMonthCategoryWrapperToJSON)(requestParameters.data), }, initOverrides); return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_1.SaveCategoryResponseFromJSON)(jsonValue)); } /** * Update a category for a specific month. Only `budgeted` (assigned) amount can be updated. * Update a category for a specific month */ async updateMonthCategory(planId, month, categoryId, data, initOverrides) { const response = await this.updateMonthCategoryRaw({ planId: planId, month: month, categoryId: categoryId, data: data }, initOverrides); return await response.value(); } } exports.CategoriesApi = CategoriesApi;