@immediately-run/sdk 0.1.4 → 0.2.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.
Files changed (43) hide show
  1. package/dist/contribute.cjs +32 -0
  2. package/dist/contribute.cjs.map +1 -0
  3. package/dist/contribute.d.cts +100 -0
  4. package/dist/contribute.d.ts +100 -0
  5. package/dist/contribute.js +8 -0
  6. package/dist/contribute.js.map +1 -0
  7. package/dist/editorContext.cjs +46 -0
  8. package/dist/editorContext.cjs.map +1 -0
  9. package/dist/editorContext.d.cts +32 -0
  10. package/dist/editorContext.d.ts +32 -0
  11. package/dist/editorContext.js +20 -0
  12. package/dist/editorContext.js.map +1 -0
  13. package/dist/formFactor.cjs +46 -0
  14. package/dist/formFactor.cjs.map +1 -0
  15. package/dist/formFactor.d.cts +29 -0
  16. package/dist/formFactor.d.ts +29 -0
  17. package/dist/formFactor.js +20 -0
  18. package/dist/formFactor.js.map +1 -0
  19. package/dist/index.cjs +10 -0
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +6 -1
  22. package/dist/index.d.ts +6 -1
  23. package/dist/index.js +5 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/mounts.cjs +41 -1
  26. package/dist/mounts.cjs.map +1 -1
  27. package/dist/mounts.d.cts +65 -7
  28. package/dist/mounts.d.ts +65 -7
  29. package/dist/mounts.js +33 -1
  30. package/dist/mounts.js.map +1 -1
  31. package/dist/protocolStream.cjs +87 -0
  32. package/dist/protocolStream.cjs.map +1 -0
  33. package/dist/protocolStream.d.cts +44 -0
  34. package/dist/protocolStream.d.ts +44 -0
  35. package/dist/protocolStream.js +61 -0
  36. package/dist/protocolStream.js.map +1 -0
  37. package/dist/theme.cjs +57 -0
  38. package/dist/theme.cjs.map +1 -0
  39. package/dist/theme.d.cts +38 -0
  40. package/dist/theme.d.ts +38 -0
  41. package/dist/theme.js +30 -0
  42. package/dist/theme.js.map +1 -0
  43. package/package.json +1 -1
