Skip to content

Commit

Permalink
all: Guard against window not existing. (#332)
Browse files Browse the repository at this point in the history
While we don't intend to support RavelinJS in node/deno or other non-browser
execution environments, it would be friendlier those users using SSR if the
library didn't error when being imported. With this change, we'll only error if
they try to initialise.
  • Loading branch information
icio committed Jun 1, 2023
1 parent 80071e1 commit cc0d1c3
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/bundle/core+encrypt+promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Core } from '../core';
import { Encrypt } from '../encrypt';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -11,6 +11,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+promise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Core } from '../core';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -9,6 +9,6 @@ function Ravelin(cfg) {
this.core = new Core(cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+track+encrypt+promise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Core } from '../core';
import { Track } from '../track';
import { Encrypt } from '../encrypt';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @typedef {object} Config
Expand All @@ -26,6 +26,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+track+encrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ function Ravelin(cfg) {
this.encrypt = new Encrypt(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
4 changes: 2 additions & 2 deletions lib/bundle/core+track+promise.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Core } from '../core';
import { Track } from '../track';
import Promise from '../promise';
import PolyfillPromise from '../promise';

/**
* @param {object} [cfg]
Expand All @@ -11,6 +11,6 @@ function Ravelin(cfg) {
this.track = new Track(this.core, cfg);
}

Ravelin.Promise = window.Promise || Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise || PolyfillPromise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core+track.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ function Ravelin(cfg) {
this.track = new Track(this.core, cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/bundle/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ function Ravelin(cfg) {
this.core = new Core(cfg);
}

Ravelin.Promise = window.Promise;
Ravelin.Promise = typeof Promise !== 'undefined' && Promise;

export default Ravelin;
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function apiFromKey(key) {
return 'https://' + encodeURIComponent(env) + '.ravelin.click';
}

var _XDomainRequest = window.XDomainRequest;
var _XDomainRequest = typeof XDomainRequest !== 'undefined' && XDomainRequest;

/**
* @typedef {Object} CoreResponse
Expand Down

0 comments on commit cc0d1c3

Please sign in to comment.