Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace psl deprecation warning by using tldts #930

Merged
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
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [20.1.3] - 2024-09-30

- Replaces `psl` with `tldts` to avoid `punycode` deprecation warning.

## [20.1.2] - 2024-09-14

- Fixes formFields to accept non string types as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ app.get("/sessioninfo", (c) => {

app.get("/", (c) => {
return c.json({
"message": "Hello from Supertokens"
})
})
message: "Hello from Supertokens",
});
});

export default app;
46 changes: 5 additions & 41 deletions lib/build/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/ts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as psl from "psl";
import { parse } from "tldts";

import type { AppInfo, NormalisedAppinfo, HTTPMethod, JSONObject, UserContext } from "./types";
import NormalisedURLDomain from "./normalisedURLDomain";
Expand Down Expand Up @@ -345,13 +345,13 @@ export function getTopLevelDomainForSameSiteResolution(url: string): string {
return "localhost";
}

let parsedURL = psl.parse(hostname) as psl.ParsedDomain;
if (parsedURL.domain === null) {
if (hostname.endsWith(".amazonaws.com") && parsedURL.tld === hostname) {
let parsedURL = parse(hostname);
if (!parsedURL.domain) {
if (hostname.endsWith(".amazonaws.com") && parsedURL.publicSuffix === hostname) {
return hostname;
}
// support for .local domain
if (hostname.endsWith(".local") && parsedURL.tld === null) {
if (hostname.endsWith(".local") && !parsedURL.publicSuffix) {
return hostname;
}
throw new Error("Please make sure that the apiDomain and websiteDomain have correct values");
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "20.1.2";
export const version = "20.1.3";

export const cdiSupported = ["5.1"];

Expand Down
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "20.1.2",
"version": "20.1.3",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -124,8 +124,8 @@
"pako": "^2.1.0",
"pkce-challenge": "^3.0.0",
"process": "^0.11.10",
"psl": "1.8.0",
"supertokens-js-override": "^0.0.4",
"tldts": "^6.1.48",
"twilio": "^4.19.3"
},
"devDependencies": {
Expand Down
38 changes: 37 additions & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require("assert");
const { getFromObjectCaseInsensitive } = require("../lib/build/utils");
const { getFromObjectCaseInsensitive, getTopLevelDomainForSameSiteResolution } = require("../lib/build/utils");

describe("SuperTokens utils test", () => {
it("Test getFromObjectCaseInsensitive", () => {
Expand All @@ -18,3 +18,39 @@ describe("SuperTokens utils test", () => {
assert.equal(getFromObjectCaseInsensitive("authoriZation", testObj), "test");
});
});

describe("getTopLevelDomainForSameSiteResolution test", () => {
it('should return "localhost" for localhost URLs', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://localhost:3000"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://localhost"), "localhost");
});

it('should return "localhost" for localhost.org URLs', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://localhost.org"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://localhost.org/test-path"), "localhost");
});

it('should return "localhost" for IP addresses', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://127.0.0.1"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://192.168.1.1"), "localhost");
});

it("should return the correct domain for normal URLs", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("https://www.example.com"), "example.com");
assert.equal(getTopLevelDomainForSameSiteResolution("http://sub.domain.co.uk"), "domain.co.uk");
});

it("should handle .amazonaws.com domains correctly", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("https://my-instance.amazonaws.com"), "amazonaws.com");
});

it("should handle .local domains correctly", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://myserver.local"), "myserver.local");
});

it("should throw an error for invalid domains", () => {
assert.throws(() => {
getTopLevelDomainForSameSiteResolution("http://invalid..com");
}, Error);
});
});
Loading