tapimo 0.8.0 → 0.9.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.
Files changed (80) hide show
  1. package/dist/App.d.ts +2095 -2111
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/App.js +0 -1
  4. package/dist/App.js.map +1 -1
  5. package/dist/admin/apps/verified-tokens.d.ts +166 -166
  6. package/dist/apps/data/App.d.ts +4084 -3845
  7. package/dist/apps/data/App.d.ts.map +1 -1
  8. package/dist/apps/data/routes/activities.d.ts +270 -270
  9. package/dist/apps/data/routes/addresses.d.ts +248 -17
  10. package/dist/apps/data/routes/addresses.d.ts.map +1 -1
  11. package/dist/apps/data/routes/balances.d.ts +272 -2
  12. package/dist/apps/data/routes/balances.d.ts.map +1 -1
  13. package/dist/apps/data/routes/balances.js +114 -2
  14. package/dist/apps/data/routes/balances.js.map +1 -1
  15. package/dist/apps/data/routes/blocks.d.ts +123 -123
  16. package/dist/apps/data/routes/earn.d.ts +65 -3
  17. package/dist/apps/data/routes/earn.d.ts.map +1 -1
  18. package/dist/apps/data/routes/earn.js +259 -14
  19. package/dist/apps/data/routes/earn.js.map +1 -1
  20. package/dist/apps/data/routes/rpc.d.ts +31 -31
  21. package/dist/apps/data/routes/tokens.d.ts +454 -454
  22. package/dist/apps/data/routes/transfers.d.ts +81 -81
  23. package/dist/apps/funding/App.d.ts +40 -299
  24. package/dist/apps/funding/App.d.ts.map +1 -1
  25. package/dist/apps/funding/App.js +20 -5
  26. package/dist/apps/funding/App.js.map +1 -1
  27. package/dist/apps/funding/routes/deposit-addresses.d.ts +43 -434
  28. package/dist/apps/funding/routes/deposit-addresses.d.ts.map +1 -1
  29. package/dist/apps/funding/routes/deposit-addresses.js +21 -103
  30. package/dist/apps/funding/routes/deposit-addresses.js.map +1 -1
  31. package/dist/apps/funding/routes/quotes.d.ts +89 -89
  32. package/dist/apps/funding/routes/transfers.js +5 -5
  33. package/dist/apps/funding/routes/transfers.js.map +1 -1
  34. package/dist/apps/management/routes/invitations.d.ts +134 -134
  35. package/dist/apps/management/routes/orgs.d.ts +98 -98
  36. package/dist/apps/management/routes/verified-token-requests.d.ts +83 -83
  37. package/dist/apps/mpp/App.d.ts +44 -44
  38. package/dist/db/Db.d.ts.map +1 -1
  39. package/dist/db/Db.js +8 -0
  40. package/dist/db/Db.js.map +1 -1
  41. package/dist/db/tables/fundingDeposits.d.ts +18 -1
  42. package/dist/db/tables/fundingDeposits.d.ts.map +1 -1
  43. package/dist/db/tables/fundingDeposits.js +46 -2
  44. package/dist/db/tables/fundingDeposits.js.map +1 -1
  45. package/dist/internal/Auth.d.ts +4 -0
  46. package/dist/internal/Auth.d.ts.map +1 -1
  47. package/dist/internal/Auth.js +11 -2
  48. package/dist/internal/Auth.js.map +1 -1
  49. package/dist/internal/funding/Provider.d.ts +6 -6
  50. package/dist/internal/funding/Provider.d.ts.map +1 -1
  51. package/dist/internal/funding/Reconciliation.d.ts.map +1 -1
  52. package/dist/internal/funding/Reconciliation.js +101 -16
  53. package/dist/internal/funding/Reconciliation.js.map +1 -1
  54. package/dist/internal/funding/providers/relay.d.ts.map +1 -1
  55. package/dist/internal/funding/providers/relay.js +6 -2
  56. package/dist/internal/funding/providers/relay.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/App.test.ts +32 -0
  59. package/src/App.ts +4 -1
  60. package/src/Client.test-d.ts +56 -33
  61. package/src/apps/composition.test.ts +39 -10
  62. package/src/apps/data/routes/balances.test.ts +42 -0
  63. package/src/apps/data/routes/balances.ts +218 -85
  64. package/src/apps/data/routes/earn.test.ts +89 -9
  65. package/src/apps/data/routes/earn.ts +355 -14
  66. package/src/apps/funding/App.ts +20 -5
  67. package/src/apps/funding/routes/deposit-addresses.test.ts +43 -22
  68. package/src/apps/funding/routes/deposit-addresses.ts +34 -117
  69. package/src/apps/funding/routes/transfers.test.ts +6 -25
  70. package/src/apps/funding/routes/transfers.ts +5 -5
  71. package/src/db/Db.ts +9 -0
  72. package/src/db/tables/fundingDeposits.test.ts +101 -0
  73. package/src/db/tables/fundingDeposits.ts +71 -2
  74. package/src/internal/Auth.test.ts +28 -0
  75. package/src/internal/Auth.ts +15 -1
  76. package/src/internal/funding/Provider.ts +4 -4
  77. package/src/internal/funding/Reconciliation.test.ts +292 -54
  78. package/src/internal/funding/Reconciliation.ts +160 -53
  79. package/src/internal/funding/SourceObservation.test.ts +2 -2
  80. package/src/internal/funding/providers/relay.ts +7 -2
