Skip to content

Commit

Permalink
fix: svix json serialiation
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 19, 2023
1 parent 3cb7122 commit 6ac319b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/api/src/services/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const NotificationsService = (): INotificationsService => {
accountId: recipient.accountId,
walletId: recipient.walletId,
eventType,
payload: transaction,
payload: { transaction },
})
if (result instanceof Error) return result

Expand Down
19 changes: 12 additions & 7 deletions core/api/src/services/svix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,24 @@ export const CallbackService = (config: SvixConfig) => {
walletId: WalletId
payload: Record<string, JSONValue>
}) => {
const accountCallbackId = getAccountCallbackId(accountId)
addAttributesToCurrentSpan({ "callback.application": accountCallbackId })
try {
const accountCallbackId = getAccountCallbackId(accountId)
addAttributesToCurrentSpan({ "callback.application": accountCallbackId })

const res = await createApplication(accountCallbackId)
if (res instanceof Error) return res
const result = await createApplication(accountCallbackId)
if (result instanceof Error) return result

try {
const safePayload = JSON.parse(
JSON.stringify(payload, (_key, value) =>
typeof value === "bigint" ? value.toString() : value,
),
)
const res = await svix.message.create(accountCallbackId, {
eventType,
payload: { ...payload, accountId, walletId, eventType },
payload: { ...safePayload, accountId, walletId, eventType },
})

const prefixedPayload = prefixObjectKeys(payload, "callback.payload.")
const prefixedPayload = prefixObjectKeys(safePayload, "callback.payload")
addAttributesToCurrentSpan({
...prefixedPayload,
["callback.accountId"]: accountId,
Expand Down

0 comments on commit 6ac319b

Please sign in to comment.