@mittwald/ext-bridge 1.0.9 → 1.1.0-next.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.
package/MIGRATION.md ADDED
@@ -0,0 +1,183 @@
1
+ # Migrations
2
+
3
+ ---
4
+
5
+ ## From version `0.2.0-alpha.1050` to `>=0.2.0-alpha.1051`
6
+
7
+ ### Context parameters are typed, and config values are never `null`
8
+
9
+ The config type and the runtime parse disagreed about unknown keys: the type
10
+ stripped them, the runtime kept them. An extension reading a host-supplied
11
+ context parameter such as `containerId` had to narrow at runtime
12
+ (`typeof x === "string"`) because the type said the key did not exist.
13
+
14
+ Both sides agree again. The known context parameters are declared, an undeclared
15
+ one still comes through, and every optional config value is typed
16
+ `string | undefined`:
17
+
18
+ ```diff
19
+ - const containerId =
20
+ - typeof (config as Record<string, unknown>).containerId === "string"
21
+ - ? (config as Record<string, unknown>).containerId
22
+ - : undefined;
23
+ + const containerId = config.containerId;
24
+ ```
25
+
26
+ Declared context parameters: `aiApiKeyId`, `appInstallationId`, `backupId`,
27
+ `certificateId`, `containerId`, `contractId`, `conversationId`, `cronjobId`,
28
+ `customerId`, `databaseId`, `deliveryBoxId`, `domainId`, `emailAddressId`,
29
+ `ingressId`, `leadId`, `licenseId`, `mailAddressId`, `projectId`, `registryId`,
30
+ `scheduleId`, `serverId`, `sftpUserId`, `sshUserId`, `stackId`, `templateId`,
31
+ `zoneId`. `emailAddressId` (use `mailAddressId`) and `ingressId` (use
32
+ `domainId`) are deprecated and stay declared.
33
+
34
+ **Type-breaking:** optional config values lost `null` from their type —
35
+ `variantKey` was `string | null | undefined` and is now `string | undefined`,
36
+ and the same applies to every context parameter and to unknown keys. A host that
37
+ still sends `null` is parsed as "value absent", so `null` no longer reaches a
38
+ consumer. Narrowing with `typeof x === "string"` or a truthiness check keeps
39
+ working unchanged; only an explicit `=== null` branch becomes dead code and can
40
+ go:
41
+
42
+ ```diff
43
+ - if (config.variantKey === null) {
44
+ - return fallback;
45
+ - }
46
+ if (config.variantKey === undefined) {
47
+ return fallback;
48
+ }
49
+ ```
50
+
51
+ ---
52
+
53
+ ## From version 0.2.0-alpha.1020 to version 0.2.0-alpha.1021
54
+
55
+ ### `HostConfig` no longer comes from an unpublished package
56
+
57
+ Between `0.2.0-alpha.789` and `0.2.0-alpha.1020`, the published types imported
58
+ `HostConfig` from `@mittwald/flow-core` — a private workspace package that is
59
+ not on npm. `tsc` stayed quiet because of `skipLibCheck`, but the import
60
+ resolved to nothing, so `useConfig()` and `getConfig()` collapsed to the error
61
+ type. Typed lint rules (`@typescript-eslint/no-unsafe-*`) then failed on every
62
+ usage.
63
+
64
+ `HostConfig` is now declared in `@mittwald/ext-bridge` itself and exported from
65
+ the package root:
66
+
67
+ ```ts
68
+ import type { ExtBridgeConfig, HostConfig } from "@mittwald/ext-bridge";
69
+ ```
70
+
71
+ Update to `>=0.2.0-alpha.1021` and remove any local workaround — an ambient
72
+ `declare module "@mittwald/flow-core"` stub, a `paths` entry in `tsconfig.json`,
73
+ or a hand-written `HostConfig` copy. The same import was removed from
74
+ `@mittwald/flow-remote-core` and `@mittwald/flow-remote-react-renderer`.
75
+
76
+ ---
77
+
78
+ ## From version `0.2.0-alpha.940` to `>=0.2.0-alpha.941`
79
+
80
+ ### Node 24 required
81
+
82
+ `engines.node` went from `>=20.19` to `>=24.0.0`. Node 24 is the only runtime
83
+ this package is tested on. Nothing changes in your code — build and run your
84
+ extension on Node 24. Installing on Node 20 or 22 warns, and fails outright with
85
+ `engine-strict`.
86
+
87
+ ---
88
+
89
+ ## From version `0.2.0-alpha.789` to `>=0.2.0-alpha.790`
90
+
91
+ ### Undeclared context parameters lost their type
92
+
93
+ The schema's `.catchall()` moved into the internal parse, so the config type
94
+ stopped carrying context parameters it did not declare. The runtime kept sending
95
+ them, which is why reading one needed a runtime narrowing:
96
+
97
+ ```ts
98
+ const containerId =
99
+ typeof (config as Record<string, unknown>).containerId === "string"
100
+ ? (config as Record<string, unknown>).containerId
101
+ : undefined;
102
+ ```
103
+
104
+ Fixed in `0.2.0-alpha.1051` — see the entry above and drop the narrowing.
105
+
106
+ ---
107
+
108
+ ## From version `0.2.0-alpha.646` to `>=0.2.0-alpha.647`
109
+
110
+ ### React peer range narrowed to `^19.2.0`
111
+
112
+ The `react` and `react-dom` peer ranges went from `^19` to `^19.2.0`. On React
113
+ 19.0 or 19.1 the install warns about an unmet peer — upgrade React to 19.2 or
114
+ later.
115
+
116
+ ---
117
+
118
+ ## From version 0.2.0-alpha.150 to version 0.2.0-alpha.151
119
+
120
+ This guide covers the key changes for migrating to the latest version of the
121
+ `@mittwald/ext-bridge` library.
122
+
123
+ ### Key Changes
124
+
125
+ #### 1. Environment Variable No Longer Required
126
+
127
+ - **Before**: Setting `MW_EXT_API_URL=api.mittwald.de` was necessary
128
+ - **After**: This environment variable is no longer needed
129
+
130
+ #### 2. Package Export Structure
131
+
132
+ - **Before**: All functions were imported directly from `@mittwald/ext-bridge`
133
+ - **After**: Exports are now split between:
134
+ - `@mittwald/ext-bridge/browser` for browser environments
135
+ - `@mittwald/ext-bridge/node` for Node.js environments
136
+
137
+ #### 3. Config Access Changes
138
+
139
+ - **Before**: Used `useExtBridge()` to access configuration
140
+ - **After**:
141
+ - React: Use `useConfig()` from `@mittwald/ext-bridge/react`
142
+ - Non-React: Use `getConfig()` from `@mittwald/ext-bridge/browser`
143
+
144
+ #### 4. Verify Method Moved
145
+
146
+ - **Before**: `verify()` was available directly from main package
147
+ - **After**: `verify()` is now available from `@mittwald/ext-bridge/node`
148
+
149
+ #### 5. Optional Package Installation
150
+
151
+ - **Before**: Installing `@mittwald/ext-bridge` was required even when not
152
+ directly used
153
+ - **After**: Package only needs to be installed when actually used
154
+
155
+ #### 6. Global Object Removed
156
+
157
+ - **Before**: Used global `mittwald` object
158
+ - **After**: Use `getConfig()` or `useConfig()` functions instead
159
+
160
+ ### Example Code
161
+
162
+ ```javascript
163
+ // Before
164
+ import { useExtBridge } from "@mittwald/ext-bridge";
165
+ const { config } = useExtBridge();
166
+
167
+ // After - React component
168
+ import { useConfig } from "@mittwald/ext-bridge/react";
169
+ const config = useConfig();
170
+
171
+ // After - Browser (non-React)
172
+ import { getConfig } from "@mittwald/ext-bridge/browser";
173
+ const config = getConfig();
174
+
175
+ // Before - verify
176
+ import { verify } from "@mittwald/ext-bridge";
177
+
178
+ // After - verify
179
+ import { verify } from "@mittwald/ext-bridge/node";
180
+ ```
181
+
182
+ This migration guide covers the most significant changes. Be sure to update all
183
+ your imports and method calls according to the new structure.
package/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mittwald/ext-bridge
2
2
 
