@plitzi/sdk-server 0.38.22 → 0.38.24
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/CHANGELOG.md +37 -0
- package/dist/functions-api.d.ts +6 -0
- package/dist/hosts/project/serveProject.d.ts +8 -0
- package/dist/hosts/project/serveProject.js +16 -12
- package/dist/modules/functions/capabilities.js +5 -0
- package/dist/modules/functions/contract.d.ts +6 -0
- package/dist/modules/functions/driver.js +4 -0
- package/dist/modules/functions/oauth.d.ts +2 -0
- package/dist/modules/functions/oauth.js +16 -3
- package/dist/modules/functions/protocol.d.ts +3 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @plitzi/sdk-server
|
|
2
2
|
|
|
3
|
+
## 0.38.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5858b9f: ## Server
|
|
8
|
+
|
|
9
|
+
- **`ctx.oauth.callbackUrl()`** (`@plitzi/sdk-server`) — PZ-161. The address providers send a visitor back to, as this
|
|
10
|
+
run's `connect` hands it to them: for a page that shows whoever sets up the app what to register, instead of
|
|
11
|
+
rebuilding the platform's rule. Refused in a run no visitor's request started when the deployment fixed no
|
|
12
|
+
`functions.oauth.callbackOrigin`.
|
|
13
|
+
- **In production the project's server fixes no OAuth callback** (`@plitzi/sdk-server`). 0.38.23's loopback default
|
|
14
|
+
applied wherever `PUBLIC_URL` was not HTTPS — a container behind a proxy sent providers to its own
|
|
15
|
+
`http://127.0.0.1:8080`. Now loopback is the default while developing only; in production the callback is on the
|
|
16
|
+
address each visitor's request came on (the site's domain, from `Host` and `X-Forwarded-Proto`), and the server says
|
|
17
|
+
to register that domain's `/fn/oauth/callback`.
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [5858b9f]
|
|
20
|
+
- @plitzi/plitzi-sdk@0.38.24
|
|
21
|
+
- @plitzi/sdk-shared@0.38.24
|
|
22
|
+
|
|
23
|
+
## 0.38.23
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 1e93ac7: ## Server
|
|
28
|
+
|
|
29
|
+
- **The project's server sends OAuth providers back to its loopback** (`@plitzi/sdk-server`) — PZ-160. 0.38.22 chose
|
|
30
|
+
`publicUrl`, which without `PUBLIC_URL` is the machine's address on the network: a private IP the router may change and
|
|
31
|
+
providers refuse, so a project opened to the network could no longer connect a new account. The callback origin is now
|
|
32
|
+
`127.0.0.1` unless `PUBLIC_URL` is HTTPS, and `serverOptions.functions.oauth.callbackOrigin` names another without
|
|
33
|
+
touching `PUBLIC_URL`. Open to the network with a loopback callback, the server says that a sign-in another device
|
|
34
|
+
starts needs a name of its own.
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [1e93ac7]
|
|
37
|
+
- @plitzi/plitzi-sdk@0.38.23
|
|
38
|
+
- @plitzi/sdk-shared@0.38.23
|
|
39
|
+
|
|
3
40
|
## 0.38.22
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/dist/functions-api.d.ts
CHANGED
|
@@ -294,6 +294,12 @@ export declare type FunctionOAuth = {
|
|
|
294
294
|
* to holds it until it lapses: answer it only to whom the connection is (its owner), from a route that checks so.
|
|
295
295
|
*/
|
|
296
296
|
token: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthToken>;
|
|
297
|
+
/**
|
|
298
|
+
* The address providers send a visitor back to (`…/fn/oauth/callback`) — the one this run's `connect` hands them, to
|
|
299
|
+
* show whoever registers the app with a provider. The space's host the request came on, or the one the deployment
|
|
300
|
+
* fixed (`functions.oauth.callbackOrigin`); refused in a run no visitor's request started, when none was fixed.
|
|
301
|
+
*/
|
|
302
|
+
callbackUrl: () => Promise<string>;
|
|
297
303
|
};
|
|
298
304
|
|
|
299
305
|
/** What a space's functions declare, read from the bundle when it is saved: its tasks, routes and reachable hosts. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AuthoredDocuments } from './watchSpace';
|
|
2
2
|
import { ServerConfig } from '../../core/createServer';
|
|
3
3
|
import { ConnectorManifest } from '../../modules/connectors';
|
|
4
|
+
import { FunctionsConfig } from '../../modules/functions/config';
|
|
4
5
|
import { ActionEntry, SSRServer } from '@plitzi/sdk-shared';
|
|
5
6
|
/** What `serveProject` sets itself, from the project's layout — so never the project's options'. */
|
|
6
7
|
type SetByProject = 'port' | 'health' | 'adapters' | 'plugins' | 'publicDir' | 'dataDir' | 'functions' | 'action';
|
|
@@ -14,6 +15,13 @@ type SetByProject = 'port' | 'health' | 'adapters' | 'plugins' | 'publicDir' | '
|
|
|
14
15
|
*/
|
|
15
16
|
export type ProjectServerOptions = Partial<Omit<ServerConfig, SetByProject>> & {
|
|
16
17
|
action?: Omit<NonNullable<ServerConfig['action']>, 'lookups'>;
|
|
18
|
+
/**
|
|
19
|
+
* Of the functions, what is the project's to say: `oauth.callbackOrigin`, the one address OAuth providers send a
|
|
20
|
+
* visitor back to — `PUBLIC_URL` when it is HTTPS; else, while developing, this machine's loopback, and in production
|
|
21
|
+
* the address each visitor's request came on. A name of its own for a sign-in another device starts while developing
|
|
22
|
+
* (`https://aiko.example.com:8080`, `process.env.OAUTH_CALLBACK_ORIGIN`).
|
|
23
|
+
*/
|
|
24
|
+
functions?: Pick<FunctionsConfig, 'oauth'>;
|
|
17
25
|
};
|
|
18
26
|
/** A space authored in the project — `authorProjectSpace` of `@plitzi/sdk-authoring/node` — and what it warned of. */
|
|
19
27
|
export type ProjectSpace = AuthoredDocuments & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { consoleLogger } from "../../helpers/serverLog.js";
|
|
2
2
|
import { isFleetWorker } from "../../core/server/fleet/role.js";
|
|
3
|
-
import {
|
|
3
|
+
import { oauthCallbackUrlOn } from "../../modules/functions/oauth.js";
|
|
4
4
|
import { loadFunctions } from "../../modules/functions/load.js";
|
|
5
5
|
import { createServer as createServer$1 } from "../../core/createServer.js";
|
|
6
6
|
import { closeOnSignals } from "../../core/server/closeOnSignals.js";
|
|
@@ -16,7 +16,6 @@ import { projectPlugins, watchProjectPlugins } from "./plugins.js";
|
|
|
16
16
|
import { createSpaceFailure } from "./spaceFailure.js";
|
|
17
17
|
import { watchSpace } from "./watchSpace.js";
|
|
18
18
|
import { fleetKv } from "../../core/server/fleet/stores.js";
|
|
19
|
-
import { FUNCTION_ROUTES_PREFIX } from "@plitzi/sdk-shared/actions";
|
|
20
19
|
import { X509Certificate } from "node:crypto";
|
|
21
20
|
import { hostname, networkInterfaces } from "node:os";
|
|
22
21
|
import { isIP } from "node:net";
|
|
@@ -73,14 +72,16 @@ var LOOPBACK = /* @__PURE__ */ new Set([
|
|
|
73
72
|
]);
|
|
74
73
|
var ANY_ADDRESS = /* @__PURE__ */ new Set(["0.0.0.0", "::"]);
|
|
75
74
|
/**
|
|
76
|
-
* Where OAuth providers send a visitor back (`ctx.oauth`)
|
|
77
|
-
*
|
|
78
|
-
*
|
|
75
|
+
* Where OAuth providers send a visitor back (`ctx.oauth`) when the project does not say: `PUBLIC_URL`, the address
|
|
76
|
+
* people reach it at, when it is HTTPS. Else, while developing — a server opened on `localhost`, its loopback and the
|
|
77
|
+
* network — this machine's loopback, the one address every provider takes: never its address on the network, which the
|
|
78
|
+
* router may change and providers refuse (a private IP, a `.local` name), nor `localhost`, refused too (RFC 8252). In
|
|
79
|
+
* production none is fixed: behind its proxy, the address each visitor's request came on — the site's own domain.
|
|
79
80
|
*/
|
|
80
|
-
var oauthCallbackOrigin = (publicUrl, localUrl) => {
|
|
81
|
-
const reached = new URL(publicUrl);
|
|
82
|
-
|
|
83
|
-
return
|
|
81
|
+
var oauthCallbackOrigin = (publicUrl, localUrl, developing) => {
|
|
82
|
+
const reached = publicUrl === void 0 ? void 0 : new URL(publicUrl);
|
|
83
|
+
if (reached?.protocol === "https:") return reached.origin;
|
|
84
|
+
return developing ? new URL(localUrl).origin : void 0;
|
|
84
85
|
};
|
|
85
86
|
/** An address as a URL writes it: an IPv6 one in brackets. */
|
|
86
87
|
var urlHost = (address) => address.includes(":") ? `[${address}]` : address;
|
|
@@ -217,7 +218,7 @@ var startProject = async (options) => {
|
|
|
217
218
|
}) : cloudAdapters(plugins.names);
|
|
218
219
|
const functionsDir = path.join(root, FUNCTIONS_DIR);
|
|
219
220
|
const functions = existsSync(functionsDir) ? await loadFunctions(functionsDir) : [];
|
|
220
|
-
const callbackOrigin = oauthCallbackOrigin(
|
|
221
|
+
const callbackOrigin = serverOptions.functions?.oauth?.callbackOrigin ?? oauthCallbackOrigin(process.env.PUBLIC_URL, localUrl, developing);
|
|
221
222
|
const runtimeBundle = path.join(root, RUNTIME_BUNDLE);
|
|
222
223
|
const spaceRuntime = await loadRuntimeModule(projectModule(root, RUNTIME_ENTRY, process.argv[1])) ?? (existsSync(runtimeBundle) ? await loadRuntime(readFileSync(runtimeBundle), path.join(root, PROJECT_TMP, "runtime")) : void 0);
|
|
223
224
|
const runtime = spaceRuntime && await serveRuntime(spaceRuntime, {
|
|
@@ -248,7 +249,7 @@ var startProject = async (options) => {
|
|
|
248
249
|
functions: {
|
|
249
250
|
native: [...functions, ...runtime?.native ?? []],
|
|
250
251
|
plugins: plugins.functions,
|
|
251
|
-
oauth: { callbackOrigin }
|
|
252
|
+
oauth: callbackOrigin === void 0 ? {} : { callbackOrigin }
|
|
252
253
|
},
|
|
253
254
|
action: {
|
|
254
255
|
signingSecret: process.env.PLITZI_SIGNING_SECRET,
|
|
@@ -273,7 +274,10 @@ var startProject = async (options) => {
|
|
|
273
274
|
console.log(`pages on ${localUrl}/`);
|
|
274
275
|
if (network.length > 0) console.log(`also on ${network.map((address) => `${address}/`).join(", ")} — anyone on this network can open it (HOST=${host})`);
|
|
275
276
|
else if (developing && LOOPBACK.has(host)) console.log("only this machine opens it: HOST=0.0.0.0 in .env opens it to your network (a phone on the Wi-Fi)");
|
|
276
|
-
if ([...functions, ...runtime?.native ?? []].some((definition) => Object.keys(definition.oauth ?? {}).length > 0))
|
|
277
|
+
if ([...functions, ...runtime?.native ?? []].some((definition) => Object.keys(definition.oauth ?? {}).length > 0)) {
|
|
278
|
+
console.log(callbackOrigin === void 0 ? `OAuth providers send visitors back to the address they asked from — register ${oauthCallbackUrlOn("https://<your domain>")} for each domain the site answers on (PUBLIC_URL fixes one)` : `OAuth providers send visitors back to ${oauthCallbackUrlOn(callbackOrigin)} — the address to register with each`);
|
|
279
|
+
if (callbackOrigin !== void 0 && network.length > 0 && callbackOrigin === new URL(localUrl).origin) console.log(" a sign-in started on another device (a tablet) comes back to its own loopback: for one, give this server a name providers accept — functions.oauth.callbackOrigin in src/config/serverOptions.ts, or PUBLIC_URL");
|
|
280
|
+
}
|
|
277
281
|
if (reached.unnamed.length > 0) console.warn(`[tls] the certificate does not name ${reached.unnamed.join(", ")}: a device that opens it there is refused — \`plitzi cert\` makes one for this machine as it is now`);
|
|
278
282
|
}
|
|
279
283
|
const watching = developing ? [...held ? [watchSpace(root, (authored) => {
|
|
@@ -181,6 +181,10 @@ var jobCallOf = (call) => {
|
|
|
181
181
|
};
|
|
182
182
|
/** A call to `ctx.oauth`, read into the one method it names: what each method takes, and an owner only as a string. */
|
|
183
183
|
var oauthCallOf = (call) => {
|
|
184
|
+
if (call.method === "callbackUrl") return {
|
|
185
|
+
op: "oauth",
|
|
186
|
+
method: "callbackUrl"
|
|
187
|
+
};
|
|
184
188
|
const connection = stringArg(call.connection, "An OAuth connection");
|
|
185
189
|
const owner = optionalString(call.owner, "An OAuth owner");
|
|
186
190
|
const own = owner === void 0 ? {} : { owner };
|
|
@@ -385,6 +389,7 @@ var answerCall = async (ctx, call) => {
|
|
|
385
389
|
case "status": return ctx.oauth.status(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
386
390
|
case "disconnect": return ctx.oauth.disconnect(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
387
391
|
case "token": return ctx.oauth.token(call.connection, call.owner === void 0 ? {} : { owner: call.owner });
|
|
392
|
+
case "callbackUrl": return ctx.oauth.callbackUrl();
|
|
388
393
|
case "fetch": return cuttable(ctx, call.request, async (cut) => wireResponseOf(await ctx.oauth.fetch(call.connection, call.url, {
|
|
389
394
|
...call.init,
|
|
390
395
|
...cut,
|
|
@@ -88,6 +88,12 @@ export type FunctionOAuth = {
|
|
|
88
88
|
* to holds it until it lapses: answer it only to whom the connection is (its owner), from a route that checks so.
|
|
89
89
|
*/
|
|
90
90
|
token: (connection: string, options?: FunctionOAuthOwner) => Promise<FunctionOAuthToken>;
|
|
91
|
+
/**
|
|
92
|
+
* The address providers send a visitor back to (`…/fn/oauth/callback`) — the one this run's `connect` hands them, to
|
|
93
|
+
* show whoever registers the app with a provider. The space's host the request came on, or the one the deployment
|
|
94
|
+
* fixed (`functions.oauth.callbackOrigin`); refused in a run no visitor's request started, when none was fixed.
|
|
95
|
+
*/
|
|
96
|
+
callbackUrl: () => Promise<string>;
|
|
91
97
|
};
|
|
92
98
|
/**
|
|
93
99
|
* The space's jobs, from its code: what starts one, reads it and stops it. Who may is the code's to decide — these are
|
|
@@ -225,6 +225,10 @@ var createFunctionsDriver = (environment) => {
|
|
|
225
225
|
connection,
|
|
226
226
|
owner: options.owner
|
|
227
227
|
}),
|
|
228
|
+
callbackUrl: () => call({
|
|
229
|
+
op: "oauth",
|
|
230
|
+
method: "callbackUrl"
|
|
231
|
+
}),
|
|
228
232
|
fetch: async (connection, url, init = {}) => {
|
|
229
233
|
const { owner, ...rest } = init;
|
|
230
234
|
const answer = await cuttable({
|
|
@@ -14,6 +14,8 @@ import { FunctionOAuthConnection } from '@plitzi/sdk-shared';
|
|
|
14
14
|
*/
|
|
15
15
|
/** Where the provider sends the visitor back, under `/fn` — the one address to register with every provider. */
|
|
16
16
|
export declare const OAUTH_CALLBACK_PATH = "/oauth/callback";
|
|
17
|
+
/** The whole address providers send a visitor back to, on an origin: what is registered with each. */
|
|
18
|
+
export declare const oauthCallbackUrlOn: (origin: string) => string;
|
|
17
19
|
/** What the parts of a run `ctx.oauth` uses are: its fetch, its kv, its credentials, its sealing, who and where. */
|
|
18
20
|
export type OAuthRun = Pick<ActionTaskContext, 'fetch' | 'kv' | 'credential' | 'seal' | 'open' | 'origin' | 'oauthCallbackOrigin' | 'user' | 'signal'>;
|
|
19
21
|
/**
|
|
@@ -18,6 +18,13 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
18
18
|
*/
|
|
19
19
|
/** Where the provider sends the visitor back, under `/fn` — the one address to register with every provider. */
|
|
20
20
|
var OAUTH_CALLBACK_PATH = "/oauth/callback";
|
|
21
|
+
/** The whole address providers send a visitor back to, on an origin: what is registered with each. */
|
|
22
|
+
var oauthCallbackUrlOn = (origin) => `${origin}${FUNCTION_ROUTES_PREFIX}${OAUTH_CALLBACK_PATH}`;
|
|
23
|
+
/** This run's: the deployment's fixed origin, or the one the visitor's request came on — none for a run nobody asked. */
|
|
24
|
+
var callbackUrlOf = (run) => {
|
|
25
|
+
const origin = run.oauthCallbackOrigin ?? run.origin;
|
|
26
|
+
return origin === void 0 ? void 0 : oauthCallbackUrlOn(origin);
|
|
27
|
+
};
|
|
21
28
|
var STATE_SECONDS = 600;
|
|
22
29
|
/** A token this close to lapsing is renewed before it is used. */
|
|
23
30
|
var RENEW_BEFORE_MS = 6e4;
|
|
@@ -211,7 +218,7 @@ var oauthFor = (run, connections, allowed) => {
|
|
|
211
218
|
const client = await clientOf(run, connection, spec);
|
|
212
219
|
const verifier = randomBytes(32).toString("base64url");
|
|
213
220
|
const state = randomBytes(24).toString("base64url");
|
|
214
|
-
const redirectUri =
|
|
221
|
+
const redirectUri = oauthCallbackUrlOn(run.oauthCallbackOrigin ?? run.origin);
|
|
215
222
|
const pending = {
|
|
216
223
|
connection,
|
|
217
224
|
spec,
|
|
@@ -281,6 +288,11 @@ var oauthFor = (run, connections, allowed) => {
|
|
|
281
288
|
await run.kv.delete(tokenKey(connection, owner));
|
|
282
289
|
return true;
|
|
283
290
|
},
|
|
291
|
+
callbackUrl: () => {
|
|
292
|
+
const url = callbackUrlOf(run);
|
|
293
|
+
if (url === void 0) return Promise.reject(/* @__PURE__ */ new Error("The OAuth callback is on the address a visitor asked from: this run has none, and the server fixed no functions.oauth.callbackOrigin"));
|
|
294
|
+
return Promise.resolve(url);
|
|
295
|
+
},
|
|
284
296
|
token: async (connection, options) => {
|
|
285
297
|
if (!specOf(connection).exposeToken) throw new Error(`OAuth connection "${connection}" keeps its token on the server: declare exposeToken: true on it for the code to read it, or reach its API with ctx.oauth.fetch`);
|
|
286
298
|
const tokens = await tokensOf(connection, ownerOf(run, connection, options));
|
|
@@ -302,7 +314,8 @@ var noOAuth = (why) => {
|
|
|
302
314
|
status: refused,
|
|
303
315
|
fetch: refused,
|
|
304
316
|
disconnect: refused,
|
|
305
|
-
token: refused
|
|
317
|
+
token: refused,
|
|
318
|
+
callbackUrl: refused
|
|
306
319
|
};
|
|
307
320
|
};
|
|
308
321
|
/**
|
|
@@ -344,4 +357,4 @@ var oauthCallback = async (run, query) => {
|
|
|
344
357
|
return back({ oauth_result: "connected" });
|
|
345
358
|
};
|
|
346
359
|
//#endregion
|
|
347
|
-
export { OAUTH_CALLBACK_PATH, noOAuth, oauthCallback, oauthFor };
|
|
360
|
+
export { OAUTH_CALLBACK_PATH, noOAuth, oauthCallback, oauthCallbackUrlOn, oauthFor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-server",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.24",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"./dist/env.js"
|
|
115
115
|
],
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@plitzi/plitzi-sdk": "0.38.
|
|
118
|
-
"@plitzi/sdk-shared": "0.38.
|
|
117
|
+
"@plitzi/plitzi-sdk": "0.38.24",
|
|
118
|
+
"@plitzi/sdk-shared": "0.38.24",
|
|
119
119
|
"ejs": "^7.0.2",
|
|
120
120
|
"esbuild": "^0.28.2",
|
|
121
121
|
"jsonwebtoken": "^9.0.3",
|