@devvit/shared-types 0.11.20-next-2025-07-25-17-24-54-9a691dab8.0 → 0.11.20-next-2025-07-28-13-12-45-ae6d04190.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.
- package/client/emit-effect.d.ts +22 -0
- package/client/emit-effect.d.ts.map +1 -0
- package/client/emit-effect.js +50 -0
- package/client/emit-effect.test.d.ts.map +1 -0
- package/constants.d.ts +2 -0
- package/constants.d.ts.map +1 -1
- package/constants.js +2 -0
- package/package.json +5 -5
- package/server/get-devvit-config.d.ts +7 -0
- package/server/get-devvit-config.d.ts.map +1 -0
- package/server/get-devvit-config.js +11 -0
|
@@ -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/constants.d.ts
CHANGED
|
@@ -24,4 +24,6 @@ export declare const REDDIT_OAUTH_COPY_PASTE_CLIENT_ID = "TWTsqXa53CexlrYGBWaesQ
|
|
|
24
24
|
export declare const apiPathPrefix = "/api/";
|
|
25
25
|
/** All unexposed APIs must start with this prefix. */
|
|
26
26
|
export declare const internalPathPrefix = "/internal/";
|
|
27
|
+
/** When an app's icon is present in the media assets list, it'll be with this special name. */
|
|
28
|
+
export declare const ICON_FILE_PATH = "$devvit_icon.png";
|
|
27
29
|
//# sourceMappingURL=constants.d.ts.map
|
package/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C,sBAAsB;AACtB,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C;;;;;MAKM;AACN,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,iCAAiC,2BAA2B,CAAC;AAE1E,wDAAwD;AACxD,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C,sBAAsB;AACtB,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C;;;;;MAKM;AACN,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,iCAAiC,2BAA2B,CAAC;AAE1E,wDAAwD;AACxD,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAE/C,+FAA+F;AAC/F,eAAO,MAAM,cAAc,qBAAqB,CAAC"}
|
package/constants.js
CHANGED
|
@@ -27,3 +27,5 @@ export const REDDIT_OAUTH_COPY_PASTE_CLIENT_ID = 'TWTsqXa53CexlrYGBWaesQ';
|
|
|
27
27
|
export const apiPathPrefix = '/api/';
|
|
28
28
|
/** All unexposed APIs must start with this prefix. */
|
|
29
29
|
export const internalPathPrefix = '/internal/';
|
|
30
|
+
/** When an app's icon is present in the media assets list, it'll be with this special name. */
|
|
31
|
+
export const ICON_FILE_PATH = '$devvit_icon.png'; // Uses special characters intentionally to avoid conflicts with real asset paths
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/shared-types",
|
|
3
|
-
"version": "0.11.20-next-2025-07-
|
|
3
|
+
"version": "0.11.20-next-2025-07-28-13-12-45-ae6d04190.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-
|
|
28
|
+
"@devvit/protos": "0.11.20-next-2025-07-28-13-12-45-ae6d04190.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-
|
|
34
|
-
"@devvit/tsconfig": "0.11.20-next-2025-07-
|
|
33
|
+
"@devvit/repo-tools": "0.11.20-next-2025-07-28-13-12-45-ae6d04190.0",
|
|
34
|
+
"@devvit/tsconfig": "0.11.20-next-2025-07-28-13-12-45-ae6d04190.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": "
|
|
49
|
+
"gitHead": "52100e7a870c1d6fd90ae04c842ae4b107e0b31d"
|
|
50
50
|
}
|
|
@@ -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
|
+
}
|