From 884d96b255e93661706d813f5c358b2eb8261650 Mon Sep 17 00:00:00 2001 From: Yannick Malins Date: Mon, 15 Jul 2024 10:54:49 +0200 Subject: [PATCH 1/3] 1255 - split off fileAttachment --- schemas/context/fileAttachment.schema.json | 53 ++++++++++++++++++++++ schemas/context/message.schema.json | 33 +------------- 2 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 schemas/context/fileAttachment.schema.json diff --git a/schemas/context/fileAttachment.schema.json b/schemas/context/fileAttachment.schema.json new file mode 100644 index 000000000..e6278dbf9 --- /dev/null +++ b/schemas/context/fileAttachment.schema.json @@ -0,0 +1,53 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://fdc3.finos.org/schemas/next/context/attachment.schema.json", + "type": "object", + "title": "File Attachment", + "description": "A File attachment encoded in the form of a data URI. Can be added to a Message.", + "allOf": [ + { + "type": "object", + "properties": { + "type": { + "const": "fdc3.fileAttachment" + }, + "data": { + "type": "object", + "properties": { + "name": { + "type": "string", + "title": "File name", + "description": "The name of the attached file" + }, + "dataUri": { + "type": "string", + "format": "uri", + "title": "", + "description": "A data URI encoding the content of the file to be attached" + } + }, + "required": [ + "name", + "dataUri" + ] + } + }, + "required": [ + "type", + "data" + ] + }, + { + "$ref": "context.schema.json#/definitions/BaseContext" + } + ], + "examples": [ + { + "type": "fdc3.fileAttachment", + "data": { + "name": "myImage.png", + "dataUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII" + } + } + ] +} \ No newline at end of file diff --git a/schemas/context/message.schema.json b/schemas/context/message.schema.json index b776eb11e..3b4e57533 100644 --- a/schemas/context/message.schema.json +++ b/schemas/context/message.schema.json @@ -38,38 +38,7 @@ "$ref": "action.schema.json#" }, { - "type": "object", - "title": "File attachment", - "description": "A File attachment encoded in the form of a data URI", - "properties": { - "type": { - "const": "fdc3.entity.fileAttachment" - }, - "data": { - "type": "object", - "properties": { - "name": { - "type": "string", - "title": "File name", - "description": "The name of the attached file" - }, - "dataUri": { - "type": "string", - "format": "uri", - "title": "", - "description": "A data URI encoding the content of the file to be attached" - } - }, - "required": [ - "name", - "dataUri" - ] - } - }, - "required": [ - "type", - "data" - ] + "$ref": "fileAttachment.schema.json#" } ] } From 1dbc92231d852affa10a4e6c2f3fb03a4326b58b Mon Sep 17 00:00:00 2001 From: Yannick Malins Date: Fri, 11 Oct 2024 11:38:47 +0200 Subject: [PATCH 2/3] kris review --- CHANGELOG.md | 1 + schemas/context/fileAttachment.schema.json | 2 +- schemas/context/message.schema.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ab34252..bf0ea3d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +* Spin off fileAttachment into its own schema, and correct related examples ([1255](https://github.com/finos/FDC3/issues/1255)) * Added missing `desktopAgent` field to ImplementationMetadata objects returned for all agents connect to a DesktopAgent bridge in Connection Step 6 connectAgentsUpdate messages and refined the schema used to collect this info in step 3 handshake. ([#1177](https://github.com/finos/FDC3/pull/1177)) * Removed the `version` field from `IntentResolution` as there are no version fields for intents in the FDC3 API definitions and hence the field has no purpose. ([#1170](https://github.com/finos/FDC3/pull/1170)) diff --git a/schemas/context/fileAttachment.schema.json b/schemas/context/fileAttachment.schema.json index e6278dbf9..b049af8c3 100644 --- a/schemas/context/fileAttachment.schema.json +++ b/schemas/context/fileAttachment.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://fdc3.finos.org/schemas/next/context/attachment.schema.json", + "$id": "https://fdc3.finos.org/schemas/next/context/fileAttachment.schema.json", "type": "object", "title": "File Attachment", "description": "A File attachment encoded in the form of a data URI. Can be added to a Message.", diff --git a/schemas/context/message.schema.json b/schemas/context/message.schema.json index 3b4e57533..ac4b34ba1 100644 --- a/schemas/context/message.schema.json +++ b/schemas/context/message.schema.json @@ -33,7 +33,7 @@ "title": "Message entities", "description": "A map of string IDs to entities that should be attached to the message, such as an action to perform, a file attachment, or other FDC3 context object.", "additionalProperties": { - "anyOf": [ + "oneOf": [ { "$ref": "action.schema.json#" }, From 92ecb7af53eaf50f2bbac797ab49eededc7a6477 Mon Sep 17 00:00:00 2001 From: Yannick Malins Date: Wed, 16 Oct 2024 08:54:25 +0200 Subject: [PATCH 3/3] build --- src/context/ContextTypes.ts | 167 ++++++++++++++---------------------- 1 file changed, 66 insertions(+), 101 deletions(-) diff --git a/src/context/ContextTypes.ts b/src/context/ContextTypes.ts index 6c6536614..8324b91c8 100644 --- a/src/context/ContextTypes.ts +++ b/src/context/ContextTypes.ts @@ -1,6 +1,6 @@ // To parse this data: // -// import { Convert, Action, Chart, ChatInitSettings, ChatMessage, ChatRoom, ChatSearchCriteria, Contact, ContactList, Context, Country, Currency, Email, Instrument, InstrumentList, Interaction, Message, Nothing, Order, OrderList, Organization, Portfolio, Position, Product, TimeRange, Trade, TradeList, TransactionResult, Valuation } from "./file"; +// import { Convert, Action, Chart, ChatInitSettings, ChatMessage, ChatRoom, ChatSearchCriteria, Contact, ContactList, Context, Country, Currency, Email, FileAttachment, Instrument, InstrumentList, Interaction, Message, Nothing, Order, OrderList, Organization, Portfolio, Position, Product, TimeRange, Trade, TradeList, TransactionResult, Valuation } from "./file"; // // const action = Convert.toAction(json); // const chart = Convert.toChart(json); @@ -14,6 +14,7 @@ // const country = Convert.toCountry(json); // const currency = Convert.toCurrency(json); // const email = Convert.toEmail(json); +// const fileAttachment = Convert.toFileAttachment(json); // const instrument = Convert.toInstrument(json); // const instrumentList = Convert.toInstrumentList(json); // const interaction = Convert.toInteraction(json); @@ -548,7 +549,7 @@ export interface MessageObject { * A map of string IDs to entities that should be attached to the message, such as an action * to perform, a file attachment, or other FDC3 context object. */ - entities?: { [key: string]: PurpleAction }; + entities?: { [key: string]: EntityValue }; /** * A map of string mime-type to string content */ @@ -572,9 +573,9 @@ export interface MessageObject { * * Accepts an optional `app` parameter in order to specify a specific app. * - * A File attachment encoded in the form of a data URI + * A File attachment encoded in the form of a data URI. Can be added to a Message. */ -export interface PurpleAction { +export interface EntityValue { /** * The **action** field indicates the type of action: * - **raiseIntent** : If no action or `raiseIntent` is specified, then `fdc3.raiseIntent` @@ -614,11 +615,11 @@ export interface PurpleAction { type: EntityType; id?: { [key: string]: any }; name?: string; - data?: PurpleData; + data?: EntityData; [property: string]: any; } -export interface PurpleData { +export interface EntityData { /** * A data URI encoding the content of the file to be attached */ @@ -636,7 +637,7 @@ export interface PurpleData { * `interactionType` SHOULD be one of `'Instant Message'`, `'Email'`, `'Call'`, or * `'Meeting'` although other string values are permitted. */ -export type EntityType = "fdc3.action" | "fdc3.entity.fileAttachment"; +export type EntityType = "fdc3.action" | "fdc3.fileAttachment"; /** * A map of string mime-type to string content @@ -1221,6 +1222,36 @@ export interface ContactTIdentifiers { */ export type EmailRecipientsType = "fdc3.contact" | "fdc3.contactList"; +/** + * Free text to be used for a keyword search + * + * `interactionType` SHOULD be one of `'Instant Message'`, `'Email'`, `'Call'`, or + * `'Meeting'` although other string values are permitted. + */ + +/** + * A File attachment encoded in the form of a data URI. Can be added to a Message. + */ +export interface FileAttachment { + data: FileAttachmentData; + type: "fdc3.fileAttachment"; + id?: { [key: string]: any }; + name?: string; + [property: string]: any; +} + +export interface FileAttachmentData { + /** + * A data URI encoding the content of the file to be attached + */ + dataUri: string; + /** + * The name of the attached file + */ + name: string; + [property: string]: any; +} + /** * Free text to be used for a keyword search * @@ -1466,7 +1497,7 @@ export interface Message { * A map of string IDs to entities that should be attached to the message, such as an action * to perform, a file attachment, or other FDC3 context object. */ - entities?: { [key: string]: FluffyAction }; + entities?: { [key: string]: EntityValue }; /** * A map of string mime-type to string content */ @@ -1477,77 +1508,6 @@ export interface Message { [property: string]: any; } -/** - * A representation of an FDC3 Action (specified via a Context or Context & Intent) that can - * be inserted inside another object, for example a chat message. - * - * The action may be completed by calling: - * - `fdc3.raiseIntent()` with the specified Intent and Context - * - `fdc3.raiseIntentForContext()` if only a context is specified, (which the Desktop Agent - * will resolve by presenting the user with a list of available Intents for the Context). - * - `channel.broadcast()` with the specified Context, if the `broadcast` action has been - * defined. - * - * Accepts an optional `app` parameter in order to specify a specific app. - * - * A File attachment encoded in the form of a data URI - */ -export interface FluffyAction { - /** - * The **action** field indicates the type of action: - * - **raiseIntent** : If no action or `raiseIntent` is specified, then `fdc3.raiseIntent` - * or `fdc3.raiseIntentForContext` will be called with the specified context (and intent if - * given). - * - **broadcast** : If `broadcast` and a `channelId` are specified then - * `fdc3.getOrCreateChannel(channelId)` is called to retrieve the channel and broadcast the - * context to it with `channel.broadcast(context)`. If no `channelId` has been specified, - * the context should be broadcast to the current channel (`fdc3.broadcast()`) - */ - action?: ActionType; - /** - * An optional target application identifier that should perform the action. The `app` - * property is ignored unless the action is raiseIntent. - */ - app?: AppIdentifier; - /** - * Optional channel on which to broadcast the context. The `channelId` property is ignored - * unless the `action` is broadcast. - */ - channelId?: string; - /** - * A context object with which the action will be performed - */ - context?: ContextElement; - /** - * Optional Intent to raise to perform the actions. Should reference an intent type name, - * such as those defined in the FDC3 Standard. If intent is not set then - * `fdc3.raiseIntentForContext` should be used to perform the action as this will usually - * allow the user to choose the intent to raise. - */ - intent?: string; - /** - * A human readable display name for the action - */ - title?: string; - type: EntityType; - id?: { [key: string]: any }; - name?: string; - data?: FluffyData; - [property: string]: any; -} - -export interface FluffyData { - /** - * A data URI encoding the content of the file to be attached - */ - dataUri: string; - /** - * The name of the attached file - */ - name: string; - [property: string]: any; -} - /** * A map of string mime-type to string content */ @@ -2265,6 +2225,14 @@ export class Convert { return JSON.stringify(uncast(value, r("Email")), null, 2); } + public static toFileAttachment(json: string): FileAttachment { + return cast(JSON.parse(json), r("FileAttachment")); + } + + public static fileAttachmentToJson(value: FileAttachment): string { + return JSON.stringify(uncast(value, r("FileAttachment")), null, 2); + } + public static toInstrument(json: string): Instrument { return cast(JSON.parse(json), r("Instrument")); } @@ -2632,13 +2600,13 @@ const typeMap: any = { { json: "FDS_ID", js: "FDS_ID", typ: u(undefined, "") }, ], "any"), "MessageObject": o([ - { json: "entities", js: "entities", typ: u(undefined, m(r("PurpleAction"))) }, + { json: "entities", js: "entities", typ: u(undefined, m(r("EntityValue"))) }, { json: "text", js: "text", typ: u(undefined, r("PurpleMessageText")) }, { json: "type", js: "type", typ: r("MessageType") }, { json: "id", js: "id", typ: u(undefined, m("any")) }, { json: "name", js: "name", typ: u(undefined, "") }, ], "any"), - "PurpleAction": o([ + "EntityValue": o([ { json: "action", js: "action", typ: u(undefined, r("ActionType")) }, { json: "app", js: "app", typ: u(undefined, r("AppIdentifier")) }, { json: "channelId", js: "channelId", typ: u(undefined, "") }, @@ -2648,9 +2616,9 @@ const typeMap: any = { { json: "type", js: "type", typ: r("EntityType") }, { json: "id", js: "id", typ: u(undefined, m("any")) }, { json: "name", js: "name", typ: u(undefined, "") }, - { json: "data", js: "data", typ: u(undefined, r("PurpleData")) }, + { json: "data", js: "data", typ: u(undefined, r("EntityData")) }, ], "any"), - "PurpleData": o([ + "EntityData": o([ { json: "dataUri", js: "dataUri", typ: "" }, { json: "name", js: "name", typ: "" }, ], "any"), @@ -2768,6 +2736,16 @@ const typeMap: any = { { json: "email", js: "email", typ: u(undefined, "") }, { json: "FDS_ID", js: "FDS_ID", typ: u(undefined, "") }, ], "any"), + "FileAttachment": o([ + { json: "data", js: "data", typ: r("FileAttachmentData") }, + { json: "type", js: "type", typ: r("FileAttachmentType") }, + { json: "id", js: "id", typ: u(undefined, m("any")) }, + { json: "name", js: "name", typ: u(undefined, "") }, + ], "any"), + "FileAttachmentData": o([ + { json: "dataUri", js: "dataUri", typ: "" }, + { json: "name", js: "name", typ: "" }, + ], "any"), "Instrument": o([ { json: "id", js: "id", typ: r("FluffyInstrumentIdentifiers") }, { json: "market", js: "market", typ: u(undefined, r("PurpleMarket")) }, @@ -2814,28 +2792,12 @@ const typeMap: any = { { json: "URI", js: "URI", typ: u(undefined, "") }, ], "any"), "Message": o([ - { json: "entities", js: "entities", typ: u(undefined, m(r("FluffyAction"))) }, + { json: "entities", js: "entities", typ: u(undefined, m(r("EntityValue"))) }, { json: "text", js: "text", typ: u(undefined, r("FluffyMessageText")) }, { json: "type", js: "type", typ: r("MessageType") }, { json: "id", js: "id", typ: u(undefined, m("any")) }, { json: "name", js: "name", typ: u(undefined, "") }, ], "any"), - "FluffyAction": o([ - { json: "action", js: "action", typ: u(undefined, r("ActionType")) }, - { json: "app", js: "app", typ: u(undefined, r("AppIdentifier")) }, - { json: "channelId", js: "channelId", typ: u(undefined, "") }, - { json: "context", js: "context", typ: u(undefined, r("ContextElement")) }, - { json: "intent", js: "intent", typ: u(undefined, "") }, - { json: "title", js: "title", typ: u(undefined, "") }, - { json: "type", js: "type", typ: r("EntityType") }, - { json: "id", js: "id", typ: u(undefined, m("any")) }, - { json: "name", js: "name", typ: u(undefined, "") }, - { json: "data", js: "data", typ: u(undefined, r("FluffyData")) }, - ], "any"), - "FluffyData": o([ - { json: "dataUri", js: "dataUri", typ: "" }, - { json: "name", js: "name", typ: "" }, - ], "any"), "FluffyMessageText": o([ { json: "text/markdown", js: "text/markdown", typ: u(undefined, "") }, { json: "text/plain", js: "text/plain", typ: u(undefined, "") }, @@ -2990,7 +2952,7 @@ const typeMap: any = { ], "EntityType": [ "fdc3.action", - "fdc3.entity.fileAttachment", + "fdc3.fileAttachment", ], "MessageType": [ "fdc3.message", @@ -3025,6 +2987,9 @@ const typeMap: any = { "EmailType": [ "fdc3.email", ], + "FileAttachmentType": [ + "fdc3.fileAttachment", + ], "InstrumentListType": [ "fdc3.instrumentList", ],