@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,74 @@
|
|
|
1
|
+
import { defineRouteConfig } from "@medusajs/admin-sdk"
|
|
2
|
+
import { CORE_LAYOUT_IDS } from "@medusajs/admin-shared"
|
|
3
|
+
import { LayoutComposer } from "@medusajs/dashboard/components"
|
|
4
|
+
import { Tag } from "@medusajs/icons"
|
|
5
|
+
import { Toaster } from "@medusajs/ui"
|
|
6
|
+
import { useTranslation } from "react-i18next"
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
StickerActiveListSection,
|
|
10
|
+
StickerBuilderSection,
|
|
11
|
+
} from "../../../components/stickers-tab"
|
|
12
|
+
import { useStoriesStudio } from "../../../hooks/use-stories-studio"
|
|
13
|
+
import { RbacGuard } from "../../../components/rbac-guard"
|
|
14
|
+
|
|
15
|
+
const StoriesStickersPage = () => {
|
|
16
|
+
const studio = useStoriesStudio()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<Toaster />
|
|
21
|
+
<LayoutComposer
|
|
22
|
+
widgetsZonePrefix="stories.stickers"
|
|
23
|
+
preferredLayoutId={CORE_LAYOUT_IDS.TWO_COLUMN}
|
|
24
|
+
data={studio.selectedSlide as any}
|
|
25
|
+
sections={{
|
|
26
|
+
main: (
|
|
27
|
+
<LayoutComposer.Entry id="StickerBuilderSection">
|
|
28
|
+
<StickerBuilderSection
|
|
29
|
+
selectedSlide={studio.selectedSlide}
|
|
30
|
+
stickerForm={studio.stickerForm}
|
|
31
|
+
onStickerFormChange={studio.setStickerForm}
|
|
32
|
+
isSaving={studio.isSavingSticker}
|
|
33
|
+
onAddSticker={() => void studio.handleAddSticker()}
|
|
34
|
+
/>
|
|
35
|
+
</LayoutComposer.Entry>
|
|
36
|
+
),
|
|
37
|
+
side: (
|
|
38
|
+
<LayoutComposer.Entry id="StickerActiveListSection">
|
|
39
|
+
<StickerActiveListSection
|
|
40
|
+
selectedSlide={studio.selectedSlide}
|
|
41
|
+
onRemoveSticker={(stickerId) =>
|
|
42
|
+
void studio.handleRemoveSticker(stickerId)
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
</LayoutComposer.Entry>
|
|
46
|
+
),
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
</>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const Breadcrumb = () => {
|
|
54
|
+
const { t } = useTranslation()
|
|
55
|
+
return t("tabs.stickers")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const config = defineRouteConfig({
|
|
59
|
+
label: "tabs.stickers",
|
|
60
|
+
translationNs: "stories",
|
|
61
|
+
icon: Tag,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export const handle = {
|
|
65
|
+
breadcrumb: () => <Breadcrumb />,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const GuardedStoriesStickersPage = () => (
|
|
69
|
+
<RbacGuard permission="stories.read">
|
|
70
|
+
<StoriesStickersPage />
|
|
71
|
+
</RbacGuard>
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
export default GuardedStoriesStickersPage
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"strict": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"paths": {
|
|
19
|
+
"@/*": ["./*"]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"include": ["."]
|
|
23
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { StoryRingTheme } from "../../modules/story/types"
|
|
2
|
+
|
|
3
|
+
export const ADMIN_RING_THEME_PRESETS: Array<{
|
|
4
|
+
id: StoryRingTheme
|
|
5
|
+
label: string
|
|
6
|
+
gradient: string
|
|
7
|
+
}> = [
|
|
8
|
+
{
|
|
9
|
+
id: "instagram",
|
|
10
|
+
label: "Instagram Classic",
|
|
11
|
+
gradient:
|
|
12
|
+
"linear-gradient(135deg, #feda75 0%, #fa7e1e 25%, #d62976 50%, #962fbf 75%, #4f5bd5 100%)",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "tiktok",
|
|
16
|
+
label: "TikTok Pulse",
|
|
17
|
+
gradient: "linear-gradient(135deg, #00f2fe 0%, #000000 50%, #ff0050 100%)",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "sunset",
|
|
21
|
+
label: "Sunset Coral",
|
|
22
|
+
gradient: "linear-gradient(135deg, #ff512f 0%, #dd2476 100%)",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "emerald",
|
|
26
|
+
label: "Emerald Mint",
|
|
27
|
+
gradient: "linear-gradient(135deg, #10b981 0%, #047857 100%)",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "violet",
|
|
31
|
+
label: "Electric Violet",
|
|
32
|
+
gradient: "linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%)",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "cyber",
|
|
36
|
+
label: "Cyber Neon",
|
|
37
|
+
gradient: "linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%)",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "neon",
|
|
41
|
+
label: "Neon Lime",
|
|
42
|
+
gradient: "linear-gradient(135deg, #a8ff78 0%, #78ffd6 50%, #00f2fe 100%)",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "gold",
|
|
46
|
+
label: "Luxury Gold",
|
|
47
|
+
gradient: "linear-gradient(135deg, #f59e0b 0%, #fde68a 50%, #b45309 100%)",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "minimal",
|
|
51
|
+
label: "Minimal Monochrome",
|
|
52
|
+
gradient: "linear-gradient(135deg, #111827 0%, #6b7280 100%)",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: "custom",
|
|
56
|
+
label: "Custom Hex",
|
|
57
|
+
gradient: "linear-gradient(135deg, #6366f1 0%, #a855f7 100%)",
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
export const resolveRingGradient = (
|
|
62
|
+
theme: StoryRingTheme,
|
|
63
|
+
customColor?: string | null
|
|
64
|
+
): string => {
|
|
65
|
+
if (
|
|
66
|
+
theme === "custom" &&
|
|
67
|
+
customColor &&
|
|
68
|
+
/^#[0-9a-fA-F]{3,8}$/.test(customColor)
|
|
69
|
+
) {
|
|
70
|
+
return customColor
|
|
71
|
+
}
|
|
72
|
+
return (
|
|
73
|
+
ADMIN_RING_THEME_PRESETS.find((p) => p.id === theme)?.gradient ??
|
|
74
|
+
ADMIN_RING_THEME_PRESETS[0].gradient
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const sanitizeAdminMediaUrl = (raw?: string | null): string | null => {
|
|
79
|
+
if (!raw) return null
|
|
80
|
+
const trimmed = raw.trim()
|
|
81
|
+
if (!trimmed) return null
|
|
82
|
+
if (trimmed.startsWith("/") && !trimmed.startsWith("//")) {
|
|
83
|
+
return trimmed
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const parsed = new URL(trimmed)
|
|
87
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
88
|
+
return parsed.toString()
|
|
89
|
+
}
|
|
90
|
+
return null
|
|
91
|
+
} catch {
|
|
92
|
+
return null
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineWidgetConfig } from "@medusajs/admin-sdk"
|
|
2
|
+
import { useTranslation } from "react-i18next"
|
|
3
|
+
import { ProductStoriesCard } from "../components"
|
|
4
|
+
import {
|
|
5
|
+
type ProductWidgetEntity,
|
|
6
|
+
useProductStories,
|
|
7
|
+
} from "../hooks/use-product-stories"
|
|
8
|
+
|
|
9
|
+
interface ProductWidgetProps {
|
|
10
|
+
data?: ProductWidgetEntity
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const ProductStoriesWidget = ({ data }: ProductWidgetProps) => {
|
|
14
|
+
const { t } = useTranslation()
|
|
15
|
+
const { taggedSlides, isCreating, handleQuickCreateProductStory } =
|
|
16
|
+
useProductStories(data)
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ProductStoriesCard
|
|
20
|
+
productTitle={data?.title || t("widget.thisProductFallback")}
|
|
21
|
+
taggedSlides={taggedSlides}
|
|
22
|
+
isCreating={isCreating}
|
|
23
|
+
onQuickCreateProductStory={handleQuickCreateProductStory}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const config = defineWidgetConfig({
|
|
29
|
+
zone: "product.details.after",
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export default ProductStoriesWidget
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# API Routes
|
|
2
|
+
|
|
3
|
+
File-based REST routes under `/admin` and `/store`, following Medusa's `src/api/<surface>/<path>/route.ts` convention.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
api/
|
|
7
|
+
├── validators.ts Zod schemas (@medusajs/framework/zod) for all Admin & Store routes
|
|
8
|
+
├── middlewares.ts defineMiddlewares binding validateAndTransformBody
|
|
9
|
+
├── admin/
|
|
10
|
+
│ ├── plugin/
|
|
11
|
+
│ │ └── route.ts GET /admin/plugin — health check
|
|
12
|
+
│ └── stories/
|
|
13
|
+
│ ├── route.ts GET (list studio state), POST (create slide) /admin/stories
|
|
14
|
+
│ ├── groups/
|
|
15
|
+
│ │ ├── route.ts GET, POST /admin/stories/groups — list or create Story Highlight Rings
|
|
16
|
+
│ │ └── [id]/
|
|
17
|
+
│ │ └── route.ts GET, PATCH, DELETE /admin/stories/groups/:id
|
|
18
|
+
│ ├── analytics/
|
|
19
|
+
│ │ └── route.ts GET /admin/stories/analytics — conversion funnel overview
|
|
20
|
+
│ └── [id]/
|
|
21
|
+
│ ├── route.ts GET, PATCH, DELETE /admin/stories/:id — slide CRUD
|
|
22
|
+
│ ├── hotspots/
|
|
23
|
+
│ │ └── route.ts POST, DELETE /admin/stories/:id/hotspots — pin or remove product hotspot
|
|
24
|
+
│ └── stickers/
|
|
25
|
+
│ └── route.ts POST, DELETE /admin/stories/:id/stickers — add or remove interactive sticker
|
|
26
|
+
└── store/
|
|
27
|
+
├── plugin/
|
|
28
|
+
│ └── route.ts GET /store/plugin — storefront health check
|
|
29
|
+
└── stories/
|
|
30
|
+
├── route.ts GET /store/stories — active Story Highlight Rings & slides
|
|
31
|
+
└── [id]/
|
|
32
|
+
├── events/
|
|
33
|
+
│ └── route.ts POST /store/stories/:id/events — record engagement & funnel events
|
|
34
|
+
└── interact/
|
|
35
|
+
└── route.ts POST /store/stories/:id/interact — vote on polls, submit Q&A, claim coupons
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Endpoint Summary
|
|
41
|
+
|
|
42
|
+
### Storefront Endpoints
|
|
43
|
+
|
|
44
|
+
| Method | Path | Validator Schema | Description |
|
|
45
|
+
| ------ | ----------------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
46
|
+
| `GET` | `/store/stories` | — | Returns `{ stories, groups }` filtered by `placement` (`home`, `collection`, `category`, `product`, `floating_bubble`, `global`), `target_entity_id`, `collection_id`, `group_id`, or `product_id`. Automatically filters out inactive and expired stories. |
|
|
47
|
+
| `POST` | `/store/stories/:id/events` | `RecordStoryEngagementSchema` | Executes `recordStoryEngagementWorkflow` to record `impression`, `complete`, `tap_forward`, `tap_back`, `exit`, `hotspot_click`, `link_click`, `add_to_cart`, or `sticker_interact`. |
|
|
48
|
+
| `POST` | `/store/stories/:id/interact` | `InteractWithStoryStickerSchema` | Records a `poll` vote (`option_id`), `question_badge` response (`answer_text`), or `coupon` claim on a sticker. |
|
|
49
|
+
|
|
50
|
+
### Admin Endpoints
|
|
51
|
+
|
|
52
|
+
| Method | Path | Validator Schema | Workflow / Service Method |
|
|
53
|
+
| -------------------------- | ----------------------------- | ------------------------------------------------------- | -------------------------------------------- |
|
|
54
|
+
| `GET` | `/admin/stories` | — | `storiesService.listAdminStudioState` |
|
|
55
|
+
| `POST` | `/admin/stories` | `CreateStorySlideSchema` | `createStorySlideWorkflow` |
|
|
56
|
+
| `GET` / `PATCH` / `DELETE` | `/admin/stories/:id` | `UpdateStorySlideSchema` | `getSlideById`, `updateSlide`, `deleteSlide` |
|
|
57
|
+
| `GET` / `POST` | `/admin/stories/groups` | `CreateStoryGroupSchema` | `listGroups`, `createStoryGroupWorkflow` |
|
|
58
|
+
| `GET` / `PATCH` / `DELETE` | `/admin/stories/groups/:id` | `UpdateStoryGroupSchema` | `getGroupById`, `updateGroup`, `deleteGroup` |
|
|
59
|
+
| `POST` / `DELETE` | `/admin/stories/:id/hotspots` | `CreateStoryHotspotSchema` / `DeleteStoryHotspotSchema` | `addHotspotToSlide`, `removeHotspot` |
|
|
60
|
+
| `POST` / `DELETE` | `/admin/stories/:id/stickers` | `CreateStoryStickerSchema` / `DeleteStoryStickerSchema` | `addStickerToSlide`, `removeSticker` |
|
|
61
|
+
| `GET` | `/admin/stories/analytics` | — | `storiesService.getAnalyticsOverview` |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../../../modules/story"
|
|
3
|
+
import type { CreateStoryHotspotInput } from "../../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const svc = resolveStoriesService(req.scope)
|
|
7
|
+
const body = req.validatedBody as CreateStoryHotspotInput
|
|
8
|
+
const hotspot = await svc.addHotspot(req.params.id, body)
|
|
9
|
+
res.status(201).json({ hotspot })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
13
|
+
const svc = resolveStoriesService(req.scope)
|
|
14
|
+
const body = req.validatedBody as { hotspot_id: string }
|
|
15
|
+
const result = await svc.removeHotspot(body.hotspot_id, req.params.id)
|
|
16
|
+
res.json(result)
|
|
17
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { MedusaError } from "@medusajs/framework/utils"
|
|
3
|
+
import {
|
|
4
|
+
resolveStoriesService,
|
|
5
|
+
type StorySlideDTO,
|
|
6
|
+
} from "../../../../modules/story"
|
|
7
|
+
import {
|
|
8
|
+
UpdateStorySlideSchema,
|
|
9
|
+
type UpdateStorySlideInput,
|
|
10
|
+
} from "../../../validators"
|
|
11
|
+
|
|
12
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
13
|
+
const svc = resolveStoriesService(req.scope)
|
|
14
|
+
const rows = await svc.listStories({ id: req.params.id })
|
|
15
|
+
const raw = rows?.[0]
|
|
16
|
+
if (!raw) {
|
|
17
|
+
throw new MedusaError(
|
|
18
|
+
MedusaError.Types.NOT_FOUND,
|
|
19
|
+
`Story "${req.params.id}" not found.`
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
const story = await svc.hydrateSlide(raw as unknown as StorySlideDTO)
|
|
23
|
+
res.json({ story })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function PATCH(req: MedusaRequest, res: MedusaResponse) {
|
|
27
|
+
const svc = resolveStoriesService(req.scope)
|
|
28
|
+
const body = (req.validatedBody ??
|
|
29
|
+
UpdateStorySlideSchema.parse(req.body ?? {})) as UpdateStorySlideInput
|
|
30
|
+
const story = await svc.updateSlide(req.params.id, body)
|
|
31
|
+
res.json({ story })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const PUT = PATCH
|
|
35
|
+
|
|
36
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
37
|
+
const svc = resolveStoriesService(req.scope)
|
|
38
|
+
const result = await svc.deleteSlide(req.params.id)
|
|
39
|
+
res.json(result)
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../../../modules/story"
|
|
3
|
+
import type {
|
|
4
|
+
CreateStoryStickerInput,
|
|
5
|
+
DeleteStoryStickerInput,
|
|
6
|
+
} from "../../../../validators"
|
|
7
|
+
|
|
8
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
9
|
+
const svc = resolveStoriesService(req.scope)
|
|
10
|
+
const body = req.validatedBody as CreateStoryStickerInput
|
|
11
|
+
const sticker = await svc.addSticker(req.params.id, body)
|
|
12
|
+
res.status(201).json({ sticker })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
16
|
+
const svc = resolveStoriesService(req.scope)
|
|
17
|
+
const body = req.validatedBody as DeleteStoryStickerInput
|
|
18
|
+
const result = await svc.removeSticker(body.sticker_id, req.params.id)
|
|
19
|
+
res.json(result)
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../../modules/story"
|
|
3
|
+
|
|
4
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
5
|
+
const svc = resolveStoriesService(req.scope)
|
|
6
|
+
const analytics = await svc.getAnalyticsOverview()
|
|
7
|
+
res.json({ analytics })
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { MedusaError } from "@medusajs/framework/utils"
|
|
3
|
+
import { resolveStoriesService } from "../../../../../modules/story"
|
|
4
|
+
import type { UpdateStoryGroupInput } from "../../../../validators"
|
|
5
|
+
|
|
6
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const svc = resolveStoriesService(req.scope)
|
|
8
|
+
const state = await svc.listAdminStudioState()
|
|
9
|
+
const group = state.groups.find((g) => g.id === req.params.id)
|
|
10
|
+
if (!group) {
|
|
11
|
+
throw new MedusaError(
|
|
12
|
+
MedusaError.Types.NOT_FOUND,
|
|
13
|
+
`Story group "${req.params.id}" not found.`
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
res.json({ group })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function PATCH(req: MedusaRequest, res: MedusaResponse) {
|
|
20
|
+
const svc = resolveStoriesService(req.scope)
|
|
21
|
+
const body = req.validatedBody as UpdateStoryGroupInput
|
|
22
|
+
const group = await svc.updateGroup(req.params.id, body)
|
|
23
|
+
res.json({ group })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function DELETE(req: MedusaRequest, res: MedusaResponse) {
|
|
27
|
+
const svc = resolveStoriesService(req.scope)
|
|
28
|
+
const result = await svc.deleteGroup(req.params.id)
|
|
29
|
+
res.json(result)
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../../modules/story"
|
|
3
|
+
import { createStoryGroupWorkflow } from "../../../../workflows"
|
|
4
|
+
import type { CreateStoryGroupInput } from "../../../validators"
|
|
5
|
+
|
|
6
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
7
|
+
const svc = resolveStoriesService(req.scope)
|
|
8
|
+
const state = await svc.listAdminStudioState()
|
|
9
|
+
res.json({ groups: state.groups })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
13
|
+
const body = req.validatedBody as CreateStoryGroupInput
|
|
14
|
+
const { result } = await createStoryGroupWorkflow(req.scope).run({
|
|
15
|
+
input: body,
|
|
16
|
+
})
|
|
17
|
+
res.status(201).json({ group: result })
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../modules/story"
|
|
3
|
+
import { createStorySlideWorkflow } from "../../../workflows"
|
|
4
|
+
import {
|
|
5
|
+
CreateStorySlideSchema,
|
|
6
|
+
type CreateStorySlideInput,
|
|
7
|
+
} from "../../validators"
|
|
8
|
+
|
|
9
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
10
|
+
const svc = resolveStoriesService(req.scope)
|
|
11
|
+
const productId =
|
|
12
|
+
typeof req.query?.product_id === "string" ? req.query.product_id : undefined
|
|
13
|
+
|
|
14
|
+
const state = await svc.listAdminStudioState(
|
|
15
|
+
productId ? { product_id: productId } : undefined
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
res.json({
|
|
19
|
+
stories: state.slides,
|
|
20
|
+
groups: state.groups,
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
25
|
+
const body = (req.validatedBody ??
|
|
26
|
+
CreateStorySlideSchema.parse(req.body ?? {})) as CreateStorySlideInput
|
|
27
|
+
const { result } = await createStorySlideWorkflow(req.scope).run({
|
|
28
|
+
input: body,
|
|
29
|
+
})
|
|
30
|
+
res.status(201).json({ story: result })
|
|
31
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineMiddlewares,
|
|
3
|
+
validateAndTransformBody,
|
|
4
|
+
} from "@medusajs/framework/http"
|
|
5
|
+
import {
|
|
6
|
+
CreateStoryGroupSchema,
|
|
7
|
+
CreateStoryHotspotSchema,
|
|
8
|
+
CreateStorySlideSchema,
|
|
9
|
+
CreateStoryStickerSchema,
|
|
10
|
+
DeleteStoryHotspotSchema,
|
|
11
|
+
DeleteStoryStickerSchema,
|
|
12
|
+
InteractWithStoryStickerSchema,
|
|
13
|
+
RecordStoryEngagementSchema,
|
|
14
|
+
UpdateStoryGroupSchema,
|
|
15
|
+
UpdateStorySlideSchema,
|
|
16
|
+
} from "./validators"
|
|
17
|
+
|
|
18
|
+
export * from "./validators"
|
|
19
|
+
|
|
20
|
+
export default defineMiddlewares({
|
|
21
|
+
routes: [
|
|
22
|
+
{
|
|
23
|
+
matcher: "/admin/stories",
|
|
24
|
+
method: ["POST"],
|
|
25
|
+
middlewares: [validateAndTransformBody(CreateStorySlideSchema)],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
matcher: "/admin/stories/:id",
|
|
29
|
+
method: ["PATCH", "PUT"],
|
|
30
|
+
middlewares: [validateAndTransformBody(UpdateStorySlideSchema)],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
matcher: "/admin/stories/groups",
|
|
34
|
+
method: ["POST"],
|
|
35
|
+
middlewares: [validateAndTransformBody(CreateStoryGroupSchema)],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
matcher: "/admin/stories/groups/:id",
|
|
39
|
+
method: ["PATCH"],
|
|
40
|
+
middlewares: [validateAndTransformBody(UpdateStoryGroupSchema)],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
matcher: "/admin/stories/:id/hotspots",
|
|
44
|
+
method: ["POST"],
|
|
45
|
+
middlewares: [validateAndTransformBody(CreateStoryHotspotSchema)],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
matcher: "/admin/stories/:id/hotspots",
|
|
49
|
+
method: ["DELETE"],
|
|
50
|
+
middlewares: [validateAndTransformBody(DeleteStoryHotspotSchema)],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
matcher: "/admin/stories/:id/stickers",
|
|
54
|
+
method: ["POST"],
|
|
55
|
+
middlewares: [validateAndTransformBody(CreateStoryStickerSchema)],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
matcher: "/admin/stories/:id/stickers",
|
|
59
|
+
method: ["DELETE"],
|
|
60
|
+
middlewares: [validateAndTransformBody(DeleteStoryStickerSchema)],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
matcher: "/store/stories/:id/events",
|
|
64
|
+
method: ["POST"],
|
|
65
|
+
middlewares: [validateAndTransformBody(RecordStoryEngagementSchema)],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
matcher: "/store/stories/:id/interact",
|
|
69
|
+
method: ["POST"],
|
|
70
|
+
middlewares: [validateAndTransformBody(InteractWithStoryStickerSchema)],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { recordStoryEngagementWorkflow } from "../../../../../workflows"
|
|
3
|
+
import type { RecordStoryEngagementInput } from "../../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const body = req.validatedBody as RecordStoryEngagementInput
|
|
7
|
+
const { result } = await recordStoryEngagementWorkflow(req.scope).run({
|
|
8
|
+
input: {
|
|
9
|
+
story_id: req.params.id,
|
|
10
|
+
...body,
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
res.json(result)
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import { resolveStoriesService } from "../../../../../modules/story"
|
|
3
|
+
import type { InteractWithStoryStickerInput } from "../../../../validators"
|
|
4
|
+
|
|
5
|
+
export async function POST(req: MedusaRequest, res: MedusaResponse) {
|
|
6
|
+
const svc = resolveStoriesService(req.scope)
|
|
7
|
+
const body = req.validatedBody as InteractWithStoryStickerInput
|
|
8
|
+
|
|
9
|
+
const sticker = await svc.interactWithSticker({
|
|
10
|
+
storyId: req.params.id,
|
|
11
|
+
stickerId: body.sticker_id,
|
|
12
|
+
optionId: body.option_id,
|
|
13
|
+
responseText: body.response_text,
|
|
14
|
+
sessionId: body.session_id,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
res.json({ sticker })
|
|
18
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
|
2
|
+
import {
|
|
3
|
+
resolveStoriesService,
|
|
4
|
+
type StoryPlacementZone,
|
|
5
|
+
} from "../../../modules/story"
|
|
6
|
+
|
|
7
|
+
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
8
|
+
const svc = resolveStoriesService(req.scope)
|
|
9
|
+
const placement =
|
|
10
|
+
typeof req.query?.placement === "string"
|
|
11
|
+
? (req.query.placement as StoryPlacementZone)
|
|
12
|
+
: undefined
|
|
13
|
+
const targetEntityId =
|
|
14
|
+
typeof req.query?.target_entity_id === "string"
|
|
15
|
+
? req.query.target_entity_id
|
|
16
|
+
: undefined
|
|
17
|
+
const collectionId =
|
|
18
|
+
typeof req.query?.collection_id === "string"
|
|
19
|
+
? req.query.collection_id
|
|
20
|
+
: undefined
|
|
21
|
+
const groupId =
|
|
22
|
+
typeof req.query?.group_id === "string" ? req.query.group_id : undefined
|
|
23
|
+
const productId =
|
|
24
|
+
typeof req.query?.product_id === "string" ? req.query.product_id : undefined
|
|
25
|
+
|
|
26
|
+
const [stories, groups] = await Promise.all([
|
|
27
|
+
svc.listActive({
|
|
28
|
+
group_id: groupId,
|
|
29
|
+
product_id: productId,
|
|
30
|
+
}),
|
|
31
|
+
svc.listStorefrontGroups({
|
|
32
|
+
placement,
|
|
33
|
+
target_entity_id: targetEntityId,
|
|
34
|
+
collection_id: collectionId,
|
|
35
|
+
group_id: groupId,
|
|
36
|
+
product_id: productId,
|
|
37
|
+
}),
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
res.json({
|
|
41
|
+
stories,
|
|
42
|
+
groups,
|
|
43
|
+
})
|
|
44
|
+
}
|