@vicacha-devs/medusa-plugin-stories 0.0.0-stage → 0.0.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.
Files changed (143) hide show
  1. package/.medusa/server/src/__tests__/stories-plugin.spec.js +358 -0
  2. package/.medusa/server/src/admin/i18n/index.js +35 -0
  3. package/.medusa/server/src/admin/i18n/json/ar.json +196 -0
  4. package/.medusa/server/src/admin/i18n/json/de.json +196 -0
  5. package/.medusa/server/src/admin/i18n/json/en.json +196 -0
  6. package/.medusa/server/src/admin/i18n/json/es.json +196 -0
  7. package/.medusa/server/src/admin/i18n/json/fr.json +196 -0
  8. package/.medusa/server/src/admin/i18n/json/it.json +196 -0
  9. package/.medusa/server/src/admin/i18n/json/nl.json +196 -0
  10. package/.medusa/server/src/admin/i18n/json/pl.json +196 -0
  11. package/.medusa/server/src/admin/i18n/json/pt.json +196 -0
  12. package/.medusa/server/src/admin/i18n/json/tr.json +196 -0
  13. package/.medusa/server/src/admin/index.cjs +4699 -0
  14. package/.medusa/server/src/admin/index.js +4699 -0
  15. package/.medusa/server/src/api/admin/plugin/route.js +4 -0
  16. package/.medusa/server/src/api/admin/stories/[id]/hotspots/route.js +14 -0
  17. package/.medusa/server/src/api/admin/stories/[id]/route.js +27 -0
  18. package/.medusa/server/src/api/admin/stories/[id]/stickers/route.js +14 -0
  19. package/.medusa/server/src/api/admin/stories/analytics/route.js +7 -0
  20. package/.medusa/server/src/api/admin/stories/groups/[id]/route.js +23 -0
  21. package/.medusa/server/src/api/admin/stories/groups/route.js +15 -0
  22. package/.medusa/server/src/api/admin/stories/route.js +21 -0
  23. package/.medusa/server/src/api/middlewares.js +58 -0
  24. package/.medusa/server/src/api/store/plugin/route.js +4 -0
  25. package/.medusa/server/src/api/store/stories/[id]/events/route.js +12 -0
  26. package/.medusa/server/src/api/store/stories/[id]/interact/route.js +14 -0
  27. package/.medusa/server/src/api/store/stories/route.js +33 -0
  28. package/.medusa/server/src/api/validators.js +136 -0
  29. package/.medusa/server/src/hooks/index.js +213 -0
  30. package/.medusa/server/src/hooks/use-sdk-primitives.js +93 -0
  31. package/.medusa/server/src/index.js +6 -0
  32. package/.medusa/server/src/jobs/expire-ephemeral-stories.js +10 -0
  33. package/.medusa/server/src/modules/index.js +7 -0
  34. package/.medusa/server/src/modules/stories/index.js +3 -0
  35. package/.medusa/server/src/modules/story/index.js +23 -0
  36. package/.medusa/server/src/modules/story/migrations/Migration20260514000000.js +181 -0
  37. package/.medusa/server/src/modules/story/models/index.js +141 -0
  38. package/.medusa/server/src/modules/story/service.js +673 -0
  39. package/.medusa/server/src/modules/story/types.js +3 -0
  40. package/.medusa/server/src/modules/story/utils/security.js +76 -0
  41. package/.medusa/server/src/rbac.js +75 -0
  42. package/.medusa/server/src/sdk/index.js +148 -0
  43. package/.medusa/server/src/subscribers/product-deleted.js +11 -0
  44. package/.medusa/server/src/types/index.js +2 -0
  45. package/.medusa/server/src/ui/index.js +5 -0
  46. package/.medusa/server/src/ui/story-hotspot-pin.js +43 -0
  47. package/.medusa/server/src/ui/story-player-modal.js +104 -0
  48. package/.medusa/server/src/ui/story-product-sheet.js +7 -0
  49. package/.medusa/server/src/ui/story-rings-bar.js +42 -0
  50. package/.medusa/server/src/workflows/index.js +50 -0
  51. package/LICENSE +21 -0
  52. package/README.md +246 -2
  53. package/package.json +127 -3
  54. package/src/__tests__/medusa-shim.mjs +533 -0
  55. package/src/__tests__/register-ts-resolver.mjs +141 -0
  56. package/src/__tests__/stories-plugin.spec.ts +526 -0
  57. package/src/admin/README.md +94 -0
  58. package/src/admin/components/analytics-tab.tsx +225 -0
  59. package/src/admin/components/canvas-editor-tab.tsx +77 -0
  60. package/src/admin/components/hotspot-form-section.tsx +155 -0
  61. package/src/admin/components/index.ts +15 -0
  62. package/src/admin/components/overview-cards.tsx +96 -0
  63. package/src/admin/components/product-stories-card.tsx +123 -0
  64. package/src/admin/components/rbac-guard.tsx +153 -0
  65. package/src/admin/components/slide-form-section.tsx +187 -0
  66. package/src/admin/components/slide-preview-canvas.tsx +166 -0
  67. package/src/admin/components/slide-timeline-section.tsx +126 -0
  68. package/src/admin/components/sticker-form-section.tsx +201 -0
  69. package/src/admin/components/sticker-list-section.tsx +113 -0
  70. package/src/admin/components/stickers-tab.tsx +34 -0
  71. package/src/admin/components/story-ring-form.tsx +241 -0
  72. package/src/admin/components/story-rings-tab.tsx +204 -0
  73. package/src/admin/components/story-rings-table.tsx +222 -0
  74. package/src/admin/components/studio-header.tsx +67 -0
  75. package/src/admin/hooks/use-product-stories.ts +71 -0
  76. package/src/admin/hooks/use-stories-studio.ts +439 -0
  77. package/src/admin/i18n/README.md +84 -0
  78. package/src/admin/i18n/index.ts +36 -0
  79. package/src/admin/i18n/json/ar.json +196 -0
  80. package/src/admin/i18n/json/de.json +196 -0
  81. package/src/admin/i18n/json/en.json +196 -0
  82. package/src/admin/i18n/json/es.json +196 -0
  83. package/src/admin/i18n/json/fr.json +196 -0
  84. package/src/admin/i18n/json/it.json +196 -0
  85. package/src/admin/i18n/json/nl.json +196 -0
  86. package/src/admin/i18n/json/pl.json +196 -0
  87. package/src/admin/i18n/json/pt.json +196 -0
  88. package/src/admin/i18n/json/tr.json +196 -0
  89. package/src/admin/routes/stories/analytics/page.tsx +66 -0
  90. package/src/admin/routes/stories/canvas/page.tsx +101 -0
  91. package/src/admin/routes/stories/page.tsx +164 -0
  92. package/src/admin/routes/stories/rings/@create/page.tsx +61 -0
  93. package/src/admin/routes/stories/rings/page.tsx +88 -0
  94. package/src/admin/routes/stories/stickers/page.tsx +74 -0
  95. package/src/admin/tsconfig.json +23 -0
  96. package/src/admin/utils/theme-presets.ts +94 -0
  97. package/src/admin/vite-env.d.ts +1 -0
  98. package/src/admin/widgets/product-stories-widget.tsx +32 -0
  99. package/src/api/README.md +61 -0
  100. package/src/api/admin/plugin/route.ts +5 -0
  101. package/src/api/admin/stories/[id]/hotspots/route.ts +17 -0
  102. package/src/api/admin/stories/[id]/route.ts +40 -0
  103. package/src/api/admin/stories/[id]/stickers/route.ts +20 -0
  104. package/src/api/admin/stories/analytics/route.ts +8 -0
  105. package/src/api/admin/stories/groups/[id]/route.ts +30 -0
  106. package/src/api/admin/stories/groups/route.ts +18 -0
  107. package/src/api/admin/stories/route.ts +31 -0
  108. package/src/api/middlewares.ts +73 -0
  109. package/src/api/store/plugin/route.ts +5 -0
  110. package/src/api/store/stories/[id]/events/route.ts +14 -0
  111. package/src/api/store/stories/[id]/interact/route.ts +18 -0
  112. package/src/api/store/stories/route.ts +44 -0
  113. package/src/api/validators.ts +166 -0
  114. package/src/hooks/index.ts +419 -0
  115. package/src/hooks/use-sdk-primitives.ts +114 -0
  116. package/src/index.ts +14 -0
  117. package/src/jobs/README.md +16 -0
  118. package/src/jobs/expire-ephemeral-stories.ts +14 -0
  119. package/src/links/README.md +18 -0
  120. package/src/modules/README.md +46 -0
  121. package/src/modules/index.ts +15 -0
  122. package/src/modules/stories/index.ts +11 -0
  123. package/src/modules/story/index.ts +34 -0
  124. package/src/modules/story/migrations/Migration20260514000000.ts +196 -0
  125. package/src/modules/story/models/index.ts +146 -0
  126. package/src/modules/story/service.ts +1052 -0
  127. package/src/modules/story/types.ts +190 -0
  128. package/src/modules/story/utils/security.ts +100 -0
  129. package/src/providers/README.md +14 -0
  130. package/src/rbac.ts +89 -0
  131. package/src/sdk/index.ts +233 -0
  132. package/src/subscribers/README.md +16 -0
  133. package/src/subscribers/product-deleted.ts +15 -0
  134. package/src/types/index.ts +1 -0
  135. package/src/types/medusa-ui.d.ts +451 -0
  136. package/src/ui/index.ts +4 -0
  137. package/src/ui/story-hotspot-pin.tsx +122 -0
  138. package/src/ui/story-player-modal.tsx +361 -0
  139. package/src/ui/story-product-sheet.tsx +85 -0
  140. package/src/ui/story-rings-bar.tsx +113 -0
  141. package/src/workflows/README.md +19 -0
  142. package/src/workflows/index.ts +217 -0
  143. package/tsconfig.json +39 -0
