@@ -7,6 +7,7 @@ import { apiClientManager } from "../apiClientManager-api.js";
77import { zodfetch } from "../zodfetch.js" ;
88import { z } from "zod" ;
99import type { RetryOptions } from "../schemas/index.js" ;
10+ import { ApiClient } from "../apiClient/index.js" ;
1011
1112export type IOPacket = {
1213 data ?: string | undefined ;
@@ -36,8 +37,11 @@ export async function parsePacket(value: IOPacket): Promise<any> {
3637 }
3738}
3839
39- export async function conditionallyImportAndParsePacket ( value : IOPacket ) : Promise < any > {
40- const importedPacket = await conditionallyImportPacket ( value ) ;
40+ export async function conditionallyImportAndParsePacket (
41+ value : IOPacket ,
42+ client ?: ApiClient
43+ ) : Promise < any > {
44+ const importedPacket = await conditionallyImportPacket ( value , undefined , client ) ;
4145
4246 return await parsePacket ( importedPacket ) ;
4347}
@@ -159,19 +163,20 @@ async function exportPacket(packet: IOPacket, pathPrefix: string): Promise<IOPac
159163
160164export async function conditionallyImportPacket (
161165 packet : IOPacket ,
162- tracer ?: TriggerTracer
166+ tracer ?: TriggerTracer ,
167+ client ?: ApiClient
163168) : Promise < IOPacket > {
164169 if ( packet . dataType !== "application/store" ) {
165170 return packet ;
166171 }
167172
168173 if ( ! tracer ) {
169- return await importPacket ( packet ) ;
174+ return await importPacket ( packet , undefined , client ) ;
170175 } else {
171176 const result = await tracer . startActiveSpan (
172177 "store.downloadPayload" ,
173178 async ( span ) => {
174- return await importPacket ( packet , span ) ;
179+ return await importPacket ( packet , span , client ) ;
175180 } ,
176181 {
177182 attributes : {
@@ -209,16 +214,18 @@ export async function resolvePresignedPacketUrl(
209214 }
210215}
211216
212- async function importPacket ( packet : IOPacket , span ?: Span ) : Promise < IOPacket > {
217+ async function importPacket ( packet : IOPacket , span ?: Span , client ?: ApiClient ) : Promise < IOPacket > {
213218 if ( ! packet . data ) {
214219 return packet ;
215220 }
216221
217- if ( ! apiClientManager . client ) {
222+ const $client = client ?? apiClientManager . client ;
223+
224+ if ( ! $client ) {
218225 return packet ;
219226 }
220227
221- const presignedResponse = await apiClientManager . client . getPayloadUrl ( packet . data ) ;
228+ const presignedResponse = await $ client. getPayloadUrl ( packet . data ) ;
222229
223230 const response = await zodfetch ( z . any ( ) , presignedResponse . presignedUrl , undefined , {
224231 retry : ioRetryOptions ,
0 commit comments