@devvit/shared-types 0.12.6-next-2025-12-08-21-42-15-9f008f8f0.0 → 0.12.6-next-2025-12-09-15-11-17-96a26acd9.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/shared-types",
|
|
3
|
-
"version": "0.12.6-next-2025-12-
|
|
3
|
+
"version": "0.12.6-next-2025-12-09-15-11-17-96a26acd9.0",
|
|
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.6-next-2025-12-
|
|
36
|
+
"@devvit/protos": "0.12.6-next-2025-12-09-15-11-17-96a26acd9.0",
|
|
37
37
|
"jsonschema": "1.4.1",
|
|
38
38
|
"uuid": "9.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@devvit/repo-tools": "0.12.6-next-2025-12-
|
|
42
|
-
"@devvit/tsconfig": "0.12.6-next-2025-12-
|
|
41
|
+
"@devvit/repo-tools": "0.12.6-next-2025-12-09-15-11-17-96a26acd9.0",
|
|
42
|
+
"@devvit/tsconfig": "0.12.6-next-2025-12-09-15-11-17-96a26acd9.0",
|
|
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": "0648a19e71928872d54b79a960ba797ae646f7a7"
|
|
55
55
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.polyfill.d.ts","sourceRoot":"","sources":["../../src/polyfill/fetch.polyfill.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HTTPDefinition } from '@devvit/protos';
|
|
2
|
+
export const WEBBIT_LOCAL_HOST = 'webbit.local';
|
|
3
|
+
let httpPlugin;
|
|
4
|
+
const noDevvitFetch = globalThis.fetch;
|
|
5
|
+
const webbitHost = `${WEBBIT_LOCAL_HOST}:${process.env.WEBBIT_PORT || '3000'}`;
|
|
6
|
+
function getHttpPlugin() {
|
|
7
|
+
if (httpPlugin !== undefined) {
|
|
8
|
+
return httpPlugin;
|
|
9
|
+
}
|
|
10
|
+
const config = globalThis?.devvit?.config;
|
|
11
|
+
if (!config?.uses?.(HTTPDefinition)) {
|
|
12
|
+
throw new Error('Fetch is not enabled. You can enable it by passing `http: true` to `Devvit.configure`');
|
|
13
|
+
}
|
|
14
|
+
const handler = config?.use?.(HTTPDefinition) ?? null;
|
|
15
|
+
if (handler === null) {
|
|
16
|
+
throw new Error('fetch polyfill failed to initialize HTTPPlugin');
|
|
17
|
+
}
|
|
18
|
+
return handler;
|
|
19
|
+
}
|
|
20
|
+
globalThis.fetch = async function fetch(request, options) {
|
|
21
|
+
let requestObj = request;
|
|
22
|
+
if (typeof requestObj === 'string' || requestObj instanceof URL || requestObj !== undefined) {
|
|
23
|
+
requestObj = new Request(request, options);
|
|
24
|
+
}
|
|
25
|
+
if (new URL(requestObj.url).host === webbitHost) {
|
|
26
|
+
// In local development and integration tests, we can't map
|
|
27
|
+
// webbit.local to 127.0.0.1 via hosts, so we replace it here.
|
|
28
|
+
const newUrl = requestObj.url.replace(`http://${WEBBIT_LOCAL_HOST}:`, `http://127.0.0.1:`);
|
|
29
|
+
const newRequest = new Request(newUrl, requestObj);
|
|
30
|
+
return noDevvitFetch(newRequest, options);
|
|
31
|
+
}
|
|
32
|
+
const fetchPlugin = getHttpPlugin();
|
|
33
|
+
const headers = {};
|
|
34
|
+
requestObj.headers.forEach((v, k) => (headers[k] = v));
|
|
35
|
+
const pluginResponse = await fetchPlugin.Fetch({
|
|
36
|
+
url: requestObj.url,
|
|
37
|
+
data: {
|
|
38
|
+
method: requestObj.method,
|
|
39
|
+
headers,
|
|
40
|
+
body: new Uint8Array(await requestObj.arrayBuffer()),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
let body = pluginResponse.body;
|
|
44
|
+
if (pluginResponse.status === 204 || pluginResponse.status === 304) {
|
|
45
|
+
body = undefined;
|
|
46
|
+
}
|
|
47
|
+
const rsp = new Response(body, {
|
|
48
|
+
headers: pluginResponse.headers,
|
|
49
|
+
status: pluginResponse.status,
|
|
50
|
+
});
|
|
51
|
+
// Redefine the url prop with new value but same as it was.
|
|
52
|
+
Object.defineProperty(rsp, 'url', {
|
|
53
|
+
configurable: true,
|
|
54
|
+
enumerable: true,
|
|
55
|
+
value: pluginResponse.url,
|
|
56
|
+
});
|
|
57
|
+
return rsp;
|
|
58
|
+
};
|