@wiro-ai/wiro-agent-connectors 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +1131 -34
  3. package/dist/cli.js +15 -12
  4. package/dist/core/credentials.d.ts +21 -0
  5. package/dist/core/credentials.js +45 -0
  6. package/dist/core/origins.d.ts +18 -0
  7. package/dist/core/origins.js +40 -0
  8. package/dist/core/upload-hosts.d.ts +15 -0
  9. package/dist/core/upload-hosts.js +43 -0
  10. package/dist/host/describe.d.ts +10 -0
  11. package/dist/host/describe.js +38 -0
  12. package/dist/host/env.d.ts +25 -2
  13. package/dist/host/env.js +24 -7
  14. package/dist/host/guarded-fetch.d.ts +36 -9
  15. package/dist/host/guarded-fetch.js +175 -52
  16. package/dist/host/index.d.ts +8 -5
  17. package/dist/host/index.js +12 -1
  18. package/dist/host/load.js +31 -1
  19. package/dist/host/server.d.ts +13 -2
  20. package/dist/host/server.js +15 -2
  21. package/dist/types.d.ts +96 -5
  22. package/dist/vendors/adapty.js +1303 -0
  23. package/dist/vendors/adjust.js +1372 -0
  24. package/dist/vendors/apollo.js +2499 -0
  25. package/dist/vendors/apple-appstore.js +2798 -0
  26. package/dist/vendors/beehiiv.js +1965 -0
  27. package/dist/vendors/blogger.js +1687 -0
  28. package/dist/vendors/bluesky.js +850 -127
  29. package/dist/vendors/brevo.js +2195 -0
  30. package/dist/vendors/calendarific.js +1116 -0
  31. package/dist/vendors/devto.js +685 -92
  32. package/dist/vendors/facebook-pages.js +2185 -0
  33. package/dist/vendors/firebase.js +1333 -0
  34. package/dist/vendors/ga4.js +1585 -0
  35. package/dist/vendors/gmail.js +1962 -0
  36. package/dist/vendors/google-ads.js +2201 -0
  37. package/dist/vendors/google-business.js +1621 -0
  38. package/dist/vendors/google-calendar.js +1936 -0
  39. package/dist/vendors/google-drive.js +2654 -0
  40. package/dist/vendors/google-merchant-center.js +1742 -0
  41. package/dist/vendors/google-play.js +1856 -0
  42. package/dist/vendors/google-search-console.js +1572 -0
  43. package/dist/vendors/hashnode.js +1722 -0
  44. package/dist/vendors/instagram.js +2249 -0
  45. package/dist/vendors/kaggle.js +2043 -0
  46. package/dist/vendors/keepa.js +2087 -0
  47. package/dist/vendors/linkedin.js +1588 -0
  48. package/dist/vendors/mailchimp.js +2402 -0
  49. package/dist/vendors/mastodon.js +1836 -0
  50. package/dist/vendors/meta-ads.js +2375 -0
  51. package/dist/vendors/notion.js +1950 -0
  52. package/dist/vendors/pinterest.js +1744 -0
  53. package/dist/vendors/qiita.js +1552 -0
  54. package/dist/vendors/reddit.js +1791 -0
  55. package/dist/vendors/revenuecat.js +1593 -0
  56. package/dist/vendors/roasit.js +1460 -0
  57. package/dist/vendors/sendgrid.js +2188 -0
  58. package/dist/vendors/serper.js +901 -179
  59. package/dist/vendors/shopify.js +2511 -0
  60. package/dist/vendors/threads.js +1869 -0
  61. package/dist/vendors/tiktok.js +2199 -0
  62. package/dist/vendors/tumblr.js +1793 -0
  63. package/dist/vendors/twitter.js +1650 -0
  64. package/dist/vendors/woocommerce.js +2258 -0
  65. package/dist/vendors/wordpress.js +1904 -0
  66. package/dist/vendors/youtube.js +2542 -0
  67. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3,25 +3,24 @@
3
3
  // wiro-agent-connectors <vendor>: serves one connector over stdio, with the
4
4
  // vendor's credentials read from the environment.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const describe_js_1 = require("./host/describe.js");
6
7
  const index_js_1 = require("./host/index.js");
