@easy-cms/plugin-backups 0.0.0-stage → 1.40.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.
- package/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/index.d.ts +29 -0
- package/dist/index.js +401 -0
- package/package.json +50 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kanawoot K.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @easy-cms/plugin-backups
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Backup destinations for [Easy CMS](https://easycms.dev): **Google Drive** and **S3-compatible
|
|
4
|
+
storage** (Cloudflare R2, Backblaze B2, AWS S3, Wasabi), connected in Settings → Integrations and
|
|
5
|
+
chosen in Settings → Backups.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { backupsPlugin } from '@easy-cms/plugin-backups'
|
|
9
|
+
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
backups: { encryptionKey: process.env.EASY_CMS_BACKUP_KEY },
|
|
12
|
+
plugins: [backupsPlugin()],
|
|
13
|
+
})
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
See the [backups guide](https://easycms.dev/docs/backups#destinations).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as _easy_cms_core from '@easy-cms/core';
|
|
2
|
+
import { IntegrationConfig } from '@easy-cms/core';
|
|
3
|
+
|
|
4
|
+
/** A failure; `permanent` when trying again won't help (access taken back, a full drive). */
|
|
5
|
+
declare class DestinationError extends Error {
|
|
6
|
+
readonly permanent: boolean;
|
|
7
|
+
constructor(message: string, permanent?: boolean);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Google Drive, for backups. */
|
|
11
|
+
declare const googleDrive: IntegrationConfig;
|
|
12
|
+
|
|
13
|
+
interface BackupsPluginOptions {
|
|
14
|
+
/** The destinations offered in Integrations → Backups. Default: Google Drive and S3-compatible. */
|
|
15
|
+
readonly destinations?: readonly IntegrationConfig[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Places backups can go (#395): connected in Integrations, chosen in Settings → Backups with how
|
|
19
|
+
* many to keep at each.
|
|
20
|
+
*/
|
|
21
|
+
declare function backupsPlugin(options?: BackupsPluginOptions): _easy_cms_core.TypedPlugin<Record<never, never>>;
|
|
22
|
+
|
|
23
|
+
/** S3-compatible storage; `fetch` for tests. */
|
|
24
|
+
declare function s3Compatible(options?: {
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}): IntegrationConfig;
|
|
27
|
+
|
|
28
|
+
export { DestinationError, backupsPlugin, googleDrive, s3Compatible };
|
|
29
|
+
export type { BackupsPluginOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var DestinationError = class extends Error {
|
|
3
|
+
permanent;
|
|
4
|
+
constructor(message, permanent = false) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "DestinationError";
|
|
7
|
+
this.permanent = permanent;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// ../../node_modules/.pnpm/simple-icons@16.36.0/node_modules/simple-icons/index.mjs
|
|
12
|
+
var c = '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>';
|
|
13
|
+
var t = '</title><path d="';
|
|
14
|
+
var a = '"/></svg>';
|
|
15
|
+
var siGoogledrive = { title: "Google Drive", slug: "googledrive", get svg() {
|
|
16
|
+
return c + "Google Drive" + t + this.path + a;
|
|
17
|
+
}, path: "M12.01 1.485c-2.082 0-3.754.02-3.743.047.01.02 1.708 3.001 3.774 6.62l3.76 6.574h3.76c2.081 0 3.753-.02 3.742-.047-.005-.02-1.708-3.001-3.775-6.62l-3.76-6.574zm-4.76 1.73a789.828 789.861 0 0 0-3.63 6.319L0 15.868l1.89 3.298 1.885 3.297 3.62-6.335 3.618-6.33-1.88-3.287C8.1 4.704 7.255 3.22 7.25 3.214zm2.259 12.653-.203.348c-.114.198-.96 1.672-1.88 3.287a423.93 423.948 0 0 1-1.698 2.97c-.01.026 3.24.042 7.222.042h7.244l1.796-3.157c.992-1.734 1.85-3.23 1.906-3.323l.104-.167h-7.249z", source: "https://developers.google.com/drive/web/branding", hex: "4285F4" };
|
|
18
|
+
|
|
19
|
+
// src/logos.ts
|
|
20
|
+
var GOOGLE_DRIVE = { paths: [{ d: siGoogledrive.path }], color: `#${siGoogledrive.hex}` };
|
|
21
|
+
|
|
22
|
+
// src/google-drive.ts
|
|
23
|
+
var SCOPE = "https://www.googleapis.com/auth/drive.file";
|
|
24
|
+
var FOLDER = "application/vnd.google-apps.folder";
|
|
25
|
+
var authURL = () => process.env.GOOGLE_AUTH_URL ?? "https://accounts.google.com/o/oauth2/v2/auth";
|
|
26
|
+
var tokenURL = () => process.env.GOOGLE_TOKEN_URL ?? "https://oauth2.googleapis.com/token";
|
|
27
|
+
var api = () => (process.env.GOOGLE_API_URL ?? "https://www.googleapis.com").replace(/\/+$/, "");
|
|
28
|
+
var LASTING = /* @__PURE__ */ new Set([
|
|
29
|
+
"invalid_grant",
|
|
30
|
+
"invalid_client",
|
|
31
|
+
"unauthorized_client",
|
|
32
|
+
"storageQuotaExceeded",
|
|
33
|
+
"insufficientPermissions",
|
|
34
|
+
"notFound"
|
|
35
|
+
]);
|
|
36
|
+
async function read(response, what) {
|
|
37
|
+
const answer = await response.json().catch(() => ({}));
|
|
38
|
+
if (response.ok) return answer;
|
|
39
|
+
const reason = typeof answer.error === "string" ? answer.error : answer.error?.errors?.[0]?.reason;
|
|
40
|
+
const message = answer.error_description ?? (typeof answer.error === "object" ? answer.error?.message : void 0) ?? reason ?? `HTTP ${response.status}`;
|
|
41
|
+
const lasting = LASTING.has(String(reason)) || response.status >= 400 && response.status < 500 && response.status !== 429 && response.status !== 408;
|
|
42
|
+
throw new DestinationError(
|
|
43
|
+
`Google Drive (${what}): ${message}${reason === "invalid_grant" ? " \u2014 connect the account again" : ""}`,
|
|
44
|
+
lasting
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
async function call(url, init, what) {
|
|
48
|
+
try {
|
|
49
|
+
return await fetch(url, { ...init, signal: AbortSignal.timeout(12e4) });
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new DestinationError(`Google Drive could not be reached: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function accessToken(app, refreshToken) {
|
|
55
|
+
const response = await call(
|
|
56
|
+
tokenURL(),
|
|
57
|
+
{
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
60
|
+
body: new URLSearchParams({
|
|
61
|
+
client_id: app.clientId ?? "",
|
|
62
|
+
client_secret: app.clientSecret ?? "",
|
|
63
|
+
refresh_token: refreshToken,
|
|
64
|
+
grant_type: "refresh_token"
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
"token"
|
|
68
|
+
);
|
|
69
|
+
return String((await read(response, "token")).access_token ?? "");
|
|
70
|
+
}
|
|
71
|
+
var googleDrive = {
|
|
72
|
+
id: "google-drive",
|
|
73
|
+
label: "Google Drive",
|
|
74
|
+
category: "backups",
|
|
75
|
+
icon: GOOGLE_DRIVE,
|
|
76
|
+
description: {
|
|
77
|
+
en: "Keeps backups in a folder of your Google Drive, through a Google Cloud app of your own.",
|
|
78
|
+
th: "\u0E40\u0E01\u0E47\u0E1A backup \u0E43\u0E19\u0E42\u0E1F\u0E25\u0E40\u0E14\u0E2D\u0E23\u0E4C\u0E02\u0E2D\u0E07 Google Drive \u0E1C\u0E48\u0E32\u0E19\u0E41\u0E2D\u0E1B Google Cloud \u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13\u0E40\u0E2D\u0E07"
|
|
79
|
+
},
|
|
80
|
+
docs: "https://easycms.dev/docs/backups#google-drive",
|
|
81
|
+
plugin: "@easy-cms/plugin-backups",
|
|
82
|
+
kind: "oauth",
|
|
83
|
+
consent: {
|
|
84
|
+
text: {
|
|
85
|
+
en: "Backups of the whole database, users\u2019 emails included, are sent to Google Drive. Set backups.encryptionKey to encrypt them first.",
|
|
86
|
+
th: "backup \u0E02\u0E2D\u0E07\u0E17\u0E31\u0E49\u0E07\u0E10\u0E32\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25 \u0E23\u0E27\u0E21\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E02\u0E2D\u0E07\u0E1C\u0E39\u0E49\u0E43\u0E0A\u0E49 \u0E08\u0E30\u0E16\u0E39\u0E01\u0E2A\u0E48\u0E07\u0E44\u0E1B\u0E22\u0E31\u0E07 Google Drive \u0E15\u0E31\u0E49\u0E07 backups.encryptionKey \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E02\u0E49\u0E32\u0E23\u0E2B\u0E31\u0E2A\u0E01\u0E48\u0E2D\u0E19\u0E2A\u0E48\u0E07"
|
|
87
|
+
},
|
|
88
|
+
policy: "https://policies.google.com/privacy"
|
|
89
|
+
},
|
|
90
|
+
oauth: {
|
|
91
|
+
app: {
|
|
92
|
+
fields: [
|
|
93
|
+
{ name: "clientId", label: { en: "Client ID", th: "Client ID" }, required: true },
|
|
94
|
+
{
|
|
95
|
+
name: "clientSecret",
|
|
96
|
+
label: { en: "Client secret", th: "Client secret" },
|
|
97
|
+
secret: true,
|
|
98
|
+
required: true
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
env: { clientId: "GOOGLE_CLIENT_ID", clientSecret: "GOOGLE_CLIENT_SECRET" }
|
|
102
|
+
},
|
|
103
|
+
authorizeUrl: ({ redirectUri, state, app }) => {
|
|
104
|
+
const query = new URLSearchParams({
|
|
105
|
+
client_id: app.clientId ?? "",
|
|
106
|
+
redirect_uri: redirectUri,
|
|
107
|
+
response_type: "code",
|
|
108
|
+
scope: SCOPE,
|
|
109
|
+
// A refresh token, every time: backups run while nobody is signed in.
|
|
110
|
+
access_type: "offline",
|
|
111
|
+
prompt: "consent",
|
|
112
|
+
state
|
|
113
|
+
});
|
|
114
|
+
return `${authURL()}?${query}`;
|
|
115
|
+
},
|
|
116
|
+
// The code → tokens → the account's email → a folder of its own for this site's backups.
|
|
117
|
+
exchange: async ({ code, redirectUri, app }) => {
|
|
118
|
+
const tokens = await read(
|
|
119
|
+
await call(
|
|
120
|
+
tokenURL(),
|
|
121
|
+
{
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
124
|
+
body: new URLSearchParams({
|
|
125
|
+
code,
|
|
126
|
+
client_id: app.clientId ?? "",
|
|
127
|
+
client_secret: app.clientSecret ?? "",
|
|
128
|
+
redirect_uri: redirectUri,
|
|
129
|
+
grant_type: "authorization_code"
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
"token"
|
|
133
|
+
),
|
|
134
|
+
"token"
|
|
135
|
+
);
|
|
136
|
+
const refreshToken = String(tokens.refresh_token ?? "");
|
|
137
|
+
if (!refreshToken) throw new Error("Google gave no refresh token: connect the account again");
|
|
138
|
+
const auth = { authorization: `Bearer ${String(tokens.access_token ?? "")}` };
|
|
139
|
+
const about = await read(
|
|
140
|
+
await call(`${api()}/drive/v3/about?fields=user(emailAddress)`, { headers: auth }, "about"),
|
|
141
|
+
"about"
|
|
142
|
+
);
|
|
143
|
+
const email = String(
|
|
144
|
+
about.user?.emailAddress ?? ""
|
|
145
|
+
);
|
|
146
|
+
const site = new URL(redirectUri).host;
|
|
147
|
+
const folder = await read(
|
|
148
|
+
await call(
|
|
149
|
+
`${api()}/drive/v3/files?fields=id`,
|
|
150
|
+
{
|
|
151
|
+
method: "POST",
|
|
152
|
+
headers: { ...auth, "content-type": "application/json" },
|
|
153
|
+
body: JSON.stringify({ name: `Easy CMS backups \u2013 ${site}`, mimeType: FOLDER })
|
|
154
|
+
},
|
|
155
|
+
"folder"
|
|
156
|
+
),
|
|
157
|
+
"folder"
|
|
158
|
+
);
|
|
159
|
+
return {
|
|
160
|
+
values: { refreshToken, folderId: String(folder.id ?? "") },
|
|
161
|
+
...email ? { account: email } : {}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
// The token still works and the folder is still there (not in the bin).
|
|
166
|
+
async test(values, { app }) {
|
|
167
|
+
try {
|
|
168
|
+
const token = await accessToken(app, values.refreshToken ?? "");
|
|
169
|
+
const folder = await read(
|
|
170
|
+
await call(
|
|
171
|
+
`${api()}/drive/v3/files/${encodeURIComponent(values.folderId ?? "")}?fields=name,trashed`,
|
|
172
|
+
{ headers: { authorization: `Bearer ${token}` } },
|
|
173
|
+
"folder"
|
|
174
|
+
),
|
|
175
|
+
"folder"
|
|
176
|
+
);
|
|
177
|
+
if (folder.trashed) return { ok: false, message: "The backups folder is in the bin" };
|
|
178
|
+
return { ok: true, account: String(folder.name ?? "") };
|
|
179
|
+
} catch (error) {
|
|
180
|
+
return { ok: false, message: error.message };
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
backups(values, { app }) {
|
|
184
|
+
const folderId = values.folderId ?? "";
|
|
185
|
+
let token;
|
|
186
|
+
const auth = async () => {
|
|
187
|
+
token ??= accessToken(app, values.refreshToken ?? "");
|
|
188
|
+
return { authorization: `Bearer ${await token}` };
|
|
189
|
+
};
|
|
190
|
+
const find = async (name) => {
|
|
191
|
+
const q = `name = '${name.replace(/['\\]/g, "\\$&")}' and '${folderId}' in parents and trashed = false`;
|
|
192
|
+
const found = await read(
|
|
193
|
+
await call(
|
|
194
|
+
`${api()}/drive/v3/files?${new URLSearchParams({ q, fields: "files(id)", pageSize: "1" })}`,
|
|
195
|
+
{ headers: await auth() },
|
|
196
|
+
"find"
|
|
197
|
+
),
|
|
198
|
+
"find"
|
|
199
|
+
);
|
|
200
|
+
return found.files?.[0]?.id ?? null;
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
// A resumable upload: the session first, then the file in one request.
|
|
204
|
+
async put(name, data) {
|
|
205
|
+
const session = await call(
|
|
206
|
+
`${api()}/upload/drive/v3/files?uploadType=resumable&fields=id,webViewLink`,
|
|
207
|
+
{
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: {
|
|
210
|
+
...await auth(),
|
|
211
|
+
"content-type": "application/json; charset=UTF-8",
|
|
212
|
+
"x-upload-content-type": "application/octet-stream",
|
|
213
|
+
"x-upload-content-length": String(data.byteLength)
|
|
214
|
+
},
|
|
215
|
+
body: JSON.stringify({ name, parents: [folderId] })
|
|
216
|
+
},
|
|
217
|
+
"upload"
|
|
218
|
+
);
|
|
219
|
+
if (!session.ok) await read(session, "upload");
|
|
220
|
+
const location = session.headers.get("location");
|
|
221
|
+
if (!location) throw new DestinationError("Google Drive (upload): no upload address");
|
|
222
|
+
const file = await read(
|
|
223
|
+
await call(
|
|
224
|
+
location,
|
|
225
|
+
{
|
|
226
|
+
method: "PUT",
|
|
227
|
+
headers: { "content-type": "application/octet-stream" },
|
|
228
|
+
body: data
|
|
229
|
+
},
|
|
230
|
+
"upload"
|
|
231
|
+
),
|
|
232
|
+
"upload"
|
|
233
|
+
);
|
|
234
|
+
return file.webViewLink ? { link: String(file.webViewLink) } : void 0;
|
|
235
|
+
},
|
|
236
|
+
async get(name) {
|
|
237
|
+
const id = await find(name);
|
|
238
|
+
if (!id) return null;
|
|
239
|
+
const response = await call(
|
|
240
|
+
`${api()}/drive/v3/files/${encodeURIComponent(id)}?alt=media`,
|
|
241
|
+
{ headers: await auth() },
|
|
242
|
+
"download"
|
|
243
|
+
);
|
|
244
|
+
if (!response.ok) await read(response, "download");
|
|
245
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
246
|
+
},
|
|
247
|
+
async delete(name) {
|
|
248
|
+
const id = await find(name);
|
|
249
|
+
if (!id) return;
|
|
250
|
+
const response = await call(
|
|
251
|
+
`${api()}/drive/v3/files/${encodeURIComponent(id)}`,
|
|
252
|
+
{ method: "DELETE", headers: await auth() },
|
|
253
|
+
"delete"
|
|
254
|
+
);
|
|
255
|
+
if (!response.ok && response.status !== 404) await read(response, "delete");
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/plugin.ts
|
|
262
|
+
import { definePlugin } from "@easy-cms/core";
|
|
263
|
+
|
|
264
|
+
// src/info.ts
|
|
265
|
+
var INFO = {
|
|
266
|
+
name: "@easy-cms/plugin-backups",
|
|
267
|
+
// The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
|
|
268
|
+
apiVersion: 1,
|
|
269
|
+
...true ? { version: "1.40.0" } : {}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/s3.ts
|
|
273
|
+
import { s3Storage } from "@easy-cms/storage-s3";
|
|
274
|
+
var CHECK = ".easy-cms-check";
|
|
275
|
+
var LASTING2 = /\b(401|403|404)\b|AccessDenied|InvalidAccessKeyId|SignatureDoesNotMatch|NoSuchBucket/;
|
|
276
|
+
function storageOf(values, fetcher) {
|
|
277
|
+
const storage = s3Storage({
|
|
278
|
+
bucket: values.bucket ?? "",
|
|
279
|
+
region: values.region || "auto",
|
|
280
|
+
...values.endpoint ? { endpoint: values.endpoint } : {},
|
|
281
|
+
accessKeyId: values.accessKeyId ?? "",
|
|
282
|
+
secretAccessKey: values.secretAccessKey ?? "",
|
|
283
|
+
...values.prefix ? { prefix: values.prefix } : {},
|
|
284
|
+
...fetcher ? { fetch: fetcher } : {}
|
|
285
|
+
});
|
|
286
|
+
storage.init?.({ cwd: process.cwd() });
|
|
287
|
+
return storage;
|
|
288
|
+
}
|
|
289
|
+
async function guarded(work) {
|
|
290
|
+
try {
|
|
291
|
+
return await work();
|
|
292
|
+
} catch (error) {
|
|
293
|
+
const message = error.message || String(error);
|
|
294
|
+
throw new DestinationError(`S3: ${message}`, LASTING2.test(message));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function s3Compatible(options = {}) {
|
|
298
|
+
return {
|
|
299
|
+
id: "s3-backups",
|
|
300
|
+
label: "S3-compatible storage",
|
|
301
|
+
category: "backups",
|
|
302
|
+
icon: "box",
|
|
303
|
+
description: {
|
|
304
|
+
en: "Keeps backups in a private bucket: Cloudflare R2, Backblaze B2, AWS S3 or Wasabi.",
|
|
305
|
+
th: "\u0E40\u0E01\u0E47\u0E1A backup \u0E43\u0E19 bucket \u0E2A\u0E48\u0E27\u0E19\u0E15\u0E31\u0E27: Cloudflare R2, Backblaze B2, AWS S3 \u0E2B\u0E23\u0E37\u0E2D Wasabi"
|
|
306
|
+
},
|
|
307
|
+
docs: "https://easycms.dev/docs/backups#s3-compatible",
|
|
308
|
+
plugin: "@easy-cms/plugin-backups",
|
|
309
|
+
kind: "fields",
|
|
310
|
+
fields: [
|
|
311
|
+
{
|
|
312
|
+
name: "endpoint",
|
|
313
|
+
type: "url",
|
|
314
|
+
label: { en: "Endpoint", th: "Endpoint" },
|
|
315
|
+
placeholder: "https://<account>.r2.cloudflarestorage.com",
|
|
316
|
+
description: {
|
|
317
|
+
en: "R2, B2 and Wasabi give one; empty for AWS S3.",
|
|
318
|
+
th: "R2, B2 \u0E41\u0E25\u0E30 Wasabi \u0E21\u0E35\u0E43\u0E2B\u0E49 \u0E16\u0E49\u0E32\u0E40\u0E1B\u0E47\u0E19 AWS S3 \u0E1B\u0E25\u0E48\u0E2D\u0E22\u0E27\u0E48\u0E32\u0E07"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: "region",
|
|
323
|
+
label: { en: "Region", th: "Region" },
|
|
324
|
+
placeholder: "auto",
|
|
325
|
+
description: { en: "R2: auto. Empty: auto.", th: "R2: auto \u0E16\u0E49\u0E32\u0E27\u0E48\u0E32\u0E07: auto" }
|
|
326
|
+
},
|
|
327
|
+
{ name: "bucket", label: { en: "Bucket", th: "Bucket" }, required: true },
|
|
328
|
+
{
|
|
329
|
+
name: "prefix",
|
|
330
|
+
label: { en: "Folder in the bucket", th: "\u0E42\u0E1F\u0E25\u0E40\u0E14\u0E2D\u0E23\u0E4C\u0E43\u0E19 bucket" },
|
|
331
|
+
placeholder: "backups/"
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
name: "accessKeyId",
|
|
335
|
+
label: { en: "Access key ID", th: "Access key ID" },
|
|
336
|
+
required: true
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
name: "secretAccessKey",
|
|
340
|
+
label: { en: "Secret access key", th: "Secret access key" },
|
|
341
|
+
secret: true,
|
|
342
|
+
required: true
|
|
343
|
+
}
|
|
344
|
+
],
|
|
345
|
+
consent: {
|
|
346
|
+
text: {
|
|
347
|
+
en: "Backups of the whole database, users\u2019 emails included, are stored in this bucket. Keep it private, and set backups.encryptionKey to encrypt them.",
|
|
348
|
+
th: "backup \u0E02\u0E2D\u0E07\u0E17\u0E31\u0E49\u0E07\u0E10\u0E32\u0E19\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25 \u0E23\u0E27\u0E21\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E02\u0E2D\u0E07\u0E1C\u0E39\u0E49\u0E43\u0E0A\u0E49 \u0E08\u0E30\u0E16\u0E39\u0E01\u0E40\u0E01\u0E47\u0E1A\u0E43\u0E19 bucket \u0E19\u0E35\u0E49 \u0E15\u0E31\u0E49\u0E07 bucket \u0E40\u0E1B\u0E47\u0E19\u0E2A\u0E48\u0E27\u0E19\u0E15\u0E31\u0E27 \u0E41\u0E25\u0E30\u0E15\u0E31\u0E49\u0E07 backups.encryptionKey \u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E40\u0E02\u0E49\u0E32\u0E23\u0E2B\u0E31\u0E2A"
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
// Writes and deletes a small file: the keys, the bucket and the right to write all work.
|
|
352
|
+
async test(values) {
|
|
353
|
+
try {
|
|
354
|
+
const storage = storageOf(values, options.fetch);
|
|
355
|
+
await guarded(
|
|
356
|
+
() => storage.put(CHECK, new TextEncoder().encode("ok"), { contentType: "text/plain" })
|
|
357
|
+
);
|
|
358
|
+
await guarded(() => storage.delete(CHECK));
|
|
359
|
+
return { ok: true, account: `${values.bucket}${values.prefix ? `/${values.prefix}` : ""}` };
|
|
360
|
+
} catch (error) {
|
|
361
|
+
return { ok: false, message: error.message };
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
backups(values) {
|
|
365
|
+
const storage = storageOf(values, options.fetch);
|
|
366
|
+
return {
|
|
367
|
+
async put(name, data) {
|
|
368
|
+
await guarded(() => storage.put(name, data, { contentType: "application/octet-stream" }));
|
|
369
|
+
return void 0;
|
|
370
|
+
},
|
|
371
|
+
async get(name) {
|
|
372
|
+
return (await guarded(() => storage.get(name)))?.body ?? null;
|
|
373
|
+
},
|
|
374
|
+
async delete(name) {
|
|
375
|
+
await guarded(() => storage.delete(name));
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/plugin.ts
|
|
383
|
+
function backupsPlugin(options = {}) {
|
|
384
|
+
const destinations = options.destinations ?? [googleDrive, s3Compatible()];
|
|
385
|
+
for (const destination of destinations)
|
|
386
|
+
if (typeof destination.backups !== "function")
|
|
387
|
+
throw new Error(`backupsPlugin: "${destination.id}" has no backups() destination`);
|
|
388
|
+
return definePlugin(
|
|
389
|
+
(config) => ({
|
|
390
|
+
...config,
|
|
391
|
+
integrations: [...config.integrations ?? [], ...destinations]
|
|
392
|
+
}),
|
|
393
|
+
INFO
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
export {
|
|
397
|
+
DestinationError,
|
|
398
|
+
backupsPlugin,
|
|
399
|
+
googleDrive,
|
|
400
|
+
s3Compatible
|
|
401
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-backups",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.40.0",
|
|
4
|
+
"description": "Backup destinations for Easy CMS: Google Drive and S3-compatible storage (Cloudflare R2, Backblaze B2, AWS S3), connected in the admin",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@easy-cms/core": "^1.40.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@easy-cms/storage-s3": "^1.40.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"simple-icons": "16.36.0",
|
|
26
|
+
"@easy-cms/db-sqlite": "^1.40.0",
|
|
27
|
+
"@easy-cms/core": "^1.40.0"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.12"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/maritonx/easy-cms.git",
|
|
38
|
+
"directory": "packages/plugin-backups"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"easy-cms",
|
|
42
|
+
"easy-cms-plugin",
|
|
43
|
+
"backups",
|
|
44
|
+
"google-drive",
|
|
45
|
+
"s3",
|
|
46
|
+
"r2"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
6
53
|
}
|