zapier-platform-core 11.3.0 → 11.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zapier-platform-core",
3
- "version": "11.3.0",
3
+ "version": "11.3.3",
4
4
  "description": "The core SDK for CLI apps in the Zapier Developer Platform.",
5
5
  "repository": "zapier/zapier-platform",
6
6
  "homepage": "https://platform.zapier.com/",
@@ -47,10 +47,10 @@
47
47
  "form-data": "4.0.0",
48
48
  "lodash": "4.17.21",
49
49
  "mime-types": "2.1.34",
50
- "node-fetch": "2.6.6",
50
+ "node-fetch": "2.6.7",
51
51
  "oauth-sign": "0.9.0",
52
52
  "semver": "7.3.5",
53
- "zapier-platform-schema": "11.3.0"
53
+ "zapier-platform-schema": "11.3.3"
54
54
  },
55
55
  "devDependencies": {
56
56
  "adm-zip": "0.5.5",
@@ -14,7 +14,24 @@ const addQueryParams = (req) => {
14
14
 
15
15
  normalizeEmptyParamFields(req);
16
16
 
17
- const stringifiedParams = querystring.stringify(req.params);
17
+ let stringifiedParams = querystring.stringify(req.params);
18
+
19
+ // it goes against spec, but for compatibility, some APIs want certain
20
+ // characters (mostly $) unencoded
21
+ if (req.skipEncodingChars) {
22
+ for (let i = 0; i < req.skipEncodingChars.length; i++) {
23
+ const char = req.skipEncodingChars.charAt(i);
24
+ const valToReplace = querystring.escape(char);
25
+ if (valToReplace === char) {
26
+ continue;
27
+ }
28
+ // no replaceAll in JS yet, coming in a node version soon!
29
+ stringifiedParams = stringifiedParams.replace(
30
+ new RegExp(valToReplace, 'g'),
31
+ char
32
+ );
33
+ }
34
+ }
18
35
 
19
36
  if (stringifiedParams) {
20
37
  req.url += `${splitter}${stringifiedParams}`;
@@ -6,6 +6,10 @@ const createHttpPatch = (event) => {
6
6
  const httpPatch = (object, logger) => {
7
7
  const originalRequest = object.request;
8
8
 
9
+ // Important not to reuse logger between calls, because we always destroy
10
+ // the logger at the end of a Lambda call.
11
+ object.zapierLogger = logger;
12
+
9
13
  // Avoids multiple patching and memory leaks (mostly when running tests locally)
10
14
  if (object.patchedByZapier) {
11
15
  return;
@@ -65,7 +69,7 @@ const createHttpPatch = (event) => {
65
69
  response_content: responseBody,
66
70
  };
67
71
 
68
- logger(
72
+ object.zapierLogger(
69
73
  `${logData.response_status_code} ${logData.request_method} ${logData.request_url}`,
70
74
  logData
71
75
  );
@@ -167,6 +167,7 @@ class LogStream extends Transform {
167
167
  class LogStreamFactory {
168
168
  constructor() {
169
169
  this._logStream = null;
170
+ this.ended = false;
170
171
  }
171
172
 
172
173
  getOrCreate(url, token) {
@@ -185,6 +186,10 @@ class LogStreamFactory {
185
186
  }
186
187
 
187
188
  async end() {
189
+ // Mark the factory as ended. This suggests that any logStream.write() that
190
+ // follows should end() right away.
191
+ this.ended = true;
192
+
188
193
  if (this._logStream) {
189
194
  this._logStream.end();
190
195
  const response = await this._logStream.request;
@@ -240,6 +245,14 @@ const sendLog = async (logStreamFactory, options, event, message, data) => {
240
245
  // no line breaks, and after an object it ends with a line break.
241
246
  JSON.stringify({ message: safeMessage, data: safeData }) + '\n'
242
247
  );
248
+
249
+ if (logStreamFactory.ended) {
250
+ // Lambda handler calls logger.end() at the end. But what if there's a
251
+ // (bad) callback that is still running after the Lambda handler returns?
252
+ // We need to make sure the bad callback ends the logger as well.
253
+ // Otherwise, it will hang!
254
+ logStreamFactory.end();
255
+ }
243
256
  }
244
257
  };
245
258