MCPcopy
hub / github.com/dubinc/dub / transformLink

Function transformLink

apps/web/lib/api/links/utils/transform-link.ts:35–69  ·  view source on GitHub ↗
(
  link: ExpandedLink,
  { skipDecodeKey = false }: { skipDecodeKey?: boolean } = {},
)

Source from the content-addressed store, hash-verified

33
34// Transform link with additional properties
35export 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};

Callers 15

getLinksForWorkspaceFunction · 0.90
createLinkFunction · 0.90
bulkUpdateLinksFunction · 0.90
deleteLinkFunction · 0.90
bulkCreateLinksFunction · 0.90
updateLinkFunction · 0.90
sendLinkClickWebhooksFunction · 0.90
getCustomerEventsFunction · 0.90
getEventsFunction · 0.90
transformLeadEventDataFunction · 0.90
transformSaleEventDataFunction · 0.90

Calls 3

toCentsNumberFunction · 0.90
prefixWorkspaceIdFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…