Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions flow-typed/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

declare module '@foxcomm/api-js' {
declare type StringDict = {[name: string]: string};

declare type AbortablePromise = Promise & {
abort(): void;
};

declare type AgentLike = AbortablePromise & {
get(url: string): AgentLike;
post(url: string): AgentLike;
patch(url: string): AgentLike;
delete(url: string): AgentLike;

set(headers: StringDict): AgentLike;
withCredentials(): AgentLike;
};

declare type RequestOptions = {
headers?: StringDict,
credentials?: string,
agent?: AgentLike;
};

// @TODO: add subclasses
declare class ApiClass {
addresses: mixed;
auth: mixed;
creditCards: mixed;
storeCredits: mixed;
cart: mixed;
account: mixed;
orders: mixed;
reviews: mixed;
analytics: mixed;
crossSell: mixed;

addAuth(jwt: string): ApiClass;
removeAuth(): ApiClass;

// Returns customer id from parsed jwt string
// You can define jwt string via `addAuth` method, if there is no jwt strings method returns null.
getCustomerId(): ?number;

setHeaders(headers: StringDict): ApiClass;
addHeaders(headers: StringDict): ApiClass;
uri(path: string): string;
queryStringToObject(qs: string): StringDict;

request(method: string, uri: string, data: ?Object, options: ?RequestOptions): AbortablePromise;
get(uri: string, data: ?Object, options: ?Object): AbortablePromise;
post(uri: string, data: ?Object, options: ?Object): AbortablePromise;
patch(uri: string, data: ?Object, options: ?Object): AbortablePromise;
delete(uri: string, data: ?Object, options: ?Object): AbortablePromise;
}

declare function parseError(err: mixed): Array<string>;

declare module.exports: typeof ApiClass;
}
13 changes: 13 additions & 0 deletions types/api/album.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

export type Image = {
alt: string,
src: string,
title?: string,
};

export type Album = {
id: number,
name: string,
images: Array<Image>,
archivedAt?: string,
};
13 changes: 13 additions & 0 deletions types/api/attrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

export type Currency = {|
t: 'price',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is price a special type?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v: {
currency: string,
value: number
}
|};

export type String = {|
t: 'string',
v: string
|};
8 changes: 8 additions & 0 deletions types/api/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export type Context = {|
name: string,
attributes: {
lang: string,
modality: string,
}
|};
31 changes: 31 additions & 0 deletions types/api/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import type { Context } from './base';
import type { String } from './attrs';
import type { Sku } from './sku';
import type { Album } from './album';

export type VariantValue = {
id: number,
name: string,
swatch: string,
skuCodes: Array<string>,
};

export type Variant = {
attributes: {
name: String,
},
values: Array<VariantValue>,
};

export type Product = {
id: number,
context: Context,
albums: Array<Album>,
skus: Array<Sku>,
attributes: {
name: String,
description: String,
},
variants: Array<Variant>,
};
15 changes: 15 additions & 0 deletions types/api/sku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import type { Context } from './base';
import type { Currency, String } from './attrs';
import type { Album } from './album';

export type Sku = {
id: number,
context: Context,
attributes: {
code: String,
salePrice: Currency,
retailPrice: Currency,
},
albums: Array<Album>,
};
12 changes: 12 additions & 0 deletions types/api/views/album.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

export type Image = {
alt?: string,
src: string,
title?: string,
baseurl?: string,
};

export type Album = {
name: string,
images: Array<Image>,
};
13 changes: 13 additions & 0 deletions types/api/views/country.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

export type Country = {
id: number,
name: string,
alpha2: string,
alpha3: string,
code: string,
continent: string,
currency: string,
uses_postal_code: boolean,
is_billable: boolean,
is_shippable: boolean,
};
21 changes: 21 additions & 0 deletions types/api/views/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import type { Album } from './album';
import type { Taxonomy } from './taxonomy';

export type Product = {
id: number,
productId: number,
slug: ?string,
context: string,
currency: string,
title: string,
description: ?string,
salePrice: string,
retailPrice: string,
currency: string,
albums: ?Array<Album> | Object,
skus: Array<string>,
tags?: Array<string>,
scope?: string,
taxonomies: Array<Taxonomy>,
};
7 changes: 7 additions & 0 deletions types/api/views/region.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export type Region = {
id: number,
name: string,
abbreviation: string,
countryId: number,
};
5 changes: 5 additions & 0 deletions types/api/views/taxonomy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export type Taxonomy = {
taxonomy: string,
taxons: Array<Array<string>>
};