@aeolus-fleet/common 0.22.0 → 0.24.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.
@@ -15,6 +15,7 @@ export * from './network.js';
15
15
  export * from './notice.js';
16
16
  export * from './operator-inbox.js';
17
17
  export * from './ping.js';
18
+ export * from './question.js';
18
19
  export * from './report.js';
19
20
  export * from './ship.js';
20
21
  export * from './system.js';
@@ -15,6 +15,7 @@ export * from './network.js';
15
15
  export * from './notice.js';
16
16
  export * from './operator-inbox.js';
17
17
  export * from './ping.js';
18
+ export * from './question.js';
18
19
  export * from './report.js';
19
20
  export * from './ship.js';
20
21
  export * from './system.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
@@ -15,7 +15,7 @@ export declare const operatorInboxInputSchema: z.ZodObject<{
15
15
  all: "all";
16
16
  }>;
17
17
  }, z.core.$strip>;
18
- /** One message to argo: its delivery's state, when it was read and done, the reply that made it done, and the message. */
18
+ /** One message to argo: its delivery's state, when it was read and done, the reply that made it done, argo's replies to it, and the message. */
19
19
  export declare const inboxMessageSchema: z.ZodObject<{
20
20
  deliveryId: z.ZodType<`dlv_${string}`, unknown, z.core.$ZodTypeInternals<`dlv_${string}`, unknown>>;
21
21
  state: z.ZodEnum<{
@@ -29,6 +29,12 @@ export declare const inboxMessageSchema: z.ZodObject<{
29
29
  readAt: z.ZodNullable<z.ZodISODateTime>;
30
30
  doneAt: z.ZodNullable<z.ZodISODateTime>;
31
31
  repliedWith: z.ZodNullable<z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>>;
32
+ replies: z.ZodArray<z.ZodObject<{
33
+ id: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
34
+ contentType: z.ZodString;
35
+ payload: z.ZodString;
36
+ sentAt: z.ZodISODateTime;
37
+ }, z.core.$strip>>;
32
38
  message: z.ZodObject<{
33
39
  id: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
34
40
  sender: z.ZodObject<{
@@ -57,6 +63,12 @@ export declare const operatorInboxOutputSchema: z.ZodArray<z.ZodObject<{
57
63
  readAt: z.ZodNullable<z.ZodISODateTime>;
58
64
  doneAt: z.ZodNullable<z.ZodISODateTime>;
59
65
  repliedWith: z.ZodNullable<z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>>;
66
+ replies: z.ZodArray<z.ZodObject<{
67
+ id: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
68
+ contentType: z.ZodString;
69
+ payload: z.ZodString;
70
+ sentAt: z.ZodISODateTime;
71
+ }, z.core.$strip>>;
60
72
  message: z.ZodObject<{
61
73
  id: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
62
74
  sender: z.ZodObject<{
@@ -83,11 +95,13 @@ export declare const markDoneInputSchema: z.ZodObject<{
83
95
  }, z.core.$strip>;
84
96
  /**
85
97
  * Input of `fleet.reply`: an answer to a message sent to argo, named by its
86
- * delivery, as plain text to its sender, which also marks the message done.
98
+ * delivery, to its sender, as plain text unless it says another content type,
99
+ * which also marks the message done.
87
100
  */
88
101
  export declare const replyInputSchema: z.ZodObject<{
89
102
  deliveryId: z.ZodType<`dlv_${string}`, unknown, z.core.$ZodTypeInternals<`dlv_${string}`, unknown>>;
90
103
  payload: z.ZodString;
104
+ contentType: z.ZodOptional<z.ZodString>;
91
105
  idempotencyKey: z.ZodString;
92
106
  }, z.core.$strip>;
93
107
  /** Output of `fleet.reply`: the reply. */
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { deliveryStateSchema } from '../fleet/index.js';
3
3
  import { idSchema } from '../ids/index.js';
4
4
  import { partySchema } from './history.js';
5
- import { sendInputSchema } from './message.js';
5
+ import { contentTypeSchema, sendInputSchema } from './message.js';
6
6
  /**
7
7
  * Inputs and outputs of the operator inbox (docs/blueprint.md, "Inbox"): the
8
8
  * messages ships sent to argo. Opening one marks it read; read is not done.
@@ -15,7 +15,7 @@ export const INBOX_FILTERS = ['open', 'done', 'all'];
15
15
  export const inboxFilterSchema = z.enum(INBOX_FILTERS);
16
16
  /** Input of `fleet.inbox`. */
17
17
  export const operatorInboxInputSchema = z.object({ filter: inboxFilterSchema });
18
- /** One message to argo: its delivery's state, when it was read and done, the reply that made it done, and the message. */
18
+ /** One message to argo: its delivery's state, when it was read and done, the reply that made it done, argo's replies to it, and the message. */
19
19
  export const inboxMessageSchema = z.object({
20
20
  deliveryId: idSchema('delivery'),
21
21
  state: deliveryStateSchema,
@@ -25,6 +25,8 @@ export const inboxMessageSchema = z.object({
25
25
  doneAt: isoTime.nullable(),
26
26
  /** The reply that acknowledged it, when a reply did. */
27
27
  repliedWith: idSchema('message').nullable(),
28
+ /** Every reply argo sent to it, oldest first: what a console reads an answer from (decision 0038). */
29
+ replies: z.array(z.object({ id: idSchema('message'), contentType: z.string(), payload: z.string(), sentAt: isoTime })),
28
30
  message: z.object({
29
31
  id: idSchema('message'),
30
32
  sender: partySchema,
@@ -46,11 +48,13 @@ export const inboxActionOutputSchema = z.strictObject({});
46
48
  export const markDoneInputSchema = z.object({ deliveryId: idSchema('delivery') });
47
49
  /**
48
50
  * Input of `fleet.reply`: an answer to a message sent to argo, named by its
49
- * delivery, as plain text to its sender, which also marks the message done.
51
+ * delivery, to its sender, as plain text unless it says another content type,
52
+ * which also marks the message done.
50
53
  */
51
54
  export const replyInputSchema = z.object({
52
55
  deliveryId: idSchema('delivery'),
53
56
  payload: sendInputSchema.shape.payload,
57
+ contentType: contentTypeSchema.optional(),
54
58
  idempotencyKey: sendInputSchema.shape.idempotencyKey,
55
59
  });
56
60
  /** Output of `fleet.reply`: the reply. */
@@ -1 +1 @@
1
- {"version":3,"file":"operator-inbox.js","sourceRoot":"","sources":["../../src/schemas/operator-inbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAA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
+ /**
4
+ * Questions to argo (decision 0038): a ship asks the operator by sending a
5
+ * message of the question content type to argo; the console answers it with a
6
+ * reply of the answer content type. Both payloads are data only: the fleet
7
+ * carries them as any message and never reads them; the console's server
8
+ * does. A question is open until argo
9
+ * sends its answer, whatever its delivery's state. The asking ship withdraws
10
+ * a question, or replaces it with a new one, by a message of its own content
11
+ * type naming the question's uuid.
12
+ */
13
+ export declare const QUESTION_CONTENT_TYPE = "application/vnd.aeolus.question+json";
14
+ export declare const ANSWER_CONTENT_TYPE = "application/vnd.aeolus.answer+json";
15
+ export declare const WITHDRAWAL_CONTENT_TYPE = "application/vnd.aeolus.question-withdrawal+json";
16
+ export declare const REPLACEMENT_CONTENT_TYPE = "application/vnd.aeolus.question-replacement+json";
17
+ export declare function isQuestionContentType(contentType: string): boolean;
18
+ export declare function isAnswerContentType(contentType: string): boolean;
19
+ export declare function isWithdrawalContentType(contentType: string): boolean;
20
+ export declare function isReplacementContentType(contentType: string): boolean;
21
+ /** A question: its own uuid, a title, the context to answer from, numbered options, and the asker's pick and why. */
22
+ export declare const questionSchema: z.ZodObject<{
23
+ id: z.ZodUUID;
24
+ title: z.ZodString;
25
+ context: z.ZodString;
26
+ options: z.ZodArray<z.ZodObject<{
27
+ key: z.ZodInt;
28
+ label: z.ZodString;
29
+ detail: z.ZodString;
30
+ }, z.core.$strip>>;
31
+ pick: z.ZodObject<{
32
+ option: z.ZodInt;
33
+ why: z.ZodString;
34
+ }, z.core.$strip>;
35
+ }, z.core.$strip>;
36
+ export type Question = z.infer<typeof questionSchema>;
37
+ /** A withdrawal: the uuid of the question the asker withdraws. */
38
+ export declare const withdrawalSchema: z.ZodObject<{
39
+ questionId: z.ZodUUID;
40
+ }, z.core.$strip>;
41
+ /** A replacement: the uuid of the question the asker replaces, and the new question, with a uuid of its own. */
42
+ export declare const replacementSchema: z.ZodObject<{
43
+ questionId: z.ZodUUID;
44
+ question: z.ZodObject<{
45
+ id: z.ZodUUID;
46
+ title: z.ZodString;
47
+ context: z.ZodString;
48
+ options: z.ZodArray<z.ZodObject<{
49
+ key: z.ZodInt;
50
+ label: z.ZodString;
51
+ detail: z.ZodString;
52
+ }, z.core.$strip>>;
53
+ pick: z.ZodObject<{
54
+ option: z.ZodInt;
55
+ why: z.ZodString;
56
+ }, z.core.$strip>;
57
+ }, z.core.$strip>;
58
+ }, z.core.$strip>;
59
+ /** What the operator answers: one option and an optional note, or a note alone (more context needed, or none of the options). */
60
+ export declare const answerChoiceSchema: z.ZodUnion<readonly [z.ZodObject<{
61
+ option: z.ZodInt;
62
+ note: z.ZodOptional<z.ZodString>;
63
+ }, z.core.$strip>, z.ZodObject<{
64
+ note: z.ZodString;
65
+ }, z.core.$strip>]>;
66
+ export type AnswerChoice = z.infer<typeof answerChoiceSchema>;
67
+ /** An answer: the question's uuid, and one option plus an optional note, or a note alone. */
68
+ export declare const answerSchema: z.ZodUnion<readonly [z.ZodObject<{
69
+ questionId: z.ZodUUID;
70
+ option: z.ZodInt;
71
+ note: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strip>, z.ZodObject<{
73
+ questionId: z.ZodUUID;
74
+ note: z.ZodString;
75
+ }, z.core.$strip>]>;
76
+ export type Answer = z.infer<typeof answerSchema>;
77
+ /** The answer a question in argo's inbox has: the reply that carries it, when, and what it says. */
78
+ export declare const inboxAnswerSchema: z.ZodObject<{
79
+ messageId: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
80
+ sentAt: z.ZodISODateTime;
81
+ option: z.ZodNullable<z.ZodInt>;
82
+ note: z.ZodNullable<z.ZodString>;
83
+ }, z.core.$strip>;
84
+ /** A question in argo's inbox, with its answer; null while it is open. */
85
+ export declare const inboxQuestionSchema: z.ZodObject<{
86
+ id: z.ZodUUID;
87
+ title: z.ZodString;
88
+ context: z.ZodString;
89
+ options: z.ZodArray<z.ZodObject<{
90
+ key: z.ZodInt;
91
+ label: z.ZodString;
92
+ detail: z.ZodString;
93
+ }, z.core.$strip>>;
94
+ pick: z.ZodObject<{
95
+ option: z.ZodInt;
96
+ why: z.ZodString;
97
+ }, z.core.$strip>;
98
+ answer: z.ZodNullable<z.ZodObject<{
99
+ messageId: z.ZodType<`msg_${string}`, unknown, z.core.$ZodTypeInternals<`msg_${string}`, unknown>>;
100
+ sentAt: z.ZodISODateTime;
101
+ option: z.ZodNullable<z.ZodInt>;
102
+ note: z.ZodNullable<z.ZodString>;
103
+ }, z.core.$strip>>;
104
+ }, z.core.$strip>;
105
+ export type InboxQuestion = z.infer<typeof inboxQuestionSchema>;
106
+ interface Carried {
107
+ contentType: string;
108
+ payload: string;
109
+ }
110
+ /**
111
+ * The question a message withdraws, and the new question when it replaces it;
112
+ * null when the message is neither a withdrawal nor a replacement.
113
+ */
114
+ export declare function withdrawalOf({ contentType, payload }: Carried): {
115
+ questionId: string;
116
+ replacement: Question | null;
117
+ } | null;
118
+ /**
119
+ * The question a message to argo asks (a question, or the new question of a
120
+ * replacement), and its answer among argo's replies
121
+ * to it (the first answer naming the question); null when the message asks
122
+ * no question.
123
+ */
124
+ export declare function inboxQuestionOf<T>({ message, replies, }: {
125
+ message: Carried;
126
+ replies: readonly (Carried & {
127
+ id: MessageId;
128
+ sentAt: T;
129
+ })[];
130
+ }): (Question & {
131
+ answer: {
132
+ messageId: MessageId;
133
+ sentAt: T;
134
+ option: number | null;
135
+ note: string | null;
136
+ } | null;
137
+ }) | null;
138
+ export {};
@@ -0,0 +1,154 @@
1
+ import { z } from 'zod';
2
+ import { idSchema } from '../ids/index.js';
3
+ /**
4
+ * Questions to argo (decision 0038): a ship asks the operator by sending a
5
+ * message of the question content type to argo; the console answers it with a
6
+ * reply of the answer content type. Both payloads are data only: the fleet
7
+ * carries them as any message and never reads them; the console's server
8
+ * does. A question is open until argo
9
+ * sends its answer, whatever its delivery's state. The asking ship withdraws
10
+ * a question, or replaces it with a new one, by a message of its own content
11
+ * type naming the question's uuid.
12
+ */
13
+ export const QUESTION_CONTENT_TYPE = 'application/vnd.aeolus.question+json';
14
+ export const ANSWER_CONTENT_TYPE = 'application/vnd.aeolus.answer+json';
15
+ export const WITHDRAWAL_CONTENT_TYPE = 'application/vnd.aeolus.question-withdrawal+json';
16
+ export const REPLACEMENT_CONTENT_TYPE = 'application/vnd.aeolus.question-replacement+json';
17
+ /** A content type's essence: media types compare without case and without their parameters (RFC 9110). */
18
+ function essenceOf(contentType) {
19
+ const [essence = ''] = contentType.split(';');
20
+ return essence.trim().toLowerCase();
21
+ }
22
+ export function isQuestionContentType(contentType) {
23
+ return essenceOf(contentType) === QUESTION_CONTENT_TYPE;
24
+ }
25
+ export function isAnswerContentType(contentType) {
26
+ return essenceOf(contentType) === ANSWER_CONTENT_TYPE;
27
+ }
28
+ export function isWithdrawalContentType(contentType) {
29
+ return essenceOf(contentType) === WITHDRAWAL_CONTENT_TYPE;
30
+ }
31
+ export function isReplacementContentType(contentType) {
32
+ return essenceOf(contentType) === REPLACEMENT_CONTENT_TYPE;
33
+ }
34
+ const FIRST_OPTION = 1;
35
+ /** An option's number, from 1. */
36
+ const optionKeySchema = z.int().min(FIRST_OPTION);
37
+ const textSchema = z.string().min(1);
38
+ const optionSchema = z.object({ key: optionKeySchema, label: textSchema, detail: z.string() });
39
+ /** A question: its own uuid, a title, the context to answer from, numbered options, and the asker's pick and why. */
40
+ export const questionSchema = z
41
+ .object({
42
+ id: z.uuid(),
43
+ title: textSchema,
44
+ context: z.string(),
45
+ options: z.array(optionSchema).min(1),
46
+ pick: z.object({ option: optionKeySchema, why: textSchema }),
47
+ })
48
+ .refine(({ options }) => new Set(options.map(({ key }) => key)).size === options.length, {
49
+ message: 'Every option has its own number',
50
+ path: ['options'],
51
+ })
52
+ .refine(({ options, pick }) => options.some(({ key }) => key === pick.option), {
53
+ message: 'The pick names one of the options',
54
+ path: ['pick', 'option'],
55
+ });
56
+ /** A withdrawal: the uuid of the question the asker withdraws. */
57
+ export const withdrawalSchema = z.object({ questionId: z.uuid() });
58
+ /** A replacement: the uuid of the question the asker replaces, and the new question, with a uuid of its own. */
59
+ export const replacementSchema = z
60
+ .object({ questionId: z.uuid(), question: questionSchema })
61
+ .refine(({ questionId, question }) => question.id !== questionId, {
62
+ message: 'The new question has a uuid of its own',
63
+ path: ['question', 'id'],
64
+ });
65
+ /** What the operator answers: one option and an optional note, or a note alone (more context needed, or none of the options). */
66
+ export const answerChoiceSchema = z.union([
67
+ z.object({ option: optionKeySchema, note: textSchema.optional() }),
68
+ z.object({ note: textSchema }),
69
+ ]);
70
+ /** An answer: the question's uuid, and one option plus an optional note, or a note alone. */
71
+ export const answerSchema = z.union([
72
+ z.object({ questionId: z.uuid(), option: optionKeySchema, note: textSchema.optional() }),
73
+ z.object({ questionId: z.uuid(), note: textSchema }),
74
+ ]);
75
+ /** The answer a question in argo's inbox has: the reply that carries it, when, and what it says. */
76
+ export const inboxAnswerSchema = z.object({
77
+ messageId: idSchema('message'),
78
+ sentAt: z.iso.datetime(),
79
+ option: optionKeySchema.nullable(),
80
+ note: z.string().nullable(),
81
+ });
82
+ /** A question in argo's inbox, with its answer; null while it is open. */
83
+ export const inboxQuestionSchema = z.object({
84
+ id: z.uuid(),
85
+ title: z.string(),
86
+ context: z.string(),
87
+ options: z.array(optionSchema),
88
+ pick: z.object({ option: optionKeySchema, why: z.string() }),
89
+ answer: inboxAnswerSchema.nullable(),
90
+ });
91
+ /** A payload as JSON; undefined when it is not JSON. */
92
+ function jsonOf(payload) {
93
+ try {
94
+ return JSON.parse(payload);
95
+ }
96
+ catch {
97
+ return undefined;
98
+ }
99
+ }
100
+ /** The question a message asks: a question's payload, or the new question a replacement carries; null for any other message. */
101
+ function questionOf({ contentType, payload }) {
102
+ if (isQuestionContentType(contentType)) {
103
+ const question = questionSchema.safeParse(jsonOf(payload));
104
+ return question.success ? question.data : null;
105
+ }
106
+ if (isReplacementContentType(contentType)) {
107
+ const replacement = replacementSchema.safeParse(jsonOf(payload));
108
+ return replacement.success ? replacement.data.question : null;
109
+ }
110
+ return null;
111
+ }
112
+ /**
113
+ * The question a message withdraws, and the new question when it replaces it;
114
+ * null when the message is neither a withdrawal nor a replacement.
115
+ */
116
+ export function withdrawalOf({ contentType, payload }) {
117
+ if (isWithdrawalContentType(contentType)) {
118
+ const withdrawal = withdrawalSchema.safeParse(jsonOf(payload));
119
+ return withdrawal.success ? { questionId: withdrawal.data.questionId, replacement: null } : null;
120
+ }
121
+ if (isReplacementContentType(contentType)) {
122
+ const replacement = replacementSchema.safeParse(jsonOf(payload));
123
+ return replacement.success ? { questionId: replacement.data.questionId, replacement: replacement.data.question } : null;
124
+ }
125
+ return null;
126
+ }
127
+ /**
128
+ * The question a message to argo asks (a question, or the new question of a
129
+ * replacement), and its answer among argo's replies
130
+ * to it (the first answer naming the question); null when the message asks
131
+ * no question.
132
+ */
133
+ export function inboxQuestionOf({ message, replies, }) {
134
+ const question = questionOf(message);
135
+ if (question === null) {
136
+ return null;
137
+ }
138
+ for (const reply of replies) {
139
+ const answer = isAnswerContentType(reply.contentType) ? answerSchema.safeParse(jsonOf(reply.payload)) : undefined;
140
+ if (answer?.success === true && answer.data.questionId === question.id) {
141
+ return {
142
+ ...question,
143
+ answer: {
144
+ messageId: reply.id,
145
+ sentAt: reply.sentAt,
146
+ option: 'option' in answer.data ? answer.data.option : null,
147
+ note: answer.data.note ?? null,
148
+ },
149
+ };
150
+ }
151
+ }
152
+ return { ...question, answer: null };
153
+ }
154
+ //# sourceMappingURL=question.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question.js","sourceRoot":"","sources":["../../src/schemas/question.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAkB,MAAM,iBAAiB,CAAC;AAE3D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,sCAAsC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,oCAAoC,CAAC;AACxE,MAAM,CAAC,MAAM,uBAAu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,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;oBAC3D,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI;iBAC/B;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACvC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@aeolus-fleet/common",
3
- "version": "0.22.0",
4
- "description": "Aeolus shared schemas, prefixed ids and types.",
3
+ "version": "0.24.0",
4
+ "description": "Shared schemas and ids for Aeolus packages.",
5
+ "keywords": [
6
+ "aeolus"
7
+ ],
5
8
  "license": "Apache-2.0",
6
9
  "type": "module",
7
10
  "sideEffects": false,