diff --git a/flow-typed/api.js b/flow-typed/api.js new file mode 100644 index 0000000..f624f8f --- /dev/null +++ b/flow-typed/api.js @@ -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; + + declare module.exports: typeof ApiClass; +} diff --git a/types/api/album.js b/types/api/album.js new file mode 100644 index 0000000..20f6b3b --- /dev/null +++ b/types/api/album.js @@ -0,0 +1,13 @@ + +export type Image = { + alt: string, + src: string, + title?: string, +}; + +export type Album = { + id: number, + name: string, + images: Array, + archivedAt?: string, +}; diff --git a/types/api/attrs.js b/types/api/attrs.js new file mode 100644 index 0000000..ec38e42 --- /dev/null +++ b/types/api/attrs.js @@ -0,0 +1,13 @@ + +export type Currency = {| + t: 'price', + v: { + currency: string, + value: number + } +|}; + +export type String = {| + t: 'string', + v: string +|}; diff --git a/types/api/base.js b/types/api/base.js new file mode 100644 index 0000000..c0e20c0 --- /dev/null +++ b/types/api/base.js @@ -0,0 +1,8 @@ + +export type Context = {| + name: string, + attributes: { + lang: string, + modality: string, + } +|}; diff --git a/types/api/product.js b/types/api/product.js new file mode 100644 index 0000000..26b4fa1 --- /dev/null +++ b/types/api/product.js @@ -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, +}; + +export type Variant = { + attributes: { + name: String, + }, + values: Array, +}; + +export type Product = { + id: number, + context: Context, + albums: Array, + skus: Array, + attributes: { + name: String, + description: String, + }, + variants: Array, +}; diff --git a/types/api/sku.js b/types/api/sku.js new file mode 100644 index 0000000..90cadcb --- /dev/null +++ b/types/api/sku.js @@ -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, +}; diff --git a/types/api/views/album.js b/types/api/views/album.js new file mode 100644 index 0000000..48c209e --- /dev/null +++ b/types/api/views/album.js @@ -0,0 +1,12 @@ + +export type Image = { + alt?: string, + src: string, + title?: string, + baseurl?: string, +}; + +export type Album = { + name: string, + images: Array, +}; diff --git a/types/api/views/country.js b/types/api/views/country.js new file mode 100644 index 0000000..4360b33 --- /dev/null +++ b/types/api/views/country.js @@ -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, +}; diff --git a/types/api/views/product.js b/types/api/views/product.js new file mode 100644 index 0000000..65cc7c5 --- /dev/null +++ b/types/api/views/product.js @@ -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 | Object, + skus: Array, + tags?: Array, + scope?: string, + taxonomies: Array, +}; diff --git a/types/api/views/region.js b/types/api/views/region.js new file mode 100644 index 0000000..4843e68 --- /dev/null +++ b/types/api/views/region.js @@ -0,0 +1,7 @@ + +export type Region = { + id: number, + name: string, + abbreviation: string, + countryId: number, +}; diff --git a/types/api/views/taxonomy.js b/types/api/views/taxonomy.js new file mode 100644 index 0000000..5f0e22d --- /dev/null +++ b/types/api/views/taxonomy.js @@ -0,0 +1,5 @@ + +export type Taxonomy = { + taxonomy: string, + taxons: Array> +};