@beignet/core 0.0.41 → 0.0.43
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/CHANGELOG.md +10 -0
- package/README.md +64 -11
- package/dist/idempotency/index.d.ts +3 -1
- package/dist/idempotency/index.d.ts.map +1 -1
- package/dist/idempotency/index.js.map +1 -1
- package/dist/mail/index.d.ts +3 -0
- package/dist/mail/index.d.ts.map +1 -1
- package/dist/mail/index.js +35 -16
- package/dist/mail/index.js.map +1 -1
- package/dist/ports/index.d.ts +2 -2
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +1 -1
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/redaction.d.ts +7 -4
- package/dist/ports/redaction.d.ts.map +1 -1
- package/dist/ports/redaction.js +29 -7
- package/dist/ports/redaction.js.map +1 -1
- package/dist/ports/storage.d.ts +50 -0
- package/dist/ports/storage.d.ts.map +1 -1
- package/dist/ports/storage.js +85 -37
- package/dist/ports/storage.js.map +1 -1
- package/dist/server/hooks/idempotency.d.ts +3 -2
- package/dist/server/hooks/idempotency.d.ts.map +1 -1
- package/dist/server/hooks/idempotency.js +1 -1
- package/dist/server/hooks/idempotency.js.map +1 -1
- package/dist/uploads/index.d.ts.map +1 -1
- package/dist/uploads/index.js +53 -47
- package/dist/uploads/index.js.map +1 -1
- package/package.json +1 -1
- package/src/idempotency/index.ts +3 -1
- package/src/mail/index.ts +37 -7
- package/src/ports/index.ts +9 -1
- package/src/ports/redaction.ts +51 -9
- package/src/ports/storage.ts +131 -46
- package/src/server/hooks/idempotency.ts +4 -3
- package/src/uploads/index.ts +49 -43
|
@@ -58,8 +58,9 @@ export interface IdempotencyHooksOptions<Ctx> {
|
|
|
58
58
|
/**
|
|
59
59
|
* Build the idempotency scope after context exists.
|
|
60
60
|
*
|
|
61
|
-
* Defaults to a scope derived from `meta.scope`:
|
|
62
|
-
* `
|
|
61
|
+
* Defaults to a scope derived from `meta.scope`: omitted metadata scopes by
|
|
62
|
+
* `ctx.actor?.id` and also `ctx.tenant?.id` when present, `"actor"` scopes by
|
|
63
|
+
* the actor only, `"global"` stays global, `"tenant"` scopes by the tenant,
|
|
63
64
|
* and `"actor-tenant"` scopes by both.
|
|
64
65
|
*/
|
|
65
66
|
scope?: (args: {
|
|
@@ -97,7 +98,7 @@ function defaultIdempotencyScope(
|
|
|
97
98
|
ctx: CtxWithIdempotency,
|
|
98
99
|
meta: IdempotencyMeta,
|
|
99
100
|
): IdempotencyScope {
|
|
100
|
-
const mode = meta.scope ?? "
|
|
101
|
+
const mode = meta.scope ?? (ctx.tenant?.id ? "actor-tenant" : "actor");
|
|
101
102
|
|
|
102
103
|
switch (mode) {
|
|
103
104
|
case "global":
|
package/src/uploads/index.ts
CHANGED
|
@@ -1037,63 +1037,69 @@ export function createUploadRouter<Ctx>(
|
|
|
1037
1037
|
|
|
1038
1038
|
const completed: CompletedUploadFile[] = [];
|
|
1039
1039
|
const storedKeys: string[] = [];
|
|
1040
|
-
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
metadata,
|
|
1058
|
-
file: verifiedIntent,
|
|
1059
|
-
uploadId,
|
|
1060
|
-
});
|
|
1061
|
-
const storageMetadata =
|
|
1062
|
-
(await definition.storageMetadata?.({
|
|
1040
|
+
try {
|
|
1041
|
+
for (const [index, file] of webFiles.entries()) {
|
|
1042
|
+
const intent = intents[index];
|
|
1043
|
+
if (!intent) continue;
|
|
1044
|
+
const uploadId = id();
|
|
1045
|
+
await assertAuthorized(definition, {
|
|
1046
|
+
ctx,
|
|
1047
|
+
metadata,
|
|
1048
|
+
file: intent,
|
|
1049
|
+
uploadId,
|
|
1050
|
+
});
|
|
1051
|
+
const verified = await verifyBlobUploadFile(definition, intent, file);
|
|
1052
|
+
const verifiedIntent = {
|
|
1053
|
+
...intent,
|
|
1054
|
+
...(verified.checksum ? { checksum: verified.checksum } : {}),
|
|
1055
|
+
};
|
|
1056
|
+
const key = await definition.key({
|
|
1063
1057
|
ctx,
|
|
1064
1058
|
metadata,
|
|
1065
1059
|
file: verifiedIntent,
|
|
1066
1060
|
uploadId,
|
|
1067
|
-
})
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1061
|
+
});
|
|
1062
|
+
const storageMetadata =
|
|
1063
|
+
(await definition.storageMetadata?.({
|
|
1064
|
+
ctx,
|
|
1065
|
+
metadata,
|
|
1066
|
+
file: verifiedIntent,
|
|
1067
|
+
uploadId,
|
|
1068
|
+
})) ?? {};
|
|
1069
|
+
const object = await options.storage.put(key, file, {
|
|
1070
|
+
contentType: verifiedIntent.contentType,
|
|
1071
|
+
...(definition.file.cacheControl !== undefined
|
|
1072
|
+
? { cacheControl: definition.file.cacheControl }
|
|
1073
|
+
: {}),
|
|
1074
|
+
metadata: storageMetadata,
|
|
1075
|
+
visibility: definition.file.visibility ?? "private",
|
|
1076
|
+
});
|
|
1077
|
+
storedKeys.push(key);
|
|
1078
|
+
const completedFile = {
|
|
1079
|
+
...verifiedIntent,
|
|
1080
|
+
uploadId,
|
|
1081
|
+
key,
|
|
1082
|
+
object,
|
|
1083
|
+
};
|
|
1084
1084
|
await assertVerifiedFile(definition, {
|
|
1085
1085
|
ctx,
|
|
1086
1086
|
metadata,
|
|
1087
1087
|
file: completedFile,
|
|
1088
1088
|
storage: options.storage,
|
|
1089
1089
|
});
|
|
1090
|
-
|
|
1090
|
+
completed.push(completedFile);
|
|
1091
|
+
}
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
if (storedKeys.length > 0) {
|
|
1091
1094
|
await cleanupRejectedServerUpload(uploadName, storedKeys);
|
|
1092
|
-
throw error;
|
|
1093
1095
|
}
|
|
1094
|
-
|
|
1096
|
+
throw error;
|
|
1095
1097
|
}
|
|
1096
1098
|
|
|
1099
|
+
// Once app-owned completion begins, the app may persist durable references
|
|
1100
|
+
// to these objects. The framework can no longer delete them safely if a
|
|
1101
|
+
// later completion step fails; transaction or compensation belongs to the
|
|
1102
|
+
// app from this point forward.
|
|
1097
1103
|
const result = await definition.onComplete?.({
|
|
1098
1104
|
ctx,
|
|
1099
1105
|
metadata,
|