UNPKG

@amplience/dc-cli

Version:
30 lines (29 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiEndpoints = void 0; const Asset_1 = require("../../model/Asset"); const Settings_1 = require("../../model/Settings"); class ApiEndpoints { constructor(client) { this.client = client; this.assets = { get: async (id) => { return this.assetsListToSingle(await this.client.fetchResource(`/assets/${id}`, {}, Asset_1.AssetsList), id); }, list: (options) => { return this.client.fetchResource('/assets{?q,filter,c,n,s,f,bucket,select,variants,preferredLocales,snippetSize,hl.fl,hl.pre,hl.post,hl.max,localeGroups.collapse,localeGroups.preferredLocales,localeGroups.limit,sort}', { query: options }, Asset_1.AssetsPage); } }; this.settings = { get: () => this.client.fetchResource(`/settings`, {}, Settings_1.Settings) }; } assetsListToSingle(list, id) { const items = list.getItems(); if (items.length === 0) { throw new Error(`Unable to find asset with id ${id}.`); } return items[0]; } } exports.ApiEndpoints = ApiEndpoints;