@cocreate/authorize 1.7.0 → 1.7.1

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
@@ -1,3 +1,10 @@
1
+ ## [1.7.1](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.7.0...v1.7.1) (2023-10-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * getAuthorization returns authorization object or promise, resulting in the key only being read once ([7b490a5](https://github.com/CoCreate-app/CoCreate-authorize/commit/7b490a515e46704d20f325ada839d3dfd1cc2099))
7
+
1
8
  # [1.7.0](https://github.com/CoCreate-app/CoCreate-authorize/compare/v1.6.6...v1.7.0) (2023-09-19)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/authorize",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "A simple authorize component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "authorize",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/crud-client": "^1.26.0",
48
+ "@cocreate/crud-client": "^1.27.0",
49
49
  "@cocreate/utils": "^1.24.2"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -63,12 +63,28 @@
63
63
  }
64
64
 
65
65
  async function getAuthorization(key, organization_id) {
66
- if (authorizations.get(key)) {
67
- return authorizations.get(key)
68
- } else {
69
- let authorization = await readAuthorization(key, organization_id);
70
- authorizations.set(key, authorization)
71
- return authorization
66
+ // Check if there is a value orpending promise for this key
67
+ if (authorizations.has(key)) {
68
+ // Return the value or pending promise
69
+ return authorizations.get(key);
70
+ }
71
+
72
+ // Create a new promise and store it
73
+ const authorizationPromise = readAuthorization(key, organization_id);
74
+ authorizations.set(key, authorizationPromise);
75
+
76
+ try {
77
+ // Wait for the authorization to be resolved
78
+ const authorization = await authorizationPromise;
79
+
80
+ // Once resolved, store the resolved authorization in the map
81
+ authorizations.set(key, authorization);
82
+
83
+ return authorization;
84
+ } catch (error) {
85
+ // Handle errors if necessary
86
+ authorizations.delete(key);
87
+ throw error;
72
88
  }
73
89
  }
74
90