aurival 0.1.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 +202 -0
- package/README.md +195 -0
- package/dist/auth.d.ts +67 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +416 -0
- package/dist/auth.js.map +1 -0
- package/dist/bot.d.ts +76 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +278 -0
- package/dist/bot.js.map +1 -0
- package/dist/cli.d.ts +27 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +137 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +140 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +205 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +77 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +106 -0
- package/dist/events.js.map +1 -0
- package/dist/http.d.ts +48 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +201 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/socket.d.ts +61 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +447 -0
- package/dist/socket.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://bots.aurival.com/docs"><img src="https://raw.githubusercontent.com/Nullspire-LLC/aurival-sdk/main/assets/aurival-banner.png" alt="Aurival" width="100%"></a>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">Write a bot for Aurival. Declare commands, call <code>run()</code>, and the SDK holds the socket.</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://pypi.org/project/aurival/"><img src="https://img.shields.io/pypi/v/aurival.svg" alt="PyPI version"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/aurival"><img src="https://img.shields.io/npm/v/aurival.svg" alt="npm version"></a>
|
|
8
|
+
<a href="https://github.com/Nullspire-LLC/aurival-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Bot } from 'aurival';
|
|
13
|
+
|
|
14
|
+
const bot = new Bot();
|
|
15
|
+
|
|
16
|
+
bot.command('ping', 'Check that the bot is alive', async (ctx) => {
|
|
17
|
+
await ctx.reply('pong');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
bot.run();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Node 22+. ESM. TypeScript source, shipping plain JS plus `.d.ts`, so you get types whether
|
|
24
|
+
or not you use TypeScript.
|
|
25
|
+
|
|
26
|
+
Node 22.0–22.10 print `[UNDICI-WS] Warning: WebSockets are experimental` on every start —
|
|
27
|
+
that line is expected, comes from Node's own `WebSocket` implementation, and does not mean
|
|
28
|
+
anything is wrong. Node 22.11+ is silent. The floor stays 22.
|
|
29
|
+
|
|
30
|
+
This is the same package as [`aurival` on PyPI](../python), file for file and name for name.
|
|
31
|
+
Learn one and you have learned the other.
|
|
32
|
+
|
|
33
|
+
## Start from nothing
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
npm install aurival
|
|
37
|
+
npx aurival init
|
|
38
|
+
node bot.js
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`init` pairs this machine and writes a starter bot that already answers `/ping`. It writes
|
|
42
|
+
`bot.ts` when the folder already has TypeScript (a `tsconfig.json`), `bot.js` otherwise, so
|
|
43
|
+
the file it names is one you can run as it stands. It never overwrites an existing bot
|
|
44
|
+
file, and it refuses before it pairs rather than after.
|
|
45
|
+
|
|
46
|
+
`init` is a convenience, not a requirement: `bot.run()` still pairs on its first run.
|
|
47
|
+
|
|
48
|
+
## First run
|
|
49
|
+
|
|
50
|
+
There is nothing to configure. The first `run()` pairs this machine:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
aurival: pairing code K7QP-2M4X
|
|
54
|
+
aurival: fingerprint 018R-6WAC
|
|
55
|
+
Compare the fingerprint in the app, then approve. Waiting...
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Compare the fingerprint in the app before you approve — it is what makes a stolen code
|
|
59
|
+
useless. The key lands in `./.aurival/machine.json` (mode `0600`, in a `0700` directory,
|
|
60
|
+
with a `.gitignore` beside it so it can never be committed). Every later run just starts.
|
|
61
|
+
|
|
62
|
+
The key deploys with the project, like a `.env`. Each bot has its own. A leaked key is one
|
|
63
|
+
machine you revoke; a leaked token would be the bot.
|
|
64
|
+
|
|
65
|
+
## What a handler gets
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
bot.command('say', async (ctx) => {
|
|
69
|
+
ctx.command; // "say"
|
|
70
|
+
ctx.arguments; // the raw rest of the line, unparsed, possibly ""
|
|
71
|
+
ctx.chat; // { id, type, name }
|
|
72
|
+
ctx.sender; // { id, handle, name }
|
|
73
|
+
ctx.message; // the id of the message that invoked you, or null
|
|
74
|
+
await ctx.reply('…');
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`ctx.reply()` quotes the message that invoked the command, so an answer never floats free
|
|
79
|
+
in a busy chat. There is no flag: on the rare event that carries no message id it sends a
|
|
80
|
+
plain message instead.
|
|
81
|
+
|
|
82
|
+
Handlers run concurrently, and an event is acked only after its handler settles — so a
|
|
83
|
+
crash mid-handler redelivers rather than loses. **Do not block inside a handler.** A
|
|
84
|
+
synchronous call (a busy loop, `execSync`, a long CPU pass) starves the heartbeat on the
|
|
85
|
+
same event loop, and the server reaps a socket that has gone quiet for three intervals.
|
|
86
|
+
Use `await`, or hand the work to a worker thread.
|
|
87
|
+
|
|
88
|
+
An exception in a handler is logged with its stack, the bot stays up, and the event is
|
|
89
|
+
still acked:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
bot.onError((error, ctx) => {
|
|
93
|
+
// ctx is null for anything that did not come from a handler
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The hook also sees the two things that are not a handler's fault: a `problem` frame from
|
|
98
|
+
the server (your socket stays open), and a `backlog.overflowed` event telling you how many
|
|
99
|
+
events you missed while you were away and where delivery resumed. Neither reaches a
|
|
100
|
+
command handler.
|
|
101
|
+
|
|
102
|
+
## Shadowed commands
|
|
103
|
+
|
|
104
|
+
Every `run()` syncs your command list, and the server answers with the chats where another
|
|
105
|
+
bot already holds one of your names. Yours never fires there. The SDK prints one warning
|
|
106
|
+
line per shadowed chat:
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
aurival warn: /ping is shadowed by another bot in chat_01j…, so it will not reach you there
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Rename the command, or get the other bot out of that chat. Nothing else in the SDK reacts
|
|
113
|
+
to it — a shadowed command in one chat is still live in every other.
|
|
114
|
+
|
|
115
|
+
## Environment
|
|
116
|
+
|
|
117
|
+
| variable | what it does |
|
|
118
|
+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
+
| `AURIVAL_API` | point at another host. Must be `https://` unless it is loopback. The SDK prints the host it is using, so a redirect is visible. |
|
|
120
|
+
| `AURIVAL_KEY_PATH` | put `machine.json` somewhere else. No `.gitignore` is written beside an override — that is your directory, not ours. |
|
|
121
|
+
| `AURIVAL_DEBUG` | Node has no stdlib logger, so the default one mirrors an unconfigured Python `logging`: warnings and errors to stderr, debug and info only with this set. |
|
|
122
|
+
|
|
123
|
+
## Errors
|
|
124
|
+
|
|
125
|
+
One class per error type, one subclass per code the SDK acts on, and `code` and `doc_url`
|
|
126
|
+
on every instance:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { RateLimitError, KeyRevoked } from 'aurival';
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await ctx.reply('…');
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof RateLimitError) {
|
|
135
|
+
console.log(error.code, error.retry_after, error.doc_url);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`KeyRevoked`, `SessionSuperseded` and `BotSuspended` end the process on purpose — each one
|
|
141
|
+
means something a reconnect cannot fix. Everything else the SDK handles for you: token
|
|
142
|
+
expiry, deploys, network faults, redelivery.
|
|
143
|
+
|
|
144
|
+
`KeyRevoked` names the file to remove, since pairing again is the only way back:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
KeyRevoked: The key on this machine was revoked. Generate a new keypair and pair the
|
|
148
|
+
machine again — a revoked key cannot be re-paired. Remove .aurival/machine.json and run
|
|
149
|
+
the bot again to pair a new key.
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Dependencies
|
|
153
|
+
|
|
154
|
+
**None.** `fetch`, `WebSocket` and Ed25519 signing are all built into Node 22, which is why
|
|
155
|
+
the floor is 22 rather than 20 — Node 20 has no unflagged `WebSocket` client, and "Node 20"
|
|
156
|
+
and "zero runtime dependencies" could not both be true.
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
$ npm ls --omit=dev
|
|
160
|
+
aurival@0.1.0
|
|
161
|
+
└── (empty)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Development only, and each earns its place:
|
|
165
|
+
|
|
166
|
+
| package | version | why |
|
|
167
|
+
| ---------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
168
|
+
| [`typescript`](https://www.npmjs.com/package/typescript) | `7.0.2` | The source is TypeScript; this compiles it to the plain JS and `.d.ts` the package ships. |
|
|
169
|
+
| [`vitest`](https://www.npmjs.com/package/vitest) | `5.0.0` | The test runner. Runs TypeScript directly, so the suite tests the source rather than a build artefact. |
|
|
170
|
+
| [`@types/node`](https://www.npmjs.com/package/@types/node) | `22.20.1` | Types for the built-ins the package leans on. Pinned to the **22** line on purpose: a later major would type APIs Node 22 does not have, and the floor is 22. |
|
|
171
|
+
| [`prettier`](https://www.npmjs.com/package/prettier) | `3.9.6` | Formatting, so a diff is about the change. |
|
|
172
|
+
|
|
173
|
+
Every version was resolved from npm at build time (2026-09-05) with `npm view <pkg> version`
|
|
174
|
+
and pinned exactly. None came from memory.
|
|
175
|
+
|
|
176
|
+
`vitest` itself wants Node `>=22.12`; the package's own floor stays Node 22.0 (SDK-20). Run
|
|
177
|
+
the suite on a 22.12+ (or newer) Node. `package.json`'s `devEngines` warns rather than
|
|
178
|
+
fails on an older Node, since the runtime floor and the dev-toolchain floor are not the
|
|
179
|
+
same number.
|
|
180
|
+
|
|
181
|
+
## Tests
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
npm test
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The end-to-end test runs a real bot against the real Go service through
|
|
188
|
+
`backend-go/cmd/bot-api-testbed`, which needs a throwaway Postgres:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
MIGRATE_TEST_DATABASE_URL='postgres://postgres@127.0.0.1:5432/postgres?sslmode=disable' npm test
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Without that variable the end-to-end test announces that it skipped.** It never passes
|
|
195
|
+
quietly — a suite reporting green when it never reached the service is worse than no suite.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key file, first-run pairing, assertion signing, access-token exchange.
|
|
3
|
+
*
|
|
4
|
+
* SDK-33: the seed lives in exactly one object (`MachineKey`) and never leaves
|
|
5
|
+
* it — not a property anywhere else, not a local in dispatch, not in a log line
|
|
6
|
+
* or thrown message. Node's `KeyObject` keeps the bytes out of reach; the only
|
|
7
|
+
* path the b64 seed travels is `KeyFile.load` -> `MachineKey.fromSeedB64`
|
|
8
|
+
* (decoded immediately) and `MachineKey.seedB64ForSave` -> `KeyFile.save`
|
|
9
|
+
* (encoded only at the moment of writing).
|
|
10
|
+
*/
|
|
11
|
+
import { inspect } from 'node:util';
|
|
12
|
+
import type { HttpClient, Logger } from './http.js';
|
|
13
|
+
export { DEFAULT_HOST } from './http.js';
|
|
14
|
+
/** The ONLY object that holds the seed (SDK-33). */
|
|
15
|
+
export declare class MachineKey {
|
|
16
|
+
#private;
|
|
17
|
+
private constructor();
|
|
18
|
+
static generate(): MachineKey;
|
|
19
|
+
static fromSeedB64(seedB64: string): MachineKey;
|
|
20
|
+
sign(payload: Uint8Array): Uint8Array;
|
|
21
|
+
get publicKeyB64(): string;
|
|
22
|
+
get fingerprint(): string;
|
|
23
|
+
/** The seed's one legitimate exit. Called ONLY by `KeyFile.save`. */
|
|
24
|
+
seedB64ForSave(): string;
|
|
25
|
+
toString(): string;
|
|
26
|
+
[inspect.custom](): string;
|
|
27
|
+
}
|
|
28
|
+
/** machine.json minus the seed. Safe to log. */
|
|
29
|
+
export interface Machine {
|
|
30
|
+
bot: string;
|
|
31
|
+
machine: string;
|
|
32
|
+
host: string;
|
|
33
|
+
created: string;
|
|
34
|
+
}
|
|
35
|
+
export declare class KeyFile {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly isDefault: boolean;
|
|
38
|
+
constructor(filePath?: string | null);
|
|
39
|
+
static defaultPath(): string;
|
|
40
|
+
load(): Promise<{
|
|
41
|
+
key: MachineKey;
|
|
42
|
+
machine: Machine;
|
|
43
|
+
} | null>;
|
|
44
|
+
save(key: MachineKey, machine: Machine): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare class Auth {
|
|
47
|
+
#private;
|
|
48
|
+
readonly bot: string;
|
|
49
|
+
constructor(http: HttpClient, key: MachineKey, machine: Machine, logger?: Logger, keyPath?: string | null);
|
|
50
|
+
token(): Promise<string>;
|
|
51
|
+
refresh(): Promise<string>;
|
|
52
|
+
buildAssertion(now?: number): string;
|
|
53
|
+
}
|
|
54
|
+
export declare function machineLabel(): string;
|
|
55
|
+
export declare function resolveHost(): string;
|
|
56
|
+
export interface PairOptions {
|
|
57
|
+
machineLabel?: string | undefined;
|
|
58
|
+
host: string;
|
|
59
|
+
out?: ((line: string) => void) | undefined;
|
|
60
|
+
logger?: Logger | undefined;
|
|
61
|
+
signal?: AbortSignal | undefined;
|
|
62
|
+
}
|
|
63
|
+
export declare function pair(http: HttpClient, options: PairOptions): Promise<{
|
|
64
|
+
key: MachineKey;
|
|
65
|
+
machine: Machine;
|
|
66
|
+
}>;
|
|
67
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAoEzC,oDAAoD;AACpD,qBAAa,UAAU;;IAGrB,OAAO,eAEN;IAED,MAAM,CAAC,QAAQ,IAAI,UAAU,CAG5B;IAED,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAQ9C;IAED,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAEpC;IAED,IAAI,YAAY,IAAI,MAAM,CAGzB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,qEAAqE;IACrE,cAAc,IAAI,MAAM,CAGvB;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAEzB;CACF;AAED,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAUD,qBAAa,OAAO;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B,YAAY,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,EAcnC;IAED,MAAM,CAAC,WAAW,IAAI,MAAM,CAE3B;IAEK,IAAI,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,UAAU,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC,CAiBlE;IAEK,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0B3D;CACF;AAMD,qBAAa,IAAI;;IACf,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAcrB,YACE,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EAQxB;IAUK,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAK7B;IAEK,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAU/B;IAwCD,cAAc,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAcnC;CACF;AAID,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAYD,wBAAgB,WAAW,IAAI,MAAM,CAuBpC;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AA4DD,wBAAsB,IAAI,CACxB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC;IAAE,GAAG,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAqDhD"}
|