Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

[Snyk] Upgrade date-fns from 2.0.0-beta.3 to 2.9.0 #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 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
Expand Up @@ -106,7 +106,7 @@
"dependencies": {
"ajv": "6.10.2",
"babel-polyfill": "6.26.0",
"date-fns": "2.0.0-beta.3",
"date-fns": "2.9.0",
"fast-plist": "0.1.2",
"fuzzaldrin": "2.1.0",
"got": "9.6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/project/settings-schema.ts
Expand Up @@ -6,7 +6,7 @@ export interface Schema {
description: string
type: string
properties: Properties
required?: (string)[] | null
required?: string[] | null
}

/** @hidden */
Expand All @@ -32,7 +32,7 @@ export interface Language {
description: string
explanation: string
type: string
enum?: (string)[] | null
enum?: string[] | null
}

/** @hidden */
Expand Down
69 changes: 33 additions & 36 deletions src/project/settings.ts
@@ -1,34 +1,31 @@
import { AlfredError, FILES, Schema, SETTINGS_PATH } from '@/project';
import { Item, List, Notification, uuid } from '@/workflow';
import AJV from 'ajv';
import compose from 'stampit';
import writeJsonFile from 'write-json-file';
import { AlfredError, FILES, Schema, SETTINGS_PATH } from '@/project'
import { Item, List, Notification, uuid } from '@/workflow'
import AJV from 'ajv'
import compose from 'stampit'
import writeJsonFile from 'write-json-file'

/** @hidden */
const ajv = new AJV({ allErrors: true })

/** @hidden */
const SettingsList = compose(
List,
{
init(this: workflow.ListInstance, { settings }: { settings: project.Settings }) {
this.items = this.items || []

Object.keys(Schema.properties).forEach((key: string) => {
if (key !== 'uuid') {
this.items.push(
Item({
title: `SETTING: ${key}`,
subtitle: `${Schema.properties[key].explanation}`,
autocomplete: ` ${key}`,
valid: false
})
)
}
})
}
const SettingsList = compose(List, {
init(this: workflow.ListInstance, { settings }: { settings: project.Settings }) {
this.items = this.items || []

Object.keys(Schema.properties).forEach((key: string) => {
if (key !== 'uuid') {
this.items.push(
Item({
title: `SETTING: ${key}`,
subtitle: `${Schema.properties[key].explanation}`,
autocomplete: ` ${key}`,
valid: false
})
)
}
})
}
)
})

/** @hidden */
const SettingList = compose(List, {
Expand Down Expand Up @@ -122,7 +119,7 @@ function createDefault() {
uuid: uuid(),
anonymous_statistics: true
}
let validate = ajv.compile(Schema)
const validate = ajv.compile(Schema)

if (validate(starter)) {
return starter
Expand All @@ -133,7 +130,7 @@ function createDefault() {

/** @hidden */
function castSettingTypes(settings: project.Settings) {
let typeCast: project.Settings = settings
const typeCast: project.Settings = settings

Object.entries(settings).forEach(([key, value]) => {
if (Schema.properties[key] && Schema.properties[key].type === 'boolean') {
Expand Down Expand Up @@ -164,8 +161,8 @@ function castSettingTypes(settings: project.Settings) {

/** @hidden */
function getErrors(key: string, value: string | number | boolean, settings: project.Settings) {
let updated = Object.assign({}, settings, { [key]: value })
let validate = ajv.compile(Schema)
const updated = Object.assign({}, settings, { [key]: value })
const validate = ajv.compile(Schema)

if (!validate(castSettingTypes(updated))) {
return validate.errors || []
Expand All @@ -180,28 +177,28 @@ export function getSettings(): project.Settings {
}

export function getSetting(setting: string) {
let settings = getSettings()
const settings = getSettings()

return settings[setting]
}

export function list() {
let settings = getSettings()
let settingsList = SettingsList({ settings })
const settings = getSettings()
const settingsList = SettingsList({ settings })

return settingsList.write()
}

export function verify(key: string, value: string | number | boolean) {
let settings = getSettings()
let settingList = SettingList({ key, value, settings })
const settings = getSettings()
const settingList = SettingList({ key, value, settings })

return settingList.write()
}

export async function save({ key, value }: { key: string; value: string | number | boolean }) {
let settings = getSettings()
let errors = getErrors(key, value, settings)
const settings = getSettings()
const errors = getErrors(key, value, settings)

if (errors.length === 0) {
await writeJsonFile(SETTINGS_PATH, Object.assign(settings, { [key]: value }))
Expand Down
41 changes: 19 additions & 22 deletions src/todoist/label.ts
@@ -1,6 +1,6 @@
import { AlfredError } from '@/project';
import { Item, List } from '@/workflow';
import compose from 'stampit';
import { AlfredError } from '@/project'
import { Item, List } from '@/workflow'
import compose from 'stampit'

/** @hidden */
export const Label: todoist.LabelFactory = compose({
Expand All @@ -22,23 +22,20 @@ export const Label: todoist.LabelFactory = compose({
})

/** @hidden */
export const LabelList: todoist.LabelListFactory = compose(
List,
{
init(
this: todoist.LabelListInstance,
{ labels = [], query }: { labels: todoist.Label[]; query: string }
) {
labels.forEach((label: todoist.Label) => {
this.items.push(
Item({
title: label.name,
subtitle: `Add label ${label.name} to task`,
autocomplete: `${query.replace(/(^.*@).*/, '$1')}${label.name} `,
valid: false
})
)
})
}
export const LabelList: todoist.LabelListFactory = compose(List, {
init(
this: todoist.LabelListInstance,
{ labels = [], query }: { labels: todoist.Label[]; query: string }
) {
labels.forEach((label: todoist.Label) => {
this.items.push(
Item({
title: label.name,
subtitle: `Add label ${label.name} to task`,
autocomplete: `${query.replace(/(^.*@).*/, '$1')}${label.name} `,
valid: false
})
)
})
}
)
})
43 changes: 20 additions & 23 deletions src/todoist/project.ts
@@ -1,6 +1,6 @@
import { AlfredError } from '@/project';
import { Item, List } from '@/workflow';
import compose from 'stampit';
import { AlfredError } from '@/project'
import { Item, List } from '@/workflow'
import compose from 'stampit'

/** @hidden */
export const Project: todoist.ProjectFactory = compose({
Expand All @@ -18,25 +18,22 @@ export const Project: todoist.ProjectFactory = compose({
})

/** @hidden */
export const ProjectList: todoist.ProjectListFactory = compose(
List,
{
init(
this: todoist.ProjectListInstance,
{ projects = [], query }: { projects: todoist.Project[]; query: string }
) {
projects.forEach((project: todoist.Project) => {
let name = project.name.indexOf(' ') !== -1 ? `[${project.name}]` : project.name
export const ProjectList: todoist.ProjectListFactory = compose(List, {
init(
this: todoist.ProjectListInstance,
{ projects = [], query }: { projects: todoist.Project[]; query: string }
) {
projects.forEach((project: todoist.Project) => {
const name = project.name.indexOf(' ') !== -1 ? `[${project.name}]` : project.name

this.items.push(
Item({
title: project.name,
subtitle: `Move task to ${project.name}`,
autocomplete: `${query.replace(/(^.*#).*/, '$1')}${name} `,
valid: false
})
)
})
}
this.items.push(
Item({
title: project.name,
subtitle: `Move task to ${project.name}`,
autocomplete: `${query.replace(/(^.*#).*/, '$1')}${name} `,
valid: false
})
)
})
}
)
})
53 changes: 29 additions & 24 deletions src/todoist/query.ts
@@ -1,55 +1,60 @@
import { getSetting } from '@/project';
import { LabelAdapter, LabelList, parser, ProjectAdapter, ProjectList, Task, TaskList } from '@/todoist';
import { Item, List } from '@/workflow';
import compose from 'stampit';
import { getSetting } from '@/project'
import {
LabelAdapter,
LabelList,
parser,
ProjectAdapter,
ProjectList,
Task,
TaskList
} from '@/todoist'
import { Item, List } from '@/workflow'
import compose from 'stampit'

/** @hidden */
function createTask(parsed: todoist.Parsed, locale: string) {
let task = Task(parsed)
let taskList = TaskList({ tasks: [task], action: 'CREATE', locale })
const task = Task(parsed)
const taskList = TaskList({ tasks: [task], action: 'CREATE', locale })

return taskList.write()
}

/** @hidden */
async function showProjects(query: string) {
let project = query.replace(/^.*#/, '').replace(/\[|\]/g, '')
let projects = await ProjectAdapter({ token: getSetting('token') }).query(project, 'name')
const project = query.replace(/^.*#/, '').replace(/\[|\]/g, '')
const projects = await ProjectAdapter({ token: getSetting('token') }).query(project, 'name')

return ProjectList({ projects, query }).write()
}

/** @hidden */
async function showLabels(query: string) {
let label = query.replace(/^.*@/, '')
let labels = await LabelAdapter({ token: getSetting('token') }).query(label, 'name')
const label = query.replace(/^.*@/, '')
const labels = await LabelAdapter({ token: getSetting('token') }).query(label, 'name')

return LabelList({ labels, query }).write()
}

/** @hidden */
function showPriorities(query: string) {
let priority = query.replace(/^.*?!!/, '').replace(/^.*?p/, '')
let priorityNames: { [index: string]: string } = {
const priority = query.replace(/^.*?!!/, '').replace(/^.*?p/, '')
const priorityNames: { [index: string]: string } = {
'1': 'urgent',
'2': 'high',
'3': 'medium',
'4': 'low'
}

const Priority: workflow.PriorityFactory = compose(
Item,
{
init(this: workflow.ItemInstance, title: number) {
this.title = `${title}`
this.subtitle = `Set priority to ${priorityNames[`${title}`]}`
this.autocomplete = `${query
.replace(/(^.*!!)[1-4]$/, '$1')
.replace(/(^.*?p)[1-4]$/, '$1')}${title} `
this.valid = false
}
const Priority: workflow.PriorityFactory = compose(Item, {
init(this: workflow.ItemInstance, title: number) {
this.title = `${title}`
this.subtitle = `Set priority to ${priorityNames[`${title}`]}`
this.autocomplete = `${query
.replace(/(^.*!!)[1-4]$/, '$1')
.replace(/(^.*?p)[1-4]$/, '$1')}${title} `
this.valid = false
}
)
})

if (+priority >= 1 && +priority <= 4) {
return List({ items: [Priority(+priority)] }).write()
Expand Down