@ankhorage/projects 0.10.0 → 0.10.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/README.md +1 -1
- package/dist/capabilities/index.d.ts +10 -0
- package/dist/capabilities/socialManagerMediaAnalytics.d.ts +10 -0
- package/dist/capabilities/socialManagerMediaAnalytics.js +8 -0
- package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js +21 -2
- package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js +30 -2
- package/dist/types/socialManager.d.ts +2 -0
- package/package.json +16 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# Ankhorage Projects
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Provides standalone project identity, persistence, and repository-oriented project actions.
|
|
9
9
|
|
|
@@ -179,6 +179,16 @@ export declare const CAPABILITIES: readonly [{
|
|
|
179
179
|
};
|
|
180
180
|
readonly label: "Read social media";
|
|
181
181
|
readonly description: "Read one immutable social media metadata record.";
|
|
182
|
+
}, {
|
|
183
|
+
readonly id: "projects.social.media.content";
|
|
184
|
+
readonly owner: "@ankhorage/projects";
|
|
185
|
+
readonly access: readonly ["read"];
|
|
186
|
+
readonly binding: {
|
|
187
|
+
readonly kind: "storage";
|
|
188
|
+
readonly bindableAs: readonly ["target"];
|
|
189
|
+
};
|
|
190
|
+
readonly label: "Read social media content";
|
|
191
|
+
readonly description: "Read immutable social media bytes for the authenticated caller.";
|
|
182
192
|
}, {
|
|
183
193
|
readonly id: "projects.social.media.remove";
|
|
184
194
|
readonly owner: "@ankhorage/projects";
|
|
@@ -29,6 +29,16 @@ export declare const SOCIAL_MANAGER_MEDIA_ANALYTICS_CAPABILITIES: readonly [{
|
|
|
29
29
|
};
|
|
30
30
|
readonly label: "Read social media";
|
|
31
31
|
readonly description: "Read one immutable social media metadata record.";
|
|
32
|
+
}, {
|
|
33
|
+
readonly id: "projects.social.media.content";
|
|
34
|
+
readonly owner: "@ankhorage/projects";
|
|
35
|
+
readonly access: readonly ["read"];
|
|
36
|
+
readonly binding: {
|
|
37
|
+
readonly kind: "storage";
|
|
38
|
+
readonly bindableAs: readonly ["target"];
|
|
39
|
+
};
|
|
40
|
+
readonly label: "Read social media content";
|
|
41
|
+
readonly description: "Read immutable social media bytes for the authenticated caller.";
|
|
32
42
|
}, {
|
|
33
43
|
readonly id: "projects.social.media.remove";
|
|
34
44
|
readonly owner: "@ankhorage/projects";
|
|
@@ -24,6 +24,14 @@ export const SOCIAL_MANAGER_MEDIA_ANALYTICS_CAPABILITIES = [
|
|
|
24
24
|
label: 'Read social media',
|
|
25
25
|
description: 'Read one immutable social media metadata record.',
|
|
26
26
|
},
|
|
27
|
+
{
|
|
28
|
+
id: 'projects.social.media.content',
|
|
29
|
+
owner: '@ankhorage/projects',
|
|
30
|
+
access: ['read'],
|
|
31
|
+
binding: { kind: 'storage', bindableAs: ['target'] },
|
|
32
|
+
label: 'Read social media content',
|
|
33
|
+
description: 'Read immutable social media bytes for the authenticated caller.',
|
|
34
|
+
},
|
|
27
35
|
{
|
|
28
36
|
id: 'projects.social.media.remove',
|
|
29
37
|
owner: '@ankhorage/projects',
|
package/dist/features/trusted-social-manager-host/adapters/createSocialManagerMediaStoreAsync.js
CHANGED
|
@@ -96,12 +96,14 @@ async function removeAsync(root, key, mediaId, isReferencedAsync) {
|
|
|
96
96
|
function readUpload(upload) {
|
|
97
97
|
const kind = mediaKind(upload.contentType);
|
|
98
98
|
if (!kind ||
|
|
99
|
+
(upload.name !== undefined && !isMediaName(upload.name)) ||
|
|
99
100
|
!(upload.bytes instanceof Uint8Array) ||
|
|
100
101
|
upload.bytes.byteLength === 0 ||
|
|
101
102
|
upload.bytes.byteLength > maximumByteLength) {
|
|
102
103
|
throw new Error('Invalid Social Manager media upload.');
|
|
103
104
|
}
|
|
104
105
|
return {
|
|
106
|
+
...(upload.name === undefined ? {} : { name: upload.name }),
|
|
105
107
|
kind,
|
|
106
108
|
contentType: upload.contentType,
|
|
107
109
|
byteLength: upload.bytes.byteLength,
|
|
@@ -116,6 +118,10 @@ function mediaKind(contentType) {
|
|
|
116
118
|
? 'video'
|
|
117
119
|
: undefined;
|
|
118
120
|
}
|
|
121
|
+
/*** Accept a bounded display name without allowing control characters into durable metadata. */
|
|
122
|
+
function isMediaName(value) {
|
|
123
|
+
return value.trim().length > 0 && value.length <= 255 && !/[\r\n]/u.test(value);
|
|
124
|
+
}
|
|
119
125
|
/*** Derive a stable opaque reference from the trusted scope and immutable content bytes. */
|
|
120
126
|
function createMediaId(key, bytes) {
|
|
121
127
|
return `media-${key}-${createHash('sha256').update(bytes).digest('hex')}`;
|
|
@@ -200,7 +206,19 @@ function findMedia(document, mediaId) {
|
|
|
200
206
|
/*** Project durable metadata without disclosing scope ownership details. */
|
|
201
207
|
function toMedia(media) {
|
|
202
208
|
const { mediaId, kind, contentType, byteLength, createdAt } = media;
|
|
203
|
-
return {
|
|
209
|
+
return {
|
|
210
|
+
mediaId,
|
|
211
|
+
name: media.name ?? defaultMediaName(kind, contentType),
|
|
212
|
+
kind,
|
|
213
|
+
contentType,
|
|
214
|
+
byteLength,
|
|
215
|
+
createdAt,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/*** Derive a stable display name for immutable records created before callers supplied one. */
|
|
219
|
+
function defaultMediaName(kind, contentType) {
|
|
220
|
+
const subtype = contentType.split('/').at(1)?.toUpperCase() ?? 'MEDIA';
|
|
221
|
+
return `${kind === 'image' ? 'Image' : 'Video'} upload (${subtype})`;
|
|
204
222
|
}
|
|
205
223
|
/*** Validate the persisted envelope and every immutable media record before returning it. */
|
|
206
224
|
function isDocument(value, key) {
|
|
@@ -230,7 +248,8 @@ function isMediaMetadata(value) {
|
|
|
230
248
|
Number.isSafeInteger(value.byteLength) &&
|
|
231
249
|
value.byteLength > 0 &&
|
|
232
250
|
value.byteLength <= maximumByteLength &&
|
|
233
|
-
typeof value.createdAt === 'string'
|
|
251
|
+
typeof value.createdAt === 'string' &&
|
|
252
|
+
(value.name === undefined || (typeof value.name === 'string' && isMediaName(value.name))));
|
|
234
253
|
}
|
|
235
254
|
/*** Keep object filenames confined to opaque hashes generated by this adapter. */
|
|
236
255
|
function isMediaId(value) {
|
package/dist/features/trusted-social-manager-host/composition/createSocialManagerMediaOperations.js
CHANGED
|
@@ -6,6 +6,7 @@ export function createSocialManagerMediaOperations(input, callerOf) {
|
|
|
6
6
|
'projects.social.media.upload': createOperation((request) => uploadMediaAsync(input, callerOf(request), request.body)),
|
|
7
7
|
'projects.social.media.list': readOperation((request) => listMediaAsync(input, callerOf(request))),
|
|
8
8
|
'projects.social.media.read': readOperation((request) => readMediaAsync(input, callerOf(request), request.params.mediaId)),
|
|
9
|
+
'projects.social.media.content': readOperation((request) => readMediaContentAsync(input, callerOf(request), request.params.mediaId)),
|
|
9
10
|
'projects.social.media.remove': deleteOperation((request) => removeMediaAsync(input, callerOf(request), request.params.mediaId)),
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -30,6 +31,20 @@ async function readMediaAsync(input, caller, mediaId) {
|
|
|
30
31
|
const media = caller && mediaId ? await input.store.readAsync(caller, mediaId) : undefined;
|
|
31
32
|
return media ? { body: media } : missingResponse();
|
|
32
33
|
}
|
|
34
|
+
/*** Deliver immutable media bytes only after the host has authenticated the caller scope. */
|
|
35
|
+
async function readMediaContentAsync(input, caller, mediaId) {
|
|
36
|
+
const item = caller && mediaId ? await input.store.loadAsync(caller, mediaId) : undefined;
|
|
37
|
+
return item
|
|
38
|
+
? {
|
|
39
|
+
body: item.bytes,
|
|
40
|
+
headers: {
|
|
41
|
+
'cache-control': 'private, no-store',
|
|
42
|
+
'content-type': item.media.contentType,
|
|
43
|
+
'x-content-type-options': 'nosniff',
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: missingResponse();
|
|
47
|
+
}
|
|
33
48
|
/*** Remove media only when no immutable draft or retained publication reference requires it. */
|
|
34
49
|
async function removeMediaAsync(input, caller, mediaId) {
|
|
35
50
|
if (!caller || !mediaId)
|
|
@@ -43,12 +58,25 @@ async function removeMediaAsync(input, caller, mediaId) {
|
|
|
43
58
|
}
|
|
44
59
|
/*** Decode only canonical nonempty base64 JSON input before durable media validation. */
|
|
45
60
|
function readUpload(value) {
|
|
46
|
-
if (!isRecord(value) ||
|
|
61
|
+
if (!isRecord(value) ||
|
|
62
|
+
typeof value.contentType !== 'string' ||
|
|
63
|
+
typeof value.base64 !== 'string' ||
|
|
64
|
+
(value.name !== undefined && (typeof value.name !== 'string' || !isMediaName(value.name))))
|
|
47
65
|
return undefined;
|
|
48
66
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value.base64))
|
|
49
67
|
return undefined;
|
|
50
68
|
const bytes = new Uint8Array(Buffer.from(value.base64, 'base64'));
|
|
51
|
-
return bytes.byteLength > 0
|
|
69
|
+
return bytes.byteLength > 0
|
|
70
|
+
? {
|
|
71
|
+
contentType: value.contentType,
|
|
72
|
+
bytes,
|
|
73
|
+
...(typeof value.name === 'string' ? { name: value.name } : {}),
|
|
74
|
+
}
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
/*** Accept a bounded display name without allowing control characters into durable metadata. */
|
|
78
|
+
function isMediaName(value) {
|
|
79
|
+
return value.trim().length > 0 && value.length <= 255 && !/[\r\n]/u.test(value);
|
|
52
80
|
}
|
|
53
81
|
/*** Declare a canonical immutable-media read operation. */
|
|
54
82
|
function readOperation(handler) {
|
|
@@ -49,6 +49,7 @@ export interface SocialManagerCaller extends SocialManagerScope {
|
|
|
49
49
|
/*** Immutable metadata for host-owned media selected by a Social Manager draft. */
|
|
50
50
|
export interface SocialManagerMedia {
|
|
51
51
|
readonly mediaId: string;
|
|
52
|
+
readonly name: string;
|
|
52
53
|
readonly kind: 'image' | 'video';
|
|
53
54
|
readonly contentType: string;
|
|
54
55
|
readonly byteLength: number;
|
|
@@ -56,6 +57,7 @@ export interface SocialManagerMedia {
|
|
|
56
57
|
}
|
|
57
58
|
/*** Raw upload content accepted only at the trusted Social Manager host boundary. */
|
|
58
59
|
export interface SocialManagerMediaUpload {
|
|
60
|
+
readonly name?: string;
|
|
59
61
|
readonly contentType: string;
|
|
60
62
|
readonly bytes: Uint8Array;
|
|
61
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/projects",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Standalone project identity and repository actions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ankhorage",
|
|
@@ -353,6 +353,21 @@
|
|
|
353
353
|
"label": "Read social media",
|
|
354
354
|
"description": "Read one immutable social media metadata record."
|
|
355
355
|
},
|
|
356
|
+
{
|
|
357
|
+
"id": "projects.social.media.content",
|
|
358
|
+
"owner": "@ankhorage/projects",
|
|
359
|
+
"access": [
|
|
360
|
+
"read"
|
|
361
|
+
],
|
|
362
|
+
"binding": {
|
|
363
|
+
"kind": "storage",
|
|
364
|
+
"bindableAs": [
|
|
365
|
+
"target"
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
"label": "Read social media content",
|
|
369
|
+
"description": "Read immutable social media bytes for the authenticated caller."
|
|
370
|
+
},
|
|
356
371
|
{
|
|
357
372
|
"id": "projects.social.media.remove",
|
|
358
373
|
"owner": "@ankhorage/projects",
|