@8ms/helpers 1.2.14 → 1.2.15

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.
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  */
6
6
  const forceUpdate = async ({ key }) => {
7
7
  // Doesn't exist
8
- if (undefined === global['ems_cache'][key] || null === global['ems_cache'][key]) {
8
+ if (undefined === global['ems_cache'] ||
9
+ undefined === global['ems_cache']?.[key] ||
10
+ null === global['ems_cache']?.[key]) {
9
11
  // Throw error - should always exist
10
12
  throw `Global key '${key}' does not exist, requires initialisation.`;
11
13
  }
package/global/read.js CHANGED
@@ -9,14 +9,16 @@ const forceUpdate_1 = __importDefault(require("./forceUpdate"));
9
9
  */
10
10
  const read = async ({ key }) => {
11
11
  // Doesn't exist
12
- if (undefined === global['ems_cache'][key] || null === global['ems_cache'][key]) {
12
+ if (undefined === global['ems_cache'] ||
13
+ undefined === global['ems_cache']?.[key] ||
14
+ null === global['ems_cache']?.[key]) {
13
15
  // Throw error - should always exist
14
16
  throw `Global key '${key}' does not exist, requires initialisation.`;
15
17
  }
16
18
  // Exists (0 is determined as forever)
17
19
  else if (0 != global['ems_cache'][key].expires) {
18
20
  // https://ui.dev/get-current-timestamp-javascript
19
- const expiresAt = Math.floor(global[key].insertedAt / 1000) + global[key].expires;
21
+ const expiresAt = Math.floor(global['ems_cache'][key].insertedAt / 1000) + global[key].expires;
20
22
  const now = Math.floor(Date.now() / 1000);
21
23
  // If we are now beyond the expiry date, update the data
22
24
  if (now > expiresAt) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.2.14",
4
+ "version": "1.2.15",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"