Skip to content

Commit

Permalink
chore: merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
JadsonLucena committed Feb 10, 2024
2 parents c4b7fe1 + 65afa42 commit 6691d9e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

package-lock.json
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,27 @@ SignedAccess(
```

```typescript
/**
* @getter
*/
// Getters
algorithm(): string

/**
* @getter
*/
key(): string | ArrayBuffer | Buffer | TypedArray | DataView | KeyObject | CryptoKey

/**
* @getter
*/
ttl(): number
```

```typescript
// Setters
/**
* @setter
* @throws {TypeError} Invalid algorithm
* @see https://nodejs.org/api/crypto.html#cryptogethashes
*/
algorithm(param?: string = 'sha512'): void

/**
* @setter
* @throws {TypeError} Invalid key
* @see https://nodejs.org/api/crypto.html#cryptocreatehmacalgorithm-key-options
*/
key(param?: (string | ArrayBuffer | Buffer | TypedArray | DataView | KeyObject | CryptoKey) = require('os').networkInterfaces().eth0[0]?.mac): void

/**
* @setter
* @throws {TypeError} Invalid ttl
* @see https://wikipedia.org/wiki/Time_to_live
*/
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@jadsonlucena/signedaccess",
"version": "1.1.0",
"version": "1.1.1",
"description": "Sign and verify URLs and cookies to add a layer of protection to publicly accessible routes",
"main": "./src/SignedAccess.js",
"engines": {
"node": ">=12"
},
"scripts": {
"test": "jest --coverage './test'",
"test": "jest --coverage ./test",
"lint": "eslint ./src ./test --ext .js"
},
"files": [
Expand Down Expand Up @@ -39,9 +39,15 @@
"jest": "latest",
"eslint": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-jest": "latest"
"eslint-plugin-jest": "latest",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest"
},
"jest": {
"collectCoverage": true,
"verbose": true,
"collectCoverageFrom": ["./src/*.js"],
"coverageReporters": ["clover", "json", "lcov", "text", "html"],
"coverageThreshold": {
"global": {
"branches": 100,
Expand All @@ -57,5 +63,8 @@
"jest/globals": true
},
"extends": "standard"
},
"commitlint": {
"extends": ["@commitlint/config-conventional"]
}
}
10 changes: 5 additions & 5 deletions src/SignedAccess.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const crypto = require('crypto')
const os = require('os')
const crypto = require('node:crypto')
const os = require('node:os')

/**
* @class
Expand Down Expand Up @@ -101,7 +101,7 @@ class SignedAccess {
set ttl (
ttl = 86400 // Seconds
) {
if (isNaN(ttl) || typeof ttl !== 'number' || ttl < 1) {
if (!Number.isSafeInteger(ttl) || ttl < 1) {
throw new TypeError('Invalid ttl')
}

Expand Down Expand Up @@ -186,7 +186,7 @@ class SignedAccess {
throw new TypeError('Invalid pathname')
} else if (typeof remoteAddress !== 'string') {
throw new TypeError('Invalid remoteAddress')
} else if (isNaN(ttl) || typeof ttl !== 'number' || ttl < 1) {
} else if (!Number.isSafeInteger(ttl) || ttl < 1) {
throw new TypeError('Invalid ttl')
}

Expand Down Expand Up @@ -327,7 +327,7 @@ class SignedAccess {
throw new TypeError('Invalid nonce')
} else if (typeof remoteAddress !== 'string') {
throw new TypeError('Invalid remoteAddress')
} else if (isNaN(ttl) || typeof ttl !== 'number' || ttl < 1) {
} else if (!Number.isSafeInteger(ttl) || ttl < 1) {
throw new TypeError('Invalid ttl')
}

Expand Down
4 changes: 2 additions & 2 deletions test/SignedAccess.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const crypto = require('crypto')
const crypto = require('node:crypto')

const SignedAccess = require('../src/SignedAccess.js')

Expand All @@ -9,7 +9,7 @@ const signedAccess = new SignedAccess()
describe('constructor', () => {
test('type guards', () => {
['xyz', 0, false, null].forEach(input => expect(() => new SignedAccess({ algorithm: input })).toThrow('Invalid algorithm'));
['xyz', -1, false, null].forEach(input => expect(() => new SignedAccess({ ttl: input })).toThrow('Invalid ttl'));
['xyz', '', 0, Infinity, NaN, false, null].forEach(input => expect(() => new SignedAccess({ ttl: input })).toThrow('Invalid ttl'));
[0, false, null].forEach(input => expect(() => new SignedAccess({ key: input })).toThrow('Invalid key'))
})

Expand Down

0 comments on commit 6691d9e

Please sign in to comment.