@netlify/config 20.12.6 → 20.13.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.
@@ -13,18 +13,37 @@ import { ERROR_CALL_TO_ACTION } from '../log/messages.js';
13
13
  */
14
14
  export const getSiteInfo = async function ({ api, siteId, mode, siteFeatureFlagPrefix, context, offline = false, testOpts = {}, }) {
15
15
  const { env: testEnv = false } = testOpts;
16
- if (api === undefined || mode === 'buildbot' || testEnv) {
16
+ if (api === undefined || testEnv || offline) {
17
17
  const siteInfo = siteId === undefined ? {} : { id: siteId };
18
- const integrations = mode === 'buildbot' && !offline ? await getIntegrations({ siteId, testOpts, offline }) : [];
18
+ return { siteInfo, accounts: [], addons: [], integrations: [] };
19
+ }
20
+ const siteInfo = await getSite(api, siteId, siteFeatureFlagPrefix);
21
+ const featureFlags = siteInfo.feature_flags;
22
+ const useV2Endpoint = featureFlags?.cli_integration_installations_meta;
23
+ if (useV2Endpoint) {
24
+ const promises = [
25
+ getAccounts(api),
26
+ getAddons(api, siteId),
27
+ getIntegrations({ siteId, testOpts, offline, accountId: siteInfo.account_id, featureFlags }),
28
+ ];
29
+ const [accounts, addons, integrations] = await Promise.all(promises);
30
+ if (siteInfo.use_envelope) {
31
+ const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context });
32
+ siteInfo.build_settings.env = envelope;
33
+ }
34
+ return { siteInfo, accounts, addons, integrations };
35
+ }
36
+ if (mode === 'buildbot') {
37
+ const siteInfo = siteId === undefined ? {} : { id: siteId };
38
+ const integrations = await getIntegrations({ siteId, testOpts, offline, featureFlags });
19
39
  return { siteInfo, accounts: [], addons: [], integrations };
20
40
  }
21
41
  const promises = [
22
- getSite(api, siteId, siteFeatureFlagPrefix),
23
42
  getAccounts(api),
24
43
  getAddons(api, siteId),
25
- getIntegrations({ siteId, testOpts, offline }),
44
+ getIntegrations({ siteId, testOpts, offline, featureFlags }),
26
45
  ];
27
- const [siteInfo, accounts, addons, integrations] = await Promise.all(promises);
46
+ const [accounts, addons, integrations] = await Promise.all(promises);
28
47
  if (siteInfo.use_envelope) {
29
48
  const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context });
30
49
  siteInfo.build_settings.env = envelope;
@@ -40,7 +59,7 @@ const getSite = async function (api, siteId, siteFeatureFlagPrefix = null) {
40
59
  return { ...site, id: siteId };
41
60
  }
42
61
  catch (error) {
43
- throwUserError(`Failed retrieving site data for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
62
+ return throwUserError(`Failed retrieving site data for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
44
63
  }
45
64
  };
46
65
  const getAccounts = async function (api) {
@@ -49,7 +68,7 @@ const getAccounts = async function (api) {
49
68
  return Array.isArray(accounts) ? accounts : [];
50
69
  }
51
70
  catch (error) {
52
- throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
71
+ return throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
53
72
  }
54
73
  };
55
74
  const getAddons = async function (api, siteId) {
@@ -61,22 +80,28 @@ const getAddons = async function (api, siteId) {
61
80
  return Array.isArray(addons) ? addons : [];
62
81
  }
63
82
  catch (error) {
64
- throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
83
+ return throwUserError(`Failed retrieving addons for site ${siteId}: ${error.message}. ${ERROR_CALL_TO_ACTION}`);
65
84
  }
66
85
  };
67
- const getIntegrations = async function ({ siteId, testOpts, offline, }) {
86
+ const getIntegrations = async function ({ siteId, accountId, testOpts, offline, featureFlags, }) {
68
87
  if (!siteId || offline) {
69
88
  return [];
70
89
  }
71
90
  const { host } = testOpts;
72
91
  const baseUrl = new URL(host ? `http://${host}` : `https://api.netlifysdk.com`);
92
+ const useV2Endpoint = featureFlags?.cli_integration_installations_meta;
93
+ const url = useV2Endpoint
94
+ ? `${baseUrl}team/${accountId}/integrations/installations/meta`
95
+ : `${baseUrl}site/${siteId}/integrations/safe`;
73
96
  try {
74
- const response = await fetch(`${baseUrl}site/${siteId}/integrations/safe`);
97
+ const response = await fetch(url);
75
98
  const integrations = await response.json();
76
99
  return Array.isArray(integrations) ? integrations : [];
77
100
  }
78
101
  catch (error) {
79
- // for now, we'll just ignore errors, as this is early days
102
+ // Integrations should not block the build if they fail to load
103
+ // TODO: We should consider blocking the build as integrations are a critical part of the build process
104
+ // https://linear.app/netlify/issue/CT-1214/implement-strategy-in-builds-to-deal-with-integrations-that-we-fail-to
80
105
  return [];
81
106
  }
82
107
  };
package/lib/main.js CHANGED
@@ -39,7 +39,6 @@ export const resolveConfig = async function (opts) {
39
39
  mode,
40
40
  offline,
41
41
  siteFeatureFlagPrefix,
42
- featureFlags,
43
42
  testOpts,
44
43
  });
45
44
  const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/config",
3
- "version": "20.12.6",
3
+ "version": "20.13.0",
4
4
  "description": "Netlify config module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -94,5 +94,5 @@
94
94
  "engines": {
95
95
  "node": "^14.16.0 || >=16.0.0"
96
96
  },
97
- "gitHead": "cb01c052b7d990ee7d1dffa03afbae70f2cfd71d"
97
+ "gitHead": "14419e3fd6fdeaba6d8f4460e5c13871db7f26ef"
98
98
  }