7
8
  // The package version, for the MCP server info and --version.
8
9
  const { version } = require('../package.json');
9
10
  const USAGE = `Usage: wiro-agent-connectors <vendor>
10
11
 
11
12
  Serves one connector as an MCP server over stdio. Each connector reads its
12
- credentials from environment variables named <VENDOR>_<CREDENTIAL>.
13
+ credentials from environment variables named <VENDOR>_<CREDENTIAL>. To limit
14
+ the accounts its tools may act on, set CONNECTOR_ACCOUNTS to JSON such as
15
+ {"pages":["123"]}, keyed by the account keys --list prints.
13
16
 
14
17
  Options:
15
- --list List the connectors with their tools and environment variables
18
+ --list List the connectors with their tools, environment variables and account keys
16
19
  --version Print the version
17
20
  --help Print this help`;
18
21
  function describeVendors() {
19
22
  return (0, index_js_1.listVendors)()
20
- .map((vendor) => {
21
- const module = (0, index_js_1.loadConnector)(vendor);
22
- const env = module.credentials.map((name) => (0, index_js_1.envNameFor)(vendor, name)).join(', ');
23
- return `${vendor}\n env: ${env || '(none)'}\n tools: ${module.tools.map((tool) => tool.name).join(', ')}`;
24
- })
23
+ .map((vendor) => (0, describe_js_1.describeConnector)((0, index_js_1.loadConnector)(vendor)))
25
24
  .join('\n\n');
26
25
  }
