{"version":3,"file":"to-raw-notification.mjs","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAgC;IAEhC,MAAM,iBAAiB,GAAG,CAAC,CAAQ,EAAS,EAAE;QAC5C,MAAM,IAAI,GAAW,IAAI,EAAE,iBAAiB,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,mEAAmE,IAAI,EAAE,CAC1E,CAAC;IACJ,CAAC,CAAC;IAEF,IAAI,IAAI,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;QAC1C,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;SACH,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;QAC1C,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,CAAC,iBAAiB;SACF,CAAC;IAC/B,CAAC;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import type {\n  UnprocessedRawNotification,\n  NormalisedAPINotification,\n  OnChainRawNotification,\n  PlatformRawNotification,\n} from 'src/NotificationServicesController/types/notification-api';\n\n/**\n * A true \"raw notification\" does not have some fields that exist on this type. E.g. the `type` field.\n * This is retro-actively added when we fetch notifications to be able to easily type-discriminate notifications.\n * We use this to ensure that the correct missing fields are added to the raw shapes\n *\n * @param data - raw onchain notification\n * @returns a complete raw onchain notification\n */\nexport function toRawAPINotification(\n  data: UnprocessedRawNotification,\n): NormalisedAPINotification {\n  const exhaustedAllCases = (_: never): never => {\n    const type: string = data?.notification_type;\n    throw new Error(\n      `toRawAPINotification - No processor found for notification kind ${type}`,\n    );\n  };\n\n  if (data.notification_type === 'on-chain') {\n    if (!data?.payload?.data?.kind) {\n      throw new Error(\n        'toRawAPINotification - No kind found for on-chain notification',\n      );\n    }\n    return {\n      ...data,\n      type: data.payload.data.kind,\n    } as OnChainRawNotification;\n  }\n\n  if (data.notification_type === 'platform') {\n    return {\n      ...data,\n      type: data.notification_type,\n    } as PlatformRawNotification;\n  }\n\n  return exhaustedAllCases(data);\n}\n"]}