backend-manager 4.0.19 → 4.0.20
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/package.json +1 -1
- package/src/cli/cli.js +1 -1
- package/src/manager/functions/core/actions/api/admin/write-repo-content.js +126 -0
- package/src/manager/functions/core/actions/api/handler/create-post.js +3 -3
- package/src/manager/functions/core/actions/api.js +4 -1
- package/src/manager/index.js +0 -3
package/package.json
CHANGED
package/src/cli/cli.js
CHANGED
|
@@ -239,7 +239,7 @@ Main.prototype.setup = async function () {
|
|
|
239
239
|
self.projectId = self.firebaseRC.projects.default;
|
|
240
240
|
self.projectUrl = `https://console.firebase.google.com/project/${self.projectId}`;
|
|
241
241
|
|
|
242
|
-
self.bemApiURL = `https://us-central1-${self?.firebaseRC?.projects?.default}.cloudfunctions.net/bm_api?
|
|
242
|
+
self.bemApiURL = `https://us-central1-${self?.firebaseRC?.projects?.default}.cloudfunctions.net/bm_api?backendManagerKey=${self?.runtimeConfigJSON?.backend_manager?.key}`;
|
|
243
243
|
|
|
244
244
|
// Log
|
|
245
245
|
log(`ID: `, chalk.bold(`${self.projectId}`));
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const fetch = require('wonderful-fetch');
|
|
2
|
+
const moment = require('moment');
|
|
3
|
+
const jetpack = require('fs-jetpack');
|
|
4
|
+
const powertools = require('node-powertools');
|
|
5
|
+
const uuidv4 = require('uuid').v4;
|
|
6
|
+
const { get, set } = require('lodash');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { Octokit } = require('@octokit/rest');
|
|
9
|
+
|
|
10
|
+
function Module() {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Module.prototype.main = function () {
|
|
15
|
+
const self = this;
|
|
16
|
+
const Manager = self.Manager;
|
|
17
|
+
const Api = self.Api;
|
|
18
|
+
const assistant = self.assistant;
|
|
19
|
+
const payload = self.payload;
|
|
20
|
+
|
|
21
|
+
return new Promise(async function(resolve, reject) {
|
|
22
|
+
try {
|
|
23
|
+
// Perform checks
|
|
24
|
+
if (!payload.user.roles.admin && !payload.user.roles.blogger) {
|
|
25
|
+
return reject(assistant.errorify(`Admin required.`, {code: 401}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Log payload
|
|
29
|
+
assistant.log(`main(): payload.data`, payload.data);
|
|
30
|
+
|
|
31
|
+
// Set now
|
|
32
|
+
const now = assistant.meta.startTime.timestamp;
|
|
33
|
+
const bemRepo = assistant.parseRepo(Manager?.config?.github?.repo_website);
|
|
34
|
+
|
|
35
|
+
// Setup Octokit
|
|
36
|
+
self.octokit = new Octokit({
|
|
37
|
+
auth: Manager?.config?.github?.key,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Check for required values
|
|
41
|
+
if (!payload.data.payload.path) {
|
|
42
|
+
return reject(assistant.errorify(`Missing required parameter: path`, {code: 400}));
|
|
43
|
+
} else if (!payload.data.payload.body) {
|
|
44
|
+
return reject(assistant.errorify(`Missing required parameter: body`, {code: 400}));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Fix other values
|
|
48
|
+
payload.data.payload.type = payload.data.payload.type || 'text';
|
|
49
|
+
// payload.data.payload.overwrite = typeof payload.data.payload.overwrite === 'undefined' ? true : payload.data.payload.overwrite;
|
|
50
|
+
payload.data.payload.githubUser = payload.data.payload.githubUser || bemRepo.user;
|
|
51
|
+
payload.data.payload.githubRepo = payload.data.payload.githubRepo || bemRepo.name;
|
|
52
|
+
|
|
53
|
+
// Log
|
|
54
|
+
assistant.log(`main(): Creating file...`, payload.data.payload);
|
|
55
|
+
|
|
56
|
+
// Upload post
|
|
57
|
+
const uploadContent = await self.uploadContent();
|
|
58
|
+
|
|
59
|
+
// Log
|
|
60
|
+
assistant.log(`main(): uploadContent`, uploadContent);
|
|
61
|
+
|
|
62
|
+
// Resolve
|
|
63
|
+
return resolve({data: payload.data.payload});
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return reject(e);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Upload post to GitHub
|
|
71
|
+
Module.prototype.uploadContent = function (content) {
|
|
72
|
+
const self = this;
|
|
73
|
+
const Manager = self.Manager;
|
|
74
|
+
const Api = self.Api;
|
|
75
|
+
const assistant = self.assistant;
|
|
76
|
+
const payload = self.payload;
|
|
77
|
+
|
|
78
|
+
return new Promise(async function(resolve, reject) {
|
|
79
|
+
// Save variables
|
|
80
|
+
const filename = payload.data.payload.pathl
|
|
81
|
+
const owner = payload.data.payload.githubUser;
|
|
82
|
+
const repo = payload.data.payload.githubRepo;
|
|
83
|
+
|
|
84
|
+
// Log
|
|
85
|
+
assistant.log(`uploadContent(): filename`, filename);
|
|
86
|
+
|
|
87
|
+
// Get existing post
|
|
88
|
+
const existing = await self.octokit.rest.repos.getContent({
|
|
89
|
+
owner: owner,
|
|
90
|
+
repo: repo,
|
|
91
|
+
path: filename,
|
|
92
|
+
})
|
|
93
|
+
.catch(e => e);
|
|
94
|
+
|
|
95
|
+
// Log
|
|
96
|
+
assistant.log(`uploadContent(): Existing`, existing);
|
|
97
|
+
|
|
98
|
+
// Quit if error and it's DIFFERENT than 404
|
|
99
|
+
if (
|
|
100
|
+
existing instanceof Error
|
|
101
|
+
&& existing?.status !== 404
|
|
102
|
+
) {
|
|
103
|
+
return reject(existing);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Upload post
|
|
107
|
+
await self.octokit.rest.repos.createOrUpdateFileContents({
|
|
108
|
+
owner: owner,
|
|
109
|
+
repo: repo,
|
|
110
|
+
path: filename,
|
|
111
|
+
sha: existing?.data?.sha || undefined,
|
|
112
|
+
message: `📦 admin:write-repo-content ${filename}`,
|
|
113
|
+
content: Buffer.from(content).toString('base64'),
|
|
114
|
+
})
|
|
115
|
+
.then((r) => {
|
|
116
|
+
// Log
|
|
117
|
+
assistant.log(`uploadContent(): Result`, r);
|
|
118
|
+
|
|
119
|
+
// Resolve
|
|
120
|
+
return resolve(r);
|
|
121
|
+
})
|
|
122
|
+
.catch((e) => reject(e));
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
module.exports = Module;
|
|
@@ -39,7 +39,7 @@ Module.prototype.main = function () {
|
|
|
39
39
|
method: 'POST',
|
|
40
40
|
response: 'json',
|
|
41
41
|
body: {
|
|
42
|
-
|
|
42
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
43
43
|
method: 'post',
|
|
44
44
|
service: 'paypal',
|
|
45
45
|
command: 'v2/invoicing/invoices',
|
|
@@ -92,7 +92,7 @@ Module.prototype.main = function () {
|
|
|
92
92
|
method: 'POST',
|
|
93
93
|
response: 'json',
|
|
94
94
|
body: {
|
|
95
|
-
|
|
95
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
96
96
|
service: 'paypal',
|
|
97
97
|
command: `v2/invoicing/invoices/${createdInvoiceId}/send`,
|
|
98
98
|
method: 'post',
|
|
@@ -120,7 +120,7 @@ Module.prototype.main = function () {
|
|
|
120
120
|
method: 'POST',
|
|
121
121
|
response: 'json',
|
|
122
122
|
body: {
|
|
123
|
-
|
|
123
|
+
backendManagerKey: Manager.config.backend_manager.key,
|
|
124
124
|
command: `admin:send-notification`,
|
|
125
125
|
payload: {
|
|
126
126
|
title: payload.data.payload.title,
|
|
@@ -157,9 +157,12 @@ Module.prototype.import = function (command, payload, user, response) {
|
|
|
157
157
|
response: response ? response : self.payload.response,
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
// 11/27/2024 - Separated this IF/ELSE into two separate IFs
|
|
161
|
+
// Set backendManagerKey and authenticationToken if it's provided
|
|
160
162
|
if (self.payload.data.backendManagerKey) {
|
|
161
163
|
lib.payload.data.backendManagerKey = self.payload.data.backendManagerKey;
|
|
162
|
-
}
|
|
164
|
+
}
|
|
165
|
+
if (self.payload.data.authenticationToken) {
|
|
163
166
|
lib.payload.data.authenticationToken = self.payload.data.authenticationToken;
|
|
164
167
|
}
|
|
165
168
|
|
package/src/manager/index.js
CHANGED
|
@@ -246,7 +246,6 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
246
246
|
self.assistant.error(`Loaded app may have wrong service account: ${loadedProjectId} =/= ${appId}`);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
|
|
250
249
|
} catch (e) {
|
|
251
250
|
self.assistant.error('Failed to call .initializeApp()', e);
|
|
252
251
|
}
|
|
@@ -261,8 +260,6 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
261
260
|
});
|
|
262
261
|
} catch (e) {
|
|
263
262
|
self.assistant.error('Failed to call .updateProjectConfig()', e);
|
|
264
|
-
} finally {
|
|
265
|
-
|
|
266
263
|
}
|
|
267
264
|
// admin.firestore().settings({/* your settings... */ timestampsInSnapshots: true})
|
|
268
265
|
}
|