@yolk-sdk/emulators 0.1.0-canary.104 → 0.1.0-canary.106

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/README.md CHANGED
@@ -1606,7 +1606,11 @@ origin its fixtures record: Gmail (the API and the multipart send upload) on
1606
1606
  `https://gmail.googleapis.com` (`googleEmulatorGmailOrigin`), Calendar and Drive on
1607
1607
  `https://www.googleapis.com` (`googleEmulatorApisOrigin`). `fetch` takes the origin from the request
1608
1608
  URL (in-process routing keeps it); behind a loopback rewrite, which loses it, serve
1609
- `fetchOn(origin)` for each origin on its own server:
1609
+ `fetchOn(origin)` for each origin on its own server. Draft attachments are not emulated:
1610
+ `gmail.draft_compose`, `gmail.draft_update`, and `gmail.draft_reply` with `attachments` write
1611
+ through the draft media upload (`POST /upload/gmail/v1/users/me/drafts?uploadType=multipart`, or
1612
+ `PUT .../drafts/{id}?uploadType=multipart`), which no fixture records, so it answers the constant
1613
+ unrecognised 400 until a draft-attachment case is recorded live. To serve both origins:
1610
1614
 
1611
1615
  ```ts
1612
1616
  import {
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.mts","names":[],"sources":["../src/google.ts"],"mappings":";;;;;;;;AAwKsE;AAQtE;;cARa,oBAAA,EAAsB,aAAa,CAAC,qBAAA;;;;;;cAQpC,gBAAA,0BAAgB,MAAA;EAAA;;;;KAEjB,gBAAA,UAA0B,kBAAA,CAAmB,IAAI;;;AAA7D;;;;AAA6D;cAShD,WAAA,0BAAW,MAAA;EAAA;;;;;;;;;;;KAEZ,WAAA,GAAc,aAAa;AAAA,KAE3B,gBAAA,GAAmB,kBAAkB;AAAA,KAErC,iBAAA,GAAoB,mBAAmB;AAAA,KAEvC,cAAA,GAAiB,gBAAgB;AAAA,cAAA,+BAAA;;;;cAGhC,0BAAA,SAAmC,+BAAA;EAAA,SACrC,KAAA,EAAO,iBAAA;EAAA,SACP,MAAA;AAAA;EAAA,IAEI,OAAA,CAAA;AAAA;AAAA,KAKH,qBAAA;sFAED,IAAA,GAAO,kBAAA;;;;;WAKP,GAAA;WAEA,MAAA,GAAS,oBAAoB;AAAA;AAAA,KAG5B,cAAA,GAAiB,mBAAA,CAAoB,mBAAA,EAAqB,kBAAA;;;AA9B/B;AAEvC;;cA6Ca,kBAAA,GACX,OAAA,GAAS,qBAAA,KACR,OAAA,CAAQ,cAAA"}
1
+ {"version":3,"file":"google.d.mts","names":[],"sources":["../src/google.ts"],"mappings":";;;;;;;;AA2KsE;AAQtE;;cARa,oBAAA,EAAsB,aAAa,CAAC,qBAAA;;;;;;cAQpC,gBAAA,0BAAgB,MAAA;EAAA;;;;KAEjB,gBAAA,UAA0B,kBAAA,CAAmB,IAAI;;;AAA7D;;;;AAA6D;cAShD,WAAA,0BAAW,MAAA;EAAA;;;;;;;;;;;KAEZ,WAAA,GAAc,aAAa;AAAA,KAE3B,gBAAA,GAAmB,kBAAkB;AAAA,KAErC,iBAAA,GAAoB,mBAAmB;AAAA,KAEvC,cAAA,GAAiB,gBAAgB;AAAA,cAAA,+BAAA;;;;cAGhC,0BAAA,SAAmC,+BAAA;EAAA,SACrC,KAAA,EAAO,iBAAA;EAAA,SACP,MAAA;AAAA;EAAA,IAEI,OAAA,CAAA;AAAA;AAAA,KAKH,qBAAA;sFAED,IAAA,GAAO,kBAAA;;;;;WAKP,GAAA;WAEA,MAAA,GAAS,oBAAoB;AAAA;AAAA,KAG5B,cAAA,GAAiB,mBAAA,CAAoB,mBAAA,EAAqB,kBAAA;;;AA9B/B;AAEvC;;cA6Ca,kBAAA,GACX,OAAA,GAAS,qBAAA,KACR,OAAA,CAAQ,cAAA"}
package/dist/google.mjs CHANGED
@@ -19,7 +19,10 @@ import { Data, Predicate } from "effect";
19
19
  * are emulated: Gmail on `https://gmail.googleapis.com` (`/gmail/v1/users/me/...` and the multipart
20
20
  * send upload), Calendar and Drive on `https://www.googleapis.com` (`/calendar/v3` and
21
21
  * `/drive/v3`). Each route answers only on its recorded origin (`fetchOn(origin)` serves one origin
22
- * behind a loopback rewrite). Response behaviour comes only from the fixtures: anything they do not
22
+ * behind a loopback rewrite). Draft attachments are not emulated: drafts with `attachments` write
23
+ * through the draft media upload (`POST`/`PUT` `/upload/gmail/v1/users/me/drafts[/{id}]`), which no
24
+ * fixture records, so it answers the constant unrecognised 400 until a draft-attachment case is
25
+ * recorded live. Response behaviour comes only from the fixtures: anything they do not
23
26
  * show answers one ledgered 400 not-emulated, writes nothing, and uses up no fault. That includes
