polyapi 0.1.55 → 0.1.56

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.
@@ -1,6 +1,6 @@
1
1
  const axios = require('../axios');
2
2
 
3
- module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#if audienceRequired}}audience, scopes, callback, { callbackUrl, timeout = 120000, autoCloseOnToken = true, userId } = {}{{else}}scopes, callback, { audience, callbackUrl, timeout = 120000, autoCloseOnToken = true, userId } = {}{{/if}}) {
3
+ module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#if audienceRequired}}audience, scopes, callback, { callbackUrl, timeout = 120000, autoCloseOnToken = true, autoCloseOnUrl = false, userId } = {}{{else}}scopes, callback, { audience, callbackUrl, timeout = 120000, autoCloseOnToken = true, autoCloseOnUrl = false, userId } = {}{{/if}}) {
4
4
  if (userId) {
5
5
  eventsClientId = `${eventsClientId}-${userId}`;
6
6
  }
@@ -8,7 +8,7 @@ module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#
8
8
  let socket = null;
9
9
  let timeoutID = null;
10
10
 
11
- const unregisterEventHandler = () => {
11
+ const closeEventHandler = () => {
12
12
  if (!socket) {
13
13
  return;
14
14
  }
@@ -18,6 +18,8 @@ module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#
18
18
  functionId: 'ee35849b-e40b-4f8a-bcb3-da4e1134f219',
19
19
  apiKey: 'ptab4f62d3421bca3674hfd627',
20
20
  });
21
+ socket.close();
22
+ socket = null;
21
23
  if (timeoutID) {
22
24
  clearTimeout(timeoutID);
23
25
  }
@@ -29,11 +31,16 @@ module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#
29
31
  callback(data.token, data.url, data.error);
30
32
  return;
31
33
  }
34
+ if (data.url && autoCloseOnUrl) {
35
+ callback(null, data.url, null);
36
+ return;
37
+ }
38
+
32
39
  socket = getSocket();
33
40
  const handleEvent = ({ token, url, error }) => {
34
41
  callback(token, url, error);
35
42
  if (token && autoCloseOnToken) {
36
- unregisterEventHandler();
43
+ closeEventHandler();
37
44
  }
38
45
  };
39
46
  socket.emit('registerAuthFunctionEventHandler', {
@@ -49,14 +56,13 @@ module.exports = function(eventsClientId, getSocket, clientId, clientSecret, {{#
49
56
 
50
57
  if (timeout) {
51
58
  timeoutID = setTimeout(() => {
52
- unregisterEventHandler();
59
+ closeEventHandler();
53
60
  callback(null, null, { message: 'Timeout reached' });
54
61
  }, timeout);
55
62
  }
56
63
  });
57
64
 
58
65
  return {
59
- revoke: () => axios.post(`/functions/auth/{{id}}/revoke`, { clientId, clientSecret }),
60
- close: () => unregisterEventHandler(),
66
+ close: closeEventHandler,
61
67
  };
62
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polyapi",
3
- "version": "0.1.55",
3
+ "version": "0.1.56",
4
4
  "description": "Poly is a CLI tool to help create and manage your Poly definitions.",
5
5
  "license": "MIT",
6
6
  "repository": {