(
link: ExpandedLink,
{ skipDecodeKey = false }: { skipDecodeKey?: boolean } = {},
)
| 33 | |
| 34 | // Transform link with additional properties |
| 35 | export const transformLink = ( |
| 36 | link: ExpandedLink, |
| 37 | { skipDecodeKey = false }: { skipDecodeKey?: boolean } = {}, |
| 38 | ) => { |
| 39 | const tags = (link.tags || []).map(({ tag }) => tag); |
| 40 | const webhookIds = link.webhooks?.map(({ webhookId }) => webhookId) ?? []; |
| 41 | |
| 42 | if (!skipDecodeKey) { |
| 43 | link = decodeLinkIfCaseSensitive(link); |
| 44 | } |
| 45 | |
| 46 | const { |
| 47 | // remove webhooks array, dashboard, partnerGroupDefaultLinkId |
| 48 | webhooks, |
| 49 | dashboard, |
| 50 | partnerGroupDefaultLinkId, |
| 51 | // hide undocumented fields from the API response for now |
| 52 | lastLeadAt, |
| 53 | lastConversionAt, |
| 54 | programEnrollment, |
| 55 | ...rest |
| 56 | } = link; |
| 57 | |
| 58 | return { |
| 59 | ...rest, |
| 60 | saleAmount: toCentsNumber(rest.saleAmount), |
| 61 | identifier: null, // backwards compatibility |
| 62 | tagId: tags?.[0]?.id ?? null, // backwards compatibility |
| 63 | tags, |
| 64 | webhookIds, |
| 65 | qrCode: `https://api.dub.co/qr?url=${link.shortLink}?qr=1`, |
| 66 | workspaceId: link.projectId ? prefixWorkspaceId(link.projectId) : null, |
| 67 | ...(dashboard && { dashboardId: dashboard.id || null }), |
| 68 | }; |
| 69 | }; |
no test coverage detected
searching dependent graphs…