@morpho-dev/router 0.0.19 → 0.0.21

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.
@@ -88,8 +88,8 @@ declare const RouterOfferSchema: (parameters?: {
88
88
  * @param input - The router offer to create.
89
89
  * @returns The created router offer with its hash.
90
90
  */
91
- declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
92
- declare namespace from {
91
+ declare function from$1(input: Omit<RouterOffer, "hash">): RouterOffer;
92
+ declare namespace from$1 {
93
93
  type ErrorType = InvalidRouterOfferError;
94
94
  }
95
95
  /**
@@ -121,12 +121,11 @@ type RouterOffer$1_OfferStatus = OfferStatus;
121
121
  declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
122
122
  type RouterOffer$1_RouterOffer = RouterOffer;
123
123
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
124
- declare const RouterOffer$1_from: typeof from;
125
124
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
126
125
  declare const RouterOffer$1_random: typeof random;
127
126
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
128
127
  declare namespace RouterOffer$1 {
129
- export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_from as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
128
+ export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, from$1 as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
130
129
  }
131
130
 
132
131
  type OfferResponse = {
@@ -422,37 +421,26 @@ declare namespace index$1 {
422
421
 
423
422
  declare const types: readonly ["offer_created", "offer_matched", "offer_validation"];
424
423
  type Type = (typeof types)[number];
425
- type EventPayload = {
426
- offer_created: {
427
- readonly offer: Offer.Offer;
428
- };
429
- offer_matched: {
430
- readonly offer: Offer.Offer;
431
- };
432
- offer_validation: {
433
- readonly offer: Offer.Offer;
434
- };
435
- };
436
- type BaseEvent<T extends Type> = {
424
+ type BaseEvent<type extends Type = Type> = {
437
425
  readonly id: string;
438
- readonly type: T;
426
+ readonly type: type;
439
427
  };
440
- type RouterEvent = Compute<{
441
- [K in keyof EventPayload]: BaseEvent<K> & EventPayload[K];
442
- }[keyof EventPayload]>;
428
+ type RouterEvent<type extends Type = Type> = type extends "offer_created" | "offer_matched" | "offer_validation" ? Compute<BaseEvent<type> & {
429
+ readonly offer: Offer.Offer;
430
+ }> : never;
443
431
  /**
444
- * Builds a deterministic event id based on the event type.
445
- * For `offer_created` it returns `offer_created:${offer.hash.toLowerCase()}`.
446
- * For `offer_matched` it returns `offer_matched:${offer.hash.toLowerCase()}`.
432
+ * Creates a RouterEvent with a deterministic id.
447
433
  */
448
- declare function buildId(event: Omit<RouterEvent, "id">): string;
434
+ declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
435
+ type: T;
436
+ }): Compute<RouterEvent<T>>;
449
437
 
450
- type RouterEvent$1_RouterEvent = RouterEvent;
438
+ type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
451
439
  type RouterEvent$1_Type = Type;
452
- declare const RouterEvent$1_buildId: typeof buildId;
440
+ declare const RouterEvent$1_from: typeof from;
453
441
  declare const RouterEvent$1_types: typeof types;
454
442
  declare namespace RouterEvent$1 {
455
- export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_buildId as buildId, RouterEvent$1_types as types };
443
+ export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
456
444
  }
457
445
 
458
446
  /**
@@ -88,8 +88,8 @@ declare const RouterOfferSchema: (parameters?: {
88
88
  * @param input - The router offer to create.
89
89
  * @returns The created router offer with its hash.
90
90
  */
