{"version":3,"file":"connect-tunnel-x-5XOct5Tm.mjs","names":[],"sources":["../src/penpal/connect-tunnel-x.ts"],"sourcesContent":["import type { RequestOptions } from \"@pkg/sdk/lib/sdks\";\nimport type {\n  CardSetupIntent,\n  CreateCardSetupIntentRes,\n  PublicCardCheckoutRequest,\n  PublicCardCheckoutResponse,\n  UpdateCardSetupIntentReq,\n} from \"@pkg/sdk/models\";\nimport type { Connection } from \"penpal\";\nimport { connectToWindow } from \".\";\n\n// Note: this file is paired with customer-portal/src/routes/embeds/v1/tunnel-x\n// The methods below should also be present in CheckoutTunnelX\n\ntype TunnelXIFrameMethods = {\n  startPayment: () => void;\n  confirmPayment: () => void;\n  submitCheckout: (values: Record<string, string>) => Promise<unknown>;\n  getCheckoutPreview: () => void;\n  getCardSetupIntent: (cardSetupIntentId: string) => Promise<CardSetupIntent>;\n  createCardSetupIntent: (secureToken: string) => Promise<CreateCardSetupIntentRes>;\n  queryPublicEndpoint: (methodName: string, params: unknown, options?: RequestOptions) => Promise<unknown>;\n};\n\ntype TunnelXParentMethods = Record<string, never>;\n\nexport type TunnelXIFrameConnection = Connection<TunnelXIFrameMethods>;\n\nexport type TunnelXParentConnection = Connection<TunnelXParentMethods>;\n\nexport const connectToTunnelXIframe = (iframe: HTMLIFrameElement, methods: TunnelXParentMethods) => {\n  return connectToWindow<TunnelXIFrameMethods>({ window: iframe.contentWindow as Window, methods });\n};\n\nexport const connectToTunnelXParent = (methods: TunnelXIFrameMethods) => {\n  return connectToWindow<TunnelXParentMethods>({ window: window.parent, methods });\n};\n\n/**\n * SDK type for publicEndpoints proxy.\n * Matches the methods on PublicCors from @pkg/sdk that are called through queryPublicEndpoint.\n * Parameter types match the SDK's operation request types.\n * All methods accept an optional RequestOptions parameter for passing headers (e.g., x-request-id).\n */\ntype PublicEndpointsProxy = {\n  createCardSetupIntent: (\n    params: { checkoutToken: string },\n    options?: RequestOptions,\n  ) => Promise<CreateCardSetupIntentRes>;\n  updateCardSetupIntent: (\n    params: {\n      checkoutToken: string;\n      cardSetupIntentId: string;\n      updateCardSetupIntentReq: UpdateCardSetupIntentReq;\n    },\n    options?: RequestOptions,\n  ) => Promise<CardSetupIntent>;\n  getCardSetupIntent: (\n    params: { checkoutToken: string; cardSetupIntentId: string },\n    options?: RequestOptions,\n  ) => Promise<CardSetupIntent>;\n  cardCheckout: (\n    params: {\n      checkoutToken: string;\n      publicCardCheckoutRequest: PublicCardCheckoutRequest;\n    },\n    options?: RequestOptions,\n  ) => Promise<PublicCardCheckoutResponse>;\n  cardCheckoutVerify: (\n    params: { checkoutToken: string },\n    options?: RequestOptions,\n  ) => Promise<PublicCardCheckoutResponse>;\n};\n\nexport class TunnelXManager {\n  private penpalConn: TunnelXIFrameConnection;\n  public _methods: TunnelXIFrameMethods;\n\n  static createFromPenpalConnection = async (penpalConn: TunnelXIFrameConnection) => {\n    const methods = await penpalConn.promise;\n    const manager = new TunnelXManager(penpalConn, methods);\n    return manager;\n  };\n\n  private constructor(penpalConn: TunnelXIFrameConnection, penpalMethods: TunnelXIFrameMethods) {\n    this.penpalConn = penpalConn;\n    this._methods = penpalMethods;\n  }\n\n  /**\n   * Makes publicEndpoints act like a real PK client, but actually forwards all calls\n   * through queryPublicEndpoint and sends it through penpal.\n   */\n  get publicEndpoints(): PublicEndpointsProxy {\n    const handler = {\n      get: (_target: Record<string, never>, prop: string) => {\n        return async (...args: unknown[]) => {\n          return await this._methods.queryPublicEndpoint(prop, args[0], args[1] as RequestOptions | undefined);\n        };\n      },\n    };\n    return new Proxy({}, handler) as unknown as PublicEndpointsProxy;\n  }\n\n  destroy() {\n    this.penpalConn.destroy();\n  }\n}\n"],"mappings":";;;AA8BA,MAAa,0BAA0B,QAA2B,YAAkC;AAClG,QAAO,gBAAsC;EAAE,QAAQ,OAAO;EAAyB;EAAS,CAAC;;AAGnG,MAAa,0BAA0B,YAAkC;AACvE,QAAO,gBAAsC;EAAE,QAAQ,OAAO;EAAQ;EAAS,CAAC;;AAuClF,IAAa,iBAAb,MAAa,eAAe;CAC1B,AAAQ;CACR,AAAO;CAEP,OAAO,6BAA6B,OAAO,eAAwC;AAGjF,SADgB,IAAI,eAAe,YADnB,MAAM,WAAW,QACsB;;CAIzD,AAAQ,YAAY,YAAqC,eAAqC;AAC5F,OAAK,aAAa;AAClB,OAAK,WAAW;;;;;;CAOlB,IAAI,kBAAwC;AAQ1C,SAAO,IAAI,MAAM,EAAE,EAPH,EACd,MAAM,SAAgC,SAAiB;AACrD,UAAO,OAAO,GAAG,SAAoB;AACnC,WAAO,MAAM,KAAK,SAAS,oBAAoB,MAAM,KAAK,IAAI,KAAK,GAAiC;;KAGzG,CAC4B;;CAG/B,UAAU;AACR,OAAK,WAAW,SAAS"}