@lantharos/pult 0.9.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/cli.mjs CHANGED
@@ -184,7 +184,7 @@ function actionChanges(prefix) {
184
184
  }
185
185
  //#endregion
186
186
  //#region package.json
187
- var version = "0.9.0";
187
+ var version = "0.11.0";
188
188
  //#endregion
189
189
  //#region ../protocol/src/checks.ts
190
190
  const COLUMNS = [
@@ -294,6 +294,7 @@ function checkManifest(manifest) {
294
294
  message: `${name}.${relation} points at unknown resource "${def.resource}"`
295
295
  });
296
296
  for (const [key, action] of Object.entries(resource.actions)) {
297
+ if (action.moves) checkMoves(manifest, name, key, action.moves, action.source, problems);
297
298
  const inputs = action.input?.properties ?? {};
298
299
  for (const field of [...Object.keys(action.pick), ...action.choices]) if (!inputs[field]) problems.push({
299
300
  source: action.source,
@@ -356,6 +357,17 @@ function checkManifest(manifest) {
356
357
  }
357
358
  return problems;
358
359
  }
360
+ function checkMoves(manifest, resource, key, state, source, problems) {
361
+ const inboxes = Object.values(manifest.inboxes).filter((inbox) => inbox.resource === resource);
362
+ if (!inboxes.length) problems.push({
363
+ source,
364
+ message: `${resource}.${key} moves items, but no inbox is about ${resource}`
365
+ });
366
+ else if (!inboxes.some((inbox) => inbox.states.includes(state))) problems.push({
367
+ source,
368
+ message: `${resource}.${key} moves items to "${state}", which no inbox about ${resource} has`
369
+ });
370
+ }
359
371
  function checkSchedule(name, action, problems) {
360
372
  const { cron, timezone } = action.schedule;
361
373
  try {
@@ -561,6 +573,7 @@ function actionDef(source, key, action) {
561
573
  approval: options.approval ?? false,
562
574
  contextual: Boolean(options.when || options.defaults),
563
575
  background: options.background ?? false,
576
+ moves: options.moves ?? null,
564
577
  pick: options.pick ?? {},
565
578
  choices: Object.keys(options.choices ?? {}),
566
579
  schedule: options.schedule ? schedule(options.schedule) : null
package/index.d.mts CHANGED
@@ -17,6 +17,7 @@ interface IncomingMessage {
17
17
  from: string;
18
18
  subject?: string;
19
19
  text: string;
20
+ attachments?: AttachmentBlock[];
20
21
  }
21
22
  type TriageDecision = {
22
23
  type: "state";
@@ -222,6 +223,9 @@ type Block = {
222
223
  flag: string;
223
224
  state?: FlagState;
224
225
  };
226
+ type AttachmentBlock = Extract<Block, {
227
+ type: "attachment";
228
+ }>;
225
229
  //#endregion
226
230
  //#region ../protocol/src/manifest.d.ts
227
231
  type JsonSchema = {
@@ -258,6 +262,7 @@ interface ActionDef {
258
262
  approval: boolean;
259
263
  contextual: boolean;
260
264
  background: boolean;
265
+ moves: string | null;
261
266
  pick: Record<string, string>;
262
267
  choices: string[];
263
268
  schedule: Schedule | null;
@@ -498,6 +503,7 @@ interface ActionOptions<R, S> {
498
503
  automatable?: boolean;
499
504
  approval?: boolean;
500
505
  background?: boolean;
506
+ moves?: string;
501
507
  when?: (record: R) => boolean;
502
508
  defaults?: (record: R) => Partial<ActionInput<S>>;
503
509
  pick?: { [K in keyof ActionInput<S>]?: string; };
@@ -512,7 +518,7 @@ type ScheduleInput = string | {
512
518
  cron: string;
513
519
  timezone?: string;
514
520
  };
515
- interface StandaloneOptions<S> extends Omit<ActionOptions<null, S>, "when"> {
521
+ interface StandaloneOptions<S> extends Omit<ActionOptions<null, S>, "when" | "moves"> {
516
522
  schedule?: ScheduleInput;
517
523
  }
518
524
  interface Action<R = any, S = any> extends Located, ActionRef {
@@ -960,6 +966,9 @@ interface SendOptions<S extends Schema | undefined, Suggested extends unknown[]
960
966
  tags?: string[];
961
967
  suggest?: { [K in keyof Suggested]: Suggestion<Suggested[K]>; };
962
968
  }
969
+ interface ReceivedMessage extends Omit<IncomingMessage, "attachments"> {
970
+ attachments?: BlockInput[];
971
+ }
963
972
  interface ListenOptions {
964
973
  onStatus?: (status: "connected" | "disconnected") => void;
965
974
  }
@@ -969,7 +978,7 @@ export declare function createPult<Component extends string = string>({ key, pro
969
978
  blocks?: BlockInput[];
970
979
  by?: string;
971
980
  }) => Promise<void>;
972
- receive: (message: IncomingMessage) => Promise<{
981
+ receive: ({ attachments, ...message }: ReceivedMessage) => Promise<{
973
982
  item: string;
974
983
  } | null>;
975
984
  flag: <T, A>(definition: Flag<T, A>, context?: string | FlagContext<A>) => Promise<T>;
@@ -986,4 +995,4 @@ export declare function createPult<Component extends string = string>({ key, pro
986
995
  };
987
996
  type Pult = ReturnType<typeof createPult>;
988
997
  //#endregion
989
- export type { Action, ActionContext, ActionOptions, ActionRef, Actor, Block, BlockInput, ButtonInput, Channel, ComponentState, Config, ConfigOptions, Duration, FieldInput, Flag, FlagContext, FlagOptions, Guard, Inbox, InboxOptions, ItemView, ListOptions, ListQuery, ListenOptions, Manifest, Notify, NotifyOptions, OutgoingEmail, Page, PageContext, PageOptions, Project, Pult, PultOptions, Question, Relation, Resource, ResourceOptions, Role, RoleOptions, Rule, SendOptions, SendResult, Space, SpaceOptions, StandaloneOptions, StateChange, Status, StatusOptions, Suggestion, Triage, View, ViewOptions };
998
+ export type { Action, ActionContext, ActionOptions, ActionRef, Actor, Block, BlockInput, ButtonInput, Channel, ComponentState, Config, ConfigOptions, Duration, FieldInput, Flag, FlagContext, FlagOptions, Guard, Inbox, InboxOptions, ItemView, ListOptions, ListQuery, ListenOptions, Manifest, Notify, NotifyOptions, OutgoingEmail, Page, PageContext, PageOptions, Project, Pult, PultOptions, Question, ReceivedMessage, Relation, Resource, ResourceOptions, Role, RoleOptions, Rule, SendOptions, SendResult, Space, SpaceOptions, StandaloneOptions, StateChange, Status, StatusOptions, Suggestion, Triage, View, ViewOptions };
package/index.mjs CHANGED
@@ -860,9 +860,13 @@ function createPult({ key = env("PULT_KEY"), project, url = env("PULT_URL") ?? "
860
860
  blocks: options.blocks && await upload(options.blocks)
861
861
  });
862
862
  }
863
- async function receive(message) {
863
+ async function receive({ attachments, ...message }) {
864
+ const incoming = attachments?.length ? {
865
+ ...message,
866
+ attachments: (await upload(attachments)).filter(isAttachment)
867
+ } : message;
864
868
  try {
865
- return await transport.request("POST", "/v1/messages", message);
869
+ return await transport.request("POST", "/v1/messages", incoming);
866
870
  } catch (error) {
867
871
  if (error instanceof PultError && error.code === "no_thread") return null;
868
872
  throw error;
@@ -936,6 +940,9 @@ function createPult({ key = env("PULT_KEY"), project, url = env("PULT_URL") ?? "
936
940
  deploy
937
941
  };
938
942
  }
943
+ function isAttachment(block) {
944
+ return block.type === "attachment";
945
+ }
939
946
  function signedHeaders(headers) {
940
947
  const timestamp = headers.get(HEADER.timestamp);
941
948
  const nonce = headers.get(HEADER.nonce);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lantharos/pult",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "The other side of your app",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "bin": {
34
- "pult": "./cli.mjs"
34
+ "pult": "cli.mjs"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"