diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d9d457..10df46f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Linkdrop SDK +## 2.0.10 +- + ## 2.0.9 - added src param to link (src=d) diff --git a/package.json b/package.json index f322463..13460ce 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/api/batch/index.ts b/src/api/batch/index.ts index 6b4cce0..41a86eb 100644 --- a/src/api/batch/index.ts +++ b/src/api/batch/index.ts @@ -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 @@ -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 }, { diff --git a/src/api/batch/types.ts b/src/api/batch/types.ts index aa92bca..6c734ab 100644 --- a/src/api/batch/types.ts +++ b/src/api/batch/types.ts @@ -29,6 +29,7 @@ type TAddLinksResponse = { export type TGetBatches = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string ) => Promise< @@ -39,6 +40,7 @@ export type TGetBatches = ( export type TGetBatch = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, batchId: string @@ -50,6 +52,7 @@ export type TGetBatch = ( export type TCreateBatch = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, claimLinks: TLinkItem[], @@ -62,6 +65,7 @@ export type TCreateBatch = ( export type TAddLinks = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, batchId: string, diff --git a/src/api/campaign/index.ts b/src/api/campaign/index.ts index f94d708..6ee0237 100644 --- a/src/api/campaign/index.ts +++ b/src/api/campaign/index.ts @@ -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 }) diff --git a/src/api/campaign/types.ts b/src/api/campaign/types.ts index 51b0a6b..c2f851b 100644 --- a/src/api/campaign/types.ts +++ b/src/api/campaign/types.ts @@ -8,6 +8,7 @@ type TGetCampaignResponse = { export type TGetCampaign = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, ) => Promise< diff --git a/src/api/link/index.ts b/src/api/link/index.ts index 066fb50..d553dca 100644 --- a/src/api/link/index.ts +++ b/src/api/link/index.ts @@ -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 diff --git a/src/api/link/types.ts b/src/api/link/types.ts index ec5fabb..a44a6ef 100644 --- a/src/api/link/types.ts +++ b/src/api/link/types.ts @@ -30,6 +30,7 @@ type TRedeemLinkResponse = { export type TGetLinkParams = ( apiHost: string, + apiKey: string, linkId: string ) => Promise< AxiosResponse< @@ -39,6 +40,7 @@ export type TGetLinkParams = ( export type TGetLinkStatus = ( apiHost: string, + apiKey: string, linkId: string ) => Promise< AxiosResponse< @@ -48,6 +50,7 @@ export type TGetLinkStatus = ( export type TDeactivateLink = ( apiHost: string, + apiKey: string, campaignSig: string, linkId: string ) => Promise< @@ -58,6 +61,7 @@ export type TDeactivateLink = ( export type TRedeemLink = ( apiHost: string, + apiKey: string, linkId: string, receiverAddress: string, receiverSignature: string @@ -69,6 +73,7 @@ export type TRedeemLink = ( export type TReactivateLink = ( apiHost: string, + apiKey: string, campaignSig: string, linkId: string ) => Promise< diff --git a/src/helpers/define-request-key-header.ts b/src/helpers/define-request-key-header.ts index 882a665..e80124a 100644 --- a/src/helpers/define-request-key-header.ts +++ b/src/helpers/define-request-key-header.ts @@ -1,10 +1,26 @@ -type TDefineRequestKeyHeader = (campaignSig: string) => Record -const defineRequestKeyHeader: TDefineRequestKeyHeader = (campaignSig) => { +type TDefineRequestKeyHeader = ( + apiKey: string, + campaignSig?: string +) => Record + +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 \ No newline at end of file diff --git a/src/helpers/get-link-params.ts b/src/helpers/get-link-params.ts index 448ea20..272d069 100644 --- a/src/helpers/get-link-params.ts +++ b/src/helpers/get-link-params.ts @@ -4,6 +4,7 @@ import { ethers } from 'ethers' const getLinkParams = async ( apiHost: string, + apiKey: string, claimCode: string ) => { let linkId @@ -16,6 +17,7 @@ const getLinkParams = async ( const linkParams = await linkApi.getParams( apiHost, + apiKey, linkId ) const { success, data } = linkParams.data diff --git a/src/helpers/get-link-status.ts b/src/helpers/get-link-status.ts index 4289e49..665a0c1 100644 --- a/src/helpers/get-link-status.ts +++ b/src/helpers/get-link-status.ts @@ -3,6 +3,7 @@ import { ethers } from 'ethers' const getLinkStatus = async ( apiHost: string, + apiKey: string, claimCode: string ) => { let linkId @@ -14,6 +15,7 @@ const getLinkStatus = async ( } const linkStatus = await linkApi.getStatus( apiHost, + apiKey, linkId ) if (linkStatus.data) {