trash-cleaner
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -0,5 +1,6 @@ | ||
const { Command, Option } = require('commander'); | ||
const { FileSystemConfigStore } = require('./store/file-system-config-store'); | ||
const { GmailClientFactory } = require('./client/gmail-client'); | ||
const { OutlookClientFactory } = require('./client/outlook-client'); | ||
const { TrashCleanerFactory } = require('./trash-cleaner'); | ||
const { GmailClientFactory } = require('./client/gmail-client'); | ||
const { Command, Option } = require('commander'); | ||
const { version } = require('../package.json'); | ||
@@ -90,2 +91,5 @@ | ||
break; | ||
case EmailService.OUTLOOK: | ||
factory = new OutlookClientFactory(configStore); | ||
break; | ||
default: | ||
@@ -92,0 +96,0 @@ throw new Error(`Email service '${service}' not yet implemented.`); |
@@ -1,3 +0,1 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const readline = require('readline'); | ||
@@ -16,5 +14,5 @@ const open = require('open'); | ||
// time. | ||
const FILE_TOKEN = 'token.json'; | ||
const FILE_TOKEN = 'gmail.token.json'; | ||
// The file credentials.json stores the google api credentials. | ||
const FILE_CREDENTIALS = 'credentials.json'; | ||
const FILE_CREDENTIALS = 'gmail.credentials.json'; | ||
@@ -156,3 +154,3 @@ /** | ||
try { | ||
let credentials = await this.configStore.get(FILE_CREDENTIALS); | ||
let credentials = await this.configStore.getJson(FILE_CREDENTIALS); | ||
// Authorize a client with credentials, then call the Gmail API. | ||
@@ -181,3 +179,3 @@ auth = await this._authorize(credentials, reconfig); | ||
// Check if we have previously stored a token. | ||
let token = await this.configStore.get(FILE_TOKEN); | ||
let token = await this.configStore.getJson(FILE_TOKEN); | ||
if (token && !reconfig) { | ||
@@ -219,3 +217,3 @@ auth.setCredentials(token) | ||
// Store the token to disk for later program executions | ||
await this.configStore.put(FILE_TOKEN, tokens); | ||
await this.configStore.putJson(FILE_TOKEN, tokens); | ||
} | ||
@@ -222,0 +220,0 @@ |
@@ -10,2 +10,10 @@ /** | ||
*/ | ||
async getJson(key) { | ||
} | ||
/** | ||
* Reads the configuration string from the store. | ||
* | ||
* @param {string} key The key to configuration. | ||
*/ | ||
async get(key) { | ||
@@ -20,2 +28,11 @@ } | ||
*/ | ||
async putJson(key, value) { | ||
} | ||
/** | ||
* Writes the configuration string to the store. | ||
* | ||
* @param {string} key The key to configuration. | ||
* @param {string} value The configuration object. | ||
*/ | ||
async put(key, value) { | ||
@@ -22,0 +39,0 @@ } |
@@ -32,2 +32,12 @@ const path = require('path'); | ||
*/ | ||
async getJson(key) { | ||
let value = await this.get(key); | ||
return JSON.parse(value); | ||
} | ||
/** | ||
* Reads the configuration string from the store. | ||
* | ||
* @param {string} key The key to configuration. | ||
*/ | ||
async get(key) { | ||
@@ -39,4 +49,3 @@ let configPath = path.join(this.configDirPath, key); | ||
let serializedValue = await fsReadFile(configPath); | ||
return JSON.parse(serializedValue); | ||
return await fsReadFile(configPath); | ||
} | ||
@@ -50,6 +59,15 @@ | ||
*/ | ||
putJson(key, value) { | ||
return this.put(key, JSON.stringify(value)); | ||
} | ||
/** | ||
* Writes the configuration string to the store. | ||
* | ||
* @param {string} key The key to configuration. | ||
* @param {string} value The configuration object. | ||
*/ | ||
async put(key, value) { | ||
let configPath = path.join(this.configDirPath, key); | ||
let serializedValue = JSON.stringify(value); | ||
await fsWriteFile(configPath, serializedValue); | ||
await fsWriteFile(configPath, value); | ||
} | ||
@@ -56,0 +74,0 @@ } |
@@ -253,3 +253,3 @@ const diacriticLess = require('diacriticless'); | ||
async readKeywords() { | ||
let keywords = await this._configStore.get(FILE_KEYWORDS); | ||
let keywords = await this._configStore.getJson(FILE_KEYWORDS); | ||
return keywords.map(keyword => { | ||
@@ -256,0 +256,0 @@ let fields = this.splitAndTrim(keyword.fields, ',', '*'); |
{ | ||
"name": "trash-cleaner", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Finds and deletes trash email in the mailbox", | ||
@@ -13,2 +13,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@azure/msal-node": "^1.3.0", | ||
"axios": "^0.21.1", | ||
"commander": "^8.0.0", | ||
@@ -27,2 +29,5 @@ "diacriticless": "^1.0.1", | ||
}, | ||
"engines": { | ||
"node": ">=16.4.0" | ||
}, | ||
"bin": { | ||
@@ -29,0 +34,0 @@ "trash-cleaner": "./bin/trash-cleaner" |
@@ -23,7 +23,12 @@ # Trash Cleaner | ||
## Configuration | ||
## Gmail Configuration | ||
1. Create a [Google Cloud Platform project with the API enabled](https://developers.google.com/workspace/guides/create-project). | ||
2. Create [Authorization credentials for a desktop application](https://developers.google.com/workspace/guides/create-credentials) and download `credentials.json` file in the `config` directory. | ||
2. Create [Authorization credentials for a desktop application](https://developers.google.com/workspace/guides/create-credentials) and download `gmail.credentials.json` file in the `config` directory. | ||
3. Rename `keywords.json.sample` file in the `config` directory to `keywords.json` and update its contents. | ||
## Outlook Configuration | ||
1. Register an application with the [Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app). | ||
2. Rename `outlook.credentials.json.sample` file in the `config` directory to `outlook.credentials.json` and update its contents. | ||
3. Rename `keywords.json.sample` file in the `config` directory to `keywords.json` and update its contents. | ||
## Get Started | ||
@@ -30,0 +35,0 @@ To get the list of all parameters type `trash-cleaner -h` |
@@ -33,3 +33,3 @@ const fs = require('fs'); | ||
let value = await store.get(FILE_TEST); | ||
let value = await store.getJson(FILE_TEST); | ||
@@ -42,3 +42,3 @@ assert.deepEqual(value, [3]); | ||
let value = await store.get(FILE_TEST + '.old'); | ||
let value = await store.getJson(FILE_TEST + '.old'); | ||
@@ -52,3 +52,3 @@ assert.isNull(value); | ||
var store = new FileSystemConfigStore(configDirPath); | ||
await store.put(FILE_TEST, { val: 3 }); | ||
await store.putJson(FILE_TEST, { val: 3 }); | ||
@@ -55,0 +55,0 @@ let value = fs.readFileSync(path.join(configDirPath, FILE_TEST), 'utf-8'); |
Sorry, the diff of this file is not supported yet
52918
22
1340
47
3
7
+ Added@azure/msal-node@^1.3.0
+ Addedaxios@^0.21.1
+ Added@azure/msal-common@13.3.1(transitive)
+ Added@azure/msal-node@1.18.4(transitive)
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.6(transitive)
+ Addedjsonwebtoken@9.0.2(transitive)
+ Addedjwa@1.4.1(transitive)
+ Addedjws@3.2.2(transitive)
+ Addedlodash.includes@4.3.0(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isinteger@4.0.4(transitive)
+ Addedlodash.isnumber@3.0.3(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.isstring@4.0.1(transitive)
+ Addedlodash.once@4.1.1(transitive)
+ Addedsemver@7.6.2(transitive)