@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/graph.ts ADDED
@@ -0,0 +1,52 @@
1
+ // The `graph` export (`@yaks/connections/graph`): what a direct tool call is
2
+ // answered with beside its own answer. A call whose answer names a connection
3
+ // is answered with the integration it goes through too, so whoever asked for
4
+ // one (an agent calling connection_need) reads how to get its key without
5
+ // asking again. A host composes it like any plugin's graph facet; nothing
6
+ // calls it by hand.
7
+ //
8
+ // Every process composing this package loads this module as it starts, so it
9
+ // needs only the names (./identity.ts), never the connection actions.
10
+
11
+ import { line } from '@yaks/query'
12
+ import type { Bundle, Comp, Eid } from 'jsr:@yaks/graph@0.2.36'
13
+ import type { Reply } from 'jsr:@yaks/tools@0.2.36'
14
+ import type { Read } from './integrations.ts'
15
+ import { CONNECTION, INTEGRATION, integrationEid, USES } from './identity.js'
16
+
17
+ /** What this needs of the host: a read of its graph. */
18
+ export type Host = { graph: { read: Read } }
19
+
20
+ /** The integrations the connections among `bundles` go through, as the graph
21
+ * holds them, but for any `bundles` already carry: what a person and their
22
+ * agent read beside a connection, how to get its key among it. A `uses` link
23
+ * whose connection is not among them is read to find which. */
24
+ export let through = async (
25
+ read: Read,
26
+ bundles: Bundle[],
27
+ ): Promise<Bundle[]> => {
28
+ let names = new Set<string>()
29
+ let ask: Eid[] = []
30
+ for (let b of bundles) {
31
+ let c = b[CONNECTION] as Comp | undefined
32
+ if (typeof c?.integration == 'string') names.add(c.integration)
33
+ else if (b[USES]) ask.push(String((b.edge as Comp | undefined)?.to))
34
+ }
35
+ if (ask.length) {
36
+ for (let b of await read(line`.entity.eid=${ask}&.${CONNECTION}`)) {
37
+ names.add(String((b[CONNECTION] as Comp).integration))
38
+ }
39
+ }
40
+ let have = new Set(
41
+ bundles.filter((b) => b[INTEGRATION]).map((b) => b.entity.eid),
42
+ )
43
+ let wanted = [...names].map(integrationEid).filter((e) => !have.has(e))
44
+ return wanted.length
45
+ ? await read(line`.entity.eid=${wanted}&.${INTEGRATION}`)
46
+ : []
47
+ }
48
+
49
+ /** Beside a direct call's answer: the integrations its connections go
50
+ * through, but for those it already carries. */
51
+ export let reply = (host: Host): Reply => (_call, answer) =>
52
+ through(host.graph.read, answer)
package/history.js ADDED
@@ -0,0 +1,31 @@
1
+ import { CONNECTION } from "./identity.js";
2
+ /** The most recent archived connection that held a credential for each id.
3
+ * A snapshot from before sign-in can sort first when writes share a timestamp. */ export let connectionHistory = async (trash, eids)=>{
4
+ let missing = new Set(eids);
5
+ let found = new Map();
6
+ let before;
7
+ while(missing.size){
8
+ let page = await trash([
9
+ ...missing
10
+ ], {
11
+ limit: 20,
12
+ before
13
+ });
14
+ if (!page.length) break;
15
+ for (let entry of page){
16
+ for (let b of entry.bundles){
17
+ if (b[CONNECTION] && b.secret?.value && missing.delete(b.entity.eid)) {
18
+ found.set(b.entity.eid, b);
19
+ }
20
+ }
21
+ }
22
+ let last = page.at(-1);
23
+ if (last.id == before?.id) break;
24
+ before = {
25
+ id: last.id,
26
+ at: last.at
27
+ };
28
+ }
29
+ return found;
30
+ };
31
+ //# sourceMappingURL=history.js.map
package/history.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","sources":["./history.ts"],"names":[],"mappings":"AAEA,SAAS,UAAU,wBAAuB;AAE1C;gFACgF,GAChF,OAAO,IAAI,oBAAoB,OAC7B,OACA;EAEA,IAAI,UAAU,IAAI,IAAI;EACtB,IAAI,QAAQ,IAAI;EAChB,IAAI;EACJ,MAAO,QAAQ,IAAI,CAAE;IACnB,IAAI,OAAO,MAAM,MAAM;SAAI;KAAQ,EAAE;MAAE,OAAO;MAAI;IAAO;IACzD,IAAI,CAAC,KAAK,MAAM,EAAE;IAClB,KAAK,IAAI,SAAS,KAAM;MACtB,KAAK,IAAI,KAAK,MAAM,OAAO,CAAE;QAC3B,IACE,CAAC,CAAC,WAAW,IAAK,EAAE,MAAM,EAAuB,SACjD,QAAQ,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,GAC3B;UACA,MAAM,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE;QAC1B;MACF;IACF;IACA,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;IACpB,IAAI,KAAK,EAAE,IAAI,QAAQ,IAAI;IAC3B,SAAS;MAAE,IAAI,KAAK,EAAE;MAAE,IAAI,KAAK,EAAE;IAAC;EACtC;EACA,OAAO;AACT,EAAC"}
package/history.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { Bundle, Comp, Storage } from 'jsr:@yaks/graph@0.2.36'
2
+ import type { TrashPage } from 'jsr:@yaks/graph@0.2.36/trash'
3
+ import { CONNECTION } from './identity.js'
4
+
5
+ /** The most recent archived connection that held a credential for each id.
6
+ * A snapshot from before sign-in can sort first when writes share a timestamp. */
7
+ export let connectionHistory = async (
8
+ trash: NonNullable<Storage['trash']>,
9
+ eids: string[],
10
+ ): Promise<Map<string, Bundle>> => {
11
+ let missing = new Set(eids)
12
+ let found = new Map<string, Bundle>()
13
+ let before: TrashPage['before']
14
+ while (missing.size) {
15
+ let page = await trash([...missing], { limit: 20, before })
16
+ if (!page.length) break
17
+ for (let entry of page) {
18
+ for (let b of entry.bundles) {
19
+ if (
20
+ b[CONNECTION] && (b.secret as Comp | undefined)?.value &&
21
+ missing.delete(b.entity.eid)
22
+ ) {
23
+ found.set(b.entity.eid, b)
24
+ }
25
+ }
26
+ }
27
+ let last = page.at(-1)!
28
+ if (last.id == before?.id) break
29
+ before = { id: last.id, at: last.at }
30
+ }
31
+ return found
32
+ }
package/identity.js ADDED
@@ -0,0 +1,15 @@
1
+ // The names a graph consumer reads: the integration an address names, and the
2
+ // components a connection, an app's use of one and a task's ask for one are, without loading the
3
+ // seed installer or connection actions. Views and graph consumers resolve the
4
+ // same stored id.
5
+ import { identityEid } from "@yaks/graph/identity";
6
+ export let INTEGRATION = 'integration';
7
+ export let CONNECTION = 'connection';
8
+ export let USES = 'uses';
9
+ export let ASKS = 'asks';
10
+ /** The mark on a connection whose brokered grant is held for the account
11
+ * that approved it (@yaks/connections `settle`). */ export let APPROVING = 'approving';
12
+ /** An integration's entity: one name identifies one integration. */ export let integrationEid = (name)=>identityEid(INTEGRATION, [
13
+ name
14
+ ]);
15
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sources":["./identity.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iGAAiG;AACjG,8EAA8E;AAC9E,kBAAkB;AAElB,SAAS,WAAW,oCAAyC;AAE7D,OAAO,IAAI,cAAc,cAAa;AACtC,OAAO,IAAI,aAAa,aAAY;AACpC,OAAO,IAAI,OAAO,OAAM;AACxB,OAAO,IAAI,OAAO,OAAM;AACxB;kDACkD,GAClD,OAAO,IAAI,YAAY,YAAW;AAElC,kEAAkE,GAClE,OAAO,IAAI,iBAAiB,CAAC,OAC3B,YAAY,aAAa;IAAC;GAAK,EAAC"}
package/identity.ts ADDED
@@ -0,0 +1,18 @@
1
+ // The names a graph consumer reads: the integration an address names, and the
2
+ // components a connection, an app's use of one and a task's ask for one are, without loading the
3
+ // seed installer or connection actions. Views and graph consumers resolve the
4
+ // same stored id.
5
+ import type { Eid } from 'jsr:@yaks/graph@0.2.36/bundle'
6
+ import { identityEid } from '@yaks/graph/identity'
7
+
8
+ export let INTEGRATION = 'integration'
9
+ export let CONNECTION = 'connection'
10
+ export let USES = 'uses'
11
+ export let ASKS = 'asks'
12
+ /** The mark on a connection whose brokered grant is held for the account
13
+ * that approved it (@yaks/connections `settle`). */
14
+ export let APPROVING = 'approving'
15
+
16
+ /** An integration's entity: one name identifies one integration. */
17
+ export let integrationEid = (name: string): Eid =>
18
+ identityEid(INTEGRATION, [name])
@@ -0,0 +1,493 @@
1
+ // Integrations: the outside services a connection can go through, as data.
2
+ //
3
+ // An integration says where a person signs in to a service and where its codes
4
+ // are exchanged, for one reached by OAuth, which hosts its credential may be
5
+ // sent to, and how a page shows it: its name, a line about it, its site and its
6
+ // logo. One with no token endpoint is reached with a pasted key instead, or
7
+ // with the several fields it names (`fields`): S3's access key ID, secret key
8
+ // and region. One key is the case of one field, named `key`.
9
+ //
10
+ // Every integration is an entity in the graph wearing `integration`, and one
11
+ // name is one entity. The ones this package builds ship as seed data, one JSON
12
+ // file each, which a host installs into its graph at start-up (`install`),
13
+ // trusted, since only the host may mark one `built`. Nothing reads the files
14
+ // after that: every lookup is a read of the graph. A custom one is a key for a
15
+ // service nobody built, or a builder's own OAuth client, made by `need` only
16
+ // where no integration holds the name yet — so no verb a space can reach
17
+ // writes over a built integration, or changes where its tokens are sent.
18
+ import { joined, line, sub } from "@yaks/query";
19
+ import { after, cmp } from "@yaks/fp";
20
+ import { token } from "@yaks/graph/sha256";
21
+ import { CallError } from "@yaks/tools/errors";
22
+ import { INTEGRATION, integrationEid } from "./identity.js";
23
+ import { fieldsOf, KEY, loginFields } from "./field.js";
24
+ export { fieldsOf, KEY };
25
+ import anthropic from './anthropic.json' with {
26
+ type: 'json'
27
+ };
28
+ import canva from './canva.json' with {
29
+ type: 'json'
30
+ };
31
+ import gmail from './gmail.json' with {
32
+ type: 'json'
33
+ };
34
+ import gmailMailbox from './gmail-mailbox.json' with {
35
+ type: 'json'
36
+ };
37
+ import discord from './discord.json' with {
38
+ type: 'json'
39
+ };
40
+ import discordAccount from './discord-account.json' with {
41
+ type: 'json'
42
+ };
43
+ import discordBot from './discord-bot.json' with {
44
+ type: 'json'
45
+ };
46
+ import slack from './slack.json' with {
47
+ type: 'json'
48
+ };
49
+ import elevenlabs from './elevenlabs.json' with {
50
+ type: 'json'
51
+ };
52
+ import facebook from './facebook.json' with {
53
+ type: 'json'
54
+ };
55
+ import googleCalendar from './google-calendar.json' with {
56
+ type: 'json'
57
+ };
58
+ import googleDrive from './google-drive.json' with {
59
+ type: 'json'
60
+ };
61
+ import googleSearchConsole from './google-search-console.json' with {
62
+ type: 'json'
63
+ };
64
+ import lulu from './lulu.json' with {
65
+ type: 'json'
66
+ };
67
+ import openrouter from './openrouter.json' with {
68
+ type: 'json'
69
+ };
70
+ import openai from './openai.json' with {
71
+ type: 'json'
72
+ };
73
+ import openaiApi from './openai-api.json' with {
74
+ type: 'json'
75
+ };
76
+ import voipms from './voipms.json' with {
77
+ type: 'json'
78
+ };
79
+ import visitorDefaults from './visitor-defaults.json' with {
80
+ type: 'json'
81
+ };
82
+ import youtube from './youtube.json' with {
83
+ type: 'json'
84
+ };
85
+ // The integrations this package builds, as their seed files say them. The JSON
86
+ // types `answers` as any string, so OpenRouter's is said again as the word it
87
+ // is.
88
+ let SEEDS = [
89
+ anthropic,
90
+ canva,
91
+ discord,
92
+ discordAccount,
93
+ discordBot,
94
+ elevenlabs,
95
+ {
96
+ ...facebook,
97
+ connects: 'signin'
98
+ },
99
+ gmail,
100
+ gmailMailbox,
101
+ googleCalendar,
102
+ googleDrive,
103
+ googleSearchConsole,
104
+ lulu,
105
+ {
106
+ ...openai,
107
+ refresh_encoding: 'json'
108
+ },
109
+ openaiApi,
110
+ {
111
+ ...openrouter,
112
+ answers: 'key'
113
+ },
114
+ {
115
+ ...slack,
116
+ scope_separator: slack.scope_separator
117
+ },
118
+ voipms,
119
+ youtube
120
+ ].map((seed)=>({
121
+ ...seed,
122
+ visitors: seed.visitors
123
+ }));
124
+ /** The integrations this package builds, as shipped: what `install` writes,
125
+ * read here with no graph, for a host that only needs to know them. */ export let seeds = ()=>SEEDS;
126
+ /** Whether a person connects it by pasting a key rather than signing in:
127
+ * one with no token endpoint and no broker to sign in through. */ export let keyed = (i)=>!i.token && !i.broker;
128
+ /** The policy for older rows and catalog entries before they are added. */ export let visitorPolicy = (i)=>{
129
+ if (!i) return 'off';
130
+ if (i.visitors) return i.visitors;
131
+ if (!keyed(i) || i.connects == 'signin' || i.connects == 'client' || loginFields(fieldsOf(i))) return 'never';
132
+ return visitorDefaults[i.name] ?? 'off';
133
+ };
134
+ /** Whether visitors may call out through a link. The integration sets the
135
+ * default for an unset `anyone`. A policy of `never` bars visitor access.
136
+ *
137
+ * ```ts
138
+ * visitorsAllowed('on', undefined) // true
139
+ * visitorsAllowed('on', false) // false
140
+ * visitorsAllowed('off', undefined) // false
141
+ * visitorsAllowed('never', true) // false
142
+ * ``` */ export let visitorsAllowed = (policy, anyone)=>policy != 'never' && (typeof anyone == 'boolean' ? anyone : policy == 'on');
143
+ /** Whether a person can connect it here: by pasting a key, through a sign-in
144
+ * that answers a key to any caller (OpenRouter), or through what it signs in
145
+ * with once that is kept (`kept`): its broker, when it names one
146
+ * (./brokers.ts), else the OAuth client it names (./clients.ts). */ export let connectable = (i, kept)=>i.broker ? !!kept : keyed(i) || i.answers == 'key' || !!i.client_id || !!kept;
147
+ /** An integration by name, as the graph holds it. */ export let known = async (read, name)=>{
148
+ let [b] = await read(line`.entity.eid=${integrationEid(name)}&.${INTEGRATION}`);
149
+ return b?.[INTEGRATION];
150
+ };
151
+ /** The integrations of these names, as the graph holds them, in one read:
152
+ * each found among them by `knownIn`. */ export let knownAll = (read, names)=>Promise.resolve(names.length ? read(line`.entity.eid=${names.map(integrationEid)}&.${INTEGRATION}`) : []);
153
+ /** The built integration that stands in for the service `name`: the one of
154
+ * that name, else one signing in through a broker's listing of it (Gmail for
155
+ * Nango's google-mail). The catalog offers, the directory lists and the
156
+ * connections page adds that one in the listing's place. */ export let standIn = (built, name, broker)=>built.find((i)=>i.built && i.name == name) ?? built.find((i)=>i.built && i.broker?.integration == name && (!broker || i.broker.name == broker));
157
+ /** An integration by name, among rows already read: what `list` and
158
+ * `borrowed` return beside their connections. */ export let knownIn = (rows, name)=>rows.find((b)=>b[INTEGRATION] && b.entity.eid == integrationEid(name))?.[INTEGRATION];
159
+ /** The built integrations a graph holds. */ export let installed = async (read)=>(await read(line`.${INTEGRATION}.built`)).map((b)=>b[INTEGRATION]);
160
+ /** The platform's mark that an integration is featured (@yaks/platform). */ export let FEATURED = 'featured';
161
+ let marked = (b)=>({
162
+ ...b[INTEGRATION],
163
+ ...b[FEATURED] ? {
164
+ featured: true
165
+ } : {}
166
+ });
167
+ // Only fields that describe an offer. A connection reads the full integration.
168
+ let CARRIED = [
169
+ 'name',
170
+ 'title',
171
+ 'tagline',
172
+ 'site',
173
+ 'connects',
174
+ 'visitors',
175
+ 'categories',
176
+ 'image',
177
+ 'logo',
178
+ 'token',
179
+ 'broker',
180
+ 'hosts',
181
+ 'fields',
182
+ 'example',
183
+ 'mcp',
184
+ 'testing'
185
+ ];
186
+ let CATALOGUED = [
187
+ ...CARRIED.map((p)=>`${INTEGRATION}.${p}`),
188
+ FEATURED
189
+ ];
190
+ /** The host catalog's rows, including integrations not connected yet: those
191
+ * built here whole, the rest without their prose (`Prose`), which is half of
192
+ * each and drawn only for the one a page opens. */ export let catalogued = async (read)=>{
193
+ let [whole, rest] = await Promise.all([
194
+ read(line`.${INTEGRATION}.built=true&?${FEATURED}`),
195
+ read(line`.${INTEGRATION}.categories&!${INTEGRATION}.built&!${INTEGRATION}.owner&.fields=${CATALOGUED}`)
196
+ ]);
197
+ let built = new Map(whole.map((b)=>[
198
+ b.entity.eid,
199
+ b
200
+ ]));
201
+ return [
202
+ ...whole,
203
+ ...rest.filter((b)=>!built.has(b.entity.eid))
204
+ ].map(marked).filter((i)=>!i.owner && (i.built || Array.isArray(i.categories)));
205
+ };
206
+ // What moves whenever the catalog does: its newest integration, its newest
207
+ // edit, and which ones are featured, a few dozen rows. A custom integration
208
+ // is its owner's and no catalog's, and nothing deletes one (an owner's death
209
+ // detaches it), so these see every change the catalog makes, while the rest
210
+ // of the store moves none of them.
211
+ let SHOWN = line`.${INTEGRATION}&!${INTEGRATION}.owner`;
212
+ let STAMP = [
213
+ line`${sub(SHOWN)}&.order=-created.at&.limit=1&.fields=created.at`,
214
+ line`${sub(SHOWN)}&.order=-updated.at&.limit=1&.fields=updated.at`,
215
+ line`${sub(SHOWN)}&.${FEATURED}&.fields=${FEATURED}.at`
216
+ ];
217
+ /** The host catalog (`catalogued`), read again only once it changed: each
218
+ * call reads a stamp of a few rows beside the rest of its moment, and the
219
+ * whole only when the stamp moved. With none held yet, it reads the one
220
+ * `kept` holds beside the stamp, and the whole only where that is not the
221
+ * stamp's; with nothing kept, the whole beside the stamp. The rows are
222
+ * shared by every caller, so none changes them.
223
+ *
224
+ * ```ts
225
+ * import { assertEquals } from '@std/assert'
226
+ * import { catalogHeld } from '@yaks/connections'
227
+ * let asked: string[] = []
228
+ * let read = (q: unknown) => (asked.push(String(q)), Promise.resolve([]))
229
+ * let stamp = '[[],[],[]]'
230
+ * let kept = { get: () => Promise.resolve({ stamp, rows: [] }), put() {} }
231
+ * assertEquals(await catalogHeld(kept)(read), [])
232
+ * assertEquals(asked.length, 3, 'the stamp alone')
233
+ * ```
234
+ */ export let catalogHeld = (kept)=>{
235
+ // Values, never the reads' promises, which settle only in the request that
236
+ // made them (@yaks/fp `Scope`).
237
+ let held;
238
+ let whole = async (read, stamp)=>{
239
+ held = {
240
+ stamp,
241
+ rows: await catalogued(read)
242
+ };
243
+ kept?.put(held);
244
+ return held.rows;
245
+ };
246
+ return async (read)=>{
247
+ let stamping = Promise.all(STAMP.map((q)=>read(q))).then(JSON.stringify);
248
+ if (held) {
249
+ let stamp = await stamping;
250
+ return held.stamp == stamp ? held.rows : await whole(read, stamp);
251
+ }
252
+ if (kept) {
253
+ let [stamp, was] = await Promise.all([
254
+ stamping,
255
+ kept.get().catch(()=>undefined)
256
+ ]);
257
+ if (was?.stamp != stamp) return await whole(read, stamp);
258
+ held = was;
259
+ return held.rows;
260
+ }
261
+ let [stamp, rows] = await Promise.all([
262
+ stamping,
263
+ catalogued(read)
264
+ ]);
265
+ held = {
266
+ stamp,
267
+ rows
268
+ };
269
+ return rows;
270
+ };
271
+ };
272
+ /** The properties of {@link About}, in the order a page shows them. */ export let ABOUT = [
273
+ 'title',
274
+ 'tagline',
275
+ 'site',
276
+ 'instructions',
277
+ 'example',
278
+ 'check'
279
+ ];
280
+ let CHECK = /^(GET|HEAD|POST) https:\/\/[^\s/]+\S*$/;
281
+ /** What was said about an integration, as it is written: each property given,
282
+ * trimmed, and an empty one cleared. A site is an https address, the only
283
+ * kind a page links, and a check a method and an https address. */ export let told = (a)=>{
284
+ let out = {};
285
+ for (let k of ABOUT){
286
+ if (a[k] == null) continue;
287
+ let v = String(a[k]).trim();
288
+ if (k == 'site' && v && !/^https:\/\/[^\s/]+\S*$/.test(v)) {
289
+ throw new CallError('site', `a site is an https address, not ${v}`);
290
+ }
291
+ if (k == 'check' && v && !CHECK.test(v)) {
292
+ throw new CallError('check', `a check is a method and an https address, GET https://…, not ${v}`);
293
+ }
294
+ out[k] = v || null;
295
+ }
296
+ if (a.image != null) {
297
+ if (typeof a.image != 'string' || !/^[a-f0-9]{64}$/.test(a.image)) {
298
+ throw new CallError('image', 'The host must store the integration icon first.');
299
+ }
300
+ out.image = a.image;
301
+ }
302
+ return out;
303
+ };
304
+ /** What a custom integration shown in the integration directory wears:
305
+ * @yaks/platform's `published{at}`, as anything shared on a platform does. */ export let PUBLISHED = 'published';
306
+ /** The patch publishing a shared thing now, or taking it out. */ export let publishing = (on)=>on ? {
307
+ at: new Date().toISOString()
308
+ } : null;
309
+ /** An integration's owner changing what is said about it, or publishing it in
310
+ * the integration directory (`listed`) or taking it out. A built one is the
311
+ * host's, and one with no owner (made before owners were kept, or whose owner
312
+ * is gone) is nobody's to change. */ export let set = async (read, a)=>{
313
+ let name = a.integration;
314
+ let [held] = await read(line`.entity.eid=${integrationEid(name)}&.${INTEGRATION}&?${PUBLISHED}`);
315
+ let i = held?.[INTEGRATION];
316
+ if (!i) {
317
+ throw new CallError('integration', `no integration is named ${name}`);
318
+ }
319
+ if (i.built) {
320
+ throw new CallError('integration', `${name} is built, and only the host changes it`);
321
+ }
322
+ if (i.owner != a.owner) {
323
+ throw new CallError('owner', `only the space that made ${name} changes it`);
324
+ }
325
+ let patch = told(a);
326
+ // Published again, it keeps the moment it was first published.
327
+ let listing = a.listed == null || a.listed == !!held[PUBLISHED] ? {} : {
328
+ [PUBLISHED]: publishing(a.listed)
329
+ };
330
+ return Object.keys(patch).length || Object.keys(listing).length ? [
331
+ {
332
+ entity: {
333
+ eid: integrationEid(name)
334
+ },
335
+ ...Object.keys(patch).length ? {
336
+ [INTEGRATION]: patch
337
+ } : {},
338
+ ...listing,
339
+ $was: {
340
+ [INTEGRATION]: {
341
+ owner: token(i.owner)
342
+ }
343
+ }
344
+ }
345
+ ] : [];
346
+ };
347
+ // What the directory's words are matched against: an integration's text, and
348
+ // the app a service is.
349
+ let WORDED = [
350
+ 'name',
351
+ 'title',
352
+ 'tagline',
353
+ 'site',
354
+ 'hosts',
355
+ 'instructions',
356
+ 'description',
357
+ 'details',
358
+ 'docs',
359
+ 'connects',
360
+ 'service',
361
+ 'categories'
362
+ ];
363
+ // A property's words: each of a list, each value of an object.
364
+ let spoken = (v)=>Array.isArray(v) ? v.join(' ') : v && typeof v == 'object' ? Object.values(v).join(' ') : String(v ?? '');
365
+ // The prose a held catalog is without (`catalogued`), which the store
366
+ // searches.
367
+ let PROSE = [
368
+ 'description',
369
+ 'details',
370
+ 'docs',
371
+ 'instructions'
372
+ ];
373
+ let text = (i)=>WORDED.map((p)=>spoken(i[p])).join(' ').toLowerCase();
374
+ // What a listing reads of a row: the row, and the platform's marks on it.
375
+ let MARKS = line`&?${PUBLISHED}&?unchecked&?${FEATURED}`;
376
+ // Every row, read whole.
377
+ let every = async (read)=>{
378
+ let rows = await read(line`.${INTEGRATION}${sub(MARKS)}`);
379
+ return {
380
+ rows,
381
+ built: rows.map(marked).filter((i)=>i.built)
382
+ };
383
+ };
384
+ // The rows a search reads whole: each one listed by its owner, and those of
385
+ // the catalog holding every word, in what `catalog` holds of it or in its
386
+ // prose, which the store searches. The catalog is a thousand rows of prose,
387
+ // never read whole to find a few.
388
+ let searched = async (read, terms, catalog)=>{
389
+ let [held, custom, ...prose] = await Promise.all([
390
+ catalog(read),
391
+ read(line`.${INTEGRATION}.owner&.${PUBLISHED}${sub(MARKS)}`),
392
+ ...terms.map((t)=>read(line`.${INTEGRATION}&!${INTEGRATION}.owner&(${sub(joined(PROSE.map((p)=>line`.${INTEGRATION}.${p}~=${t}`), '|'))})&.fields=${INTEGRATION}.name`))
393
+ ]);
394
+ let inProse = prose.map((rows)=>new Set(rows.map((b)=>b.entity.eid)));
395
+ let eids = held.filter((i)=>terms.every((t, n)=>text(i).includes(t) || inProse[n].has(integrationEid(i.name)))).map((i)=>integrationEid(i.name));
396
+ let whole = eids.length ? await read(line`.entity.eid=${eids}&.${INTEGRATION}${sub(MARKS)}`) : [];
397
+ let got = new Set(whole.map((b)=>b.entity.eid));
398
+ return {
399
+ rows: [
400
+ ...whole,
401
+ ...custom.filter((b)=>!got.has(b.entity.eid))
402
+ ],
403
+ built: held.filter((i)=>i.built)
404
+ };
405
+ };
406
+ /**
407
+ * The integration directory: host catalog services outside testing and custom
408
+ * integrations their owner listed, by title. Words match every part of the
409
+ * service and integration descriptions, including categories and docs. A
410
+ * search takes the catalog without its prose from `catalog`, such as one
411
+ * `catalogHeld` keeps.
412
+ */ export let listing = async (read, words = '', catalog = catalogued)=>{
413
+ let terms = words.toLowerCase().split(/\s+/).filter(Boolean);
414
+ let { rows, built } = terms.length ? await searched(read, terms, catalog) : await every(read);
415
+ let all = rows.flatMap((b)=>{
416
+ let i = marked(b);
417
+ let at = b[PUBLISHED]?.at;
418
+ // A listing whose owner is gone is nobody's to keep, or take down; one
419
+ // a built integration stands in for is that one.
420
+ return !i.testing && !i.owner && (i.built || Array.isArray(i.categories) && !standIn(built, i.name)) || b[PUBLISHED] && i.owner ? [
421
+ {
422
+ ...i,
423
+ ...at ? {
424
+ published: at
425
+ } : {},
426
+ ...b.unchecked ? {
427
+ unchecked: true
428
+ } : {}
429
+ }
430
+ ] : [];
431
+ });
432
+ return all.filter((i)=>terms.every((t)=>text(i).includes(t))).sort((a, b)=>cmp((a.title || a.name).toLowerCase(), (b.title || b.name).toLowerCase()));
433
+ };
434
+ // A value in one order, so two that say the same thing compare equal: every
435
+ // object's properties sorted, and an absent one the same as a cleared one.
436
+ let canon = (v)=>Array.isArray(v) ? v.map(canon) : v && typeof v == 'object' ? Object.entries(v).filter(([, x])=>x != null).sort(([a], [b])=>cmp(a, b)).map(([k, x])=>[
437
+ k,
438
+ canon(x)
439
+ ]) : v;
440
+ let said = (v)=>JSON.stringify(canon(v));
441
+ // Catalog descriptions are maintained in the graph, independently of the
442
+ // operational seed definitions shipped by this package.
443
+ let EDITORIAL = [
444
+ 'title',
445
+ 'tagline',
446
+ 'site',
447
+ 'description',
448
+ 'details',
449
+ 'docs',
450
+ 'categories',
451
+ 'image'
452
+ ];
453
+ /**
454
+ * The batch that installs built integrations in a graph: each one missing
455
+ * there, or held otherwise than its seed says, with operational seed fields
456
+ * current and graph-authored catalog descriptions preserved, and marked `built`. Nothing, where every one
457
+ * already matches. A host applies it trusted, since `built` is server-owned,
458
+ * once at start-up. `seeds` defaults to this package's own.
459
+ */ export let install = (read, seeds = SEEDS)=>after(seeds.length ? read(line`.entity.eid=${seeds.map((i)=>integrationEid(i.name))}&.${INTEGRATION}`) : [], (found)=>{
460
+ let held = new Map(found.map((b)=>[
461
+ b.entity.eid,
462
+ b[INTEGRATION]
463
+ ]));
464
+ return seeds.flatMap((seed)=>{
465
+ let eid = integrationEid(seed.name);
466
+ let was = held.get(eid) ?? {};
467
+ let editorial = Object.fromEntries(EDITORIAL.filter((k)=>was[k] != null).map((k)=>[
468
+ k,
469
+ was[k]
470
+ ]));
471
+ let now = {
472
+ ...seed,
473
+ ...editorial,
474
+ built: true
475
+ };
476
+ let gone = Object.keys(was).filter((k)=>now[k] == null);
477
+ return said(was) == said(now) ? [] : [
478
+ {
479
+ entity: {
480
+ eid
481
+ },
482
+ [INTEGRATION]: {
483
+ ...Object.fromEntries(gone.map((k)=>[
484
+ k,
485
+ null
486
+ ])),
487
+ ...now
488
+ }
489
+ }
490
+ ];
491
+ });
492
+ });
493
+ //# sourceMappingURL=integrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrations.js","sources":["./integrations.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,6DAA6D;AAC7D,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,yEAAyE;AACzE,yEAAyE;AAEzE,SAAS,MAAM,EAAE,IAAI,EAAE,GAAG,2BAAgC;AAC1D,SAAS,KAAK,EAAE,GAAG,wBAA6B;AAEhD,SAAS,KAAK,kCAAuC;AAErD,SAAS,SAAS,kCAAuC;AACzD,SAAS,WAAW,EAAE,cAAc,wBAAuB;AAC3D,SAAqB,QAAQ,EAAE,GAAG,EAAE,WAAW,qBAAoB;AAEnE,SAAqB,QAAQ,EAAE,GAAG,GAAE;AACpC,OAAO,eAAe,wBAAwB;EAAE,MAAM;AAAO,EAAC;AAC9D,OAAO,WAAW,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACtD,OAAO,WAAW,oBAAoB;EA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