UNPKG

shopify-admin-api

Version:

Shopify Admin API is a NodeJS library built to help developers easily authenticate and make calls against the Shopify API. It was inspired by and borrows heavily from ShopifySharp.

106 lines (105 loc) 3.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Pages = void 0; const infrastructure_1 = require("../infrastructure"); /** * A service for manipulating Shopify pages. */ class Pages extends infrastructure_1.BaseService { constructor(shopDomain, accessToken) { super(shopDomain, accessToken, "pages"); } /** * Creates a new page. * @param page The page being created. */ create(page) { return this.createRequest("POST", `.json`, "page", { page }); } /** * Retrieves a single page by its ID. * @param id Id of the page to retrieve. * @param options Options for filtering the result. */ get(id, options) { return this.createRequest("GET", `${id}.json`, "page", options); } /** * Updates a page with the given id. * @param id Id of the page being updated. * @param page The updated page. */ update(id, page) { return this.createRequest("PUT", `${id}.json`, "page", { page }); } /** * Retrieve a list of all pages. * @param options Options for filtering the results. */ list(options) { return this.createRequest("GET", `.json`, "pages", options); } /** * Retrieves a page count. */ count(options) { return this.createRequest("GET", "count.json", "count", options); } /** * Deletes a page with the given id. * @param id Id of the page being deleted. */ delete(id) { return this.createRequest("DELETE", `${id}.json`); } /** * Gets a list of up to 250 metafields from the given page. * @param id The page's id. * @param options Options for filtering the results. */ listMetafields(pageId, options) { return this.createRequest("GET", `${pageId}/metafields.json`, 'metafields', options); } /** * Returns the number of metafields belonging to the given page. * @param id The page's id. */ countMetafields(pageId) { return this.createRequest("GET", `${pageId}/metafields/count.json`, 'count'); } /** * Gets the metafield with the given id from an page. * @param pageId The page's id. * @param id The metafield's id. */ getMetafield(pageId, id) { return this.createRequest("GET", `${pageId}/metafields/${id}.json`, 'metafield'); } /** * Creates a metafield for the given page. * @param pageId The page's id. * @param id The metafield's id. * @param metafield Options for the metafield */ createMetafield(pageId, metafield) { return this.createRequest("POST", `${pageId}/metafields.json`, 'metafield', { metafield }); } /** * Updates a metafield for the given page * @param pageId The page's id. * @param id The metafield's id. * @param metafield Options for the metafield */ updateMetafield(pageId, id, metafield) { return this.createRequest("PUT", `${pageId}/metafields/${id}.json`, 'metafield', { metafield }); } /** * Deletes the metafield with the given id from an page. * @param pageId The page's id. * @param id The metafield's id. */ deleteMetafield(pageId, id) { return this.createRequest("DELETE", `${pageId}/metafields/${id}.json`, 'metafield'); } } exports.Pages = Pages;