@@ -187,7 +187,20 @@ export declare namespace listBySourceTransaction {
187
187
  }
188
188
  }
189
189
 
190
- /** Returns whether an address has a nonterminal source transfer awaiting provider attribution. */
190
+ /** Lists nonterminal source transfers that await provider attribution. */
191
+ export function listUnattributed(db: Db.Db, depositAddressId: string): Promise<Record[]> {
192
+ return db.kysely
193
+ .selectFrom('funding_deposits')
194
+ .selectAll()
195
+ .where('depositAddressId', '=', depositAddressId)
196
+ .where('providerRequestId', 'is', null)
197
+ .where('status', 'not in', ['completed', 'refunded'])
198
+ .orderBy('createdAt', 'asc')
199
+ .orderBy('id', 'asc')
200
+ .execute()
201
+ }
202
+
203
+ /** Returns whether an address has a source transfer awaiting provider attribution. */
191
204
  export async function hasUnattributed(db: Db.Db, depositAddressId: string): Promise<boolean> {
192
205
  return Boolean(
193
206
  await db.kysely
@@ -195,7 +208,6 @@ export async function hasUnattributed(db: Db.Db, depositAddressId: string): Prom
195
208
  .select('id')
196
209
  .where('depositAddressId', '=', depositAddressId)
197
210
  .where('providerRequestId', 'is', null)
198
- .where('status', 'not in', ['completed', 'refunded'])
199
211
  .limit(1)
200
212
  .executeTakeFirst(),
201
213
  )
@@ -265,6 +277,63 @@ export declare namespace listByAddress {
265
277
  }
266
278
  }
267
279
 