@@ -0,0 +1,526 @@
1
+ import { describe, it } from "node:test"
2
+ import assert from "node:assert/strict"
3
+ import { MedusaError } from "@medusajs/framework/utils"
4
+ import {
5
+ clampCoordinatePercent,
6
+ sanitizeHttpUrl,
7
+ sanitizeRingColor,
8
+ slugifyStoryHandle,
9
+ } from "../modules/story/utils/security"
10
+ import { StoriesModuleService } from "../modules/story/service"
11
+ import {
12
+ CreateStoryGroupSchema,
13
+ CreateStoryHotspotSchema,
14
+ CreateStorySlideSchema,
15
+ CreateStoryStickerSchema,
16
+ DeleteStoryHotspotSchema,
17
+ DeleteStoryStickerSchema,
18
+ InteractWithStoryStickerSchema,
19
+ RecordStoryEngagementSchema,
20
+ } from "../api/validators"
21
+ import middlewares from "../api/middlewares"
22
+ import { createStoriesSdk } from "../sdk"
23
+ import adminI18n, { SUPPORTED_UI_LOCALES } from "../admin/i18n"
24
+
25
+ describe("medusa-plugin-stories security utilities", () => {
26
+ it("accepts http/https and relative store paths while rejecting javascript:/data: URLs with MedusaError", () => {
27
+ assert.equal(
28
+ sanitizeHttpUrl("https://cdn.example.com/reel.mp4"),
29
+ "https://cdn.example.com/reel.mp4"
30
+ )
31
+ assert.equal(
32
+ sanitizeHttpUrl("/products/classic-hoodie", "link_url", true),
33
+ "/products/classic-hoodie"
34
+ )
35
+
36
+ assert.throws(
37
+ () => sanitizeHttpUrl("javascript:alert(1)"),
38
+ (err: unknown) =>
39
+ err instanceof MedusaError &&
40
+ err.type === MedusaError.Types.INVALID_DATA
41
+ )
42
+ assert.throws(
43
+ () => sanitizeHttpUrl("data:text/html,<script>alert(1)</script>"),
44
+ (err: unknown) =>
45
+ err instanceof MedusaError &&
46
+ err.type === MedusaError.Types.INVALID_DATA
47
+ )
48
+ })
49
+
50
+ it("clamps hotspot coordinates to [0, 100] and throws MedusaError on non-finite values", () => {
51
+ assert.equal(clampCoordinatePercent(-15), 0)
52
+ assert.equal(clampCoordinatePercent(145), 100)
53
+ assert.equal(clampCoordinatePercent(42.345), 42.35)
54
+
55
+ assert.throws(
56
+ () => clampCoordinatePercent(Number.NaN),
57
+ (err: unknown) =>
58
+ err instanceof MedusaError &&
59
+ err.type === MedusaError.Types.INVALID_DATA
60
+ )
61
+ })
62
+
63
+ it("validates custom CSS hex ring colors and slugifies handles", () => {
64
+ assert.equal(sanitizeRingColor("#ff0050"), "#ff0050")
65
+ assert.equal(
66
+ slugifyStoryHandle("Summer Lookbook '26!"),
67
+ "summer-lookbook-26"
68
+ )
69
+
70
+ assert.throws(
71
+ () => sanitizeRingColor("expression(alert(1))"),
72
+ (err: unknown) =>
73
+ err instanceof MedusaError &&
74
+ err.type === MedusaError.Types.INVALID_DATA
75
+ )
76
+ })
77
+ })
78
+
79
+ describe("StoriesModuleService — groups, slides, hotspots, stickers, funnel & expiration", () => {
80
+ it("manages Story Highlight Rings and preserves @bambiste/medusa-stories listActive() compatibility", async () => {
81
+ const service = new StoriesModuleService({}, {})
82
+
83
+ const createdGroup = await service.createGroup({
84
+ title: "VIP Archive Drops",
85
+ placement: "home",
86
+ ring_theme: "sunset",
87
+ })
88
+ assert.equal(createdGroup.handle, "vip-archive-drops")
89
+
90
+ const createdSlide = await service.createSlide({
91
+ group_id: createdGroup.id,
92
+ title: "Limited Metallic Jacket",
93
+ media_type: "video",
94
+ media_url: "https://cdn.example.com/metallic.mp4",
95
+ link_url: "/products/metallic-jacket",
96
+ link_text: "Shop Limited Drop",
97
+ })
98
+ assert.equal(createdSlide.group_id, createdGroup.id)
99
+ assert.equal(createdSlide.link_url, "/products/metallic-jacket")
100
+
101
+ const activeStories = await service.listActive()
102
+ assert.equal(activeStories.length, 1)
103
+ assert.equal(activeStories[0].title, "Limited Metallic Jacket")
104
+ })
105
+
106
+ it("pins X/Y product hotspots, enforces max_hotspots_per_slide, and removes them cleanly", async () => {
107
+ const service = new StoriesModuleService({}, { max_hotspots_per_slide: 2 })
108
+
109
+ const slide = await service.createSlide({
110
+ title: "Runway Look #1",
111
+ media_type: "image",
112
+ media_url: "https://images.unsplash.com/photo-1515886657613-9f3515b0c78f",
113
+ })
114
+
115
+ const h1 = await service.addHotspot(slide.id, {
116
+ product_id: "prod_coat",
117
+ product_title: "Trench Coat",
118
+ x_percent: 35.5,
119
+ y_percent: 48.2,
120
+ price_formatted: "$240.00",
121
+ })
122
+ assert.equal(h1.x_percent, 35.5)
123
+
124
+ const h2 = await service.addHotspot(slide.id, {
125
+ product_id: "prod_boots",
126
+ product_title: "Chelsea Boots",
127
+ x_percent: 52,
128
+ y_percent: 82,
129
+ price_formatted: "$180.00",
130
+ })
131
+ assert.equal(h2.product_id, "prod_boots")
132
+
133
+ await assert.rejects(
134
+ () =>
135
+ service.addHotspot(slide.id, {
136
+ product_id: "prod_bag",
137
+ product_title: "Crossbody Bag",
138
+ x_percent: 25,
139
+ y_percent: 60,
140
+ }),
141
+ (err: unknown) =>
142
+ err instanceof MedusaError &&
143
+ err.type === MedusaError.Types.INVALID_DATA
144
+ )
145
+
146
+ const hydrated = await service.hydrateSlide(slide)
147
+ assert.equal(hydrated.hotspots?.length, 2)
148
+
149
+ const removed = await service.removeHotspot(h1.id, slide.id)
150
+ assert.equal(removed.deleted, true)
151
+
152
+ const cleaned = await service.removeHotspotsByProductId("prod_boots")
153
+ assert.equal(cleaned.removed_count, 1)
154
+ })
155
+
156
+ it("handles interactive Poll stickers, sticker deletion, and records conversion funnel analytics", async () => {
157
+ const service = new StoriesModuleService({}, {})
158
+
159
+ const group = await service.createGroup({
160
+ title: "Drop Polls",
161
+ placement: "home",
162
+ })
163
+
164
+ const slide = await service.createSlide({
165
+ group_id: group.id,
166
+ title: "Flash Sale Poll",
167
+ media_type: "image",
168
+ media_url: "https://images.unsplash.com/photo-1509631179647-0177331693ae",
169
+ })
170
+
171
+ const pollSticker = await service.addSticker(slide.id, {
172
+ type: "poll",
173
+ prompt: "Which colorway next?",
174
+ options: [
175
+ { id: "opt_obsidian", label: "Obsidian Black" },
176
+ { id: "opt_sage", label: "Sage Green" },
177
+ ],
178
+ })
179
+
180
+ const updatedSticker = await service.interactWithSticker({
181
+ storyId: slide.id,
182
+ stickerId: pollSticker.id,
183
+ optionId: "opt_obsidian",
184
+ })
185
+ assert.equal(updatedSticker.total_interactions, 1)
186
+ assert.equal(updatedSticker.options?.[0].votes, 1)
187
+
188
+ await service.recordEngagementEvent({
189
+ story_id: slide.id,
190
+ event_type: "impression",
191
+ })
192
+ await service.recordEngagementEvent({
193
+ story_id: slide.id,
194
+ event_type: "impression",
195
+ })
196
+ await service.recordEngagementEvent({
197
+ story_id: slide.id,
198
+ event_type: "complete",
199
+ })
200
+ await service.recordEngagementEvent({
201
+ story_id: slide.id,
202
+ event_type: "hotspot_click",
203
+ product_id: "prod_1",
204
+ })
205
+ await service.recordEngagementEvent({
206
+ story_id: slide.id,
207
+ event_type: "add_to_cart",
208
+ product_id: "prod_1",
209
+ })
210
+
211
+ const report = await service.getAnalyticsOverview()
212
+ assert.equal(report.total_impressions, 2)
213
+ assert.equal(report.total_completions, 1)
214
+ assert.equal(report.total_hotspot_clicks, 1)
215
+ assert.equal(report.total_cart_conversions, 1)
216
+ assert.equal(report.overall_completion_rate_pct, 50)
217
+ assert.equal(report.overall_conversion_rate_pct, 50)
218
+
219
+ const removedSticker = await service.removeSticker(pollSticker.id, slide.id)
220
+ assert.equal(removedSticker.deleted, true)
221
+ })
222
+
223
+ it("auto-expires elapsed 24h ephemeral stories via expireOutdatedStories()", async () => {
224
+ const service = new StoriesModuleService({}, {})
225
+
226
+ const pastIso = new Date(Date.now() - 60_000).toISOString()
227
+ const expiredSlide = await service.createSlide({
228
+ title: "Yesterday Flash Drop",
229
+ media_type: "image",
230
+ media_url: "https://images.unsplash.com/photo-1523275335684-37898b6baf30",
231
+ expires_at: pastIso,
232
+ is_active: true,
233
+ })
234
+
235
+ const result = await service.expireOutdatedStories()
236
+ assert.equal(result.expired_slides, 1)
237
+ assert.deepEqual(result.expired_ids, [expiredSlide.id])
238
+ })
239
+ })
240
+
241
+ describe("Centralized API validators & Storefront/Admin StoriesSdk", () => {
242
+ it("exports all Zod schemas in src/api/validators.ts and registers route middlewares", () => {
243
+ assert.ok(CreateStoryGroupSchema)
244
+ assert.ok(CreateStorySlideSchema)
245
+ assert.ok(CreateStoryHotspotSchema)
246
+ assert.ok(DeleteStoryHotspotSchema)
247
+ assert.ok(CreateStoryStickerSchema)
248
+ assert.ok(DeleteStoryStickerSchema)
249
+ assert.ok(RecordStoryEngagementSchema)
250
+ assert.ok(InteractWithStoryStickerSchema)
251
+ assert.ok(Array.isArray(middlewares.routes))
252
+ assert.equal(middlewares.routes.length, 10)
253
+ })
254
+
255
+ it("executes typed StoriesSdk calls for storefront feed and admin sticker deletion", async () => {
256
+ const calls: Array<{ url: string; method: string }> = []
257
+ const sdk = createStoriesSdk({
258
+ baseUrl: "https://medusa.example.com",
259
+ fetchImpl: (async (input: RequestInfo | URL, init?: RequestInit) => {
260
+ calls.push({
261
+ url: String(input),
262
+ method: init?.method ?? "GET",
263
+ })
264
+ return new Response(
265
+ JSON.stringify({
266
+ groups: [],
267
+ stories: [],
268
+ id: "sstk_1",
269
+ deleted: true,
270
+ }),
271
+ { status: 200 }
272
+ )
273
+ }) as typeof fetch,
274
+ })
275
+
276
+ await sdk.store.listStories({
277
+ placement: "collection",
278
+ collection_id: "pcol_summer",
279
+ })
280
+ assert.equal(calls.length, 1)
281
+ assert.equal(
282
+ calls[0].url,
283
+ "https://medusa.example.com/store/stories?placement=collection&collection_id=pcol_summer"
284
+ )
285
+ assert.equal(calls[0].method, "GET")
286
+
287
+ await sdk.admin.removeSticker("stry_1", "sstk_1")
288
+ assert.equal(calls.length, 2)
289
+ assert.equal(
290
+ calls[1].url,
291
+ "https://medusa.example.com/admin/stories/stry_1/stickers"
292
+ )
293
+ assert.equal(calls[1].method, "DELETE")
294
+ })
295
+ })
296
+
297
+ describe("Admin UI Localization (10 Locales Key Parity)", () => {
298
+ it("exports all 10 locales (ar, de, en, es, fr, it, nl, pl, tr, pt) with 100% key parity", () => {
299
+ const bundles = adminI18n
300
+ const locales = SUPPORTED_UI_LOCALES.map((l) => l.code)
301
+
302
+ assert.equal(locales.length, 10)
303
+
304
+ const flattenKeys = (obj: Record<string, unknown>, prefix = ""): string[] =>
305
+ Object.entries(obj).flatMap(([k, v]) => {
306
+ const nextKey = prefix ? `${prefix}.${k}` : k
307
+ if (v && typeof v === "object" && !Array.isArray(v)) {
308
+ return flattenKeys(v as Record<string, unknown>, nextKey)
309
+ }
310
+ return [nextKey]
311
+ })
312
+
313
+ const enKeys = flattenKeys(
314
+ bundles.en.translation as unknown as Record<string, unknown>
315
+ ).toSorted()
316
+ assert.ok(enKeys.length >= 130)
317
+
318
+ for (const localeCode of locales) {
319
+ const entry = bundles[localeCode]
320
+ assert.ok(entry, `Missing locale bundle for ${localeCode}`)
321
+ assert.ok(entry.stories, `Missing "stories" namespace for ${localeCode}`)
322
+ const localeKeys = flattenKeys(
323
+ entry.translation as unknown as Record<string, unknown>
324
+ ).toSorted()
325
+ assert.deepEqual(
326
+ localeKeys,
327
+ enKeys,
328
+ `Locale "${localeCode}" keys do not match "en"`
329
+ )
330
+ }
331
+ })
332
+
333
+ it("exports Medusa v2 Admin routes, breadcrumbs, components, and product widget", async () => {
334
+ const overviewRoute: any = await import(
335
+ "../admin/routes/stories/page.js" as string
336
+ )
337
+ const canvasRoute: any = await import(
338
+ "../admin/routes/stories/canvas/page.js" as string
339
+ )
340
+ const ringsRoute: any = await import(
341
+ "../admin/routes/stories/rings/page.js" as string
342
+ )
343
+ const ringsCreateRoute: any = await import(
344
+ "../admin/routes/stories/rings/@create/page.js" as string
345
+ )
346
+ const stickersRoute: any = await import(
347
+ "../admin/routes/stories/stickers/page.js" as string
348
+ )
349
+ const analyticsRoute: any = await import(
350
+ "../admin/routes/stories/analytics/page.js" as string
351
+ )
352
+ const adminComponents: any = await import(
353
+ "../admin/components/index.js" as string
354
+ )
355
+ const productWidget: any = await import(
356
+ "../admin/widgets/product-stories-widget.js" as string
357
+ )
358
+
359
+ assert.equal(overviewRoute.config.translationNs, "stories")
360
+ assert.equal(typeof overviewRoute.handle.breadcrumb, "function")
361
+ assert.equal(canvasRoute.config.translationNs, "stories")
362
+ assert.equal(typeof canvasRoute.handle.breadcrumb, "function")
363
+ assert.equal(ringsRoute.config.translationNs, "stories")
364
+ assert.equal(typeof ringsRoute.handle.breadcrumb, "function")
365
+ assert.equal(typeof ringsCreateRoute.default, "function")
366
+ assert.equal(stickersRoute.config.translationNs, "stories")
367
+ assert.equal(typeof stickersRoute.handle.breadcrumb, "function")
368
+ assert.equal(analyticsRoute.config.translationNs, "stories")
369
+ assert.equal(typeof analyticsRoute.handle.breadcrumb, "function")
370
+
371
+ assert.equal(typeof adminComponents.StudioHeader, "function")
372
+ assert.equal(typeof adminComponents.StoryRingsTab, "function")
373
+ assert.equal(typeof adminComponents.CanvasEditorTab, "function")
374
+ assert.equal(typeof adminComponents.StickersTab, "function")
375
+ assert.equal(typeof adminComponents.AnalyticsTab, "function")
376
+ assert.equal(typeof adminComponents.ProductStoriesCard, "function")
377
+ assert.equal(productWidget.config.zone, "product.details.after")
378
+ })
379
+ })
380
+
381
+ describe("@bambiste/medusa-stories Compatibility — Migrations, PUT Route, Exports & Fallback", () => {
382
+ it("runs Migration20260514000000 up() and down() for all 5 tables and @bambiste column upgrades", async () => {
383
+ const { Migration20260514000000 } =
384
+ await import("../modules/story/migrations/Migration20260514000000.js")
385
+ const migration = new Migration20260514000000() as unknown as {
386
+ up: () => Promise<void>
387
+ down: () => Promise<void>
388
+ queries: string[]
389
+ }
390
+
391
+ await migration.up()
392
+ const combinedUpSql = migration.queries.join("\n")
393
+
394
+ assert.ok(
395
+ combinedUpSql.includes('CREATE TABLE IF NOT EXISTS "mps_story_group"')
396
+ )
397
+ assert.ok(combinedUpSql.includes('CREATE TABLE IF NOT EXISTS "story"'))
398
+ assert.ok(combinedUpSql.includes('ALTER TABLE "story"'))
399
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "group_id"'))
400
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "caption"'))
401
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "duration_ms"'))
402
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "starts_at"'))
403
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "views_count"'))
404
+ assert.ok(
405
+ combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "completions_count"')
406
+ )
407
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "taps_count"'))
408
+ assert.ok(
409
+ combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "conversions_count"')
410
+ )
411
+ assert.ok(combinedUpSql.includes('ADD COLUMN IF NOT EXISTS "metadata"'))
412
+ assert.ok(
413
+ combinedUpSql.includes('CREATE TABLE IF NOT EXISTS "mps_story_hotspot"')
414
+ )
415
+ assert.ok(
416
+ combinedUpSql.includes('CREATE TABLE IF NOT EXISTS "mps_story_sticker"')
417
+ )
418
+ assert.ok(
419
+ combinedUpSql.includes('CREATE TABLE IF NOT EXISTS "mps_story_event"')
420
+ )
421
+
422
+ migration.queries.length = 0
423
+ await migration.down()
424
+ const combinedDownSql = migration.queries.join("\n")
425
+ assert.ok(
426
+ combinedDownSql.includes('DROP TABLE IF EXISTS "mps_story_event"')
427
+ )
428
+ assert.ok(
429
+ combinedDownSql.includes('DROP TABLE IF EXISTS "mps_story_sticker"')
430
+ )
431
+ assert.ok(
432
+ combinedDownSql.includes('DROP TABLE IF EXISTS "mps_story_hotspot"')
433
+ )
434
+ assert.ok(combinedDownSql.includes('DROP TABLE IF EXISTS "story"'))
435
+ assert.ok(
436
+ combinedDownSql.includes('DROP TABLE IF EXISTS "mps_story_group"')
437
+ )
438
+ })
439
+
440
+ it("coerces string display_order to integer in CreateStorySlideSchema and UpdateStorySlideSchema", async () => {
441
+ const { UpdateStorySlideSchema } = await import("../api/validators.js")
442
+
443
+ const createdParsed = CreateStorySlideSchema.parse({
444
+ title: "Coerced Order Slide",
445
+ media_url: "https://cdn.example.com/slide.jpg",
446
+ display_order: "7",
447
+ })
448
+ assert.equal(createdParsed.display_order, 7)
449
+
450
+ const updatedParsed = UpdateStorySlideSchema.parse({
451
+ display_order: "12",
452
+ })
453
+ assert.equal(updatedParsed.display_order, 12)
454
+ })
455
+
456
+ it("exports StoriesService, IStoryService, StoryServiceType, src/modules barrel, and supports PUT /admin/stories/:id with 'Story' fallback", async () => {
457
+ const rootIndex = await import("../index.js")
458
+ const modulesBarrel = await import("../modules/index.js")
459
+ const storyModule = await import("../modules/story/index.js")
460
+ const adminStoryByIdRoute =
461
+ await import("../api/admin/stories/[id]/route.js")
462
+ const storeStoriesRoute = await import("../api/store/stories/route.js")
463
+
464
+ assert.equal(rootIndex.StoriesService, StoriesModuleService)
465
+ assert.equal(modulesBarrel.StoriesService, StoriesModuleService)
466
+ assert.equal(modulesBarrel.STORIES_MODULE, "stories")
467
+ assert.equal(storyModule.LEGACY_STORIES_MODULE, "Story")
468
+ assert.equal(adminStoryByIdRoute.PUT, adminStoryByIdRoute.PATCH)
469
+
470
+ const idMiddleware = middlewares.routes.find(
471
+ (r: { matcher: string }) => r.matcher === "/admin/stories/:id"
472
+ )
473
+ assert.ok(idMiddleware)
474
+ assert.deepEqual(idMiddleware?.method, ["PATCH", "PUT"])
475
+
476
+ // Verify fallback resolution when module is registered under legacy "Story" key
477
+ const legacyService: import("../index").IStoryService =
478
+ new rootIndex.StoriesService({}, {})
479
+ const slide = await legacyService.createSlide({
480
+ title: "Initial Title",
481
+ media_type: "image",
482
+ media_url: "https://cdn.example.com/story.jpg",
483
+ display_order: 1,
484
+ })
485
+
486
+ const legacyScope = {
487
+ resolve(key: string) {
488
+ if (key === "Story") return legacyService
489
+ throw new Error(`Could not resolve '${key}'`)
490
+ },
491
+ }
492
+
493
+ let jsonPayload: any = null
494
+ const mockRes = {
495
+ status() {
496
+ return this
497
+ },
498
+ json(data: any) {
499
+ jsonPayload = data
500
+ return this
501
+ },
502
+ }
503
+
504
+ await adminStoryByIdRoute.PUT(
505
+ {
506
+ params: { id: slide.id },
507
+ body: { title: "Updated via PUT", display_order: "9" },
508
+ scope: legacyScope,
509
+ } as any,
510
+ mockRes as any
511
+ )
512
+
513
+ assert.equal(jsonPayload?.story?.title, "Updated via PUT")
514
+ assert.equal(jsonPayload?.story?.display_order, 9)
515
+
516
+ await storeStoriesRoute.GET(
517
+ {
518
+ query: {},
519
+ scope: legacyScope,
520
+ } as any,
521
+ mockRes as any
522
+ )
523
+ assert.equal(jsonPayload?.stories?.length, 1)
524
+ assert.equal(jsonPayload?.stories?.[0]?.title, "Updated via PUT")
525
+ })
526
+ })
@@ -0,0 +1,94 @@
1
+ # Admin
2
+
3
+ Medusa Admin extension — routes, widgets, decoupled 9:16 visual studio components, data-fetching hooks, and 10-locale i18n dictionaries for the Shoppable Stories plugin.
4
+
5
+ ```sh
6
+ admin/
7
+ ├── tsconfig.json TypeScript config for the Admin Vite bundle
8
+ ├── i18n/ react-i18next setup and 10 locale JSON files
9
+ ├── utils/ Ring gradient styles & 9:16 canvas helpers
10
+ ├── hooks/
11
+ │ ├── use-stories-studio.ts State & mutation hook for the /stories Studio routes
12
+ │ └── use-product-stories.ts Hook for the Product Detail Stories widget
13
+ ├── components/
14
+ │ ├── index.ts Barrel export for all 15 Admin UI components
15
+ │ ├── overview-cards.tsx StatCard & NavigationCard components
16
+ │ ├── studio-header.tsx Studio header bar with refresh & slide/ring counters
17
+ │ ├── story-ring-form.tsx Form for creating a Story Highlight Ring (StoryGroup)
18
+ │ ├── story-rings-table.tsx Table of Story Highlight Rings with delete action
19
+ │ ├── story-rings-tab.tsx Circular ring preview bar + StoryRingsTable
20
+ │ ├── slide-preview-canvas.tsx Interactive 9:16 visual canvas with click-to-place X/Y pins
21
+ │ ├── slide-form-section.tsx Form for creating/editing a 9:16 image or video slide
22
+ │ ├── slide-timeline-section.tsx Ordered slide timeline selector & active/delete controls
23
+ │ ├── hotspot-form-section.tsx Form for pinning X/Y product hotspots onto the active slide
24
+ │ ├── canvas-editor-tab.tsx 3-pane 9:16 visual editor (slide form, 9:16 canvas, hotspots)
25
+ │ ├── sticker-form-section.tsx Form for attaching Poll, Countdown, Coupon & Q&A stickers
26
+ │ ├── sticker-list-section.tsx List of active stickers on the selected slide
27
+ │ ├── stickers-tab.tsx Interactive Stickers builder tab
28
+ │ ├── analytics-tab.tsx Conversion Funnel KPI cards & per-slide funnel table
29
+ │ └── product-stories-card.tsx Card rendered inside product.details.after widget
30
+ ├── routes/
31
+ │ └── stories/ Page routes registered in the Medusa admin shell
32
+ │ ├── page.tsx /stories — overview dashboard
33
+ │ ├── canvas/
34
+ │ │ └── page.tsx /stories/canvas — 9:16 visual canvas & hotspot tagger
35
+ │ ├── rings/
36
+ │ │ ├── page.tsx /stories/rings — Story Highlight Rings manager
37
+ │ │ └── @create/
38
+ │ │ └── page.tsx /stories/rings/create — create Story Ring focus modal
39
+ │ ├── stickers/
40
+ │ │ └── page.tsx /stories/stickers — interactive stickers builder
41
+ │ └── analytics/
42
+ │ └── page.tsx /stories/analytics — conversion funnel analytics
43
+ └── widgets/
44
+ └── product-stories-widget.tsx product.details.after widget
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Route & Widget registration
50
+
51
+ The top-level `/stories` page exports a `config` object created with `defineRouteConfig` from `@medusajs/admin-sdk`:
52
+
53
+ ```tsx
54
+ export const config = defineRouteConfig({
55
+ label: "nav.label",
56
+ translationNs: "stories",
57
+ icon: BuildingStorefront,
58
+ })
59
+ ```
60
+
61
+ `widgets/product-stories-widget.tsx` registers in the `product.details.after` zone using `defineWidgetConfig`.
62
+
63
+ All route and widget files are kept concise (`< 170` lines per file) and delegate state management to `hooks/` and UI rendering to `components/`.
64
+
65
+ ---
66
+
67
+ ## Data fetching & state hooks
68
+
69
+ | Hook | File | Purpose |
70
+ | ------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71
+ | `useStoriesStudio` | `hooks/use-stories-studio.ts` | Manages full studio state (`groups`, `slides`, `analytics`, selected slide, 9:16 canvas click coordinates, hotspot form state, sticker form state) and calls `/admin/stories/*` endpoints |
72
+ | `useProductStories` | `hooks/use-product-stories.ts` | Fetches all story slides featuring a specific `product_id` and provides a 1-click `handleQuickCreateProductStory` action using the product's thumbnail, title, handle, and price |
73
+
74
+ ---
75
+
76
+ ## Component library
77
+
78
+ All components live in `components/` and are internal to the Admin extension:
79
+
80
+ | Component | File | Purpose |
81
+ | --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
82
+ | `StatCard`, `NavigationCard` | `overview-cards.tsx` | KPI stat cards and navigation cards on `/stories` |
83
+ | `StudioHeader` | `studio-header.tsx` | Studio title, subtitle, and refresh controls |
84
+ | `StoryRingsTab`, `StoryRingsTable`, `StoryRingForm` | `story-rings-tab.tsx`, `story-rings-table.tsx`, `story-ring-form.tsx` | Circular Highlight Ring preview bar, rings table, and create ring form |
85
+ | `CanvasEditorTab`, `SlidePreviewCanvas`, `SlideFormSection`, `SlideTimelineSection`, `HotspotFormSection` | `canvas-editor-tab.tsx`, `slide-preview-canvas.tsx`, `slide-form-section.tsx`, `slide-timeline-section.tsx`, `hotspot-form-section.tsx` | Interactive 9:16 slide builder with click-to-position `(x_percent, y_percent)` product hotspot pins |
86
+ | `StickersTab`, `StickerFormSection`, `StickerListSection` | `stickers-tab.tsx`, `sticker-form-section.tsx`, `sticker-list-section.tsx` | Interactive Poll, Countdown, Coupon, and Q&A sticker builder |
87
+ | `AnalyticsTab` | `analytics-tab.tsx` | Conversion funnel metrics (`impression` → `complete` → `hotspot_click` → `add_to_cart`) |
88
+ | `ProductStoriesCard` | `product-stories-card.tsx` | Product detail widget card with 1-click story slide generator |
89
+
90
+ ---
91
+
92
+ ## i18n
93
+
94
+ Translations are configured in `i18n/` using `react-i18next` across 10 locales (`en`, `es`, `fr`, `de`, `it`, `pt`, `nl`, `pl`, `tr`, `ar` with RTL layout support). See [`i18n/README.md`](./i18n/README.md) for details.