@makefully/dutifully 1.18.0 → 1.19.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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.19.0
6
+
7
+ - Authenticate Showfully yap chores with `Authorization: Bearer` and `POST /yap/:service` (token no longer in the URL path).
8
+
5
9
  ## 1.18.0
6
10
 
7
11
  - Store GIF content hashes in a Comment Extension (`CheerfullyHashes:{...}`), lossless.
package/README.md CHANGED
@@ -11,10 +11,12 @@ To use the API, you will need to specify a root `./env-cheerfully.json` file wit
11
11
  ```javascript
12
12
  {
13
13
  "server": "http://server:port",
14
- "accessToken": "accessTokenToUseCheerfullyService"
14
+ "accessToken": "BearerTokenForShowfullyYap"
15
15
  }
16
16
  ```
17
17
 
18
+ `accessToken` is sent as `Authorization: Bearer …` on yap submit/status/download (Showfully 1.4+). For local Showfully, use the same value as `SHOWFULLY_DEBUG_TOKEN` with `SHOWFULLY_ALLOW_DEBUG_TOKEN=1`.
19
+
18
20
  ## Services
19
21
 
20
22
  All services can be specified in `cheerfully.json` as described in the following sections. Services can be run as scripts specified in `package.json` as:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makefully/dutifully",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "Client tools for Cheerfully service.",
5
5
  "main": "./src/index.js",
6
6
  "bin": {
@@ -15,13 +15,17 @@ const
15
15
  }
16
16
  return buf.subarray(0, max).toString('utf8').replace(/\s+/g, ' ').trim();
17
17
  },
18
- postStream = (url, stream) => new Promise ((resolve, reject) => {
18
+ authHeaders = (accessToken) => (accessToken
19
+ ? {Authorization: `Bearer ${accessToken}`}
20
+ : {}),
21
+ postStream = (url, stream, headers = {}) => new Promise ((resolve, reject) => {
19
22
  const
20
23
  protocol = url.startsWith('https') ? https : http;
21
24
  req = protocol.request(url, {
22
25
  method: 'post',
23
26
  headers: {
24
- 'Content-Type': 'application/zip'
27
+ 'Content-Type': 'application/zip',
28
+ ...headers
25
29
  }
26
30
  }, async (res) => {
27
31
  let data = '';
@@ -61,7 +65,7 @@ const
61
65
  let response = null;
62
66
 
63
67
  try {
64
- response = await fetchStream(`${url}/${choreId}`);
68
+ response = await fetchStream(`${url}/${choreId}`, headers);
65
69
  } catch (e) {
66
70
  console.warn(e);
67
71
 
@@ -101,11 +105,11 @@ const
101
105
 
102
106
  stream.pipe(req);
103
107
  }),
104
- fetchStream = (url) => new Promise((resolve, reject) => {
108
+ fetchStream = (url, headers = {}) => new Promise((resolve, reject) => {
105
109
  const
106
110
  protocol = url.startsWith('https') ? https : http;
107
111
 
108
- protocol.get(url, (res) => {
112
+ protocol.get(url, {headers}, (res) => {
109
113
  const
110
114
  contentType = res.headers['content-type'] || '',
111
115
  statusCode = res.statusCode || 0;
@@ -285,7 +289,11 @@ const
285
289
  try {
286
290
  const
287
291
  archiveStream = await archive((archive) => this.beforeSend(archive)),
288
- data = await postStream(`${cleanPath(server)}/yap/${service}/${accessToken}`, archiveStream);
292
+ data = await postStream(
293
+ `${cleanPath(server)}/yap/${service}`,
294
+ archiveStream,
295
+ authHeaders(accessToken)
296
+ );
289
297
 
290
298
  // listen for all archive data to be written
291
299
  archiveStream.on('close', function () {