@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,16 @@
1
+ # Scheduled Jobs
2
+
3
+ Medusa scheduled background jobs for `@vicacha-devs/medusa-plugin-stories`.
4
+
5
+ ```
6
+ jobs/
7
+ └── expire-ephemeral-stories.ts Runs every 15 minutes (*/15 * * * *)
8
+ ```
9
+
10
+ ---
11
+
12
+ ## Job Index
13
+
14
+ | Job Name | Schedule | File | Behavior |
15
+ | -------------------------- | --------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16
+ | `expire-ephemeral-stories` | `*/15 * * * *` (Every 15 minutes) | `expire-ephemeral-stories.ts` | Resolves `StoriesModuleService` (`STORIES_MODULE`) and calls `expireOutdatedStories()` to automatically set `is_active = false` on any story slide whose `expires_at` timestamp has passed. |
@@ -0,0 +1,14 @@
1
+ import type { MedusaContainer } from "@medusajs/framework/types"
2
+ import { resolveStoriesService } from "../modules/story"
3
+
4
+ export default async function expireEphemeralStoriesJob(
5
+ container: MedusaContainer
6
+ ) {
7
+ const storiesService = resolveStoriesService(container)
8
+ await storiesService.expireOutdatedStories()
9
+ }
10
+
11
+ export const config = {
12
+ name: "expire-ephemeral-stories",
13
+ schedule: "*/15 * * * *",
14
+ }
@@ -0,0 +1,18 @@
1
+ # Links
2
+
3
+ Cross-entity associations in `@vicacha-devs/medusa-plugin-stories`.
4
+
5
+ ```
6
+ links/
7
+ └── README.md
8
+ ```
9
+
10
+ ---
11
+
12
+ ## Overview
13
+
14
+ `@vicacha-devs/medusa-plugin-stories` associates story slides and highlight rings with Medusa core entities (`Product`, `ProductVariant`, `ProductCollection`, `ProductCategory`) via indexed identifier columns on its module models rather than cross-module join tables:
15
+
16
+ - **`StoryHotspot`** (`src/modules/story/models/index.ts`) — stores `story_id`, `product_id` (indexed), `variant_id`, and denormalized product card metadata (`product_title`, `product_handle`, `product_thumbnail`, `price_formatted`, `price_amount`, `currency_code`, `x_percent`, `y_percent`) for zero-latency 9:16 player rendering.
17
+ - **`StoryGroup`** (`src/modules/story/models/index.ts`) — stores `placement` (`home`, `collection`, `category`, `product`, `floating_bubble`, `global`) and `target_entity_id` to scope Highlight Rings to specific collections, categories, or product pages.
18
+ - **`product-deleted.ts` subscriber** (`src/subscribers/product-deleted.ts`) — listens to `product.deleted` and calls `storiesService.removeHotspotsByProductId(productId)` to keep hotspot references clean.
@@ -0,0 +1,46 @@
1
+ # Modules
2
+
3
+ Custom Medusa module (`stories`) implementing Story Highlight Rings (`StoryGroup`), 9:16 Story Slides (`Story`), X/Y Product Hotspots (`StoryHotspot`), Interactive Stickers (`StorySticker`), and Conversion Funnel Analytics (`StoryEvent`).
4
+
5
+ ```
6
+ modules/
7
+ ├── story/
8
+ │ ├── index.ts Module("stories", { service: StoriesModuleService })
9
+ │ ├── service.ts StoriesModuleService (extends MedusaService)
10
+ │ ├── types.ts DTOs, ring themes, placement zones, sticker & funnel types
11
+ │ ├── models/
12
+ │ │ └── index.ts StoryGroup, Story, StoryHotspot, StorySticker, StoryEvent
13
+ │ └── utils/
14
+ │ └── security.ts sanitizeSafeUrl, sanitizeHexColor, clampPercentage
15
+ └── stories/
16
+ └── index.ts Alias re-exporting ../story for backward compatibility
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Service Registration
22
+
23
+ - **Module token:** `STORIES_MODULE = "stories"` (100% compatible with `@bambiste/medusa-stories`)
24
+ - **Service class:** `StoriesModuleService`
25
+
26
+ ---
27
+
28
+ ## Data Models (`story/models/index.ts`)
29
+
30
+ | Model | Table Name | ID Prefix | Purpose |
31
+ | -------------- | ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
32
+ | `StoryGroup` | `mps_story_group` | `sgrp_` | Highlight Ring container with `title`, `handle`, `avatar_url`, `ring_theme` (`instagram`, `tiktok`, `sunset`, `emerald`, `violet`, `cyber`, `neon`, `gold`, `minimal`, `custom`), `placement`, `target_entity_id`, `is_pinned`, `is_ephemeral`, `is_active`, and `display_order`. |
33
+ | `Story` | `story` | `stry_` | Individual 9:16 slide (`image` or `video`) with `group_id`, `title`, `caption`, `media_url`, `thumbnail_url`, `duration_ms`, `link_url`, `link_text`, `starts_at`, `expires_at`, and funnel counters (`views_count`, `completions_count`, `clicks_count`, `cart_conversions_count`). |
34
+ | `StoryHotspot` | `mps_story_hotspot` | `shsp_` | Product pin at `(x_percent, y_percent)` on a slide with `product_id`, `variant_id`, `product_title`, `product_handle`, `product_thumbnail`, `price_formatted`, `price_amount`, `currency_code`, `label`, and `badge_style` (`pill \| card \| dot`). |
35
+ | `StorySticker` | `mps_story_sticker` | `sstk_` | Interactive overlay (`poll`, `countdown`, `coupon`, `question_badge`) at `(x_percent, y_percent)` with `prompt`, `options`, `coupon_code`, `countdown_until`, and `total_interactions`. |
36
+ | `StoryEvent` | `mps_story_event` | `sevt_` | Funnel telemetry log (`impression`, `complete`, `tap_forward`, `tap_back`, `exit`, `hotspot_click`, `link_click`, `add_to_cart`, `sticker_interact`). |
37
+
38
+ ---
39
+
40
+ ## Key Service Methods (`story/service.ts`)
41
+
42
+ - **Story Groups (Highlight Rings):** `createGroup`, `updateGroup`, `deleteGroup`, `getGroupById`, `listGroups`
43
+ - **Story Slides:** `createSlide`, `updateSlide`, `deleteSlide`, `getSlideById`, `listSlides`, `listAdminStudioState`, `listStorefrontStories`
44
+ - **Product Hotspots:** `addHotspotToSlide`, `removeHotspot`, `removeHotspotsByProductId`
45
+ - **Interactive Stickers:** `addStickerToSlide`, `removeSticker`, `interactWithSticker`
46
+ - **Analytics & Expiration:** `recordEngagementEvent`, `getAnalyticsOverview`, `expireOutdatedStories`
@@ -0,0 +1,15 @@
1
+ export {
2
+ default,
3
+ STORIES_MODULE,
4
+ LEGACY_STORIES_MODULE,
5
+ StoriesModuleService,
6
+ StoriesService,
7
+ resolveStoriesService,
8
+ type StoryServiceType,
9
+ type IStoryService,
10
+ } from "./story"
11
+ export * from "./story"
12
+ export * from "./story/models"
13
+ export * from "./story/service"
14
+ export * from "./story/types"
15
+ export * from "./story/utils/security"
@@ -0,0 +1,11 @@
1
+ export {
2
+ default,
3
+ STORIES_MODULE,
4
+ LEGACY_STORIES_MODULE,
5
+ StoriesModuleService,
6
+ StoriesService,
7
+ resolveStoriesService,
8
+ type StoryServiceType,
9
+ type IStoryService,
10
+ } from "../story"
11
+ export * from "../story"
@@ -0,0 +1,34 @@
1
+ import { Module } from "@medusajs/framework/utils"
2
+ import StoriesModuleService from "./service"
3
+ import { LEGACY_STORIES_MODULE, STORIES_MODULE } from "./types"
4
+
5
+ export type StoryServiceType = typeof StoriesModuleService
6
+ export type IStoryService = StoriesModuleService
7
+
8
+ export function resolveStoriesService(scope: {
9
+ resolve: (key: string) => unknown
10
+ }): StoriesModuleService {
11
+ try {
12
+ const svc = scope.resolve(STORIES_MODULE)
13
+ if (svc) {
14
+ return svc as StoriesModuleService
15
+ }
16
+ } catch {
17
+ // Fall back to legacy @bambiste/medusa-stories module key ("Story")
18
+ }
19
+ return scope.resolve(LEGACY_STORIES_MODULE) as StoriesModuleService
20
+ }
21
+
22
+ export {
23
+ STORIES_MODULE,
24
+ LEGACY_STORIES_MODULE,
25
+ StoriesModuleService,
26
+ StoriesModuleService as StoriesService,
27
+ }
28
+ export * from "./models"
29
+ export * from "./types"
30
+ export * from "./utils/security"
31
+
32
+ export default Module(STORIES_MODULE, {
33
+ service: StoriesModuleService,
34
+ })
@@ -0,0 +1,196 @@
1
+ import { Migration } from "@mikro-orm/migrations"
2
+
3
+ export class Migration20260514000000 extends Migration {
4
+ override async up(): Promise<void> {
5
+ this.addSql(`
6
+ CREATE TABLE IF NOT EXISTS "mps_story_group" (
7
+ "id" text NOT NULL,
8
+ "title" text NOT NULL,
9
+ "handle" text NOT NULL,
10
+ "subtitle" text NULL,
11
+ "avatar_url" text NULL,
12
+ "ring_theme" text NOT NULL DEFAULT 'instagram',
13
+ "custom_ring_color" text NULL,
14
+ "placement" text NOT NULL DEFAULT 'home',
15
+ "target_entity_id" text NULL,
16
+ "is_pinned" boolean NOT NULL DEFAULT true,
17
+ "is_ephemeral" boolean NOT NULL DEFAULT false,
18
+ "is_active" boolean NOT NULL DEFAULT true,
19
+ "display_order" integer NOT NULL DEFAULT 0,
20
+ "metadata" jsonb NULL,
21
+ "created_at" timestamptz NOT NULL DEFAULT now(),
22
+ "updated_at" timestamptz NOT NULL DEFAULT now(),
23
+ "deleted_at" timestamptz NULL,
24
+ CONSTRAINT "PK_mps_story_group" PRIMARY KEY ("id")
25
+ );
26
+ `)
27
+
28
+ this.addSql(`
29
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_group_handle"
30
+ ON "mps_story_group" ("handle")
31
+ WHERE "deleted_at" IS NULL;
32
+ `)
33
+
34
+ this.addSql(`
35
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_group_placement_active"
36
+ ON "mps_story_group" ("placement", "is_active")
37
+ WHERE "deleted_at" IS NULL;
38
+ `)
39
+
40
+ this.addSql(`
41
+ CREATE TABLE IF NOT EXISTS "story" (
42
+ "id" text NOT NULL,
43
+ "group_id" text NULL,
44
+ "title" text NOT NULL,
45
+ "caption" text NULL,
46
+ "media_type" text NOT NULL DEFAULT 'image',
47
+ "media_url" text NOT NULL,
48
+ "thumbnail_url" text NULL,
49
+ "duration_ms" integer NOT NULL DEFAULT 5000,
50
+ "link_url" text NULL,
51
+ "link_text" text NULL,
52
+ "is_active" boolean NOT NULL DEFAULT true,
53
+ "display_order" integer NOT NULL DEFAULT 0,
54
+ "starts_at" timestamptz NULL,
55
+ "expires_at" timestamptz NULL,
56
+ "views_count" integer NOT NULL DEFAULT 0,
57
+ "completions_count" integer NOT NULL DEFAULT 0,
58
+ "clicks_count" integer NOT NULL DEFAULT 0,
59
+ "cart_conversions_count" integer NOT NULL DEFAULT 0,
60
+ "taps_count" integer NOT NULL DEFAULT 0,
61
+ "conversions_count" integer NOT NULL DEFAULT 0,
62
+ "metadata" jsonb NULL,
63
+ "created_at" timestamptz NOT NULL DEFAULT now(),
64
+ "updated_at" timestamptz NOT NULL DEFAULT now(),
65
+ "deleted_at" timestamptz NULL,
66
+ CONSTRAINT "PK_story" PRIMARY KEY ("id")
67
+ );
68
+ `)
69
+
70
+ this.addSql(`
71
+ ALTER TABLE "story"
72
+ ADD COLUMN IF NOT EXISTS "group_id" text NULL,
73
+ ADD COLUMN IF NOT EXISTS "caption" text NULL,
74
+ ADD COLUMN IF NOT EXISTS "duration_ms" integer NOT NULL DEFAULT 5000,
75
+ ADD COLUMN IF NOT EXISTS "starts_at" timestamptz NULL,
76
+ ADD COLUMN IF NOT EXISTS "views_count" integer NOT NULL DEFAULT 0,
77
+ ADD COLUMN IF NOT EXISTS "completions_count" integer NOT NULL DEFAULT 0,
78
+ ADD COLUMN IF NOT EXISTS "clicks_count" integer NOT NULL DEFAULT 0,
79
+ ADD COLUMN IF NOT EXISTS "cart_conversions_count" integer NOT NULL DEFAULT 0,
80
+ ADD COLUMN IF NOT EXISTS "taps_count" integer NOT NULL DEFAULT 0,
81
+ ADD COLUMN IF NOT EXISTS "conversions_count" integer NOT NULL DEFAULT 0,
82
+ ADD COLUMN IF NOT EXISTS "metadata" jsonb NULL;
83
+ `)
84
+
85
+ this.addSql(`
86
+ CREATE INDEX IF NOT EXISTS "IDX_story_group_id_active"
87
+ ON "story" ("group_id", "is_active")
88
+ WHERE "deleted_at" IS NULL;
89
+ `)
90
+
91
+ this.addSql(`
92
+ CREATE INDEX IF NOT EXISTS "IDX_story_active_display_order"
93
+ ON "story" ("is_active", "display_order")
94
+ WHERE "deleted_at" IS NULL;
95
+ `)
96
+
97
+ this.addSql(`
98
+ CREATE TABLE IF NOT EXISTS "mps_story_hotspot" (
99
+ "id" text NOT NULL,
100
+ "story_id" text NOT NULL,
101
+ "product_id" text NOT NULL,
102
+ "variant_id" text NULL,
103
+ "product_title" text NOT NULL,
104
+ "product_handle" text NULL,
105
+ "product_thumbnail" text NULL,
106
+ "price_formatted" text NULL,
107
+ "price_amount" numeric NULL,
108
+ "currency_code" text NULL,
109
+ "x_percent" numeric NOT NULL DEFAULT 50,
110
+ "y_percent" numeric NOT NULL DEFAULT 50,
111
+ "label" text NULL,
112
+ "badge_style" text NOT NULL DEFAULT 'pill',
113
+ "created_at" timestamptz NOT NULL DEFAULT now(),
114
+ "updated_at" timestamptz NOT NULL DEFAULT now(),
115
+ "deleted_at" timestamptz NULL,
116
+ CONSTRAINT "PK_mps_story_hotspot" PRIMARY KEY ("id")
117
+ );
118
+ `)
119
+
120
+ this.addSql(`
121
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_hotspot_story_id"
122
+ ON "mps_story_hotspot" ("story_id")
123
+ WHERE "deleted_at" IS NULL;
124
+ `)
125
+
126
+ this.addSql(`
127
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_hotspot_product_id"
128
+ ON "mps_story_hotspot" ("product_id")
129
+ WHERE "deleted_at" IS NULL;
130
+ `)
131
+
132
+ this.addSql(`
133
+ CREATE TABLE IF NOT EXISTS "mps_story_sticker" (
134
+ "id" text NOT NULL,
135
+ "story_id" text NOT NULL,
136
+ "type" text NOT NULL DEFAULT 'poll',
137
+ "prompt" text NOT NULL,
138
+ "x_percent" numeric NOT NULL DEFAULT 50,
139
+ "y_percent" numeric NOT NULL DEFAULT 25,
140
+ "options" jsonb NULL,
141
+ "coupon_code" text NULL,
142
+ "countdown_until" text NULL,
143
+ "total_interactions" integer NOT NULL DEFAULT 0,
144
+ "metadata" jsonb NULL,
145
+ "created_at" timestamptz NOT NULL DEFAULT now(),
146
+ "updated_at" timestamptz NOT NULL DEFAULT now(),
147
+ "deleted_at" timestamptz NULL,
148
+ CONSTRAINT "PK_mps_story_sticker" PRIMARY KEY ("id")
149
+ );
150
+ `)
151
+
152
+ this.addSql(`
153
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_sticker_story_id"
154
+ ON "mps_story_sticker" ("story_id")
155
+ WHERE "deleted_at" IS NULL;
156
+ `)
157
+
158
+ this.addSql(`
159
+ CREATE TABLE IF NOT EXISTS "mps_story_event" (
160
+ "id" text NOT NULL,
161
+ "story_id" text NOT NULL,
162
+ "group_id" text NULL,
163
+ "event_type" text NOT NULL,
164
+ "hotspot_id" text NULL,
165
+ "sticker_id" text NULL,
166
+ "product_id" text NULL,
167
+ "session_id" text NULL,
168
+ "metadata" jsonb NULL,
169
+ "created_at" timestamptz NOT NULL DEFAULT now(),
170
+ "updated_at" timestamptz NOT NULL DEFAULT now(),
171
+ "deleted_at" timestamptz NULL,
172
+ CONSTRAINT "PK_mps_story_event" PRIMARY KEY ("id")
173
+ );
174
+ `)
175
+
176
+ this.addSql(`
177
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_event_story_type"
178
+ ON "mps_story_event" ("story_id", "event_type")
179
+ WHERE "deleted_at" IS NULL;
180
+ `)
181
+
182
+ this.addSql(`
183
+ CREATE INDEX IF NOT EXISTS "IDX_mps_story_event_group_type"
184
+ ON "mps_story_event" ("group_id", "event_type")
185
+ WHERE "deleted_at" IS NULL;
186
+ `)
187
+ }
188
+
189
+ override async down(): Promise<void> {
190
+ this.addSql(`DROP TABLE IF EXISTS "mps_story_event" CASCADE;`)
191
+ this.addSql(`DROP TABLE IF EXISTS "mps_story_sticker" CASCADE;`)
192
+ this.addSql(`DROP TABLE IF EXISTS "mps_story_hotspot" CASCADE;`)
193
+ this.addSql(`DROP TABLE IF EXISTS "story" CASCADE;`)
194
+ this.addSql(`DROP TABLE IF EXISTS "mps_story_group" CASCADE;`)
195
+ }
196
+ }
@@ -0,0 +1,146 @@
1
+ import { model } from "@medusajs/framework/utils"
2
+
3
+ export const StoryGroup = model
4
+ .define("mps_story_group", {
5
+ id: model.id({ prefix: "sgrp" }).primaryKey(),
6
+ title: model.text().searchable(),
7
+ handle: model.text().searchable(),
8
+ subtitle: model.text().nullable(),
9
+ avatar_url: model.text().nullable(),
10
+ ring_theme: model
11
+ .enum([
12
+ "instagram",
13
+ "tiktok",
14
+ "sunset",
15
+ "emerald",
16
+ "violet",
17
+ "cyber",
18
+ "neon",
19
+ "gold",
20
+ "minimal",
21
+ "custom",
22
+ ])
23
+ .default("instagram"),
24
+ custom_ring_color: model.text().nullable(),
25
+ placement: model
26
+ .enum([
27
+ "home",
28
+ "collection",
29
+ "category",
30
+ "product",
31
+ "floating_bubble",
32
+ "global",
33
+ ])
34
+ .default("home"),
35
+ target_entity_id: model.text().nullable(),
36
+ is_pinned: model.boolean().default(true),
37
+ is_ephemeral: model.boolean().default(false),
38
+ is_active: model.boolean().default(true),
39
+ display_order: model.number().default(0),
40
+ metadata: model.json().nullable(),
41
+ })
42
+ .indexes([{ on: ["handle"] }, { on: ["placement", "is_active"] }])
43
+
44
+ /**
45
+ * Backward-compatible with `@bambiste/medusa-stories` `Story` model (`title`, `media_type`,
46
+ * `media_url`, `thumbnail_url`, `link_url`, `link_text`, `is_active`, `display_order`, `expires_at`)
47
+ * plus group association, duration, scheduling, and funnel counters.
48
+ */
49
+ export const Story = model
50
+ .define("story", {
51
+ id: model.id({ prefix: "stry" }).primaryKey(),
52
+ group_id: model.text().nullable(),
53
+ title: model.text().searchable(),
54
+ caption: model.text().nullable(),
55
+ media_type: model.enum(["image", "video"]).default("image"),
56
+ media_url: model.text(),
57
+ thumbnail_url: model.text().nullable(),
58
+ duration_ms: model.number().default(5000),
59
+ link_url: model.text().nullable(),
60
+ link_text: model.text().nullable(),
61
+ is_active: model.boolean().default(true),
62
+ display_order: model.number().default(0),
63
+ starts_at: model.dateTime().nullable(),
64
+ expires_at: model.dateTime().nullable(),
65
+ views_count: model.number().default(0),
66
+ completions_count: model.number().default(0),
67
+ clicks_count: model.number().default(0),
68
+ cart_conversions_count: model.number().default(0),
69
+ metadata: model.json().nullable(),
70
+ })
71
+ .indexes([
72
+ { on: ["group_id", "is_active"] },
73
+ { on: ["is_active", "display_order"] },
74
+ ])
75
+
76
+ export const StoryHotspot = model
77
+ .define("mps_story_hotspot", {
78
+ id: model.id({ prefix: "shsp" }).primaryKey(),
79
+ story_id: model.text(),
80
+ product_id: model.text(),
81
+ variant_id: model.text().nullable(),
82
+ product_title: model.text(),
83
+ product_handle: model.text().nullable(),
84
+ product_thumbnail: model.text().nullable(),
85
+ price_formatted: model.text().nullable(),
86
+ price_amount: model.number().nullable(),
87
+ currency_code: model.text().nullable(),
88
+ x_percent: model.number().default(50),
89
+ y_percent: model.number().default(50),
90
+ label: model.text().nullable(),
91
+ badge_style: model.enum(["pill", "card", "dot"]).default("pill"),
92
+ })
93
+ .indexes([{ on: ["story_id"] }, { on: ["product_id"] }])
94
+
95
+ export const StorySticker = model
96
+ .define("mps_story_sticker", {
97
+ id: model.id({ prefix: "sstk" }).primaryKey(),
98
+ story_id: model.text(),
99
+ type: model
100
+ .enum(["poll", "countdown", "coupon", "question_badge"])
101
+ .default("poll"),
102
+ prompt: model.text(),
103
+ x_percent: model.number().default(50),
104
+ y_percent: model.number().default(25),
105
+ options: model.json().nullable(),
106
+ coupon_code: model.text().nullable(),
107
+ countdown_until: model.text().nullable(),
108
+ total_interactions: model.number().default(0),
109
+ metadata: model.json().nullable(),
110
+ })
111
+ .indexes([{ on: ["story_id"] }])
112
+
113
+ export const StoryEvent = model
114
+ .define("mps_story_event", {
115
+ id: model.id({ prefix: "sevt" }).primaryKey(),
116
+ story_id: model.text(),
117
+ group_id: model.text().nullable(),
118
+ event_type: model.enum([
119
+ "impression",
120
+ "complete",
121
+ "tap_forward",
122
+ "tap_back",
123
+ "exit",
124
+ "hotspot_click",
125
+ "link_click",
126
+ "add_to_cart",
127
+ "sticker_interact",
128
+ ]),
129
+ hotspot_id: model.text().nullable(),
130
+ sticker_id: model.text().nullable(),
131
+ product_id: model.text().nullable(),
132
+ session_id: model.text().nullable(),
133
+ metadata: model.json().nullable(),
134
+ })
135
+ .indexes([
136
+ { on: ["story_id", "event_type"] },
137
+ { on: ["group_id", "event_type"] },
138
+ ])
139
+
140
+ export const StoriesModels = {
141
+ StoryGroup,
142
+ Story,
143
+ StoryHotspot,
144
+ StorySticker,
145
+ StoryEvent,
146
+ }