@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/mod.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/connections — the outside services a yaks graph can reach, and the
|
|
3
|
+
* links between a space or a person and one.
|
|
4
|
+
*
|
|
5
|
+
* An **integration** is an outside service as data: where a person signs in to
|
|
6
|
+
* it and where its codes are exchanged, for one reached by OAuth, the hosts
|
|
7
|
+
* its credential may be sent to, and how a page shows it. Every one is an
|
|
8
|
+
* `integration` entity in the graph: the built ones ship with this package as
|
|
9
|
+
* seed data, which a host installs at start-up ({@link install}), and a custom
|
|
10
|
+
* one is owned by the space or person that made it.
|
|
11
|
+
*
|
|
12
|
+
* A **connection** is one link through an integration, owned by a space or a
|
|
13
|
+
* person, and is also the secret its credential is kept as
|
|
14
|
+
* ({@link https://jsr.io/@yaks/secrets | @yaks/secrets}): the graph holds a
|
|
15
|
+
* handle, the vault holds the key or the tokens, and code that calls out is
|
|
16
|
+
* handed a sentinel. A `uses` link says which app calls out through which
|
|
17
|
+
* connection.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { need, connect, resolve } from '@yaks/connections'
|
|
21
|
+
*
|
|
22
|
+
* // an app says what it needs; the space sees it as needed
|
|
23
|
+
* // await g.apply(await need(g.read, { owner: space, app, integration: 'twilio' }))
|
|
24
|
+
* // the person pastes the key; it goes to the vault
|
|
25
|
+
* // await connect({ graph: g, vault }, connection, { key })
|
|
26
|
+
* // the app is handed what it calls out with
|
|
27
|
+
* // await resolve({ graph: g, vault }, app, 'twilio') → { connection, link, sentinel }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* An app may instead ask each person who uses it to connect their own
|
|
31
|
+
* (`each`): each person's connection is theirs, and only they call out
|
|
32
|
+
* through it.
|
|
33
|
+
*
|
|
34
|
+
* The verbs: {@link need}, {@link list} (the two tools), {@link attach} and
|
|
35
|
+
* {@link set} for a space owner through its host, {@link carry} for a copy of
|
|
36
|
+
* an app, {@link lend}, {@link recall} and {@link borrowed} for a connection
|
|
37
|
+
* lent to the copies, {@link using},
|
|
38
|
+
* {@link through},
|
|
39
|
+
* {@link begin} and {@link connect}, {@link disconnect}, {@link resolve},
|
|
40
|
+
* {@link used} and {@link envOf}, {@link credential}, {@link refresh}, and
|
|
41
|
+
* {@link call} for a call out by the one who holds the connection.
|
|
42
|
+
*
|
|
43
|
+
* A person's sources of tools (an MCP server, a connection sent requests
|
|
44
|
+
* through, an app service) are named by address, and an app reaches one only
|
|
45
|
+
* where the person granted it: {@link grant}, {@link granted},
|
|
46
|
+
* {@link grantees},
|
|
47
|
+
* {@link grantsOf}, {@link revoke} and {@link grantable}. A connection's own
|
|
48
|
+
* command is {@link requests} and {@link request}. A host
|
|
49
|
+
* that composes this package
|
|
50
|
+
* composes @yaks/secrets, over its vault, and @yaks/edge beside it; the egress
|
|
51
|
+
* that swaps sentinels is @yaks/egress.
|
|
52
|
+
*
|
|
53
|
+
* @module
|
|
54
|
+
*/ export { connectionsDoc } from "./vocab.js";
|
|
55
|
+
export { ABOUT, catalogHeld, catalogued, connectable, FEATURED, fieldsOf, install, installed, KEY, keyed, known, knownAll, knownIn, listing, PUBLISHED, seeds, set, standIn, told, visitorPolicy, visitorsAllowed } from "./integrations.js";
|
|
56
|
+
export { CONNECTION, INTEGRATION, integrationEid, USES } from "./identity.js";
|
|
57
|
+
export { connectionHistory } from "./history.js";
|
|
58
|
+
export { through } from "./graph.js";
|
|
59
|
+
export { configuredConnections, configuredSignIns } from "./sign-in.js";
|
|
60
|
+
export { clientOf, registered, registration } from "./clients.js";
|
|
61
|
+
export { BrokerError, brokerKey, brokerOf, BROKERS, exampleLogo, logoSources, nango } from "./brokers.js";
|
|
62
|
+
export { adopted, catalogKey, catalogue, find, initialLogo, isSvg, keyGuide, keyHelp, kind, kinds, offerOf } from "./catalog.js";
|
|
63
|
+
export { accountCredential, AccountError, accountOf, approve, attach, attachInstallation, begin, bindingOf, borrowed, botFrom, botOf, call, carry, chatConnections, connect, credential, decline, disconnect, envOf, keysOf, lacking, lapsedHold, lend, list, loginCredential, namesOf, need, opens, pick, recall, redeemInstallation, refresh, resolve, settle, signsInWith, toAccount, used, using } from "./connections.js";
|
|
64
|
+
export { authorize } from "./authorize.js";
|
|
65
|
+
export { REDIRECT, signins } from "./signin.js";
|
|
66
|
+
export { codeFor, codeIn, lettersFor } from "./signin-mail.js";
|
|
67
|
+
export { addressed, grant, grantable, granted, grantedTo, grantees, grantOf, grantsOf, revoke, serviceAt } from "./sources.js";
|
|
68
|
+
export { request, requestable, requests } from "./requests.js";
|
|
69
|
+
export { grantService, publishService, serviceAuthority, serviceName } from "./services.js";
|
|
70
|
+
//# sourceMappingURL=mod.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDC,GAED,SAAS,cAAc,qBAAoB;AAC3C,SACE,KAAK,EAGL,WAAW,EAEX,UAAU,EACV,WAAW,EACX,QAAQ,EAER,QAAQ,EAER,OAAO,EACP,SAAS,EAET,GAAG,EACH,KAAK,EACL,KAAK,EACL,QAAQ,EACR,OAAO,EAEP,OAAO,EAEP,SAAS,EAET,KAAK,EACL,GAAG,EACH,OAAO,EACP,IAAI,EAEJ,aAAa,EACb,eAAe,4BACS;AAC1B,SAAS,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,IAAI,wBAAuB;AAC7E,SAAS,iBAAiB,uBAAsB;AAChD,SAAS,OAAO,qBAAoB;AACpC,SAAS,qBAAqB,EAAE,iBAAiB,uBAAsB;AACvE,SACE,QAAQ,EAER,UAAU,EACV,YAAY,uBACO;AACrB,SAEE,WAAW,EACX,SAAS,EACT,QAAQ,EACR,OAAO,EACP,WAAW,EAIX,WAAW,EACX,KAAK,uBACc;AACrB,SACE,OAAO,EACP,UAAU,EACV,SAAS,EACT,IAAI,EACJ,WAAW,EACX,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,KAAK,EAEL,OAAO,uBACY;AACrB,SACE,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,OAAO,EACP,MAAM,EACN,kBAAkB,EAClB,KAAK,EACL,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,EACL,IAAI,EACJ,KAAK,EACL,eAAe,EACf,OAAO,EACP,UAAU,EAEV,OAAO,EACP,UAAU,EACV,KAAK,EAEL,MAAM,EACN,OAAO,EACP,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,eAAe,EACf,OAAO,EAEP,IAAI,EAEJ,KAAK,EAGL,IAAI,EACJ,MAAM,EACN,kBAAkB,EAClB,OAAO,EACP,OAAO,EAEP,MAAM,EACN,WAAW,EAEX,SAAS,EACT,IAAI,EACJ,KAAK,2BACkB;AAEzB,SAGE,SAAS,yBAIY;AACvB,SAAS,QAAQ,EAAgB,OAAO,sBAAqB;AAE7D,SAAS,OAAO,EAAE,MAAM,EAAE,UAAU,2BAA0B;AAE9D,SACE,SAAS,EACT,KAAK,EAEL,SAAS,EACT,OAAO,EACP,SAAS,EACT,QAAQ,EACR,OAAO,EACP,QAAQ,EAER,MAAM,EACN,SAAS,uBACU;AACrB,SAEE,OAAO,EACP,WAAW,EACX,QAAQ,wBAEY;AAEtB,SACE,YAAY,EACZ,cAAc,EAEd,gBAAgB,EAChB,WAAW,wBACS"}
|
package/mod.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/connections — the outside services a yaks graph can reach, and the
|
|
3
|
+
* links between a space or a person and one.
|
|
4
|
+
*
|
|
5
|
+
* An **integration** is an outside service as data: where a person signs in to
|
|
6
|
+
* it and where its codes are exchanged, for one reached by OAuth, the hosts
|
|
7
|
+
* its credential may be sent to, and how a page shows it. Every one is an
|
|
8
|
+
* `integration` entity in the graph: the built ones ship with this package as
|
|
9
|
+
* seed data, which a host installs at start-up ({@link install}), and a custom
|
|
10
|
+
* one is owned by the space or person that made it.
|
|
11
|
+
*
|
|
12
|
+
* A **connection** is one link through an integration, owned by a space or a
|
|
13
|
+
* person, and is also the secret its credential is kept as
|
|
14
|
+
* ({@link https://jsr.io/@yaks/secrets | @yaks/secrets}): the graph holds a
|
|
15
|
+
* handle, the vault holds the key or the tokens, and code that calls out is
|
|
16
|
+
* handed a sentinel. A `uses` link says which app calls out through which
|
|
17
|
+
* connection.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { need, connect, resolve } from '@yaks/connections'
|
|
21
|
+
*
|
|
22
|
+
* // an app says what it needs; the space sees it as needed
|
|
23
|
+
* // await g.apply(await need(g.read, { owner: space, app, integration: 'twilio' }))
|
|
24
|
+
* // the person pastes the key; it goes to the vault
|
|
25
|
+
* // await connect({ graph: g, vault }, connection, { key })
|
|
26
|
+
* // the app is handed what it calls out with
|
|
27
|
+
* // await resolve({ graph: g, vault }, app, 'twilio') → { connection, link, sentinel }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* An app may instead ask each person who uses it to connect their own
|
|
31
|
+
* (`each`): each person's connection is theirs, and only they call out
|
|
32
|
+
* through it.
|
|
33
|
+
*
|
|
34
|
+
* The verbs: {@link need}, {@link list} (the two tools), {@link attach} and
|
|
35
|
+
* {@link set} for a space owner through its host, {@link carry} for a copy of
|
|
36
|
+
* an app, {@link lend}, {@link recall} and {@link borrowed} for a connection
|
|
37
|
+
* lent to the copies, {@link using},
|
|
38
|
+
* {@link through},
|
|
39
|
+
* {@link begin} and {@link connect}, {@link disconnect}, {@link resolve},
|
|
40
|
+
* {@link used} and {@link envOf}, {@link credential}, {@link refresh}, and
|
|
41
|
+
* {@link call} for a call out by the one who holds the connection.
|
|
42
|
+
*
|
|
43
|
+
* A person's sources of tools (an MCP server, a connection sent requests
|
|
44
|
+
* through, an app service) are named by address, and an app reaches one only
|
|
45
|
+
* where the person granted it: {@link grant}, {@link granted},
|
|
46
|
+
* {@link grantees},
|
|
47
|
+
* {@link grantsOf}, {@link revoke} and {@link grantable}. A connection's own
|
|
48
|
+
* command is {@link requests} and {@link request}. A host
|
|
49
|
+
* that composes this package
|
|
50
|
+
* composes @yaks/secrets, over its vault, and @yaks/edge beside it; the egress
|
|
51
|
+
* that swaps sentinels is @yaks/egress.
|
|
52
|
+
*
|
|
53
|
+
* @module
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export { connectionsDoc } from './vocab.js'
|
|
57
|
+
export {
|
|
58
|
+
ABOUT,
|
|
59
|
+
type About,
|
|
60
|
+
type Catalog,
|
|
61
|
+
catalogHeld,
|
|
62
|
+
type CatalogKept,
|
|
63
|
+
catalogued,
|
|
64
|
+
connectable,
|
|
65
|
+
FEATURED,
|
|
66
|
+
type Field,
|
|
67
|
+
fieldsOf,
|
|
68
|
+
type HeldCatalog,
|
|
69
|
+
install,
|
|
70
|
+
installed,
|
|
71
|
+
type Integration,
|
|
72
|
+
KEY,
|
|
73
|
+
keyed,
|
|
74
|
+
known,
|
|
75
|
+
knownAll,
|
|
76
|
+
knownIn,
|
|
77
|
+
type Listed,
|
|
78
|
+
listing,
|
|
79
|
+
type Marked,
|
|
80
|
+
PUBLISHED,
|
|
81
|
+
type Read,
|
|
82
|
+
seeds,
|
|
83
|
+
set,
|
|
84
|
+
standIn,
|
|
85
|
+
told,
|
|
86
|
+
type VisitorPolicy,
|
|
87
|
+
visitorPolicy,
|
|
88
|
+
visitorsAllowed,
|
|
89
|
+
} from './integrations.js'
|
|
90
|
+
export { CONNECTION, INTEGRATION, integrationEid, USES } from './identity.js'
|
|
91
|
+
export { connectionHistory } from './history.js'
|
|
92
|
+
export { through } from './graph.js'
|
|
93
|
+
export { configuredConnections, configuredSignIns } from './sign-in.js'
|
|
94
|
+
export {
|
|
95
|
+
clientOf,
|
|
96
|
+
type Registered,
|
|
97
|
+
registered,
|
|
98
|
+
registration,
|
|
99
|
+
} from './clients.js'
|
|
100
|
+
export {
|
|
101
|
+
type Broker,
|
|
102
|
+
BrokerError,
|
|
103
|
+
brokerKey,
|
|
104
|
+
brokerOf,
|
|
105
|
+
BROKERS,
|
|
106
|
+
exampleLogo,
|
|
107
|
+
type Found,
|
|
108
|
+
type Grant,
|
|
109
|
+
type Listing,
|
|
110
|
+
logoSources,
|
|
111
|
+
nango,
|
|
112
|
+
} from './brokers.js'
|
|
113
|
+
export {
|
|
114
|
+
adopted,
|
|
115
|
+
catalogKey,
|
|
116
|
+
catalogue,
|
|
117
|
+
find,
|
|
118
|
+
initialLogo,
|
|
119
|
+
isSvg,
|
|
120
|
+
keyGuide,
|
|
121
|
+
keyHelp,
|
|
122
|
+
kind,
|
|
123
|
+
kinds,
|
|
124
|
+
type Offer,
|
|
125
|
+
offerOf,
|
|
126
|
+
} from './catalog.js'
|
|
127
|
+
export {
|
|
128
|
+
accountCredential,
|
|
129
|
+
AccountError,
|
|
130
|
+
accountOf,
|
|
131
|
+
approve,
|
|
132
|
+
attach,
|
|
133
|
+
attachInstallation,
|
|
134
|
+
begin,
|
|
135
|
+
bindingOf,
|
|
136
|
+
borrowed,
|
|
137
|
+
botFrom,
|
|
138
|
+
botOf,
|
|
139
|
+
call,
|
|
140
|
+
carry,
|
|
141
|
+
chatConnections,
|
|
142
|
+
connect,
|
|
143
|
+
credential,
|
|
144
|
+
type Ctx,
|
|
145
|
+
decline,
|
|
146
|
+
disconnect,
|
|
147
|
+
envOf,
|
|
148
|
+
type Given,
|
|
149
|
+
keysOf,
|
|
150
|
+
lacking,
|
|
151
|
+
lapsedHold,
|
|
152
|
+
lend,
|
|
153
|
+
list,
|
|
154
|
+
loginCredential,
|
|
155
|
+
namesOf,
|
|
156
|
+
type Need,
|
|
157
|
+
need,
|
|
158
|
+
type NewSignIn,
|
|
159
|
+
opens,
|
|
160
|
+
type Owners,
|
|
161
|
+
type Path,
|
|
162
|
+
pick,
|
|
163
|
+
recall,
|
|
164
|
+
redeemInstallation,
|
|
165
|
+
refresh,
|
|
166
|
+
resolve,
|
|
167
|
+
type Resolved,
|
|
168
|
+
settle,
|
|
169
|
+
signsInWith,
|
|
170
|
+
type Status,
|
|
171
|
+
toAccount,
|
|
172
|
+
used,
|
|
173
|
+
using,
|
|
174
|
+
} from './connections.js'
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
type AuthAction,
|
|
178
|
+
type AuthOptions,
|
|
179
|
+
authorize,
|
|
180
|
+
type AuthReply,
|
|
181
|
+
type AuthTarget,
|
|
182
|
+
type Callback,
|
|
183
|
+
} from './authorize.js'
|
|
184
|
+
export { REDIRECT, type SignIns, signins } from './signin.js'
|
|
185
|
+
|
|
186
|
+
export { codeFor, codeIn, lettersFor } from './signin-mail.js'
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
addressed,
|
|
190
|
+
grant,
|
|
191
|
+
type Grantable,
|
|
192
|
+
grantable,
|
|
193
|
+
granted,
|
|
194
|
+
grantedTo,
|
|
195
|
+
grantees,
|
|
196
|
+
grantOf,
|
|
197
|
+
grantsOf,
|
|
198
|
+
type Kind,
|
|
199
|
+
revoke,
|
|
200
|
+
serviceAt,
|
|
201
|
+
} from './sources.js'
|
|
202
|
+
export {
|
|
203
|
+
type Answer,
|
|
204
|
+
request,
|
|
205
|
+
requestable,
|
|
206
|
+
requests,
|
|
207
|
+
type SourceCommand,
|
|
208
|
+
} from './requests.js'
|
|
209
|
+
|
|
210
|
+
export {
|
|
211
|
+
grantService,
|
|
212
|
+
publishService,
|
|
213
|
+
type ServiceAuthority,
|
|
214
|
+
serviceAuthority,
|
|
215
|
+
serviceName,
|
|
216
|
+
} from './services.js'
|
package/openai-api.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openai-api",
|
|
3
|
+
"visitors": "off",
|
|
4
|
+
"title": "OpenAI API",
|
|
5
|
+
"tagline": "OpenAI models on an API project key.",
|
|
6
|
+
"site": "https://platform.openai.com",
|
|
7
|
+
"hosts": [
|
|
8
|
+
"api.openai.com"
|
|
9
|
+
],
|
|
10
|
+
"instructions": "Open [API keys](https://platform.openai.com/api-keys) in the OpenAI project for this connection. Create a project key and paste it here.",
|
|
11
|
+
"example": "sk-proj-••••••••"
|
|
12
|
+
}
|
package/openai.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openai",
|
|
3
|
+
"visitors": "never",
|
|
4
|
+
"title": "OpenAI",
|
|
5
|
+
"tagline": "OpenAI models through your ChatGPT account.",
|
|
6
|
+
"site": "https://chatgpt.com",
|
|
7
|
+
"authorize": "https://auth.openai.com/oauth/authorize",
|
|
8
|
+
"token": "https://auth.openai.com/oauth/token",
|
|
9
|
+
"scopes": [
|
|
10
|
+
"openid",
|
|
11
|
+
"profile",
|
|
12
|
+
"email",
|
|
13
|
+
"offline_access",
|
|
14
|
+
"api.connectors.read",
|
|
15
|
+
"api.connectors.invoke"
|
|
16
|
+
],
|
|
17
|
+
"params": {
|
|
18
|
+
"id_token_add_organizations": "true",
|
|
19
|
+
"codex_cli_simplified_flow": "true",
|
|
20
|
+
"originator": "yaks_harness"
|
|
21
|
+
},
|
|
22
|
+
"refresh_encoding": "json",
|
|
23
|
+
"client_id": "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
24
|
+
"hosts": ["chatgpt.com"]
|
|
25
|
+
}
|
package/openrouter.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "openrouter",
|
|
3
|
+
"visitors": "never",
|
|
4
|
+
"title": "OpenRouter",
|
|
5
|
+
"tagline": "AI models from many makers, through one account.",
|
|
6
|
+
"site": "https://openrouter.ai",
|
|
7
|
+
"logo": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"#94A3B8\"><path d=\"M16.778 1.844v1.919q-.569-.026-1.138-.032-.708-.008-1.415.037c-1.93.126-4.023.728-6.149 2.237-2.911 2.066-2.731 1.95-4.14 2.75-.396.223-1.342.574-2.185.798-.841.225-1.753.333-1.751.333v4.229s.768.108 1.61.333c.842.224 1.789.575 2.185.799 1.41.798 1.228.683 4.14 2.75 2.126 1.509 4.22 2.11 6.148 2.236.88.058 1.716.041 2.555.005v1.918l7.222-4.168-7.222-4.17v2.176c-.86.038-1.611.065-2.278.021-1.364-.09-2.417-.357-3.979-1.465-2.244-1.593-2.866-2.027-3.68-2.508.889-.518 1.449-.906 3.822-2.59 1.56-1.109 2.614-1.377 3.978-1.466.667-.044 1.418-.017 2.278.02v2.176L24 6.014Z\"/></svg>",
|
|
8
|
+
"authorize": "https://openrouter.ai/auth",
|
|
9
|
+
"token": "https://openrouter.ai/api/v1/auth/keys",
|
|
10
|
+
"answers": "key",
|
|
11
|
+
"hosts": [
|
|
12
|
+
"openrouter.ai"
|
|
13
|
+
]
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/connections",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/connections",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./identity": {
|
|
12
|
+
"types": "./_dist/identity.d.ts",
|
|
13
|
+
"default": "./identity.js"
|
|
14
|
+
},
|
|
15
|
+
"./integrations": {
|
|
16
|
+
"types": "./_dist/integrations.d.ts",
|
|
17
|
+
"default": "./integrations.js"
|
|
18
|
+
},
|
|
19
|
+
"./vocab": {
|
|
20
|
+
"types": "./_dist/vocab.d.ts",
|
|
21
|
+
"default": "./vocab.js"
|
|
22
|
+
},
|
|
23
|
+
"./tools": {
|
|
24
|
+
"types": "./_dist/tools.d.ts",
|
|
25
|
+
"default": "./tools.js"
|
|
26
|
+
},
|
|
27
|
+
"./graph": {
|
|
28
|
+
"types": "./_dist/graph.d.ts",
|
|
29
|
+
"default": "./graph.js"
|
|
30
|
+
},
|
|
31
|
+
"./effects": {
|
|
32
|
+
"types": "./_dist/effects.d.ts",
|
|
33
|
+
"default": "./effects.js"
|
|
34
|
+
},
|
|
35
|
+
"./cli": {
|
|
36
|
+
"types": "./_dist/cli.d.ts",
|
|
37
|
+
"default": "./cli.js"
|
|
38
|
+
},
|
|
39
|
+
"./authorize-cli": {
|
|
40
|
+
"types": "./_dist/authorize_cli.d.ts",
|
|
41
|
+
"default": "./authorize_cli.js"
|
|
42
|
+
},
|
|
43
|
+
"./views": {
|
|
44
|
+
"types": "./_dist/views.d.ts",
|
|
45
|
+
"default": "./views.js"
|
|
46
|
+
},
|
|
47
|
+
"./form": {
|
|
48
|
+
"types": "./_dist/form.d.ts",
|
|
49
|
+
"default": "./form.js"
|
|
50
|
+
},
|
|
51
|
+
"./paste": {
|
|
52
|
+
"types": "./_dist/paste.d.ts",
|
|
53
|
+
"default": "./paste.js"
|
|
54
|
+
},
|
|
55
|
+
"./yaks-app": {
|
|
56
|
+
"types": "./_dist/yaks-app.d.ts",
|
|
57
|
+
"default": "./yaks-app.js"
|
|
58
|
+
},
|
|
59
|
+
"./mcp": {
|
|
60
|
+
"types": "./_dist/mcp.d.ts",
|
|
61
|
+
"default": "./mcp.js"
|
|
62
|
+
},
|
|
63
|
+
"./mcp-retirement": {
|
|
64
|
+
"types": "./_dist/mcp-retirement.d.ts",
|
|
65
|
+
"default": "./mcp-retirement.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"license": "Apache-2.0",
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@yaks/cli": "0.2.36",
|
|
71
|
+
"@yaks/edge": "0.2.36",
|
|
72
|
+
"@yaks/effects": "0.2.36",
|
|
73
|
+
"@yaks/fp": "0.2.36",
|
|
74
|
+
"@yaks/graph": "0.2.36",
|
|
75
|
+
"@yaks/hook": "0.2.36",
|
|
76
|
+
"@yaks/host": "0.2.36",
|
|
77
|
+
"@yaks/mcp-client": "0.2.36",
|
|
78
|
+
"@yaks/oauth": "0.2.36",
|
|
79
|
+
"@yaks/process": "0.2.36",
|
|
80
|
+
"@yaks/query": "0.2.36",
|
|
81
|
+
"@yaks/render": "0.2.36",
|
|
82
|
+
"@yaks/secrets": "0.2.36",
|
|
83
|
+
"@yaks/tools": "0.2.36",
|
|
84
|
+
"@yaks/ui": "0.2.36",
|
|
85
|
+
"@yaks/vocab": "0.2.36",
|
|
86
|
+
"@types/react": "19.3.0",
|
|
87
|
+
"react": "19.3.0"
|
|
88
|
+
},
|
|
89
|
+
"description": "Integrations and connections: the outside services a space can reach, the link between a space or a person and one, and the credential behind it, kept as a secret.",
|
|
90
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
91
|
+
}
|
package/paste.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A pasted key as the write that keeps it: the connection's secret given its
|
|
2
|
+
// value, which @yaks/secrets takes out of the write and seals in the vault,
|
|
3
|
+
// and the connection marked connected. `connect` writes it for trusted code,
|
|
4
|
+
// and a page writes it itself through the graph (./form.ts): both are this.
|
|
5
|
+
// It reads nothing, so a browser can make it from what it already holds.
|
|
6
|
+
import { CONNECTION } from "./identity.js";
|
|
7
|
+
/** What the vault keeps for a pasted credential: one field's value as it is,
|
|
8
|
+
* so one key is kept as it always was, and several as a JSON object by name. */ export let keptOf = (name, fields, given)=>{
|
|
9
|
+
let said = 'key' in given ? fields.length == 1 ? {
|
|
10
|
+
[fields[0].name]: given.key
|
|
11
|
+
} : {} : given.fields;
|
|
12
|
+
let extra = Object.keys(said).filter((k)=>!fields.some((f)=>f.name == k));
|
|
13
|
+
let missing = fields.filter((f)=>!said[f.name]);
|
|
14
|
+
if (extra.length || missing.length) {
|
|
15
|
+
throw new Error(`${name} is connected with ${fields.map((f)=>f.label).join(', ')}; ${missing.length ? `${missing.map((f)=>f.label).join(', ')} not given` : `it has no ${extra.join(', ')}`}`);
|
|
16
|
+
}
|
|
17
|
+
return fields.length == 1 ? said[fields[0].name] : JSON.stringify(Object.fromEntries(fields.map((f)=>[
|
|
18
|
+
f.name,
|
|
19
|
+
said[f.name]
|
|
20
|
+
])));
|
|
21
|
+
};
|
|
22
|
+
/** The write keeping `given` as connection `b`'s credential, through the
|
|
23
|
+
* integration `name` that asks for `fields`: its secret's value, and its
|
|
24
|
+
* status connected. */ export let pasted = (b, name, fields, given)=>({
|
|
25
|
+
entity: {
|
|
26
|
+
eid: b.entity.eid
|
|
27
|
+
},
|
|
28
|
+
secret: {
|
|
29
|
+
name: String(b.secret?.name),
|
|
30
|
+
value: keptOf(name, fields, given)
|
|
31
|
+
},
|
|
32
|
+
[CONNECTION]: {
|
|
33
|
+
status: 'connected'
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=paste.js.map
|
package/paste.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paste.js","sources":["./paste.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AAIzE,SAAS,UAAU,wBAAuB;AAK1C;8EAC8E,GAC9E,OAAO,IAAI,SAAS,CAClB,MACA,QACA;EAEA,IAAI,OAAO,SAAS,QAChB,OAAO,MAAM,IAAI,IAAI;IAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;EAAC,IAAI,CAAC,IACxD,MAAM,MAAM;EAChB,IAAI,QAAQ,OAAO,IAAI,CAAC,MAAM,MAAM,CAAC,CAAC,IAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAM,EAAE,IAAI,IAAI;EAC1E,IAAI,UAAU,OAAO,MAAM,CAAC,CAAC,IAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;EAChD,IAAI,MAAM,MAAM,IAAI,QAAQ,MAAM,EAAE;IAClC,MAAM,IAAI,MACR,GAAG,KAAK,mBAAmB,EAAE,OAAO,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,EACnE,QAAQ,MAAM,GACV,GAAG,QAAQ,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,UAAU,CAAC,GACrD,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,OAAO,EACnC;EAEN;EACA,OAAO,OAAO,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAC/D,OAAO,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC,IAAM;MAAC,EAAE,IAAI;MAAE,IAAI,CAAC,EAAE,IAAI,CAAC;KAAC;AAE/D,EAAC;AAED;;qBAEqB,GACrB,OAAO,IAAI,SAAS,CAClB,GACA,MACA,QACA,QACW,CAAC;IACZ,QAAQ;MAAE,KAAK,EAAE,MAAM,CAAC,GAAG;IAAC;IAC5B,QAAQ;MACN,MAAM,OAAQ,EAAE,MAAM,EAAoC;MAC1D,OAAO,OAAO,MAAM,QAAQ;IAC9B;IACA,CAAC,WAAW,EAAE;MAAE,QAAQ;IAAY;EACtC,CAAC,EAAC"}
|
package/paste.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// A pasted key as the write that keeps it: the connection's secret given its
|
|
2
|
+
// value, which @yaks/secrets takes out of the write and seals in the vault,
|
|
3
|
+
// and the connection marked connected. `connect` writes it for trusted code,
|
|
4
|
+
// and a page writes it itself through the graph (./form.ts): both are this.
|
|
5
|
+
// It reads nothing, so a browser can make it from what it already holds.
|
|
6
|
+
|
|
7
|
+
import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
|
|
8
|
+
import type { Field } from './field.ts'
|
|
9
|
+
import { CONNECTION } from './identity.js'
|
|
10
|
+
|
|
11
|
+
/** What a person gave: the one key, or each field by name. */
|
|
12
|
+
export type Pasted = { key: string } | { fields: Record<string, string> }
|
|
13
|
+
|
|
14
|
+
/** What the vault keeps for a pasted credential: one field's value as it is,
|
|
15
|
+
* so one key is kept as it always was, and several as a JSON object by name. */
|
|
16
|
+
export let keptOf = (
|
|
17
|
+
name: string,
|
|
18
|
+
fields: Field[],
|
|
19
|
+
given: Pasted,
|
|
20
|
+
): string => {
|
|
21
|
+
let said = 'key' in given
|
|
22
|
+
? fields.length == 1 ? { [fields[0].name]: given.key } : {}
|
|
23
|
+
: given.fields
|
|
24
|
+
let extra = Object.keys(said).filter((k) => !fields.some((f) => f.name == k))
|
|
25
|
+
let missing = fields.filter((f) => !said[f.name])
|
|
26
|
+
if (extra.length || missing.length) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`${name} is connected with ${fields.map((f) => f.label).join(', ')}; ${
|
|
29
|
+
missing.length
|
|
30
|
+
? `${missing.map((f) => f.label).join(', ')} not given`
|
|
31
|
+
: `it has no ${extra.join(', ')}`
|
|
32
|
+
}`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return fields.length == 1 ? said[fields[0].name] : JSON.stringify(
|
|
36
|
+
Object.fromEntries(fields.map((f) => [f.name, said[f.name]])),
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The write keeping `given` as connection `b`'s credential, through the
|
|
41
|
+
* integration `name` that asks for `fields`: its secret's value, and its
|
|
42
|
+
* status connected. */
|
|
43
|
+
export let pasted = (
|
|
44
|
+
b: Bundle,
|
|
45
|
+
name: string,
|
|
46
|
+
fields: Field[],
|
|
47
|
+
given: Pasted,
|
|
48
|
+
): Bundle => ({
|
|
49
|
+
entity: { eid: b.entity.eid },
|
|
50
|
+
secret: {
|
|
51
|
+
name: String((b.secret as { name?: string } | undefined)?.name),
|
|
52
|
+
value: keptOf(name, fields, given),
|
|
53
|
+
},
|
|
54
|
+
[CONNECTION]: { status: 'connected' },
|
|
55
|
+
})
|
package/requests.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// A connection as a source of tools: `connection:<connection>` offers one
|
|
2
|
+
// command, `request`, which sends an HTTPS request through the connection
|
|
3
|
+
// (`call`), its credential added on the way. So it reaches only the hosts its
|
|
4
|
+
// integration names, and its answer is the service's, never the credential.
|
|
5
|
+
//
|
|
6
|
+
// Who may send through which connection is the host's to say (`owners`): the
|
|
7
|
+
// person's own, the space's for its owner, an app's grants. A connection that
|
|
8
|
+
// is an MCP server's credential, or an app service's, is a source of its own
|
|
9
|
+
// kind already. A shared chat bot is read through its platform within the
|
|
10
|
+
// servers it serves. A workspace's own OAuth grant can be called here.
|
|
11
|
+
import { line } from "@yaks/query";
|
|
12
|
+
import { CallError } from "@yaks/tools/errors";
|
|
13
|
+
import { call } from "./connections.js";
|
|
14
|
+
import { CONNECTION } from "./identity.js";
|
|
15
|
+
import { known } from "./integrations.js";
|
|
16
|
+
let REQUEST = 'request';
|
|
17
|
+
let INPUT = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
method: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'The HTTP method; GET if omitted.'
|
|
23
|
+
},
|
|
24
|
+
url: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: 'The https URL, on one of the hosts the connection names.'
|
|
27
|
+
},
|
|
28
|
+
headers: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
additionalProperties: {
|
|
31
|
+
type: 'string'
|
|
32
|
+
},
|
|
33
|
+
description: 'Request headers. The credential is added on the way.'
|
|
34
|
+
},
|
|
35
|
+
body: {
|
|
36
|
+
description: 'The request body: text as it is, or JSON, sent with content-type application/json.'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
required: [
|
|
40
|
+
'url'
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
let comp = (b, name)=>b?.[name] ?? {};
|
|
44
|
+
let addressOf = (eid)=>`connection:${eid}`;
|
|
45
|
+
/** Whether a service can be called through a connection its owner holds. */ export let requestable = (i)=>!!i && !i.name.startsWith('mcp:') && !i.service && !i.broker?.scoped && (!i.chat || !!i.chat_grant) && i.hosts.length > 0;
|
|
46
|
+
// A connected source held by one of `owners`, with its integration.
|
|
47
|
+
let offered = async (read, b, owners)=>{
|
|
48
|
+
let c = comp(b, CONNECTION);
|
|
49
|
+
if (c.status != 'connected' || !owners.includes(String(c.owner)) || typeof c.integration != 'string' || c.integration.startsWith('mcp:')) return undefined;
|
|
50
|
+
let i = await known(read, c.integration);
|
|
51
|
+
return requestable(i) ? i : undefined;
|
|
52
|
+
};
|
|
53
|
+
let described = (b, i)=>{
|
|
54
|
+
let title = i.title || i.name;
|
|
55
|
+
let account = comp(b, CONNECTION).account;
|
|
56
|
+
return {
|
|
57
|
+
at: addressOf(b.entity.eid),
|
|
58
|
+
name: REQUEST,
|
|
59
|
+
title: `${title}: request`,
|
|
60
|
+
description: `Send an HTTPS request through the ${title} connection${account ? ` of ${account}` : ''}, its credential added on the way. It reaches ${i.hosts.join(', ')} and no other host.`,
|
|
61
|
+
readOnly: false,
|
|
62
|
+
input: INPUT
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** The `request` command of each connection `owners` hold, or of the ones
|
|
66
|
+
* among `only`. */ export let requests = async (read, owners, only)=>{
|
|
67
|
+
if (!owners.length || only?.length === 0) return [];
|
|
68
|
+
let held = await read(only ? line`.entity.eid=${only}&.${CONNECTION}&*` : line`.${CONNECTION}.owner=${owners}&.${CONNECTION}.status=${'connected'}&*`);
|
|
69
|
+
let found = await Promise.all(held.map((b)=>offered(read, b, owners)));
|
|
70
|
+
return held.flatMap((b, n)=>found[n] ? [
|
|
71
|
+
described(b, found[n])
|
|
72
|
+
] : []);
|
|
73
|
+
};
|
|
74
|
+
let object = (v)=>!!v && typeof v == 'object' && !Array.isArray(v);
|
|
75
|
+
// The request the arguments say, refused where they say none.
|
|
76
|
+
let methodOf = (i, url)=>{
|
|
77
|
+
if (!i.api?.reads?.length) return 'GET';
|
|
78
|
+
let base = new URL(i.api.base);
|
|
79
|
+
let at = URL.parse(url);
|
|
80
|
+
let prefix = base.pathname.replace(/\/$/, '');
|
|
81
|
+
if (at?.origin != base.origin || !at.pathname.startsWith(prefix + '/')) {
|
|
82
|
+
return 'GET';
|
|
83
|
+
}
|
|
84
|
+
let path = at.pathname.slice(prefix.length);
|
|
85
|
+
return i.api.reads.find((r)=>r.endsWith(' ' + path))?.split(' ')[0] ?? 'GET';
|
|
86
|
+
};
|
|
87
|
+
let asked = (i, args)=>{
|
|
88
|
+
if (typeof args.url != 'string') {
|
|
89
|
+
throw new CallError('arguments', 'request needs a url');
|
|
90
|
+
}
|
|
91
|
+
let method = typeof args.method == 'string' ? args.method.toUpperCase() : methodOf(i, args.url);
|
|
92
|
+
if (args.headers != null && !object(args.headers)) {
|
|
93
|
+
throw new CallError('arguments', 'headers is an object of strings');
|
|
94
|
+
}
|
|
95
|
+
let headers = new Headers(Object.entries(args.headers ?? {}).map(([k, v])=>[
|
|
96
|
+
k,
|
|
97
|
+
String(v)
|
|
98
|
+
]));
|
|
99
|
+
let body = args.body == null ? undefined : typeof args.body == 'string' ? args.body : JSON.stringify(args.body);
|
|
100
|
+
if (body != null && typeof args.body != 'string' && !headers.has('content-type')) {
|
|
101
|
+
headers.set('content-type', 'application/json');
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
return new Request(args.url, {
|
|
105
|
+
method,
|
|
106
|
+
headers,
|
|
107
|
+
body
|
|
108
|
+
});
|
|
109
|
+
} catch (e) {
|
|
110
|
+
throw new CallError('arguments', `request: ${e.message}`);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/** Run a connection's command for a caller that may send through what
|
|
114
|
+
* `owners` hold: the request, sent through `call`. */ export let request = async (c, a)=>{
|
|
115
|
+
let eid = a.at.slice('connection:'.length);
|
|
116
|
+
let [b] = eid ? await c.graph.read(line`.entity.eid=${eid}&.${CONNECTION}&*`) : [];
|
|
117
|
+
let i = b && await offered(c.graph.read, b, a.owners);
|
|
118
|
+
if (!i) {
|
|
119
|
+
throw new CallError('access', `${a.at} is not a connection you can use`);
|
|
120
|
+
}
|
|
121
|
+
if (a.name != REQUEST) {
|
|
122
|
+
throw new CallError('missing', `${i.title || i.name} has one command, request`);
|
|
123
|
+
}
|
|
124
|
+
let res = await call(c, eid, asked(i, a.args));
|
|
125
|
+
let headers = Object.fromEntries([
|
|
126
|
+
...res.headers
|
|
127
|
+
].filter(([k])=>k != 'set-cookie'));
|
|
128
|
+
return {
|
|
129
|
+
text: '',
|
|
130
|
+
value: {
|
|
131
|
+
status: res.status,
|
|
132
|
+
headers,
|
|
133
|
+
body: await res.text()
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=requests.js.map
|