@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.
Files changed (184) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +609 -2
  3. package/_dist/authorize.d.ts +38 -0
  4. package/_dist/authorize.d.ts.map +1 -0
  5. package/_dist/authorize_cli.d.ts +12 -0
  6. package/_dist/authorize_cli.d.ts.map +1 -0
  7. package/_dist/brokers.d.ts +66 -0
  8. package/_dist/brokers.d.ts.map +1 -0
  9. package/_dist/catalog.d.ts +33 -0
  10. package/_dist/catalog.d.ts.map +1 -0
  11. package/_dist/cli.d.ts +3 -0
  12. package/_dist/cli.d.ts.map +1 -0
  13. package/_dist/clients.d.ts +18 -0
  14. package/_dist/clients.d.ts.map +1 -0
  15. package/_dist/connections.d.ts +296 -0
  16. package/_dist/connections.d.ts.map +1 -0
  17. package/_dist/effects.d.ts +15 -0
  18. package/_dist/effects.d.ts.map +1 -0
  19. package/_dist/field.d.ts +17 -0
  20. package/_dist/field.d.ts.map +1 -0
  21. package/_dist/form.d.ts +49 -0
  22. package/_dist/form.d.ts.map +1 -0
  23. package/_dist/given.d.ts +10 -0
  24. package/_dist/given.d.ts.map +1 -0
  25. package/_dist/graph.d.ts +15 -0
  26. package/_dist/graph.d.ts.map +1 -0
  27. package/_dist/history.d.ts +4 -0
  28. package/_dist/history.d.ts.map +1 -0
  29. package/_dist/identity.d.ts +9 -0
  30. package/_dist/identity.d.ts.map +1 -0
  31. package/_dist/integrations.d.ts +196 -0
  32. package/_dist/integrations.d.ts.map +1 -0
  33. package/_dist/loopback.d.ts +7 -0
  34. package/_dist/loopback.d.ts.map +1 -0
  35. package/_dist/mcp-retirement.d.ts +33 -0
  36. package/_dist/mcp-retirement.d.ts.map +1 -0
  37. package/_dist/mcp.d.ts +179 -0
  38. package/_dist/mcp.d.ts.map +1 -0
  39. package/_dist/mod.d.ts +70 -0
  40. package/_dist/mod.d.ts.map +1 -0
  41. package/_dist/paste.d.ts +13 -0
  42. package/_dist/paste.d.ts.map +1 -0
  43. package/_dist/requests.d.ts +30 -0
  44. package/_dist/requests.d.ts.map +1 -0
  45. package/_dist/services.d.ts +25 -0
  46. package/_dist/services.d.ts.map +1 -0
  47. package/_dist/sign-in.d.ts +9 -0
  48. package/_dist/sign-in.d.ts.map +1 -0
  49. package/_dist/signin-mail.d.ts +12 -0
  50. package/_dist/signin-mail.d.ts.map +1 -0
  51. package/_dist/signin.d.ts +19 -0
  52. package/_dist/signin.d.ts.map +1 -0
  53. package/_dist/sources.d.ts +61 -0
  54. package/_dist/sources.d.ts.map +1 -0
  55. package/_dist/tools.d.ts +3 -0
  56. package/_dist/tools.d.ts.map +1 -0
  57. package/_dist/views.d.ts +3 -0
  58. package/_dist/views.d.ts.map +1 -0
  59. package/_dist/vocab.d.ts +6 -0
  60. package/_dist/vocab.d.ts.map +1 -0
  61. package/_dist/yaks-app.d.ts +29 -0
  62. package/_dist/yaks-app.d.ts.map +1 -0
  63. package/anthropic.json +12 -0
  64. package/auth_command.js +69 -0
  65. package/auth_command.js.map +1 -0
  66. package/auth_command.ts +74 -0
  67. package/authorize.js +89 -0
  68. package/authorize.js.map +1 -0
  69. package/authorize.ts +138 -0
  70. package/authorize_cli.js +167 -0
  71. package/authorize_cli.js.map +1 -0
  72. package/authorize_cli.ts +211 -0
  73. package/brokers.js +318 -0
  74. package/brokers.js.map +1 -0
  75. package/brokers.ts +423 -0
  76. package/canva.json +32 -0
  77. package/catalog.js +178 -0
  78. package/catalog.js.map +1 -0
  79. package/catalog.ts +216 -0
  80. package/cli.js +30 -0
  81. package/cli.js.map +1 -0
  82. package/cli.ts +26 -0
  83. package/clients.js +34 -0
  84. package/clients.js.map +1 -0
  85. package/clients.ts +65 -0
  86. package/connections.js +1961 -0
  87. package/connections.js.map +1 -0
  88. package/connections.ts +2561 -0
  89. package/deno.json +1 -0
  90. package/discord-account.json +22 -0
  91. package/discord-bot.json +20 -0
  92. package/discord.json +26 -0
  93. package/effects.js +168 -0
  94. package/effects.js.map +1 -0
  95. package/effects.ts +160 -0
  96. package/elevenlabs.json +18 -0
  97. package/facebook.json +18 -0
  98. package/field.js +19 -0
  99. package/field.js.map +1 -0
  100. package/field.ts +31 -0
  101. package/form.js +112 -0
  102. package/form.js.map +1 -0
  103. package/form.ts +178 -0
  104. package/git-config.js +44 -0
  105. package/git-config.js.map +1 -0
  106. package/git-config.ts +26 -0
  107. package/given.js +83 -0
  108. package/given.js.map +1 -0
  109. package/given.ts +88 -0
  110. package/gmail-mailbox.json +29 -0
  111. package/gmail.json +31 -0
  112. package/google-calendar.json +31 -0
  113. package/google-drive.json +31 -0
  114. package/google-search-console.json +29 -0
  115. package/graph.js +36 -0
  116. package/graph.js.map +1 -0
  117. package/graph.ts +52 -0
  118. package/history.js +31 -0
  119. package/history.js.map +1 -0
  120. package/history.ts +32 -0
  121. package/identity.js +15 -0
  122. package/identity.js.map +1 -0
  123. package/identity.ts +18 -0
  124. package/integrations.js +493 -0
  125. package/integrations.js.map +1 -0
  126. package/integrations.ts +725 -0
  127. package/loopback.js +72 -0
  128. package/loopback.js.map +1 -0
  129. package/loopback.ts +89 -0
  130. package/lulu.json +32 -0
  131. package/mcp-retirement.js +133 -0
  132. package/mcp-retirement.js.map +1 -0
  133. package/mcp-retirement.ts +200 -0
  134. package/mcp-signin.js +14 -0
  135. package/mcp-signin.js.map +1 -0
  136. package/mcp-signin.ts +13 -0
  137. package/mcp.js +1036 -0
  138. package/mcp.js.map +1 -0
  139. package/mcp.ts +1283 -0
  140. package/mod.js +70 -0
  141. package/mod.js.map +1 -0
  142. package/mod.ts +216 -0
  143. package/openai-api.json +12 -0
  144. package/openai.json +25 -0
  145. package/openrouter.json +14 -0
  146. package/package.json +89 -4
  147. package/paste.js +36 -0
  148. package/paste.js.map +1 -0
  149. package/paste.ts +55 -0
  150. package/requests.js +137 -0
  151. package/requests.js.map +1 -0
  152. package/requests.ts +200 -0
  153. package/services.js +84 -0
  154. package/services.js.map +1 -0
  155. package/services.ts +111 -0
  156. package/sign-in.js +36 -0
  157. package/sign-in.js.map +1 -0
  158. package/sign-in.ts +53 -0
  159. package/signin-mail.js +29 -0
  160. package/signin-mail.js.map +1 -0
  161. package/signin-mail.ts +56 -0
  162. package/signin.js +68 -0
  163. package/signin.js.map +1 -0
  164. package/signin.ts +109 -0
  165. package/slack.json +90 -0
  166. package/sources.js +178 -0
  167. package/sources.js.map +1 -0
  168. package/sources.ts +237 -0
  169. package/tools.js +39 -0
  170. package/tools.js.map +1 -0
  171. package/tools.ts +46 -0
  172. package/views.js +85 -0
  173. package/views.js.map +1 -0
  174. package/views.ts +89 -0
  175. package/visitor-defaults.json +8 -0
  176. package/vocab.js +17 -0
  177. package/vocab.js.map +1 -0
  178. package/vocab.json +863 -0
  179. package/vocab.ts +18 -0
  180. package/voipms.json +32 -0
  181. package/yaks-app.js +159 -0
  182. package/yaks-app.js.map +1 -0
  183. package/yaks-app.ts +177 -0
  184. package/youtube.json +26 -0
