@devvit/shared-types 0.12.3-next-2025-11-13-21-16-59-229dd7e60.0 → 0.12.3
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 +4 -6
- package/client/emit-effect.d.ts.map +1 -1
- package/client/emit-effect.js +14 -37
- package/package.json +5 -5
package/client/emit-effect.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
import type { WebViewShareEffect } from '@devvit/protos/json/devvit/ui/effects/web_view/v1alpha/share.js';
|
|
1
|
+
import { EffectType } from '@devvit/protos/json/devvit/ui/effects/v1alpha/effect.js';
|
|
2
|
+
import { type WebViewInternalMessage } from '@devvit/protos/json/devvit/ui/effects/web_view/v1alpha/post_message.js';
|
|
4
3
|
import { WebViewInternalEventMessage } from '@devvit/protos/types/devvit/ui/events/v1alpha/web_view.js';
|
|
5
|
-
export type Effect = Omit<
|
|
6
|
-
|
|
7
|
-
share?: WebViewShareEffect;
|
|
4
|
+
export type Effect = Omit<WebViewInternalMessage, 'id' | 'scope' | 'type'> & {
|
|
5
|
+
type: EffectType;
|
|
8
6
|
};
|
|
9
7
|
/**
|
|
10
8
|
* Emits an effect to the parent window and handles the response if required.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-effect.d.ts","sourceRoot":"","sources":["../../src/client/emit-effect.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"emit-effect.d.ts","sourceRoot":"","sources":["../../src/client/emit-effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yDAAyD,CAAC;AACrF,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,wEAAwE,CAAC;AAChF,OAAO,EACL,2BAA2B,EAE5B,MAAM,2DAA2D,CAAC;AAEnE,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,EAAE,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAQlG;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,QAAQ,CAAC,MAAM,CAAC,KACvB,OAAO,CAAC,2BAA2B,GAAG,SAAS,CA2CjD,CAAC"}
|
package/client/emit-effect.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EffectType
|
|
1
|
+
import { EffectType } from '@devvit/protos/json/devvit/ui/effects/v1alpha/effect.js';
|
|
2
2
|
import { WebViewInternalMessageScope, } from '@devvit/protos/json/devvit/ui/effects/web_view/v1alpha/post_message.js';
|
|
3
3
|
import { WebViewInternalEventMessage, WebViewMessageEvent_MessageData, } from '@devvit/protos/types/devvit/ui/events/v1alpha/web_view.js'; // to-do: use /json/ not /types/.
|
|
4
|
-
const EFFECTS_WITH_RESPONSE =
|
|
5
|
-
EffectType.EFFECT_SHOW_FORM,
|
|
6
|
-
EffectType.EFFECT_CAN_RUN_AS_USER,
|
|
7
|
-
EffectType.EFFECT_CREATE_ORDER,
|
|
8
|
-
|
|
4
|
+
const EFFECTS_WITH_RESPONSE = {
|
|
5
|
+
[EffectType.EFFECT_SHOW_FORM]: true,
|
|
6
|
+
[EffectType.EFFECT_CAN_RUN_AS_USER]: true,
|
|
7
|
+
[EffectType.EFFECT_CREATE_ORDER]: true,
|
|
8
|
+
};
|
|
9
9
|
/**
|
|
10
10
|
* Emits an effect to the parent window and handles the response if required.
|
|
11
11
|
*
|
|
@@ -22,34 +22,11 @@ const EFFECTS_WITH_RESPONSE = [
|
|
|
22
22
|
export const emitEffect = (effect) => {
|
|
23
23
|
return new Promise((resolve) => {
|
|
24
24
|
const message = {
|
|
25
|
+
...effect,
|
|
26
|
+
realtimeEffect: effect.realtime, // to-do: remove deprecated field.
|
|
25
27
|
scope: WebViewInternalMessageScope.CLIENT,
|
|
26
28
|
type: 'devvit-internal',
|
|
27
29
|
};
|
|
28
|
-
if (effect.realtimeSubscriptions) {
|
|
29
|
-
message.realtimeEffect = effect.realtimeSubscriptions; // deprecated field, should eventually be removed
|
|
30
|
-
message.realtime = effect.realtimeSubscriptions;
|
|
31
|
-
}
|
|
32
|
-
else if (effect.immersiveMode) {
|
|
33
|
-
message.immersiveMode = effect.immersiveMode;
|
|
34
|
-
}
|
|
35
|
-
else if (effect.share) {
|
|
36
|
-
message.share = effect.share;
|
|
37
|
-
}
|
|
38
|
-
else if (effect.showToast) {
|
|
39
|
-
message.showToast = effect.showToast;
|
|
40
|
-
}
|
|
41
|
-
else if (effect.navigateToUrl) {
|
|
42
|
-
message.navigateToUrl = effect.navigateToUrl;
|
|
43
|
-
}
|
|
44
|
-
else if (effect.showForm) {
|
|
45
|
-
message.showForm = effect.showForm;
|
|
46
|
-
}
|
|
47
|
-
else if (effect.createOrder) {
|
|
48
|
-
message.createOrder = effect.createOrder;
|
|
49
|
-
}
|
|
50
|
-
else if (effect.canRunAsUser) {
|
|
51
|
-
message.canRunAsUser = effect.canRunAsUser;
|
|
52
|
-
}
|
|
53
30
|
// For temporary backward compatibility, we set both `message.effect_type` above, and `effect` below
|
|
54
31
|
// Once mobile clients are updated to consume the strongly typed properties above, we can remove this block
|
|
55
32
|
// *Do not* add new effects here, use the strongly typed properties above
|
|
@@ -60,22 +37,22 @@ export const emitEffect = (effect) => {
|
|
|
60
37
|
message.effect = effect;
|
|
61
38
|
}
|
|
62
39
|
// Only set message id and add a listener for effects which require a response
|
|
63
|
-
if (EFFECTS_WITH_RESPONSE
|
|
64
|
-
const id =
|
|
40
|
+
if (EFFECTS_WITH_RESPONSE[effect.type]) {
|
|
41
|
+
const id = crypto.randomUUID();
|
|
65
42
|
message.id = id;
|
|
66
43
|
const handleEffect = (event) => {
|
|
67
44
|
if (event.data?.type === 'devvit-message' && event.data?.data?.id === id) {
|
|
68
45
|
const serializedMessage = WebViewInternalEventMessage.fromJSON(event.data.data);
|
|
69
46
|
resolve(serializedMessage);
|
|
70
|
-
|
|
47
|
+
removeEventListener('message', handleEffect);
|
|
71
48
|
}
|
|
72
49
|
};
|
|
73
|
-
|
|
50
|
+
addEventListener('message', handleEffect);
|
|
74
51
|
// Post message to the parent window, handled by client web view component
|
|
75
|
-
|
|
52
|
+
parent.postMessage(message, '*');
|
|
76
53
|
}
|
|
77
54
|
else {
|
|
78
|
-
|
|
55
|
+
parent.postMessage(message, '*');
|
|
79
56
|
// Resolve immediately for effects that don't expect a response.
|
|
80
57
|
resolve(undefined);
|
|
81
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/shared-types",
|
|
3
|
-
"version": "0.12.3
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@devvit/protos": "0.12.3
|
|
36
|
+
"@devvit/protos": "0.12.3",
|
|
37
37
|
"jsonschema": "1.4.1",
|
|
38
38
|
"uuid": "9.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@devvit/repo-tools": "0.12.3
|
|
42
|
-
"@devvit/tsconfig": "0.12.3
|
|
41
|
+
"@devvit/repo-tools": "0.12.3",
|
|
42
|
+
"@devvit/tsconfig": "0.12.3",
|
|
43
43
|
"@types/redis-mock": "0.17.1",
|
|
44
44
|
"@types/uuid": "9.0.0",
|
|
45
45
|
"chokidar-cli": "3.0.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"vitest": "1.6.1"
|
|
52
52
|
},
|
|
53
53
|
"source": "./src/index.ts",
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "def4ddd93c8eed822d4843d5fb6012efa9453981"
|
|
55
55
|
}
|