24
27
  * an empty listing and every read of the leftover lookup (`findGoogleConformanceLeftovers`, whose
25
28
  * label listing, draft search, and free-text event query no fixture records): the lookup fails, and
@@ -1 +1 @@
1
- {"version":3,"file":"google.mjs","names":[],"sources":["../src/google.ts"],"sourcesContent":["/**\n * Stateful Google emulator (the Gmail, Calendar, and Drive routes the Google conformance cases\n * send), built on the upstream `@emulators/core` custom runtime, with a request ledger, status\n * faults, and an `/_emulate/*` control plane.\n *\n * It never imports SDK code: its wire shapes, error envelopes, and default seed are copied as data\n * from the synthetic Google conformance fixtures, and every route names the conformance cases it\n * follows in `googleEmulatorRoutes`. Only the routes those fifteen cases (with their cleanup) send\n * are emulated: Gmail on `https://gmail.googleapis.com` (`/gmail/v1/users/me/...` and the multipart\n * send upload), Calendar and Drive on `https://www.googleapis.com` (`/calendar/v3` and\n * `/drive/v3`). Each route answers only on its recorded origin (`fetchOn(origin)` serves one origin\n * behind a loopback rewrite). Response behaviour comes only from the fixtures: anything they do not\n * show answers one ledgered 400 not-emulated, writes nothing, and uses up no fault. That includes\n * an empty listing and every read of the leftover lookup (`findGoogleConformanceLeftovers`, whose\n * label listing, draft search, and free-text event query no fixture records): the lookup fails, and\n * runners print their lookup-failed WARN.\n *\n * The practice send (`google.gmail.send-practice-address`) is irreversible on Gmail. Here it is\n * only recorded in the state (the sent message reads back; nothing is delivered anywhere), and only\n * the recorded 7-bit message whose sole recipient header is `To: <the seeded practice address>`\n * is accepted, and only while that address is the recorded `practice@example.test` (the recorded\n * `sizeEstimate` covers it, as it covers the draft and send subjects, which therefore take only a\n * run id of the fixtures' 13-character length).\n *\n * Fail closed: Google follows the shared fail-closed rule of `src/stateful-emulator.ts` (its opt-in\n * `failClosed` mode, the same rule as `/github`). Every route parameter has a raw pattern matched\n * in full, so a request is recognised only when its raw path is exactly an emulated route shape\n * under that route's method and any `Authorization` header is exactly `Bearer <token>` with a\n * recognisable bearer (below); every other request is ledgered and answered with constant text only\n * (`/<unrecognised>`, a standard method or `<other>`, an empty query, no body, a constant reason).\n * The bearer value is never compared against anything, stored, forwarded, or ledgered. A recognised\n * request that repeats it in its raw path, any path segment, the query or any query key or value,\n * the recorded `content-type` header, or its raw body (the multipart send body included), or, on\n * the draft compose and update routes, in the base64url-decoded MIME of `message.raw` (Gmail's own\n * wire format wraps the draft this way; the routes give it to the wrapper as a decoded view), is\n * ledgered as the constant credential-repeat entry, checked through the wrapper's fixpoint closure\n * of a tolerant percent-decode and a tolerant JSON-unescape; any other recognised request has the\n * bearer scrubbed from its ledgered fields and every not-emulated reason. A `message.raw` the route\n * would refuse (anything but canonical unpadded base64url of exactly the recorded draft MIME, the\n * run id aside) makes the view throw a `DecodedViewRefusal` with one of the route's declared\n * constant reasons (`viewRefusalReasons`: the canonical-base64url reason, the\n * other-than-the-recorded-run-draft reason, the 13-character run-id reason, the extra-key reason),\n * which the wrapper ledgers in the constant entry before anything is recorded (or\n * `the request body repeats the credential` when the raw decodes cleanly to text holding the\n * bearer), so a refused `message.raw` never reaches the ledger. Google refusals use the wrapper's\n * constant-reason `exactQuery` and `exactBodyKeys`, so they never echo a request's own query or\n * body keys.\n *\n * Request-shape latitude (`/google`, the only accepted deviations): any bearer value in the RFC\n * 6750 `b64token` syntax (`[A-Za-z0-9\\-._~+/]+=*`) of at least 8 characters, starting with a\n * character in `[G-Zg-z\\-._~+/]` other than `n`, `r`, `t`, `u`, with at least one outside\n * `[0-9.eE+-]` (Google's `ya29.…` access tokens qualify), that occurs nowhere else in the request\n * (never compared against anything, stored, or ledgered); extra request headers (except\n * `X-Goog-Drive-Resource-Keys`, which no fixture sends); JSON key order; `content-type` media-type\n * parameters on JSON requests; query parameters in any order; any `run-` run id (at most 40\n * characters) in a run-scoped label name, event summary, or folder name; in a draft subject\n * (compose and update) and the sent subject, only a run id of exactly 13 characters, the length of\n * the fixtures' `run-synthetic`, because the recorded `sizeEstimate` of the draft and sent messages\n * (answered by their message reads and the draft thread) covers the subject; on the practice send,\n * a `content-type` of exactly `multipart/related; boundary=<b>` with any one unquoted boundary of 1\n * to 70 `[A-Za-z0-9_]` characters and no other parameter; a `gmail.list` or `gmail.list_threads`\n * `maxResults` from 1 to 500, a `calendar.list_events` `maxResults` from 1 to 2500, and a\n * `drive.list_files` `pageSize` from 1 to 1000; any `timeMin` before `timeMax` (RFC 3339 instants\n * with a real calendar date, hour 0 to 23, minute and second 0 to 59, and a `Z` or in-range numeric\n * offset); any id of an item the state holds where a fixture has an id (writes: only items created\n * here, plus label changes, trash, and untrash of a stored non-draft message); and, for an id the\n * state does not hold, only the recorded not-found answers (a `format=minimal` read of a\n * 16-hex-digit message id, a read of a `Label_<1 to 999999999>` label, a delete of an `r-<digits>`\n * draft, and a Drive file read); on a `format=metadata` message read, and on a `format=metadata`\n * read of a thread of stored non-draft messages (a thread read in that format takes a selection), a\n * `metadataHeaders` selection, repeated in any order, of 1 to 50 distinct header names each spelled\n * exactly as a header of the recorded metadata rendering, answered as that rendering with only the\n * selected headers, in recorded order. A seed may set another `practiceAddress`, but then every\n * send is refused, since the recorded `sizeEstimate` of the sent message also covers the address:\n * the send answers only while the seeded address is the recorded `practice@example.test`. On the\n * draft compose and update routes, `message.raw` must be canonical unpadded base64url of exactly\n * the recorded draft MIME of that route, the run id aside; any other `message.raw` (line-wrapped,\n * the standard alphabet, padded, with a stray character, or with MIME-level encodings such as RFC\n * 2047 encoded-words, quoted-printable other than the recorded parts, or UTF-16) is refused\n * before anything is recorded or a fault is decided, as a constant entry with the route's own\n * declared reason\n * (`message.raw must be canonical base64url UTF-8 MIME`,\n * `a draft compose other than the recorded run draft is not emulated` or its `update` form, the\n * 13-character run-id reason, or `message has a key this route does not take`), or\n * `the request body repeats the credential` when that raw decodes cleanly to text holding the\n * bearer, so a refused `message.raw` never reaches the ledger and an admitted one is the recorded\n * text. `Authorization` must be exactly `Bearer <token>` (that spelling, one space). Everything\n * else (other keys, values, formats, query parameters, empty query components such as a bare `?` or\n * a stray `&`, recorded headers such as Drive's `accept: application/json` missing, another origin,\n * repeated query parameters, any recipient but the seeded practice address, a draft or send run id\n * of another length, a bearer repeated anywhere in the request, including base64url-encoded inside\n * a draft's `message.raw`, and page tokens not issued for the same list since the last reset or\n * seed, or whose list changed) is not emulated.\n *\n * Node-only: `@emulators/core` imports Node builtins, so the core is loaded lazily by\n * `makeGoogleEmulator` (importing this module has no side effects).\n *\n * @experimental\n */\nimport { Data, Predicate } from 'effect'\nimport { calendarRoutes } from './google/calendar.ts'\nimport { driveRoutes } from './google/drive.ts'\nimport { gmailRoutes } from './google/gmail.ts'\nimport {\n googleEmulatorDrillKnobs,\n type GoogleApiEnv,\n type GoogleEmulatorDrills,\n type GoogleRoute\n} from './google/shared.ts'\nimport {\n buildSeedState,\n decodeState,\n type GoogleEmulatorSeed,\n type GoogleEmulatorState\n} from './google/state.ts'\nimport type { EmulatorRouteEvidence } from './route-evidence.ts'\nimport {\n StatefulFault,\n StatefulFaultMatch,\n checkBooleanDrills,\n makeStatefulEmulator,\n routeEvidence,\n type StatefulCoverage,\n type StatefulEmulatorApi,\n type StatefulFaultState,\n type StatefulInputKind,\n type StatefulLedgerEntry\n} from './stateful-emulator.ts'\nimport { statefulCoreRuntime } from './stateful-core.ts'\n\nexport type { EmulatorEvidence, EmulatorRouteEvidence } from './route-evidence.ts'\n\nexport { emulatorEvidenceHeader } from './route-evidence.ts'\n\nexport {\n googleEmulatorApisOrigin,\n googleEmulatorGmailOrigin,\n type GoogleEmulatorDrills\n} from './google/shared.ts'\n\nexport {\n GoogleEmulatorAttachment,\n GoogleEmulatorCalendar,\n GoogleEmulatorCalendarEvent,\n GoogleEmulatorDraft,\n GoogleEmulatorDriveFile,\n GoogleEmulatorEventBoundary,\n GoogleEmulatorGmailLabel,\n GoogleEmulatorGmailMessage,\n GoogleEmulatorImpliedMessage,\n GoogleEmulatorPracticeAddress,\n GoogleEmulatorProfile,\n GoogleEmulatorSeed,\n GoogleEmulatorStateSchema,\n type GoogleEmulatorState\n} from './google/state.ts'\n\nconst googleApiRoutes: ReadonlyArray<GoogleRoute> = [\n ...gmailRoutes,\n ...calendarRoutes,\n ...driveRoutes\n]\n\n/**\n * Route evidence manifest: every emulated route, whether it writes, and the conformance cases\n * whose (currently synthetic, unverified) wire claims it follows. Kept in sync with the handlers\n * by construction (both come from one route table). Every route cites at least one case.\n */\nexport const googleEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> =\n googleApiRoutes.map(routeEvidence)\n\n/**\n * Optional fault filter; an omitted field matches every request. `method` is the HTTP method;\n * `path` is the raw request path (ending in `*`, a prefix); `route` is a route template of the\n * manifest (another value is rejected when the fault is added).\n */\nexport const GoogleFaultMatch = StatefulFaultMatch\n\nexport type GoogleFaultMatch = typeof StatefulFaultMatch.Type\n\n/**\n * A status fault (400-599): answer matching requests with this status, headers, and body instead\n * of the route's write, so nothing is written. The body defaults to\n * `{ error: { type: 'emulator_fault', message } }`; `count` limits how many requests it answers.\n * Only a request the emulator would answer reaches a fault: a request that is not emulated, by\n * its shape or by the state, never uses one up.\n */\nexport const GoogleFault = StatefulFault\n\nexport type GoogleFault = StatefulFault\n\nexport type GoogleFaultState = StatefulFaultState\n\nexport type GoogleLedgerEntry = StatefulLedgerEntry\n\nexport type GoogleCoverage = StatefulCoverage\n\n/** Invalid emulator input from the JS API: a seed, a fault, or an option. A programmer error. */\nexport class GoogleEmulatorInputInvalid extends Data.TaggedError('GoogleEmulatorInputInvalid')<{\n readonly input: StatefulInputKind\n readonly reason: string\n}> {\n override get message(): string {\n return `Invalid Google emulator ${this.input}: ${this.reason}`\n }\n}\n\nexport type GoogleEmulatorOptions = {\n /** Typed seed; defaults to the fixture entities (`profile: 'default'`). */\n readonly seed?: GoogleEmulatorSeed\n /**\n * Clock in epoch milliseconds (created and updated event times, Drive folder times, and the\n * sent message's `Date` header). Defaults to `Date.now`.\n */\n readonly now?: () => number\n /** Drill knobs (tests only): make the emulator disagree with one conformance case. */\n readonly drills?: GoogleEmulatorDrills\n}\n\nexport type GoogleEmulator = StatefulEmulatorApi<GoogleEmulatorState, GoogleEmulatorSeed>\n\n/** The constant reason of a request on no emulated route shape (nothing of it is ledgered). */\nconst googleUnrecognisedReason = 'no emulated Google route for this method and path'\n\n/** The constant reason of a request whose `Authorization` header is not one recognisable bearer. */\nconst googleUnrecognisedAuthorizationReason =\n 'an unrecognisable Authorization header is not emulated'\n\nconst inputInvalid = (input: StatefulInputKind, reason: string) =>\n new GoogleEmulatorInputInvalid({ input, reason })\n\n/**\n * Create a stateful Google emulator on the `@emulators/core` custom runtime. Each call has its\n * own state, ledger, faults, and page tokens. Rejects with `GoogleEmulatorInputInvalid` for an\n * invalid seed or option. See `src/stateful-emulator.ts` for the request precedence.\n */\nexport const makeGoogleEmulator = async (\n options: GoogleEmulatorOptions = {}\n): Promise<GoogleEmulator> => {\n const initial = buildSeedState(options.seed ?? {})\n\n if (Predicate.isString(initial)) {\n throw inputInvalid('seed', initial)\n }\n\n checkBooleanDrills(options.drills, googleEmulatorDrillKnobs, inputInvalid)\n\n const drills = options.drills ?? {}\n\n const env: GoogleApiEnv = {\n now: options.now ?? (() => Date.now()),\n drills: {\n gmailPageRepeats: drills.gmailPageRepeats === true,\n attachmentStandardBase64: drills.attachmentStandardBase64 === true,\n notFoundWithoutMessage: drills.notFoundWithoutMessage === true,\n gmailThreadPageRepeats: drills.gmailThreadPageRepeats === true,\n metadataHeadersIgnored: drills.metadataHeadersIgnored === true,\n labelDeleteKeepsOnMessages: drills.labelDeleteKeepsOnMessages === true,\n draftUpdateKeepsContent: drills.draftUpdateKeepsContent === true,\n trashAnswerOmitsTrash: drills.trashAnswerOmitsTrash === true,\n sentMessageWithoutTo: drills.sentMessageWithoutTo === true,\n calendarPageRepeats: drills.calendarPageRepeats === true,\n eventPatchKeepsSummary: drills.eventPatchKeepsSummary === true,\n repeatedEventDeleteConflict: drills.repeatedEventDeleteConflict === true,\n drivePageRepeats: drills.drivePageRepeats === true,\n getFileWithoutParents: drills.getFileWithoutParents === true,\n listIncludesTrashed: drills.listIncludesTrashed === true\n },\n pageTokens: new Map(),\n generation: { current: 0 },\n firstIssued: new Map()\n }\n\n return makeStatefulEmulator<GoogleEmulatorState, GoogleApiEnv, GoogleEmulatorSeed>(\n {\n routes: googleApiRoutes,\n env,\n initial,\n buildSeed: buildSeedState,\n requestProblem: header =>\n header('x-goog-drive-resource-keys') === undefined\n ? undefined\n : 'X-Goog-Drive-Resource-Keys is not emulated (no fixture sends it)',\n // `content-type` only (never a credential header); the bearer is checked in it too.\n recordHeaders: [{ name: 'content-type', json: false }],\n // Page token values never cross a reset or seed: the generation makes later tokens distinct.\n clearRuntime: () => {\n env.pageTokens.clear()\n env.generation.current += 1\n },\n runtimeState: () => ({ pageTokens: env.pageTokens.size }),\n seedSummary: state => ({\n messages: state.messages.length,\n events: state.events.length,\n files: state.files.length\n }),\n inputInvalid,\n failClosed: {\n unrecognised: googleUnrecognisedReason,\n unrecognisedAuthorization: googleUnrecognisedAuthorizationReason\n }\n },\n statefulCoreRuntime({ name: 'google', initial, decodeState, inputInvalid })\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JA,MAAM,kBAA8C;CAClD,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;AAOA,MAAa,uBACX,gBAAgB,IAAI,aAAa;;;;;;AAOnC,MAAa,mBAAmB;;;;;;;;AAWhC,MAAa,cAAc;;AA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E,MAAM;GAAgB,MAAM;EAAM,CAAC;EAErD,oBAAoB;GAClB,IAAI,WAAW,MAAM;GACrB,IAAI,WAAW,WAAW;EAC5B;EACA,qBAAqB,EAAE,YAAY,IAAI,WAAW,KAAK;EACvD,cAAa,WAAU;GACrB,UAAU,MAAM,SAAS;GACzB,QAAQ,MAAM,OAAO;GACrB,OAAO,MAAM,MAAM;EACrB;EACA;EACA,YAAY;GACV,cAAc;GACd,2BAA2B;EAC7B;CACF,GACA,oBAAoB;EAAE,MAAM;EAAU;EAAS;EAAa;CAAa,CAAC,CAC5E;AACF"}
1
+ {"version":3,"file":"google.mjs","names":[],"sources":["../src/google.ts"],"sourcesContent":["/**\n * Stateful Google emulator (the Gmail, Calendar, and Drive routes the Google conformance cases\n * send), built on the upstream `@emulators/core` custom runtime, with a request ledger, status\n * faults, and an `/_emulate/*` control plane.\n *\n * It never imports SDK code: its wire shapes, error envelopes, and default seed are copied as data\n * from the synthetic Google conformance fixtures, and every route names the conformance cases it\n * follows in `googleEmulatorRoutes`. Only the routes those fifteen cases (with their cleanup) send\n * are emulated: Gmail on `https://gmail.googleapis.com` (`/gmail/v1/users/me/...` and the multipart\n * send upload), Calendar and Drive on `https://www.googleapis.com` (`/calendar/v3` and\n * `/drive/v3`). Each route answers only on its recorded origin (`fetchOn(origin)` serves one origin\n * behind a loopback rewrite). Draft attachments are not emulated: drafts with `attachments` write\n * through the draft media upload (`POST`/`PUT` `/upload/gmail/v1/users/me/drafts[/{id}]`), which no\n * fixture records, so it answers the constant unrecognised 400 until a draft-attachment case is\n * recorded live. Response behaviour comes only from the fixtures: anything they do not\n * show answers one ledgered 400 not-emulated, writes nothing, and uses up no fault. That includes\n * an empty listing and every read of the leftover lookup (`findGoogleConformanceLeftovers`, whose\n * label listing, draft search, and free-text event query no fixture records): the lookup fails, and\n * runners print their lookup-failed WARN.\n *\n * The practice send (`google.gmail.send-practice-address`) is irreversible on Gmail. Here it is\n * only recorded in the state (the sent message reads back; nothing is delivered anywhere), and only\n * the recorded 7-bit message whose sole recipient header is `To: <the seeded practice address>`\n * is accepted, and only while that address is the recorded `practice@example.test` (the recorded\n * `sizeEstimate` covers it, as it covers the draft and send subjects, which therefore take only a\n * run id of the fixtures' 13-character length).\n *\n * Fail closed: Google follows the shared fail-closed rule of `src/stateful-emulator.ts` (its opt-in\n * `failClosed` mode, the same rule as `/github`). Every route parameter has a raw pattern matched\n * in full, so a request is recognised only when its raw path is exactly an emulated route shape\n * under that route's method and any `Authorization` header is exactly `Bearer <token>` with a\n * recognisable bearer (below); every other request is ledgered and answered with constant text only\n * (`/<unrecognised>`, a standard method or `<other>`, an empty query, no body, a constant reason).\n * The bearer value is never compared against anything, stored, forwarded, or ledgered. A recognised\n * request that repeats it in its raw path, any path segment, the query or any query key or value,\n * the recorded `content-type` header, or its raw body (the multipart send body included), or, on\n * the draft compose and update routes, in the base64url-decoded MIME of `message.raw` (Gmail's own\n * wire format wraps the draft this way; the routes give it to the wrapper as a decoded view), is\n * ledgered as the constant credential-repeat entry, checked through the wrapper's fixpoint closure\n * of a tolerant percent-decode and a tolerant JSON-unescape; any other recognised request has the\n * bearer scrubbed from its ledgered fields and every not-emulated reason. A `message.raw` the route\n * would refuse (anything but canonical unpadded base64url of exactly the recorded draft MIME, the\n * run id aside) makes the view throw a `DecodedViewRefusal` with one of the route's declared\n * constant reasons (`viewRefusalReasons`: the canonical-base64url reason, the\n * other-than-the-recorded-run-draft reason, the 13-character run-id reason, the extra-key reason),\n * which the wrapper ledgers in the constant entry before anything is recorded (or\n * `the request body repeats the credential` when the raw decodes cleanly to text holding the\n * bearer), so a refused `message.raw` never reaches the ledger. Google refusals use the wrapper's\n * constant-reason `exactQuery` and `exactBodyKeys`, so they never echo a request's own query or\n * body keys.\n *\n * Request-shape latitude (`/google`, the only accepted deviations): any bearer value in the RFC\n * 6750 `b64token` syntax (`[A-Za-z0-9\\-._~+/]+=*`) of at least 8 characters, starting with a\n * character in `[G-Zg-z\\-._~+/]` other than `n`, `r`, `t`, `u`, with at least one outside\n * `[0-9.eE+-]` (Google's `ya29.…` access tokens qualify), that occurs nowhere else in the request\n * (never compared against anything, stored, or ledgered); extra request headers (except\n * `X-Goog-Drive-Resource-Keys`, which no fixture sends); JSON key order; `content-type` media-type\n * parameters on JSON requests; query parameters in any order; any `run-` run id (at most 40\n * characters) in a run-scoped label name, event summary, or folder name; in a draft subject\n * (compose and update) and the sent subject, only a run id of exactly 13 characters, the length of\n * the fixtures' `run-synthetic`, because the recorded `sizeEstimate` of the draft and sent messages\n * (answered by their message reads and the draft thread) covers the subject; on the practice send,\n * a `content-type` of exactly `multipart/related; boundary=<b>` with any one unquoted boundary of 1\n * to 70 `[A-Za-z0-9_]` characters and no other parameter; a `gmail.list` or `gmail.list_threads`\n * `maxResults` from 1 to 500, a `calendar.list_events` `maxResults` from 1 to 2500, and a\n * `drive.list_files` `pageSize` from 1 to 1000; any `timeMin` before `timeMax` (RFC 3339 instants\n * with a real calendar date, hour 0 to 23, minute and second 0 to 59, and a `Z` or in-range numeric\n * offset); any id of an item the state holds where a fixture has an id (writes: only items created\n * here, plus label changes, trash, and untrash of a stored non-draft message); and, for an id the\n * state does not hold, only the recorded not-found answers (a `format=minimal` read of a\n * 16-hex-digit message id, a read of a `Label_<1 to 999999999>` label, a delete of an `r-<digits>`\n * draft, and a Drive file read); on a `format=metadata` message read, and on a `format=metadata`\n * read of a thread of stored non-draft messages (a thread read in that format takes a selection), a\n * `metadataHeaders` selection, repeated in any order, of 1 to 50 distinct header names each spelled\n * exactly as a header of the recorded metadata rendering, answered as that rendering with only the\n * selected headers, in recorded order. A seed may set another `practiceAddress`, but then every\n * send is refused, since the recorded `sizeEstimate` of the sent message also covers the address:\n * the send answers only while the seeded address is the recorded `practice@example.test`. On the\n * draft compose and update routes, `message.raw` must be canonical unpadded base64url of exactly\n * the recorded draft MIME of that route, the run id aside; any other `message.raw` (line-wrapped,\n * the standard alphabet, padded, with a stray character, or with MIME-level encodings such as RFC\n * 2047 encoded-words, quoted-printable other than the recorded parts, or UTF-16) is refused\n * before anything is recorded or a fault is decided, as a constant entry with the route's own\n * declared reason\n * (`message.raw must be canonical base64url UTF-8 MIME`,\n * `a draft compose other than the recorded run draft is not emulated` or its `update` form, the\n * 13-character run-id reason, or `message has a key this route does not take`), or\n * `the request body repeats the credential` when that raw decodes cleanly to text holding the\n * bearer, so a refused `message.raw` never reaches the ledger and an admitted one is the recorded\n * text. `Authorization` must be exactly `Bearer <token>` (that spelling, one space). Everything\n * else (other keys, values, formats, query parameters, empty query components such as a bare `?` or\n * a stray `&`, recorded headers such as Drive's `accept: application/json` missing, another origin,\n * repeated query parameters, any recipient but the seeded practice address, a draft or send run id\n * of another length, a bearer repeated anywhere in the request, including base64url-encoded inside\n * a draft's `message.raw`, and page tokens not issued for the same list since the last reset or\n * seed, or whose list changed) is not emulated.\n *\n * Node-only: `@emulators/core` imports Node builtins, so the core is loaded lazily by\n * `makeGoogleEmulator` (importing this module has no side effects).\n *\n * @experimental\n */\nimport { Data, Predicate } from 'effect'\nimport { calendarRoutes } from './google/calendar.ts'\nimport { driveRoutes } from './google/drive.ts'\nimport { gmailRoutes } from './google/gmail.ts'\nimport {\n googleEmulatorDrillKnobs,\n type GoogleApiEnv,\n type GoogleEmulatorDrills,\n type GoogleRoute\n} from './google/shared.ts'\nimport {\n buildSeedState,\n decodeState,\n type GoogleEmulatorSeed,\n type GoogleEmulatorState\n} from './google/state.ts'\nimport type { EmulatorRouteEvidence } from './route-evidence.ts'\nimport {\n StatefulFault,\n StatefulFaultMatch,\n checkBooleanDrills,\n makeStatefulEmulator,\n routeEvidence,\n type StatefulCoverage,\n type StatefulEmulatorApi,\n type StatefulFaultState,\n type StatefulInputKind,\n type StatefulLedgerEntry\n} from './stateful-emulator.ts'\nimport { statefulCoreRuntime } from './stateful-core.ts'\n\nexport type { EmulatorEvidence, EmulatorRouteEvidence } from './route-evidence.ts'\n\nexport { emulatorEvidenceHeader } from './route-evidence.ts'\n\nexport {\n googleEmulatorApisOrigin,\n googleEmulatorGmailOrigin,\n type GoogleEmulatorDrills\n} from './google/shared.ts'\n\nexport {\n GoogleEmulatorAttachment,\n GoogleEmulatorCalendar,\n GoogleEmulatorCalendarEvent,\n GoogleEmulatorDraft,\n GoogleEmulatorDriveFile,\n GoogleEmulatorEventBoundary,\n GoogleEmulatorGmailLabel,\n GoogleEmulatorGmailMessage,\n GoogleEmulatorImpliedMessage,\n GoogleEmulatorPracticeAddress,\n GoogleEmulatorProfile,\n GoogleEmulatorSeed,\n GoogleEmulatorStateSchema,\n type GoogleEmulatorState\n} from './google/state.ts'\n\nconst googleApiRoutes: ReadonlyArray<GoogleRoute> = [\n ...gmailRoutes,\n ...calendarRoutes,\n ...driveRoutes\n]\n\n/**\n * Route evidence manifest: every emulated route, whether it writes, and the conformance cases\n * whose (currently synthetic, unverified) wire claims it follows. Kept in sync with the handlers\n * by construction (both come from one route table). Every route cites at least one case.\n */\nexport const googleEmulatorRoutes: ReadonlyArray<EmulatorRouteEvidence> =\n googleApiRoutes.map(routeEvidence)\n\n/**\n * Optional fault filter; an omitted field matches every request. `method` is the HTTP method;\n * `path` is the raw request path (ending in `*`, a prefix); `route` is a route template of the\n * manifest (another value is rejected when the fault is added).\n */\nexport const GoogleFaultMatch = StatefulFaultMatch\n\nexport type GoogleFaultMatch = typeof StatefulFaultMatch.Type\n\n/**\n * A status fault (400-599): answer matching requests with this status, headers, and body instead\n * of the route's write, so nothing is written. The body defaults to\n * `{ error: { type: 'emulator_fault', message } }`; `count` limits how many requests it answers.\n * Only a request the emulator would answer reaches a fault: a request that is not emulated, by\n * its shape or by the state, never uses one up.\n */\nexport const GoogleFault = StatefulFault\n\nexport type GoogleFault = StatefulFault\n\nexport type GoogleFaultState = StatefulFaultState\n\nexport type GoogleLedgerEntry = StatefulLedgerEntry\n\nexport type GoogleCoverage = StatefulCoverage\n\n/** Invalid emulator input from the JS API: a seed, a fault, or an option. A programmer error. */\nexport class GoogleEmulatorInputInvalid extends Data.TaggedError('GoogleEmulatorInputInvalid')<{\n readonly input: StatefulInputKind\n readonly reason: string\n}> {\n override get message(): string {\n return `Invalid Google emulator ${this.input}: ${this.reason}`\n }\n}\n\nexport type GoogleEmulatorOptions = {\n /** Typed seed; defaults to the fixture entities (`profile: 'default'`). */\n readonly seed?: GoogleEmulatorSeed\n /**\n * Clock in epoch milliseconds (created and updated event times, Drive folder times, and the\n * sent message's `Date` header). Defaults to `Date.now`.\n */\n readonly now?: () => number\n /** Drill knobs (tests only): make the emulator disagree with one conformance case. */\n readonly drills?: GoogleEmulatorDrills\n}\n\nexport type GoogleEmulator = StatefulEmulatorApi<GoogleEmulatorState, GoogleEmulatorSeed>\n\n/** The constant reason of a request on no emulated route shape (nothing of it is ledgered). */\nconst googleUnrecognisedReason = 'no emulated Google route for this method and path'\n\n/** The constant reason of a request whose `Authorization` header is not one recognisable bearer. */\nconst googleUnrecognisedAuthorizationReason =\n 'an unrecognisable Authorization header is not emulated'\n\nconst inputInvalid = (input: StatefulInputKind, reason: string) =>\n new GoogleEmulatorInputInvalid({ input, reason })\n\n/**\n * Create a stateful Google emulator on the `@emulators/core` custom runtime. Each call has its\n * own state, ledger, faults, and page tokens. Rejects with `GoogleEmulatorInputInvalid` for an\n * invalid seed or option. See `src/stateful-emulator.ts` for the request precedence.\n */\nexport const makeGoogleEmulator = async (\n options: GoogleEmulatorOptions = {}\n): Promise<GoogleEmulator> => {\n const initial = buildSeedState(options.seed ?? {})\n\n if (Predicate.isString(initial)) {\n throw inputInvalid('seed', initial)\n }\n\n checkBooleanDrills(options.drills, googleEmulatorDrillKnobs, inputInvalid)\n\n const drills = options.drills ?? {}\n\n const env: GoogleApiEnv = {\n now: options.now ?? (() => Date.now()),\n drills: {\n gmailPageRepeats: drills.gmailPageRepeats === true,\n attachmentStandardBase64: drills.attachmentStandardBase64 === true,\n notFoundWithoutMessage: drills.notFoundWithoutMessage === true,\n gmailThreadPageRepeats: drills.gmailThreadPageRepeats === true,\n metadataHeadersIgnored: drills.metadataHeadersIgnored === true,\n labelDeleteKeepsOnMessages: drills.labelDeleteKeepsOnMessages === true,\n draftUpdateKeepsContent: drills.draftUpdateKeepsContent === true,\n trashAnswerOmitsTrash: drills.trashAnswerOmitsTrash === true,\n sentMessageWithoutTo: drills.sentMessageWithoutTo === true,\n calendarPageRepeats: drills.calendarPageRepeats === true,\n eventPatchKeepsSummary: drills.eventPatchKeepsSummary === true,\n repeatedEventDeleteConflict: drills.repeatedEventDeleteConflict === true,\n drivePageRepeats: drills.drivePageRepeats === true,\n getFileWithoutParents: drills.getFileWithoutParents === true,\n listIncludesTrashed: drills.listIncludesTrashed === true\n },\n pageTokens: new Map(),\n generation: { current: 0 },\n firstIssued: new Map()\n }\n\n return makeStatefulEmulator<GoogleEmulatorState, GoogleApiEnv, GoogleEmulatorSeed>(\n {\n routes: googleApiRoutes,\n env,\n initial,\n buildSeed: buildSeedState,\n requestProblem: header =>\n header('x-goog-drive-resource-keys') === undefined\n ? undefined\n : 'X-Goog-Drive-Resource-Keys is not emulated (no fixture sends it)',\n // `content-type` only (never a credential header); the bearer is checked in it too.\n recordHeaders: [{ name: 'content-type', json: false }],\n // Page token values never cross a reset or seed: the generation makes later tokens distinct.\n clearRuntime: () => {\n env.pageTokens.clear()\n env.generation.current += 1\n },\n runtimeState: () => ({ pageTokens: env.pageTokens.size }),\n seedSummary: state => ({\n messages: state.messages.length,\n events: state.events.length,\n files: state.files.length\n }),\n inputInvalid,\n failClosed: {\n unrecognised: googleUnrecognisedReason,\n unrecognisedAuthorization: googleUnrecognisedAuthorizationReason\n }\n },\n statefulCoreRuntime({ name: 'google', initial, decodeState, inputInvalid })\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgKA,MAAM,kBAA8C;CAClD,GAAG;CACH,GAAG;CACH,GAAG;AACL;;;;;;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ACA;EACA,WAAW;EACX,iBAAgB,WACd,OAAO,4BAA4B,MAAM,KAAA,IACrC,KAAA,IACA;EAEN,eAAe,CAAC;GAAE,MAAM;GAAgB,MAAM;EAAM,CAAC;EAErD,oBAAoB;GAClB,IAAI,WAAW,MAAM;GACrB,IAAI,WAAW,WAAW;EAC5B;EACA,qBAAqB,EAAE,YAAY,IAAI,WAAW,KAAK;EACvD,cAAa,WAAU;GACrB,UAAU,MAAM,SAAS;GACzB,QAAQ,MAAM,OAAO;GACrB,OAAO,MAAM,MAAM;EACrB;EACA;EACA,YAAY;GACV,cAAc;GACd,2BAA2B;EAC7B;CACF,GACA,oBAAoB;EAAE,MAAM;EAAU;EAAS;EAAa;CAAa,CAAC,CAC5E;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolk-sdk/emulators",
3
- "version": "0.1.0-canary.104",
3
+ "version": "0.1.0-canary.106",
4
4
  "description": "Experimental emulators for outside services: an Effect HttpClient router, Vercel AI Gateway, OpenAI Chat Completions, Anthropic Messages, OpenAI Responses (Codex, xAI Grok), and OpenCode Go fetch-handler emulators with subscription-usage routes, fixture-driven fake EmailClient and R2 (R2Presigner, R2ObjectClient) backends, stateful Fortnox, Microsoft Graph, Dropbox, Notion, Todoist, Telegram, GitHub, Google (Gmail, Calendar, Drive), LinkedIn search (Exa, Enrich Layer), and synthetic and Afloat MCP emulators, and a loopback Node server.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -143,10 +143,10 @@
143
143
  "effect": "4.0.0"
144
144
  },
145
145
  "devDependencies": {
146
- "@yolk-sdk/agent": "^0.1.0-canary.104",
147
- "@yolk-sdk/conformance": "^0.1.0-canary.104",
148
- "@yolk-sdk/connectors": "^0.1.0-canary.104",
149
- "@yolk-sdk/mcp": "^0.1.0-canary.104"
146
+ "@yolk-sdk/conformance": "^0.1.0-canary.106",
147
+ "@yolk-sdk/agent": "^0.1.0-canary.106",
148
+ "@yolk-sdk/mcp": "^0.1.0-canary.106",
149
+ "@yolk-sdk/connectors": "^0.1.0-canary.106"
150
150
  },
151
151
  "scripts": {
152
152
  "build": "tsdown",
package/src/google.ts CHANGED
@@ -9,7 +9,10 @@
9
9
  * are emulated: Gmail on `https://gmail.googleapis.com` (`/gmail/v1/users/me/...` and the multipart
10
10
  * send upload), Calendar and Drive on `https://www.googleapis.com` (`/calendar/v3` and
11
11
  * `/drive/v3`). Each route answers only on its recorded origin (`fetchOn(origin)` serves one origin
12
- * behind a loopback rewrite). Response behaviour comes only from the fixtures: anything they do not
12
+ * behind a loopback rewrite). Draft attachments are not emulated: drafts with `attachments` write
13
+ * through the draft media upload (`POST`/`PUT` `/upload/gmail/v1/users/me/drafts[/{id}]`), which no
14
+ * fixture records, so it answers the constant unrecognised 400 until a draft-attachment case is
15
+ * recorded live. Response behaviour comes only from the fixtures: anything they do not
13
16
  * show answers one ledgered 400 not-emulated, writes nothing, and uses up no fault. That includes
14
17
  * an empty listing and every read of the leftover lookup (`findGoogleConformanceLeftovers`, whose
15
18
  * label listing, draft search, and free-text event query no fixture records): the lookup fails, and