@hubspot/local-dev-lib 0.0.1-experimental.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 (230) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -0
  6. package/api/customObjects.js +45 -0
  7. package/api/designManager.d.ts +5 -0
  8. package/api/designManager.js +18 -0
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +6 -0
  12. package/api/fileManager.js +63 -0
  13. package/api/fileMapper.d.ts +12 -0
  14. package/api/fileMapper.js +106 -0
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +8 -0
  18. package/api/functions.js +43 -0
  19. package/api/github.d.ts +11 -0
  20. package/api/github.js +71 -0
  21. package/api/hubdb.d.ts +12 -0
  22. package/api/hubdb.js +67 -0
  23. package/api/lighthouseScore.d.ts +6 -0
  24. package/api/lighthouseScore.js +26 -0
  25. package/api/localDevAuth.d.ts +8 -0
  26. package/api/localDevAuth.js +53 -0
  27. package/api/marketplaceValidation.d.ts +6 -0
  28. package/api/marketplaceValidation.js +26 -0
  29. package/api/projects.d.ts +40 -0
  30. package/api/projects.js +216 -0
  31. package/api/sandboxHubs.d.ts +7 -0
  32. package/api/sandboxHubs.js +49 -0
  33. package/api/sandboxSync.d.ts +4 -0
  34. package/api/sandboxSync.js +26 -0
  35. package/api/secrets.d.ts +6 -0
  36. package/api/secrets.js +37 -0
  37. package/api/validateHubl.d.ts +3 -0
  38. package/api/validateHubl.js +15 -0
  39. package/config/CLIConfiguration.d.ts +62 -0
  40. package/config/CLIConfiguration.js +467 -0
  41. package/config/configFile.d.ts +21 -0
  42. package/config/configFile.js +102 -0
  43. package/config/configUtils.d.ts +5 -0
  44. package/config/configUtils.js +87 -0
  45. package/config/config_DEPRECATED.d.ts +75 -0
  46. package/config/config_DEPRECATED.js +678 -0
  47. package/config/environment.d.ts +2 -0
  48. package/config/environment.js +60 -0
  49. package/config/getAccountIdentifier.d.ts +2 -0
  50. package/config/getAccountIdentifier.js +15 -0
  51. package/config/index.d.ts +41 -0
  52. package/config/index.js +260 -0
  53. package/constants/api.d.ts +15 -0
  54. package/constants/api.js +18 -0
  55. package/constants/auth.d.ts +37 -0
  56. package/constants/auth.js +38 -0
  57. package/constants/config.d.ts +18 -0
  58. package/constants/config.js +22 -0
  59. package/constants/environments.d.ts +15 -0
  60. package/constants/environments.js +18 -0
  61. package/constants/extensions.d.ts +6 -0
  62. package/constants/extensions.js +28 -0
  63. package/constants/files.d.ts +21 -0
  64. package/constants/files.js +24 -0
  65. package/constants/ports.d.ts +3 -0
  66. package/constants/ports.js +6 -0
  67. package/enums/build.d.ts +36 -0
  68. package/enums/build.js +39 -0
  69. package/enums/deploy.d.ts +11 -0
  70. package/enums/deploy.js +14 -0
  71. package/enums/project.d.ts +6 -0
  72. package/enums/project.js +9 -0
  73. package/errors/errors_DEPRECATED.d.ts +3 -0
  74. package/errors/errors_DEPRECATED.js +60 -0
  75. package/errors/index.d.ts +18 -0
  76. package/errors/index.js +63 -0
  77. package/http/addQueryParams.d.ts +2 -0
  78. package/http/addQueryParams.js +14 -0
  79. package/http/getAxiosConfig.d.ts +9 -0
  80. package/http/getAxiosConfig.js +66 -0
  81. package/http/index.d.ts +17 -0
  82. package/http/index.js +173 -0
  83. package/http/unauthed.d.ts +15 -0
  84. package/http/unauthed.js +38 -0
  85. package/lang/en.json +389 -0
  86. package/lib/archive.d.ts +3 -0
  87. package/lib/archive.js +117 -0
  88. package/lib/cms/functions.d.ts +8 -0
  89. package/lib/cms/functions.js +181 -0
  90. package/lib/cms/handleFieldsJS.d.ts +33 -0
  91. package/lib/cms/handleFieldsJS.js +148 -0
  92. package/lib/cms/modules.d.ts +14 -0
  93. package/lib/cms/modules.js +186 -0
  94. package/lib/cms/processFieldsJs.d.ts +1 -0
  95. package/lib/cms/processFieldsJs.js +97 -0
  96. package/lib/cms/templates.d.ts +65 -0
  97. package/lib/cms/templates.js +107 -0
  98. package/lib/cms/themes.d.ts +2 -0
  99. package/lib/cms/themes.js +34 -0
  100. package/lib/cms/uploadFolder.d.ts +7 -0
  101. package/lib/cms/uploadFolder.js +202 -0
  102. package/lib/cms/validate.d.ts +2 -0
  103. package/lib/cms/validate.js +40 -0
  104. package/lib/cms/watch.d.ts +4 -0
  105. package/lib/cms/watch.js +201 -0
  106. package/lib/customObjects.d.ts +5 -0
  107. package/lib/customObjects.js +42 -0
  108. package/lib/environment.d.ts +2 -0
  109. package/lib/environment.js +16 -0
  110. package/lib/escapeRegExp.d.ts +1 -0
  111. package/lib/escapeRegExp.js +7 -0
  112. package/lib/fileManager.d.ts +2 -0
  113. package/lib/fileManager.js +184 -0
  114. package/lib/fileMapper.d.ts +18 -0
  115. package/lib/fileMapper.js +317 -0
  116. package/lib/fs.d.ts +4 -0
  117. package/lib/fs.js +71 -0
  118. package/lib/github.d.ts +8 -0
  119. package/lib/github.js +167 -0
  120. package/lib/gitignore.d.ts +3 -0
  121. package/lib/gitignore.js +49 -0
  122. package/lib/hubdb.d.ts +17 -0
  123. package/lib/hubdb.js +133 -0
  124. package/lib/ignoreRules.d.ts +3 -0
  125. package/lib/ignoreRules.js +69 -0
  126. package/lib/logger.d.ts +56 -0
  127. package/lib/logger.js +146 -0
  128. package/lib/notify.d.ts +1 -0
  129. package/lib/notify.js +43 -0
  130. package/lib/oauth.d.ts +4 -0
  131. package/lib/oauth.js +34 -0
  132. package/lib/path.d.ts +14 -0
  133. package/lib/path.js +134 -0
  134. package/lib/personalAccessKey.d.ts +10 -0
  135. package/lib/personalAccessKey.js +163 -0
  136. package/lib/portManager.d.ts +10 -0
  137. package/lib/portManager.js +46 -0
  138. package/lib/text.d.ts +2 -0
  139. package/lib/text.js +24 -0
  140. package/lib/trackUsage.d.ts +1 -0
  141. package/lib/trackUsage.js +63 -0
  142. package/lib/urls.d.ts +2 -0
  143. package/lib/urls.js +24 -0
  144. package/models/FileSystemError.d.ts +6 -0
  145. package/models/FileSystemError.js +47 -0
  146. package/models/HubSpotHttpError.d.ts +24 -0
  147. package/models/HubSpotHttpError.js +197 -0
  148. package/models/OAuth2Manager.d.ts +12 -0
  149. package/models/OAuth2Manager.js +105 -0
  150. package/package.json +81 -0
  151. package/types/Accounts.d.ts +178 -0
  152. package/types/Accounts.js +2 -0
  153. package/types/Activity.d.ts +20 -0
  154. package/types/Activity.js +2 -0
  155. package/types/Api.d.ts +2 -0
  156. package/types/Api.js +2 -0
  157. package/types/Apps.d.ts +77 -0
  158. package/types/Apps.js +2 -0
  159. package/types/Archive.d.ts +9 -0
  160. package/types/Archive.js +2 -0
  161. package/types/Build.d.ts +41 -0
  162. package/types/Build.js +2 -0
  163. package/types/CLIOptions.d.ts +8 -0
  164. package/types/CLIOptions.js +2 -0
  165. package/types/ComponentStructure.d.ts +40 -0
  166. package/types/ComponentStructure.js +2 -0
  167. package/types/Config.d.ts +37 -0
  168. package/types/Config.js +2 -0
  169. package/types/Deploy.d.ts +42 -0
  170. package/types/Deploy.js +2 -0
  171. package/types/DesignManager.d.ts +10 -0
  172. package/types/DesignManager.js +2 -0
  173. package/types/Error.d.ts +37 -0
  174. package/types/Error.js +2 -0
  175. package/types/FieldsJS.d.ts +1 -0
  176. package/types/FieldsJS.js +2 -0
  177. package/types/FileManager.d.ts +71 -0
  178. package/types/FileManager.js +2 -0
  179. package/types/Files.d.ts +79 -0
  180. package/types/Files.js +2 -0
  181. package/types/Functions.d.ts +66 -0
  182. package/types/Functions.js +2 -0
  183. package/types/Github.d.ts +76 -0
  184. package/types/Github.js +2 -0
  185. package/types/Http.d.ts +29 -0
  186. package/types/Http.js +2 -0
  187. package/types/Hubdb.d.ts +109 -0
  188. package/types/Hubdb.js +2 -0
  189. package/types/HublValidation.d.ts +59 -0
  190. package/types/HublValidation.js +2 -0
  191. package/types/Lang.d.ts +10 -0
  192. package/types/Lang.js +2 -0
  193. package/types/Lighthouse.d.ts +25 -0
  194. package/types/Lighthouse.js +2 -0
  195. package/types/MarketplaceValidation.d.ts +28 -0
  196. package/types/MarketplaceValidation.js +2 -0
  197. package/types/Migration.d.ts +28 -0
  198. package/types/Migration.js +10 -0
  199. package/types/Modules.d.ts +16 -0
  200. package/types/Modules.js +2 -0
  201. package/types/PortManager.d.ts +11 -0
  202. package/types/PortManager.js +2 -0
  203. package/types/Project.d.ts +42 -0
  204. package/types/Project.js +2 -0
  205. package/types/ProjectLog.d.ts +9 -0
  206. package/types/ProjectLog.js +2 -0
  207. package/types/Sandbox.d.ts +155 -0
  208. package/types/Sandbox.js +2 -0
  209. package/types/Schemas.d.ts +39 -0
  210. package/types/Schemas.js +2 -0
  211. package/types/Secrets.d.ts +3 -0
  212. package/types/Secrets.js +2 -0
  213. package/types/Utils.d.ts +6 -0
  214. package/types/Utils.js +2 -0
  215. package/types/developerTestAccounts.d.ts +12 -0
  216. package/types/developerTestAccounts.js +2 -0
  217. package/utils/PortManagerServer.d.ts +26 -0
  218. package/utils/PortManagerServer.js +158 -0
  219. package/utils/accounts.d.ts +4 -0
  220. package/utils/accounts.js +28 -0
  221. package/utils/cms/fieldsJS.d.ts +2 -0
  222. package/utils/cms/fieldsJS.js +18 -0
  223. package/utils/cms/modules.d.ts +4 -0
  224. package/utils/cms/modules.js +54 -0
  225. package/utils/detectPort.d.ts +1 -0
  226. package/utils/detectPort.js +102 -0
  227. package/utils/git.d.ts +3 -0
  228. package/utils/git.js +71 -0
  229. package/utils/lang.d.ts +6 -0
  230. package/utils/lang.js +88 -0
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright 2019 HubSpot, Inc.
2
+ Licensed under the Apache License, Version 2.0 (the "License");
3
+ you may not use this file except in compliance with the License.
4
+ You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software
9
+ distributed under the License is distributed on an "AS IS" BASIS,
10
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ See the License for the specific language governing permissions and
12
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # hubspot/local-dev-lib
2
+
3
+ Provides library functionality for HubSpot local development tooling, including the [HubSpot CLI](https://github.com/HubSpot/hubspot-cli).
4
+
5
+ **NOTE:** This library is intended to replace the deprecated [@hubspot/cli-lib](https://github.com/HubSpot/cli-lib) library.
6
+
7
+ ## Overview
8
+
9
+ This library contains utils that facilitate interactions with HubSpot. It is consumed by the [HubSpot CLI](https://github.com/HubSpot/hubspot-cli) as well as other HubSpot development tooling. Major exports include:
10
+
11
+ - Config utils for managing HubSpot account configuration and access keys ([docs](./config/README.md))
12
+ - API utils to interact with HubSpot assets such as Design Manager and Developer Projects ([docs](./api/README.md))
13
+ - Utils to navigate the local filesystem, parse common HubSpot files, interact with common HubSpot objects, and connect with GitHub ([docs](./lib/README.md))
14
+
15
+ ## Contributing
16
+
17
+ For more information on developing, see the [Contributing Guide](CONTRIBUTING.md).
@@ -0,0 +1,6 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { PublicApp, PublicAppInstallCounts, PublicAppDeveloperTestAccountInstallData, FetchPublicAppsForPortalResponse } from '../types/Apps';
3
+ export declare function fetchPublicAppsForPortal(accountId: number): AxiosPromise<FetchPublicAppsForPortalResponse>;
4
+ export declare function fetchPublicAppDeveloperTestAccountInstallData(appId: number, accountId: number): AxiosPromise<PublicAppDeveloperTestAccountInstallData>;
5
+ export declare function fetchPublicAppProductionInstallCounts(appId: number, accountId: number): AxiosPromise<PublicAppInstallCounts>;
6
+ export declare function fetchPublicAppMetadata(appId: number, accountId: number): AxiosPromise<PublicApp>;
package/api/appsDev.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchPublicAppMetadata = exports.fetchPublicAppProductionInstallCounts = exports.fetchPublicAppDeveloperTestAccountInstallData = exports.fetchPublicAppsForPortal = void 0;
4
+ const http_1 = require("../http");
5
+ const APPS_DEV_API_PATH = 'apps-dev/external/public/v3';
6
+ function fetchPublicAppsForPortal(accountId) {
7
+ return http_1.http.get(accountId, {
8
+ url: `${APPS_DEV_API_PATH}/full/portal`,
9
+ });
10
+ }
11
+ exports.fetchPublicAppsForPortal = fetchPublicAppsForPortal;
12
+ function fetchPublicAppDeveloperTestAccountInstallData(appId, accountId) {
13
+ return http_1.http.get(accountId, {
14
+ url: `${APPS_DEV_API_PATH}/${appId}/test-portal-installs`,
15
+ });
16
+ }
17
+ exports.fetchPublicAppDeveloperTestAccountInstallData = fetchPublicAppDeveloperTestAccountInstallData;
18
+ function fetchPublicAppProductionInstallCounts(appId, accountId) {
19
+ return http_1.http.get(accountId, {
20
+ url: `${APPS_DEV_API_PATH}/${appId}/install-counts-without-test-portals`,
21
+ });
22
+ }
23
+ exports.fetchPublicAppProductionInstallCounts = fetchPublicAppProductionInstallCounts;
24
+ function fetchPublicAppMetadata(appId, accountId) {
25
+ return http_1.http.get(accountId, {
26
+ url: `${APPS_DEV_API_PATH}/${appId}/full`,
27
+ });
28
+ }
29
+ exports.fetchPublicAppMetadata = fetchPublicAppMetadata;
@@ -0,0 +1,8 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { FetchSchemasResponse, Schema, CreateObjectsResponse } from '../types/Schemas';
3
+ export declare function batchCreateObjects(accountId: number, objectTypeId: string, objects: JSON): AxiosPromise<CreateObjectsResponse>;
4
+ export declare function createObjectSchema(accountId: number, schema: JSON): AxiosPromise<Schema>;
5
+ export declare function updateObjectSchema(accountId: number, schemaObjectType: string, schema: Schema): AxiosPromise<Schema>;
6
+ export declare function fetchObjectSchema(accountId: number, schemaObjectType: string): AxiosPromise<Schema>;
7
+ export declare function fetchObjectSchemas(accountId: number): AxiosPromise<FetchSchemasResponse>;
8
+ export declare function deleteObjectSchema(accountId: number, schemaObjectType: string): AxiosPromise<void>;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteObjectSchema = exports.fetchObjectSchemas = exports.fetchObjectSchema = exports.updateObjectSchema = exports.createObjectSchema = exports.batchCreateObjects = void 0;
4
+ const http_1 = require("../http");
5
+ const CUSTOM_OBJECTS_API_PATH = 'crm/v3/objects';
6
+ const SCHEMA_API_PATH = 'crm-object-schemas/v3/schemas';
7
+ function batchCreateObjects(accountId, objectTypeId, objects) {
8
+ return http_1.http.post(accountId, {
9
+ url: `${CUSTOM_OBJECTS_API_PATH}/${objectTypeId}/batch/create`,
10
+ data: objects,
11
+ });
12
+ }
13
+ exports.batchCreateObjects = batchCreateObjects;
14
+ function createObjectSchema(accountId, schema) {
15
+ return http_1.http.post(accountId, {
16
+ url: SCHEMA_API_PATH,
17
+ data: schema,
18
+ });
19
+ }
20
+ exports.createObjectSchema = createObjectSchema;
21
+ function updateObjectSchema(accountId, schemaObjectType, schema) {
22
+ return http_1.http.patch(accountId, {
23
+ url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
24
+ data: schema,
25
+ });
26
+ }
27
+ exports.updateObjectSchema = updateObjectSchema;
28
+ function fetchObjectSchema(accountId, schemaObjectType) {
29
+ return http_1.http.get(accountId, {
30
+ url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
31
+ });
32
+ }
33
+ exports.fetchObjectSchema = fetchObjectSchema;
34
+ function fetchObjectSchemas(accountId) {
35
+ return http_1.http.get(accountId, {
36
+ url: SCHEMA_API_PATH,
37
+ });
38
+ }
39
+ exports.fetchObjectSchemas = fetchObjectSchemas;
40
+ function deleteObjectSchema(accountId, schemaObjectType) {
41
+ return http_1.http.delete(accountId, {
42
+ url: `${SCHEMA_API_PATH}/${schemaObjectType}`,
43
+ });
44
+ }
45
+ exports.deleteObjectSchema = deleteObjectSchema;
@@ -0,0 +1,5 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { QueryParams } from '../types/Http';
3
+ import { FetchThemesResponse, FetchBuiltinMappingResponse } from '../types/DesignManager';
4
+ export declare function fetchThemes(accountId: number, params?: QueryParams): AxiosPromise<FetchThemesResponse>;
5
+ export declare function fetchBuiltinMapping(accountId: number): AxiosPromise<FetchBuiltinMappingResponse>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchBuiltinMapping = exports.fetchThemes = void 0;
4
+ const http_1 = require("../http");
5
+ const DESIGN_MANAGER_API_PATH = 'designmanager/v1';
6
+ function fetchThemes(accountId, params = {}) {
7
+ return http_1.http.get(accountId, {
8
+ url: `${DESIGN_MANAGER_API_PATH}/themes/combined`,
9
+ params,
10
+ });
11
+ }
12
+ exports.fetchThemes = fetchThemes;
13
+ function fetchBuiltinMapping(accountId) {
14
+ return http_1.http.get(accountId, {
15
+ url: `${DESIGN_MANAGER_API_PATH}/widgets/builtin-mapping`,
16
+ });
17
+ }
18
+ exports.fetchBuiltinMapping = fetchBuiltinMapping;
@@ -0,0 +1,7 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { DeveloperTestAccount, FetchDeveloperTestAccountsResponse } from '../types/developerTestAccounts';
3
+ import { Environment } from '../types/Config';
4
+ export declare function fetchDeveloperTestAccounts(accountId: number): AxiosPromise<FetchDeveloperTestAccountsResponse>;
5
+ export declare function createDeveloperTestAccount(accountId: number, accountName: string): AxiosPromise<DeveloperTestAccount>;
6
+ export declare function deleteDeveloperTestAccount(accountId: number, testAccountId: number): AxiosPromise<void>;
7
+ export declare function fetchDeveloperTestAccountData(accessToken: string, accountId: number, env?: Environment): AxiosPromise<DeveloperTestAccount>;
@@ -0,0 +1,48 @@
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.fetchDeveloperTestAccountData = exports.deleteDeveloperTestAccount = exports.createDeveloperTestAccount = exports.fetchDeveloperTestAccounts = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const http_1 = require("../http");
9
+ const getAxiosConfig_1 = require("../http/getAxiosConfig");
10
+ const environments_1 = require("../constants/environments");
11
+ const api_1 = require("../constants/api");
12
+ const TEST_ACCOUNTS_API_PATH = 'integrators/test-portals/v2';
13
+ function fetchDeveloperTestAccounts(accountId) {
14
+ return http_1.http.get(accountId, {
15
+ url: TEST_ACCOUNTS_API_PATH,
16
+ });
17
+ }
18
+ exports.fetchDeveloperTestAccounts = fetchDeveloperTestAccounts;
19
+ function createDeveloperTestAccount(accountId, accountName) {
20
+ return http_1.http.post(accountId, {
21
+ url: TEST_ACCOUNTS_API_PATH,
22
+ data: { accountName, generatePersonalAccessKey: true },
23
+ timeout: api_1.SANDBOX_TIMEOUT,
24
+ });
25
+ }
26
+ exports.createDeveloperTestAccount = createDeveloperTestAccount;
27
+ function deleteDeveloperTestAccount(accountId, testAccountId) {
28
+ return http_1.http.delete(accountId, {
29
+ url: `${TEST_ACCOUNTS_API_PATH}/${testAccountId}`,
30
+ });
31
+ }
32
+ exports.deleteDeveloperTestAccount = deleteDeveloperTestAccount;
33
+ function fetchDeveloperTestAccountData(accessToken, accountId, env = environments_1.ENVIRONMENTS.PROD) {
34
+ const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
35
+ env,
36
+ url: `${TEST_ACCOUNTS_API_PATH}/self`,
37
+ params: { portalId: accountId },
38
+ });
39
+ const reqWithToken = {
40
+ ...axiosConfig,
41
+ headers: {
42
+ ...axiosConfig.headers,
43
+ Authorization: `Bearer ${accessToken}`,
44
+ },
45
+ };
46
+ return (0, axios_1.default)(reqWithToken);
47
+ }
48
+ exports.fetchDeveloperTestAccountData = fetchDeveloperTestAccountData;
@@ -0,0 +1,6 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { FetchStatResponse, FetchFilesResponse, FetchFolderResponse, UploadResponse } from '../types/FileManager';
3
+ export declare function uploadFile(accountId: number, src: string, dest: string): AxiosPromise<UploadResponse>;
4
+ export declare function fetchStat(accountId: number, src: string): AxiosPromise<FetchStatResponse>;
5
+ export declare function fetchFiles(accountId: number, folderId: number | 'None', offset: number, archived?: boolean): AxiosPromise<FetchFilesResponse>;
6
+ export declare function fetchFolders(accountId: number, folderId: number | 'None'): AxiosPromise<FetchFolderResponse>;
@@ -0,0 +1,63 @@
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.fetchFolders = exports.fetchFiles = exports.fetchStat = exports.uploadFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const http_1 = require("../http");
10
+ const FILE_MANAGER_V2_API_PATH = 'filemanager/api/v2';
11
+ const FILE_MANAGER_V3_API_PATH = 'filemanager/api/v3';
12
+ function uploadFile(accountId, src, dest) {
13
+ const directory = path_1.default.dirname(dest);
14
+ const filename = path_1.default.basename(dest);
15
+ const formData = {
16
+ file: fs_1.default.createReadStream(src),
17
+ fileName: filename,
18
+ options: JSON.stringify({
19
+ access: 'PUBLIC_INDEXABLE',
20
+ overwrite: true,
21
+ }),
22
+ };
23
+ if (directory && directory !== '.') {
24
+ formData.folderPath = directory;
25
+ }
26
+ else {
27
+ formData.folderPath = '/';
28
+ }
29
+ return http_1.http.post(accountId, {
30
+ url: `${FILE_MANAGER_V3_API_PATH}/files/upload`,
31
+ data: formData,
32
+ headers: { 'Content-Type': 'multipart/form-data' },
33
+ });
34
+ }
35
+ exports.uploadFile = uploadFile;
36
+ function fetchStat(accountId, src) {
37
+ return http_1.http.get(accountId, {
38
+ url: `${FILE_MANAGER_V2_API_PATH}/files/stat/${src}`,
39
+ });
40
+ }
41
+ exports.fetchStat = fetchStat;
42
+ function fetchFiles(accountId, folderId, offset, archived) {
43
+ return http_1.http.get(accountId, {
44
+ url: `${FILE_MANAGER_V2_API_PATH}/files/`,
45
+ params: {
46
+ hidden: 0,
47
+ offset: offset,
48
+ folder_id: folderId,
49
+ ...(!archived && { archived: 0 }),
50
+ },
51
+ });
52
+ }
53
+ exports.fetchFiles = fetchFiles;
54
+ function fetchFolders(accountId, folderId) {
55
+ return http_1.http.get(accountId, {
56
+ url: `${FILE_MANAGER_V2_API_PATH}/folders/`,
57
+ params: {
58
+ hidden: 0,
59
+ parent_folder_id: folderId,
60
+ },
61
+ });
62
+ }
63
+ exports.fetchFolders = fetchFolders;
@@ -0,0 +1,12 @@
1
+ import { AxiosResponse, AxiosPromise } from 'axios';
2
+ import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files';
3
+ export declare const FILE_MAPPER_API_PATH = "content/filemapper/v1";
4
+ export declare function createFileMapperNodeFromStreamResponse(filePath: string, response: Partial<AxiosResponse>): FileMapperNode;
5
+ export declare function upload(accountId: number, src: string, dest: string, options?: FileMapperOptions): AxiosPromise<void>;
6
+ export declare function fetchModule(accountId: number, moduleId: number, options?: FileMapperOptions): AxiosPromise<FileTree>;
7
+ export declare function fetchFileStream(accountId: number, filePath: string, destination: string, options?: FileMapperOptions): Promise<FileMapperNode>;
8
+ export declare function download(accountId: number, filepath: string, options?: FileMapperOptions): AxiosPromise<FileMapperNode>;
9
+ export declare function downloadDefault(accountId: number, filepath: string, options?: FileMapperOptions): AxiosPromise<FileMapperNode>;
10
+ export declare function deleteFile(accountId: number, filePath: string): AxiosPromise<void>;
11
+ export declare function moveFile(accountId: number, srcPath: string, destPath: string): AxiosPromise<void>;
12
+ export declare function getDirectoryContentsByPath(accountId: number, path: string): AxiosPromise<FileMapperNode>;
@@ -0,0 +1,106 @@
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.getDirectoryContentsByPath = exports.moveFile = exports.deleteFile = exports.downloadDefault = exports.download = exports.fetchFileStream = exports.fetchModule = exports.upload = exports.createFileMapperNodeFromStreamResponse = exports.FILE_MAPPER_API_PATH = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const content_disposition_1 = __importDefault(require("content-disposition"));
10
+ const http_1 = require("../http");
11
+ const path_2 = require("../lib/path");
12
+ exports.FILE_MAPPER_API_PATH = 'content/filemapper/v1';
13
+ function createFileMapperNodeFromStreamResponse(filePath, response) {
14
+ if (filePath[0] !== '/') {
15
+ filePath = `/${filePath}`;
16
+ }
17
+ if (filePath[filePath.length - 1] === '/') {
18
+ filePath = filePath.slice(0, filePath.length - 1);
19
+ }
20
+ const node = {
21
+ source: null,
22
+ path: filePath,
23
+ name: path_1.default.basename(filePath),
24
+ folder: false,
25
+ children: [],
26
+ createdAt: 0,
27
+ updatedAt: 0,
28
+ };
29
+ if (!(response.headers && response.headers['content-disposition'])) {
30
+ return node;
31
+ }
32
+ const { parameters } = content_disposition_1.default.parse(response.headers['content-disposition']);
33
+ return {
34
+ ...node,
35
+ name: parameters.filename,
36
+ createdAt: parseInt(parameters['creation-date'], 10) || 0,
37
+ updatedAt: parseInt(parameters['modification-date'], 10) || 0,
38
+ };
39
+ }
40
+ exports.createFileMapperNodeFromStreamResponse = createFileMapperNodeFromStreamResponse;
41
+ function upload(accountId, src, dest, options = {}) {
42
+ return http_1.http.post(accountId, {
43
+ url: `${exports.FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`,
44
+ data: {
45
+ file: fs_1.default.createReadStream(path_1.default.resolve((0, path_2.getCwd)(), src)),
46
+ },
47
+ headers: { 'Content-Type': 'multipart/form-data' },
48
+ ...options,
49
+ });
50
+ }
51
+ exports.upload = upload;
52
+ // Fetch a module by moduleId
53
+ function fetchModule(accountId, moduleId, options = {}) {
54
+ return http_1.http.get(accountId, {
55
+ url: `${exports.FILE_MAPPER_API_PATH}/modules/${moduleId}`,
56
+ ...options,
57
+ });
58
+ }
59
+ exports.fetchModule = fetchModule;
60
+ // Fetch a file by file path.
61
+ async function fetchFileStream(accountId, filePath, destination, options = {}) {
62
+ const response = await http_1.http.getOctetStream(accountId, {
63
+ url: `${exports.FILE_MAPPER_API_PATH}/stream/${encodeURIComponent(filePath)}`,
64
+ ...options,
65
+ }, destination);
66
+ return createFileMapperNodeFromStreamResponse(filePath, response);
67
+ }
68
+ exports.fetchFileStream = fetchFileStream;
69
+ // Fetch a folder or file node by path.
70
+ function download(accountId, filepath, options = {}) {
71
+ return http_1.http.get(accountId, {
72
+ url: `${exports.FILE_MAPPER_API_PATH}/download/${encodeURIComponent(filepath)}`,
73
+ ...options,
74
+ });
75
+ }
76
+ exports.download = download;
77
+ // Fetch a folder or file node by path.
78
+ function downloadDefault(accountId, filepath, options = {}) {
79
+ return http_1.http.get(accountId, {
80
+ url: `${exports.FILE_MAPPER_API_PATH}/download-default/${filepath}`,
81
+ ...options,
82
+ });
83
+ }
84
+ exports.downloadDefault = downloadDefault;
85
+ // Delete a file or folder by path
86
+ function deleteFile(accountId, filePath) {
87
+ return http_1.http.delete(accountId, {
88
+ url: `${exports.FILE_MAPPER_API_PATH}/delete/${encodeURIComponent(filePath)}`,
89
+ });
90
+ }
91
+ exports.deleteFile = deleteFile;
92
+ // Moves file from srcPath to destPath
93
+ function moveFile(accountId, srcPath, destPath) {
94
+ return http_1.http.put(accountId, {
95
+ url: `${exports.FILE_MAPPER_API_PATH}/rename/${srcPath}?path=${destPath}`,
96
+ headers: { 'Content-Type': 'application/json' },
97
+ });
98
+ }
99
+ exports.moveFile = moveFile;
100
+ // Get directory contents
101
+ function getDirectoryContentsByPath(accountId, path) {
102
+ return http_1.http.get(accountId, {
103
+ url: `${exports.FILE_MAPPER_API_PATH}/meta/${path}`,
104
+ });
105
+ }
106
+ exports.getDirectoryContentsByPath = getDirectoryContentsByPath;
@@ -0,0 +1,4 @@
1
+ import { AxiosPromise } from 'axios';
2
+ export declare function createSchemaFromHubFile(accountId: number, filepath: string): AxiosPromise;
3
+ export declare function updateSchemaFromHubFile(accountId: number, filepath: string): AxiosPromise;
4
+ export declare function fetchHubFileSchema(accountId: number, objectName: string, path: string): AxiosPromise;
@@ -0,0 +1,39 @@
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.fetchHubFileSchema = exports.updateSchemaFromHubFile = exports.createSchemaFromHubFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const path_2 = require("../lib/path");
10
+ const http_1 = require("../http");
11
+ const HUBFILES_API_PATH = '/file-transport/v1/hubfiles';
12
+ function createSchemaFromHubFile(accountId, filepath) {
13
+ const file = fs_1.default.createReadStream(path_1.default.resolve((0, path_2.getCwd)(), filepath));
14
+ return http_1.http.post(accountId, {
15
+ url: `${HUBFILES_API_PATH}/object-schemas`,
16
+ data: {
17
+ file,
18
+ },
19
+ headers: { 'Content-Type': 'multipart/form-data' },
20
+ });
21
+ }
22
+ exports.createSchemaFromHubFile = createSchemaFromHubFile;
23
+ async function updateSchemaFromHubFile(accountId, filepath) {
24
+ const file = fs_1.default.createReadStream(path_1.default.resolve((0, path_2.getCwd)(), filepath));
25
+ return http_1.http.put(accountId, {
26
+ url: `${HUBFILES_API_PATH}/object-schemas`,
27
+ data: {
28
+ file,
29
+ },
30
+ headers: { 'Content-Type': 'multipart/form-data' },
31
+ });
32
+ }
33
+ exports.updateSchemaFromHubFile = updateSchemaFromHubFile;
34
+ async function fetchHubFileSchema(accountId, objectName, path) {
35
+ return http_1.http.getOctetStream(accountId, {
36
+ url: `${HUBFILES_API_PATH}/object-schemas/${objectName}`,
37
+ }, path);
38
+ }
39
+ exports.fetchHubFileSchema = fetchHubFileSchema;
@@ -0,0 +1,8 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { QueryParams } from '../types/Http';
3
+ import { GetBuildStatusResponse, GetRoutesResponse } from '../types/Functions';
4
+ export declare function getRoutes(accountId: number): AxiosPromise<GetRoutesResponse>;
5
+ export declare function getFunctionLogs(accountId: number, route: string, params?: QueryParams): AxiosPromise;
6
+ export declare function getLatestFunctionLog(accountId: number, route: string): AxiosPromise;
7
+ export declare function buildPackage(accountId: number, folderPath: string): AxiosPromise<string>;
8
+ export declare function getBuildStatus(accountId: number, buildId: number): AxiosPromise<GetBuildStatusResponse>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBuildStatus = exports.buildPackage = exports.getLatestFunctionLog = exports.getFunctionLogs = exports.getRoutes = void 0;
4
+ const http_1 = require("../http");
5
+ const FUNCTION_API_PATH = 'cms/v3/functions';
6
+ function getRoutes(accountId) {
7
+ return http_1.http.get(accountId, {
8
+ url: `${FUNCTION_API_PATH}/routes`,
9
+ });
10
+ }
11
+ exports.getRoutes = getRoutes;
12
+ function getFunctionLogs(accountId, route, params = {}) {
13
+ const { limit = 5 } = params;
14
+ return http_1.http.get(accountId, {
15
+ url: `${FUNCTION_API_PATH}/results/by-route/${encodeURIComponent(route)}`,
16
+ params: { ...params, limit },
17
+ });
18
+ }
19
+ exports.getFunctionLogs = getFunctionLogs;
20
+ function getLatestFunctionLog(accountId, route) {
21
+ return http_1.http.get(accountId, {
22
+ url: `${FUNCTION_API_PATH}/results/by-route/${encodeURIComponent(route)}/latest`,
23
+ });
24
+ }
25
+ exports.getLatestFunctionLog = getLatestFunctionLog;
26
+ function buildPackage(accountId, folderPath) {
27
+ return http_1.http.post(accountId, {
28
+ url: `${FUNCTION_API_PATH}/build/async`,
29
+ headers: {
30
+ Accept: 'text/plain',
31
+ },
32
+ data: {
33
+ folderPath,
34
+ },
35
+ });
36
+ }
37
+ exports.buildPackage = buildPackage;
38
+ function getBuildStatus(accountId, buildId) {
39
+ return http_1.http.get(accountId, {
40
+ url: `${FUNCTION_API_PATH}/build/${buildId}/poll`,
41
+ });
42
+ }
43
+ exports.getBuildStatus = getBuildStatus;
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { AxiosPromise } from 'axios';
3
+ import { GithubReleaseData, GithubRepoFile, RepoPath } from '../types/Github';
4
+ declare global {
5
+ var githubToken: string;
6
+ }
7
+ export declare function fetchRepoReleaseData(repoPath: RepoPath, tag?: string): AxiosPromise<GithubReleaseData>;
8
+ export declare function fetchRepoAsZip(zipUrl: string): AxiosPromise<Buffer>;
9
+ export declare function fetchRepoFile(repoPath: RepoPath, filePath: string, ref: string): AxiosPromise<Buffer>;
10
+ export declare function fetchRepoFileByDownloadUrl(downloadUrl: string): AxiosPromise<Buffer>;
11
+ export declare function fetchRepoContents(repoPath: RepoPath, path: string, ref?: string): AxiosPromise<Array<GithubRepoFile>>;
package/api/github.js ADDED
@@ -0,0 +1,71 @@
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.fetchRepoContents = exports.fetchRepoFileByDownloadUrl = exports.fetchRepoFile = exports.fetchRepoAsZip = exports.fetchRepoReleaseData = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const getAxiosConfig_1 = require("../http/getAxiosConfig");
9
+ const GITHUB_REPOS_API = 'https://api.github.com/repos';
10
+ const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com';
11
+ function getAdditionalHeaders() {
12
+ const headers = {};
13
+ if (global && global.githubToken) {
14
+ headers.authorization = `Bearer ${global.githubToken}`;
15
+ }
16
+ else if (process.env.GITHUB_TOKEN) {
17
+ headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
18
+ }
19
+ return headers;
20
+ }
21
+ // Returns information about the repo's releases. Defaults to "latest" if no tag is provided
22
+ // https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-a-release-by-tag-name
23
+ function fetchRepoReleaseData(repoPath, tag = '') {
24
+ const URL = `${GITHUB_REPOS_API}/${repoPath}/releases`;
25
+ return axios_1.default.get(`${URL}/${tag ? `tags/${tag}` : 'latest'}`, {
26
+ headers: {
27
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
28
+ ...getAdditionalHeaders(),
29
+ },
30
+ });
31
+ }
32
+ exports.fetchRepoReleaseData = fetchRepoReleaseData;
33
+ // Returns the entire repo content as a zip, using the zipball_url from fetchRepoReleaseData()
34
+ // https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-zip
35
+ function fetchRepoAsZip(zipUrl) {
36
+ return axios_1.default.get(zipUrl, {
37
+ responseType: 'arraybuffer',
38
+ headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
39
+ });
40
+ }
41
+ exports.fetchRepoAsZip = fetchRepoAsZip;
42
+ // Returns the raw file contents via the raw.githubusercontent endpoint
43
+ function fetchRepoFile(repoPath, filePath, ref) {
44
+ return axios_1.default.get(`${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`, {
45
+ headers: {
46
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
47
+ ...getAdditionalHeaders(),
48
+ },
49
+ });
50
+ }
51
+ exports.fetchRepoFile = fetchRepoFile;
52
+ // Returns the raw file contents via the raw.githubusercontent endpoint
53
+ function fetchRepoFileByDownloadUrl(downloadUrl) {
54
+ return axios_1.default.get(downloadUrl, {
55
+ headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
56
+ responseType: 'arraybuffer',
57
+ });
58
+ }
59
+ exports.fetchRepoFileByDownloadUrl = fetchRepoFileByDownloadUrl;
60
+ // Returns the contents of a file or directory in a repository by path
61
+ // https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content
62
+ function fetchRepoContents(repoPath, path, ref) {
63
+ const refQuery = ref ? `?ref=${ref}` : '';
64
+ return axios_1.default.get(`${GITHUB_REPOS_API}/${repoPath}/contents/${path}${refQuery}`, {
65
+ headers: {
66
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
67
+ ...getAdditionalHeaders(),
68
+ },
69
+ });
70
+ }
71
+ exports.fetchRepoContents = fetchRepoContents;
package/api/hubdb.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { AxiosPromise } from 'axios';
2
+ import { QueryParams } from '../types/Http';
3
+ import { CreateRowsResponse, FetchRowsResponse, Row, Schema, Table, FetchTablesResponse } from '../types/Hubdb';
4
+ export declare function fetchTables(accountId: number): AxiosPromise<FetchTablesResponse>;
5
+ export declare function fetchTable(accountId: number, tableId: string): AxiosPromise<Table>;
6
+ export declare function createTable(accountId: number, schema: Schema): AxiosPromise<Table>;
7
+ export declare function updateTable(accountId: number, tableId: string, schema: Schema): AxiosPromise<Table>;
8
+ export declare function publishTable(accountId: number, tableId: string): AxiosPromise<Table>;
9
+ export declare function deleteTable(accountId: number, tableId: string): AxiosPromise<void>;
10
+ export declare function createRows(accountId: number, tableId: string, rows: Array<Row>): AxiosPromise<CreateRowsResponse>;
11
+ export declare function fetchRows(accountId: number, tableId: string, params?: QueryParams): AxiosPromise<FetchRowsResponse>;
12
+ export declare function deleteRows(accountId: number, tableId: string, rowIds: Array<string>): AxiosPromise<void>;