@ankhorage/projects 0.10.0 → 0.11.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Ankhorage Projects
5
5
 
6
- ![license: MIT](././paradox/badges/license.svg) ![npm: v0.10.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
6
+ ![license: MIT](././paradox/badges/license.svg) ![npm: v0.11.0](././paradox/badges/npm.svg) ![runtime: bun](././paradox/badges/runtime.svg) ![typescript: strict](././paradox/badges/typescript.svg) ![eslint: checked](././paradox/badges/eslint.svg) ![prettier: checked](././paradox/badges/prettier.svg) ![build: checked](././paradox/badges/build.svg) ![tests: configured](././paradox/badges/tests.svg) ![paradox: canonical](././paradox/badges/docs.svg)
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";
@@ -419,6 +429,16 @@ export declare const CAPABILITIES: readonly [{
419
429
  };
420
430
  readonly label: "List scheduled social publications";
421
431
  readonly description: "List active caller-owned social publication executions.";
432
+ }, {
433
+ readonly id: "projects.social.publications.calendar.list";
434
+ readonly owner: "@ankhorage/projects";
435
+ readonly access: readonly ["read"];
436
+ readonly binding: {
437
+ readonly kind: "action";
438
+ readonly bindableAs: readonly ["target"];
439
+ };
440
+ readonly label: "List social publication calendar events";
441
+ readonly description: "List active caller-owned social publications as Calendar events.";
422
442
  }, {
423
443
  readonly id: "projects.social.publications.history.list";
424
444
  readonly owner: "@ankhorage/projects";
@@ -266,6 +266,14 @@ export const CAPABILITIES = [
266
266
  label: 'List scheduled social publications',
267
267
  description: 'List active caller-owned social publication executions.',
268
268
  },
269
+ {
270
+ id: 'projects.social.publications.calendar.list',
271
+ owner: '@ankhorage/projects',
272
+ access: ['read'],
273
+ binding: { kind: 'action', bindableAs: ['target'] },
274
+ label: 'List social publication calendar events',
275
+ description: 'List active caller-owned social publications as Calendar events.',
276
+ },
269
277
  {
270
278
  id: 'projects.social.publications.history.list',
271
279
  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',
@@ -10,6 +10,8 @@ export function composeGeneratedRuntimeMaterialization(input) {
10
10
  const packageJson = JSON.parse(input.packageSource);
11
11
  return {
12
12
  navigatorBindings: {
13
+ ...input.callerBindings,
14
+ ...input.runtimeBindings,
13
15
  guards: { ...input.callerBindings.guards, ...input.runtimeBindings.guards },
14
16
  screens: { ...input.callerBindings.screens, ...input.runtimeBindings.screens },
15
17
  },
@@ -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 { mediaId, kind, contentType, byteLength, createdAt };
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) {
@@ -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) || typeof value.contentType !== 'string' || typeof value.base64 !== 'string')
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 ? { contentType: value.contentType, bytes } : undefined;
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) {
@@ -11,6 +11,7 @@ export function createSocialManagerPublicationOperations(input, callerOf) {
11
11
  'projects.social.publications.approval.status': readOperation((request) => readApprovalAsync(input.runtime, callerOf(request), request.params.runId)),
12
12
  'projects.social.publications.approval.resolve': updateOperation((request) => resolveApprovalAsync(input.runtime, callerOf(request), request.params.runId, request.body)),
13
13
  'projects.social.publications.scheduled.list': readOperation((request) => listPublicationsAsync(input.runtime, callerOf(request), true)),
14
+ 'projects.social.publications.calendar.list': readOperation((request) => listPublicationCalendarEventsAsync(input.runtime, callerOf(request))),
14
15
  'projects.social.publications.history.list': readOperation((request) => listPublicationsAsync(input.runtime, callerOf(request), false)),
15
16
  'projects.social.publications.receipts.list': readOperation((request) => listReceiptsAsync(input.runtime, callerOf(request))),
16
17
  };
@@ -76,6 +77,14 @@ async function listPublicationsAsync(runtime, caller, scheduled) {
76
77
  const publications = runs;
77
78
  return { body: publications.filter((run) => isActive(run) === scheduled).map(projectRun) };
78
79
  }
80
+ /*** Project active caller-owned durable publications into ZORA's canonical timed Calendar events. */
81
+ async function listPublicationCalendarEventsAsync(runtime, caller) {
82
+ if (!caller)
83
+ return { body: [] };
84
+ const runs = await listCallerPublicationRunsAsync(runtime, caller);
85
+ const events = await Promise.all(runs.filter(isActive).map((run) => calendarEventOf(runtime, caller, run)));
86
+ return { body: events.flat() };
87
+ }
79
88
  /*** Project redacted Social receipts from terminal or active publication run outputs. */
80
89
  async function listReceiptsAsync(runtime, caller) {
81
90
  if (!caller)
@@ -128,7 +137,8 @@ async function isCallerPublicationRunAsync(runtime, caller, run) {
128
137
  return false;
129
138
  try {
130
139
  const config = readPublicationConfig(node, caller);
131
- return (config.caller.tenantId === caller.tenantId &&
140
+ return (config.caller.actorId === caller.actorId &&
141
+ config.caller.tenantId === caller.tenantId &&
132
142
  config.caller.projectId === caller.projectId &&
133
143
  config.caller.environmentId === caller.environmentId);
134
144
  }
@@ -136,6 +146,27 @@ async function isCallerPublicationRunAsync(runtime, caller, run) {
136
146
  return false;
137
147
  }
138
148
  }
149
+ /*** Convert a configured durable publication run into a short UTC Calendar appointment. */
150
+ async function calendarEventOf(runtime, caller, run) {
151
+ const workflow = await runtime.runtime.getWorkflowAsync(scopeOf(caller), run.flow.id, run.flow.version);
152
+ const node = workflow?.definition.nodes.find((candidate) => candidate.id === 'publication');
153
+ if (!node)
154
+ return [];
155
+ try {
156
+ const { runAt } = readPublicationConfig(node, caller);
157
+ return [
158
+ {
159
+ id: run.id,
160
+ title: 'Social publication',
161
+ status: run.status === 'pending' ? 'tentative' : 'confirmed',
162
+ range: { allDay: false, start: runAt, duration: 'PT1M', timeZone: 'Etc/UTC' },
163
+ },
164
+ ];
165
+ }
166
+ catch {
167
+ return [];
168
+ }
169
+ }
139
170
  /*** Identify Flow statuses whose durable work is still eligible for future execution. */
140
171
  function isActive(run) {
141
172
  return !['cancelled', 'failed', 'succeeded', 'timed_out'].includes(run.status);
@@ -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.0",
3
+ "version": "0.11.0",
4
4
  "description": "Standalone project identity and repository actions.",
5
5
  "keywords": [
6
6
  "ankhorage",
@@ -68,11 +68,11 @@
68
68
  "@ankhorage/api": "^0.8.0",
69
69
  "@ankhorage/api-fastify": "^0.4.0",
70
70
  "@ankhorage/connection": "^0.3.0",
71
- "@ankhorage/contracts": "^28.0.0",
71
+ "@ankhorage/contracts": "^28.4.0",
72
72
  "@ankhorage/data-sources": "^2.4.0",
73
73
  "@ankhorage/expo-runtime": "^7.11.0",
74
74
  "@ankhorage/flow": "^0.12.0",
75
- "@ankhorage/navigator": "^3.9.0",
75
+ "@ankhorage/navigator": "^3.9.7",
76
76
  "@ankhorage/permissions": "^0.2.64",
77
77
  "@ankhorage/runtime": "^5.8.1",
78
78
  "@ankhorage/secrets": "^0.3.2",
@@ -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",
@@ -713,6 +728,21 @@
713
728
  "label": "List scheduled social publications",
714
729
  "description": "List active caller-owned social publication executions."
715
730
  },
731
+ {
732
+ "id": "projects.social.publications.calendar.list",
733
+ "owner": "@ankhorage/projects",
734
+ "access": [
735
+ "read"
736
+ ],
737
+ "binding": {
738
+ "kind": "action",
739
+ "bindableAs": [
740
+ "target"
741
+ ]
742
+ },
743
+ "label": "List social publication calendar events",
744
+ "description": "List active caller-owned social publications as Calendar events."
745
+ },
716
746
  {
717
747
  "id": "projects.social.publications.history.list",
718
748
  "owner": "@ankhorage/projects",