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

💤 Add single page test expiration #773

Merged
merged 6 commits into from
Dec 11, 2024
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 6.0.0 (2024-12-11)

## 🛠 Core

- Tests created with `calibre test create` or `Test.create` now expire after 1 year. Once expired, the test will be deleted. You can set a custom expiry date with the `--expiresAt` flag.
- Adds `--expiresAt` flag to `calibre test create`. You can use this flag to set an expiry date for the test. After the expiry date, the test will be automatically deleted.

## 🧹 Housekeeping

- Updates dependencies in response to latest dependabot updates and security patches.

# 5.2.0 (2024-08-29)

## 🛠 Core
Expand Down
3 changes: 2 additions & 1 deletion CLI_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Flags:
* `--webhookSecret`: Secret used to sign the webhook payload. Secret can be validated using `Calibre-HMAC-SHA256-Signature` HTTP header. See https://calibreapp.com/docs/integrations/webhooks#webhook-security-and-verification for more information.,
* `--adblocker`: Turn adblocking on or off. (boolean),
* `--private`: Make the results of a test private (only accessible by members of your Calibre organisation). (boolean),
* `--expiresAt`: Set a future UTC date time string (ISO8601). After this date, the test will be automatically deleted. (Min=24 hrs, Max=2 years) e.g.: 2025-12-31T23:59:59Z (Default: Expires 1 year from creation date.: `2025-12-11T09:55:39.255Z`) (string),
* `--cookie-jar`: Set cookies by specifying a path to a Netscape formatted cookie jar file.,
* `--headers`: Set HTTP headers by providing a path to a JSON file or a valid JSON key-value pairs.,
* `--json`: Outputs the results of the command in JSON format.,
Expand All @@ -314,7 +315,7 @@ Flags:

### calibre test list

List all previously run Single Page Tests (includes UUID, URL, device, connection, test location and status).
List recent Single Page Tests (includes UUID, URL, device, connection, test location and status).

Flags:

Expand Down
12 changes: 10 additions & 2 deletions generate-cli-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ const formatOptions = options => {
return `Flags:
${optionKeys.map(key => {
// eslint-disable-next-line security/detect-object-injection
const { describe, default: defaultValue, type } = options[key]
const {
describe,
default: defaultValue,
defaultDescription,
type
// eslint-disable-next-line security/detect-object-injection
} = options[key]
return `
* \`--${key}\`: ${describe}${
defaultValue ? ` (default: \`${defaultValue}\`)` : ''
defaultValue
? ` (${defaultDescription ? defaultDescription : 'default'}: \`${defaultValue}\`)`
: ''
}${type ? ` (${type})` : ''}`
})}`
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "calibre",
"version": "5.2.0",
"version": "6.0.0",
"engines": {
"node": ">= 18"
},
Expand Down
11 changes: 7 additions & 4 deletions src/api/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { request } from './graphql.js'

const CREATE_MUTATION = `
mutation CreateSinglePageTest($url: URL!, $location: LocationTag!, $device: DeviceTag, $connection: ConnectionTag, $cookies: [CookieInput!], $headers: [HeaderInput!], $adBlockerIsEnabled: Boolean, $isPrivate: Boolean, $webhookUrl: URL, $webhookSecret: String) {
createTest(url: $url, location: $location, device: $device, connection: $connection, cookies: $cookies, headers: $headers, adBlockerIsEnabled: $adBlockerIsEnabled, isPrivate: $isPrivate, webhookUrl: $webhookUrl, webhookSecret: $webhookSecret) {
mutation CreateSinglePageTest($url: URL!, $location: LocationTag!, $device: DeviceTag, $connection: ConnectionTag, $cookies: [CookieInput!], $headers: [HeaderInput!], $adBlockerIsEnabled: Boolean, $isPrivate: Boolean, $webhookUrl: URL, $webhookSecret: String, $expiresAt: ISO8601DateTime) {
createTest(url: $url, location: $location, device: $device, connection: $connection, cookies: $cookies, headers: $headers, adBlockerIsEnabled: $adBlockerIsEnabled, isPrivate: $isPrivate, webhookUrl: $webhookUrl, webhookSecret: $webhookSecret, expiresAt: $expiresAt) {
uuid
formattedTestUrl
}
Expand Down Expand Up @@ -101,7 +101,9 @@ const create = async ({
adblocker,
isPrivate,
webhookUrl,
webhookSecret
webhookSecret,
// Expire in 1 year
expiresAt = new Date(Date.now() + 31556952000).toISOString()
}) => {
const response = await request({
query: CREATE_MUTATION,
Expand All @@ -114,7 +116,8 @@ const create = async ({
adBlockerIsEnabled: adblocker,
isPrivate,
webhookUrl,
webhookSecret
webhookSecret,
expiresAt
})
return response.createTest
}
Expand Down
21 changes: 19 additions & 2 deletions src/cli/test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ const main = async function (args) {
try {
new URL(args.url)
} catch {
return new Error('Please enter a valid URL')
throw new Error('Please enter a valid URL')
}

if (args.webhookUrl) {
try {
new URL(args.webhookUrl)
} catch {
return new Error('Please enter a valid webhook URL')
throw new Error('Please enter a valid webhook URL')
}
}

if (args.expiresAt) {
const date = new Date(args.expiresAt).valueOf()

if (isNaN(date)) {
throw new Error(
'Please enter a valid `expiresAt` ISO8601 date time string'
)
}
}

Expand Down Expand Up @@ -130,6 +140,13 @@ const builder = {
type: 'boolean',
default: false
},
expiresAt: {
describe:
'Set a future UTC date time string (ISO8601). After this date, the test will be automatically deleted. (Min=24 hrs, Max=2 years) e.g.: 2025-12-31T23:59:59Z',
type: 'string',
default: new Date(Date.now() + 31556952000).toISOString(),
defaultDescription: 'Default: Expires 1 year from creation date.'
},
'cookie-jar': {
describe:
'Set cookies by specifying a path to a Netscape formatted cookie jar file.'
Expand Down
2 changes: 1 addition & 1 deletion src/cli/test/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const main = async args => {

const command = 'list'
const describe =
'List all previously run Single Page Tests (includes UUID, URL, device, connection, test location and status).'
'List recent Single Page Tests (includes UUID, URL, device, connection, test location and status).'
const handler = main
const builder = {
json: options.json
Expand Down
Loading