@devvit/web-view-scripts 0.11.15 → 0.11.16-next-2025-05-12-cce3059bc.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/init-context.d.ts +22 -0
- package/init-context.d.ts.map +1 -0
- package/init-context.js +24 -0
- package/package.json +6 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type T2ID, type T3ID, type T5ID } from '@devvit/shared-types/tid.js';
|
|
2
|
+
export type Context = {
|
|
3
|
+
subredditId: T5ID;
|
|
4
|
+
userId: T2ID;
|
|
5
|
+
subredditName: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
appVersion: string;
|
|
8
|
+
postId: T3ID;
|
|
9
|
+
};
|
|
10
|
+
declare global {
|
|
11
|
+
namespace globalThis {
|
|
12
|
+
var devvit: {
|
|
13
|
+
context: Context;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export declare const _initContext: ({ search }: Location) => void;
|
|
19
|
+
export declare const devvit: () => {
|
|
20
|
+
context: Context;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=init-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-context.d.ts","sourceRoot":"","sources":["../src/init-context.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,IAAI,EACV,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,OAAO,GAAG;IACpB,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,IAAI,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU,CAAC;QAEnB,IAAI,MAAM,EAAE;YACV,OAAO,EAAE,OAAO,CAAC;SAClB,CAAC;KACH;CACF;AAED,gBAAgB;AAChB,eAAO,MAAM,YAAY,GAAI,YAAY,QAAQ,KAAG,IAkBnD,CAAC;AAMF,eAAO,MAAM,MAAM,QAAO;IAAE,OAAO,EAAE,OAAO,CAAA;CAAuB,CAAC"}
|
package/init-context.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WebViewContext } from '@devvit/protos/types/devvit/ui/effects/web_view/v1alpha/context.js';
|
|
2
|
+
import { asT2ID, asT3ID, asT5ID, } from '@devvit/shared-types/tid.js';
|
|
3
|
+
/** @internal */
|
|
4
|
+
export const _initContext = ({ search }) => {
|
|
5
|
+
const contextParam = new URLSearchParams(search).get('context');
|
|
6
|
+
// TODO: throw an error here after clients have been updated to start sending the context param
|
|
7
|
+
if (contextParam) {
|
|
8
|
+
const jsonString = decodeURIComponent(contextParam);
|
|
9
|
+
const contextProto = WebViewContext.fromJSON(JSON.parse(jsonString));
|
|
10
|
+
const context = {
|
|
11
|
+
subredditId: asT5ID(contextProto.subredditId),
|
|
12
|
+
userId: asT2ID(contextProto.userId),
|
|
13
|
+
subredditName: contextProto.subredditName,
|
|
14
|
+
appName: contextProto.appName,
|
|
15
|
+
appVersion: contextProto.appVersion,
|
|
16
|
+
postId: asT3ID(contextProto.postId),
|
|
17
|
+
};
|
|
18
|
+
globalThis.devvit = { context };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
if (globalThis.location) {
|
|
22
|
+
_initContext(globalThis.location);
|
|
23
|
+
}
|
|
24
|
+
export const devvit = () => globalThis.devvit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/web-view-scripts",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.16-next-2025-05-12-cce3059bc.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
},
|
|
24
24
|
"types": "./index.d.ts",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@devvit/protos": "0.11.
|
|
27
|
-
"@devvit/repo-tools": "0.11.
|
|
28
|
-
"@devvit/
|
|
26
|
+
"@devvit/protos": "0.11.16-next-2025-05-12-cce3059bc.0",
|
|
27
|
+
"@devvit/repo-tools": "0.11.16-next-2025-05-12-cce3059bc.0",
|
|
28
|
+
"@devvit/shared-types": "0.11.16-next-2025-05-12-cce3059bc.0",
|
|
29
|
+
"@devvit/tsconfig": "0.11.16-next-2025-05-12-cce3059bc.0",
|
|
29
30
|
"eslint": "9.11.1",
|
|
30
31
|
"typescript": "5.8.3",
|
|
31
32
|
"vitest": "1.6.1"
|
|
@@ -34,5 +35,5 @@
|
|
|
34
35
|
"directory": "dist"
|
|
35
36
|
},
|
|
36
37
|
"source": "./src/index.ts",
|
|
37
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "37436d9f6c8044c83c45766923ed928e410f2cd0"
|
|
38
39
|
}
|