Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
spacehaz committed Nov 20, 2024
1 parent baf0013 commit 6103794
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Linkdrop SDK

## 2.0.10
-

## 2.0.9
- added src param to link (src=d)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkdrop-sdk",
"version": "2.0.9",
"version": "2.0.10",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
12 changes: 8 additions & 4 deletions src/api/batch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,36 @@ import { defineRequestKeyHeader } from '../../helpers'
const requests: TRequests = {
getBatches: (
apiHost,
apiKey,
campaignSig,
campaignId
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey, campaignSig)
return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches`, {
headers,
})
},
getBatch: (
apiHost,
apiKey,
campaignSig,
campaignId,
batchId
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey, campaignSig)
return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches/${batchId}`, {
headers,
})
},
createBatch: (
apiHost,
apiKey,
campaignSig,
campaignId,
claimLinks,
batchDescription
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey, campaignSig)
return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/save-batch`, {
claim_links: claimLinks,
batch_description: batchDescription
Expand All @@ -41,12 +44,13 @@ const requests: TRequests = {
},
addLinks: (
apiHost,
apiKey,
campaignSig,
campaignId,
batchId,
claimLinks,
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey, campaignSig)
return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches/${batchId}/add-links `, {
claim_links: claimLinks
}, {
Expand Down
4 changes: 4 additions & 0 deletions src/api/batch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TAddLinksResponse = {

export type TGetBatches = (
apiHost: string,
apiKey: string,
campaignSig: string,
campaignId: string
) => Promise<
Expand All @@ -39,6 +40,7 @@ export type TGetBatches = (

export type TGetBatch = (
apiHost: string,
apiKey: string,
campaignSig: string,
campaignId: string,
batchId: string
Expand All @@ -50,6 +52,7 @@ export type TGetBatch = (

export type TCreateBatch = (
apiHost: string,
apiKey: string,
campaignSig: string,
campaignId: string,
claimLinks: TLinkItem[],
Expand All @@ -62,6 +65,7 @@ export type TCreateBatch = (

export type TAddLinks = (
apiHost: string,
apiKey: string,
campaignSig: string,
campaignId: string,
batchId: string,
Expand Down
3 changes: 2 additions & 1 deletion src/api/campaign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { defineRequestKeyHeader } from '../../helpers'
const requests: TRequests = {
getCampaign: (
apiHost,
apiKey,
campaignSig,
campaignId
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey, campaignSig)
return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}`, {
headers
})
Expand Down
1 change: 1 addition & 0 deletions src/api/campaign/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type TGetCampaignResponse = {

export type TGetCampaign = (
apiHost: string,
apiKey: string,
campaignSig: string,
campaignId: string,
) => Promise<
Expand Down
14 changes: 12 additions & 2 deletions src/api/link/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,52 @@ import { defineRequestKeyHeader } from '../../helpers'
const requests: TRequests = {
getParams: (
apiHost,
apiKey,
linkId,
) => {
const headers = defineRequestKeyHeader(apiKey)

return axios.get(`${apiHost}/api/v2/claim-links/${linkId}`)
},
getStatus: (
apiHost,
apiKey,
linkId
) => {
const headers = defineRequestKeyHeader(apiKey)

return axios.get(`${apiHost}/api/v2/claim-links/${linkId}/status`)
},
deactivateLink: (
apiHost,
apiKey,
campaignSig,
linkId
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey)
return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/claim-links/${linkId}/deactivate`, {}, {
headers
})
},
reactivateLink: (
apiHost,
apiKey,
campaignSig,
linkId
) => {
const headers = defineRequestKeyHeader(campaignSig)
const headers = defineRequestKeyHeader(apiKey)
return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/claim-links/${linkId}/reactivate`, {}, {
headers
})
},
redeemLink: (
apiHost,
apiKey,
linkId,
receiverAddress,
receiverSignature
) => {
const headers = defineRequestKeyHeader(apiKey)
return axios.post(`${apiHost}/api/v2/claim-links/${linkId}/claim`, {
receiver_address: receiverAddress,
receiver_signature: receiverSignature
Expand Down
5 changes: 5 additions & 0 deletions src/api/link/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type TRedeemLinkResponse = {

export type TGetLinkParams = (
apiHost: string,
apiKey: string,
linkId: string
) => Promise<
AxiosResponse<
Expand All @@ -39,6 +40,7 @@ export type TGetLinkParams = (

export type TGetLinkStatus = (
apiHost: string,
apiKey: string,
linkId: string
) => Promise<
AxiosResponse<
Expand All @@ -48,6 +50,7 @@ export type TGetLinkStatus = (

export type TDeactivateLink = (
apiHost: string,
apiKey: string,
campaignSig: string,
linkId: string
) => Promise<
Expand All @@ -58,6 +61,7 @@ export type TDeactivateLink = (

export type TRedeemLink = (
apiHost: string,
apiKey: string,
linkId: string,
receiverAddress: string,
receiverSignature: string
Expand All @@ -69,6 +73,7 @@ export type TRedeemLink = (

export type TReactivateLink = (
apiHost: string,
apiKey: string,
campaignSig: string,
linkId: string
) => Promise<
Expand Down
28 changes: 22 additions & 6 deletions src/helpers/define-request-key-header.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
type TDefineRequestKeyHeader = (campaignSig: string) => Record<string, string>
const defineRequestKeyHeader: TDefineRequestKeyHeader = (campaignSig) => {
type TDefineRequestKeyHeader = (
apiKey: string,
campaignSig?: string
) => Record<string, string>

const defineRequestKeyHeader: TDefineRequestKeyHeader = (
apiKey,
campaignSig
) => {
const headers = {}
headers[
'X-CAMPAIGN-KEY'
] = campaignSig

if (campaignSig) {
headers[
'X-CAMPAIGN-KEY'
] = campaignSig
}


if (apiKey) {
headers['authorization'] = `Bearer ${apiKey}`
}

return headers
}

export default defineRequestKeyHeader
export default defineRequestKeyHeader
2 changes: 2 additions & 0 deletions src/helpers/get-link-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ethers } from 'ethers'

const getLinkParams = async (
apiHost: string,
apiKey: string,
claimCode: string
) => {
let linkId
Expand All @@ -16,6 +17,7 @@ const getLinkParams = async (

const linkParams = await linkApi.getParams(
apiHost,
apiKey,
linkId
)
const { success, data } = linkParams.data
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/get-link-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from 'ethers'

const getLinkStatus = async (
apiHost: string,
apiKey: string,
claimCode: string
) => {
let linkId
Expand All @@ -14,6 +15,7 @@ const getLinkStatus = async (
}
const linkStatus = await linkApi.getStatus(
apiHost,
apiKey,
linkId
)
if (linkStatus.data) {
Expand Down

0 comments on commit 6103794

Please sign in to comment.