Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poap-xyz/providers

Package Overview
Dependencies
Maintainers
4
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poap-xyz/providers - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

dist/cjs/core/AuthenticationProviderHttp/AuthenticationProviderHttp.d.ts

1

dist/cjs/core/index.d.ts
export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi';
export { PoapDropApi } from './PoapDropApi/PoapDropApi';
export { PoapCompass } from './PoapCompass/PoapCompass';
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp';

18

dist/cjs/core/PoapMomentsApi/PoapMomentsApi.d.ts
/// <reference types="node" />
import { MediaStatus } from './constants';
import { CreateMomentResponse } from './../../ports/MomentsApiProvider/Types/response';
import { CreateMomentInput } from './../../ports/MomentsApiProvider/Types/input';
import { MomentsApiProvider } from './../../ports/MomentsApiProvider/MomentsApiProvider';
import { CreateMomentResponse } from '../../ports/MomentsApiProvider';
import { CreateMomentInput } from '../../ports/MomentsApiProvider';
import { MomentsApiProvider } from '../../ports';
import { AuthenticationProvider } from '../../ports';
export declare class PoapMomentsApi implements MomentsApiProvider {
private apiKey;
private baseUrl;
constructor(apiKey: string, baseUrl?: string);
private readonly baseUrl;
private readonly authenticationProvider?;
constructor(params: {
baseUrl?: string;
authenticationProvider?: AuthenticationProvider;
});
getSignedUrl(): Promise<{

@@ -18,3 +22,3 @@ url: string;

createMoment(input: CreateMomentInput): Promise<CreateMomentResponse>;
secureFetch(url: string, options: any): Promise<any>;
private getAuthorizationToken;
}

@@ -5,1 +5,2 @@ export * from './MomentsApiProvider/MomentsApiProvider';

export { CompassProvider } from './CompassProvider/CompassProvider';
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider';
export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi';
export { PoapDropApi } from './PoapDropApi/PoapDropApi';
export { PoapCompass } from './PoapCompass/PoapCompass';
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp';
/// <reference types="node" />
import { MediaStatus } from './constants';
import { CreateMomentResponse } from './../../ports/MomentsApiProvider/Types/response';
import { CreateMomentInput } from './../../ports/MomentsApiProvider/Types/input';
import { MomentsApiProvider } from './../../ports/MomentsApiProvider/MomentsApiProvider';
import { CreateMomentResponse } from '../../ports/MomentsApiProvider';
import { CreateMomentInput } from '../../ports/MomentsApiProvider';
import { MomentsApiProvider } from '../../ports';
import { AuthenticationProvider } from '../../ports';
export declare class PoapMomentsApi implements MomentsApiProvider {
private apiKey;
private baseUrl;
constructor(apiKey: string, baseUrl?: string);
private readonly baseUrl;
private readonly authenticationProvider?;
constructor(params: {
baseUrl?: string;
authenticationProvider?: AuthenticationProvider;
});
getSignedUrl(): Promise<{

@@ -18,3 +22,3 @@ url: string;

createMoment(input: CreateMomentInput): Promise<CreateMomentResponse>;
secureFetch(url: string, options: any): Promise<any>;
private getAuthorizationToken;
}

@@ -5,1 +5,2 @@ export * from './MomentsApiProvider/MomentsApiProvider';

export { CompassProvider } from './CompassProvider/CompassProvider';
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider';
export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi';
export { PoapDropApi } from './PoapDropApi/PoapDropApi';
export { PoapCompass } from './PoapCompass/PoapCompass';
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp';
/// <reference types="node" />
import { MediaStatus } from './constants';
import { CreateMomentResponse } from './../../ports/MomentsApiProvider/Types/response';
import { CreateMomentInput } from './../../ports/MomentsApiProvider/Types/input';
import { MomentsApiProvider } from './../../ports/MomentsApiProvider/MomentsApiProvider';
import { CreateMomentResponse } from '../../ports/MomentsApiProvider';
import { CreateMomentInput } from '../../ports/MomentsApiProvider';
import { MomentsApiProvider } from '../../ports';
import { AuthenticationProvider } from '../../ports';
export declare class PoapMomentsApi implements MomentsApiProvider {
private apiKey;
private baseUrl;
constructor(apiKey: string, baseUrl?: string);
private readonly baseUrl;
private readonly authenticationProvider?;
constructor(params: {
baseUrl?: string;
authenticationProvider?: AuthenticationProvider;
});
getSignedUrl(): Promise<{

@@ -18,3 +22,3 @@ url: string;

createMoment(input: CreateMomentInput): Promise<CreateMomentResponse>;
secureFetch(url: string, options: any): Promise<any>;
private getAuthorizationToken;
}

@@ -22,16 +22,17 @@ (function (global, factory) {

class PoapMomentsApi {
constructor(apiKey, baseUrl = MOMENTS_BASE_URL) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
constructor(params) {
var _a;
this.baseUrl = (_a = params.baseUrl) !== null && _a !== void 0 ? _a : MOMENTS_BASE_URL;
this.authenticationProvider = params.authenticationProvider;
}
async getSignedUrl() {
return await this.secureFetch(`${this.baseUrl}/moments/media-upload-url`, {
method: 'POST',
body: JSON.stringify({}),
const response = await axios.post(`${this.baseUrl}/moments/media-upload-url`, undefined, {
headers: {
Authorization: await this.getAuthorizationToken(),
},
});
return response.data;
}
async uploadFile(file, signedUrl, fileType) {
return await this.secureFetch(signedUrl, {
method: 'PUT',
body: file,
await axios.put(signedUrl, file, {
headers: {

@@ -43,10 +44,12 @@ 'Content-Type': fileType,

async fetchMediaStatus(mediaKey) {
var _a;
try {
const response = await this.secureFetch(`${this.baseUrl}/media/${mediaKey}`, {
method: 'GET',
});
return response.status;
const response = await axios.get(`${this.baseUrl}/media/${mediaKey}`);
return response.data.status;
}
catch (_a) {
return MediaStatus.IN_PROCESS;
catch (error) {
if (error instanceof axios.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
return MediaStatus.IN_PROCESS;
}
throw error;
}

@@ -75,20 +78,16 @@ }

async createMoment(input) {
return await this.secureFetch(`${this.baseUrl}/moments`, {
method: 'POST',
body: JSON.stringify(input),
headers: { 'Content-Type': 'application/json' },
const response = await axios.post(`${this.baseUrl}/moments`, input, {
headers: {
'Content-Type': 'application/json',
Authorization: await this.getAuthorizationToken(),
},
});
}
async secureFetch(url, options) {
const headersWithApiKey = {
...options.headers,
'x-api-key': this.apiKey,
};
const response = await axios(url, {
method: options.method,
data: options.body,
headers: headersWithApiKey,
});
return response.data;
}
async getAuthorizationToken() {
if (!this.authenticationProvider) {
throw new Error('An AuthenticationProvider is required for write operations');
}
return `Bearer ${await this.authenticationProvider.getJWT(this.baseUrl)}`;
}
}

@@ -186,2 +185,35 @@

const OAUTH_SERVER = 'poapauth.auth0.com';
class AuthenticationProviderHttp {
constructor(clientId, clientSecret, oAuthServerDomain) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.oAuthServerDomain = oAuthServerDomain || OAUTH_SERVER;
}
async getJWT(audience) {
if (this.tokenData && !this.isTokenExpired()) {
return this.tokenData.accessToken;
}
const response = await axios.post(`https://${this.oAuthServerDomain}/oauth/token`, {
client_id: this.clientId,
client_secret: this.clientSecret,
audience,
grant_type: 'client_credentials',
}, {
headers: {
'content-type': 'application/json',
},
});
this.tokenData = {
accessToken: response.data.access_token,
expiresAt: Date.now() + response.data.expires_in * 1000,
};
return response.data.access_token;
}
isTokenExpired() {
return !this.tokenData || this.tokenData.expiresAt < Date.now();
}
}
exports.AuthenticationProviderHttp = AuthenticationProviderHttp;
exports.InvalidMediaFileError = InvalidMediaFileError;

@@ -188,0 +220,0 @@ exports.PoapCompass = PoapCompass;

@@ -5,1 +5,2 @@ export * from './MomentsApiProvider/MomentsApiProvider';

export { CompassProvider } from './CompassProvider/CompassProvider';
export { AuthenticationProvider } from './AuthenticationProvider/AuthenticationProvider';
{
"name": "@poap-xyz/providers",
"version": "0.0.15",
"version": "0.0.16",
"description": "Providers module for the poap.js library",

@@ -29,2 +29,3 @@ "main": "dist/cjs/index.cjs",

"axios-mock-adapter": "^1.21.4",
"jest-mock-extended": "^3.0.4",
"rollup": "^3.20.2"

@@ -31,0 +32,0 @@ },

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc