@superforge/infra 0.5.0 → 1.0.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/README.md +15 -10
- package/output/choose.js +3 -0
- package/output/client.js +5 -1
- package/output/contract/index.d.ts +1 -1
- package/output/contract/index.js +3 -3
- package/output/contract/login.d.ts +44 -0
- package/output/contract/login.js +32 -8
- package/output/index.d.ts +1 -1
- package/output/index.js +1 -1
- package/output/infra.d.ts +9 -1
- package/output/stand-in.d.ts +4 -2
- package/output/stand-in.js +45 -5
- package/output/version.d.ts +2 -2
- package/output/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,7 @@ Every method answers a result; every refusal but `unavailable` and
|
|
|
86
86
|
| ------------------------------------------------------ | --------------------------------------------------------------------------------------- | ------------------------------------------------- |
|
|
87
87
|
| `project()` | the key's project, its mode and its domains | `unavailable` |
|
|
88
88
|
| `startLogin({ channel, address, ip, link_to? })` | the address, `with_link`, `expires_at`, and `test` (the code and link, with a test key) | `rate-limited`, `not-sent`, `unavailable` |
|
|
89
|
+
| `makeLoginLink({ channel, address, ip, link_to })` | the address, the `link` for the app's own message, and `expires_at` (24 hours on) | `rate-limited`, `unavailable` |
|
|
89
90
|
| `verifyLogin({ channel, address, code } \| { token })` | whose address it was | `wrong-code`, `no-code`, `no-link`, `unavailable` |
|
|
90
91
|
| `fileComment(comment)` | the comment's `id` and `created_at` | `invalid`, `too-large`, `unavailable` |
|
|
91
92
|
| `passOAuth(request, call, origin)` | the `Response` for one of Claude's OAuth calls | (a `Response`: OAuth's own errors) |
|
|
@@ -136,7 +137,9 @@ address unless set).
|
|
|
136
137
|
memory: login sends nothing and answers the code and the link, which
|
|
137
138
|
verify as Infra's do (once each, for 15 minutes, a code for five tries),
|
|
138
139
|
and links, as Infra's do, only to this computer and the project's
|
|
139
|
-
`domains`, over https; any other host gets `with_link: false`. A
|
|
140
|
+
`domains`, over https; any other host gets `with_link: false`. A link
|
|
141
|
+
made for the app's own message (`makeLoginLink`) verifies the same way,
|
|
142
|
+
for 24 hours, and one to any other host is refused `unavailable`. A comment
|
|
140
143
|
is checked as Infra checks it and kept nowhere; Claude logs in to nothing,
|
|
141
144
|
and `checkAgentToken` takes only the tokens `standInAgentToken()` mints:
|
|
142
145
|
`standInAgentToken({ user_id, resource, scopes?, origin?, expires_in? })`,
|
|
@@ -149,18 +152,19 @@ app's tests use it, so they never reach Infra.
|
|
|
149
152
|
a page can import it: the constants and types every call is made of, every
|
|
150
153
|
reason a call is refused, Infra's (`INFRA_ERRORS`) and the package's own
|
|
151
154
|
(`CLIENT_ERRORS`), and the zod schemas of what Infra is sent (`login_start`,
|
|
152
|
-
`login_verify`, `filed_comment`, `agent_allow`,
|
|
153
|
-
Infra checks with, with the
|
|
154
|
-
|
|
155
|
+
`login_link`, `login_verify`, `filed_comment`, `agent_allow`,
|
|
156
|
+
`connections_query`), which Infra checks with, with the three answers
|
|
157
|
+
Infra's own server ties itself to (`started_login`, `made_login_link`,
|
|
158
|
+
`verified_login`). The package itself exports the same
|
|
155
159
|
constants and types, and no schema.
|
|
156
160
|
|
|
157
161
|
A schema here is made with the package's own zod: parse with it as it is,
|
|
158
162
|
and never put it inside a schema of the app's own, which may be another
|
|
159
163
|
zod's and then fails. Build the app's own from the constants instead.
|
|
160
164
|
|
|
161
|
-
Every name either entry exports is a promise:
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
Every name either entry exports is a promise: taking one away is a major.
|
|
166
|
+
So they export only what an app or Infra's server uses; the rest is the
|
|
167
|
+
package's own.
|
|
164
168
|
|
|
165
169
|
## When something goes wrong
|
|
166
170
|
|
|
@@ -219,9 +223,10 @@ CI signs in to npm with trusted publishing: npm trusts this repository's
|
|
|
219
223
|
after `main`'s, with its line in `CHANGELOG.md`.
|
|
220
224
|
|
|
221
225
|
Infra changes its API additively: it adds fields and calls, and never
|
|
222
|
-
renames or drops one
|
|
223
|
-
|
|
224
|
-
|
|
226
|
+
renames or drops one a release calls. When an answer has to change, Infra
|
|
227
|
+
keeps answering each release from 1.0.0 on as that release expects ("What
|
|
228
|
+
every call tells Infra"), so a release keeps working, and an app takes the
|
|
229
|
+
next when it wants what's in it.
|
|
225
230
|
|
|
226
231
|
A release reads what Infra adds without breaking: a field it doesn't know
|
|
227
232
|
is dropped, a 429's `limit` is read as any name, and a request's or a
|
package/output/choose.js
CHANGED
package/output/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { checkToken, infraKeys, passOAuth } from "./agents.js";
|
|
2
|
-
import { AGENT_ID, APP_PATHS, agent_connections, agent_ended, agent_redirect, agent_refused, agent_request, CLIENT_HEADER, comment_refused, infra_failure, infra_project, kept_comment, start_refused, started_login, verified_login, verify_refused } from "./contract/all.js";
|
|
2
|
+
import { AGENT_ID, APP_PATHS, agent_connections, agent_ended, agent_redirect, agent_refused, agent_request, CLIENT_HEADER, comment_refused, infra_failure, infra_project, kept_comment, link_refused, made_login_link, start_refused, started_login, verified_login, verify_refused } from "./contract/all.js";
|
|
3
3
|
import { CALL_TIMEOUT } from "./primitives.js";
|
|
4
4
|
import { CLIENT } from "./version.js";
|
|
5
5
|
/** Infra's API, which a project's keys call */
|
|
@@ -107,6 +107,10 @@ export function infraClient({ key, url = INFRA_URL, send = fetch, paths = APP_PA
|
|
|
107
107
|
const call = "/login/start";
|
|
108
108
|
return answered(ask("POST", call, request), call, { schema: started_login }, start_refused);
|
|
109
109
|
},
|
|
110
|
+
makeLoginLink(request) {
|
|
111
|
+
const call = "/login/links";
|
|
112
|
+
return answered(ask("POST", call, request), call, { schema: made_login_link }, link_refused);
|
|
113
|
+
},
|
|
110
114
|
verifyLogin(proof) {
|
|
111
115
|
const call = "/login/verify";
|
|
112
116
|
return answered(ask("POST", call, proof), call, { schema: verified_login }, verify_refused);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AGENT_ID, AGENT_SCOPES, type AgentAllow, type AgentConnection, type AgentRefused, type AgentRequest, type AgentScope, APP_ORIGIN_HEADER, APP_PATHS, type AppPaths, agent_allow, connections_query, OAUTH_CALLS, type OAuthCall } from "./agents.js";
|
|
2
2
|
export { COMMENT_BODY_LIMIT, type CommentRefused, type FiledComment, filed_comment, type KeptComment, LONGEST_COMMENT } from "./comments.js";
|
|
3
3
|
export { CLIENT_ERRORS, type ClientErrorReason, INFRA_ERRORS, type InfraErrorReason, type InfraIssue } from "./errors.js";
|
|
4
|
-
export { LOGIN_CHANNELS, type LoginChannel, type LoginProof, type LoginStart, login_start, login_verify, type StartedLogin, type StartRefused, started_login, type VerifiedLogin, type VerifyRefused, verified_login } from "./login.js";
|
|
4
|
+
export { type LinkRefused, LOGIN_CHANNELS, type LoginChannel, type LoginLink, type LoginProof, type LoginStart, login_link, login_start, login_verify, type MadeLoginLink, made_login_link, type StartedLogin, type StartRefused, started_login, type VerifiedLogin, type VerifyRefused, verified_login } from "./login.js";
|
|
5
5
|
export { CLIENT_HEADER, type InfraProject, isLoopbackHost, KEY_BODY, KEY_MODES, KEY_PREFIXES, type KeyMode, LOOPBACK_HOSTNAMES, PROJECT_ID_PREFIX } from "./project.js";
|
package/output/contract/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Infra's contract, as `@superforge/infra/contract` exports it: the
|
|
2
2
|
// constants and types every call is made of, the schemas of what Infra is
|
|
3
|
-
// sent, which Infra checks with, and the
|
|
3
|
+
// sent, which Infra checks with, and the three answers Infra's own server
|
|
4
4
|
// ties itself to. Nothing here runs in Node alone, so a page can import it
|
|
5
5
|
// too. Infra's README has the calls.
|
|
6
6
|
//
|
|
7
|
-
// Every name here is a promise:
|
|
7
|
+
// Every name here is a promise: taking one away is a major.
|
|
8
8
|
// So a name is here only when an app or Infra's server needs it; the rest
|
|
9
9
|
// of contract/ is the package's own (all.ts). A schema here is made with
|
|
10
10
|
// the package's own zod: parse with it as it is, and never put it inside a
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
export { AGENT_ID, AGENT_SCOPES, APP_ORIGIN_HEADER, APP_PATHS, agent_allow, connections_query, OAUTH_CALLS } from "./agents.js";
|
|
13
13
|
export { COMMENT_BODY_LIMIT, filed_comment, LONGEST_COMMENT } from "./comments.js";
|
|
14
14
|
export { CLIENT_ERRORS, INFRA_ERRORS } from "./errors.js";
|
|
15
|
-
export { LOGIN_CHANNELS, login_start, login_verify, started_login, verified_login } from "./login.js";
|
|
15
|
+
export { LOGIN_CHANNELS, login_link, login_start, login_verify, made_login_link, started_login, verified_login } from "./login.js";
|
|
16
16
|
export { CLIENT_HEADER, isLoopbackHost, KEY_BODY, KEY_MODES, KEY_PREFIXES, LOOPBACK_HOSTNAMES, PROJECT_ID_PREFIX } from "./project.js";
|
|
@@ -81,6 +81,50 @@ export declare const start_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
|
81
81
|
};
|
|
82
82
|
}>>]>;
|
|
83
83
|
export type StartRefused = z.output<typeof start_refused>;
|
|
84
|
+
/**
|
|
85
|
+
* `POST /v1/login/links`: a login whose link the app sends in a message of
|
|
86
|
+
* its own, like a welcome email, where `login/start` has Infra send one.
|
|
87
|
+
* `link_to` must be on one of the project's domains, or this computer.
|
|
88
|
+
*/
|
|
89
|
+
export declare const login_link: z.ZodObject<{
|
|
90
|
+
channel: z.ZodLiteral<"email">;
|
|
91
|
+
address: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
92
|
+
ip: z.ZodUnion<readonly [z.ZodIPv4, z.ZodIPv6]>;
|
|
93
|
+
link_to: z.ZodURL;
|
|
94
|
+
}, z.core.$strip>;
|
|
95
|
+
export type LoginLink = z.input<typeof login_link>;
|
|
96
|
+
/** What `login/links` answers: the link, for the app's own message */
|
|
97
|
+
export declare const made_login_link: z.ZodObject<{
|
|
98
|
+
channel: z.ZodEnum<{
|
|
99
|
+
email: "email";
|
|
100
|
+
}>;
|
|
101
|
+
address: z.ZodString;
|
|
102
|
+
link: z.ZodString;
|
|
103
|
+
expires_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
export type MadeLoginLink = z.output<typeof made_login_link>;
|
|
106
|
+
/** Why `login/links` made nothing: over one of Infra's limits, as a start can be */
|
|
107
|
+
export declare const link_refused: z.ZodPipe<z.ZodObject<{
|
|
108
|
+
error: z.ZodObject<{
|
|
109
|
+
reason: z.ZodLiteral<"rate-limited">;
|
|
110
|
+
message: z.ZodString;
|
|
111
|
+
limit: z.ZodString;
|
|
112
|
+
retry_after: z.ZodNumber;
|
|
113
|
+
}, z.core.$strip>;
|
|
114
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
115
|
+
reason: "rate-limited";
|
|
116
|
+
message: string;
|
|
117
|
+
limit: string;
|
|
118
|
+
retry_after: number;
|
|
119
|
+
}, {
|
|
120
|
+
error: {
|
|
121
|
+
reason: "rate-limited";
|
|
122
|
+
message: string;
|
|
123
|
+
limit: string;
|
|
124
|
+
retry_after: number;
|
|
125
|
+
};
|
|
126
|
+
}>>;
|
|
127
|
+
export type LinkRefused = z.output<typeof link_refused>;
|
|
84
128
|
/**
|
|
85
129
|
* `POST /v1/login/verify`: the code, with the address it went to, or the
|
|
86
130
|
* link's token alone
|
package/output/contract/login.js
CHANGED
|
@@ -63,19 +63,43 @@ export const started_login = z.object({
|
|
|
63
63
|
// held, for a dev server to show on the page. Null with a secret key.
|
|
64
64
|
test: z.object({ code: z.string(), link: z.string().nullable() }).nullable()
|
|
65
65
|
});
|
|
66
|
+
// Over one of Infra's limits: today this address (one a minute, five an
|
|
67
|
+
// hour), the person's network, or the project's. Read as any name, since
|
|
68
|
+
// Infra may add a limit, and a release that can't read its name would
|
|
69
|
+
// answer "login isn't working" in place of "try again soon".
|
|
70
|
+
const rate_limited = refusal("rate-limited", {
|
|
71
|
+
limit: z.string(),
|
|
72
|
+
retry_after: z.number()
|
|
73
|
+
});
|
|
66
74
|
/** Why `login/start` sent nothing */
|
|
67
75
|
export const start_refused = z.union([
|
|
68
|
-
|
|
69
|
-
// an hour), the person's network, or the project's. Read as any name,
|
|
70
|
-
// since Infra may add a limit, and a release that can't read its name
|
|
71
|
-
// would answer "login isn't working" in place of "try again soon".
|
|
72
|
-
refusal("rate-limited", {
|
|
73
|
-
limit: z.string(),
|
|
74
|
-
retry_after: z.number()
|
|
75
|
-
}),
|
|
76
|
+
rate_limited,
|
|
76
77
|
// The message didn't go out, and nothing was counted
|
|
77
78
|
refusal("not-sent", {})
|
|
78
79
|
]);
|
|
80
|
+
/**
|
|
81
|
+
* `POST /v1/login/links`: a login whose link the app sends in a message of
|
|
82
|
+
* its own, like a welcome email, where `login/start` has Infra send one.
|
|
83
|
+
* `link_to` must be on one of the project's domains, or this computer.
|
|
84
|
+
*/
|
|
85
|
+
export const login_link = login_address.extend({
|
|
86
|
+
ip: visitor_ip,
|
|
87
|
+
link_to
|
|
88
|
+
});
|
|
89
|
+
/** What `login/links` answers: the link, for the app's own message */
|
|
90
|
+
export const made_login_link = z.object({
|
|
91
|
+
channel: login_channel,
|
|
92
|
+
// The address as Infra keeps it
|
|
93
|
+
address: z.string(),
|
|
94
|
+
// `link_to#<token>`, which logs in once, until `expires_at`. A newer
|
|
95
|
+
// login to the same address replaces it.
|
|
96
|
+
link: z.string(),
|
|
97
|
+
expires_at: z.iso
|
|
98
|
+
.datetime({ offset: true })
|
|
99
|
+
.transform((value) => new Date(value))
|
|
100
|
+
});
|
|
101
|
+
/** Why `login/links` made nothing: over one of Infra's limits, as a start can be */
|
|
102
|
+
export const link_refused = rate_limited;
|
|
79
103
|
/**
|
|
80
104
|
* `POST /v1/login/verify`: the code, with the address it went to, or the
|
|
81
105
|
* link's token alone
|
package/output/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { requestOrigin } from "./agents.js";
|
|
2
2
|
export { chooseInfra, type InfraChoice } from "./choose.js";
|
|
3
3
|
export { infraClient } from "./client.js";
|
|
4
|
-
export { AGENT_SCOPES, type AgentAllow, type AgentConnection, type AgentRefused, type AgentRequest, type AgentScope, APP_PATHS, type AppPaths, type ClientErrorReason, type CommentRefused, type FiledComment, type InfraErrorReason, type InfraIssue, type InfraProject, type KeptComment, type KeyMode, type LoginChannel, type LoginProof, type LoginStart, OAUTH_CALLS, type OAuthCall, type StartedLogin, type StartRefused, type VerifiedLogin, type VerifyRefused } from "./contract/index.js";
|
|
4
|
+
export { AGENT_SCOPES, type AgentAllow, type AgentConnection, type AgentRefused, type AgentRequest, type AgentScope, APP_PATHS, type AppPaths, type ClientErrorReason, type CommentRefused, type FiledComment, type InfraErrorReason, type InfraIssue, type InfraProject, type KeptComment, type KeyMode, type LinkRefused, type LoginChannel, type LoginLink, type LoginProof, type LoginStart, type MadeLoginLink, OAUTH_CALLS, type OAuthCall, type StartedLogin, type StartRefused, type VerifiedLogin, type VerifyRefused } from "./contract/index.js";
|
|
5
5
|
export type { AgentToken, AgentTokenRefused, Infra, InfraUnavailable } from "./infra.js";
|
|
6
6
|
export type { AsyncOperationResult, OperationResult } from "./results.js";
|
|
7
7
|
export { standInAgentToken, standInInfra } from "./stand-in.js";
|
package/output/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Skylevel apps run on, as an app's server calls it. README.md has how an
|
|
3
3
|
// app uses it.
|
|
4
4
|
//
|
|
5
|
-
// Every name here is a promise:
|
|
5
|
+
// Every name here is a promise: taking one away is a major.
|
|
6
6
|
// So the package exports what an app calls, its constants and its types,
|
|
7
7
|
// and no zod schema: those are at `@superforge/infra/contract` alone
|
|
8
8
|
// (contract/index.ts), made with the package's own zod.
|
package/output/infra.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentAllow, AgentConnection, AgentRefused, AgentRequest, CommentRefused, FiledComment, InfraProject, KeptComment, LoginProof, LoginStart, OAuthCall, StartedLogin, StartRefused, VerifiedLogin, VerifyRefused } from "./contract/all.js";
|
|
1
|
+
import type { AgentAllow, AgentConnection, AgentRefused, AgentRequest, CommentRefused, FiledComment, InfraProject, KeptComment, LinkRefused, LoginLink, LoginProof, LoginStart, MadeLoginLink, OAuthCall, StartedLogin, StartRefused, VerifiedLogin, VerifyRefused } from "./contract/all.js";
|
|
2
2
|
import type { AsyncOperationResult } from "./results.js";
|
|
3
3
|
/** What an app asks of Infra, whichever answers: the real one or the stand-in */
|
|
4
4
|
export type Infra = {
|
|
@@ -13,6 +13,14 @@ export type Infra = {
|
|
|
13
13
|
* `ip` is theirs, which Infra's limits count.
|
|
14
14
|
*/
|
|
15
15
|
startLogin(request: LoginStart): AsyncOperationResult<StartedLogin, StartRefused | InfraUnavailable>;
|
|
16
|
+
/**
|
|
17
|
+
* Makes a login whose link the app sends in a message of its own, like
|
|
18
|
+
* a welcome email, rather than Infra sending one: a link to `link_to`,
|
|
19
|
+
* which must be on one of the project's domains or localhost, that
|
|
20
|
+
* logs in once, for 24 hours. It's counted and limited as a login
|
|
21
|
+
* Infra sends is. `ip` is the person's, which Infra's limits count.
|
|
22
|
+
*/
|
|
23
|
+
makeLoginLink(request: LoginLink): AsyncOperationResult<MadeLoginLink, LinkRefused | InfraUnavailable>;
|
|
16
24
|
/**
|
|
17
25
|
* Whose address `proof` is: the code typed with the address it went to,
|
|
18
26
|
* or the link's token alone. Either works once, and spends the other.
|
package/output/stand-in.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export type WaitingLogin = {
|
|
|
13
13
|
* with no key and no network. Starting a login sends nothing and answers
|
|
14
14
|
* the code and the link, and verifying checks them as Infra does: each
|
|
15
15
|
* works once, for 15 minutes, a code for five tries, and using either
|
|
16
|
-
* spends both.
|
|
16
|
+
* spends both. A link made for the app to send itself works once, for 24
|
|
17
|
+
* hours. No limits apply, as none do to a test key. A request is
|
|
17
18
|
* checked with Infra's own contract, as Infra checks it, and a comment is
|
|
18
19
|
* answered an ID, though nothing keeps it. Its project has the `domains`
|
|
19
20
|
* it's given, an app's website's. An app's tests always use it, so they
|
|
@@ -22,7 +23,8 @@ export type WaitingLogin = {
|
|
|
22
23
|
* the page shows the code. Its refusals have Infra's reasons, though not
|
|
23
24
|
* always its words, which aren't contract. Like Infra, it links only to
|
|
24
25
|
* this computer and the project's `domains`, over https, and answers
|
|
25
|
-
* `with_link: false` for any other host
|
|
26
|
+
* `with_link: false` for any other host, or makes no link the app sends
|
|
27
|
+
* itself.
|
|
26
28
|
*/
|
|
27
29
|
export declare function standInInfra({ domains }?: {
|
|
28
30
|
domains?: string[];
|
package/output/stand-in.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { createLocalJWKSet, exportJWK, generateKeyPair, SignJWT } from "jose";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { checkToken, unavailableOAuth } from "./agents.js";
|
|
4
|
-
import { COMMENT_BODY_LIMIT, filed_comment, isLoopbackHost, login_start, login_verify } from "./contract/all.js";
|
|
4
|
+
import { COMMENT_BODY_LIMIT, filed_comment, isLoopbackHost, login_link, login_start, login_verify } from "./contract/all.js";
|
|
5
5
|
import { MINUTE, randomToken } from "./primitives.js";
|
|
6
6
|
// How Infra treats a code: it works for 15 minutes and five tries, and a
|
|
7
|
-
// new one for the same address replaces it, link and all
|
|
7
|
+
// new one for the same address replaces it, link and all. A link the app
|
|
8
|
+
// sends itself works for 24 hours, since its message may be read later.
|
|
8
9
|
const LIFETIME = 15 * MINUTE;
|
|
10
|
+
const LINK_LIFETIME = 24 * 60 * MINUTE;
|
|
9
11
|
const ATTEMPTS = 5;
|
|
10
12
|
/**
|
|
11
13
|
* Infra's test mode, in memory: what a test key gets from the real one,
|
|
12
14
|
* with no key and no network. Starting a login sends nothing and answers
|
|
13
15
|
* the code and the link, and verifying checks them as Infra does: each
|
|
14
16
|
* works once, for 15 minutes, a code for five tries, and using either
|
|
15
|
-
* spends both.
|
|
17
|
+
* spends both. A link made for the app to send itself works once, for 24
|
|
18
|
+
* hours. No limits apply, as none do to a test key. A request is
|
|
16
19
|
* checked with Infra's own contract, as Infra checks it, and a comment is
|
|
17
20
|
* answered an ID, though nothing keeps it. Its project has the `domains`
|
|
18
21
|
* it's given, an app's website's. An app's tests always use it, so they
|
|
@@ -21,7 +24,8 @@ const ATTEMPTS = 5;
|
|
|
21
24
|
* the page shows the code. Its refusals have Infra's reasons, though not
|
|
22
25
|
* always its words, which aren't contract. Like Infra, it links only to
|
|
23
26
|
* this computer and the project's `domains`, over https, and answers
|
|
24
|
-
* `with_link: false` for any other host
|
|
27
|
+
* `with_link: false` for any other host, or makes no link the app sends
|
|
28
|
+
* itself.
|
|
25
29
|
*/
|
|
26
30
|
export function standInInfra({ domains = [] } = {}) {
|
|
27
31
|
return standInWith({ domains });
|
|
@@ -76,6 +80,42 @@ export function standInWith({ waiting = new Map(), logs = false, domains = [] }
|
|
|
76
80
|
}
|
|
77
81
|
};
|
|
78
82
|
},
|
|
83
|
+
async makeLoginLink(request) {
|
|
84
|
+
const parsed = login_link.safeParse(request);
|
|
85
|
+
if (!parsed.success) {
|
|
86
|
+
return misfit(parsed.error);
|
|
87
|
+
}
|
|
88
|
+
const { channel, address, link_to } = parsed.data;
|
|
89
|
+
const page = linkPage(link_to, domains);
|
|
90
|
+
if (page === null) {
|
|
91
|
+
// Infra answers it 400 `invalid`, which the client reads
|
|
92
|
+
// as unavailable: the app named a page that isn't its own
|
|
93
|
+
return {
|
|
94
|
+
ok: false,
|
|
95
|
+
error: {
|
|
96
|
+
reason: "unavailable",
|
|
97
|
+
message: `link_to isn't on one of the project's domains (${domains.join(", ") || "none"}) or this computer, so Infra makes no link to it.`
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const made = {
|
|
102
|
+
address,
|
|
103
|
+
code: randomCode(),
|
|
104
|
+
token: randomToken(),
|
|
105
|
+
attempts: 0,
|
|
106
|
+
expires_at: Date.now() + LINK_LIFETIME
|
|
107
|
+
};
|
|
108
|
+
waiting.set(address, made);
|
|
109
|
+
return {
|
|
110
|
+
ok: true,
|
|
111
|
+
data: {
|
|
112
|
+
channel,
|
|
113
|
+
address,
|
|
114
|
+
link: `${page}#${made.token}`,
|
|
115
|
+
expires_at: new Date(made.expires_at)
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
},
|
|
79
119
|
async verifyLogin(given) {
|
|
80
120
|
const parsed = login_verify.safeParse(given);
|
|
81
121
|
if (!parsed.success) {
|
|
@@ -236,7 +276,7 @@ const NO_CODE = {
|
|
|
236
276
|
};
|
|
237
277
|
const NO_LINK = {
|
|
238
278
|
reason: "no-link",
|
|
239
|
-
message:
|
|
279
|
+
message: "That link has been used, ran out (after 15 minutes, or 24 hours for one the app sent itself), or isn't this project's. Start a new login."
|
|
240
280
|
};
|
|
241
281
|
const NO_REQUEST = {
|
|
242
282
|
reason: "not-found",
|
package/output/version.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** The package's version, as package.json says it */
|
|
2
|
-
export declare const PACKAGE_VERSION = "0.
|
|
2
|
+
export declare const PACKAGE_VERSION = "1.0.0";
|
|
3
3
|
/** What it says: the package and its version, `@superforge/infra/<version>` */
|
|
4
|
-
export declare const CLIENT = "@superforge/infra/0.
|
|
4
|
+
export declare const CLIENT = "@superforge/infra/1.0.0";
|
package/output/version.js
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
// package away from its package.json; a test checks the two agree, so a
|
|
6
6
|
// release that bumps one and not the other fails `pnpm check`.
|
|
7
7
|
/** The package's version, as package.json says it */
|
|
8
|
-
export const PACKAGE_VERSION = "0.
|
|
8
|
+
export const PACKAGE_VERSION = "1.0.0";
|
|
9
9
|
/** What it says: the package and its version, `@superforge/infra/<version>` */
|
|
10
10
|
export const CLIENT = `@superforge/infra/${PACKAGE_VERSION}`;
|
package/package.json
CHANGED