@netlify/config 20.5.2 → 20.6.1

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.
@@ -1,3 +1,4 @@
1
+ import fetch from 'node-fetch';
1
2
  import { getEnvelope } from '../env/envelope.js';
2
3
  import { throwUserError } from '../error.js';
3
4
  import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
@@ -8,21 +9,23 @@ import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
8
9
  // Requires knowing the `siteId` and having the access `token`.
9
10
  // Silently ignore API errors. For example the network connection might be down,
10
11
  // but local builds should still work regardless.
11
- export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, testOpts: { env: testEnv = true } = {}, }) {
12
+ export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, featureFlags = {}, testOpts = {}, }) {
13
+ const { env: testEnv = true } = testOpts;
12
14
  if (api === undefined || mode === 'buildbot' || !testEnv) {
13
15
  const siteInfo = siteId === undefined ? {} : { id: siteId };
14
16
  return { siteInfo, accounts: [], addons: [] };
15
17
  }
16
- const [siteInfo, accounts, addons] = await Promise.all([
17
- getSite(api, siteId, siteFeatureFlagPrefix),
18
- getAccounts(api),
19
- getAddons(api, siteId),
20
- ]);
18
+ const fetchIntegrations = featureFlags.buildbot_fetch_integrations;
19
+ const promises = [getSite(api, siteId, siteFeatureFlagPrefix), getAccounts(api), getAddons(api, siteId)];
20
+ if (fetchIntegrations) {
21
+ promises.push(getIntegrations({ api, ownerType: 'site', ownerId: siteId, testOpts }));
22
+ }
23
+ const [siteInfo, accounts, addons, integrations = []] = await Promise.all(promises);
21
24
  if (siteInfo.use_envelope) {
22
25
  const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId });
23
26
  siteInfo.build_settings.env = envelope;
24
27
  }
25
- return { siteInfo, accounts, addons };
28
+ return { siteInfo, accounts, addons, integrations: integrations };
26
29
  };
27
30
  const getSite = async function (api, siteId, siteFeatureFlagPrefix = null) {
28
31
  if (siteId === undefined) {
@@ -57,3 +60,24 @@ const getAddons = async function (api, siteId) {
57
60
  throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
58
61
  }
59
62
  };
63
+ const getIntegrations = async function ({ api, ownerType, ownerId, testOpts }) {
64
+ if (ownerId === undefined) {
65
+ return [];
66
+ }
67
+ const { host } = testOpts;
68
+ const baseUrl = host ? `http://${host}` : `https://api.netlifysdk.com`;
69
+ try {
70
+ const token = api.accessToken;
71
+ const response = await fetch(`${baseUrl}/${ownerType}/${ownerId}/integrations`, {
72
+ headers: {
73
+ Authorization: `Bearer ${token}`,
74
+ },
75
+ });
76
+ const integrations = await response.json();
77
+ return Array.isArray(integrations) ? integrations : [];
78
+ }
79
+ catch (error) {
80
+ // for now, we'll just ignore errors, as this is early days
81
+ return [];
82
+ }
83
+ };
package/lib/main.js CHANGED
@@ -29,7 +29,14 @@ export const resolveConfig = async function (opts) {
29
29
  return parsedCachedConfig;
30
30
  }
31
31
  const { config: configOpt, defaultConfig, inlineConfig, configMutations, cwd, context, repositoryRoot, base, branch, siteId, deployId, buildId, baseRelDir, mode, debug, logs, featureFlags, } = await normalizeOpts(optsA);
32
- const { siteInfo, accounts, addons } = await getSiteInfo({ api, siteId, mode, testOpts, siteFeatureFlagPrefix });
32
+ const { siteInfo, accounts, addons, integrations } = await getSiteInfo({
33
+ api,
34
+ siteId,
35
+ mode,
36
+ testOpts,
37
+ siteFeatureFlagPrefix,
38
+ featureFlags,
39
+ });
33
40
  const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
34
41
  defaultConfig,
35
42
  base,
@@ -68,6 +75,7 @@ export const resolveConfig = async function (opts) {
68
75
  const configA = addLegacyFunctionsDirectory(config);
69
76
  const result = {
70
77
  siteInfo,
78
+ integrations,
71
79
  accounts,
72
80
  addons,
73
81
  env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/config",
3
- "version": "20.5.2",
3
+ "version": "20.6.1",
4
4
  "description": "Netlify config module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -70,9 +70,10 @@
70
70
  "is-plain-obj": "^4.0.0",
71
71
  "js-yaml": "^4.0.0",
72
72
  "map-obj": "^5.0.0",
73
- "netlify": "^13.1.9",
73
+ "netlify": "^13.1.10",
74
74
  "netlify-headers-parser": "^7.1.2",
75
75
  "netlify-redirect-parser": "^14.1.3",
76
+ "node-fetch": "^3.3.1",
76
77
  "omit.js": "^2.0.2",
77
78
  "p-locate": "^6.0.0",
78
79
  "path-type": "^5.0.0",
@@ -82,7 +83,7 @@
82
83
  "yargs": "^17.6.0"
83
84
  },
84
85
  "devDependencies": {
85
- "@types/node": "^18.14.2",
86
+ "@types/node": "^14.18.53",
86
87
  "ava": "^4.0.0",
87
88
  "c8": "^7.12.0",
88
89
  "has-ansi": "^5.0.0",
@@ -93,5 +94,5 @@
93
94
  "engines": {
94
95
  "node": "^14.16.0 || >=16.0.0"
95
96
  },
96
- "gitHead": "2bb08a1fb4ad1bca50cee1131b70cbd94a9f08a3"
97
+ "gitHead": "955ef6d9b44d9dd92cef78ba80b15f416044bfc9"
97
98
  }