@poap-xyz/providers
Advanced tools
Comparing version 0.0.38 to 0.0.39
@@ -5,2 +5,3 @@ export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi'; | ||
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp'; | ||
export { PoapTokenApi, PoapTokenApiOptions } from './PoapTokenApi/PoapTokenApi'; | ||
export { InvalidMediaError } from './PoapMomentsApi/errors/InvalidMediaError'; |
@@ -5,5 +5,9 @@ import { CompassProvider } from '../../ports/CompassProvider/CompassProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
constructor(config: PoapCompassConfig); | ||
private fetchGraphQL; | ||
request<T>(query: string, variables: any): Promise<T>; | ||
} | ||
export interface PoapCompassConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
@@ -6,3 +6,4 @@ import { DropApiProvider } from '../../ports/DropApiProvider/DropApiProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
private poapApi; | ||
constructor(config: PoapDropApiConfig); | ||
createDrop(input: CreateDropInput): Promise<DropResponse>; | ||
@@ -12,1 +13,5 @@ updateDrop(input: UpdateDropInput): Promise<DropResponse>; | ||
} | ||
export interface PoapDropApiConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
export * from './MomentsApiProvider/MomentsApiProvider'; | ||
export * from './DropApiProvider/DropApiProvider'; | ||
export { TokensApiProvider, GetMintCodeResponse, PostMintCodeResponse, MintCodeInput, MintStatusResponse, } from './TokensApiProvider'; | ||
export { HttpProvider } from './HttpProvider/HttpProvider'; | ||
export { CompassProvider } from './CompassProvider/CompassProvider'; | ||
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider'; |
@@ -5,2 +5,3 @@ export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi'; | ||
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp'; | ||
export { PoapTokenApi, PoapTokenApiOptions } from './PoapTokenApi/PoapTokenApi'; | ||
export { InvalidMediaError } from './PoapMomentsApi/errors/InvalidMediaError'; |
@@ -5,5 +5,9 @@ import { CompassProvider } from '../../ports/CompassProvider/CompassProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
constructor(config: PoapCompassConfig); | ||
private fetchGraphQL; | ||
request<T>(query: string, variables: any): Promise<T>; | ||
} | ||
export interface PoapCompassConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
@@ -6,3 +6,4 @@ import { DropApiProvider } from '../../ports/DropApiProvider/DropApiProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
private poapApi; | ||
constructor(config: PoapDropApiConfig); | ||
createDrop(input: CreateDropInput): Promise<DropResponse>; | ||
@@ -12,1 +13,5 @@ updateDrop(input: UpdateDropInput): Promise<DropResponse>; | ||
} | ||
export interface PoapDropApiConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
export * from './MomentsApiProvider/MomentsApiProvider'; | ||
export * from './DropApiProvider/DropApiProvider'; | ||
export { TokensApiProvider, GetMintCodeResponse, PostMintCodeResponse, MintCodeInput, MintStatusResponse, } from './TokensApiProvider'; | ||
export { HttpProvider } from './HttpProvider/HttpProvider'; | ||
export { CompassProvider } from './CompassProvider/CompassProvider'; | ||
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider'; |
@@ -5,2 +5,3 @@ export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi'; | ||
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp'; | ||
export { PoapTokenApi, PoapTokenApiOptions } from './PoapTokenApi/PoapTokenApi'; | ||
export { InvalidMediaError } from './PoapMomentsApi/errors/InvalidMediaError'; |
@@ -5,5 +5,9 @@ import { CompassProvider } from '../../ports/CompassProvider/CompassProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
constructor(config: PoapCompassConfig); | ||
private fetchGraphQL; | ||
request<T>(query: string, variables: any): Promise<T>; | ||
} | ||
export interface PoapCompassConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
@@ -6,3 +6,4 @@ import { DropApiProvider } from '../../ports/DropApiProvider/DropApiProvider'; | ||
private baseUrl; | ||
constructor(apiKey: string, baseUrl?: string); | ||
private poapApi; | ||
constructor(config: PoapDropApiConfig); | ||
createDrop(input: CreateDropInput): Promise<DropResponse>; | ||
@@ -12,1 +13,5 @@ updateDrop(input: UpdateDropInput): Promise<DropResponse>; | ||
} | ||
export interface PoapDropApiConfig { | ||
apiKey: string; | ||
baseUrl?: string; | ||
} |
@@ -21,7 +21,7 @@ (function (global, factory) { | ||
const MOMENTS_BASE_URL = 'https://moments.poap.tech'; | ||
const DEFAULT_MOMENTS_BASE_URL = 'https://moments.poap.tech'; | ||
class PoapMomentsApi { | ||
constructor(params) { | ||
var _a; | ||
this.baseUrl = (_a = params.baseUrl) !== null && _a !== void 0 ? _a : MOMENTS_BASE_URL; | ||
this.baseUrl = (_a = params.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_MOMENTS_BASE_URL; | ||
this.authenticationProvider = params.authenticationProvider; | ||
@@ -108,7 +108,10 @@ } | ||
const DROP_BASE_URL = 'https://api.poap.tech'; | ||
const DEFAULT_DROP_BASE_URL$1 = 'https://api.poap.tech'; | ||
class PoapDropApi { | ||
constructor(apiKey, baseUrl = DROP_BASE_URL) { | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
constructor(config) { | ||
this.apiKey = config.apiKey; | ||
this.baseUrl = config.baseUrl || DEFAULT_DROP_BASE_URL$1; | ||
this.poapApi = axios.create({ | ||
timeout: 10000, | ||
}); | ||
} | ||
@@ -150,3 +153,3 @@ async createDrop(input) { | ||
}; | ||
return (await axios(url, { | ||
return (await this.poapApi(url, { | ||
method: options.method, | ||
@@ -159,7 +162,7 @@ data: options.body, | ||
const COMPASS_BASE_URL = 'https://compass.poap.tech/v1/graphql'; | ||
const DEFAULT_COMPASS_BASE_URL = 'https://public.compass.poap.tech/v1/graphql'; | ||
class PoapCompass { | ||
constructor(apiKey, baseUrl = COMPASS_BASE_URL) { | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
constructor(config) { | ||
this.apiKey = config.apiKey; | ||
this.baseUrl = config.baseUrl || DEFAULT_COMPASS_BASE_URL; | ||
} | ||
@@ -201,3 +204,3 @@ async fetchGraphQL(query, variables) { | ||
const OAUTH_SERVER = 'auth.accounts.poap.xyz'; | ||
const DEFAULT_OAUTH_SERVER = 'auth.accounts.poap.xyz'; | ||
class AuthenticationProviderHttp { | ||
@@ -207,3 +210,3 @@ constructor(clientId, clientSecret, oAuthServerDomain) { | ||
this.clientSecret = clientSecret; | ||
this.oAuthServerDomain = oAuthServerDomain || OAUTH_SERVER; | ||
this.oAuthServerDomain = oAuthServerDomain || DEFAULT_OAUTH_SERVER; | ||
} | ||
@@ -235,2 +238,57 @@ async getJWT(audience) { | ||
class MissingAuthenticationProviderError extends Error { | ||
constructor() { | ||
super(`An AuthenticationProvider is required for write operations`); | ||
} | ||
} | ||
const DEFAULT_DROP_BASE_URL = 'https://api.poap.tech'; | ||
class PoapTokenApi { | ||
constructor({ apiKey, baseUrl = DEFAULT_DROP_BASE_URL, authenticationProvider, }) { | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
this.authenticationProvider = authenticationProvider; | ||
this.poapApi = axios.create({ | ||
timeout: 10000, | ||
}); | ||
} | ||
async getMintCode(code) { | ||
return await this.secureFetch(`${this.baseUrl}/actions/claim-qr?qr_hash=${code}`, { | ||
method: 'GET', | ||
headers: {}, | ||
}); | ||
} | ||
async postMintCode(input) { | ||
return await this.secureFetch(`${this.baseUrl}/actions/claim-qr`, { | ||
method: 'POST', | ||
body: input, | ||
headers: {}, | ||
}); | ||
} | ||
async mintStatus(uid) { | ||
return await this.secureFetch(`${this.baseUrl}/queue-message/${uid}`, { | ||
method: 'GET', | ||
headers: {}, | ||
}); | ||
} | ||
async secureFetch(url, options) { | ||
const headersWithApiKey = { | ||
...options.headers, | ||
'x-api-key': this.apiKey, | ||
Authorization: await this.getAuthorizationToken(), | ||
}; | ||
return (await this.poapApi(url, { | ||
method: options.method, | ||
data: options.body, | ||
headers: headersWithApiKey, | ||
})).data; | ||
} | ||
async getAuthorizationToken() { | ||
if (!this.authenticationProvider) { | ||
throw new MissingAuthenticationProviderError(); | ||
} | ||
return `Bearer ${await this.authenticationProvider.getJWT(this.baseUrl)}`; | ||
} | ||
} | ||
exports.AuthenticationProviderHttp = AuthenticationProviderHttp; | ||
@@ -241,4 +299,5 @@ exports.InvalidMediaError = InvalidMediaError; | ||
exports.PoapMomentsApi = PoapMomentsApi; | ||
exports.PoapTokenApi = PoapTokenApi; | ||
})); | ||
//# sourceMappingURL=index.js.map |
export * from './MomentsApiProvider/MomentsApiProvider'; | ||
export * from './DropApiProvider/DropApiProvider'; | ||
export { TokensApiProvider, GetMintCodeResponse, PostMintCodeResponse, MintCodeInput, MintStatusResponse, } from './TokensApiProvider'; | ||
export { HttpProvider } from './HttpProvider/HttpProvider'; | ||
export { CompassProvider } from './CompassProvider/CompassProvider'; | ||
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider'; |
{ | ||
"name": "@poap-xyz/providers", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"description": "Providers module for the poap.js library", | ||
@@ -27,2 +27,5 @@ "main": "dist/cjs/index.cjs", | ||
}, | ||
"dependencies": { | ||
"@poap-xyz/utils": "0.0.39" | ||
}, | ||
"devDependencies": { | ||
@@ -29,0 +32,0 @@ "axios-mock-adapter": "^1.21.4" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
151722
95
1737
3
+ Added@poap-xyz/utils@0.0.39
+ Added@poap-xyz/utils@0.0.39(transitive)