280
+ /** Lists deposits for one reusable source-chain address newest-first. */
281
+ export function listByDepositAddress(
282
+ db: Db.Db,
283
+ options: listByDepositAddress.Options,
284
+ ): Promise<Record[]> {
285
+ const { cursor, depositAddress, limit, owner } = options
286
+ const address = /^0x[0-9a-fA-F]{40}$/.test(depositAddress)
287
+ ? depositAddress.toLowerCase()
288
+ : depositAddress
289
+ let query = db.kysely
290
+ .selectFrom('funding_deposits')
291
+ .innerJoin(
292
+ 'funding_deposit_addresses',
293
+ 'funding_deposit_addresses.id',
294
+ 'funding_deposits.depositAddressId',
295
+ )
296
+ .selectAll('funding_deposits')
297
+ .where('funding_deposit_addresses.address', '=', address)
298
+ .where('funding_deposit_addresses.environment', '=', owner.environment)
299
+ .where('funding_deposit_addresses.orgId', '=', owner.orgId)
300
+ .where('funding_deposits.environment', '=', owner.environment)
301
+ .where('funding_deposits.orgId', '=', owner.orgId)
302
+ if (owner.projectId !== undefined)
303
+ query = query
304
+ .where('funding_deposit_addresses.projectId', '=', owner.projectId)
305
+ .where('funding_deposits.projectId', '=', owner.projectId)
306
+ if (cursor)
307
+ query = query.where((eb) =>
308
+ eb.or([
309
+ eb('funding_deposits.createdAt', '<', cursor.createdAt),
310
+ eb.and([
311
+ eb('funding_deposits.createdAt', '=', cursor.createdAt),
312
+ eb('funding_deposits.id', '<', cursor.id),
313
+ ]),
314
+ ]),
315
+ )
316
+ return query
317
+ .orderBy('funding_deposits.createdAt', 'desc')
318
+ .orderBy('funding_deposits.id', 'desc')
319
+ .limit(limit)
320
+ .execute()
321
+ }
322
+
323
+ export declare namespace listByDepositAddress {
324
+ /** Deposit address filter, ownership, and paging options. */
325
+ type Options = {
326
+ /** Exclusive lower bound from the previous page. */
327
+ cursor?: listByAddress.Cursor | undefined
328
+ /** Reusable source-chain address that received the funds. */
329
+ depositAddress: string
330
+ /** Maximum rows to return. */
331
+ limit: number
332
+ /** Ownership filter derived from the authenticated API key. */
333
+ owner: Owner
334
+ }
335
+ }
336
+
268
337
  /** Lists one recipient's owner-visible deposits newest-first. */
269
338
  export function listByRecipient(db: Db.Db, options: listByRecipient.Options): Promise<Record[]> {
270
339
  const { cursor, limit, owner, recipient } = options
@@ -1256,6 +1256,34 @@ describe('require', () => {
1256
1256
  })
1257
1257
  })
1258
1258
 