package/vocab.ts ADDED
@@ -0,0 +1,18 @@
1
+ // The component and tool declarations, and nothing else: the module a server or
2
+ // a browser page imports at `@yaks/connections/vocab`. It reaches no storage,
3
+ // no vault and no runtime, so a browser tab loading this vocabulary loads
4
+ // nothing else.
5
+
6
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
7
+ import doc from './vocab.json' with { type: 'json' }
8
+ import manifest from './package.json' with { type: 'json' }
9
+
10
+ /** `integration`, `connection`, the `uses` relation, and the two tools. */
11
+ export let connectionsDoc: VocabDoc = doc as VocabDoc
12
+
13
+ /** What this package is: its manifest's description, the one place it is
14
+ * written, which a host stamps on each document here. */
15
+ export let description: string = manifest.description
16
+
17
+ /** Every document this plugin declares. */
18
+ export let docs: VocabDoc[] = [connectionsDoc]
package/voipms.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "voipms",
3
+ "visitors": "never",
4
+ "title": "voip.ms",
5
+ "tagline": "Your own phone number: your Operator texts the people you ask it to from it.",
6
+ "site": "https://voip.ms",
7
+ "logo": "<svg viewBox=\"0 0 40 33\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M29.1832 0.766602C27.6059 0.767647 26.0537 1.16686 24.6672 1.92808C23.2808 2.68931 22.1039 3.7885 21.2431 5.12611L12.6133 18.5394C11.0671 20.95 7.48705 21.2989 6.08011 20.1113L12.8327 30.684C13.2622 31.3524 13.8497 31.9016 14.5422 32.2818C15.2346 32.662 16.0098 32.8611 16.7976 32.8611C17.5854 32.8611 18.3607 32.662 19.0531 32.2818C19.7455 31.9016 20.3331 31.3524 20.7625 30.684L40 0.766602H29.1832Z\" fill=\"#E1382D\"/><path d=\"M0 10.6628L3.71237 16.5307C3.71237 16.5307 5.19593 18.7016 7.71728 18.7016C10.2386 18.7016 11.6804 16.5307 11.6804 16.5307L15.3963 10.6664L0 10.6628Z\" fill=\"#444444\"/></svg>",
8
+ "hosts": [
9
+ "voip.ms"
10
+ ],
11
+ "methods": [
12
+ "getDIDsInfo",
13
+ "sendSMS",
14
+ "sendMMS",
15
+ "getSMS",
16
+ "getMMS",
17
+ "setSMS"
18
+ ],
19
+ "fields": [
20
+ {
21
+ "name": "username",
22
+ "label": "Sign-in email",
23
+ "shown": true,
24
+ "example": "you@example.com"
25
+ },
26
+ {
27
+ "name": "password",
28
+ "label": "API password"
29
+ }
30
+ ],
31
+ "instructions": "1. Sign in at [voip.ms](https://voip.ms) and open **Main Menu → SOAP & REST/JSON API**.\n2. Turn on **Enable API** and save it.\n3. Set an **API Password** and save it.\n4. Under **Enable IP Addresses**, enter `0.0.0.0` and save it. yaks.app calls from changing addresses.\n5. Enter your voip.ms sign-in email and that API password here.\n\nyaks.app lists every number on the account and changes none of them. A number you connected from your own account is never cancelled by yaks.app: it can read your numbers, text from them, and set where their texts go, and nothing else. Tell your Operator which number to text from (\"text from the church line\"), and whether texts to it should come to your Operator. Only a number you send texts to your Operator has its SMS URL callback pointed at yaks.app; its email and forwarding stay as they are, and the callback goes back as it was when you stop."
32
+ }
package/yaks-app.js ADDED
@@ -0,0 +1,159 @@
1
+ // yaks.app signs in as a discovered MCP integration. A bot walks the same
2
+ // sign-in and consent pages, retaining its website session only in the vault.
3
+ import { Refused } from "@yaks/graph/errors";
4
+ import { discover } from "@yaks/mcp-client/oauth";
5
+ import { registered, registration } from "./clients.js";
6
+ import { known } from "./integrations.js";
7
+ import { integrationEid } from "./identity.js";
8
+ import { REDIRECT } from "./signin.js";
9
+ import { codeFor } from "./signin-mail.js";
10
+ let cookie = (headers)=>/(?:^|,\s*)yak_session=([^;,\s]+)/.exec(headers.get('set-cookie') ?? '')?.[1];
11
+ // The cookies a page set, as the next request's cookie header: a typed code
12
+ // signs in only the browser that asked for it (signin.ts `spend`).
13
+ let jar = (headers)=>headers.getSetCookie().map((c)=>c.split(';')[0]).join('; ');
14
+ let unescape = (text)=>text.replaceAll('&amp;', '&').replaceAll('&quot;', '"').replaceAll('&#39;', "'").replaceAll('&lt;', '<').replaceAll('&gt;', '>');
15
+ let field = (html, name)=>{
16
+ let inputs = html.match(/<input\b[^>]*>/gi) ?? [];
17
+ for (let input of inputs){
18
+ if (new RegExp(`\\bname=["']${name}["']`).test(input)) {
19
+ let value = /\bvalue=["']([^"']*)["']/.exec(input)?.[1];
20
+ if (value != null) return unescape(value);
21
+ }
22
+ }
23
+ throw new Error(`the consent page has no ${name}`);
24
+ };
25
+ let form = (go, origin)=>(path, fields, cookies = '')=>go(`${origin}${path}`, {
26
+ method: 'POST',
27
+ redirect: 'manual',
28
+ signal: AbortSignal.timeout(30_000),
29
+ headers: {
30
+ 'content-type': 'application/x-www-form-urlencoded',
31
+ origin,
32
+ ...cookies ? {
33
+ cookie: cookies
34
+ } : {}
35
+ },
36
+ body: new URLSearchParams(fields)
37
+ });
38
+ /** A website session for a bot, signed in at `origin` the way a person signs
39
+ * in: it asks for a code, reads it from the letter this bot's graph received,
40
+ * and spends it. No browser and nobody else is asked, so a bot whose session
41
+ * lapsed signs itself in again. */ export let botSession = async (graph, origin, address, opts = {})=>{
42
+ let post = form(opts.fetch ?? fetch, origin);
43
+ let since = Date.now();
44
+ let asked = await post('/login', {
45
+ email: address
46
+ });
47
+ await asked.body?.cancel();
48
+ if (asked.status != 200) {
49
+ throw new Error(`the sign-in page refused: ${asked.status}`);
50
+ }
51
+ let code = await (opts.code ?? codeFor)(graph.read, address, since);
52
+ let spent = await post('/login/code', {
53
+ email: address,
54
+ code
55
+ }, jar(asked.headers));
56
+ let session = spent.status == 303 ? cookie(spent.headers) : undefined;
57
+ await spent.body?.cancel();
58
+ if (!session) {
59
+ throw new Error(`the sign-in code returned no website session: ${spent.status}`);
60
+ }
61
+ return session;
62
+ };
63
+ /** Spend the code sent to this bot's graph, then grant the OAuth request
64
+ * through the page's own q and consent fields. Redirects are never followed
65
+ * with a cookie or code, and the final return must name this flow's redirect. */ export let botCallback = async (graph, url, address, opts = {})=>{
66
+ let authorize = new URL(url), origin = authorize.origin;
67
+ let go = opts.fetch ?? fetch;
68
+ let post = form(go, origin);
69
+ let session = opts.session ?? await botSession(graph, origin, address, {
70
+ fetch: go,
71
+ code: opts.code
72
+ });
73
+ let page = await go(url, {
74
+ headers: {
75
+ cookie: `yak_session=${session}`
76
+ },
77
+ redirect: 'manual',
78
+ signal: AbortSignal.timeout(30_000)
79
+ });
80
+ if (!page.ok) {
81
+ await page.body?.cancel();
82
+ throw new Error(`the authorize page refused: ${page.status}`);
83
+ }
84
+ let html = await page.text();
85
+ let allowed = await post('/oauth/allow', {
86
+ q: field(html, 'q'),
87
+ consent: field(html, 'consent')
88
+ }, `yak_session=${session}`);
89
+ let callback = allowed.headers.get('location');
90
+ await allowed.body?.cancel();
91
+ if (allowed.status != 302 && allowed.status != 303 || !callback) {
92
+ throw new Error(`the consent page refused: ${allowed.status}`);
93
+ }
94
+ let target = new URL(callback), redirect = new URL(authorize.searchParams.get('redirect_uri') ?? '');
95
+ if (target.origin != redirect.origin || target.pathname != redirect.pathname) {
96
+ throw new Error('the consent page returned another redirect');
97
+ }
98
+ return {
99
+ callback: target.href,
100
+ session
101
+ };
102
+ };
103
+ /** The discovery and unattended callback seams for the ordinary auth command.
104
+ * A supplied session is for the held-cookie migration, not a terminal option. */ export let yaksApp = (h, opts = {})=>{
105
+ let origin = opts.origin ?? 'https://yaks.app';
106
+ let go = opts.fetch ?? fetch;
107
+ return {
108
+ fetch: go,
109
+ offers: [
110
+ 'yaks.app'
111
+ ],
112
+ prepare: async (name)=>{
113
+ if (name != 'yaks.app') return undefined;
114
+ let held = await known(h.graph.read, name);
115
+ let clientName = `mcp ${origin}/mcp`;
116
+ if (!held || !await registered(h.vault, clientName)) {
117
+ let found = await discover(`${origin}/mcp`, {}, go);
118
+ let id = await found.register(REDIRECT);
119
+ await h.graph.apply([
120
+ {
121
+ entity: {
122
+ eid: integrationEid(name)
123
+ },
124
+ integration: {
125
+ ...found.integration,
126
+ name,
127
+ title: 'yaks.app',
128
+ site: origin,
129
+ client: clientName
130
+ }
131
+ },
132
+ registration(clientName, {
133
+ id
134
+ })
135
+ ]);
136
+ }
137
+ return {
138
+ integration: name,
139
+ redirect: REDIRECT
140
+ };
141
+ },
142
+ callback: async (target, url, as)=>{
143
+ if (target.integration != 'yaks.app') return undefined;
144
+ if (!as && !opts.session) return undefined;
145
+ if (!opts.session && !as.toLowerCase().endsWith('@bot.yak.sh')) {
146
+ // --as selects accounts, it must not silently request mail we cannot read.
147
+ return undefined;
148
+ }
149
+ if (as && !as.includes('@')) {
150
+ throw new Refused('signing in a bot needs its whole address');
151
+ }
152
+ return await botCallback(h.graph, url, as ?? '', {
153
+ ...opts,
154
+ fetch: go
155
+ });
156
+ }
157
+ };
158
+ };
159
+ //# sourceMappingURL=yaks-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaks-app.js","sources":["./yaks-app.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAE9E,SAAS,OAAO,kCAAuC;AACvD,SAAS,QAAQ,sC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AM,QAAQ,CAAC;QAC9B,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC;UAClB;YACE,QAAQ;cAAE,KAAK,eAAe;YAAM;YACpC,aAAa;cACX,GAAG,MAAM,WAAW;cACpB;cACA,OAAO;cACP,MAAM;cACN,QAAQ;YACV;UACF;UACA,aAAa,YAAY;YAAE;UAAG;SAC/B;MACH;MACA,OAAO;QAAE,aAAa;QAAM,UAAU;MAAS;IACjD;IACA,UAAU,OAAO,QAAQ,KAAK;MAC5B,IAAI,OAAO,WAAW,IAAI,YAAY,OAAO;MAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,OAAO,EAAE,OAAO;MACjC,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,GAAI,WAAW,GAAG,QAAQ,CAAC,gBAAgB;QAC/D,2EAA2E;QAC3E,OAAO;MACT;MACA,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM;QAC3B,MAAM,IAAI,QAAQ;MACpB;MACA,OAAO,MAAM,YAAY,EAAE,KAAK,EAAE,KAAK,MAAM,IAAI;QAAE,GAAG,IAAI;QAAE,OAAO;MAAG;IACxE;EACF;AACF,EAAC"}
package/yaks-app.ts ADDED
@@ -0,0 +1,177 @@
1
+ // yaks.app signs in as a discovered MCP integration. A bot walks the same
2
+ // sign-in and consent pages, retaining its website session only in the vault.
3
+ import type { Graph } from 'jsr:@yaks/graph@0.2.36'
4
+ import { Refused } from '@yaks/graph/errors'
5
+ import { discover } from '@yaks/mcp-client/oauth'
6
+ import { registered, registration } from './clients.js'
7
+ import { known } from './integrations.js'
8
+ import { integrationEid } from './identity.js'
9
+ import type { Vault } from 'jsr:@yaks/secrets@0.2.36'
10
+ import type { AuthOptions, Callback } from './authorize.ts'
11
+ import { REDIRECT } from './signin.js'
12
+ import { codeFor } from './signin-mail.js'
13
+
14
+ let cookie = (headers: Headers) =>
15
+ /(?:^|,\s*)yak_session=([^;,\s]+)/.exec(headers.get('set-cookie') ?? '')?.[1]
16
+ // The cookies a page set, as the next request's cookie header: a typed code
17
+ // signs in only the browser that asked for it (signin.ts `spend`).
18
+ let jar = (headers: Headers) =>
19
+ headers.getSetCookie().map((c) => c.split(';')[0]).join('; ')
20
+ let unescape = (text: string) =>
21
+ text.replaceAll('&amp;', '&').replaceAll('&quot;', '"')
22
+ .replaceAll('&#39;', "'").replaceAll('&lt;', '<').replaceAll('&gt;', '>')
23
+ let field = (html: string, name: string) => {
24
+ let inputs = html.match(/<input\b[^>]*>/gi) ?? []
25
+ for (let input of inputs) {
26
+ if (new RegExp(`\\bname=["']${name}["']`).test(input)) {
27
+ let value = /\bvalue=["']([^"']*)["']/.exec(input)?.[1]
28
+ if (value != null) return unescape(value)
29
+ }
30
+ }
31
+ throw new Error(`the consent page has no ${name}`)
32
+ }
33
+ let form = (
34
+ go: typeof fetch,
35
+ origin: string,
36
+ ) =>
37
+ (path: string, fields: Record<string, string>, cookies = '') =>
38
+ go(`${origin}${path}`, {
39
+ method: 'POST',
40
+ redirect: 'manual',
41
+ signal: AbortSignal.timeout(30_000),
42
+ headers: {
43
+ 'content-type': 'application/x-www-form-urlencoded',
44
+ origin,
45
+ ...cookies ? { cookie: cookies } : {},
46
+ },
47
+ body: new URLSearchParams(fields),
48
+ })
49
+
50
+ /** A website session for a bot, signed in at `origin` the way a person signs
51
+ * in: it asks for a code, reads it from the letter this bot's graph received,
52
+ * and spends it. No browser and nobody else is asked, so a bot whose session
53
+ * lapsed signs itself in again. */
54
+ export let botSession = async (
55
+ graph: Pick<Graph, 'read'>,
56
+ origin: string,
57
+ address: string,
58
+ opts: { fetch?: typeof fetch; code?: typeof codeFor } = {},
59
+ ): Promise<string> => {
60
+ let post = form(opts.fetch ?? fetch, origin)
61
+ let since = Date.now()
62
+ let asked = await post('/login', { email: address })
63
+ await asked.body?.cancel()
64
+ if (asked.status != 200) {
65
+ throw new Error(`the sign-in page refused: ${asked.status}`)
66
+ }
67
+ let code = await (opts.code ?? codeFor)(graph.read, address, since)
68
+ let spent = await post(
69
+ '/login/code',
70
+ { email: address, code },
71
+ jar(asked.headers),
72
+ )
73
+ let session = spent.status == 303 ? cookie(spent.headers) : undefined
74
+ await spent.body?.cancel()
75
+ if (!session) {
76
+ throw new Error(
77
+ `the sign-in code returned no website session: ${spent.status}`,
78
+ )
79
+ }
80
+ return session
81
+ }
82
+
83
+ /** Spend the code sent to this bot's graph, then grant the OAuth request
84
+ * through the page's own q and consent fields. Redirects are never followed
85
+ * with a cookie or code, and the final return must name this flow's redirect. */
86
+ export let botCallback = async (
87
+ graph: Pick<Graph, 'read'>,
88
+ url: string,
89
+ address: string,
90
+ opts: { fetch?: typeof fetch; code?: typeof codeFor; session?: string } = {},
91
+ ): Promise<Callback> => {
92
+ let authorize = new URL(url), origin = authorize.origin
93
+ let go = opts.fetch ?? fetch
94
+ let post = form(go, origin)
95
+ let session = opts.session ??
96
+ await botSession(graph, origin, address, { fetch: go, code: opts.code })
97
+ let page = await go(url, {
98
+ headers: { cookie: `yak_session=${session}` },
99
+ redirect: 'manual',
100
+ signal: AbortSignal.timeout(30_000),
101
+ })
102
+ if (!page.ok) {
103
+ await page.body?.cancel()
104
+ throw new Error(`the authorize page refused: ${page.status}`)
105
+ }
106
+ let html = await page.text()
107
+ let allowed = await post('/oauth/allow', {
108
+ q: field(html, 'q'),
109
+ consent: field(html, 'consent'),
110
+ }, `yak_session=${session}`)
111
+ let callback = allowed.headers.get('location')
112
+ await allowed.body?.cancel()
113
+ if (allowed.status != 302 && allowed.status != 303 || !callback) {
114
+ throw new Error(`the consent page refused: ${allowed.status}`)
115
+ }
116
+ let target = new URL(callback),
117
+ redirect = new URL(authorize.searchParams.get('redirect_uri') ?? '')
118
+ if (
119
+ target.origin != redirect.origin || target.pathname != redirect.pathname
120
+ ) {
121
+ throw new Error('the consent page returned another redirect')
122
+ }
123
+ return { callback: target.href, session }
124
+ }
125
+ /** The discovery and unattended callback seams for the ordinary auth command.
126
+ * A supplied session is for the held-cookie migration, not a terminal option. */
127
+ export let yaksApp = (
128
+ h: { graph: Graph; vault: Vault },
129
+ opts: {
130
+ origin?: string
131
+ fetch?: typeof fetch
132
+ code?: typeof codeFor
133
+ session?: string
134
+ } = {},
135
+ ): AuthOptions => {
136
+ let origin = opts.origin ?? 'https://yaks.app'
137
+ let go = opts.fetch ?? fetch
138
+ return {
139
+ fetch: go,
140
+ offers: ['yaks.app'],
141
+ prepare: async (name) => {
142
+ if (name != 'yaks.app') return undefined
143
+ let held = await known(h.graph.read, name)
144
+ let clientName = `mcp ${origin}/mcp`
145
+ if (!held || !await registered(h.vault, clientName)) {
146
+ let found = await discover(`${origin}/mcp`, {}, go)
147
+ let id = await found.register(REDIRECT)
148
+ await h.graph.apply([
149
+ {
150
+ entity: { eid: integrationEid(name) },
151
+ integration: {
152
+ ...found.integration,
153
+ name,
154
+ title: 'yaks.app',
155
+ site: origin,
156
+ client: clientName,
157
+ },
158
+ },
159
+ registration(clientName, { id }),
160
+ ])
161
+ }
162
+ return { integration: name, redirect: REDIRECT }
163
+ },
164
+ callback: async (target, url, as) => {
165
+ if (target.integration != 'yaks.app') return undefined
166
+ if (!as && !opts.session) return undefined
167
+ if (!opts.session && !as!.toLowerCase().endsWith('@bot.yak.sh')) {
168
+ // --as selects accounts, it must not silently request mail we cannot read.
169
+ return undefined
170
+ }
171
+ if (as && !as.includes('@')) {
172
+ throw new Refused('signing in a bot needs its whole address')
173
+ }
174
+ return await botCallback(h.graph, url, as ?? '', { ...opts, fetch: go })
175
+ },
176
+ }
177
+ }
package/youtube.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "youtube",
3
+ "visitors": "never",
4
+ "title": "YouTube",
5
+ "tagline": "Read your liked videos, playlists, and subscriptions.",
6
+ "site": "https://www.youtube.com",
7
+ "logo": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><rect x=\"1\" y=\"4\" width=\"22\" height=\"16\" rx=\"4\" fill=\"#f00\"/><path d=\"m10 8 6 4-6 4z\" fill=\"#fff\"/></svg>",
8
+ "authorize": "https://accounts.google.com/o/oauth2/v2/auth",
9
+ "token": "https://oauth2.googleapis.com/token",
10
+ "client": "google",
11
+ "scopes": [
12
+ "https://www.googleapis.com/auth/youtube.readonly"
13
+ ],
14
+ "params": {
15
+ "access_type": "offline",
16
+ "prompt": "consent"
17
+ },
18
+ "hosts": [
19
+ "www.googleapis.com"
20
+ ],
21
+ "api": {
22
+ "base": "https://www.googleapis.com/youtube/v3",
23
+ "docs": "https://developers.google.com/youtube/data/reference/rest"
24
+ },
25
+ "testing": true
26
+ }