UNPKG

@paddle/paddle-node-sdk

Version:

A Node.js SDK that you can use to integrate Paddle Billing with applications written in server-side JavaScript.

58 lines (57 loc) 2.73 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { BaseResource, PathParameters, QueryParameters } from '../../internal/base/index.js'; import { Product, ProductCollection } from '../../entities/index.js'; const ProductPaths = { list: '/products', create: '/products', get: '/products/{product_id}', update: '/products/{product_id}', }; export * from './operations/index.js'; export class ProductsResource extends BaseResource { list(queryParams) { const queryParameters = new QueryParameters(queryParams); return new ProductCollection(this.client, ProductPaths.list + queryParameters.toQueryString()); } create(createProductParameters) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.client.post(ProductPaths.create, createProductParameters); const data = this.handleResponse(response); return new Product(data); }); } get(productId, queryParams) { return __awaiter(this, void 0, void 0, function* () { const queryParameters = new QueryParameters(queryParams); const urlWithPathParams = new PathParameters(ProductPaths.get, { product_id: productId, }).deriveUrl(); const response = yield this.client.get(urlWithPathParams, queryParameters); const data = this.handleResponse(response); return new Product(data); }); } update(productId, updateProduct) { return __awaiter(this, void 0, void 0, function* () { const urlWithPathParams = new PathParameters(ProductPaths.update, { product_id: productId, }).deriveUrl(); const response = yield this.client.patch(urlWithPathParams, updateProduct); const data = this.handleResponse(response); return new Product(data); }); } archive(productId) { return __awaiter(this, void 0, void 0, function* () { return yield this.update(productId, { status: 'archived' }); }); } }