@hubspot/local-dev-lib 2.0.0 → 2.0.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.
- package/api/github.js +24 -8
- package/lib/cms/functions.d.ts +7 -1
- package/lib/cms/functions.js +4 -1
- package/package.json +1 -1
package/api/github.js
CHANGED
|
@@ -8,15 +8,25 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const getAxiosConfig_1 = require("../http/getAxiosConfig");
|
|
9
9
|
const GITHUB_REPOS_API = 'https://api.github.com/repos';
|
|
10
10
|
const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
14
21
|
// Returns information about the repo's releases. Defaults to "latest" if no tag is provided
|
|
15
22
|
// https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-a-release-by-tag-name
|
|
16
23
|
function fetchRepoReleaseData(repoPath, tag = '') {
|
|
17
24
|
const URL = `${GITHUB_REPOS_API}/${repoPath}/releases`;
|
|
18
25
|
return axios_1.default.get(`${URL}/${tag ? `tags/${tag}` : 'latest'}`, {
|
|
19
|
-
headers: {
|
|
26
|
+
headers: {
|
|
27
|
+
...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
|
|
28
|
+
...getAdditionalHeaders(),
|
|
29
|
+
},
|
|
20
30
|
});
|
|
21
31
|
}
|
|
22
32
|
exports.fetchRepoReleaseData = fetchRepoReleaseData;
|
|
@@ -25,21 +35,24 @@ exports.fetchRepoReleaseData = fetchRepoReleaseData;
|
|
|
25
35
|
function fetchRepoAsZip(zipUrl) {
|
|
26
36
|
return axios_1.default.get(zipUrl, {
|
|
27
37
|
responseType: 'arraybuffer',
|
|
28
|
-
headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...
|
|
38
|
+
headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
|
|
29
39
|
});
|
|
30
40
|
}
|
|
31
41
|
exports.fetchRepoAsZip = fetchRepoAsZip;
|
|
32
42
|
// Returns the raw file contents via the raw.githubusercontent endpoint
|
|
33
43
|
function fetchRepoFile(repoPath, filePath, ref) {
|
|
34
44
|
return axios_1.default.get(`${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`, {
|
|
35
|
-
headers: {
|
|
45
|
+
headers: {
|
|
46
|
+
...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
|
|
47
|
+
...getAdditionalHeaders(),
|
|
48
|
+
},
|
|
36
49
|
});
|
|
37
50
|
}
|
|
38
51
|
exports.fetchRepoFile = fetchRepoFile;
|
|
39
52
|
// Returns the raw file contents via the raw.githubusercontent endpoint
|
|
40
53
|
function fetchRepoFileByDownloadUrl(downloadUrl) {
|
|
41
54
|
return axios_1.default.get(downloadUrl, {
|
|
42
|
-
headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...
|
|
55
|
+
headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
|
|
43
56
|
responseType: 'arraybuffer',
|
|
44
57
|
});
|
|
45
58
|
}
|
|
@@ -49,7 +62,10 @@ exports.fetchRepoFileByDownloadUrl = fetchRepoFileByDownloadUrl;
|
|
|
49
62
|
function fetchRepoContents(repoPath, path, ref) {
|
|
50
63
|
const refQuery = ref ? `?ref=${ref}` : '';
|
|
51
64
|
return axios_1.default.get(`${GITHUB_REPOS_API}/${repoPath}/contents/${path}${refQuery}`, {
|
|
52
|
-
headers: {
|
|
65
|
+
headers: {
|
|
66
|
+
...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
|
|
67
|
+
...getAdditionalHeaders(),
|
|
68
|
+
},
|
|
53
69
|
});
|
|
54
70
|
}
|
|
55
71
|
exports.fetchRepoContents = fetchRepoContents;
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import { FunctionInfo, FunctionOptions } from '../../types/Functions';
|
|
1
|
+
import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
|
|
2
|
+
export declare function isObjectOrFunction(value: object): boolean;
|
|
3
|
+
export declare function createEndpoint(endpointMethod: string, filename: string): {
|
|
4
|
+
method: string;
|
|
5
|
+
file: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function createConfig({ endpointPath, endpointMethod, functionFile, }: FunctionConfigInfo): FunctionConfig;
|
|
2
8
|
export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions): Promise<void>;
|
package/lib/cms/functions.js
CHANGED
|
@@ -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.createFunction = void 0;
|
|
6
|
+
exports.createFunction = exports.createConfig = exports.createEndpoint = exports.isObjectOrFunction = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
@@ -17,12 +17,14 @@ function isObjectOrFunction(value) {
|
|
|
17
17
|
const type = typeof value;
|
|
18
18
|
return value != null && (type === 'object' || type === 'function');
|
|
19
19
|
}
|
|
20
|
+
exports.isObjectOrFunction = isObjectOrFunction;
|
|
20
21
|
function createEndpoint(endpointMethod, filename) {
|
|
21
22
|
return {
|
|
22
23
|
method: endpointMethod || 'GET',
|
|
23
24
|
file: filename,
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
exports.createEndpoint = createEndpoint;
|
|
26
28
|
function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
27
29
|
return {
|
|
28
30
|
runtime: 'nodejs18.x',
|
|
@@ -34,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
|
|
|
34
36
|
},
|
|
35
37
|
};
|
|
36
38
|
}
|
|
39
|
+
exports.createConfig = createConfig;
|
|
37
40
|
function writeConfig(configFilePath, config) {
|
|
38
41
|
const configJson = JSON.stringify(config, null, ' ');
|
|
39
42
|
fs_extra_1.default.writeFileSync(configFilePath, configJson);
|
package/package.json
CHANGED