@haus-storefront-react/vendure-plugin-configs 0.0.49 → 0.0.52-1
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/CHANGELOG.md +39 -7
- package/badge.js +21 -21
- package/badge.mjs +1522 -1439
- package/package.json +4 -4
- package/README.md +0 -176
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haus-storefront-react/vendure-plugin-configs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.52-1",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@haus-storefront-react/common-utils": "0.0.
|
|
45
|
-
"@haus-storefront-react/core": "0.0.
|
|
46
|
-
"@haus-storefront-react/shared-types": "0.0.
|
|
44
|
+
"@haus-storefront-react/common-utils": "0.0.52-1",
|
|
45
|
+
"@haus-storefront-react/core": "0.0.52-1",
|
|
46
|
+
"@haus-storefront-react/shared-types": "0.0.52-1"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/README.md
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
# Vendure Plugin Configs
|
|
2
|
-
|
|
3
|
-
This package provides a framework for creating and sharing plugin configurations for Vendure-based storefronts. Plugin configs allow you to extend the Vendure SDK with new features, queries, and type-safe entity augmentations—**only when you import the plugin**.
|
|
4
|
-
|
|
5
|
-
## What is a Plugin Config?
|
|
6
|
-
|
|
7
|
-
A plugin config is a TypeScript class that encapsulates:
|
|
8
|
-
|
|
9
|
-
- Feature functions (e.g. `showBadges`)
|
|
10
|
-
- Query/request extensions
|
|
11
|
-
- Optional type augmentation for Vendure entities (e.g. adding `badges` to `Product`)
|
|
12
|
-
|
|
13
|
-
## How to Create a Plugin Config
|
|
14
|
-
|
|
15
|
-
1. **Create a new file** in `libs/plugin-configs/vendure/src/lib/`, e.g. `my-plugin.ts`.
|
|
16
|
-
2. **Export a class or constant** that extends the base `VendurePluginConfig`.
|
|
17
|
-
3. **(Optional) Add type augmentation** for Vendure entities by placing a `declare module` block in the same file.
|
|
18
|
-
|
|
19
|
-
### Example: Badge Plugin
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import {
|
|
23
|
-
Asset,
|
|
24
|
-
Collection,
|
|
25
|
-
ErrorResult,
|
|
26
|
-
Maybe,
|
|
27
|
-
PaginatedList,
|
|
28
|
-
Product,
|
|
29
|
-
ProductVariant,
|
|
30
|
-
SearchResult,
|
|
31
|
-
} from '@haus-storefront-react/shared-types'
|
|
32
|
-
import VendurePluginConfig from './plugin-config'
|
|
33
|
-
import { filter } from 'lodash'
|
|
34
|
-
|
|
35
|
-
// Type augmentation: Only active if this plugin is imported!
|
|
36
|
-
declare module '@haus-storefront-react/shared-types' {
|
|
37
|
-
interface Product {
|
|
38
|
-
badges?: Maybe<Array<Badge>>
|
|
39
|
-
}
|
|
40
|
-
interface SearchResult {
|
|
41
|
-
badges?: Maybe<Array<Badge>>
|
|
42
|
-
}
|
|
43
|
-
interface ProductVariant {
|
|
44
|
-
badges?: Maybe<Array<Badge>>
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface BadgePluginRequests {
|
|
49
|
-
getBadges: () => Promise<PaginatedList<Badge> | ErrorResult>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type BadgeFeatures = {
|
|
53
|
-
showBadges: (props: {
|
|
54
|
-
product?: Product | SearchResult
|
|
55
|
-
variant?: ProductVariant
|
|
56
|
-
parentComponent?: string
|
|
57
|
-
badges: Maybe<Badge[]>
|
|
58
|
-
}) => { badges: Badge[]; availablePositions?: string[] }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export type Badge = {
|
|
62
|
-
id: string
|
|
63
|
-
createdAt: string
|
|
64
|
-
updatedAt: string
|
|
65
|
-
collection: Collection
|
|
66
|
-
collectionId: string
|
|
67
|
-
position: string
|
|
68
|
-
asset: Asset
|
|
69
|
-
assetId: string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const VendureBadgePlugin = new VendurePluginConfig<BadgeFeatures, BadgePluginRequests>({
|
|
73
|
-
name: 'badges',
|
|
74
|
-
enableFeatures: {
|
|
75
|
-
showBadges: ({ badges = [], parentComponent }) => {
|
|
76
|
-
// ...implementation
|
|
77
|
-
return { badges: [], availablePositions: [] }
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
queryUpdates: {},
|
|
81
|
-
settings: {},
|
|
82
|
-
})
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## How to Use a Plugin Config in Your App
|
|
86
|
-
|
|
87
|
-
1. **Import the plugin in your app:**
|
|
88
|
-
```ts
|
|
89
|
-
import { VendureBadgePlugin } from '@haus-storefront-react/vendure-plugin-configs'
|
|
90
|
-
```
|
|
91
|
-
2. **Add it to your DataProvider/pluginConfigs:**
|
|
92
|
-
```tsx
|
|
93
|
-
<DataProvider
|
|
94
|
-
provider="vendure"
|
|
95
|
-
options={{
|
|
96
|
-
// ...
|
|
97
|
-
pluginConfigs: [VendureBadgePlugin.init({ enableFeatures: ['showBadges'] })],
|
|
98
|
-
}}
|
|
99
|
-
>
|
|
100
|
-
{/* ... */}
|
|
101
|
-
</DataProvider>
|
|
102
|
-
```
|
|
103
|
-
3. **TypeScript will now know about `product.badges`!**
|
|
104
|
-
|
|
105
|
-
### Example: Type-Safe Usage in a Component
|
|
106
|
-
|
|
107
|
-
```tsx
|
|
108
|
-
import { Product } from '@haus-storefront-react/shared-types'
|
|
109
|
-
|
|
110
|
-
function ProductBadges({ product }: { product: Product }) {
|
|
111
|
-
if (!product.badges?.length) return null
|
|
112
|
-
return (
|
|
113
|
-
<div>
|
|
114
|
-
{product.badges.map((badge) => (
|
|
115
|
-
<span key={badge.id}>{badge.position}</span>
|
|
116
|
-
))}
|
|
117
|
-
</div>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
**Note:** The type augmentation is _opt-in_: Only projects that import the plugin will see the new fields on `Product`, `SearchResult`, etc.
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
## Creating a Plugin Config in an External App
|
|
127
|
-
|
|
128
|
-
You can also create your own plugin config in an external app (outside this package). This is useful for app-specific features or experiments. See the example below, inspired by `test-plugin.ts`:
|
|
129
|
-
|
|
130
|
-
### 1. Create your plugin config (e.g. `test-plugin.ts`):
|
|
131
|
-
|
|
132
|
-
```ts
|
|
133
|
-
import { VendurePluginConfig, PluginFeatures } from '@haus-storefront-react/vendure-plugin-configs'
|
|
134
|
-
|
|
135
|
-
// Type augmentation: Adds testFeature to PluginFeatureMappings if this plugin is imported
|
|
136
|
-
|
|
137
|
-
declare module '@haus-storefront-react/vendure-plugin-configs' {
|
|
138
|
-
interface PluginFeatureMappings {
|
|
139
|
-
testFeature: (props: { value: string }) => string
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export const TestPlugin = new VendurePluginConfig<PluginFeatures>({
|
|
144
|
-
name: 'test',
|
|
145
|
-
enableFeatures: {
|
|
146
|
-
testFeature: ({ value }: { value: string }) => `Test feature says: ${value}`,
|
|
147
|
-
},
|
|
148
|
-
queryUpdates: {},
|
|
149
|
-
settings: {},
|
|
150
|
-
})
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### 2. Use your plugin config in your app:
|
|
154
|
-
|
|
155
|
-
```tsx
|
|
156
|
-
import { TestPlugin } from './plugin-configs/test-plugin'
|
|
157
|
-
;<DataProvider
|
|
158
|
-
provider="vendure"
|
|
159
|
-
options={{
|
|
160
|
-
// ...
|
|
161
|
-
pluginConfigs: [TestPlugin.init({ enableFeatures: ['testFeature'] })],
|
|
162
|
-
}}
|
|
163
|
-
>
|
|
164
|
-
{/* ... */}
|
|
165
|
-
</DataProvider>
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
- The `declare module` block ensures TypeScript is aware of your new feature when the plugin is imported.
|
|
169
|
-
- You can add any features, queries, or type augmentations you need for your app.
|
|
170
|
-
|
|
171
|
-
---
|
|
172
|
-
|
|
173
|
-
## Nx Commands
|
|
174
|
-
|
|
175
|
-
- **Build:** `nx build plugin-configs/vendure`
|
|
176
|
-
- **Test:** `nx test plugin-configs/vendure`
|