@grafikr/shopify-typescript 0.0.2 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/global/Shopify.ts +31 -0
- package/package.json +5 -4
- package/type/Cart.ts +18 -0
- package/type/Collection.ts +12 -0
- package/type/DiscountAllocations.ts +6 -0
- package/type/DiscountApplication.ts +13 -0
- package/type/Image.ts +6 -0
- package/type/LineItem.ts +49 -0
- package/{types → type}/Option.ts +0 -0
- package/{types → type}/Product.ts +3 -3
- package/type/ProductImage.ts +10 -0
- package/{types → type}/Variant.ts +0 -0
- package/type/object/Article.ts +18 -0
- package/type/object/Collection.ts +17 -0
- package/type/object/FeaturedMedia.ts +8 -0
- package/{types → type/object}/Image.ts +0 -5
- package/type/object/Media.ts +13 -0
- package/type/object/PreviewImage.ts +6 -0
- package/type/object/Product.ts +29 -0
- package/type/object/Rule.ts +5 -0
- package/type/object/Variant.ts +24 -0
- package/type/search/Article.ts +12 -0
- package/type/search/Collection.ts +7 -0
- package/type/search/FeaturedImage.ts +7 -0
- package/type/search/Item.ts +7 -0
- package/type/search/Page.ts +6 -0
- package/type/search/Product.ts +17 -0
- package/type/search/Result.ts +13 -0
- package/globals/Shopify.ts +0 -28
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Shopify TypeScript
|
|
2
|
+
|
|
3
|
+
This packages adds TypeScript for all Shopify responses and objects.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
You can install the package using Yarn:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ yarn install @grafikr/shopify-typescript --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import Product from '@grafikr/shopify-typescript/type/Product';
|
|
17
|
+
|
|
18
|
+
const func = (data: Product) => {
|
|
19
|
+
...
|
|
20
|
+
};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can have a look in the repository under `global` and `type` folder, to find types you can use.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ProductJSON from '../type/Product';
|
|
2
|
+
import ProductObject from '../type/object/Product';
|
|
3
|
+
|
|
4
|
+
export default interface Shopify {
|
|
5
|
+
Image: {
|
|
6
|
+
switchImage: CallableFunction
|
|
7
|
+
getSizedImageUrl: (src: string, size: string) => string
|
|
8
|
+
imageSize: (src: string) => string | null
|
|
9
|
+
loadImage: (src: string) => void
|
|
10
|
+
removeProtocol: (url: string) => string
|
|
11
|
+
}
|
|
12
|
+
OptionSelectors: (selector: string, config: {
|
|
13
|
+
product: ProductJSON | ProductObject
|
|
14
|
+
onVariantSelected: CallableFunction
|
|
15
|
+
enableHistoryState: boolean
|
|
16
|
+
}) => void
|
|
17
|
+
OptionSelectorsFromDOM: FunctionConstructor
|
|
18
|
+
loadFeatures: (features: any[], callback: CallableFunction) => void
|
|
19
|
+
customerPrivacy?: (consented: boolean, callback: CallableFunction) => void
|
|
20
|
+
currency: {
|
|
21
|
+
active: string
|
|
22
|
+
rate: string
|
|
23
|
+
}
|
|
24
|
+
cdnHost: 'cdn.shopify.com'
|
|
25
|
+
country: string
|
|
26
|
+
locale: string
|
|
27
|
+
formatMoney: (price: string | number, format: string) => string
|
|
28
|
+
money_format: string
|
|
29
|
+
shop: string
|
|
30
|
+
designMode: true | undefined
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafikr/shopify-typescript",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"lint": "node_modules/.bin/eslint . --ext .js,.ts"
|
|
6
|
+
"lint": "node_modules/.bin/eslint . --ext .js,.ts",
|
|
7
|
+
"test": "yarn lint"
|
|
7
8
|
},
|
|
8
9
|
"devDependencies": {
|
|
9
10
|
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
"url": "https://github.com/grafikr/shopify-typescript.git"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
|
-
"
|
|
23
|
-
"
|
|
23
|
+
"global",
|
|
24
|
+
"type"
|
|
24
25
|
]
|
|
25
26
|
}
|
package/type/Cart.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import LineItem from './LineItem';
|
|
2
|
+
import DiscountApplication from './DiscountApplication';
|
|
3
|
+
|
|
4
|
+
export default interface Cart {
|
|
5
|
+
token: string
|
|
6
|
+
note: string | null
|
|
7
|
+
attributes: { [key: string]: string | boolean } | null
|
|
8
|
+
original_total_price: number
|
|
9
|
+
total_price: number
|
|
10
|
+
total_discount: number
|
|
11
|
+
total_weight: number
|
|
12
|
+
item_count: number
|
|
13
|
+
items: LineItem[]
|
|
14
|
+
requires_shipping: boolean
|
|
15
|
+
currency: string
|
|
16
|
+
items_subtotal_price: number
|
|
17
|
+
cart_level_discount_applications: DiscountApplication[]
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default interface DiscountApplication {
|
|
2
|
+
type: 'automatic' | 'discount_code' | 'manual' | 'script'
|
|
3
|
+
key: string
|
|
4
|
+
title: string
|
|
5
|
+
description: string | null
|
|
6
|
+
value: number
|
|
7
|
+
created_at: string
|
|
8
|
+
value_type: 'fixed_amount' | 'percentage'
|
|
9
|
+
allocation_method: 'across' | 'each' | 'one'
|
|
10
|
+
target_selection: 'all' | 'entitled' | 'explicit'
|
|
11
|
+
target_type: 'line_item' | 'shipping_line'
|
|
12
|
+
total_allocated_amount: number
|
|
13
|
+
}
|
package/type/Image.ts
ADDED
package/type/LineItem.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default interface Item {
|
|
2
|
+
id: number
|
|
3
|
+
properties: { [key: string]: string | boolean } | null
|
|
4
|
+
quantity: number
|
|
5
|
+
variant_id: number
|
|
6
|
+
key: string
|
|
7
|
+
title: string
|
|
8
|
+
price: number
|
|
9
|
+
original_price: number
|
|
10
|
+
discounted_price: number
|
|
11
|
+
line_price: number
|
|
12
|
+
original_line_price: number
|
|
13
|
+
total_discount: number
|
|
14
|
+
discounts: [{
|
|
15
|
+
amount: number
|
|
16
|
+
title: string
|
|
17
|
+
}]
|
|
18
|
+
sku: string
|
|
19
|
+
grams: number
|
|
20
|
+
vendor: string
|
|
21
|
+
taxable: boolean
|
|
22
|
+
product_id: number
|
|
23
|
+
product_has_only_default_variant: boolean
|
|
24
|
+
gift_card: boolean
|
|
25
|
+
final_price: number
|
|
26
|
+
final_line_price: number
|
|
27
|
+
url: string
|
|
28
|
+
featured_image: [{
|
|
29
|
+
aspect_ratio: number
|
|
30
|
+
alt: string
|
|
31
|
+
height: number
|
|
32
|
+
url: string
|
|
33
|
+
width: number
|
|
34
|
+
}]
|
|
35
|
+
image: string
|
|
36
|
+
handle: string
|
|
37
|
+
requires_shipping: boolean
|
|
38
|
+
product_type: string
|
|
39
|
+
product_title: string
|
|
40
|
+
product_description: string
|
|
41
|
+
variant_title: string
|
|
42
|
+
variant_options: string[]
|
|
43
|
+
options_with_values: [{
|
|
44
|
+
name: string
|
|
45
|
+
value: string
|
|
46
|
+
}]
|
|
47
|
+
line_level_discount_allocations: any[]
|
|
48
|
+
line_level_total_discount: number
|
|
49
|
+
}
|
package/{types → type}/Option.ts
RENAMED
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Variant from './Variant';
|
|
2
2
|
import Option from './Option';
|
|
3
|
-
import
|
|
3
|
+
import ProductImage from './ProductImage';
|
|
4
4
|
|
|
5
5
|
export default interface Product {
|
|
6
6
|
id: number
|
|
@@ -17,6 +17,6 @@ export default interface Product {
|
|
|
17
17
|
tags: string
|
|
18
18
|
variants: Variant[]
|
|
19
19
|
options: Option[]
|
|
20
|
-
images:
|
|
21
|
-
image:
|
|
20
|
+
images: ProductImage[]
|
|
21
|
+
image: ProductImage
|
|
22
22
|
}
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Image from './Image';
|
|
2
|
+
|
|
3
|
+
export default interface Article {
|
|
4
|
+
id: number
|
|
5
|
+
title: string
|
|
6
|
+
created_at: string
|
|
7
|
+
body_html: string
|
|
8
|
+
blog_id: number
|
|
9
|
+
author: string
|
|
10
|
+
user_id: number
|
|
11
|
+
published_at: string
|
|
12
|
+
updated_at: string
|
|
13
|
+
summary_html: string
|
|
14
|
+
template_suffix: string
|
|
15
|
+
handle: string
|
|
16
|
+
tags: string
|
|
17
|
+
image: Image
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Image from './Image';
|
|
2
|
+
import Rule from './Rule';
|
|
3
|
+
|
|
4
|
+
export default interface Collection {
|
|
5
|
+
id: number
|
|
6
|
+
handle: string
|
|
7
|
+
title: string
|
|
8
|
+
updated_at: string
|
|
9
|
+
body_html: string
|
|
10
|
+
published_at: string
|
|
11
|
+
sort_order: string
|
|
12
|
+
template_suffix: string
|
|
13
|
+
disjunctive?: boolean
|
|
14
|
+
rules?: Rule[]
|
|
15
|
+
published_scope: string
|
|
16
|
+
image?: Image
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import PreviewImage from './PreviewImage';
|
|
2
|
+
|
|
3
|
+
export default interface Media {
|
|
4
|
+
alt: string | null
|
|
5
|
+
id: number
|
|
6
|
+
position: number
|
|
7
|
+
preview_image: PreviewImage
|
|
8
|
+
aspect_ratio: number
|
|
9
|
+
height: number
|
|
10
|
+
media_type: string
|
|
11
|
+
src: string
|
|
12
|
+
width: number
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Variant from './Variant';
|
|
2
|
+
import Media from './Media';
|
|
3
|
+
|
|
4
|
+
export default interface Product {
|
|
5
|
+
id: number
|
|
6
|
+
title: string
|
|
7
|
+
handle: string
|
|
8
|
+
description: string
|
|
9
|
+
published_at: string
|
|
10
|
+
created_at: string
|
|
11
|
+
vendor: string
|
|
12
|
+
type: string
|
|
13
|
+
tags: string[]
|
|
14
|
+
price: number
|
|
15
|
+
price_min: number
|
|
16
|
+
price_max: number
|
|
17
|
+
available: boolean
|
|
18
|
+
price_varies: boolean
|
|
19
|
+
compare_at_price: string | null
|
|
20
|
+
compare_at_price_min: number
|
|
21
|
+
compare_at_price_max: number
|
|
22
|
+
compare_at_price_varies: boolean
|
|
23
|
+
variants: Variant[]
|
|
24
|
+
images: string[]
|
|
25
|
+
featured_image: string | null
|
|
26
|
+
options: string[]
|
|
27
|
+
media: Media[]
|
|
28
|
+
content: string
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import FeaturedImage from '../search/FeaturedImage';
|
|
2
|
+
import FeaturedMedia from './FeaturedMedia';
|
|
3
|
+
|
|
4
|
+
export default interface Variant {
|
|
5
|
+
id: number
|
|
6
|
+
title: string
|
|
7
|
+
option1: string | null
|
|
8
|
+
option2: string | null
|
|
9
|
+
option3: string | null
|
|
10
|
+
sku: string | null
|
|
11
|
+
requires_shipping: boolean
|
|
12
|
+
taxable: boolean
|
|
13
|
+
featured_image?: FeaturedImage
|
|
14
|
+
featured_media?: FeaturedMedia
|
|
15
|
+
available: boolean
|
|
16
|
+
name: string
|
|
17
|
+
public_title: string | null
|
|
18
|
+
options: string[]
|
|
19
|
+
price: number | null
|
|
20
|
+
weight: number
|
|
21
|
+
compare_at_price: number | null
|
|
22
|
+
inventory_management: string
|
|
23
|
+
barcode: string | null
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Item from './Item';
|
|
2
|
+
import FeaturedImage from './FeaturedImage';
|
|
3
|
+
|
|
4
|
+
export default interface Article extends Item{
|
|
5
|
+
author: string
|
|
6
|
+
image: string | null
|
|
7
|
+
published_at: string
|
|
8
|
+
summary_html: string
|
|
9
|
+
tags: string[]
|
|
10
|
+
title: string
|
|
11
|
+
featured_image: FeaturedImage
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Item from './Item';
|
|
2
|
+
import FeaturedImage from './FeaturedImage';
|
|
3
|
+
|
|
4
|
+
export default interface Product extends Item {
|
|
5
|
+
available: boolean
|
|
6
|
+
compare_at_price_max: string
|
|
7
|
+
compare_at_price_min: string
|
|
8
|
+
image: string | null
|
|
9
|
+
price: string
|
|
10
|
+
price_max: string
|
|
11
|
+
price_min: string
|
|
12
|
+
tags: string[]
|
|
13
|
+
type: string
|
|
14
|
+
variants: []
|
|
15
|
+
vendor: string
|
|
16
|
+
featured_image: FeaturedImage
|
|
17
|
+
}
|
package/globals/Shopify.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Product from '../types/Product';
|
|
2
|
-
|
|
3
|
-
export {};
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
const Shopify: {
|
|
7
|
-
Image: {
|
|
8
|
-
getSizedImageUrl: CallableFunction
|
|
9
|
-
imageSize: CallableFunction
|
|
10
|
-
loadImage: CallableFunction
|
|
11
|
-
removeProtocol: CallableFunction
|
|
12
|
-
switchImage: CallableFunction
|
|
13
|
-
}
|
|
14
|
-
OptionSelectors: (selector: string, config: {
|
|
15
|
-
product: Product
|
|
16
|
-
onVariantSelected: CallableFunction
|
|
17
|
-
enableHistoryState: boolean
|
|
18
|
-
}) => void
|
|
19
|
-
OptionSelectorsFromDOM: FunctionConstructor
|
|
20
|
-
currency: {
|
|
21
|
-
active: string
|
|
22
|
-
rate: string
|
|
23
|
-
}
|
|
24
|
-
formatMoney: (price: string | number, format: string) => string
|
|
25
|
-
money_format: string
|
|
26
|
-
shop: string
|
|
27
|
-
};
|
|
28
|
-
}
|