91
- declare function from(input: Omit<RouterOffer, "hash">): RouterOffer;
92
- declare namespace from {
91
+ declare function from$1(input: Omit<RouterOffer, "hash">): RouterOffer;
92
+ declare namespace from$1 {
93
93
  type ErrorType = InvalidRouterOfferError;
94
94
  }
95
95
  /**
@@ -121,12 +121,11 @@ type RouterOffer$1_OfferStatus = OfferStatus;
121
121
  declare const RouterOffer$1_OfferStatusValues: typeof OfferStatusValues;
122
122
  type RouterOffer$1_RouterOffer = RouterOffer;
123
123
  declare const RouterOffer$1_RouterOfferSchema: typeof RouterOfferSchema;
124
- declare const RouterOffer$1_from: typeof from;
125
124
  declare const RouterOffer$1_fromSnakeCase: typeof fromSnakeCase;
126
125
  declare const RouterOffer$1_random: typeof random;
127
126
  declare const RouterOffer$1_toSnakeCase: typeof toSnakeCase;
128
127
  declare namespace RouterOffer$1 {
129
- export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, RouterOffer$1_from as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
128
+ export { RouterOffer$1_InvalidRouterOfferError as InvalidRouterOfferError, type RouterOffer$1_OfferMetadata as OfferMetadata, type RouterOffer$1_OfferStatus as OfferStatus, RouterOffer$1_OfferStatusValues as OfferStatusValues, type RouterOffer$1_RouterOffer as RouterOffer, RouterOffer$1_RouterOfferSchema as RouterOfferSchema, from$1 as from, RouterOffer$1_fromSnakeCase as fromSnakeCase, RouterOffer$1_random as random, RouterOffer$1_toSnakeCase as toSnakeCase };
130
129
  }
131
130
 
132
131
  type OfferResponse = {
@@ -422,37 +421,26 @@ declare namespace index$1 {
422
421
 
423
422
  declare const types: readonly ["offer_created", "offer_matched", "offer_validation"];
424
423
  type Type = (typeof types)[number];
425
- type EventPayload = {
426
- offer_created: {
427
- readonly offer: Offer.Offer;
428
- };
429
- offer_matched: {
430
- readonly offer: Offer.Offer;
431
- };
432
- offer_validation: {
433
- readonly offer: Offer.Offer;
434
- };
435
- };
436
- type BaseEvent<T extends Type> = {
424
+ type BaseEvent<type extends Type = Type> = {
437
425
  readonly id: string;
438
- readonly type: T;
426
+ readonly type: type;
439
427
  };
440
- type RouterEvent = Compute<{
441
- [K in keyof EventPayload]: BaseEvent<K> & EventPayload[K];
442
- }[keyof EventPayload]>;
428
+ type RouterEvent<type extends Type = Type> = type extends "offer_created" | "offer_matched" | "offer_validation" ? Compute<BaseEvent<type> & {
429
+ readonly offer: Offer.Offer;
430
+ }> : never;
443
431
  /**
444
- * Builds a deterministic event id based on the event type.
445
- * For `offer_created` it returns `offer_created:${offer.hash.toLowerCase()}`.
446
- * For `offer_matched` it returns `offer_matched:${offer.hash.toLowerCase()}`.
432
+ * Creates a RouterEvent with a deterministic id.
447
433
  */
448
- declare function buildId(event: Omit<RouterEvent, "id">): string;
434
+ declare function from<T extends Type = Type>(base: Omit<RouterEvent<T>, "id" | "type"> & {
435
+ type: T;
436
+ }): Compute<RouterEvent<T>>;
449
437
 
450
- type RouterEvent$1_RouterEvent = RouterEvent;
438
+ type RouterEvent$1_RouterEvent<type extends Type = Type> = RouterEvent<type>;
451
439
  type RouterEvent$1_Type = Type;
452
- declare const RouterEvent$1_buildId: typeof buildId;
440
+ declare const RouterEvent$1_from: typeof from;
453
441
  declare const RouterEvent$1_types: typeof types;
454
442
  declare namespace RouterEvent$1 {
455
- export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_buildId as buildId, RouterEvent$1_types as types };
443
+ export { type RouterEvent$1_RouterEvent as RouterEvent, type RouterEvent$1_Type as Type, RouterEvent$1_from as from, RouterEvent$1_types as types };
456
444
  }
457
445
 
458
446
  /**
@@ -5,6 +5,7 @@ var chains$1 = require('viem/chains');
5
5
  var viem = require('viem');
6
6
  var v4 = require('zod/v4');
7
7
  var zodOpenapi = require('zod-openapi');
8
+ var jsBase64 = require('js-base64');
8
9
 
9
10
  var __defProp = Object.defineProperty;
10
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -157,8 +158,6 @@ function* batch(array, batchSize) {
157
158
  yield array.slice(i, i + batchSize);
158
159
  }
159
160
  }
160
-
161
- // src/utils/cursor.ts
162
161
  function validateCursor(cursor) {
163
162
  if (!cursor || typeof cursor !== "object") {
164
163
  throw new Error("Cursor must be an object");
@@ -229,11 +228,11 @@ function validateCursor(cursor) {
229
228
  return true;
230
229
  }
231
230
  function encodeCursor(c) {
232
- return Buffer.from(JSON.stringify(c)).toString("base64url");
231
+ return jsBase64.Base64.encodeURL(JSON.stringify(c));
233
232
  }
234
233
  function decodeCursor(token) {
235
234
  if (!token) return null;
236
- const decoded = JSON.parse(Buffer.from(token, "base64url").toString());
235
+ const decoded = JSON.parse(jsBase64.Base64.decode(token));
237
236
  validateCursor(decoded);
238
237
  return decoded;
239
238
  }
@@ -986,12 +985,12 @@ async function getApi(config, url) {
986
985
  const pathname = url.pathname;
987
986
  let action;
988
987
  switch (true) {
989
- case pathname.includes("/v1/offers"):
990
- action = "get_offers";
991
- break;
992
988
  case pathname.includes("/v1/offers/match"):
993
989
  action = "match_offers";
994
990
  break;
991
+ case pathname.includes("/v1/offers"):
992
+ action = "get_offers";
993
+ break;
995
994
  default:
996
995
  throw new HttpGetOffersFailedError("Unknown endpoint", {
997
996
  details: `Unsupported path: ${pathname}`
@@ -1418,22 +1417,13 @@ function memory(parameters) {
1418
1417
  // src/RouterEvent.ts
1419
1418
  var RouterEvent_exports = {};
1420
1419
  __export(RouterEvent_exports, {
1421
- buildId: () => buildId,
1420
+ from: () => from2,
1422
1421
  types: () => types
1423
1422
  });
1424
1423
  var types = ["offer_created", "offer_matched", "offer_validation"];
1425
- function buildId(event) {
1426
- switch (event.type) {
1427
- case "offer_created":
1428
- return `offer_created:${event.offer.hash.toLowerCase()}`;
1429
- case "offer_matched":
1430
- return `offer_matched:${event.offer.hash.toLowerCase()}`;
1431
- case "offer_validation":
1432
- return `offer_validation:${event.offer.hash.toLowerCase()}`;
1433
- default: {
1434
- throw new Error("Unhandled event type");
1435
- }
1436
- }
1424
+ function from2(base) {
1425
+ const id = `${base.type}:${base.offer.hash.toLowerCase()}`;
1426
+ return { id, ...base };
1437
1427
  }
1438
1428
 
1439
1429
  // src/Validation.ts