@yaks/connections 0.0.0-stage → 0.2.36
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 +609 -2
- package/_dist/authorize.d.ts +38 -0
- package/_dist/authorize.d.ts.map +1 -0
- package/_dist/authorize_cli.d.ts +12 -0
- package/_dist/authorize_cli.d.ts.map +1 -0
- package/_dist/brokers.d.ts +66 -0
- package/_dist/brokers.d.ts.map +1 -0
- package/_dist/catalog.d.ts +33 -0
- package/_dist/catalog.d.ts.map +1 -0
- package/_dist/cli.d.ts +3 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/clients.d.ts +18 -0
- package/_dist/clients.d.ts.map +1 -0
- package/_dist/connections.d.ts +296 -0
- package/_dist/connections.d.ts.map +1 -0
- package/_dist/effects.d.ts +15 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/field.d.ts +17 -0
- package/_dist/field.d.ts.map +1 -0
- package/_dist/form.d.ts +49 -0
- package/_dist/form.d.ts.map +1 -0
- package/_dist/given.d.ts +10 -0
- package/_dist/given.d.ts.map +1 -0
- package/_dist/graph.d.ts +15 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/history.d.ts +4 -0
- package/_dist/history.d.ts.map +1 -0
- package/_dist/identity.d.ts +9 -0
- package/_dist/identity.d.ts.map +1 -0
- package/_dist/integrations.d.ts +196 -0
- package/_dist/integrations.d.ts.map +1 -0
- package/_dist/loopback.d.ts +7 -0
- package/_dist/loopback.d.ts.map +1 -0
- package/_dist/mcp-retirement.d.ts +33 -0
- package/_dist/mcp-retirement.d.ts.map +1 -0
- package/_dist/mcp.d.ts +179 -0
- package/_dist/mcp.d.ts.map +1 -0
- package/_dist/mod.d.ts +70 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/paste.d.ts +13 -0
- package/_dist/paste.d.ts.map +1 -0
- package/_dist/requests.d.ts +30 -0
- package/_dist/requests.d.ts.map +1 -0
- package/_dist/services.d.ts +25 -0
- package/_dist/services.d.ts.map +1 -0
- package/_dist/sign-in.d.ts +9 -0
- package/_dist/sign-in.d.ts.map +1 -0
- package/_dist/signin-mail.d.ts +12 -0
- package/_dist/signin-mail.d.ts.map +1 -0
- package/_dist/signin.d.ts +19 -0
- package/_dist/signin.d.ts.map +1 -0
- package/_dist/sources.d.ts +61 -0
- package/_dist/sources.d.ts.map +1 -0
- package/_dist/tools.d.ts +3 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/views.d.ts +3 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/yaks-app.d.ts +29 -0
- package/_dist/yaks-app.d.ts.map +1 -0
- package/anthropic.json +12 -0
- package/auth_command.js +69 -0
- package/auth_command.js.map +1 -0
- package/auth_command.ts +74 -0
- package/authorize.js +89 -0
- package/authorize.js.map +1 -0
- package/authorize.ts +138 -0
- package/authorize_cli.js +167 -0
- package/authorize_cli.js.map +1 -0
- package/authorize_cli.ts +211 -0
- package/brokers.js +318 -0
- package/brokers.js.map +1 -0
- package/brokers.ts +423 -0
- package/canva.json +32 -0
- package/catalog.js +178 -0
- package/catalog.js.map +1 -0
- package/catalog.ts +216 -0
- package/cli.js +30 -0
- package/cli.js.map +1 -0
- package/cli.ts +26 -0
- package/clients.js +34 -0
- package/clients.js.map +1 -0
- package/clients.ts +65 -0
- package/connections.js +1961 -0
- package/connections.js.map +1 -0
- package/connections.ts +2561 -0
- package/deno.json +1 -0
- package/discord-account.json +22 -0
- package/discord-bot.json +20 -0
- package/discord.json +26 -0
- package/effects.js +168 -0
- package/effects.js.map +1 -0
- package/effects.ts +160 -0
- package/elevenlabs.json +18 -0
- package/facebook.json +18 -0
- package/field.js +19 -0
- package/field.js.map +1 -0
- package/field.ts +31 -0
- package/form.js +112 -0
- package/form.js.map +1 -0
- package/form.ts +178 -0
- package/git-config.js +44 -0
- package/git-config.js.map +1 -0
- package/git-config.ts +26 -0
- package/given.js +83 -0
- package/given.js.map +1 -0
- package/given.ts +88 -0
- package/gmail-mailbox.json +29 -0
- package/gmail.json +31 -0
- package/google-calendar.json +31 -0
- package/google-drive.json +31 -0
- package/google-search-console.json +29 -0
- package/graph.js +36 -0
- package/graph.js.map +1 -0
- package/graph.ts +52 -0
- package/history.js +31 -0
- package/history.js.map +1 -0
- package/history.ts +32 -0
- package/identity.js +15 -0
- package/identity.js.map +1 -0
- package/identity.ts +18 -0
- package/integrations.js +493 -0
- package/integrations.js.map +1 -0
- package/integrations.ts +725 -0
- package/loopback.js +72 -0
- package/loopback.js.map +1 -0
- package/loopback.ts +89 -0
- package/lulu.json +32 -0
- package/mcp-retirement.js +133 -0
- package/mcp-retirement.js.map +1 -0
- package/mcp-retirement.ts +200 -0
- package/mcp-signin.js +14 -0
- package/mcp-signin.js.map +1 -0
- package/mcp-signin.ts +13 -0
- package/mcp.js +1036 -0
- package/mcp.js.map +1 -0
- package/mcp.ts +1283 -0
- package/mod.js +70 -0
- package/mod.js.map +1 -0
- package/mod.ts +216 -0
- package/openai-api.json +12 -0
- package/openai.json +25 -0
- package/openrouter.json +14 -0
- package/package.json +89 -4
- package/paste.js +36 -0
- package/paste.js.map +1 -0
- package/paste.ts +55 -0
- package/requests.js +137 -0
- package/requests.js.map +1 -0
- package/requests.ts +200 -0
- package/services.js +84 -0
- package/services.js.map +1 -0
- package/services.ts +111 -0
- package/sign-in.js +36 -0
- package/sign-in.js.map +1 -0
- package/sign-in.ts +53 -0
- package/signin-mail.js +29 -0
- package/signin-mail.js.map +1 -0
- package/signin-mail.ts +56 -0
- package/signin.js +68 -0
- package/signin.js.map +1 -0
- package/signin.ts +109 -0
- package/slack.json +90 -0
- package/sources.js +178 -0
- package/sources.js.map +1 -0
- package/sources.ts +237 -0
- package/tools.js +39 -0
- package/tools.js.map +1 -0
- package/tools.ts +46 -0
- package/views.js +85 -0
- package/views.js.map +1 -0
- package/views.ts +89 -0
- package/visitor-defaults.json +8 -0
- package/vocab.js +17 -0
- package/vocab.js.map +1 -0
- package/vocab.json +863 -0
- package/vocab.ts +18 -0
- package/voipms.json +32 -0
- package/yaks-app.js +159 -0
- package/yaks-app.js.map +1 -0
- package/yaks-app.ts +177 -0
- package/youtube.json +26 -0
package/catalog.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// The catalog: every service a person can be offered, whether or not anything
|
|
2
|
+
// is connected to it yet. It is the built integrations (./integrations.ts)
|
|
3
|
+
// and every service a broker lists (./brokers.ts `catalog`), as one list of
|
|
4
|
+
// offers, each the integration it would be once someone connects it.
|
|
5
|
+
//
|
|
6
|
+
// Direct comes first. A built integration stands in for the broker's listing
|
|
7
|
+
// of the same service: one by its name, and one whose broker is the listing
|
|
8
|
+
// (Gmail for Nango's google-mail). A listing reached with a key is direct
|
|
9
|
+
// too: the key is kept here and sent only to the listing's hosts, so the
|
|
10
|
+
// broker is never asked. Only a service signed in to through the broker's
|
|
11
|
+
// own app, or with a client of the person's own, is brokered. A listing whose
|
|
12
|
+
// hosts depend on the account names none, and is left out until it can say
|
|
13
|
+
// them.
|
|
14
|
+
//
|
|
15
|
+
// Every offer can have its own integration row before anyone connects it.
|
|
16
|
+
// Connecting marks it built only once its broker is ready (`adopted`).
|
|
17
|
+
|
|
18
|
+
import { cmp } from '@yaks/fp'
|
|
19
|
+
import type { Listing } from './brokers.ts'
|
|
20
|
+
import {
|
|
21
|
+
type Integration,
|
|
22
|
+
type Marked,
|
|
23
|
+
standIn,
|
|
24
|
+
visitorPolicy,
|
|
25
|
+
} from './integrations.js'
|
|
26
|
+
|
|
27
|
+
/** A service as the catalog offers it: the integration it is or would be,
|
|
28
|
+
* the kinds of service it is, the address of its logo where it has no SVG of
|
|
29
|
+
* its own, and whether it is featured. */
|
|
30
|
+
export type Offer = Marked & {
|
|
31
|
+
categories: string[]
|
|
32
|
+
image?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// A kind of service as a person reads it: "crm" as CRM, "dev-tools" as Dev
|
|
36
|
+
// tools.
|
|
37
|
+
let WORDS: Record<string, string> = {
|
|
38
|
+
crm: 'CRM',
|
|
39
|
+
hr: 'HR',
|
|
40
|
+
ats: 'Hiring',
|
|
41
|
+
erp: 'ERP',
|
|
42
|
+
iam: 'Identity',
|
|
43
|
+
cms: 'CMS',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// kind('dev-tools') -> 'Dev tools'
|
|
47
|
+
/// kind('crm') -> 'CRM'
|
|
48
|
+
export let kind = (category: string): string =>
|
|
49
|
+
WORDS[category] ??
|
|
50
|
+
category.charAt(0).toUpperCase() + category.slice(1).replaceAll('-', ' ')
|
|
51
|
+
|
|
52
|
+
/** Whether an integration can take credential help from the broker catalog. */
|
|
53
|
+
export let catalogKey = (i: Integration): boolean =>
|
|
54
|
+
!i.owner && i.connects == 'key' && Array.isArray(i.categories)
|
|
55
|
+
|
|
56
|
+
/** Instructions someone wrote, ignoring old imports of credential field
|
|
57
|
+
* descriptions from the broker catalog. */
|
|
58
|
+
export let keyHelp = (i?: Integration): string => {
|
|
59
|
+
let source = i?.instructions ?? ''
|
|
60
|
+
return !source.trim() || i && catalogKey(i) &&
|
|
61
|
+
/^(?:- \*\*[^\n]+?\*\*:|\*\*[^\n]+?\*\*\r?\n[ \t]*:)/.test(
|
|
62
|
+
source.trimStart(),
|
|
63
|
+
)
|
|
64
|
+
? ''
|
|
65
|
+
: source
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A link to the credential page or guide, for a listing with no written
|
|
69
|
+
* steps. */
|
|
70
|
+
export let keyGuide = (l?: Listing): string => {
|
|
71
|
+
let url = l?.keyGuide && URL.canParse(l.keyGuide) && new URL(l.keyGuide)
|
|
72
|
+
return l?.connects == 'key' && url && url.protocol == 'https:' &&
|
|
73
|
+
!url.username && !url.password
|
|
74
|
+
? `[Where to get your key](<${url.href}>)`
|
|
75
|
+
: ''
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The integration a broker's listing would be: brokered where it is signed
|
|
79
|
+
* in to through the broker, a pasted key where it is reached with one. */
|
|
80
|
+
export let offerOf = (l: Listing, broker: string): Offer => {
|
|
81
|
+
let instructions = keyGuide(l)
|
|
82
|
+
let i: Offer = {
|
|
83
|
+
name: l.name,
|
|
84
|
+
title: l.title,
|
|
85
|
+
tagline: l.categories.slice(0, 3).map(kind).join(' · '),
|
|
86
|
+
hosts: l.hosts,
|
|
87
|
+
connects: l.connects,
|
|
88
|
+
...l.connects == 'key'
|
|
89
|
+
? { ...l.fields ? { fields: l.fields } : {} }
|
|
90
|
+
: { broker: { name: broker, integration: l.name } },
|
|
91
|
+
...instructions ? { instructions } : {},
|
|
92
|
+
categories: l.categories,
|
|
93
|
+
...l.logo ? { image: l.logo } : {},
|
|
94
|
+
...l.popular ? { featured: true } : {},
|
|
95
|
+
}
|
|
96
|
+
return { ...i, visitors: visitorPolicy(i) }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The catalog: the built integrations a person may be offered unasked (none
|
|
100
|
+
* in its service's testing mode), each featured, and every listing of
|
|
101
|
+
* `broker` that no built one stands in for and that names its hosts, featured
|
|
102
|
+
* where the broker features it, by title. A built integration takes the kinds
|
|
103
|
+
* of the listing it stands in for. */
|
|
104
|
+
export let catalogue = (
|
|
105
|
+
integrations: Marked[],
|
|
106
|
+
listings: Listing[],
|
|
107
|
+
broker: string,
|
|
108
|
+
): Offer[] => {
|
|
109
|
+
let built = integrations.filter((i) => i.built)
|
|
110
|
+
let by = new Map(listings.map((l) => [l.name, l]))
|
|
111
|
+
let standing = (i: Integration) =>
|
|
112
|
+
by.get(i.broker?.name == broker ? i.broker.integration : i.name) ??
|
|
113
|
+
by.get(i.name)
|
|
114
|
+
let taken = (name: string) => !!standIn(built, name, broker)
|
|
115
|
+
// A described one the broker signs in to is offered only while the broker
|
|
116
|
+
// lists it: it can connect nothing else.
|
|
117
|
+
let pending = integrations.filter((i) =>
|
|
118
|
+
!i.built && !i.owner && !i.testing && i.hosts.length &&
|
|
119
|
+
Array.isArray(i.categories) && !taken(i.name) &&
|
|
120
|
+
(i.broker?.name != broker || by.has(i.broker.integration))
|
|
121
|
+
).map((i): Offer => ({
|
|
122
|
+
...i,
|
|
123
|
+
visitors: visitorPolicy(i),
|
|
124
|
+
categories: i.categories ?? [],
|
|
125
|
+
}))
|
|
126
|
+
let described = new Set(pending.map((i) => i.name))
|
|
127
|
+
return [
|
|
128
|
+
...built.filter((i) => !i.testing).map((i): Offer => {
|
|
129
|
+
let l = standing(i)
|
|
130
|
+
return {
|
|
131
|
+
...i,
|
|
132
|
+
visitors: visitorPolicy(i),
|
|
133
|
+
categories: i.categories ?? l?.categories ?? [],
|
|
134
|
+
...!i.logo && !i.image && l?.logo ? { image: l.logo } : {},
|
|
135
|
+
featured: true,
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
...pending,
|
|
139
|
+
...listings.filter((l) =>
|
|
140
|
+
!taken(l.name) && !described.has(l.name) && l.hosts.length
|
|
141
|
+
)
|
|
142
|
+
.map((l) => offerOf(l, broker)),
|
|
143
|
+
].sort((a, b) =>
|
|
144
|
+
cmp((a.title || a.name).toLowerCase(), (b.title || b.name).toLowerCase())
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// How well an offer answers one word: its title starting with it, a word of
|
|
149
|
+
// its title starting with it, its name or kinds holding it, or not at all.
|
|
150
|
+
let fit = (o: Offer, word: string): number => {
|
|
151
|
+
let title = (o.title || o.name).toLowerCase()
|
|
152
|
+
if (title.startsWith(word)) return 3
|
|
153
|
+
if (title.split(/[^a-z0-9]+/).some((w) => w.startsWith(word))) return 2
|
|
154
|
+
return [o.name, ...o.categories, ...o.categories.map(kind), o.tagline ?? '']
|
|
155
|
+
.some((t) => t.toLowerCase().includes(word))
|
|
156
|
+
? 1
|
|
157
|
+
: 0
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The offers that hold every word of `words`, best first: by how well each
|
|
161
|
+
* word fits, then featured, then by title. No words is every offer. */
|
|
162
|
+
export let find = (offers: Offer[], words: string): Offer[] => {
|
|
163
|
+
let terms = words.toLowerCase().split(/\s+/).filter(Boolean)
|
|
164
|
+
return offers
|
|
165
|
+
.map((o) => ({ o, score: terms.map((t) => fit(o, t)) }))
|
|
166
|
+
.filter(({ score }) => score.every((s) => s > 0))
|
|
167
|
+
.sort((a, b) =>
|
|
168
|
+
b.score.reduce((n, s) => n + s, 0) - a.score.reduce((n, s) => n + s, 0) ||
|
|
169
|
+
Number(!!b.o.featured) - Number(!!a.o.featured)
|
|
170
|
+
)
|
|
171
|
+
.map(({ o }) => o)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The kinds of service the catalog holds, the most common first. */
|
|
175
|
+
export let kinds = (offers: Offer[]): string[] => {
|
|
176
|
+
let n = new Map<string, number>()
|
|
177
|
+
for (let c of offers.flatMap((o) => o.categories)) {
|
|
178
|
+
n.set(c, (n.get(c) ?? 0) + 1)
|
|
179
|
+
}
|
|
180
|
+
return [...n].sort((a, b) => b[1] - a[1] || cmp(a[0], b[0])).map(([c]) => c)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The integration an offer is written as once someone connects it, with
|
|
184
|
+
* its logo as an SVG document where one was fetched: only the host writes
|
|
185
|
+
* it, so it is `built`. Whether it is featured is the platform's mark, never
|
|
186
|
+
* the integration's own word. */
|
|
187
|
+
export let adopted = (o: Offer, logo?: string): Integration => {
|
|
188
|
+
let { featured: _, ...i } = o
|
|
189
|
+
return { ...i, ...logo ? { logo } : {}, built: true }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// What may stand before an SVG document's root: a byte-order mark, space, an
|
|
193
|
+
// XML declaration, comments and its doctype.
|
|
194
|
+
let PROLOG =
|
|
195
|
+
/^(?:\uFEFF|\s|<\?xml[^>]*\?>|<!--[\s\S]*?-->|<!DOCTYPE svg[^>]*>)*/i
|
|
196
|
+
|
|
197
|
+
/** Whether `text` is an SVG document: its root is `<svg>`. A page that holds
|
|
198
|
+
* an SVG is not one. */
|
|
199
|
+
/// isSvg('<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg"/>') -> true
|
|
200
|
+
/// isSvg('<!-- drawn --><svg><path/></svg>') -> true
|
|
201
|
+
/// isSvg('<!doctype html><html><body><svg></svg></body></html>') -> false
|
|
202
|
+
export let isSvg = (text: string): boolean =>
|
|
203
|
+
/^<svg[\s>/]/.test(text.replace(PROLOG, ''))
|
|
204
|
+
|
|
205
|
+
let XML: Record<string, string> = { '&': '&', '<': '<', '>': '>' }
|
|
206
|
+
|
|
207
|
+
/** The logo a service with no image of its own wears: the first letter of
|
|
208
|
+
* its title on a rounded square, as an SVG document. */
|
|
209
|
+
export let initialLogo = (title: string): string => {
|
|
210
|
+
let first = ([...title.trim()][0] ?? '?').toUpperCase()
|
|
211
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">' +
|
|
212
|
+
'<rect width="24" height="24" rx="6" fill="#8882"/>' +
|
|
213
|
+
'<text x="12" y="16.5" text-anchor="middle" font-size="13" ' +
|
|
214
|
+
'font-family="system-ui,sans-serif" font-weight="600" fill="#888">' +
|
|
215
|
+
`${first.replace(/[&<>]/g, (c) => XML[c])}</text></svg>`
|
|
216
|
+
}
|
package/cli.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Terminal command declarations. Authorization loads only when yak auth runs.
|
|
2
|
+
export let commands = [
|
|
3
|
+
{
|
|
4
|
+
name: 'auth',
|
|
5
|
+
description: 'List integrations or sign in. Paste the complete return URL into masked terminal input.',
|
|
6
|
+
inputSchema: {
|
|
7
|
+
type: 'object',
|
|
8
|
+
additionalProperties: false,
|
|
9
|
+
properties: {
|
|
10
|
+
name: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'integration name or title'
|
|
13
|
+
},
|
|
14
|
+
key: {
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
description: 'paste an agent grant or service key into masked input'
|
|
17
|
+
},
|
|
18
|
+
as: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'outside account, when signing in without a browser'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
positional: [
|
|
25
|
+
'name'
|
|
26
|
+
],
|
|
27
|
+
run: async (args, host, context)=>(await import("./auth_command.js")).auth(args, host, context)
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
//# sourceMappingURL=cli.js.map
|
package/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sources":["./cli.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAG9E,OAAO,IAAI,WAAyB;EAAC;IACnC,MAAM;IACN,aACE;IACF,aAAa;MACX,MAAM;MACN,sBAAsB;MACtB,YAAY;QACV,MAAM;UAAE,MAAM;UAAU,aAAa;QAA4B;QACjE,KAAK;UACH,MAAM;UACN,aAAa;QACf;QACA,IAAI;UACF,MAAM;UACN,aAAa;QACf;MACF;IACF;IACA,YAAY;MAAC;KAAO;IACpB,KAAK,OAAO,MAAM,MAAM,UACtB,CAAC,MAAM,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,MAAM;EACzD;CAAE,CAAA"}
|
package/cli.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Terminal command declarations. Authorization loads only when yak auth runs.
|
|
2
|
+
import type { CliCommand } from 'jsr:@yaks/cli@0.2.36/host'
|
|
3
|
+
|
|
4
|
+
export let commands: CliCommand[] = [{
|
|
5
|
+
name: 'auth',
|
|
6
|
+
description:
|
|
7
|
+
'List integrations or sign in. Paste the complete return URL into masked terminal input.',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
name: { type: 'string', description: 'integration name or title' },
|
|
13
|
+
key: {
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
description: 'paste an agent grant or service key into masked input',
|
|
16
|
+
},
|
|
17
|
+
as: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
description: 'outside account, when signing in without a browser',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
positional: ['name'],
|
|
24
|
+
run: async (args, host, context) =>
|
|
25
|
+
(await import('./auth_command.js')).auth(args, host, context),
|
|
26
|
+
}]
|
package/clients.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// OAuth clients: what an integration signs in as, registered once with a
|
|
2
|
+
// service and kept once, however many integrations share it. google-calendar,
|
|
3
|
+
// gmail and google-search-console name `google`; a product that needs a
|
|
4
|
+
// client of its own names another. An integration names its client
|
|
5
|
+
// (`Integration.client`); the client is a secret (@yaks/secrets), so the graph
|
|
6
|
+
// holds its handle and the vault its id and secret. It is set the way any
|
|
7
|
+
// secret is — a sealed write through trusted code — never through a tool's
|
|
8
|
+
// arguments, which a graph keeps as the text of a call, nor a host's
|
|
9
|
+
// environment.
|
|
10
|
+
import { reveal, sealed } from "@yaks/secrets";
|
|
11
|
+
import { installed } from "./integrations.js";
|
|
12
|
+
// The name a client is kept under among the graph's secrets.
|
|
13
|
+
export let clientSecret = (name)=>`oauth_client ${name}`;
|
|
14
|
+
/** The bundle that keeps `client` under `name`: the id and the secret go to
|
|
15
|
+
* the vault, and the graph holds the handle. */ export let registration = (name, client)=>sealed(clientSecret(name), JSON.stringify(client));
|
|
16
|
+
/** The client kept under `name`, if one is. */ export let registered = async (vault, name)=>{
|
|
17
|
+
let text = await reveal(vault, clientSecret(name), {
|
|
18
|
+
env: ()=>undefined
|
|
19
|
+
});
|
|
20
|
+
if (!text) return undefined;
|
|
21
|
+
let c = JSON.parse(text);
|
|
22
|
+
if (typeof c?.id != 'string' || c.secret != null && typeof c.secret != 'string' || c.bot != null && typeof c.bot != 'string' || c.signing != null && typeof c.signing != 'string') throw new Error(`${name} is not an OAuth client`);
|
|
23
|
+
return c;
|
|
24
|
+
};
|
|
25
|
+
/** The client an integration signs in as. A custom integration never signs in
|
|
26
|
+
* as a client a built one names: that client's secret would go to whatever
|
|
27
|
+
* token endpoint the custom integration gives. */ export let clientOf = async (vault, read, i)=>{
|
|
28
|
+
if (!i.client) return undefined;
|
|
29
|
+
let taken = !i.built && (await installed(read)).some((b)=>b.client == i.client);
|
|
30
|
+
let client = taken ? undefined : await registered(vault, i.client);
|
|
31
|
+
if (i.chat_grant && (!client?.secret || !client.signing)) return undefined;
|
|
32
|
+
return client;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=clients.js.map
|
package/clients.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clients.js","sources":["./clients.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E,wEAAwE;AACxE,mEAAmE;AACnE,+EAA+E;AAC/E,0EAA0E;AAC1E,2EAA2E;AAC3E,qEAAqE;AACrE,eAAe;AAGf,SAAS,MAAM,EAAE,MAAM,6BAA8C;AACrE,SAAS,SAAS,4BAAwD;AAa1E,6DAA6D;AAC7D,OAAO,IAAI,eAAe,CAAC,OAAiB,CAAC,aAAa,EAAE,MAAM,CAAA;AAElE;8CAC8C,GAC9C,OAAO,IAAI,eAAe,CAAC,MAAc,SACvC,OAAO,aAAa,OAAO,KAAK,SAAS,CAAC,SAAQ;AAEpD,6CAA6C,GAC7C,OAAO,IAAI,aAAa,OACtB,OACA;EAEA,IAAI,OAAO,MAAM,OAAO,OAAO,aAAa,OAAO;IAAE,KAAK,IAAM;EAAU;EAC1E,IAAI,CAAC,MAAM,OAAO;EAClB,IAAI,IAAI,KAAK,KAAK,CAAC;EACnB,IACE,OAAO,GAAG,MAAM,YACf,EAAE,MAAM,IAAI,QAAQ,OAAO,EAAE,MAAM,IAAI,YACvC,EAAE,GAAG,IAAI,QAAQ,OAAO,EAAE,GAAG,IAAI,YACjC,EAAE,OAAO,IAAI,QAAQ,OAAO,EAAE,OAAO,IAAI,UAC1C,MAAM,IAAI,MAAM,GAAG,KAAK,uBAAuB,CAAC;EAClD,OAAO;AACT,EAAC;AAED;;gDAEgD,GAChD,OAAO,IAAI,WAAW,OACpB,OACA,MACA;EAEA,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO;EACtB,IAAI,QAAQ,CAAC,EAAE,KAAK,IAClB,CAAC,MAAM,UAAU,KAAK,EAAE,IAAI,CAAC,CAAC,IAAM,EAAE,MAAM,IAAI,EAAE,MAAM;EAC1D,IAAI,SAAS,QAAQ,YAAY,MAAM,WAAW,OAAO,EAAE,MAAM;EACjE,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC,QAAQ,UAAU,CAAC,OAAO,OAAO,GAAG,OAAO;EACjE,OAAO;AACT,EAAC"}
|
package/clients.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// OAuth clients: what an integration signs in as, registered once with a
|
|
2
|
+
// service and kept once, however many integrations share it. google-calendar,
|
|
3
|
+
// gmail and google-search-console name `google`; a product that needs a
|
|
4
|
+
// client of its own names another. An integration names its client
|
|
5
|
+
// (`Integration.client`); the client is a secret (@yaks/secrets), so the graph
|
|
6
|
+
// holds its handle and the vault its id and secret. It is set the way any
|
|
7
|
+
// secret is — a sealed write through trusted code — never through a tool's
|
|
8
|
+
// arguments, which a graph keeps as the text of a call, nor a host's
|
|
9
|
+
// environment.
|
|
10
|
+
|
|
11
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
12
|
+
import { reveal, sealed, type Vault } from '@yaks/secrets'
|
|
13
|
+
import { installed, type Integration, type Read } from './integrations.js'
|
|
14
|
+
|
|
15
|
+
/** A client registered with a service: its id, a confidential client's
|
|
16
|
+
* secret, and the token of the bot its application speaks as on a chat
|
|
17
|
+
* platform (Discord's), for an integration that `chat`s. */
|
|
18
|
+
export type Registered = {
|
|
19
|
+
id: string
|
|
20
|
+
secret?: string
|
|
21
|
+
bot?: string
|
|
22
|
+
/** The signing secret for events sent by the application's chat provider. */
|
|
23
|
+
signing?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The name a client is kept under among the graph's secrets.
|
|
27
|
+
export let clientSecret = (name: string) => `oauth_client ${name}`
|
|
28
|
+
|
|
29
|
+
/** The bundle that keeps `client` under `name`: the id and the secret go to
|
|
30
|
+
* the vault, and the graph holds the handle. */
|
|
31
|
+
export let registration = (name: string, client: Registered): Bundle =>
|
|
32
|
+
sealed(clientSecret(name), JSON.stringify(client))
|
|
33
|
+
|
|
34
|
+
/** The client kept under `name`, if one is. */
|
|
35
|
+
export let registered = async (
|
|
36
|
+
vault: Vault,
|
|
37
|
+
name: string,
|
|
38
|
+
): Promise<Registered | undefined> => {
|
|
39
|
+
let text = await reveal(vault, clientSecret(name), { env: () => undefined })
|
|
40
|
+
if (!text) return undefined
|
|
41
|
+
let c = JSON.parse(text)
|
|
42
|
+
if (
|
|
43
|
+
typeof c?.id != 'string' ||
|
|
44
|
+
(c.secret != null && typeof c.secret != 'string') ||
|
|
45
|
+
(c.bot != null && typeof c.bot != 'string') ||
|
|
46
|
+
(c.signing != null && typeof c.signing != 'string')
|
|
47
|
+
) throw new Error(`${name} is not an OAuth client`)
|
|
48
|
+
return c
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The client an integration signs in as. A custom integration never signs in
|
|
52
|
+
* as a client a built one names: that client's secret would go to whatever
|
|
53
|
+
* token endpoint the custom integration gives. */
|
|
54
|
+
export let clientOf = async (
|
|
55
|
+
vault: Vault,
|
|
56
|
+
read: Read,
|
|
57
|
+
i: Integration,
|
|
58
|
+
): Promise<Registered | undefined> => {
|
|
59
|
+
if (!i.client) return undefined
|
|
60
|
+
let taken = !i.built &&
|
|
61
|
+
(await installed(read)).some((b) => b.client == i.client)
|
|
62
|
+
let client = taken ? undefined : await registered(vault, i.client)
|
|
63
|
+
if (i.chat_grant && (!client?.secret || !client.signing)) return undefined
|
|
64
|
+
return client
|
|
65
|
+
}
|