@devvit/external-endpoints 0.12.23-next-2026-05-07-21-21-02-37fac60f0.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/LICENSE +26 -0
- package/README.md +28 -0
- package/package.json +47 -0
- package/server/index.d.ts +2 -0
- package/server/index.d.ts.map +1 -0
- package/server/index.js +1 -0
- package/server/index.test.d.ts.map +1 -0
- package/server/serverImportInClientCodePanic.d.ts +17 -0
- package/server/serverImportInClientCodePanic.d.ts.map +1 -0
- package/server/serverImportInClientCodePanic.js +17 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2023 Reddit Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions
|
|
5
|
+
are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
13
|
+
contributors may be used to endorse or promote products derived from
|
|
14
|
+
this software without specific prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
22
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
23
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
24
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
25
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
26
|
+
SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @devvit/external-endpoints
|
|
2
|
+
|
|
3
|
+
The external endpoints feature supports invoking a Devvit app's `/external/…` endpoints from outside HTTP requests.
|
|
4
|
+
|
|
5
|
+
## Short-term Callbacks
|
|
6
|
+
|
|
7
|
+
Callbacks are external requests that are initiated by a Devvit app over a short time period. Callback URLs can only be used once and expire quickly. Callbacks are invoked in the same `context` they were initiated in and may invoke plugins as the user account via run-as.
|
|
8
|
+
|
|
9
|
+
### Example
|
|
10
|
+
|
|
11
|
+
1. A user clicks a button in your app's web view.
|
|
12
|
+
2. The button calls `fetch('/api/word-of-the-day/new', {method: 'POST'})`.
|
|
13
|
+
3. Your Devvit app server receives the fetch and invokes `external.getCallbackUrl('onWordNew')` to generate a callback URL. Eg, `https://wotdapp-2th52-external.devvit.net/external/on/word/new?externalToken=devvit_at_abc123`.
|
|
14
|
+
4. Your Devvit app server passes the callback URL in a request to an external server, `fetch('https://example.com/word-of-the-day/new', {method: 'POST', body})`.
|
|
15
|
+
5. Your Devvit app server doesn't wait for the callback. It responds to the `/api/word-of-the-day/new` request to let the user know their request has been received.
|
|
16
|
+
6. Your external server, `example.com`, has a short time period to unpack the callback URL from the request, do whatever work it needs to, and call the Devvit app back using the given callback URL like `fetch('https://wotdapp-2th52-external.devvit.net/external/on/word/new?externalToken=devvit_at_abc123', {method: 'POST'})`. Only `getCallbackUrl()` generated URLs are supported for external requests; the token must appear in the URL as a query param.
|
|
17
|
+
7. Your Devvit app server gets the callback request from `example.com` on its `/external/on/word/new` endpoint. Perhaps your app submits a post containing the word of the day.
|
|
18
|
+
|
|
19
|
+
## Long-term App Tokens Calls
|
|
20
|
+
|
|
21
|
+
App token calls are usually initiated by external servers. Unlike callbacks, they have long token lifetimes which may be reused and are managed by the app developer. Long-term invocations always execute with subreddit installation `context` as the app account.
|
|
22
|
+
|
|
23
|
+
### Example
|
|
24
|
+
|
|
25
|
+
1. Your external server calls `https://weatherapp-cs7yk0-external.devvit.net/external/weather/alert` with an `Authorization` header containing the app token. Eg, `bearer devvit_at_abc123`.
|
|
26
|
+
2. Your Devvit app server's receives the `/external/weather/alert` request.
|
|
27
|
+
|
|
28
|
+
Sign up for Reddit's Developer Platform [here!](https://developers.reddit.com)
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devvit/external-endpoints",
|
|
3
|
+
"version": "0.12.23-next-2026-05-07-21-21-02-37fac60f0.0",
|
|
4
|
+
"license": "BSD-3-Clause",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://developers.reddit.com/"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./server": {
|
|
12
|
+
"browser": "./server/serverImportInClientCodePanic.js",
|
|
13
|
+
"default": "./server/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"**"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"clean": "rm -rf .turbo coverage dist",
|
|
23
|
+
"clobber": "yarn clean && rm -rf node_modules",
|
|
24
|
+
"lint": "redlint .",
|
|
25
|
+
"lint:fix": "yarn lint --fix",
|
|
26
|
+
"prepublishOnly": "publish-package-json",
|
|
27
|
+
"test": "yarn test:unit && yarn test:types && yarn lint",
|
|
28
|
+
"test:types": "tsc --noEmit",
|
|
29
|
+
"test:unit": "vitest run",
|
|
30
|
+
"test:unit-with-coverage": "vitest run --coverage"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@devvit/protos": "0.12.23-next-2026-05-07-21-21-02-37fac60f0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@devvit/server": "*"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@devvit/repo-tools": "0.12.23-next-2026-05-07-21-21-02-37fac60f0.0",
|
|
40
|
+
"@devvit/server": "0.12.23-next-2026-05-07-21-21-02-37fac60f0.0",
|
|
41
|
+
"@devvit/tsconfig": "0.12.23-next-2026-05-07-21-21-02-37fac60f0.0",
|
|
42
|
+
"eslint": "9.11.1",
|
|
43
|
+
"typescript": "5.8.3",
|
|
44
|
+
"vitest": "4.0.15"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "758161fe5f8b765a03d15a7c9f8eb4bf13330f0d"
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":""}
|
package/server/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/server/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hey! If you're seeing this, you're probably trying to run server code in the
|
|
3
|
+
* client context, or you have your server build environment set up incorrectly.
|
|
4
|
+
* To fix this:
|
|
5
|
+
* 1) Check that you're not importing server code in your client files. If you
|
|
6
|
+
* are, you should import from `@devvit/web/client` instead of
|
|
7
|
+
* `@devvit/web/server`. `@devvit/external` is server only and has no client
|
|
8
|
+
* support.
|
|
9
|
+
* 2) If this is coming from server code, ensure that your client's tsconfig &
|
|
10
|
+
* build environment is set up correctly - specifically, make sure you do NOT
|
|
11
|
+
* have `compilerOptions.customConditions` set to include `["browser"]` in
|
|
12
|
+
* your `tsconfig.json` file. Also, verify that whatever bundler you're using
|
|
13
|
+
* (esbuild, vite, etc.) is bundling the client code for a Node environment,
|
|
14
|
+
* and not a web browser!
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=serverImportInClientCodePanic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverImportInClientCodePanic.d.ts","sourceRoot":"","sources":["../../src/server/serverImportInClientCodePanic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hey! If you're seeing this, you're probably trying to run server code in the
|
|
3
|
+
* client context, or you have your server build environment set up incorrectly.
|
|
4
|
+
* To fix this:
|
|
5
|
+
* 1) Check that you're not importing server code in your client files. If you
|
|
6
|
+
* are, you should import from `@devvit/web/client` instead of
|
|
7
|
+
* `@devvit/web/server`. `@devvit/external` is server only and has no client
|
|
8
|
+
* support.
|
|
9
|
+
* 2) If this is coming from server code, ensure that your client's tsconfig &
|
|
10
|
+
* build environment is set up correctly - specifically, make sure you do NOT
|
|
11
|
+
* have `compilerOptions.customConditions` set to include `["browser"]` in
|
|
12
|
+
* your `tsconfig.json` file. Also, verify that whatever bundler you're using
|
|
13
|
+
* (esbuild, vite, etc.) is bundling the client code for a Node environment,
|
|
14
|
+
* and not a web browser!
|
|
15
|
+
*/
|
|
16
|
+
console.error("Can't import server code in the client!");
|
|
17
|
+
export {};
|