Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #27 from JumpLink/master
Browse files Browse the repository at this point in the history
Added themes api
  • Loading branch information
nozzlegear authored Oct 16, 2018
2 parents ca500b5 + 804e623 commit f55c046
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tests/built/

# Ignore private configuration files
*.private.json
.vscode

# Ignore test project's yarn.lock
tests/yarn.lock
tests/yarn.lock
2 changes: 1 addition & 1 deletion auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function buildHashString(type: "web" | "proxy", querystring: { [index: string]:
* @param convertToBase64 Whether the resulting hash should be converted to base64 or left as hex. Should be true for validating webhook requests.
*/
function getHmacHash(secretKey: string, hashString: string, convertToBase64 = false) {
let hash = crypto.HmacSHA256(hashString, secretKey);
let hash: string | crypto.WordArray = crypto.HmacSHA256(hashString, secretKey);

if (convertToBase64) {
hash = crypto.enc.Base64.stringify(hash);
Expand Down
4 changes: 4 additions & 0 deletions models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ export interface ShopifyObject {
* The object's unique id.
*/
id?: number;
/**
* To help with migrating from our REST to the GraphQL, REST responses now include the GraphQL Admin API ID field, admin_graphql_api_id,. The ID in this field can be used to query the object directly using the GraphQL Admin API.
*/
admin_graphql_api_id?: string;
}
1 change: 1 addition & 0 deletions models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export * from "./refund";
export * from "./script_tag";
export * from "./shipping_line";
export * from "./shop";
export * from "./theme";
export * from "./tax_line";
export * from "./transaction";
export * from "./usage_charge";
Expand Down
35 changes: 35 additions & 0 deletions models/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ShopifyObject } from "./base";

export interface Theme extends ShopifyObject {
/**
* The name of the theme.
*/
name?: string;
/**
* The date and time (ISO 8601 format) when the theme was created.
*/
created_at?: string;
/**
* The date and time ( ISO 8601 format) when the theme was last updated.
*/
updated_at?: string;
/**
* Specifies how the theme is being used within the shop. Valid values:
* * main: The theme is published. Customers see it when they visit the online store.
* * unpublished: The theme is unpublished. Customers can't see it.
* * demo: The theme is installed on the store as a demo. The theme can't be published until the merchant buys the full version.
*/
role?: 'main' | 'unpublished' | 'demo';
/**
* A unique identifier applied to Shopify-made themes that are installed from the Shopify Theme Store Theme Store. Not all themes available in the Theme Store are developed by Shopify. Returns null if the store's theme isn't made by Shopify, or if it wasn't installed from the Theme Store.
*/
theme_store_id?: number | null;
/**
* Whether the theme can currently be previewed.
*/
previewable?: boolean;
/**
* Whether files are still being copied into place for this theme.
*/
processing?: boolean;
}
1 change: 1 addition & 0 deletions services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export * from "./redirects";
export * from "./script_tags";
export * from "./shops";
export * from "./smart_collections";
export * from "./themes";
export * from "./usage_charges";
export * from "./webhooks";
56 changes: 56 additions & 0 deletions services/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as Options from '../options';
import { BaseService } from '../infrastructure';
import { Theme } from '../models';

/**
* A service for manipulating a Shopify shop's theme.
*/
export class Themes extends BaseService {
constructor(shopDomain: string, accessToken: string) {
super(shopDomain, accessToken, "themes");
}

/**
* Creates a theme by providing the public URL of a ZIP file that contains the theme.
* @param themes The theme being created.
*/
public create(themes: Theme) {
return this.createRequest<Theme>("POST", `.json`, "", { themes });
}

/**
* Gets a tsingle hemes with the given id.
* @param id Id of the theme to retrieve.
* @param options Options for filtering the result.
*/
public get(id: number, options?: Options.FieldOptions) {
return this.createRequest<Theme>("GET", `${id}.json`, "", options);
}

/**
* Updates an existing theme.
* @param id Id of the themes being updated.
* @param themes The updated theme.
*/
public update(id: number, themes: Theme) {
return this.createRequest<Theme>("PUT", `${id}.json`, "themes", { themes });
}

/**
* Gets a list of all themes on the shop.
* @param options Options for filtering the results.
*/
public list(options?: Options.FieldOptions) {
return this.createRequest<Theme[]>("GET", `.json`, "themes", options);
}

/**
* Deletes the themes with the given id.
* @param id Id of the theme being deleted.
*/
public delete(id: number) {
return this.createRequest<void>("DELETE", `${id}.json`);
}
}

export default Themes;

0 comments on commit f55c046

Please sign in to comment.