3
- This package is part of
4
- [Flow – mittwald design system](https://flow.mittwald.de/). See the homepage for
5
- more details.
3
+ The runtime bridge between an **mStudio extension** and the mStudio host: the
4
+ extension's context (user, project, extension instance, language, theme) and the
5
+ session token your backend exchanges for an mStudio API access token.
6
+
7
+ Part of [Flow – mittwald design system](https://flow.mittwald.de/).
8
+
9
+ **[USAGE.md](./USAGE.md)** — the four entry points and which runtime each
10
+ belongs in, reading the context, and the auth flow.
11
+
12
+ Upgrade notes: [MIGRATION.md](./MIGRATION.md).
package/USAGE.md ADDED
@@ -0,0 +1,98 @@
1
+ # Using ext-bridge — guide for agents and developers
2
+
3
+ `@mittwald/ext-bridge` is the runtime bridge between an **mStudio extension**
4
+ and the mStudio host. It answers two questions your extension cannot answer on
5
+ its own:
6
+
7
+ 1. **Where am I running?** Which user, which project, which extension instance,
8
+ which language and theme.
9
+ 2. **How do I prove it?** The session token your own backend exchanges for an
10
+ mStudio API access token.
11
+
12
+ It renders nothing. For the UI side, see
13
+ [`@mittwald/flow-remote-react-components`](https://www.npmjs.com/package/@mittwald/flow-remote-react-components).
14
+
15
+ ## The entry points are not interchangeable
16
+
17
+ | Specifier | Runs in | Exports |
18
+ | ------------------------------ | ---------------------------- | ----------------------------------------------- |
19
+ | `@mittwald/ext-bridge/browser` | the extension iframe | `initExtBridge`, `getConfig`, `getSessionToken` |
20
+ | `@mittwald/ext-bridge/react` | the extension iframe | `useConfig`, `useLanguage` |
21
+ | `@mittwald/ext-bridge/node` | **your extension's backend** | `getAccessToken`, `verify` |
22
+ | `@mittwald/ext-bridge/i18next` | the extension iframe | i18next integration |
23
+ | `@mittwald/ext-bridge` | — | types only, no runtime |
24
+
25
+ The `/node` entry is the one that matters most to get right: `verify` and
26
+ `getAccessToken` handle the extension secret and must **never** run in the
27
+ browser. Importing `/node` into client code leaks that secret.
28
+
29
+ ## Reading the context
30
+
31
+ ```tsx
32
+ import { useConfig, useLanguage } from "@mittwald/ext-bridge/react";
33
+
34
+ const config = useConfig();
35
+ // config.projectId, config.userId, config.extensionInstanceId, config.theme, …
36
+ ```
37
+
38
+ Outside React, `getConfig()` from `/browser` returns the same object. The bridge
39
+ initializes itself and resolves once the host reports readiness, so both are
40
+ async-safe but neither is synchronous on first call.
41
+
42
+ What the config carries:
43
+
44
+ - Always — `sessionId`, `userId`, `extensionId`, `extensionInstanceId`, and the
45
+ host-contributed `language` and `theme`.
46
+ - Optional, depending on where the extension is mounted — `appInstallationId`,
47
+ `projectId`, `customerId`, `variantKey`.
48
+
49
+ **The optional ones are genuinely optional.** An extension mounted at customer
50
+ level has no `projectId`. Branch on their presence instead of assuming the
51
+ context you happened to test in.
52
+
53
+ Use `language` and `theme` from the config rather than sniffing the browser or a
54
+ media query — the host owns both, and the user's mStudio setting is the truth.
55
+
56
+ ## The auth flow
57
+
58
+ Three steps, and the middle one is the one people skip:
59
+
60
+ ```ts
61
+ // 1. in the iframe
62
+ import { getSessionToken } from "@mittwald/ext-bridge/browser";
63
+ const sessionToken = await getSessionToken();
64
+ // send it to your own backend
65
+
66
+ // 2. in your backend — verify before trusting anything in it
67
+ import { verify, getAccessToken } from "@mittwald/ext-bridge/node";
68
+ const decoded = await verify(sessionToken); // JWT signature check
69
+
70
+ // 3. exchange it for an mStudio API token
71
+ const { publicToken, expiry } = await getAccessToken(
72
+ sessionToken,
73
+ process.env.EXTENSION_SECRET!,
74
+ );
75
+ ```
76
+
77
+ - **Always `verify` first.** A session token arrives from the browser; without
78
+ the signature check its contents are attacker-controlled.
79
+ - The extension secret belongs in your backend's environment, never in the
80
+ bundle.
81
+ - `getAccessToken` returns an `expiry` — respect it rather than caching the
82
+ token indefinitely.
83
+
84
+ ## Stability
85
+
86
+ The config schema carries an explicit contract: existing properties are never
87
+ removed, renamed or changed, because extensions in the wild read them. New
88
+ properties are released on the host before clients can rely on them. So reading
89
+ the config is safe across upgrades, and a **newly added** property may not be
90
+ populated by an older host yet.
91
+
92
+ Upgrade notes: [MIGRATION.md](./MIGRATION.md).
93
+
94
+ ## Links
95
+
96
+ - mStudio extension development — <https://developer.mittwald.de>
97
+ - Flow documentation — <https://flow.mittwald.de>
98
+ - Source and issues — <https://github.com/mittwald/flow>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/ext-bridge",
3
- "version": "1.0.9",
3
+ "version": "1.1.0-next.1",
4
4
  "type": "module",
5
5
  "description": "Bridge for mStudio embedded frontend extensions",
6
6
  "homepage": "https://flow.mittwald.de",
@@ -27,6 +27,8 @@
27
27
  }
28
28
  },
29
29
  "files": [
30
+ "MIGRATION.md",
31
+ "USAGE.md",
30
32
  "dist"
31
33
  ],
32
34
  "engines": {
@@ -45,7 +47,7 @@
45
47
  "zod": "^4.4.3"
46
48
  },
47
49
  "devDependencies": {
48
- "@mittwald/typescript-config": "1.0.9",
50
+ "@mittwald/typescript-config": "1.1.0-next.1",
49
51
  "@types/node": "^25.9.3",
50
52
  "@types/react": "^19.2",
51
53
  "@types/react-dom": "^19.2",
@@ -76,5 +78,5 @@
76
78
  "optional": true
77
79
  }
78
80
  },
79
- "gitHead": "574a316e6bbffc1afa5a45582f5b6aee1b17fde8"
81
+ "gitHead": "3d1fcf6eb22e5098804ffadf7537a8005be1c3fc"
80
82
  }