@imbue-ai/detent 1.14.0 → 1.15.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.
@@ -2048,4 +2048,166 @@ describe('builtin schemas: tailscale', () => {
2048
2048
  }))).toBe(false);
2049
2049
  });
2050
2050
  });
2051
+ describe('builtin schemas: fastmail', () => {
2052
+ /** A JMAP method-call envelope: `POST /jmap/api/` carrying the named calls. */
2053
+ function jmapRequest(methodNames, domain = 'phl.api.fastmail.com') {
2054
+ return makeRequest({
2055
+ domain,
2056
+ method: 'POST',
2057
+ path: '/jmap/api/',
2058
+ parsedBody: {
2059
+ using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'],
2060
+ methodCalls: methodNames.map((name, index) => [name, {}, String(index)]),
2061
+ },
2062
+ });
2063
+ }
2064
+ it('fastmail-api matches the API host, its regional shards, and the blob host', () => {
2065
+ expectSchemaExists('fastmail-api');
2066
+ const api = builtinRegistry.get('fastmail-api');
2067
+ for (const domain of [
2068
+ 'api.fastmail.com',
2069
+ 'phl.api.fastmail.com',
2070
+ 'www.fastmailusercontent.com',
2071
+ 'phl-www.fastmailusercontent.com',
2072
+ ]) {
2073
+ expect(api.match(makeRequest({ domain })), `expected fastmail-api to match ${domain}`).toBe(true);
2074
+ }
2075
+ });
2076
+ it('fastmail-api rejects lookalike and DAV domains', () => {
2077
+ const api = builtinRegistry.get('fastmail-api');
2078
+ // The DAV hosts take a different credential and have their own schemas.
2079
+ expect(api.match(makeRequest({ domain: 'carddav.fastmail.com' }))).toBe(false);
2080
+ expect(api.match(makeRequest({ domain: 'api.fastmail.com.evil.test' }))).toBe(false);
2081
+ expect(api.match(makeRequest({ domain: 'fastmailusercontent.com.evil.test' }))).toBe(false);
2082
+ });
2083
+ it('fastmail-read-all matches read-only method calls, the session document and downloads', () => {
2084
+ expectSchemaExists('fastmail-read-all');
2085
+ const read = builtinRegistry.get('fastmail-read-all');
2086
+ expect(read.match(jmapRequest(['Email/get', 'Mailbox/changes', 'Thread/get']))).toBe(true);
2087
+ expect(read.match(jmapRequest(['Email/query', 'Email/queryChanges']))).toBe(true);
2088
+ expect(read.match(makeRequest({ domain: 'api.fastmail.com', method: 'GET', path: '/jmap/session' }))).toBe(true);
2089
+ expect(read.match(makeRequest({
2090
+ domain: 'phl-www.fastmailusercontent.com',
2091
+ method: 'GET',
2092
+ path: '/jmap/download/u1/G1/message.eml',
2093
+ }))).toBe(true);
2094
+ });
2095
+ it('fastmail-read-all rejects a batch where any single call writes', () => {
2096
+ // JMAP batches many calls into one request, so a read-only grant is only
2097
+ // meaningful if one write anywhere in the envelope disqualifies the whole
2098
+ // request.
2099
+ const read = builtinRegistry.get('fastmail-read-all');
2100
+ expect(read.match(jmapRequest(['Email/set']))).toBe(false);
2101
+ expect(read.match(jmapRequest(['Email/get', 'Email/set']))).toBe(false);
2102
+ expect(read.match(jmapRequest(['Email/get', 'Mailbox/get', 'EmailSubmission/set']))).toBe(false);
2103
+ });
2104
+ it('fastmail-write-all matches writes and blob uploads', () => {
2105
+ expectSchemaExists('fastmail-write-all');
2106
+ const write = builtinRegistry.get('fastmail-write-all');
2107
+ expect(write.match(jmapRequest(['Email/set', 'Mailbox/set']))).toBe(true);
2108
+ expect(write.match(jmapRequest(['Email/import']))).toBe(true);
2109
+ expect(write.match(makeRequest({ domain: 'phl.api.fastmail.com', method: 'POST', path: '/jmap/upload/u1/' }))).toBe(true);
2110
+ expect(write.match(jmapRequest(['Email/get']))).toBe(false);
2111
+ });
2112
+ it('per-capability schemas keep mail, contacts and calendars apart', () => {
2113
+ for (const name of [
2114
+ 'fastmail-read-mail',
2115
+ 'fastmail-read-contacts',
2116
+ 'fastmail-read-calendars',
2117
+ ]) {
2118
+ expectSchemaExists(name);
2119
+ }
2120
+ const mail = builtinRegistry.get('fastmail-read-mail');
2121
+ const contacts = builtinRegistry.get('fastmail-read-contacts');
2122
+ const calendars = builtinRegistry.get('fastmail-read-calendars');
2123
+ expect(mail.match(jmapRequest(['Email/get', 'Mailbox/get']))).toBe(true);
2124
+ expect(mail.match(jmapRequest(['ContactCard/get']))).toBe(false);
2125
+ expect(mail.match(jmapRequest(['CalendarEvent/get']))).toBe(false);
2126
+ expect(contacts.match(jmapRequest(['AddressBook/get', 'ContactCard/query']))).toBe(true);
2127
+ expect(contacts.match(jmapRequest(['Email/get']))).toBe(false);
2128
+ expect(contacts.match(jmapRequest(['ContactCard/set']))).toBe(false);
2129
+ expect(calendars.match(jmapRequest(['Calendar/get', 'CalendarEvent/query']))).toBe(true);
2130
+ expect(calendars.match(jmapRequest(['Email/get']))).toBe(false);
2131
+ });
2132
+ it('fastmail-send-mail is separate from fastmail-write-mail', () => {
2133
+ expectSchemaExists('fastmail-send-mail');
2134
+ const send = builtinRegistry.get('fastmail-send-mail');
2135
+ const writeMail = builtinRegistry.get('fastmail-write-mail');
2136
+ // Sending is externally visible and irreversible, so mailbox writes must not
2137
+ // carry it along.
2138
+ expect(send.match(jmapRequest(['EmailSubmission/set']))).toBe(true);
2139
+ expect(writeMail.match(jmapRequest(['EmailSubmission/set']))).toBe(false);
2140
+ expect(writeMail.match(jmapRequest(['Email/set', 'Mailbox/set']))).toBe(true);
2141
+ });
2142
+ it('fastmail-session covers discovery without exposing content', () => {
2143
+ expectSchemaExists('fastmail-session');
2144
+ const session = builtinRegistry.get('fastmail-session');
2145
+ expect(session.match(makeRequest({ domain: 'api.fastmail.com', method: 'GET', path: '/jmap/session' }))).toBe(true);
2146
+ expect(session.match(makeRequest({ domain: 'api.fastmail.com', method: 'GET', path: '/.well-known/jmap' }))).toBe(true);
2147
+ expect(session.match(jmapRequest(['Email/get']))).toBe(false);
2148
+ });
2149
+ });
2150
+ describe('builtin schemas: fastmail (DAV scope)', () => {
2151
+ it('fastmail-dav-api matches the CardDAV and CalDAV hosts only', () => {
2152
+ expectSchemaExists('fastmail-dav-api');
2153
+ const api = builtinRegistry.get('fastmail-dav-api');
2154
+ for (const domain of ['carddav.fastmail.com', 'caldav.fastmail.com']) {
2155
+ expect(api.match(makeRequest({ domain })), `expected match for ${domain}`).toBe(true);
2156
+ }
2157
+ // The JMAP hosts take a different credential entirely.
2158
+ expect(api.match(makeRequest({ domain: 'api.fastmail.com' }))).toBe(false);
2159
+ expect(api.match(makeRequest({ domain: 'carddav.fastmail.com.evil.test' }))).toBe(false);
2160
+ });
2161
+ it('fastmail-dav read and write split on the DAV method verbs', () => {
2162
+ expectSchemaExists('fastmail-dav-read-all');
2163
+ expectSchemaExists('fastmail-dav-write-all');
2164
+ const read = builtinRegistry.get('fastmail-dav-read-all');
2165
+ const write = builtinRegistry.get('fastmail-dav-write-all');
2166
+ const dav = {
2167
+ domain: 'carddav.fastmail.com',
2168
+ path: '/dav/addressbooks/user/a@b.test/Default/',
2169
+ };
2170
+ for (const method of ['GET', 'PROPFIND', 'REPORT', 'OPTIONS', 'HEAD']) {
2171
+ expect(read.match(makeRequest({ ...dav, method })), `read should match ${method}`).toBe(true);
2172
+ expect(write.match(makeRequest({ ...dav, method })), `write should not match ${method}`).toBe(false);
2173
+ }
2174
+ for (const method of ['PUT', 'DELETE', 'PROPPATCH', 'MKCOL', 'MOVE']) {
2175
+ expect(write.match(makeRequest({ ...dav, method })), `write should match ${method}`).toBe(true);
2176
+ expect(read.match(makeRequest({ ...dav, method })), `read should not match ${method}`).toBe(false);
2177
+ }
2178
+ });
2179
+ it('fastmail-dav per-capability schemas split on collection path', () => {
2180
+ const contacts = builtinRegistry.get('fastmail-dav-read-contacts');
2181
+ const calendars = builtinRegistry.get('fastmail-dav-read-calendars');
2182
+ expect(contacts.match(makeRequest({
2183
+ domain: 'carddav.fastmail.com',
2184
+ method: 'PROPFIND',
2185
+ path: '/dav/addressbooks/user/a@b.test/Default/',
2186
+ }))).toBe(true);
2187
+ expect(contacts.match(makeRequest({
2188
+ domain: 'caldav.fastmail.com',
2189
+ method: 'PROPFIND',
2190
+ path: '/dav/calendars/user/a@b.test/Default/',
2191
+ }))).toBe(false);
2192
+ expect(calendars.match(makeRequest({
2193
+ domain: 'caldav.fastmail.com',
2194
+ method: 'PROPFIND',
2195
+ path: '/dav/calendars/user/a@b.test/Default/',
2196
+ }))).toBe(true);
2197
+ });
2198
+ it('fastmail-dav-discover covers the principal lookup a client must make first', () => {
2199
+ expectSchemaExists('fastmail-dav-discover');
2200
+ const discover = builtinRegistry.get('fastmail-dav-discover');
2201
+ expect(discover.match(makeRequest({
2202
+ domain: 'carddav.fastmail.com',
2203
+ method: 'PROPFIND',
2204
+ path: '/dav/principals/',
2205
+ }))).toBe(true);
2206
+ expect(discover.match(makeRequest({
2207
+ domain: 'carddav.fastmail.com',
2208
+ method: 'PROPFIND',
2209
+ path: '/dav/addressbooks/user/a@b.test/',
2210
+ }))).toBe(false);
2211
+ });
2212
+ });
2051
2213
  //# sourceMappingURL=builtinSchemas.test.js.map