package/dist/theme.cjs ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var theme_exports = {};
20
+ __export(theme_exports, {
21
+ getHostTheme: () => getHostTheme,
22
+ onHostThemeChange: () => onHostThemeChange,
23
+ setHostTheme: () => setHostTheme,
24
+ useHostTheme: () => useHostTheme
25
+ });
26
+ module.exports = __toCommonJS(theme_exports);
27
+ var import_react = require("react");
28
+ var import_sandboxUtils = require("./sandboxUtils");
29
+ const themeService = () => {
30
+ return module.evaluation.module.bundler.theme;
31
+ };
32
+ const getHostTheme = () => themeService().getTheme();
33
+ const onHostThemeChange = (listener) => {
34
+ const disposable = themeService().onChange(listener);
35
+ return () => disposable.dispose();
36
+ };
37
+ const useHostTheme = () => {
38
+ const [theme, setTheme] = (0, import_react.useState)(getHostTheme);
39
+ (0, import_react.useEffect)(() => onHostThemeChange(setTheme), []);
40
+ return theme;
41
+ };
42
+ const setHostTheme = async (theme) => {
43
+ const res = await (0, import_sandboxUtils.protocolRequest)("theme", "set", [{ theme }]);
44
+ if (!res || res.ok !== true) {
45
+ const err = new Error(res?.message ?? "setHostTheme failed");
46
+ err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
47
+ throw err;
48
+ }
49
+ };
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ getHostTheme,
53
+ onHostThemeChange,
54
+ setHostTheme,
55
+ useHostTheme
56
+ });
57
+ //# sourceMappingURL=theme.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/theme.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { protocolRequest } from './sandboxUtils';\n\n/**\n * The host UI theme, mirrored from the immediately.run host window into the\n * sandbox. Your app can read this to render in step with the host chrome\n * (light / dark).\n *\n * This is the baseline `theme:read` capability — every app may read it. Changing\n * the host theme is a separate, elevated action (`theme:set`), available only to\n * the theme-toggle system app.\n */\nexport type HostTheme = 'light' | 'dark';\n\ninterface ThemeService {\n getTheme(): HostTheme;\n onChange(listener: (theme: HostTheme) => void): { dispose(): void };\n}\n\n// `module.evaluation.module.bundler.theme` is the sandbox bundler injected into\n// the evaluation context (same path the other SDK helpers use for `auth`).\nconst themeService = (): ThemeService => {\n // @ts-ignore - injected by the sandbox runtime\n return module.evaluation.module.bundler.theme;\n};\n\n/**\n * Returns the current host theme. Poll this for a one-off read; use\n * {@link onHostThemeChange} or {@link useHostTheme} to react to changes.\n */\nexport const getHostTheme = (): HostTheme => themeService().getTheme();\n\n/**\n * Subscribe to host theme changes. The listener is invoked immediately with the\n * current theme, then again on every change. Returns an unsubscribe fn.\n */\nexport const onHostThemeChange = (\n listener: (theme: HostTheme) => void,\n): (() => void) => {\n const disposable = themeService().onChange(listener);\n return () => disposable.dispose();\n};\n\n/**\n * React hook returning the current host theme, re-rendering when it changes.\n * The recommended way to implement an app's own `useTheme`: follow the host,\n * allow a local override.\n */\nexport const useHostTheme = (): HostTheme => {\n const [theme, setTheme] = useState<HostTheme>(getHostTheme);\n useEffect(() => onHostThemeChange(setTheme), []);\n return theme;\n};\n\n/**\n * Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host\n * applies it and re-pushes the new value to every `theme:read` iframe, so your\n * own {@link useHostTheme} confirms the change (the loop closes with no special\n * case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may\n * call this; any other app is rejected host-side with a `forbidden`\n * {@link Error} (carrying `.code`), regardless of what the app claims. Update\n * optimistically and let the re-push confirm.\n */\nexport const setHostTheme = async (theme: HostTheme): Promise<void> => {\n const res = (await protocolRequest('theme', 'set', [{ theme }])) as\n | { ok: true; data?: unknown }\n | { ok: false; code?: string; message?: string }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? 'setHostTheme failed') as Error & {\n code?: string;\n };\n err.code = (res && 'code' in res ? res.code : undefined) ?? 'unknown';\n throw err;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoC;AACpC,0BAAgC;AAoBhC,MAAM,eAAe,MAAoB;AAEvC,SAAO,OAAO,WAAW,OAAO,QAAQ;AAC1C;AAMO,MAAM,eAAe,MAAiB,aAAa,EAAE,SAAS;AAM9D,MAAM,oBAAoB,CAC/B,aACiB;AACjB,QAAM,aAAa,aAAa,EAAE,SAAS,QAAQ;AACnD,SAAO,MAAM,WAAW,QAAQ;AAClC;AAOO,MAAM,eAAe,MAAiB;AAC3C,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB,YAAY;AAC1D,8BAAU,MAAM,kBAAkB,QAAQ,GAAG,CAAC,CAAC;AAC/C,SAAO;AACT;AAWO,MAAM,eAAe,OAAO,UAAoC;AACrE,QAAM,MAAO,UAAM,qCAAgB,SAAS,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AAI9D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,qBAAqB;AAG3D,QAAI,QAAQ,OAAO,UAAU,MAAM,IAAI,OAAO,WAAc;AAC5D,UAAM;AAAA,EACR;AACF;","names":[]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The host UI theme, mirrored from the immediately.run host window into the
3
+ * sandbox. Your app can read this to render in step with the host chrome
4
+ * (light / dark).
5
+ *
6
+ * This is the baseline `theme:read` capability — every app may read it. Changing
7
+ * the host theme is a separate, elevated action (`theme:set`), available only to
8
+ * the theme-toggle system app.
9
+ */
10
+ type HostTheme = 'light' | 'dark';
11
+ /**
12
+ * Returns the current host theme. Poll this for a one-off read; use
13
+ * {@link onHostThemeChange} or {@link useHostTheme} to react to changes.
14
+ */
15
+ declare const getHostTheme: () => HostTheme;
16
+ /**
17
+ * Subscribe to host theme changes. The listener is invoked immediately with the
18
+ * current theme, then again on every change. Returns an unsubscribe fn.
19
+ */
20
+ declare const onHostThemeChange: (listener: (theme: HostTheme) => void) => (() => void);
21
+ /**
22
+ * React hook returning the current host theme, re-rendering when it changes.
23
+ * The recommended way to implement an app's own `useTheme`: follow the host,
24
+ * allow a local override.
25
+ */
26
+ declare const useHostTheme: () => HostTheme;
27
+ /**
28
+ * Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host
29
+ * applies it and re-pushes the new value to every `theme:read` iframe, so your
30
+ * own {@link useHostTheme} confirms the change (the loop closes with no special
31
+ * case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may
32
+ * call this; any other app is rejected host-side with a `forbidden`
33
+ * {@link Error} (carrying `.code`), regardless of what the app claims. Update
34
+ * optimistically and let the re-push confirm.
35
+ */
36
+ declare const setHostTheme: (theme: HostTheme) => Promise<void>;
37
+
38
+ export { type HostTheme, getHostTheme, onHostThemeChange, setHostTheme, useHostTheme };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The host UI theme, mirrored from the immediately.run host window into the
3
+ * sandbox. Your app can read this to render in step with the host chrome
4
+ * (light / dark).
5
+ *
6
+ * This is the baseline `theme:read` capability — every app may read it. Changing
7
+ * the host theme is a separate, elevated action (`theme:set`), available only to
8
+ * the theme-toggle system app.
9
+ */
10
+ type HostTheme = 'light' | 'dark';
11
+ /**
12
+ * Returns the current host theme. Poll this for a one-off read; use
13
+ * {@link onHostThemeChange} or {@link useHostTheme} to react to changes.
14
+ */
15
+ declare const getHostTheme: () => HostTheme;
16
+ /**
17
+ * Subscribe to host theme changes. The listener is invoked immediately with the
18
+ * current theme, then again on every change. Returns an unsubscribe fn.
19
+ */
20
+ declare const onHostThemeChange: (listener: (theme: HostTheme) => void) => (() => void);
21
+ /**
22
+ * React hook returning the current host theme, re-rendering when it changes.
23
+ * The recommended way to implement an app's own `useTheme`: follow the host,
24
+ * allow a local override.
25
+ */
26
+ declare const useHostTheme: () => HostTheme;
27
+ /**
28
+ * Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host
29
+ * applies it and re-pushes the new value to every `theme:read` iframe, so your
30
+ * own {@link useHostTheme} confirms the change (the loop closes with no special
31
+ * case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may
32
+ * call this; any other app is rejected host-side with a `forbidden`
33
+ * {@link Error} (carrying `.code`), regardless of what the app claims. Update
34
+ * optimistically and let the re-push confirm.
35
+ */
36
+ declare const setHostTheme: (theme: HostTheme) => Promise<void>;
37
+
38
+ export { type HostTheme, getHostTheme, onHostThemeChange, setHostTheme, useHostTheme };
package/dist/theme.js ADDED
@@ -0,0 +1,30 @@
1
+ import { useEffect, useState } from "react";
2
+ import { protocolRequest } from "./sandboxUtils";
3
+ const themeService = () => {
4
+ return module.evaluation.module.bundler.theme;
5
+ };
6
+ const getHostTheme = () => themeService().getTheme();
7
+ const onHostThemeChange = (listener) => {
8
+ const disposable = themeService().onChange(listener);
9
+ return () => disposable.dispose();
10
+ };
11
+ const useHostTheme = () => {
12
+ const [theme, setTheme] = useState(getHostTheme);
13
+ useEffect(() => onHostThemeChange(setTheme), []);
14
+ return theme;
15
+ };
16
+ const setHostTheme = async (theme) => {
17
+ const res = await protocolRequest("theme", "set", [{ theme }]);
18
+ if (!res || res.ok !== true) {
19
+ const err = new Error(res?.message ?? "setHostTheme failed");
20
+ err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
21
+ throw err;
22
+ }
23
+ };
24
+ export {
25
+ getHostTheme,
26
+ onHostThemeChange,
27
+ setHostTheme,
28
+ useHostTheme
29
+ };
30
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/theme.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { protocolRequest } from './sandboxUtils';\n\n/**\n * The host UI theme, mirrored from the immediately.run host window into the\n * sandbox. Your app can read this to render in step with the host chrome\n * (light / dark).\n *\n * This is the baseline `theme:read` capability — every app may read it. Changing\n * the host theme is a separate, elevated action (`theme:set`), available only to\n * the theme-toggle system app.\n */\nexport type HostTheme = 'light' | 'dark';\n\ninterface ThemeService {\n getTheme(): HostTheme;\n onChange(listener: (theme: HostTheme) => void): { dispose(): void };\n}\n\n// `module.evaluation.module.bundler.theme` is the sandbox bundler injected into\n// the evaluation context (same path the other SDK helpers use for `auth`).\nconst themeService = (): ThemeService => {\n // @ts-ignore - injected by the sandbox runtime\n return module.evaluation.module.bundler.theme;\n};\n\n/**\n * Returns the current host theme. Poll this for a one-off read; use\n * {@link onHostThemeChange} or {@link useHostTheme} to react to changes.\n */\nexport const getHostTheme = (): HostTheme => themeService().getTheme();\n\n/**\n * Subscribe to host theme changes. The listener is invoked immediately with the\n * current theme, then again on every change. Returns an unsubscribe fn.\n */\nexport const onHostThemeChange = (\n listener: (theme: HostTheme) => void,\n): (() => void) => {\n const disposable = themeService().onChange(listener);\n return () => disposable.dispose();\n};\n\n/**\n * React hook returning the current host theme, re-rendering when it changes.\n * The recommended way to implement an app's own `useTheme`: follow the host,\n * allow a local override.\n */\nexport const useHostTheme = (): HostTheme => {\n const [theme, setTheme] = useState<HostTheme>(getHostTheme);\n useEffect(() => onHostThemeChange(setTheme), []);\n return theme;\n};\n\n/**\n * Set the host UI theme — the ELEVATED `theme:set` action (§8.5). The host\n * applies it and re-pushes the new value to every `theme:read` iframe, so your\n * own {@link useHostTheme} confirms the change (the loop closes with no special\n * case). Only a grant holding `theme:set` (e.g. the theme-toggle system app) may\n * call this; any other app is rejected host-side with a `forbidden`\n * {@link Error} (carrying `.code`), regardless of what the app claims. Update\n * optimistically and let the re-push confirm.\n */\nexport const setHostTheme = async (theme: HostTheme): Promise<void> => {\n const res = (await protocolRequest('theme', 'set', [{ theme }])) as\n | { ok: true; data?: unknown }\n | { ok: false; code?: string; message?: string }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? 'setHostTheme failed') as Error & {\n code?: string;\n };\n err.code = (res && 'code' in res ? res.code : undefined) ?? 'unknown';\n throw err;\n }\n};\n"],"mappings":"AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,uBAAuB;AAoBhC,MAAM,eAAe,MAAoB;AAEvC,SAAO,OAAO,WAAW,OAAO,QAAQ;AAC1C;AAMO,MAAM,eAAe,MAAiB,aAAa,EAAE,SAAS;AAM9D,MAAM,oBAAoB,CAC/B,aACiB;AACjB,QAAM,aAAa,aAAa,EAAE,SAAS,QAAQ;AACnD,SAAO,MAAM,WAAW,QAAQ;AAClC;AAOO,MAAM,eAAe,MAAiB;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAoB,YAAY;AAC1D,YAAU,MAAM,kBAAkB,QAAQ,GAAG,CAAC,CAAC;AAC/C,SAAO;AACT;AAWO,MAAM,eAAe,OAAO,UAAoC;AACrE,QAAM,MAAO,MAAM,gBAAgB,SAAS,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AAI9D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,qBAAqB;AAG3D,QAAI,QAAQ,OAAO,UAAU,MAAM,IAAI,OAAO,WAAc;AAC5D,UAAM;AAAA,EACR;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/sdk",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Runtime SDK for code executing inside an immediately.run sandbox.",
5
5
  "license": "MIT",
6
6
  "repository": "github:immediately-run/immediately-run-sdk",