server-set properties should not be required in create method calls #15

Closed
opened 2024-11-26 00:59:13 +00:00 by kwshi · 3 comments
kwshi commented 2024-11-26 00:59:13 +00:00 (Migrated from github.com)

preface: I'm new to working with JMAP so maybe I'm misunderstanding how things work. but assuming I'm not...

the JMAP spec indicates that "server-set" properties of objects should not be submitted by the client when creating these objects:

server-set – Only the server can set the value for this property. The client MUST NOT send this property when creating a new object of this type.

This seems to be contradicted by the current type annotations on this library. For example, Email object properties id blobId threadId and others marked as server-set (per JMAP Mail spec):

id: Id (immutable; server-set) The id of the Email object. Note that this is the JMAP object id, NOT the Message-ID header field value of the message [@!RFC5322].
blobId: Id (immutable; server-set) The id representing the raw octets of the message [@!RFC5322] for this Email. This may be used to download the raw original message or to attach it directly to another Email, etc.
threadId: Id (immutable; server-set) The id of the Thread to which this Email belongs.

However when trying to create an email using this library with the following code (with tsconfig strict enabled):

import Jam from "jmap-jam";

const env = process.env;

const jam = new Jam({
	bearerToken: env.JMAP_TOKEN!,
	sessionUrl: env.JMAP_URL!,
});

const accountId = await jam.getPrimaryAccount();

await jam.api.Email.set({
	accountId,
	create: {
		testDraftId: {
			subject: "hi",
		},
	},
	ifInState: null,
	update: null,
	destroy: null,
        // some other properties omitted for brevity, e.g. `from` `to` `bodyStructure` `bodyValues`
});

we get a type error saying properties id blobId threadId and others are missing:
image

This seems incorrect, one because it seems to contradict the spec and two because how would I come up with the correct values for these properties when creating an email on the client side?

Also, notice that the email creation example in the JMAP Mail documentation also does not include these fields in the sample request submission.

preface: I'm new to working with JMAP so maybe I'm misunderstanding how things work. but assuming I'm not... the [JMAP spec](https://jmap.io/spec-core.html#notational-conventions) indicates that "server-set" properties of objects should _not_ be submitted by the client when creating these objects: > `server-set` – Only the server can set the value for this property. The client MUST NOT send this property when creating a new object of this type. This seems to be contradicted by the current type annotations on this library. For example, `Email` object properties `id` `blobId` `threadId` and others marked as _server-set_ (per [JMAP Mail spec](https://jmap.io/spec-mail.html#properties-of-the-email-object)): > `id`: `Id` (immutable; server-set) The id of the Email object. Note that this is the JMAP object id, NOT the Message-ID header field value of the message [@!RFC5322]. > `blobId`: `Id` (immutable; server-set) The id representing the raw octets of the message [@!RFC5322] for this Email. This may be used to download the raw original message or to attach it directly to another Email, etc. > `threadId`: `Id` (immutable; server-set) The id of the Thread to which this Email belongs. However when trying to create an email using this library with the following code (with tsconfig strict enabled): ```typescript import Jam from "jmap-jam"; const env = process.env; const jam = new Jam({ bearerToken: env.JMAP_TOKEN!, sessionUrl: env.JMAP_URL!, }); const accountId = await jam.getPrimaryAccount(); await jam.api.Email.set({ accountId, create: { testDraftId: { subject: "hi", }, }, ifInState: null, update: null, destroy: null, // some other properties omitted for brevity, e.g. `from` `to` `bodyStructure` `bodyValues` }); ``` we get a type error saying properties `id` `blobId` `threadId` and others are missing: ![image](https://github.com/user-attachments/assets/17cf2e19-89d5-47e0-8d7f-a62280755899) This seems incorrect, one because it seems to contradict the spec and two because how would I come up with the correct values for these properties when creating an email on the client side? Also, notice that the [email creation example in the JMAP Mail documentation](https://jmap.io/spec-mail.html#examples) also does _not_ include these fields in the sample request submission.
Owner

Thanks for noting this! Likely an oversight on my part when assembling these types. I'll take a closer look!

Thanks for noting this! Likely an oversight on my part when assembling these types. I'll take a closer look!
Owner

This was a really good find. I did not appropriately account for server-set fields (likely because I use JMAP for reading emails rather than writing emails).

I'll focus on fixing this in the next release, but it may be some time until I pick it up to work on.

This was a really good find. I did not appropriately account for server-set fields (likely because I use JMAP for reading emails rather than writing emails). I'll focus on fixing this in the next release, but it may be some time until I pick it up to work on.
Owner

@kwshi I believe v0.8.0 should unblock you, though there is more I'd like to do to improve these types in the future.

Thank you again for raising this issue!

@kwshi I believe [v0.8.0](https://github.com/htunnicliff/jmap-jam/releases/tag/v0.8.0) should unblock you, though there is more I'd like to do to improve these types in the future. Thank you again for raising this issue!
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
htunnicliff/jmap-jam#15
No description provided.