sanity-plugin-shopify-assets 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Sanity.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # sanity-plugin-shopify-assets
2
+
3
+ > This is a **Sanity Studio v3** plugin.
4
+
5
+ Select assets from your Shopify store in the context of your Sanity Studio. This plugin allows you to serve assets from the Shopify CDN in your frontends.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ npm install sanity-plugin-shopify-assets
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Add it as a plugin in sanity.config.ts (or .js):
16
+
17
+ ```
18
+ import {defineConfig} from 'sanity'
19
+ import {shopifyAssets} from 'sanity-plugin-shopify-assets'
20
+
21
+ export const defineConfig({
22
+ //...
23
+ plugins: [
24
+ shopifyAssets({
25
+ shopifyDomain: '*.myshopify.com'
26
+ })
27
+ ]
28
+ })
29
+ ```
30
+
31
+ Simply update the `shopifyDomain` to your store URL. You'll need to install the [Sanity Connect](https://www.sanity.io/docs/sanity-connect-for-shopify) app on your store to handle authorisation.
32
+
33
+ Then you can enable the asset selector on a field:
34
+
35
+ ```
36
+ import {defineType, defineField} from 'sanity'
37
+
38
+ export const myDocumentSchema = defineType({
39
+ type: "document",
40
+ name: "article",
41
+ fields: [
42
+ defineField({
43
+ type: "shopify.asset",
44
+ name: "shopifyAsset",
45
+ }),
46
+ ]
47
+ })
48
+ ```
49
+
50
+ It's also possible to define the Shopify domain on the field level, which allows you to retrieve assets from different stores. Each store must be connected to your Sanity project via the Sanity Connect app. In order to do this, simply declare the `shopifyDomain` on the field:
51
+
52
+ ```
53
+ defineField({
54
+ type: "shopify.asset",
55
+ name: "shopifyAsset",
56
+ options: {
57
+ shopifyDomain: '*.myshopify.com'
58
+ }
59
+ }),
60
+ ```
61
+
62
+ ## Example of resulting object
63
+
64
+ ```jsonc
65
+ {
66
+ "id": "gid://shopify/MediaImage/21154034647345",
67
+ "url": "https://cdn.shopify.com/s/files/1/0555/4906/7569/files/Green_1.jpg?v=1665668073",
68
+ "type": "image", // image, video, or file
69
+ "meta": {
70
+ "fileSize": 362812,
71
+ "alt": "",
72
+ "width": 3169,
73
+ "height": 3169,
74
+ "duration": 60 // video only
75
+ },
76
+ "preview": {
77
+ "url": "https://cdn.shopify.com/s/files/1/0555/4906/7569/files/Green_1.jpg?v=1665668073",
78
+ "width": 3169,
79
+ "height": 3169
80
+ },
81
+ "filename": "Green_1.jpg"
82
+ }
83
+ ```
84
+
85
+ ## License
86
+
87
+ [MIT](LICENSE) © Sanity.io <hello@sanity.io>
88
+
89
+ ## Develop & test
90
+
91
+ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
92
+ with default configuration for build & watch scripts.
93
+
94
+ See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
95
+ on how to run this plugin with hotreload in the studio.
96
+
97
+ ## License
98
+
99
+ [MIT](LICENSE) © Sanity.io
100
+
101
+ ### Release new version
102
+
103
+ Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-shopify-assets/actions/workflows/main.yml).
104
+ Make sure to select the main branch and check "Release new version".
105
+
106
+ Semantic release will only release on configured branches, so it is safe to run release on any branch.
@@ -0,0 +1,73 @@
1
+ import {ObjectSchemaType} from 'sanity'
2
+ import {Plugin as Plugin_2} from 'sanity'
3
+
4
+ export declare interface Asset extends ShopifyFile {
5
+ _type?: string
6
+ _key?: string
7
+ filename?: string
8
+ }
9
+
10
+ export declare interface AssetMeta {
11
+ alt?: string
12
+ duration?: number
13
+ fileSize?: number
14
+ height?: number
15
+ width?: number
16
+ }
17
+
18
+ export declare interface AssetPreviewImage {
19
+ height: number
20
+ url: string
21
+ width: number
22
+ }
23
+
24
+ export declare interface ObjectSchemaWithOptions extends ObjectSchemaType {
25
+ options: {
26
+ shopifyDomain: string
27
+ }
28
+ }
29
+
30
+ export declare interface PageInfo {
31
+ hasNextPage: boolean
32
+ cursor: string
33
+ }
34
+
35
+ export declare interface PluginConfig {
36
+ /**
37
+ * Your *.myshopify.com domain. Do not include https:// or any path.
38
+ */
39
+ shopifyDomain: string
40
+ }
41
+
42
+ declare type PossibleFileTypes = 'file' | 'image' | 'video'
43
+
44
+ export declare interface ShopifyAPIResponse {
45
+ pageInfo: PageInfo
46
+ assets: ShopifyFile[]
47
+ }
48
+
49
+ export declare const shopifyAssets: Plugin_2<PluginConfig>
50
+
51
+ export declare interface ShopifyFile {
52
+ meta: AssetMeta
53
+ preview: AssetPreviewImage
54
+ id: string
55
+ type: PossibleFileTypes
56
+ url: string
57
+ }
58
+
59
+ export {}
60
+
61
+ declare module 'sanity' {
62
+ namespace Schema {
63
+ type ShopifyAssetTypeDef = Omit<ObjectDefinition, 'type' | 'fields'> & {
64
+ type: 'shopify.asset'
65
+ options: {
66
+ shopifyDomain: string
67
+ }
68
+ }
69
+ interface IntrinsicTypeDefinition {
70
+ 'shopify.asset': ShopifyAssetTypeDef
71
+ }
72
+ }
73
+ }