Skip to content

Commit

Permalink
PLT-1395 Change Axios and Form-data by requiring minimum node version (
Browse files Browse the repository at this point in the history
  • Loading branch information
rlajous authored Sep 28, 2023
1 parent bdbd9a8 commit c23696e
Show file tree
Hide file tree
Showing 30 changed files with 865 additions and 583 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Check package versions and publish
run: yarn publish
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Check package versions and publish
run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/npm_publish_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Set Git config
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build packages
run: yarn build
- name: Build packages
run: yarn build

- name: Run tests
run: yarn test
- name: Run tests
run: yarn test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
1 change: 1 addition & 0 deletions examples/drops/backend/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ CLIENT_ID=
CLIENT_SECRET=
API_KEY=
OAUTH_SERVER_DOMAIN=
POAP_DROPS_BASE_URL=
1 change: 1 addition & 0 deletions examples/drops/backend/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
3 changes: 3 additions & 0 deletions examples/drops/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"@types/node-fetch": "^2.6.3",
"ts-node": "^10.4.0",
"typescript": "^4.5.5"
},
"engines": {
"node": ">=18"
}
}
5 changes: 4 additions & 1 deletion examples/drops/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ async function main(): Promise<void> {
// Use your library here
const client = new DropsClient(
new PoapCompass({ apiKey: getRequiredEnvVar('API_KEY') }),
new PoapDropApi({ apiKey: getRequiredEnvVar('API_KEY') }),
new PoapDropApi({
apiKey: getRequiredEnvVar('API_KEY'),
baseUrl: getRequiredEnvVar('POAP_DROPS_BASE_URL'),
}),
);
// Multiple Drops
await measurePerformance(
Expand Down
5 changes: 4 additions & 1 deletion examples/drops/backend/src/methods/create_drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const toPOAPdate = (date: Date): string => {
};

export const create_drop = async (client: DropsClient): Promise<void> => {
const buffer = await fs.promises.readFile('src/assets/poap.png');
const image = new Blob([buffer], { type: 'image/png' });

const createDrop: CreateDropsInput = {
name: 'Test ' + toPOAPdate(today),
description: 'Description',
Expand All @@ -36,7 +39,7 @@ export const create_drop = async (client: DropsClient): Promise<void> => {
eventUrl: 'https://poap.xyz/',
virtualEvent: true,
secretCode: '123456',
image: await fs.promises.readFile('src/assets/poap.png'),
image,
filename: 'file.png',
contentType: 'image/png',
eventTemplateId: 1,
Expand Down
1 change: 1 addition & 0 deletions examples/moments/backend/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
1 change: 1 addition & 0 deletions examples/poaps/backend/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"jest-mock-extended": "^3.0.4",
"prettier": "^2.8.6",
"rollup": "^3.20.2",
Expand Down
9 changes: 6 additions & 3 deletions packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.0.39",
"version": "0.1.0",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -25,8 +25,11 @@
"scripts": {
"build": "rollup -c --bundleConfigAsCjs"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"@poap-xyz/providers": "0.0.39",
"@poap-xyz/utils": "0.0.39"
"@poap-xyz/providers": "0.1.0",
"@poap-xyz/utils": "0.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/drops/src/types/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface CreateDropsInput {
expiryDate: string;
eventUrl: string;
virtualEvent: boolean;
image: Buffer;
image: Blob;
filename: string;
contentType: string;
secretCode: string;
Expand Down
9 changes: 6 additions & 3 deletions packages/moments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/moments",
"version": "0.0.39",
"version": "0.1.0",
"description": "Moments module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,10 +26,13 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.0.39",
"@poap-xyz/utils": "0.0.39",
"@poap-xyz/providers": "0.1.0",
"@poap-xyz/utils": "0.1.0",
"uuid": "^9.0.0"
},
"engines": {
"node": ">=18"
},
"devDependencies": {
"@types/uuid": "^9.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/performance/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/performance",
"version": "0.0.39",
"version": "0.1.0",
"description": "Performance module for the poap.js library",
"type": "module",
"main": "dist/cjs/index.cjs",
Expand Down
9 changes: 6 additions & 3 deletions packages/poaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poaps",
"version": "0.0.39",
"version": "0.1.0",
"description": "Poaps module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,7 +26,10 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.0.39",
"@poap-xyz/utils": "0.0.39"
"@poap-xyz/providers": "0.1.0",
"@poap-xyz/utils": "0.1.0"
},
"engines": {
"node": ">=18"
}
}
10 changes: 5 additions & 5 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/providers",
"version": "0.0.39",
"version": "0.1.0",
"description": "Providers module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -25,13 +25,13 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/utils": "0.0.39"
"@poap-xyz/utils": "0.1.0",
"axios": "^1.3.5"
},
"devDependencies": {
"axios-mock-adapter": "^1.21.4"
},
"peerDependencies": {
"axios": "^1.3.5",
"form-data": "^4.0.0"
"engines": {
"node": ">=18"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AuthenticationProvider } from '../../ports';
import axios from 'axios';

const DEFAULT_OAUTH_SERVER = 'auth.accounts.poap.xyz';

Expand All @@ -24,27 +23,34 @@ export class AuthenticationProviderHttp implements AuthenticationProvider {
return this.tokenData.accessToken;
}

const response = await axios.post(
const response = await fetch(
`https://${this.oAuthServerDomain}/oauth/token`,
{
client_id: this.clientId,
client_secret: this.clientSecret,
audience,
grant_type: 'client_credentials',
},
{
method: 'POST',
headers: {
'content-type': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_id: this.clientId,
client_secret: this.clientSecret,
audience,
grant_type: 'client_credentials',
}),
},
);

if (!response.ok) {
throw new Error(`Network response was not ok: ${response.statusText}`);
}

const responseData = await response.json();

this.tokenData = {
accessToken: response.data.access_token,
expiresAt: Date.now() + response.data.expires_in * 1000,
accessToken: responseData.access_token,
expiresAt: Date.now() + responseData.expires_in * 1000,
};

return response.data.access_token;
return responseData.access_token;
}

private isTokenExpired(): boolean {
Expand Down
10 changes: 4 additions & 6 deletions packages/providers/src/core/PoapCompass/PoapCompass.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { CompassProvider } from '../../ports/CompassProvider/CompassProvider';
import axios from 'axios';
// TODO: Change variable type any to a more specific type

const DEFAULT_COMPASS_BASE_URL = 'https://public.compass.poap.tech/v1/graphql';

Expand Down Expand Up @@ -44,19 +42,19 @@ export class PoapCompass implements CompassProvider {
const endpoint = this.baseUrl;

try {
const response = await axios(endpoint, {
const response = await fetch(endpoint, {
method: 'POST',
data: {
body: JSON.stringify({
query,
variables,
},
}),
headers: {
'Content-Type': 'application/json',
'x-api-key': this.apiKey,
},
});

const json = response.data;
const json = await response.json();

if (json.errors) {
throw new Error(
Expand Down
Loading

0 comments on commit c23696e

Please sign in to comment.