{"version":3,"file":"internals.mjs","names":[],"sources":["../../src/utils/internals.ts"],"sourcesContent":["import type { B2BRequest, Reply, ReplyStatus } from '../Common/types.js';\nimport { assert } from './assert.js';\nimport { NMB2BError } from './NMB2BError.js';\n\nexport type WithInjectedSendTime<T extends B2BRequest> = Omit<T, 'sendTime'> & {\n  sendTime?: Date | undefined;\n};\n\nexport function injectSendTime<T extends B2BRequest>(\n  values: WithInjectedSendTime<T>,\n): T {\n  const sendTime = new Date();\n\n  return { sendTime, ...values } as T;\n}\n\nexport function assertOkReply<T extends Reply>(\n  reply: T,\n): asserts reply is T & { status: 'OK' } {\n  assert(\n    typeof reply === 'object' &&\n      // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Just in case the response is completely broken.\n      reply !== null &&\n      'status' in reply,\n    `Invalid NM B2B Response:\\n` + JSON.stringify(reply),\n  );\n\n  if (reply.status !== 'OK') {\n    throw new NMB2BError({\n      reply: reply as T & { status: Exclude<ReplyStatus, 'OK'> },\n    });\n  }\n}\n"],"mappings":";;;AAQA,SAAgB,eACd,QACG;AAGH,QAAO;EAAE,0BAAA,IAFY,MAEJ;EAAE,GAAG;EAAQ;;AAGhC,SAAgB,cACd,OACuC;AACvC,QACE,OAAO,UAAU,YAEf,UAAU,QACV,YAAY,OACd,+BAA+B,KAAK,UAAU,MAAM,CACrD;AAED,KAAI,MAAM,WAAW,KACnB,OAAM,IAAI,WAAW,EACZ,OACR,CAAC"}