@devvit/shared-types 0.11.20-next-2025-07-25-00-00-20-b42f98f6e.0 → 0.11.20-next-2025-07-28-12-50-32-fb5e880af.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.
@@ -0,0 +1,22 @@
1
+ import type { Effect as SharedEffects } from '@devvit/protos';
2
+ import { WebViewImmersiveModeEffect } from '@devvit/protos/types/devvit/ui/effects/web_view/v1alpha/immersive_mode.js';
3
+ import { WebViewInternalEventMessage } from '@devvit/protos/types/devvit/ui/events/v1alpha/web_view.js';
4
+ type Effect = Omit<SharedEffects, 'interval'> & {
5
+ immersiveMode?: WebViewImmersiveModeEffect | undefined;
6
+ };
7
+ /**
8
+ * Emits an effect to the parent window and handles the response if required.
9
+ *
10
+ * @param effect - The effect to be emitted to the parent window
11
+ * @returns A promise that resolves with the response message for effects that require
12
+ * a response, or resolves immediately with undefined for effects that don't
13
+ *
14
+ * @description
15
+ * This function handles two types of effects:
16
+ * 1. Effects that require a response: Creates a unique ID, sets up a message listener,
17
+ * and resolves the promise when a matching response is received
18
+ * 2. Effects that don't require a response: Posts the message and resolves immediately
19
+ */
20
+ export declare const emitEffect: (effect: Effect) => Promise<WebViewInternalEventMessage | undefined>;
21
+ export {};
22
+ //# sourceMappingURL=emit-effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-effect.d.ts","sourceRoot":"","sources":["../../src/client/emit-effect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAc,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2EAA2E,CAAC;AAKvH,OAAO,EAAE,2BAA2B,EAAE,MAAM,2DAA2D,CAAC;AAExG,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,GAAG;IAC9C,aAAa,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;CACxD,CAAC;AAIF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAkC1F,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { WebViewImmersiveModeEffect } from '@devvit/protos/types/devvit/ui/effects/web_view/v1alpha/immersive_mode.js';
2
+ import { WebViewInternalEventMessage } from '@devvit/protos/types/devvit/ui/events/v1alpha/web_view.js';
3
+ const EFFECTS_WITH_RESPONSE = [3];
4
+ /**
5
+ * Emits an effect to the parent window and handles the response if required.
6
+ *
7
+ * @param effect - The effect to be emitted to the parent window
8
+ * @returns A promise that resolves with the response message for effects that require
9
+ * a response, or resolves immediately with undefined for effects that don't
10
+ *
11
+ * @description
12
+ * This function handles two types of effects:
13
+ * 1. Effects that require a response: Creates a unique ID, sets up a message listener,
14
+ * and resolves the promise when a matching response is received
15
+ * 2. Effects that don't require a response: Posts the message and resolves immediately
16
+ */
17
+ export const emitEffect = (effect) => {
18
+ return new Promise((resolve) => {
19
+ const message = {
20
+ scope: 0,
21
+ type: 'devvit-internal',
22
+ };
23
+ if (effect.realtimeSubscriptions) {
24
+ message.realtimeEffect = effect.realtimeSubscriptions;
25
+ }
26
+ else {
27
+ message.effect = effect;
28
+ }
29
+ // Only set message id and add a listener for effects which require a response
30
+ if (EFFECTS_WITH_RESPONSE.includes(effect.type)) {
31
+ const id = self.crypto.randomUUID();
32
+ message.id = id;
33
+ const handleEffect = (event) => {
34
+ if (event.data?.type === 'devvit-message' && event.data?.data?.id === id) {
35
+ const serializedMessage = WebViewInternalEventMessage.fromJSON(event.data.data);
36
+ resolve(serializedMessage);
37
+ window.removeEventListener('message', handleEffect);
38
+ }
39
+ };
40
+ window.addEventListener('message', handleEffect);
41
+ // Post message to the parent window, handled by client web view component
42
+ window.parent.postMessage(message, '*');
43
+ }
44
+ else {
45
+ window.parent.postMessage(message, '*');
46
+ // Resolve immediately for effects that don't expect a response.
47
+ resolve(undefined);
48
+ }
49
+ });
50
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-effect.test.d.ts","sourceRoot":"","sources":["../../src/client/emit-effect.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/shared-types",
3
- "version": "0.11.20-next-2025-07-25-00-00-20-b42f98f6e.0",
3
+ "version": "0.11.20-next-2025-07-28-12-50-32-fb5e880af.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,13 +25,13 @@
25
25
  },
26
26
  "types": "./index.d.ts",
27
27
  "dependencies": {
28
- "@devvit/protos": "0.11.20-next-2025-07-25-00-00-20-b42f98f6e.0",
28
+ "@devvit/protos": "0.11.20-next-2025-07-28-12-50-32-fb5e880af.0",
29
29
  "jsonschema": "1.4.1",
30
30
  "uuid": "9.0.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@devvit/repo-tools": "0.11.20-next-2025-07-25-00-00-20-b42f98f6e.0",
34
- "@devvit/tsconfig": "0.11.20-next-2025-07-25-00-00-20-b42f98f6e.0",
33
+ "@devvit/repo-tools": "0.11.20-next-2025-07-28-12-50-32-fb5e880af.0",
34
+ "@devvit/tsconfig": "0.11.20-next-2025-07-28-12-50-32-fb5e880af.0",
35
35
  "@types/redis-mock": "0.17.1",
36
36
  "@types/uuid": "9.0.0",
37
37
  "chokidar-cli": "3.0.0",
@@ -46,5 +46,5 @@
46
46
  "directory": "dist"
47
47
  },
48
48
  "source": "./src/index.ts",
49
- "gitHead": "8343dda7b00e1649f7864d562f442e26956f0c50"
49
+ "gitHead": "ea8c67f0f877eafc8b41e537fe6758d22d7db8b6"
50
50
  }
@@ -0,0 +1,7 @@
1
+ import type { Config } from '../Config.js';
2
+ /**
3
+ * Gets the Config object that the runtime drops on globalThis. For internal use only.
4
+ * @internal
5
+ */
6
+ export declare function getDevvitConfig(): Config;
7
+ //# sourceMappingURL=get-devvit-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-devvit-config.d.ts","sourceRoot":"","sources":["../../src/server/get-devvit-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Gets the Config object that the runtime drops on globalThis. For internal use only.
3
+ * @internal
4
+ */
5
+ export function getDevvitConfig() {
6
+ const config = globalThis?.devvit?.config;
7
+ if (!config) {
8
+ throw new Error('Devvit config is not available. Make sure to call getDevvitConfig() after the Devvit runtime has been initialized.');
9
+ }
10
+ return config;
11
+ }