@hubspot/local-dev-lib 1.0.0 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ import { PublicApp } from '../types/Apps';
2
+ export declare function fetchPublicAppsForPortal(accountId: number): Promise<Array<PublicApp>>;
package/api/appsDev.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchPublicAppsForPortal = void 0;
7
+ const http_1 = __importDefault(require("../http"));
8
+ const APPS_DEV_API_PATH = 'apps-dev/external/public/v3';
9
+ async function fetchPublicAppsForPortal(accountId) {
10
+ const resp = await http_1.default.get(accountId, {
11
+ url: `${APPS_DEV_API_PATH}/full/portal`,
12
+ });
13
+ return resp ? resp.results : [];
14
+ }
15
+ exports.fetchPublicAppsForPortal = fetchPublicAppsForPortal;
@@ -2,6 +2,7 @@ import { Environment } from '../types/Config';
2
2
  import { ScopeData } from '../types/Accounts';
3
3
  import { HUBSPOT_ACCOUNT_TYPES } from '../constants/config';
4
4
  import { ValueOf } from '../types/Utils';
5
+ import { PublicAppInstallationData } from '../types/Apps';
5
6
  type AccessTokenResponse = {
6
7
  hubId: number;
7
8
  userId: number;
@@ -17,4 +18,5 @@ type AccessTokenResponse = {
17
18
  };
18
19
  export declare function fetchAccessToken(personalAccessKey: string, env?: Environment, portalId?: number): Promise<AccessTokenResponse>;
19
20
  export declare function fetchScopeData(accountId: number, scopeGroup: string): Promise<ScopeData>;
21
+ export declare function fetchAppInstallationData(portalId: number, projectId: number, appUid: string, requiredScopeGroups: Array<string>, optionalScopeGroups?: Array<string>): Promise<PublicAppInstallationData>;
20
22
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchScopeData = exports.fetchAccessToken = void 0;
6
+ exports.fetchAppInstallationData = exports.fetchScopeData = exports.fetchAccessToken = void 0;
7
7
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
8
8
  const http_1 = __importDefault(require("../http"));
9
9
  const environments_1 = require("../constants/environments");
@@ -28,8 +28,21 @@ async function fetchAccessToken(personalAccessKey, env = environments_1.ENVIRONM
28
28
  exports.fetchAccessToken = fetchAccessToken;
29
29
  async function fetchScopeData(accountId, scopeGroup) {
30
30
  return http_1.default.get(accountId, {
31
- url: `localdevauth/v1/auth/check-scopes`,
31
+ url: `${LOCALDEVAUTH_API_AUTH_PATH}/check-scopes`,
32
32
  params: { scopeGroup },
33
33
  });
34
34
  }
35
35
  exports.fetchScopeData = fetchScopeData;
36
+ async function fetchAppInstallationData(portalId, projectId, appUid, requiredScopeGroups, optionalScopeGroups = []) {
37
+ return http_1.default.post(portalId, {
38
+ url: `${LOCALDEVAUTH_API_AUTH_PATH}/install-info`,
39
+ data: {
40
+ portalId,
41
+ projectId,
42
+ sourceId: appUid,
43
+ requiredScopeGroups,
44
+ optionalScopeGroups,
45
+ },
46
+ });
47
+ }
48
+ exports.fetchAppInstallationData = fetchAppInstallationData;
@@ -83,7 +83,7 @@ function throwValidationError(error) {
83
83
  function getAxiosErrorWithContext(
84
84
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
85
  error, context = {}) {
86
- const { status } = error;
86
+ const status = error.response?.status;
87
87
  const method = error.config?.method;
88
88
  const { projectName } = context;
89
89
  let messageDetail;
@@ -106,8 +106,8 @@ error, context = {}) {
106
106
  if ((method === 'put' || method === 'post') && context.payload) {
107
107
  errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
108
108
  }
109
- const isProjectMissingScopeError = isMissingScopeError(error) && projectName;
110
- const isProjectGatingError = isGatingError(error) && projectName;
109
+ const isProjectMissingScopeError = isMissingScopeError(error) && !!projectName;
110
+ const isProjectGatingError = isGatingError(error) && !!projectName;
111
111
  switch (status) {
112
112
  case 400:
113
113
  errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -0,0 +1,42 @@
1
+ export type PublicAppInstallationData = {
2
+ appId: number;
3
+ isInstalledWithScopeGroups: boolean;
4
+ previouslyAuthorizedScopeGroups: Array<{
5
+ id: number;
6
+ name: string;
7
+ }>;
8
+ };
9
+ export type PublicApp = {
10
+ id: number;
11
+ name: string;
12
+ description: string;
13
+ portalId: number;
14
+ updatedAt: number;
15
+ createdAt: number;
16
+ clientId: string;
17
+ iconUrl: string;
18
+ archived: boolean;
19
+ ownerId: number;
20
+ isUserLevel: boolean;
21
+ isBusinessUnitEnabled: boolean;
22
+ isFeatured: boolean;
23
+ isInternal: boolean;
24
+ documentationUrl: string | null;
25
+ supportUrl: string | null;
26
+ supportEmail: string | null;
27
+ supportPhone: string | null;
28
+ extensionIconUrl: string | null;
29
+ isAdvancedScopesSettingEnabled: boolean;
30
+ publicApplicationInstallCounts: {
31
+ uniquePortalInstallCount: number;
32
+ uniqueUserInstallCount: number;
33
+ uniqueBusinessUnitInstallCount: number;
34
+ };
35
+ redirectUrls: Array<string>;
36
+ scopeGroupIds: Array<number>;
37
+ additionalScopeGroupIds: Array<number>;
38
+ optionalScopeGroupIds: Array<number>;
39
+ projectId: number | null;
40
+ sourceId: string | null;
41
+ allowedExternalUrls: Array<string>;
42
+ };
package/types/Apps.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });