Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.1.1

- Updated `axios` to `1.7.7`.

## 4.1.0

- Added [upload](./README.md#upload) method.
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ module.exports = {
lines: 0,
},
},
moduleNameMapper: {
"^axios$": "axios/dist/node/axios.cjs",
},
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pixelbin/admin",
"version": "4.1.0",
"version": "4.1.1",
"description": "Pixelbin Backend SDK for Javascript",
"main": "index.js",
"scripts": {
Expand All @@ -14,8 +14,8 @@
"author": "Pixelbin",
"license": "MIT",
"dependencies": {
"axios": "0.21.4",
"crypto-js": "^4.2.0",
"axios": "1.7.7",
"crypto-js": "4.2.0",
"joi": "17.4.0",
"query-string": "7.1.3",
"camelcase": "6.2.0",
Expand Down
34 changes: 30 additions & 4 deletions sdk/common/AxiosHelper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
const combineURLs = require("axios/lib/helpers/combineURLs");
const isAbsoluteURL = require("axios/lib/helpers/isAbsoluteURL");
const axios = require("axios");
const { default: axios } = require("axios");
const querystring = require("query-string");
const { sign } = require("./RequestSigner");
const { PDKServerResponseError } = require("./PDKError");
const FormData = require("form-data");

/**
* https://github.com/axios/axios/blob/5b8a826771b77ab30081d033fdba9ef3b90e439a/lib/helpers/isAbsoluteURL.js
* Determines whether the specified URL is absolute
* @ignore
* @param {string} url The URL to test
* @returns {boolean} True if the specified URL is absolute, otherwise false
*/
function isAbsoluteURL(url) {
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
// by any combination of letters, digits, plus, period, or hyphen.
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
}

/**
* https://github.com/axios/axios/blob/5b8a826771b77ab30081d033fdba9ef3b90e439a/lib/helpers/combineURLs.js
* Creates a new URL by combining the specified URLs
* @ignore
* @param {string} baseURL The base URL
* @param {string} relativeURL The relative URL
* @returns {string} The combined URL
*/
function combineURLs(baseURL, relativeURL) {
return relativeURL
? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "")
: baseURL;
}

axios.defaults.withCredentials = true;

function transformRequestOptions(params) {
Expand Down Expand Up @@ -115,7 +141,7 @@ function userAgentInterceptor(options) {
return (config) => {
const sdk = {
name: "@pixelbin/admin",
version: "4.1.0",
version: "4.1.1",
};
const language = "JavaScript";

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/user-agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("User-Agent Header Test", () => {
it("should correctly set the User-Agent header incase no integerationPlatform is set", async () => {
const userAgentInterceptor = pdkAxios.interceptors.request.handlers[0].fulfilled;
const config = await userAgentInterceptor({ headers: {} });
let userAgent = `@pixelbin/admin/4.1.0 (JavaScript)`;
let userAgent = `@pixelbin/admin/4.1.1 (JavaScript)`;
expect(config.headers["user-agent"]).toEqual(userAgent);
});

Expand All @@ -48,7 +48,7 @@ describe("User-Agent Header Test", () => {
const interceptedConfig = await userAgentInterceptor({
headers: { "user-agent": "Erasebg Plugin/1.2.3 (Figma/3.2.1)" },
});
let userAgent = `Erasebg Plugin/1.2.3 (Figma/3.2.1) @pixelbin/admin/4.1.0 (JavaScript)`;
let userAgent = `Erasebg Plugin/1.2.3 (Figma/3.2.1) @pixelbin/admin/4.1.1 (JavaScript)`;
expect(interceptedConfig.headers["user-agent"]).toEqual(userAgent);
});
});