@salla.sa/applepay 2.14.516 → 2.14.518

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": "@salla.sa/applepay",
3
- "version": "2.14.516",
3
+ "version": "2.14.518",
4
4
  "description": "Salla Apple Pay light",
5
5
  "main": "dist/app.js",
6
6
  "scripts": {
@@ -26,5 +26,5 @@
26
26
  "dependencies": {
27
27
  "axios": "^1.10.0"
28
28
  },
29
- "gitHead": "00bec9d26b4954d75099534933f3d19c47a3c11f"
29
+ "gitHead": "71ca14e6fbe582a269ce3a60f260049238f2d307"
30
30
  }
package/src/DetectOS.js CHANGED
@@ -1,75 +1,84 @@
1
1
  export default {
2
- options: [],
3
- header: [navigator.platform, navigator.userAgent, navigator.appVersion, navigator.vendor, window.opera],
4
- dataos: [
5
- {name: 'Windows Phone', value: 'Windows Phone', version: 'OS'},
6
- {name: 'Windows', value: 'Win', version: 'NT'},
7
- {name: 'iPhone', value: 'iPhone', version: 'OS'},
8
- {name: 'iPad', value: 'iPad', version: 'OS'},
9
- {name: 'Kindle', value: 'Silk', version: 'Silk'},
10
- {name: 'Android', value: 'Android', version: 'Android'},
11
- {name: 'PlayBook', value: 'PlayBook', version: 'OS'},
12
- {name: 'BlackBerry', value: 'BlackBerry', version: '/'},
13
- {name: 'Macintosh', value: 'Mac', version: 'OS X'},
14
- {name: 'Linux', value: 'Linux', version: 'rv'},
15
- {name: 'Palm', value: 'Palm', version: 'PalmOS'}
16
- ],
17
- databrowser: [
18
- {name: 'Chrome', value: 'Chrome', version: 'Chrome'},
19
- {name: 'Firefox', value: 'Firefox', version: 'Firefox'},
20
- {name: 'Safari', value: 'Safari', version: 'Version'},
21
- {name: 'Internet Explorer', value: 'MSIE', version: 'MSIE'},
22
- {name: 'Opera', value: 'Opera', version: 'Opera'},
23
- {name: 'BlackBerry', value: 'CLDC', version: 'CLDC'},
24
- {name: 'Mozilla', value: 'Mozilla', version: 'Mozilla'}
25
- ],
26
- init: function () {
27
- var agent = this.header.join(' '),
28
- os = this.matchItem(agent, this.dataos),
29
- browser = this.matchItem(agent, this.databrowser);
2
+ options: [],
3
+ header:
4
+ typeof navigator !== "undefined" && typeof window !== "undefined"
5
+ ? [
6
+ navigator.platform,
7
+ navigator.userAgent,
8
+ navigator.appVersion,
9
+ navigator.vendor,
10
+ window.opera,
11
+ ]
12
+ : [],
13
+ dataos: [
14
+ { name: "Windows Phone", value: "Windows Phone", version: "OS" },
15
+ { name: "Windows", value: "Win", version: "NT" },
16
+ { name: "iPhone", value: "iPhone", version: "OS" },
17
+ { name: "iPad", value: "iPad", version: "OS" },
18
+ { name: "Kindle", value: "Silk", version: "Silk" },
19
+ { name: "Android", value: "Android", version: "Android" },
20
+ { name: "PlayBook", value: "PlayBook", version: "OS" },
21
+ { name: "BlackBerry", value: "BlackBerry", version: "/" },
22
+ { name: "Macintosh", value: "Mac", version: "OS X" },
23
+ { name: "Linux", value: "Linux", version: "rv" },
24
+ { name: "Palm", value: "Palm", version: "PalmOS" },
25
+ ],
26
+ databrowser: [
27
+ { name: "Chrome", value: "Chrome", version: "Chrome" },
28
+ { name: "Firefox", value: "Firefox", version: "Firefox" },
29
+ { name: "Safari", value: "Safari", version: "Version" },
30
+ { name: "Internet Explorer", value: "MSIE", version: "MSIE" },
31
+ { name: "Opera", value: "Opera", version: "Opera" },
32
+ { name: "BlackBerry", value: "CLDC", version: "CLDC" },
33
+ { name: "Mozilla", value: "Mozilla", version: "Mozilla" },
34
+ ],
35
+ init: function () {
36
+ var agent = this.header.join(" "),
37
+ os = this.matchItem(agent, this.dataos),
38
+ browser = this.matchItem(agent, this.databrowser);
30
39
 
31
- return {os: os, browser: browser};
32
- },
33
- matchItem: function (string, data) {
34
- var i = 0,
35
- j = 0,
36
- html = '',
37
- regex,
38
- regexv,
39
- match,
40
- matches,
41
- version;
40
+ return { os: os, browser: browser };
41
+ },
42
+ matchItem: function (string, data) {
43
+ var i = 0,
44
+ j = 0,
45
+ html = "",
46
+ regex,
47
+ regexv,
48
+ match,
49
+ matches,
50
+ version;
42
51
 
43
- for (i = 0; i < data.length; i += 1) {
44
- regex = new RegExp(data[i].value, 'i');
45
- match = regex.test(string);
46
- if (match) {
47
- regexv = new RegExp(data[i].version + '[- /:;]([\\d._]+)', 'i');
48
- matches = string.match(regexv);
49
- version = '';
50
- if (matches) {
51
- if (matches[1]) {
52
- matches = matches[1];
53
- }
54
- }
55
- if (matches) {
56
- matches = matches.split(/[._]+/);
57
- for (j = 0; j < matches.length; j += 1) {
58
- if (j === 0) {
59
- version += matches[j] + '.';
60
- } else {
61
- version += matches[j];
62
- }
63
- }
64
- } else {
65
- version = '0';
66
- }
67
- return {
68
- name: data[i].name,
69
- version: parseFloat(version)
70
- };
52
+ for (i = 0; i < data.length; i += 1) {
53
+ regex = new RegExp(data[i].value, "i");
54
+ match = regex.test(string);
55
+ if (match) {
56
+ regexv = new RegExp(data[i].version + "[- /:;]([\\d._]+)", "i");
57
+ matches = string.match(regexv);
58
+ version = "";
59
+ if (matches) {
60
+ if (matches[1]) {
61
+ matches = matches[1];
62
+ }
63
+ }
64
+ if (matches) {
65
+ matches = matches.split(/[._]+/);
66
+ for (j = 0; j < matches.length; j += 1) {
67
+ if (j === 0) {
68
+ version += matches[j] + ".";
69
+ } else {
70
+ version += matches[j];
71
71
  }
72
+ }
73
+ } else {
74
+ version = "0";
72
75
  }
73
- return {name: 'unknown', version: 0};
76
+ return {
77
+ name: data[i].name,
78
+ version: parseFloat(version),
79
+ };
80
+ }
74
81
  }
82
+ return { name: "unknown", version: 0 };
83
+ },
75
84
  };
package/src/index.js CHANGED
@@ -2,8 +2,11 @@ import http from './http';
2
2
  import DetectOS from './DetectOS';
3
3
  import { mutateShippingContact } from './utils';
4
4
 
5
- window.Salla = window.Salla || {};
6
- window.Salla.Payments = window.Salla.Payments || {};
5
+ // SSR-safe: only access window in browser environment
6
+ if (typeof window !== 'undefined') {
7
+ window.Salla = window.Salla || {};
8
+ window.Salla.Payments = window.Salla.Payments || {};
9
+ }
7
10
 
8
11
  /**
9
12
  * Full Example
@@ -35,7 +38,9 @@ window.Salla.Payments = window.Salla.Payments || {};
35
38
  * // }
36
39
  * });
37
40
  */
38
- window.SallaApplePay = {
41
+
42
+ // SSR-safe: define SallaApplePay as a stub during SSR, actual object in browser
43
+ const SallaApplePay = typeof window !== 'undefined' ? {
39
44
  session: null,
40
45
  detail: null,
41
46
  address_id: null,
@@ -580,13 +585,20 @@ window.SallaApplePay = {
580
585
  'detail': '',
581
586
  'identifier': method.ship_id.toString() + (method.private_ship_id ? ',' + method.private_ship_id.toString() : '') + (method.type ? ',' + method.type : '') + (method.route_id ? ',' + method.route_id : '')
582
587
  }))
588
+ } : {};
589
+
590
+ // SSR-safe: export and assign to window in browser
591
+ if (typeof window !== 'undefined') {
592
+ window.SallaApplePay = SallaApplePay;
583
593
  }
584
594
 
585
595
  //applePay doesn't allow iframes
586
- // if (window.ApplePaySession && window.self === window.top && ApplePaySession.canMakePayments()) {
587
- if (window.ApplePaySession?.canMakePayments()) {
596
+ // SSR-safe: only initialize in browser
597
+ if (typeof window !== 'undefined' && window.ApplePaySession?.canMakePayments()) {
588
598
  SallaApplePay.init();
589
- } else {
599
+ } else if (typeof document !== 'undefined') {
590
600
  // You can hide the Apple Pay button easy with add data-show-if-apple-pay-supported to element like <div data-show-if-apple-pay-supported>
591
601
  document.querySelectorAll('data-show-if-apple-pay-supported').forEach(element => element.style.display = 'none');
592
602
  }
603
+
604
+ export default SallaApplePay;