1259
+ test('session challenge rejects a chain outside the configured allowlist', async () => {
1260
+ const mpp = Object.assign(
1261
+ createMppServer({
1262
+ chainId: Viem.chainId.mainnet,
1263
+ getClient: ({ chainId = Viem.chainId.mainnet }) => Viem.getClient({ chainId }),
1264
+ }),
1265
+ { sessionChainIds: new Set([Viem.chainId.mainnet, Viem.chainId.testnet]) },
1266
+ )
1267
+ const app = createApp({
1268
+ auth: {
1269
+ apiKey: { resolve: TestApp.resolver({ keys: [{ ...key, token }] }) },
1270
+ mpp,
1271
+ rateLimit: overQuota(),
1272
+ },
1273
+ policy: {
1274
+ mpp: { session: { amount: '1' } },
1275
+ public: { rateLimit: { perMinute: 1 } },
1276
+ },
1277
+ })
1278
+
1279
+ const response = await app.request('/protected?chainId=31318')
1280
+ const body = await response.json()
1281
+
1282
+ expect(response.status).toBe(429)
1283
+ expect(response.headers.has('www-authenticate')).toBe(false)
1284
+ expect(body).toMatchObject({ error: { code: 'payment_required' } })
1285
+ })
1286
+
1259
1287
  test('route session overrides propagate to the challenge', async () => {
1260
1288
  const mpp = createMppServer()
1261
1289
  const app = createApp({
@@ -117,6 +117,8 @@ type MppHandler = {
117
117
  session(options: Mpp.Session): MiddlewareHandler
118
118
  /** Resolves the chain from a challenge issued by this server. */
119
119
  sessionChainId?: ((c: hono_Context) => number | undefined) | undefined
120
+ /** Chains accepted from request-driven Tempo Session payment overrides. */
121
+ sessionChainIds?: ReadonlySet<number> | undefined
120
122
  }
121
123
 
122
124
  /**
@@ -504,6 +506,7 @@ export function middleware<
504
506
  const {
505
507
  rateLimit: mppRateLimit = defaultMppRateLimit,
506
508
  session: session_ = {},
509
+ sessionChainIds,
507
510
  ...mpp
508
511
  } = options.mpp === false ? {} : (options.mpp ?? {})
509
512
  const secretKey = resolveMppSecretKey(mpp.secretKey)
@@ -565,6 +568,7 @@ export function middleware<
565
568
  ],
566
569
  }).session,
567
570
  sessionChainId: (c) => paymentSessionChainId(c, secretKey),
571
+ ...(sessionChainIds ? { sessionChainIds: new Set(sessionChainIds) } : {}),
568
572
  },
569
573
  }),
570
574
  rateLimit: RateLimit.memory(options.rateLimit),
@@ -666,6 +670,8 @@ export declare namespace middleware {
666
670
  rateLimit?: RateLimit.Limit | undefined
667
671
  /** Global Tempo Session options passed to the MPP method instantiator. */
668
672
  session?: NonNullable<Parameters<typeof tempo.session>[0]> | undefined
673
+ /** Chains accepted from request-driven Tempo Session payment overrides. Omit to preserve the MPP client's chain support. */
674
+ sessionChainIds?: readonly number[] | undefined
669
675
  }
670
676
  }
671
677
 
@@ -1991,8 +1997,16 @@ async function requirePayment<environment extends Environment>(
1991
1997
  }
1992
1998
 
1993
1999
  const session = options.policy.mpp?.session ?? {}
2000
+ const explicit = explicitChainId(c)
2001
+ const sessionChainIds = options.auth.mpp?.sessionChainIds
2002
+ if (explicit !== undefined && sessionChainIds && !sessionChainIds.has(explicit))
2003
+ return jsonError(c, {
2004
+ code: 'payment_required',
2005
+ message: 'Payment is not available for the requested chain',
2006
+ status: 429,
2007
+ })
1994
2008
  const chainId =
1995
- explicitChainId(c) ??
2009
+ explicit ??
1996
2010
  (c.req.method === 'POST' && session.scope?.startsWith('GET ')
1997
2011
  ? options.auth.mpp?.sessionChainId?.(c)
1998
2012
  : undefined)
@@ -503,9 +503,9 @@ export declare namespace observeDepositAddressRequest {
503
503
  recipient: string
504
504
  /** Source-chain account credited by the provider deposit. */
505
505
  refundAddress: string
506
- /** Pending provider request being accelerated. */
507
- request: listDepositAddressRequests.ReturnType['requests'][number]
508
- /** One verified source transfer attributed to the request. */
506
+ /** Provider request, when the provider has indexed the source transfer. */
507
+ request?: listDepositAddressRequests.ReturnType['requests'][number] | undefined
508
+ /** One verified source transfer received by the deposit address. */
509
509
  source: Source
510
510
  /** Chain containing the source transfer. */
511
511
  sourceChain: ChainRef
@@ -649,7 +649,7 @@ export type Provider<id extends string = string> = core_Provider.Provider<id, 'f
649
649
  input: listDepositAddressRequests.Parameters,
650
650
  signal: AbortSignal,
651
651
  ): Promise<listDepositAddressRequests.ReturnType>
652
- /** Observes authenticated delivery for a pending reusable-address request, when supported. */
652
+ /** Observes authenticated delivery for a verified reusable-address transfer, when supported. */
653
653
  observeDepositAddressRequest?(
654
654
  input: observeDepositAddressRequest.Parameters,
655
655
  signal: AbortSignal,