27
26
  async function main(argv) {
@@ -49,17 +48,21 @@ async function main(argv) {
49
48
  process.exitCode = 1;
50
49
  return;
51
50
  }
52
- const { credentials, missing } = (0, index_js_1.credentialsFromEnv)(module, process.env);
51
+ const { credentials, needed } = (0, index_js_1.credentialsFromEnv)(module, process.env);
53
52
  const accounts = (0, index_js_1.accountsFromEnv)(process.env);
54
- if (missing.length) {
55
- process.stderr.write(`${module.vendor}: ${missing.join(' and ')} ${missing.length > 1 ? 'are' : 'is'} not set; tools will answer with an error until ${missing.length > 1 ? 'they are' : 'it is'}.\n`);
53
+ const [only] = needed;
54
+ if (needed.length === 1 && only) {
55
+ process.stderr.write(`${module.vendor}: ${(0, describe_js_1.describeNeeded)(needed)} ${only.length > 1 ? 'are' : 'is'} not set; tools will answer with an error until ${only.length > 1 ? 'they are' : 'it is'}.\n`);
56
+ }
57
+ else if (needed.length > 1) {
58
+ process.stderr.write(`${module.vendor}: set ${(0, describe_js_1.describeNeeded)(needed)}; tools will answer with an error until then.\n`);
56
59
  }
57
60
  await (0, index_js_1.serveStdio)(module, {
58
61
  credentials,
59
62
  accounts,
60
63
  version,
61
- ...(missing.length
62
- ? { missingCredentials: `This server has no credentials for ${module.vendor}: set ${missing.join(' and ')} in its environment and restart it.` }
64
+ ...(needed.length
65
+ ? { missingCredentials: `This server has no credentials for ${module.vendor}: set ${(0, describe_js_1.describeNeeded)(needed)} in its environment and restart it.` }
63
66
  : {}),
64
67
  });
65
68
  }
@@ -0,0 +1,21 @@
1
+ type Lists = ReadonlyArray<ReadonlyArray<string>>;
2
+ /**
3
+ * A module's alternatives: its requiredCredentials, or one list of every
4
+ * credential when it names none (a module built before they existed).
5
+ */
6
+ export declare function requiredAlternatives(module: {
7
+ credentials: readonly string[];
8
+ requiredCredentials?: Lists;
9
+ }): string[][];
10
+ /**
11
+ * What each alternative still lacks, or [] when one of them is complete. An
12
+ * alternative that lacks everything another one lacks, and more, is left out
13
+ * (and of two that lack the same, the first is kept), so each list returned
14
+ * is a smallest set of credentials that would complete the connection.
15
+ */
16
+ export declare function unmetAlternatives(alternatives: Lists, has: (name: string) => boolean): string[][];
17
+ /** "A", "A and B", "A, B and C". */
18
+ export declare function andList(items: readonly string[]): string;
19
+ /** "A", "A, or B", "A, B, or C": alternatives in plain words. */
20
+ export declare function orList(items: readonly string[]): string;
21
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ // Which credentials a call needs. A module may name them as alternatives
3
+ // (requiredCredentials): a call goes ahead when every credential of at least
4
+ // one list has a value. The core and the CLI host decide it with these
5
+ // helpers, so they agree on when a connector is connected. Web-standard
6
+ // globals only: the connector modules bundle this file, and the CLI host
7
+ // compiles it too.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.requiredAlternatives = requiredAlternatives;
10
+ exports.unmetAlternatives = unmetAlternatives;
11
+ exports.andList = andList;
12
+ exports.orList = orList;
13
+ /**
14
+ * A module's alternatives: its requiredCredentials, or one list of every
15
+ * credential when it names none (a module built before they existed).
16
+ */
17
+ function requiredAlternatives(module) {
18
+ return (module.requiredCredentials ?? [module.credentials]).map((list) => [...list]);
19
+ }
20
+ /**
21
+ * What each alternative still lacks, or [] when one of them is complete. An
22
+ * alternative that lacks everything another one lacks, and more, is left out
23
+ * (and of two that lack the same, the first is kept), so each list returned
24
+ * is a smallest set of credentials that would complete the connection.
25
+ */
26
+ function unmetAlternatives(alternatives, has) {
27
+ const lacking = alternatives.map((list) => list.filter((name) => !has(name)));
28
+ if (lacking.some((list) => list.length === 0))
29
+ return [];
30
+ return lacking.filter((list, index) => !lacking.some((other, otherIndex) => otherIndex !== index
31
+ && other.every((name) => list.includes(name))
32
+ && (other.length < list.length || otherIndex < index)));
33
+ }
34
+ /** "A", "A and B", "A, B and C". */
35
+ function andList(items) {
36
+ if (items.length <= 2)
37
+ return items.join(' and ');
38
+ return `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;
39
+ }
40
+ /** "A", "A, or B", "A, B, or C": alternatives in plain words. */
41
+ function orList(items) {
42
+ if (items.length <= 1)
43
+ return items.join('');
44
+ return `${items.slice(0, -1).join(', ')}, or ${items[items.length - 1]}`;
45
+ }
@@ -0,0 +1,18 @@
1
+ export type SiteUrl = {
2
+ ok: true;
3
+ url: URL;
4
+ origin: string;
5
+ } | {
6
+ ok: false;
7
+ problem: string;
8
+ };
9
+ /**
10
+ * Reads a site or instance URL from a credential value: "mastodon.social",
11
+ * "https://mastodon.social" and "https://example.com/blog/" are all accepted,
12
+ * and a value without a scheme gets https. It must be https and carry no user
13
+ * name or password. On failure, `problem` completes a sentence such as "the
14
+ * instance URL <problem>".
15
+ */
16
+ export declare function parseSiteUrl(value: string): SiteUrl;
17
+ /** The https origin of a site or instance URL, or undefined when parseSiteUrl refuses it. */
18
+ export declare function siteOrigin(value: string): string | undefined;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // Credential origins: a module may name credentials whose value is a site or
3
+ // instance URL (a Mastodon instance, a WordPress site, a shop). The core and
4
+ // every host turn such a value into an https origin with this one rule, so
5
+ // they agree on where a call may go. Web-standard globals only: the connector
6
+ // modules bundle this file, and the CLI host compiles it too.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.parseSiteUrl = parseSiteUrl;
9
+ exports.siteOrigin = siteOrigin;
10
+ /**
11
+ * Reads a site or instance URL from a credential value: "mastodon.social",
12
+ * "https://mastodon.social" and "https://example.com/blog/" are all accepted,
13
+ * and a value without a scheme gets https. It must be https and carry no user
14
+ * name or password. On failure, `problem` completes a sentence such as "the
15
+ * instance URL <problem>".
16
+ */
17
+ function parseSiteUrl(value) {
18
+ const text = typeof value === 'string' ? value.trim() : '';
19
+ if (!text)
20
+ return { ok: false, problem: 'is empty' };
21
+ let url;
22
+ try {
23
+ url = new URL(text.includes('://') ? text : `https://${text}`);
24
+ }
25
+ catch {
26
+ return { ok: false, problem: 'is not a valid address (expected one like https://example.com)' };
27
+ }
28
+ if (url.protocol !== 'https:')
29
+ return { ok: false, problem: `must be an https address, not ${url.protocol}//` };
30
+ if (url.username || url.password)
31
+ return { ok: false, problem: 'must not contain a user name or password' };
32
+ if (!url.hostname)
33
+ return { ok: false, problem: 'has no host name' };
34
+ return { ok: true, url, origin: url.origin };
35
+ }
36
+ /** The https origin of a site or instance URL, or undefined when parseSiteUrl refuses it. */
37
+ function siteOrigin(value) {
38
+ const site = parseSiteUrl(value);
39
+ return site.ok ? site.origin : undefined;
40
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What is wrong with an uploadHosts entry, completing a sentence such as
3
+ * "upload host X <problem>", or undefined when it is a good one: a lowercase
4
+ * host name of at least two labels ("uploads.example.com"), or the same with a
5
+ * leading dot for every host under it (".blobstore.apple.com").
6
+ */
7
+ export declare function uploadHostProblem(entry: unknown): string | undefined;
8
+ /**
9
+ * Whether a URL's host name is on one of a module's upload hosts. An entry
10
+ * with a leading dot matches every host under it (".blobstore.apple.com"
11
+ * matches store-030.blobstore.apple.com, never blobstore.apple.com itself or
12
+ * evil-blobstore.apple.com); any other entry matches that host only. The name
13
+ * is compared in lower case, without a trailing dot.
14
+ */
15
+ export declare function isUploadHost(hostname: string, uploadHosts: readonly string[]): boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // Upload hosts: a module may name the hosts its API's own upload addresses
3
+ // are on (pre-signed part addresses such as App Store Connect's
4
+ // store-030.blobstore.apple.com, which change per upload), in uploadHosts. The
5
+ // core checks the list when the module loads, and every host matches an
6
+ // address against it with this one rule. Web-standard globals only: the
7
+ // connector modules bundle this file, and the CLI host compiles it too.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.uploadHostProblem = uploadHostProblem;
10
+ exports.isUploadHost = isUploadHost;
11
+ /** One DNS label: lowercase letters, digits and inner hyphens, 1 to 63 characters. */
12
+ const LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
13
+ /**
14
+ * What is wrong with an uploadHosts entry, completing a sentence such as
15
+ * "upload host X <problem>", or undefined when it is a good one: a lowercase
16
+ * host name of at least two labels ("uploads.example.com"), or the same with a
17
+ * leading dot for every host under it (".blobstore.apple.com").
18
+ */
19
+ function uploadHostProblem(entry) {
20
+ if (typeof entry !== 'string')
21
+ return 'must be a host name';
22
+ const name = entry.startsWith('.') ? entry.slice(1) : entry;
23
+ const labels = name.split('.');
24
+ if (name.length > 253 || !labels.every((label) => LABEL.test(label))) {
25
+ return 'must be a lowercase host name like uploads.example.com, or one with a leading dot like .example.com for every host under it';
26
+ }
27
+ if (labels.length < 2)
28
+ return 'needs at least two labels, like example.com';
29
+ if (/^[0-9]+$/.test(labels[labels.length - 1]))
30
+ return 'must be a host name, not an IP address';
31
+ return undefined;
32
+ }
33
+ /**
34
+ * Whether a URL's host name is on one of a module's upload hosts. An entry
35
+ * with a leading dot matches every host under it (".blobstore.apple.com"
36
+ * matches store-030.blobstore.apple.com, never blobstore.apple.com itself or
37
+ * evil-blobstore.apple.com); any other entry matches that host only. The name
38
+ * is compared in lower case, without a trailing dot.
39
+ */
40
+ function isUploadHost(hostname, uploadHosts) {
41
+ const name = hostname.toLowerCase().replace(/\.$/, '');
42
+ return uploadHosts.some((entry) => (entry.startsWith('.') ? name.length > entry.length && name.endsWith(entry) : name === entry));
43
+ }
@@ -0,0 +1,10 @@
1
+ import type { ConnectorModule } from '../types.js';
2
+ /** The variables of each alternative in plain words: "A", "A and B", "A, or B". */
3
+ export declare function describeNeeded(needed: ReadonlyArray<ReadonlyArray<string>>): string;
4
+ /**
5
+ * A connector's entry in `--list`: its environment variables, which of them a
6
+ * call needs when that is not all of them, its tools, and its account pickers.
7
+ * The CLI maps no variable to a picker: accounts are chosen in
8
+ * CONNECTOR_ACCOUNTS, under the pickers' keys.
9
+ */
10
+ export declare function describeConnector(module: ConnectorModule): string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ // What `--list` prints for each connector, and how the CLI names the
3
+ // variables a connector still needs.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.describeNeeded = describeNeeded;
6
+ exports.describeConnector = describeConnector;
7
+ const credentials_js_1 = require("../core/credentials.js");
8
+ const env_js_1 = require("./env.js");
9
+ /** The variables of each alternative in plain words: "A", "A and B", "A, or B". */
10
+ function describeNeeded(needed) {
11
+ return (0, credentials_js_1.orList)(needed.map((list) => (0, credentials_js_1.andList)(list)));
12
+ }
13
+ /**
14
+ * A connector's entry in `--list`: its environment variables, which of them a
15
+ * call needs when that is not all of them, its tools, and its account pickers.
16
+ * The CLI maps no variable to a picker: accounts are chosen in
17
+ * CONNECTOR_ACCOUNTS, under the pickers' keys.
18
+ */
19
+ function describeConnector(module) {
20
+ const variables = (names) => names.map((name) => (0, env_js_1.envNameFor)(module.vendor, name));
21
+ const rows = [['env', [variables(module.credentials).join(', ') || '(none)']]];
22
+ const alternatives = (0, credentials_js_1.requiredAlternatives)(module);
23
+ const [only] = alternatives;
24
+ const all = alternatives.length === 1 && only !== undefined
25
+ && only.length === module.credentials.length && module.credentials.every((name) => only.includes(name));
26
+ if (!all) {
27
+ rows.push(['needs', [alternatives.some((list) => !list.length) ? 'nothing (every variable is optional)' : describeNeeded(alternatives.map(variables))]]);
28
+ }
29
+ rows.push(['tools', [module.tools.map((tool) => tool.name).join(', ')]]);
30
+ const pickers = module.accountPickers ?? [];
31
+ if (pickers.length) {
32
+ rows.push(['accounts', pickers.map((picker) => `${picker.key} (${picker.label}, ${picker.multiple ? 'one or more' : 'one'}, listed by ${picker.tool})`)]);
33
+ }
34
+ // Labels line up within an entry: "env: " and "tools: " as before, wider only with accounts.
35
+ const width = Math.max(...rows.map(([label]) => label.length)) + 2;
36
+ const lines = rows.flatMap(([label, values]) => values.map((value, index) => ` ${(index === 0 ? `${label}:` : '').padEnd(width)}${value}`));
37
+ return [module.vendor, ...lines].join('\n');
38
+ }
@@ -1,12 +1,35 @@
1
1
  import type { ConnectorAccounts, ConnectorModule } from '../types.js';
2
2
  /** The environment variable a credential is read from: <VENDOR>_<CREDENTIAL>, e.g. DEVTO_API_KEY. */
3
3
  export declare function envNameFor(vendor: string, credential: string): string;
4
+ /**
5
+ * The credential an OAuth connection's current access token arrives in. Hosts
6
+ * pass their current (refreshed) token there on every call; the CLI reads it
7
+ * from <VENDOR>_ACCESS_TOKEN and never refreshes it.
8
+ */
9
+ export declare const ACCESS_TOKEN_CREDENTIAL = "access_token";
4
10
  export interface EnvCredentials {
5
11
  credentials: Record<string, string>;
6
- /** The variables that are not set, e.g. ["DEVTO_API_KEY"]. */
12
+ /**
13
+ * The variables still to set before a call can go ahead, e.g.
14
+ * ["DEVTO_API_KEY"]; empty once one of the module's requiredCredentials
15
+ * lists is complete. With several lists, `needed` keeps them apart.
16
+ */
7
17
  missing: string[];
18
+ /**
19
+ * What each requiredCredentials list still lacks, e.g.
20
+ * [["META_ADS_ACCESS_TOKEN"], ["META_ADS_SYSTEM_USER_TOKEN"]]: setting the
21
+ * variables of any one of them is enough. Empty once a list is complete.
22
+ */
23
+ needed: string[][];
8
24
  }
9
- export declare function credentialsFromEnv(module: Pick<ConnectorModule, 'vendor' | 'credentials'>, env: NodeJS.ProcessEnv): EnvCredentials;
25
+ /**
26
+ * The credentials of a module from <VENDOR>_<CREDENTIAL> variables. Every
27
+ * declared credential is read; the module's requiredCredentials say which
28
+ * are needed (by default all of them). An OAuth access token is read from
29
+ * <VENDOR>_ACCESS_TOKEN into access_token even when the module does not
30
+ * declare it, as hosts pass a connection's token, and is then optional.
31
+ */
32
+ export declare function credentialsFromEnv(module: Pick<ConnectorModule, 'vendor' | 'credentials'> & Partial<Pick<ConnectorModule, 'requiredCredentials'>>, env: NodeJS.ProcessEnv): EnvCredentials;
10
33
  /** The variable that limits account-scoped arguments in the CLI. */
11
34
  export declare const ACCOUNTS_ENV = "CONNECTOR_ACCOUNTS";
12
35
  /**
package/dist/host/env.js CHANGED
@@ -1,25 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACCOUNTS_ENV = void 0;
3
+ exports.ACCOUNTS_ENV = exports.ACCESS_TOKEN_CREDENTIAL = void 0;
4
4
  exports.envNameFor = envNameFor;
5
5
  exports.credentialsFromEnv = credentialsFromEnv;
6
6
  exports.accountsFromEnv = accountsFromEnv;
7
+ const credentials_js_1 = require("../core/credentials.js");
7
8
  /** The environment variable a credential is read from: <VENDOR>_<CREDENTIAL>, e.g. DEVTO_API_KEY. */
8
9
  function envNameFor(vendor, credential) {
9
10
  return `${vendor}_${credential}`.toUpperCase().replace(/[^A-Z0-9]+/g, '_');
10
11
  }
12
+ /**
13
+ * The credential an OAuth connection's current access token arrives in. Hosts
14
+ * pass their current (refreshed) token there on every call; the CLI reads it
15
+ * from <VENDOR>_ACCESS_TOKEN and never refreshes it.
16
+ */
17
+ exports.ACCESS_TOKEN_CREDENTIAL = 'access_token';
18
+ /**
19
+ * The credentials of a module from <VENDOR>_<CREDENTIAL> variables. Every
20
+ * declared credential is read; the module's requiredCredentials say which
21
+ * are needed (by default all of them). An OAuth access token is read from
22
+ * <VENDOR>_ACCESS_TOKEN into access_token even when the module does not
23
+ * declare it, as hosts pass a connection's token, and is then optional.
24
+ */
11
25
  function credentialsFromEnv(module, env) {
12
26
  const credentials = {};
13
- const missing = [];
14
27
  for (const name of module.credentials) {
15
- const variable = envNameFor(module.vendor, name);
16
- const value = env[variable]?.trim();
28
+ const value = env[envNameFor(module.vendor, name)]?.trim();
17
29
  if (value)
18
30
  credentials[name] = value;
19
- else
20
- missing.push(variable);
21
31
  }
22
- return { credentials, missing };
32
+ if (!module.credentials.includes(exports.ACCESS_TOKEN_CREDENTIAL)) {
33
+ const token = env[envNameFor(module.vendor, exports.ACCESS_TOKEN_CREDENTIAL)]?.trim();
34
+ if (token)
35
+ credentials[exports.ACCESS_TOKEN_CREDENTIAL] = token;
36
+ }
37
+ const needed = (0, credentials_js_1.unmetAlternatives)((0, credentials_js_1.requiredAlternatives)(module), (name) => Boolean(credentials[name]))
38
+ .map((list) => list.map((name) => envNameFor(module.vendor, name)));
39
+ return { credentials, missing: [...new Set(needed.flat())], needed };
23
40
  }
24
41
  /** The variable that limits account-scoped arguments in the CLI. */
25
42
  exports.ACCOUNTS_ENV = 'CONNECTOR_ACCOUNTS';
@@ -1,4 +1,4 @@
1
- import type { ConnectorFetch } from '../types.js';
1
+ import type { ConnectorFetch, ConnectorModule } from '../types.js';
2
2
  export type ConnectorFetchErrorCode = 'URL_REFUSED' | 'TOO_LARGE' | 'TIMEOUT' | 'ABORTED' | 'NETWORK';
3
3
  export declare class ConnectorFetchError extends Error {
4
4
  readonly code: ConnectorFetchErrorCode;
@@ -8,33 +8,60 @@ export interface ResolvedAddress {
8
8
  address: string;
9
9
  family: number;
10
10
  }
11
- export interface MediaReply {
11
+ export interface PinnedReply {
12
12
  status: number;
13
13
  headers: Record<string, string | string[] | undefined>;
14
14
  body: AsyncIterable<Uint8Array>;
15
15
  destroy(): void;
16
16
  }
17
- /** One HTTPS request to an already checked address. */
18
- export type MediaTransport = (request: {
17
+ /** One HTTPS request to an address that was already checked: a media download, an upload, or an API request to a credential origin. */
18
+ export type PinnedTransport = (request: {
19
19
  url: URL;
20
20
  address: ResolvedAddress;
21
- method: 'GET' | 'HEAD';
21
+ method: string;
22
22
  headers: Record<string, string>;
23
+ body?: string | Uint8Array;
23
24
  signal: AbortSignal;
24
- }) => Promise<MediaReply>;
25
+ }) => Promise<PinnedReply>;
26
+ /** The names of 0.1.0. */
27
+ export type MediaReply = PinnedReply;
28
+ export type MediaTransport = PinnedTransport;
25
29
  export interface GuardedFetchOptions {
26
30
  /** The module's origins. */
27
31
  origins: readonly string[];
32
+ /**
33
+ * The https origins of this connection's originFields credentials (see
34
+ * originsFromCredentials). API requests may go there, after the SSRF checks.
35
+ */
36
+ credentialOrigins?: readonly string[];
37
+ /**
38
+ * The module's uploadHosts: a PUT or POST with a body may go to an address
39
+ * on one of them, after the checks of an upload (see isUploadHost).
40
+ */
41
+ uploadHosts?: readonly string[];
28
42
  /** Per request, API and media alike (default 30 s). */
29
43
  timeoutMs?: number;
30
- /** The largest API reply (default 8 MiB). */
44
+ /** The largest API reply (default 25 MiB, as large as a file a call hands back may be). */
31
45
  maxResponseBytes?: number;
32
46
  /** The largest media download (default 25 MiB). */
33
47
  maxMediaBytes?: number;
48
+ /** The largest body of an upload to an upload host (default 25 MiB). */
49
+ maxUploadBytes?: number;
34
50
  maxRedirects?: number;
35
- /** Replacements for tests: the API fetch, the DNS lookup and the media transport. */
51
+ /** Replacements for tests: the API fetch, the DNS lookup and the HTTPS transport to checked addresses. */
36
52
  apiFetch?: typeof fetch;
37
53
  resolve?: (hostname: string) => Promise<ResolvedAddress[]>;
38
- mediaTransport?: MediaTransport;
54
+ transport?: PinnedTransport;
55
+ /** The name of `transport` in 0.1.0. */
56
+ mediaTransport?: PinnedTransport;
39
57
  }
58
+ /**
59
+ * The https origins of a connection's originFields credentials, resolved with
60
+ * the rule the modules use (parseSiteUrl). A value that is not a usable site
61
+ * address is left out: the module refuses those calls itself, before sending.
62
+ * Pass the result to createGuardedFetch as credentialOrigins.
63
+ */
64
+ export declare function originsFromCredentials(module: Pick<ConnectorModule, 'originFields'> | {
65
+ originFields?: readonly string[];
66
+ }, credentials: Readonly<Record<string, string | undefined>>): string[];
40
67
  export declare function createGuardedFetch(options: GuardedFetchOptions): ConnectorFetch;