@ampless/backend 1.0.0-alpha.33 → 1.0.0-alpha.35
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.
|
@@ -25,7 +25,7 @@ interface CreateProcessorTrustedHandlerOpts {
|
|
|
25
25
|
* SQS-driven trusted plugin executor. Trusted plugins get a runtime
|
|
26
26
|
* context with `listPublishedPosts` (one Query against the byStatus
|
|
27
27
|
* GSI) and `writePublicAsset` (S3 PutObject under
|
|
28
|
-
* `public/plugins/{name}/{key}`).
|
|
28
|
+
* `public/plugins/{instanceId ?? name}/{key}`).
|
|
29
29
|
*
|
|
30
30
|
* Built-in: rebuilds the site-settings JSON cache at
|
|
31
31
|
* `public/site-settings.json` whenever a `site.settings.updated`
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
QueryCommand
|
|
9
9
|
} from "@aws-sdk/lib-dynamodb";
|
|
10
10
|
import {
|
|
11
|
-
formatPublicAssetUrl
|
|
11
|
+
formatPublicAssetUrl,
|
|
12
|
+
isValidPluginKey,
|
|
13
|
+
validatePublicAssetKey
|
|
12
14
|
} from "ampless";
|
|
13
15
|
|
|
14
16
|
// src/events/posttag-sync.ts
|
|
@@ -56,7 +58,27 @@ function safeParse(s) {
|
|
|
56
58
|
function createProcessorTrustedHandler(opts) {
|
|
57
59
|
const trustedPlugins = (opts.plugins ?? []).filter(
|
|
58
60
|
(p) => typeof p === "object" && p.trust_level === "trusted"
|
|
59
|
-
)
|
|
61
|
+
).filter((p) => {
|
|
62
|
+
const ns = p.instanceId ?? p.name;
|
|
63
|
+
if (!isValidPluginKey(ns)) {
|
|
64
|
+
console.warn(
|
|
65
|
+
`[trusted-processor] plugin "${p.name}" (instanceId="${p.instanceId ?? "(none)"}") has invalid namespace "${ns}". Must match /^[a-zA-Z0-9_-]+$/. Plugin skipped \u2014 no hooks will run for it.`
|
|
66
|
+
);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
const seenNamespaces = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const plugin of trustedPlugins) {
|
|
73
|
+
const ns = plugin.instanceId ?? plugin.name;
|
|
74
|
+
if (seenNamespaces.has(ns)) {
|
|
75
|
+
console.warn(
|
|
76
|
+
`[trusted-processor] duplicate plugin namespace "${ns}" detected in trusted plugins. Set distinct \`instanceId\` on each instance to disambiguate writePublicAsset output.`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
seenNamespaces.add(ns);
|
|
80
|
+
}
|
|
81
|
+
const warnedWritePublicAssetCapability = /* @__PURE__ */ new Set();
|
|
60
82
|
const s3 = new S3Client({});
|
|
61
83
|
const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({}));
|
|
62
84
|
const BUCKET = requireEnv("AMPLESS_BUCKET_NAME");
|
|
@@ -97,11 +119,23 @@ function createProcessorTrustedHandler(opts) {
|
|
|
97
119
|
return items;
|
|
98
120
|
}
|
|
99
121
|
function makeContext(plugin) {
|
|
122
|
+
const namespace = plugin.instanceId ?? plugin.name;
|
|
123
|
+
const label = plugin.instanceId ? `${plugin.name}#${plugin.instanceId}` : plugin.name;
|
|
100
124
|
return {
|
|
101
125
|
site: opts.site,
|
|
102
126
|
listPublishedPosts: () => listPublished(),
|
|
103
127
|
async writePublicAsset(key, body, contentType) {
|
|
104
|
-
const
|
|
128
|
+
const keyError = validatePublicAssetKey(key);
|
|
129
|
+
if (keyError) {
|
|
130
|
+
throw new Error(`[${plugin.name}] writePublicAsset: ${keyError}`);
|
|
131
|
+
}
|
|
132
|
+
if (plugin.capabilities && !plugin.capabilities.includes("writePublicAsset") && !warnedWritePublicAssetCapability.has(label)) {
|
|
133
|
+
console.warn(
|
|
134
|
+
`[trusted-processor] ${label}: called ctx.writePublicAsset() but "writePublicAsset" is not in declared capabilities. Add it so admin UI / capability gates see the surface.`
|
|
135
|
+
);
|
|
136
|
+
warnedWritePublicAssetCapability.add(label);
|
|
137
|
+
}
|
|
138
|
+
const objectKey = `public/plugins/${namespace}/${key}`;
|
|
105
139
|
await s3.send(
|
|
106
140
|
new PutObjectCommand({
|
|
107
141
|
Bucket: BUCKET,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampless/backend",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.35",
|
|
4
4
|
"description": "Amplify Gen 2 backend factories for ampless: auth, data, storage, event processors, API key renewer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"@smithy/protocol-http": "^5.4.4",
|
|
66
66
|
"@smithy/signature-v4": "^5.4.4",
|
|
67
67
|
"fflate": "^0.8.3",
|
|
68
|
-
"ampless": "1.0.0-alpha.
|
|
69
|
-
"@ampless/mcp-server": "1.0.0-alpha.
|
|
68
|
+
"ampless": "1.0.0-alpha.20",
|
|
69
|
+
"@ampless/mcp-server": "1.0.0-alpha.24"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@aws-amplify/backend": "^1",
|