@medusajs/cloud 0.0.0-stage → 2.22.6

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/AGENTS.md ADDED
@@ -0,0 +1,78 @@
1
+ # @medusajs/cloud
2
+
3
+ An official Medusa plugin that adds Medusa Cloud features to the Medusa Admin of every Medusa project, on Medusa Cloud or self-hosted. It currently shows in-app announcements fetched from the Medusa Cloud API: a "What's new" button in the admin topbar that opens a drawer of announcements, and a card at the bottom of the admin sidebar, above Settings, that shows new announcements until they're dismissed. The announcement categories shown to the team are chosen in Settings > Announcements. Announcements of type `admin` can target an admin page through `admin_path`, such as what users can ask an AI tool connected to the Medusa MCP server on the Orders page. Announcements are authored in the Medusa Cloud admin, so they change without a plugin release. It's the place for future Cloud-only admin features, such as feature promotions.
4
+
5
+ ## Using this package
6
+
7
+ - Nothing to install or configure. `@medusajs/medusa` depends on it, and `defineConfig` (`packages/core/utils/src/common/define-config.ts`) adds it to `plugins` of every project.
8
+ - `defineConfig` fills the options from environment variables, which are only set on Medusa Cloud. To override them, list the plugin yourself in `medusa-config.ts`; user entries replace the default by `resolve` key:
9
+
10
+ ```ts
11
+ module.exports = defineConfig({
12
+ plugins: [
13
+ {
14
+ resolve: "@medusajs/cloud",
15
+ options: {
16
+ apiUrl: "https://api.prod.medusajs.cloud",
17
+ organizationId: "org_123",
18
+ disabled: false,
19
+ },
20
+ },
21
+ ],
22
+ })
23
+ ```
24
+
25
+ | Option | Env variable | Default | Description |
26
+ | --- | --- | --- | --- |
27
+ | `apiUrl` | `MEDUSA_CLOUD_API_URL` | `https://api.prod.medusajs.cloud` | Base URL of the Medusa Cloud API. |
28
+ | `organizationId` | `MEDUSA_CLOUD_ORGANIZATION_ID` | none | Used to turn `link_url` paths into links to the organization's Cloud dashboard; without it they lead to the Medusa Cloud sign-up page. Also sent as the `x-medusa-organization` header. |
29
+ | `planHandle` | `MEDUSA_CLOUD_PLAN_HANDLE` | none | The handle of the organization's Cloud plan. Sent as the `plan_handle` query parameter so the Cloud API also returns announcements targeted at that plan. Without it, only announcements with no plan targeting are returned. |
30
+ | `disabled` | none | `false` | When `true`, `defineConfig` leaves the plugin out of `plugins`, so nothing of it loads: no Cloud API calls, admin widgets, Settings > Announcements page, API routes, or module. |
31
+
32
+ - Plugin docs: https://docs.medusajs.com/learn/fundamentals/plugins.md
33
+
34
+ ## Architecture
35
+
36
+ - `src/api/admin/cloud/announcements/route.ts`: `GET /admin/cloud/announcements`, authenticated like every `/admin` route. It resolves the Cloud module (`CLOUD_MODULE`), and calls `listAnnouncements()`. On failure it logs a warning and returns an empty list so the admin never breaks.
37
+ - `src/modules/cloud`: the `cloud` module, registered automatically like every plugin module, so its service gets the plugin options. `CloudModuleService` (`service.ts`) sends all requests to the Medusa Cloud API through `request_()`. `listAnnouncements()` fetches the latest 50 announcements of the enabled categories' types from the public, unauthenticated `GET /v1/announcements` (5s timeout), with the `plan_handle` filter when `planHandle` is set. It keeps only display fields (no `plan_handles`), drops announcements whose `published_at` is in the future (scheduled), drops links and images that aren't `http(s)`, turns a `link_url` path such as `/settings` into a link to the organization's Cloud dashboard (`https://cloud.medusajs.com/<organizationId>/settings`, or the sign-up page (`CLOUD_SIGNUP_URL`, `https://cloud.medusajs.com/signup` with UTM parameters) when `organizationId` isn't set), keeps `admin_path` only for `admin` announcements (an empty one becomes `null`), and caches each response for 10 minutes with the Caching Module (`Modules.CACHING`) when it's registered, tagged `MedusaCloudAnnouncements` (`ANNOUNCEMENTS_CACHE_TAG`) so it can be cleared with `caching.clear({ tags })`. Without it, nothing is cached and every request hits the Cloud API. Cache read and write errors are logged as warnings and never fail the request.
38
+ - Announcement preferences: team-wide, shared by every admin user. They're stored in the `cloud` module's `CloudAnnouncementPreference` model (`src/modules/cloud/models/cloud-announcement-preference.ts`, table `cloud_announcement_preference`) as a single row with a boolean per category (`security`, `feature`, `cloud`). Every category is enabled until the row exists.
39
+ - `listAnnouncements()` in the service reads the row and maps each enabled category to its types (`ANNOUNCEMENT_CATEGORY_TYPES`): `security` covers `security` and `incident`, `feature` covers `feature`, and `cloud` covers `cloud-feature` and `admin`. It sends them to the Cloud API as the `type[]` filter. With every category disabled, the Cloud API isn't called.
40
+ - `src/api/admin/cloud/announcement-preferences/route.ts`: `GET` returns the preferences and `POST` updates the passed categories through `updateAnnouncementPreferencesWorkflow` (`src/workflows/update-announcement-preferences.ts`), which creates the row the first time. The body is validated in `src/api/middlewares.ts`.
41
+ - `src/admin/routes/settings/announcements/page.tsx`: the Settings > Announcements page with a switch per category.
42
+ - RBAC: with the RBAC module installed, the admin routes are guarded by the `cloud_announcement` resource (`src/api/middlewares.ts`). `cloud_announcement:read` covers `GET /admin/cloud/announcements` and `GET /admin/cloud/announcement-preferences`, and `cloud_announcement:update` covers `POST /admin/cloud/announcement-preferences`. Without RBAC, `authorize` is a no-op.
43
+ - `src/types/rbac.ts` declares the resource, and `src/migration-scripts/create-cloud-rbac-policies.ts` creates the two policies on `db:migrate` (skipped, and retried later, while RBAC isn't installed). It calls the RBAC module directly instead of `createRbacPoliciesWorkflow`, because the plugin can't depend on `@medusajs/medusa`.
44
+ - In the admin, the widgets only fetch announcements with `cloud_announcement:read`, the settings page needs it to show, and its switches are disabled without `cloud_announcement:update`.
45
+ - `src/admin/widgets/cloud-announcements.tsx`: widget in the `topbar` zone. Renders no button when there are no announcements. Its drawer lists every announcement, or shows one announcement's details (`src/admin/components/announcement-details.tsx`) when opened from a list item with `content`. Read state is stored per browser in `localStorage` (`src/admin/lib/storage.ts`).
46
+ - `src/admin/widgets/cloud-announcement-card.tsx`: widget in the `sidebar.settings.before` zone, which the dashboard renders above the Settings item of the main sidebar. Shows one announcement as a card with its image, title, subtitle, and one action: "View details" (opens the details drawer) when the announcement has `content`, or else "Learn more" (opens `link_url` in a new tab). `getAnnouncementForPath` (`src/admin/lib/announcements.ts`) picks it the same way for every type:
47
+ - An announcement whose `admin_path` matches the page exactly (trailing slashes ignored) wins.
48
+ - Otherwise, the newest one without an `admin_path`, which can be shown on any page. Every type other than `admin` has none.
49
+ - It stays until it's dismissed with the close button or Esc, or its action is used. The IDs of dismissed announcements are stored per browser in `localStorage`.
50
+ - The first time the admin opens in a browser, the current date is stored in `localStorage` (`getAnnouncementsSince`). Announcements published on or before it never show in the card and aren't marked as new in the topbar drawer, so a new install isn't flooded with old announcements. The drawer still lists them.
51
+ - After one is dismissed, the next matching announcement shows the next time a page opens, not right away.
52
+ - `src/admin/lib/sdk.ts`: JS SDK client configured from the admin build globals `__BACKEND_URL__`, `__AUTH_TYPE__`, `__JWT_TOKEN_STORAGE_KEY__` (declared in `src/admin/vite-env.d.ts`).
53
+ - `src/index.ts` and `index.d.ts` are intentional no-ops for the TypeScript compiler.
54
+
55
+ ## Development
56
+
57
+ ```bash
58
+ yarn build:plugin # medusa plugin:build -> .medusa/server (the only published dir)
59
+ yarn dev # medusa plugin:develop (watch + publish to local registry)
60
+ yarn test # jest unit tests under src/**/__tests__
61
+ yarn medusa plugin:db:generate # generate a migration after changing a model in src/modules/cloud/models
62
+ ```
63
+
64
+ - HTTP integration tests for `/admin/cloud/announcements` and `/admin/cloud/announcement-preferences` live in `integration-tests/http/__tests__/cloud/admin/announcements.spec.ts`, and the RBAC ones in `rbac.spec.ts` next to it. `integration-tests/http/medusa-config.js` registers the plugin with `apiUrl: "http://cloud-api.test"`, and the spec mocks `global.fetch` for that URL. They run against the built plugin, so run `yarn build:plugin` first.
65
+
66
+ - The Cloud API source lives in the private platform repository (`apps/backend/src/api/v1/announcements`).
67
+
68
+ ## Gotchas
69
+
70
+ - The `MedusaService` key of a model must match its table name in PascalCase (`CloudAnnouncementPreference` for `cloud_announcement_preference`), or `query.graph` fails with `Method "listCloudAnnouncementPreferences" does not exist on "cloud"`.
71
+ - Until the module's migration runs, `GET /admin/cloud/announcements` fails to read the preferences and returns an empty list.
72
+ - Don't add `@medusajs/medusa` as a dependency: it already depends on this package.
73
+ - `tsconfig.json` excludes `src/admin`; admin code is type-checked with `src/admin/tsconfig.json` and bundled by `plugin:build`.
74
+ - `content` is HTML authored in the Cloud admin and forwarded as is. Always render it through `sanitizeHtml` (`src/admin/lib/sanitize.ts`, DOMPurify), never directly.
75
+ - Announcement types are `cloud-feature` (the default when the Cloud API sends none), `feature`, `security`, `incident`, and `admin`. They must match the platform's `AnnouncementTypeSchema`.
76
+ - It runs on self-hosted projects too, where the backend calls the public Medusa Cloud API to fetch announcements. To turn it off, list the plugin in `medusa-config.ts` with `options: { disabled: true }`. `defineConfig` (`resolvePlugins`) then removes it from `plugins`, because admin widgets and UI routes can't be hidden at runtime. The plugin itself doesn't read `disabled`, so a config that isn't built with `defineConfig` still loads it.
77
+ - Listing the plugin in `medusa-config.ts` replaces the default entry, so on Cloud pass `apiUrl`, `organizationId`, and `planHandle` again when overriding other options.
78
+ - Medusa Cloud doesn't inject `MEDUSA_CLOUD_API_URL`, `MEDUSA_CLOUD_ORGANIZATION_ID`, or `MEDUSA_CLOUD_PLAN_HANDLE` yet, so by default the plugin uses the production API, shows only announcements visible to all plans, and `link_url` paths lead to the sign-up page.
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/cloud
12
+ </h1>
2
13
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
14
+ <p align="center">
15
+ Adds Medusa Cloud features, such as in-app announcements, to the Medusa Admin.
16
+ </p>
17
+
18
+ ## Usage
19
+
20
+ The plugin is added automatically to every Medusa project, whether it runs on [Medusa Cloud](https://docs.medusajs.com/cloud) or is self-hosted. You don't need to install or configure it.
21
+
22
+ It adds a "What's new" button to the Medusa Admin topbar that lists the latest Medusa Cloud announcements, and shows new announcements in a card at the bottom of the sidebar until you dismiss them. An announcement with more content opens in a details drawer. Some announcements target an admin page, such as a tip on the Orders page about what you can ask an AI tool connected to the [Medusa MCP server](https://docs.medusajs.com/cloud/medusa-mcp). Others can be shown on any page.
23
+
24
+ Choose the announcements your team sees in **Settings > Announcements**: security updates, feature announcements, and Cloud announcements.
25
+
26
+ If you use role-based access control (RBAC), add the `cloud_announcement:read` policy to a role to let its users see announcements, and `cloud_announcement:update` to let them change these settings.
27
+
28
+ ## Options
29
+
30
+ | Option | Env variable | Description |
31
+ | --- | --- | --- |
32
+ | `apiUrl` | `MEDUSA_CLOUD_API_URL` | Base URL of the Medusa Cloud API. Defaults to `https://api.prod.medusajs.cloud`. |
33
+ | `organizationId` | `MEDUSA_CLOUD_ORGANIZATION_ID` | Medusa Cloud organization ID, used to link announcements to your organization's Cloud dashboard. |
34
+ | `planHandle` | `MEDUSA_CLOUD_PLAN_HANDLE` | Handle of your Medusa Cloud plan, used to include announcements targeted at the plan. |
35
+ | `disabled` | none | Set to `true` to disable the plugin. It isn't loaded, so no announcements, admin widgets, or settings page are added. |
36
+
37
+ ## Resources
38
+
39
+ - [Plugins documentation](https://docs.medusajs.com/learn/fundamentals/plugins)
40
+ - [Medusa Cloud documentation](https://docs.medusajs.com/cloud)
package/package.json CHANGED
@@ -1,6 +1,112 @@
1
1
  {
2
2
  "name": "@medusajs/cloud",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.22.6",
4
+ "description": "A Medusa plugin that adds Medusa Cloud features, such as in-app announcements, to the Medusa Admin.",
5
+ "author": "Medusa (https://medusajs.com)",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/medusajs/medusa.git",
10
+ "directory": "packages/plugins/cloud"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/medusajs/medusa/issues"
14
+ },
15
+ "files": [
16
+ ".medusa/server",
17
+ "AGENTS.md"
18
+ ],
19
+ "llms": "https://docs.medusajs.com/llms.txt",
20
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
21
+ "mcpServer": "https://docs.medusajs.com/mcp",
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ "./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
25
+ "./modules/*": "./.medusa/server/src/modules/*/index.js",
26
+ "./*": "./.medusa/server/src/*.js",
27
+ "./admin": {
28
+ "import": "./.medusa/server/src/admin/index.mjs",
29
+ "require": "./.medusa/server/src/admin/index.js",
30
+ "default": "./.medusa/server/src/admin/index.js"
31
+ }
32
+ },
33
+ "keywords": [
34
+ "medusa",
35
+ "plugin",
36
+ "medusa-plugin",
37
+ "medusa-v2",
38
+ "medusa-cloud"
39
+ ],
40
+ "scripts": {
41
+ "build:plugin": "medusa plugin:build",
42
+ "dev": "medusa plugin:develop",
43
+ "prepare": "cross-env NODE_ENV=production yarn run build:plugin",
44
+ "link:watch": "medusa plugin:publish && medusa plugin:develop",
45
+ "watch": "medusa plugin:develop",
46
+ "test": "../../../node_modules/.bin/jest --bail --forceExit --testPathPatterns=src"
47
+ },
48
+ "dependencies": {
49
+ "@medusajs/js-sdk": "2.22.6",
50
+ "@tanstack/react-query": "5.64.2",
51
+ "dompurify": "3.4.17"
52
+ },
53
+ "devDependencies": {
54
+ "@medusajs/admin-sdk": "2.22.6",
55
+ "@medusajs/cli": "2.22.6",
56
+ "@medusajs/dashboard": "2.22.6",
57
+ "@medusajs/framework": "2.22.6",
58
+ "@medusajs/icons": "2.22.6",
59
+ "@medusajs/types": "2.22.6",
60
+ "@medusajs/ui": "4.2.13",
61
+ "@medusajs/ui-preset": "2.22.6",
62
+ "@swc/core": "^1.16.20",
63
+ "@types/node": "^22.20.5",
64
+ "cross-env": "^10.1.0",
65
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
66
+ },
67
+ "peerDependencies": {
68
+ "@medusajs/admin-sdk": "2.22.6",
69
+ "@medusajs/cli": "2.22.6",
70
+ "@medusajs/dashboard": "2.22.6",
71
+ "@medusajs/framework": "2.22.6",
72
+ "@medusajs/icons": "2.22.6",
73
+ "@medusajs/test-utils": "2.22.6",
74
+ "@medusajs/ui": "4.2.13",
75
+ "react": "^18.3.1",
76
+ "react-dom": "^18.3.1",
77
+ "react-router-dom": "^6.30.4 || ^7.0.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "@medusajs/admin-sdk": {
81
+ "optional": true
82
+ },
83
+ "@medusajs/cli": {
84
+ "optional": true
85
+ },
86
+ "@medusajs/dashboard": {
87
+ "optional": true
88
+ },
89
+ "@medusajs/icons": {
90
+ "optional": true
91
+ },
92
+ "@medusajs/test-utils": {
93
+ "optional": true
94
+ },
95
+ "@medusajs/ui": {
96
+ "optional": true
97
+ },
98
+ "react": {
99
+ "optional": true
100
+ },
101
+ "react-dom": {
102
+ "optional": true
103
+ },
104
+ "react-router-dom": {
105
+ "optional": true
106
+ }
107
+ },
108
+ "engines": {
109
+ "node": ">=22.22.0"
110
+ },
111
+ "packageManager": "yarn@4.18.1"
112
+ }