@vicacha-devs/medusa-plugin-stories 0.0.0-stage → 0.1.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/.medusa/server/src/__tests__/stories-plugin.spec.js +358 -0
- package/.medusa/server/src/admin/i18n/index.js +35 -0
- package/.medusa/server/src/admin/i18n/json/ar.json +196 -0
- package/.medusa/server/src/admin/i18n/json/de.json +196 -0
- package/.medusa/server/src/admin/i18n/json/en.json +196 -0
- package/.medusa/server/src/admin/i18n/json/es.json +196 -0
- package/.medusa/server/src/admin/i18n/json/fr.json +196 -0
- package/.medusa/server/src/admin/i18n/json/it.json +196 -0
- package/.medusa/server/src/admin/i18n/json/nl.json +196 -0
- package/.medusa/server/src/admin/i18n/json/pl.json +196 -0
- package/.medusa/server/src/admin/i18n/json/pt.json +196 -0
- package/.medusa/server/src/admin/i18n/json/tr.json +196 -0
- package/.medusa/server/src/admin/index.cjs +4699 -0
- package/.medusa/server/src/admin/index.js +4699 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/admin/stories/[id]/hotspots/route.js +14 -0
- package/.medusa/server/src/api/admin/stories/[id]/route.js +27 -0
- package/.medusa/server/src/api/admin/stories/[id]/stickers/route.js +14 -0
- package/.medusa/server/src/api/admin/stories/analytics/route.js +7 -0
- package/.medusa/server/src/api/admin/stories/groups/[id]/route.js +23 -0
- package/.medusa/server/src/api/admin/stories/groups/route.js +15 -0
- package/.medusa/server/src/api/admin/stories/route.js +21 -0
- package/.medusa/server/src/api/middlewares.js +58 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/store/stories/[id]/events/route.js +12 -0
- package/.medusa/server/src/api/store/stories/[id]/interact/route.js +14 -0
- package/.medusa/server/src/api/store/stories/route.js +33 -0
- package/.medusa/server/src/api/validators.js +136 -0
- package/.medusa/server/src/hooks/index.js +213 -0
- package/.medusa/server/src/hooks/use-sdk-primitives.js +93 -0
- package/.medusa/server/src/index.js +6 -0
- package/.medusa/server/src/jobs/expire-ephemeral-stories.js +10 -0
- package/.medusa/server/src/modules/index.js +7 -0
- package/.medusa/server/src/modules/stories/index.js +3 -0
- package/.medusa/server/src/modules/story/index.js +23 -0
- package/.medusa/server/src/modules/story/migrations/Migration20260514000000.js +181 -0
- package/.medusa/server/src/modules/story/models/index.js +141 -0
- package/.medusa/server/src/modules/story/service.js +673 -0
- package/.medusa/server/src/modules/story/types.js +3 -0
- package/.medusa/server/src/modules/story/utils/security.js +76 -0
- package/.medusa/server/src/rbac.js +75 -0
- package/.medusa/server/src/sdk/index.js +148 -0
- package/.medusa/server/src/subscribers/product-deleted.js +11 -0
- package/.medusa/server/src/types/index.js +2 -0
- package/.medusa/server/src/ui/index.js +5 -0
- package/.medusa/server/src/ui/story-hotspot-pin.js +43 -0
- package/.medusa/server/src/ui/story-player-modal.js +104 -0
- package/.medusa/server/src/ui/story-product-sheet.js +7 -0
- package/.medusa/server/src/ui/story-rings-bar.js +42 -0
- package/.medusa/server/src/workflows/index.js +50 -0
- package/LICENSE +21 -0
- package/README.md +246 -2
- package/package.json +132 -3
- package/src/__tests__/medusa-shim.mjs +533 -0
- package/src/__tests__/register-ts-resolver.mjs +141 -0
- package/src/__tests__/stories-plugin.spec.ts +526 -0
- package/src/admin/README.md +94 -0
- package/src/admin/components/analytics-tab.tsx +225 -0
- package/src/admin/components/canvas-editor-tab.tsx +77 -0
- package/src/admin/components/hotspot-form-section.tsx +155 -0
- package/src/admin/components/index.ts +15 -0
- package/src/admin/components/overview-cards.tsx +96 -0
- package/src/admin/components/product-stories-card.tsx +123 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/components/slide-form-section.tsx +187 -0
- package/src/admin/components/slide-preview-canvas.tsx +166 -0
- package/src/admin/components/slide-timeline-section.tsx +126 -0
- package/src/admin/components/sticker-form-section.tsx +201 -0
- package/src/admin/components/sticker-list-section.tsx +113 -0
- package/src/admin/components/stickers-tab.tsx +34 -0
- package/src/admin/components/story-ring-form.tsx +241 -0
- package/src/admin/components/story-rings-tab.tsx +204 -0
- package/src/admin/components/story-rings-table.tsx +222 -0
- package/src/admin/components/studio-header.tsx +67 -0
- package/src/admin/hooks/use-product-stories.ts +71 -0
- package/src/admin/hooks/use-stories-studio.ts +439 -0
- package/src/admin/i18n/README.md +84 -0
- package/src/admin/i18n/index.ts +36 -0
- package/src/admin/i18n/json/ar.json +196 -0
- package/src/admin/i18n/json/de.json +196 -0
- package/src/admin/i18n/json/en.json +196 -0
- package/src/admin/i18n/json/es.json +196 -0
- package/src/admin/i18n/json/fr.json +196 -0
- package/src/admin/i18n/json/it.json +196 -0
- package/src/admin/i18n/json/nl.json +196 -0
- package/src/admin/i18n/json/pl.json +196 -0
- package/src/admin/i18n/json/pt.json +196 -0
- package/src/admin/i18n/json/tr.json +196 -0
- package/src/admin/routes/stories/analytics/page.tsx +66 -0
- package/src/admin/routes/stories/canvas/page.tsx +101 -0
- package/src/admin/routes/stories/page.tsx +164 -0
- package/src/admin/routes/stories/rings/@create/page.tsx +61 -0
- package/src/admin/routes/stories/rings/page.tsx +88 -0
- package/src/admin/routes/stories/stickers/page.tsx +74 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/utils/theme-presets.ts +94 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/product-stories-widget.tsx +32 -0
- package/src/api/README.md +61 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/admin/stories/[id]/hotspots/route.ts +17 -0
- package/src/api/admin/stories/[id]/route.ts +40 -0
- package/src/api/admin/stories/[id]/stickers/route.ts +20 -0
- package/src/api/admin/stories/analytics/route.ts +8 -0
- package/src/api/admin/stories/groups/[id]/route.ts +30 -0
- package/src/api/admin/stories/groups/route.ts +18 -0
- package/src/api/admin/stories/route.ts +31 -0
- package/src/api/middlewares.ts +73 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/store/stories/[id]/events/route.ts +14 -0
- package/src/api/store/stories/[id]/interact/route.ts +18 -0
- package/src/api/store/stories/route.ts +44 -0
- package/src/api/validators.ts +166 -0
- package/src/hooks/index.ts +419 -0
- package/src/hooks/use-sdk-primitives.ts +114 -0
- package/src/index.ts +14 -0
- package/src/jobs/README.md +16 -0
- package/src/jobs/expire-ephemeral-stories.ts +14 -0
- package/src/links/README.md +18 -0
- package/src/modules/README.md +46 -0
- package/src/modules/index.ts +15 -0
- package/src/modules/stories/index.ts +11 -0
- package/src/modules/story/index.ts +34 -0
- package/src/modules/story/migrations/Migration20260514000000.ts +196 -0
- package/src/modules/story/models/index.ts +146 -0
- package/src/modules/story/service.ts +1052 -0
- package/src/modules/story/types.ts +190 -0
- package/src/modules/story/utils/security.ts +100 -0
- package/src/providers/README.md +14 -0
- package/src/rbac.ts +89 -0
- package/src/sdk/index.ts +233 -0
- package/src/subscribers/README.md +16 -0
- package/src/subscribers/product-deleted.ts +15 -0
- package/src/types/index.ts +1 -0
- package/src/types/medusa-ui.d.ts +451 -0
- package/src/ui/index.ts +4 -0
- package/src/ui/story-hotspot-pin.tsx +122 -0
- package/src/ui/story-player-modal.tsx +361 -0
- package/src/ui/story-product-sheet.tsx +85 -0
- package/src/ui/story-rings-bar.tsx +113 -0
- package/src/workflows/README.md +19 -0
- package/src/workflows/index.ts +217 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
const chainableField = () => {
|
|
2
|
+
const field = {
|
|
3
|
+
primaryKey: () => field,
|
|
4
|
+
searchable: () => field,
|
|
5
|
+
nullable: () => field,
|
|
6
|
+
default: () => field,
|
|
7
|
+
}
|
|
8
|
+
return field
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const model = {
|
|
12
|
+
define(name, schema) {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
schema,
|
|
16
|
+
indexes() {
|
|
17
|
+
return this
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
id: chainableField,
|
|
22
|
+
text: chainableField,
|
|
23
|
+
number: chainableField,
|
|
24
|
+
boolean: chainableField,
|
|
25
|
+
json: chainableField,
|
|
26
|
+
dateTime: chainableField,
|
|
27
|
+
enum: chainableField,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function MedusaService(models = {}) {
|
|
31
|
+
return class BaseMedusaService {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.__stores = {}
|
|
34
|
+
let counter = 1
|
|
35
|
+
for (const key of Object.keys(models)) {
|
|
36
|
+
const plural = key.endsWith("y") ? `${key.slice(0, -1)}ies` : `${key}s`
|
|
37
|
+
this.__stores[plural] = []
|
|
38
|
+
|
|
39
|
+
if (typeof this[`list${plural}`] !== "function") {
|
|
40
|
+
this[`list${plural}`] = async (filter = {}) => {
|
|
41
|
+
const rows = this.__stores[plural]
|
|
42
|
+
return rows.filter((row) =>
|
|
43
|
+
Object.entries(filter).every(([k, v]) =>
|
|
44
|
+
v === undefined ? true : row[k] === v
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (typeof this[`create${plural}`] !== "function") {
|
|
50
|
+
this[`create${plural}`] = async (data) => {
|
|
51
|
+
const record = {
|
|
52
|
+
id: data.id ?? `${key.toLowerCase()}_${counter++}`,
|
|
53
|
+
created_at: new Date(),
|
|
54
|
+
updated_at: new Date(),
|
|
55
|
+
...data,
|
|
56
|
+
}
|
|
57
|
+
this.__stores[plural].push(record)
|
|
58
|
+
return record
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (typeof this[`update${plural}`] !== "function") {
|
|
62
|
+
this[`update${plural}`] = async (data) => {
|
|
63
|
+
const rows = this.__stores[plural]
|
|
64
|
+
const idx = rows.findIndex((r) => r.id === data.id)
|
|
65
|
+
if (idx >= 0) {
|
|
66
|
+
rows[idx] = { ...rows[idx], ...data, updated_at: new Date() }
|
|
67
|
+
return rows[idx]
|
|
68
|
+
}
|
|
69
|
+
return data
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (typeof this[`delete${plural}`] !== "function") {
|
|
73
|
+
this[`delete${plural}`] = async (id) => {
|
|
74
|
+
this.__stores[plural] = this.__stores[plural].filter(
|
|
75
|
+
(r) => r.id !== id
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class MedusaError extends Error {
|
|
85
|
+
static Types = {
|
|
86
|
+
DB_ERROR: "database_error",
|
|
87
|
+
DUPLICATE_ERROR: "duplicate_error",
|
|
88
|
+
INVALID_ARGUMENT: "invalid_argument",
|
|
89
|
+
INVALID_DATA: "invalid_data",
|
|
90
|
+
UNAUTHORIZED: "unauthorized",
|
|
91
|
+
NOT_FOUND: "not_found",
|
|
92
|
+
NOT_ALLOWED: "not_allowed",
|
|
93
|
+
UNEXPECTED_STATE: "unexpected_state",
|
|
94
|
+
CONFLICT: "conflict",
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
constructor(type, message, code) {
|
|
98
|
+
super(message)
|
|
99
|
+
this.type = type
|
|
100
|
+
this.code = code
|
|
101
|
+
this.name = "MedusaError"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function Module(name, config) {
|
|
106
|
+
return { name, ...config }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export class StepResponse {
|
|
110
|
+
constructor(output, compensateInput) {
|
|
111
|
+
this.output = output
|
|
112
|
+
this.compensateInput = compensateInput
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class WorkflowResponse {
|
|
117
|
+
constructor(output) {
|
|
118
|
+
this.output = output
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function createStep(name, invokeFn, compensateFn) {
|
|
123
|
+
const stepFn = (input) => ({
|
|
124
|
+
__stepName: name,
|
|
125
|
+
input,
|
|
126
|
+
invokeFn,
|
|
127
|
+
compensateFn,
|
|
128
|
+
})
|
|
129
|
+
stepFn.__stepName = name
|
|
130
|
+
stepFn.invoke = invokeFn
|
|
131
|
+
stepFn.compensate = compensateFn
|
|
132
|
+
return stepFn
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function createWorkflow(name, composerFn) {
|
|
136
|
+
const wf = (container) => ({
|
|
137
|
+
async run({ input } = {}) {
|
|
138
|
+
const composed = composerFn(input)
|
|
139
|
+
const stepDescriptor =
|
|
140
|
+
composed instanceof WorkflowResponse ? composed.output : composed
|
|
141
|
+
if (stepDescriptor && typeof stepDescriptor.invokeFn === "function") {
|
|
142
|
+
const stepRes = await stepDescriptor.invokeFn(stepDescriptor.input, {
|
|
143
|
+
container,
|
|
144
|
+
})
|
|
145
|
+
const result =
|
|
146
|
+
stepRes instanceof StepResponse ? stepRes.output : stepRes
|
|
147
|
+
return {
|
|
148
|
+
result,
|
|
149
|
+
compensate: async () => {
|
|
150
|
+
if (typeof stepDescriptor.compensateFn === "function") {
|
|
151
|
+
await stepDescriptor.compensateFn(stepRes?.compensateInput, {
|
|
152
|
+
container,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { result: stepDescriptor }
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
wf.getName = () => name
|
|
162
|
+
return wf
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export class Migration {
|
|
166
|
+
constructor() {
|
|
167
|
+
this.queries = []
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
addSql(sql) {
|
|
171
|
+
this.queries.push(sql)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const createZodChain = (constraints = {}) => {
|
|
176
|
+
const validators = [...(constraints.validators ?? [])]
|
|
177
|
+
const transforms = [...(constraints.transforms ?? [])]
|
|
178
|
+
const schema = {
|
|
179
|
+
shape: constraints.shape ?? {},
|
|
180
|
+
min: (n) =>
|
|
181
|
+
createZodChain({
|
|
182
|
+
...constraints,
|
|
183
|
+
validators: [
|
|
184
|
+
...validators,
|
|
185
|
+
(v) => {
|
|
186
|
+
if (typeof v === "string" && v.length < n) {
|
|
187
|
+
throw new Error(`Min length ${n}`)
|
|
188
|
+
}
|
|
189
|
+
if (typeof v === "number" && v < n) {
|
|
190
|
+
throw new Error(`Min value ${n}`)
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
}),
|
|
195
|
+
max: (n) =>
|
|
196
|
+
createZodChain({
|
|
197
|
+
...constraints,
|
|
198
|
+
validators: [
|
|
199
|
+
...validators,
|
|
200
|
+
(v) => {
|
|
201
|
+
if (typeof v === "string" && v.length > n) {
|
|
202
|
+
throw new Error(`Max length ${n}`)
|
|
203
|
+
}
|
|
204
|
+
if (typeof v === "number" && v > n) {
|
|
205
|
+
throw new Error(`Max value ${n}`)
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(v) && v.length > n) {
|
|
208
|
+
throw new Error(`Max items ${n}`)
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
}),
|
|
213
|
+
int: () =>
|
|
214
|
+
createZodChain({
|
|
215
|
+
...constraints,
|
|
216
|
+
validators: [
|
|
217
|
+
...validators,
|
|
218
|
+
(v) => {
|
|
219
|
+
if (typeof v === "number" && !Number.isInteger(v)) {
|
|
220
|
+
throw new Error("Expected integer")
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
}),
|
|
225
|
+
positive: () => schema,
|
|
226
|
+
nonnegative: () => schema,
|
|
227
|
+
email: () => schema,
|
|
228
|
+
url: () => schema,
|
|
229
|
+
refine: (fn, opts) =>
|
|
230
|
+
createZodChain({
|
|
231
|
+
...constraints,
|
|
232
|
+
validators: [
|
|
233
|
+
...(constraints.validators ?? []),
|
|
234
|
+
(v) => {
|
|
235
|
+
if (!fn(v)) {
|
|
236
|
+
throw new Error(
|
|
237
|
+
(typeof opts === "string" ? opts : opts?.message) ||
|
|
238
|
+
"Validation failed"
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
optional: () => createZodChain({ ...constraints, optional: true }),
|
|
245
|
+
nullable: () => createZodChain({ ...constraints, nullable: true }),
|
|
246
|
+
default: (defVal) =>
|
|
247
|
+
createZodChain({ ...constraints, optional: true, defaultValue: defVal }),
|
|
248
|
+
partial: () => createZodChain({ ...constraints, partial: true }),
|
|
249
|
+
omit: (keys = {}) => {
|
|
250
|
+
const nextShape = { ...constraints.shape }
|
|
251
|
+
for (const k of Object.keys(keys)) {
|
|
252
|
+
if (keys[k]) delete nextShape[k]
|
|
253
|
+
}
|
|
254
|
+
return createZodChain({ ...constraints, shape: nextShape })
|
|
255
|
+
},
|
|
256
|
+
passthrough: () => schema,
|
|
257
|
+
parse: (val) => {
|
|
258
|
+
const res = schema.safeParse(val)
|
|
259
|
+
if (!res.success) {
|
|
260
|
+
throw new Error(res.error.issues.map((i) => i.message).join("; "))
|
|
261
|
+
}
|
|
262
|
+
return res.data
|
|
263
|
+
},
|
|
264
|
+
safeParse: (rawVal) => {
|
|
265
|
+
try {
|
|
266
|
+
let val = rawVal
|
|
267
|
+
if (val === undefined) {
|
|
268
|
+
if (constraints.defaultValue !== undefined) {
|
|
269
|
+
return { success: true, data: constraints.defaultValue }
|
|
270
|
+
}
|
|
271
|
+
if (constraints.optional) {
|
|
272
|
+
return { success: true, data: undefined }
|
|
273
|
+
}
|
|
274
|
+
throw new Error("Required")
|
|
275
|
+
}
|
|
276
|
+
if (val === null && constraints.nullable) {
|
|
277
|
+
return { success: true, data: null }
|
|
278
|
+
}
|
|
279
|
+
for (const tf of transforms) {
|
|
280
|
+
val = tf(val)
|
|
281
|
+
}
|
|
282
|
+
for (const fn of validators) {
|
|
283
|
+
fn(val)
|
|
284
|
+
}
|
|
285
|
+
if (constraints.shape && typeof val === "object" && val !== null) {
|
|
286
|
+
const out = { ...val }
|
|
287
|
+
for (const [k, fieldSchema] of Object.entries(constraints.shape)) {
|
|
288
|
+
if (constraints.partial && out[k] === undefined) continue
|
|
289
|
+
const r = fieldSchema.safeParse(out[k])
|
|
290
|
+
if (!r.success) {
|
|
291
|
+
return {
|
|
292
|
+
success: false,
|
|
293
|
+
error: {
|
|
294
|
+
issues: r.error.issues.map((iss) => ({
|
|
295
|
+
path: [k, ...(iss.path ?? [])],
|
|
296
|
+
message: iss.message,
|
|
297
|
+
})),
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (r.data !== undefined) {
|
|
302
|
+
out[k] = r.data
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return { success: true, data: out }
|
|
306
|
+
}
|
|
307
|
+
if (constraints.item && Array.isArray(val)) {
|
|
308
|
+
const arr = []
|
|
309
|
+
for (let i = 0; i < val.length; i++) {
|
|
310
|
+
const r = constraints.item.safeParse(val[i])
|
|
311
|
+
if (!r.success) {
|
|
312
|
+
return {
|
|
313
|
+
success: false,
|
|
314
|
+
error: {
|
|
315
|
+
issues: r.error.issues.map((iss) => ({
|
|
316
|
+
path: [i, ...(iss.path ?? [])],
|
|
317
|
+
message: iss.message,
|
|
318
|
+
})),
|
|
319
|
+
},
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
arr.push(r.data)
|
|
323
|
+
}
|
|
324
|
+
return { success: true, data: arr }
|
|
325
|
+
}
|
|
326
|
+
return { success: true, data: val }
|
|
327
|
+
} catch (err) {
|
|
328
|
+
return {
|
|
329
|
+
success: false,
|
|
330
|
+
error: {
|
|
331
|
+
issues: [
|
|
332
|
+
{
|
|
333
|
+
path: [],
|
|
334
|
+
message: err instanceof Error ? err.message : String(err),
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
}
|
|
342
|
+
return schema
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export const z = {
|
|
346
|
+
object: (shape) => createZodChain({ shape }),
|
|
347
|
+
string: () =>
|
|
348
|
+
createZodChain({
|
|
349
|
+
validators: [
|
|
350
|
+
(v) => {
|
|
351
|
+
if (typeof v !== "string") throw new Error("Expected string")
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
}),
|
|
355
|
+
number: () =>
|
|
356
|
+
createZodChain({
|
|
357
|
+
validators: [
|
|
358
|
+
(v) => {
|
|
359
|
+
if (typeof v !== "number" || Number.isNaN(v)) {
|
|
360
|
+
throw new Error("Expected number")
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
}),
|
|
365
|
+
boolean: () => createZodChain(),
|
|
366
|
+
enum: (values) =>
|
|
367
|
+
createZodChain({
|
|
368
|
+
validators: [
|
|
369
|
+
(v) => {
|
|
370
|
+
if (!values.includes(v)) throw new Error("Invalid enum value")
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
}),
|
|
374
|
+
array: (item) => createZodChain({ item }),
|
|
375
|
+
record: (key, val) => createZodChain({ key, val }),
|
|
376
|
+
unknown: () => createZodChain(),
|
|
377
|
+
union: (items) => createZodChain({ items }),
|
|
378
|
+
coerce: {
|
|
379
|
+
number: () =>
|
|
380
|
+
createZodChain({
|
|
381
|
+
transforms: [
|
|
382
|
+
(v) => {
|
|
383
|
+
if (typeof v === "string" && v.trim() === "") {
|
|
384
|
+
return Number.NaN
|
|
385
|
+
}
|
|
386
|
+
return Number(v)
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
validators: [
|
|
390
|
+
(v) => {
|
|
391
|
+
if (typeof v !== "number" || Number.isNaN(v)) {
|
|
392
|
+
throw new Error("Expected number")
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
}),
|
|
397
|
+
},
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function defineMiddlewares(config) {
|
|
401
|
+
return config
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function validateAndTransformBody(schema) {
|
|
405
|
+
return schema
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function defineRouteConfig(config) {
|
|
409
|
+
return config
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export function defineWidgetConfig(config) {
|
|
413
|
+
return config
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export const CORE_LAYOUT_IDS = {
|
|
417
|
+
SINGLE_COLUMN: "single_column",
|
|
418
|
+
TWO_COLUMN: "two_column",
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export const LayoutComposer = Object.assign((props) => props, {
|
|
422
|
+
Entry: (props) => props,
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
export const SectionRow = (props) => props
|
|
426
|
+
export const RouteDrawer = Object.assign((props) => props, {
|
|
427
|
+
Header: (props) => props,
|
|
428
|
+
Body: (props) => props,
|
|
429
|
+
Footer: (props) => props,
|
|
430
|
+
Close: (props) => props,
|
|
431
|
+
Form: (props) => props,
|
|
432
|
+
})
|
|
433
|
+
export const RouteFocusModal = Object.assign((props) => props, {
|
|
434
|
+
Header: (props) => props,
|
|
435
|
+
Body: (props) => props,
|
|
436
|
+
Footer: (props) => props,
|
|
437
|
+
Close: (props) => props,
|
|
438
|
+
Form: (props) => props,
|
|
439
|
+
})
|
|
440
|
+
export const Form = {
|
|
441
|
+
Field: (props) => props,
|
|
442
|
+
Item: (props) => props,
|
|
443
|
+
Label: (props) => props,
|
|
444
|
+
Control: (props) => props,
|
|
445
|
+
ErrorMessage: (props) => props,
|
|
446
|
+
}
|
|
447
|
+
export const KeyboundForm = (props) => props
|
|
448
|
+
export const useRouteModal = () => ({ handleSuccess: () => {} })
|
|
449
|
+
export const zodResolver = () => () => ({ values: {}, errors: {} })
|
|
450
|
+
export const useForm = () => ({
|
|
451
|
+
control: {},
|
|
452
|
+
watch: () => "instagram",
|
|
453
|
+
handleSubmit: (fn) => fn,
|
|
454
|
+
})
|
|
455
|
+
export const useNavigate = () => () => {}
|
|
456
|
+
|
|
457
|
+
export const ArrowPath = "ArrowPath"
|
|
458
|
+
export const BuildingStorefront = "BuildingStorefront"
|
|
459
|
+
export const CheckCircle = "CheckCircle"
|
|
460
|
+
export const DocumentText = "DocumentText"
|
|
461
|
+
export const PlaySolid = "PlaySolid"
|
|
462
|
+
export const PlusMini = "PlusMini"
|
|
463
|
+
export const Tag = "Tag"
|
|
464
|
+
export const Trash = "Trash"
|
|
465
|
+
export const Users = "Users"
|
|
466
|
+
|
|
467
|
+
export const Badge = "Badge"
|
|
468
|
+
export const Button = "Button"
|
|
469
|
+
export const clx = (...args) => args.filter(Boolean).join(" ")
|
|
470
|
+
export const Container = "Container"
|
|
471
|
+
export const Heading = "Heading"
|
|
472
|
+
export const Input = "Input"
|
|
473
|
+
export const Label = "Label"
|
|
474
|
+
export const Select = Object.assign("Select", {
|
|
475
|
+
Trigger: "Select.Trigger",
|
|
476
|
+
Value: "Select.Value",
|
|
477
|
+
Content: "Select.Content",
|
|
478
|
+
Item: "Select.Item",
|
|
479
|
+
})
|
|
480
|
+
export const Skeleton = "Skeleton"
|
|
481
|
+
export const StatusBadge = "StatusBadge"
|
|
482
|
+
export const Switch = "Switch"
|
|
483
|
+
export const Table = Object.assign("Table", {
|
|
484
|
+
Header: "Table.Header",
|
|
485
|
+
Row: "Table.Row",
|
|
486
|
+
HeaderCell: "Table.HeaderCell",
|
|
487
|
+
Body: "Table.Body",
|
|
488
|
+
Cell: "Table.Cell",
|
|
489
|
+
})
|
|
490
|
+
export const Text = "Text"
|
|
491
|
+
export const Toaster = "Toaster"
|
|
492
|
+
export const toast = {
|
|
493
|
+
success: () => {},
|
|
494
|
+
error: () => {},
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export const useState = (init) => [
|
|
498
|
+
typeof init === "function" ? init() : init,
|
|
499
|
+
() => {},
|
|
500
|
+
]
|
|
501
|
+
export const useEffect = () => {}
|
|
502
|
+
export const useCallback = (fn) => fn
|
|
503
|
+
export const useMemo = (fn) => fn()
|
|
504
|
+
export const useRef = (init) => ({ current: init })
|
|
505
|
+
export const createElement = (type, props, ...children) => ({
|
|
506
|
+
type,
|
|
507
|
+
props: { ...props, children },
|
|
508
|
+
})
|
|
509
|
+
export const jsx = createElement
|
|
510
|
+
export const jsxs = createElement
|
|
511
|
+
export const Fragment = "Fragment"
|
|
512
|
+
|
|
513
|
+
export const useTranslation = () => ({
|
|
514
|
+
t: (key) => key,
|
|
515
|
+
i18n: {
|
|
516
|
+
language: "en",
|
|
517
|
+
resolvedLanguage: "en",
|
|
518
|
+
changeLanguage: async () => {},
|
|
519
|
+
dir: () => "ltr",
|
|
520
|
+
},
|
|
521
|
+
ready: true,
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
export default {
|
|
525
|
+
useState,
|
|
526
|
+
useEffect,
|
|
527
|
+
useCallback,
|
|
528
|
+
useMemo,
|
|
529
|
+
useRef,
|
|
530
|
+
createElement,
|
|
531
|
+
Fragment,
|
|
532
|
+
useTranslation,
|
|
533
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createRequire, registerHooks } from "node:module"
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
4
|
+
import { dirname, resolve as resolvePath } from "node:path"
|
|
5
|
+
|
|
6
|
+
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const shimUrl = pathToFileURL(resolvePath(currentDir, "medusa-shim.mjs")).href
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
9
|
+
|
|
10
|
+
let ts = null
|
|
11
|
+
try {
|
|
12
|
+
ts = require("typescript")
|
|
13
|
+
} catch {
|
|
14
|
+
const candidates = [
|
|
15
|
+
resolvePath(
|
|
16
|
+
currentDir,
|
|
17
|
+
"../../../strapi-plugin-tiptap-editor/node_modules/typescript"
|
|
18
|
+
),
|
|
19
|
+
resolvePath(
|
|
20
|
+
currentDir,
|
|
21
|
+
"../../../../gweb-uniblog-author-prod/node_modules/typescript"
|
|
22
|
+
),
|
|
23
|
+
]
|
|
24
|
+
for (const candidate of candidates) {
|
|
25
|
+
if (existsSync(candidate)) {
|
|
26
|
+
ts = require(candidate)
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
registerHooks({
|
|
33
|
+
resolve(specifier, context, nextResolve) {
|
|
34
|
+
if (
|
|
35
|
+
specifier.startsWith("@medusajs/") ||
|
|
36
|
+
specifier === "@mikro-orm/migrations" ||
|
|
37
|
+
specifier === "react" ||
|
|
38
|
+
specifier.startsWith("react/") ||
|
|
39
|
+
specifier === "react-i18next" ||
|
|
40
|
+
specifier === "react-router-dom" ||
|
|
41
|
+
specifier === "react-hook-form" ||
|
|
42
|
+
specifier.startsWith("@hookform/") ||
|
|
43
|
+
specifier === "zod"
|
|
44
|
+
) {
|
|
45
|
+
return { url: shimUrl, shortCircuit: true }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
(specifier.startsWith("./") || specifier.startsWith("../")) &&
|
|
50
|
+
context.parentURL
|
|
51
|
+
) {
|
|
52
|
+
const parentDir = dirname(fileURLToPath(context.parentURL))
|
|
53
|
+
const baseCandidate = resolvePath(parentDir, specifier)
|
|
54
|
+
const withoutJs = baseCandidate.endsWith(".js")
|
|
55
|
+
? baseCandidate.slice(0, -3)
|
|
56
|
+
: baseCandidate
|
|
57
|
+
|
|
58
|
+
const candidates = [
|
|
59
|
+
`${withoutJs}.ts`,
|
|
60
|
+
`${withoutJs}.tsx`,
|
|
61
|
+
`${baseCandidate}.ts`,
|
|
62
|
+
`${baseCandidate}.tsx`,
|
|
63
|
+
resolvePath(withoutJs, "index.ts"),
|
|
64
|
+
resolvePath(withoutJs, "index.tsx"),
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
if (existsSync(candidate)) {
|
|
69
|
+
return nextResolve(pathToFileURL(candidate).href, context)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return nextResolve(specifier, context)
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
load(url, context, nextLoad) {
|
|
78
|
+
if (url.endsWith(".json") && !url.includes("/node_modules/")) {
|
|
79
|
+
const filePath = fileURLToPath(url)
|
|
80
|
+
const source = readFileSync(filePath, "utf8")
|
|
81
|
+
return {
|
|
82
|
+
format: "module",
|
|
83
|
+
source: `export default ${source}`,
|
|
84
|
+
shortCircuit: true,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (url.endsWith(".tsx")) {
|
|
88
|
+
const filePath = fileURLToPath(url)
|
|
89
|
+
const source = readFileSync(filePath, "utf8")
|
|
90
|
+
if (ts) {
|
|
91
|
+
const transpiled = ts.transpileModule(source, {
|
|
92
|
+
compilerOptions: {
|
|
93
|
+
module: ts.ModuleKind.ESNext,
|
|
94
|
+
target: ts.ScriptTarget.ES2022,
|
|
95
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
96
|
+
},
|
|
97
|
+
fileName: filePath,
|
|
98
|
+
})
|
|
99
|
+
return {
|
|
100
|
+
format: "module",
|
|
101
|
+
source: transpiled.outputText,
|
|
102
|
+
shortCircuit: true,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const lines = []
|
|
106
|
+
const configMatch = source.match(
|
|
107
|
+
/export\s+const\s+config\s*=\s*(defineRouteConfig|defineWidgetConfig)\s*\(\{[\s\S]*?\}\)/
|
|
108
|
+
)
|
|
109
|
+
if (configMatch) {
|
|
110
|
+
lines.push(
|
|
111
|
+
`import { defineRouteConfig, defineWidgetConfig } from "@medusajs/admin-sdk"`
|
|
112
|
+
)
|
|
113
|
+
lines.push(
|
|
114
|
+
`import { ArrowPath, BuildingStorefront, CheckCircle, DocumentText, PlaySolid, PlusMini, Tag, Trash, Users } from "@medusajs/icons"`
|
|
115
|
+
)
|
|
116
|
+
lines.push(configMatch[0])
|
|
117
|
+
}
|
|
118
|
+
if (/export\s+const\s+handle\s*=/.test(source)) {
|
|
119
|
+
lines.push(`export const handle = { breadcrumb: () => null }`)
|
|
120
|
+
}
|
|
121
|
+
const namedExports = [
|
|
122
|
+
...source.matchAll(/export\s+(?:const|function)\s+([A-Za-z0-9_]+)\b/g),
|
|
123
|
+
]
|
|
124
|
+
for (const match of namedExports) {
|
|
125
|
+
const name = match[1]
|
|
126
|
+
if (name !== "config" && name !== "handle") {
|
|
127
|
+
lines.push(`export const ${name} = () => null`)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (/export\s+default\b/.test(source)) {
|
|
131
|
+
lines.push(`export default function Component() { return null }`)
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
format: "module",
|
|
135
|
+
source: lines.join("\n"),
|
|
136
|
+
shortCircuit: true,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return nextLoad(url, context)
|
|
140
|
+
},
|
|
141
|
+
})
|