alfy 0.12.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cleanup.js +1 -1
- package/index.d.ts +1 -7
- package/index.js +24 -10
- package/init.js +1 -1
- package/lib/update-notification.js +2 -2
- package/package.json +13 -13
- package/readme.md +51 -6
package/cleanup.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import Conf from 'conf';
|
|
2
2
|
import {Options} from 'got';
|
|
3
3
|
|
|
4
|
-
export interface FetchOptions extends Options {
|
|
5
|
-
// Deprecated, but left for backwards-compatibility.
|
|
6
|
-
/**
|
|
7
|
-
URL search parameters.
|
|
8
|
-
*/
|
|
9
|
-
readonly query?: string | Record<string, string | number | boolean | null | undefined> | URLSearchParams | undefined;
|
|
10
|
-
|
|
4
|
+
export interface FetchOptions extends Partial<Options> {
|
|
11
5
|
/**
|
|
12
6
|
Number of milliseconds this request should be cached.
|
|
13
7
|
*/
|
package/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import process from 'node:process';
|
|
|
3
3
|
import {createRequire} from 'node:module';
|
|
4
4
|
import Conf from 'conf';
|
|
5
5
|
import got from 'got';
|
|
6
|
-
import
|
|
6
|
+
import {hookStderr} from 'hook-std';
|
|
7
7
|
import loudRejection from 'loud-rejection';
|
|
8
8
|
import cleanStack from 'clean-stack';
|
|
9
|
-
import
|
|
9
|
+
import {getProperty} from 'dot-prop';
|
|
10
10
|
import AlfredConfig from 'alfred-config';
|
|
11
11
|
import updateNotification from './lib/update-notification.js';
|
|
12
12
|
|
|
@@ -50,7 +50,7 @@ alfy.matches = (input, list, item) => {
|
|
|
50
50
|
|
|
51
51
|
return list.filter(listItem => {
|
|
52
52
|
if (typeof item === 'string') {
|
|
53
|
-
listItem =
|
|
53
|
+
listItem = getProperty(listItem, item);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (typeof listItem === 'string') {
|
|
@@ -113,12 +113,13 @@ alfy.cache = new CacheConf({
|
|
|
113
113
|
|
|
114
114
|
alfy.fetch = async (url, options) => {
|
|
115
115
|
options = {
|
|
116
|
+
resolveBodyOnly: true,
|
|
116
117
|
...options,
|
|
117
118
|
};
|
|
118
119
|
|
|
119
|
-
//
|
|
120
|
+
// TODO: Remove this in 2024.
|
|
120
121
|
if (options.query) {
|
|
121
|
-
|
|
122
|
+
throw new Error('The `query` option was renamed to `searchParams`.');
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
if (typeof url !== 'string') {
|
|
@@ -130,6 +131,12 @@ alfy.fetch = async (url, options) => {
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
const rawKey = url + JSON.stringify(options);
|
|
134
|
+
|
|
135
|
+
// This must be below the cache key generation.
|
|
136
|
+
const {transform, maxAge} = options;
|
|
137
|
+
delete options.transform;
|
|
138
|
+
delete options.maxAge;
|
|
139
|
+
|
|
133
140
|
const key = rawKey.replace(/\./g, '\\.');
|
|
134
141
|
const cachedResponse = alfy.cache.get(key, {ignoreMaxAge: true});
|
|
135
142
|
|
|
@@ -137,9 +144,16 @@ alfy.fetch = async (url, options) => {
|
|
|
137
144
|
return cachedResponse;
|
|
138
145
|
}
|
|
139
146
|
|
|
147
|
+
if ('json' in options && options.json === false) {
|
|
148
|
+
delete options.json;
|
|
149
|
+
options.responseType = 'text';
|
|
150
|
+
} else {
|
|
151
|
+
options.responseType = 'json';
|
|
152
|
+
}
|
|
153
|
+
|
|
140
154
|
let response;
|
|
141
155
|
try {
|
|
142
|
-
response = await got(url, options)
|
|
156
|
+
response = await got(url, options);
|
|
143
157
|
} catch (error) {
|
|
144
158
|
if (cachedResponse) {
|
|
145
159
|
return cachedResponse;
|
|
@@ -148,10 +162,10 @@ alfy.fetch = async (url, options) => {
|
|
|
148
162
|
throw error;
|
|
149
163
|
}
|
|
150
164
|
|
|
151
|
-
const data =
|
|
165
|
+
const data = transform ? transform(response) : response;
|
|
152
166
|
|
|
153
|
-
if (
|
|
154
|
-
alfy.cache.set(key, data, {maxAge
|
|
167
|
+
if (maxAge) {
|
|
168
|
+
alfy.cache.set(key, data, {maxAge});
|
|
155
169
|
}
|
|
156
170
|
|
|
157
171
|
return data;
|
|
@@ -171,6 +185,6 @@ alfy.icon = {
|
|
|
171
185
|
|
|
172
186
|
loudRejection(alfy.error);
|
|
173
187
|
process.on('uncaughtException', alfy.error);
|
|
174
|
-
|
|
188
|
+
hookStderr(alfy.error);
|
|
175
189
|
|
|
176
190
|
export default alfy;
|
package/init.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {readPackageUp} from 'read-pkg-up';
|
|
2
2
|
import alfredNotifier from 'alfred-notifier';
|
|
3
3
|
|
|
4
4
|
export default async function updateNotification() {
|
|
5
|
-
const {package: pkg} = await
|
|
5
|
+
const {package: pkg} = await readPackageUp();
|
|
6
6
|
const alfy = (pkg || {}).alfy || {};
|
|
7
7
|
|
|
8
8
|
if (alfy.updateNotification !== false) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alfy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Create Alfred workflows with ease",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/alfy",
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"mac"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"alfred-config": "^0.2.
|
|
40
|
+
"alfred-config": "^0.2.3",
|
|
41
41
|
"alfred-link": "^0.3.1",
|
|
42
42
|
"alfred-notifier": "^0.2.3",
|
|
43
43
|
"cache-conf": "^0.6.0",
|
|
44
44
|
"clean-stack": "^4.1.0",
|
|
45
|
-
"conf": "^10.
|
|
46
|
-
"dot-prop": "^
|
|
47
|
-
"execa": "^
|
|
48
|
-
"got": "^
|
|
49
|
-
"hook-std": "^
|
|
45
|
+
"conf": "^10.1.1",
|
|
46
|
+
"dot-prop": "^7.2.0",
|
|
47
|
+
"execa": "^6.1.0",
|
|
48
|
+
"got": "^12.0.3",
|
|
49
|
+
"hook-std": "^3.0.0",
|
|
50
50
|
"loud-rejection": "^2.2.0",
|
|
51
|
-
"read-pkg-up": "^
|
|
51
|
+
"read-pkg-up": "^9.1.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"ava": "^
|
|
54
|
+
"ava": "^4.1.0",
|
|
55
55
|
"delay": "^5.0.0",
|
|
56
|
-
"nock": "^13.
|
|
56
|
+
"nock": "^13.2.4",
|
|
57
57
|
"tempfile": "^4.0.0",
|
|
58
|
-
"tsd": "^0.
|
|
59
|
-
"typescript": "^4.3
|
|
60
|
-
"xo": "^0.
|
|
58
|
+
"tsd": "^0.19.1",
|
|
59
|
+
"typescript": "^4.6.3",
|
|
60
|
+
"xo": "^0.48.0"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/readme.md
CHANGED
|
@@ -21,8 +21,8 @@ You need [Node.js 14+](https://nodejs.org) and [Alfred 4](https://www.alfredapp.
|
|
|
21
21
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
24
|
-
```
|
|
25
|
-
|
|
24
|
+
```sh
|
|
25
|
+
npm install alfy
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
## Usage
|
|
@@ -121,8 +121,8 @@ You can remove [these](https://github.com/samverschueren/alfred-link#infoplist)
|
|
|
121
121
|
|
|
122
122
|
After publishing your workflow to npm, your users can easily install or update the workflow.
|
|
123
123
|
|
|
124
|
-
```
|
|
125
|
-
|
|
124
|
+
```sh
|
|
125
|
+
npm install --global alfred-unicorn
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
> Tip: instead of manually updating every workflow yourself, use the [alfred-updater](https://github.com/SamVerschueren/alfred-updater) workflow to do that for you.
|
|
@@ -351,7 +351,7 @@ URL to fetch.
|
|
|
351
351
|
|
|
352
352
|
Type: `object`
|
|
353
353
|
|
|
354
|
-
Any of the [`got` options](https://github.com/sindresorhus/got/tree/
|
|
354
|
+
Any of the [`got` options](https://github.com/sindresorhus/got/tree/v12.0.3#api) and the below options.
|
|
355
355
|
|
|
356
356
|
###### json
|
|
357
357
|
|
|
@@ -366,11 +366,39 @@ Type: `number`
|
|
|
366
366
|
|
|
367
367
|
Number of milliseconds this request should be cached.
|
|
368
368
|
|
|
369
|
+
###### resolveBodyOnly
|
|
370
|
+
|
|
371
|
+
Type: `boolean`\
|
|
372
|
+
Default: `true`
|
|
373
|
+
|
|
374
|
+
Whether to resolve with only body or a full response.
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
import alfy from 'alfy';
|
|
378
|
+
|
|
379
|
+
await alfy.fetch('https://api.foo.com');
|
|
380
|
+
//=> {foo: 'bar'}
|
|
381
|
+
|
|
382
|
+
await alfy.fetch('https://api.foo.com', {
|
|
383
|
+
resolveBodyOnly: false
|
|
384
|
+
});
|
|
385
|
+
/*
|
|
386
|
+
{
|
|
387
|
+
body: {
|
|
388
|
+
foo: 'bar'
|
|
389
|
+
},
|
|
390
|
+
headers: {
|
|
391
|
+
'content-type': 'application/json'
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
*/
|
|
395
|
+
```
|
|
396
|
+
|
|
369
397
|
###### transform
|
|
370
398
|
|
|
371
399
|
Type: `Function`
|
|
372
400
|
|
|
373
|
-
Transform the response before it gets cached.
|
|
401
|
+
Transform the response body before it gets cached.
|
|
374
402
|
|
|
375
403
|
```js
|
|
376
404
|
import alfy from 'alfy';
|
|
@@ -383,6 +411,20 @@ await alfy.fetch('https://api.foo.com', {
|
|
|
383
411
|
})
|
|
384
412
|
```
|
|
385
413
|
|
|
414
|
+
Transform the response.
|
|
415
|
+
|
|
416
|
+
```js
|
|
417
|
+
import alfy from 'alfy';
|
|
418
|
+
|
|
419
|
+
await alfy.fetch('https://api.foo.com', {
|
|
420
|
+
resolveBodyOnly: false,
|
|
421
|
+
transform: response => {
|
|
422
|
+
response.body.foo = 'bar';
|
|
423
|
+
return response;
|
|
424
|
+
}
|
|
425
|
+
})
|
|
426
|
+
```
|
|
427
|
+
|
|
386
428
|
You can also return a Promise.
|
|
387
429
|
|
|
388
430
|
```js
|
|
@@ -639,6 +681,9 @@ Non-synced local preferences are stored within `Alfred.alfredpreferences` under
|
|
|
639
681
|
- [alfred-amphetamine](https://github.com/demartini/alfred-amphetamine) - Start and end sessions quickly in the Amphetamine app
|
|
640
682
|
- [alfred-ids](https://github.com/rizowski/alfred-ids) - Generate various types of IDs.
|
|
641
683
|
- [alfred-awesome-stars](https://github.com/jopemachine/alfred-awesome-stars) - Search starred GitHub repos through awesome-stars.
|
|
684
|
+
- [alfred-pwgen](https://github.com/olssonm/alfred-password-generator) - Generate random and secure passwords.
|
|
685
|
+
- [alfred-bear](https://github.com/jmeischner/alfred-bear) - Use dynamic templates with the Bear app.
|
|
686
|
+
- [alfred-color-converter](https://github.com/toFrankie/alfred-color-converter) - Convert colors between RGB and Hex.
|
|
642
687
|
|
|
643
688
|
## Related
|
|
644
689
|
|