mkfashion-sdk 2.4.2 → 2.4.4

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/index.html CHANGED
@@ -1,22 +1,24 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="pt-BR">
3
+
3
4
  <head>
4
5
  <meta charset="UTF-8">
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
7
  <title>Provador Virtual</title>
7
- <script src="./src/mkfashion.js"></script>
8
+ <script src="https://unpkg.com/mkfashion-sdk/src/mkfashion.js"></script>
8
9
  </head>
10
+
9
11
  <body>
10
12
 
11
13
  <button id="btn-provar" style="display: none;">Provar Virtualmente</button>
12
14
 
13
15
  <script>
14
- (function() {
16
+ (function () {
15
17
  var projectid = '698c806c1d3129430f15ddde';
16
18
  var identifier = '8964289003742';
17
19
 
18
20
  function initMkFashion() {
19
- mkfashion.addToCart(function(payload) {
21
+ mkfashion.addToCart(function (payload) {
20
22
  console.log('Adicionando ao carrinho:', payload);
21
23
 
22
24
  var variantSku = payload.selectedIdentifier;
@@ -33,27 +35,31 @@
33
35
  }]
34
36
  })
35
37
  })
36
- .then(function(response) {
37
- return response.json();
38
- })
39
- .then(function(data) {
40
- console.log('Produto adicionado:', data);
41
- // document.dispatchEvent(new CustomEvent('cart:updated'));
42
- })
43
- .catch(function(error) {
44
- console.error('Erro carrinho:', error);
45
- });
38
+ .then(function (response) {
39
+ return response.json();
40
+ })
41
+ .then(function (data) {
42
+ console.log('Produto adicionado:', data);
43
+ // document.dispatchEvent(new CustomEvent('cart:updated'));
44
+ })
45
+ .catch(function (error) {
46
+ console.error('Erro carrinho:', error);
47
+ });
46
48
  });
47
49
 
50
+ mkfashion.onInteraction((data) => {
51
+ console.log(data.category, data.action)
52
+ })
53
+
48
54
  mkfashion.isAvailable(projectid, identifier)
49
- .then(function(disponivel) {
55
+ .then(function (disponivel) {
50
56
  if (disponivel) {
51
57
  var button = document.getElementById('btn-provar');
52
58
 
53
59
  if (button) {
54
60
  button.style.display = 'inline-block';
55
61
 
56
- button.onclick = function() {
62
+ button.onclick = function () {
57
63
  mkfashion.open({
58
64
  projectid: projectid,
59
65
  identifier: identifier
@@ -62,7 +68,7 @@
62
68
  }
63
69
  }
64
70
  })
65
- .catch(function(error) {
71
+ .catch(function (error) {
66
72
  console.error('Erro disponibilidade MK Fashion:', error);
67
73
  });
68
74
  }
@@ -84,4 +90,5 @@
84
90
  </script>
85
91
 
86
92
  </body>
93
+
87
94
  </html>
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mkfashion-sdk",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "SDK para integrar o provador virtual mKFashion com suporte a Wake Commerce",
5
5
  "main": "src/mkfashion.js",
6
6
  "scripts": {
package/src/mkfashion.js CHANGED
@@ -22,8 +22,8 @@ const mkfashion = {
22
22
  debug: false,
23
23
 
24
24
  // DEV - Descomentar para desenvolvimento local
25
- // appUrl: 'http://localhost:5174',
26
- // apiUrl: 'http://localhost:3007',
25
+ //appUrl: 'http://localhost:5174/visualizer',
26
+ //apiUrl: 'http://localhost:3007',
27
27
 
28
28
  // ============ ESTADO INTERNO ============
29
29
 
@@ -44,7 +44,8 @@ const mkfashion = {
44
44
  onAddToCart: null,
45
45
  onGenerationComplete: null,
46
46
  onProductLoaded: null,
47
- onError: null
47
+ onError: null,
48
+ onInteraction: null
48
49
  },
49
50
 
50
51
  // ============ METODOS PUBLICOS ============
@@ -184,6 +185,19 @@ const mkfashion = {
184
185
  }
185
186
  },
186
187
 
188
+ /**
189
+ * Registra callback para eventos de interação do usuário dentro do provador.
190
+ *
191
+ * Payload:
192
+ * { category, action, projectId, identifier, ...extra }
193
+ */
194
+ onInteraction(callback) {
195
+ if (typeof callback === 'function') {
196
+ this._callbacks.onInteraction = callback
197
+ this._log('Callback onInteraction registrado')
198
+ }
199
+ },
200
+
187
201
  /** Recarrega o iframe com a mesma configuração */
188
202
  restart() {
189
203
  if (!this._iframe || !this._config) {
@@ -209,7 +223,8 @@ const mkfashion = {
209
223
  onAddToCart: null,
210
224
  onGenerationComplete: null,
211
225
  onProductLoaded: null,
212
- onError: null
226
+ onError: null,
227
+ onInteraction: null
213
228
  }
214
229
  this._log('Destruído')
215
230
  },
@@ -697,6 +712,11 @@ const mkfashion = {
697
712
  this._triggerCallback('onGenerationComplete', data)
698
713
  break
699
714
 
715
+ case 'interaction':
716
+ this._log('Interação', data)
717
+ this._triggerCallback('onInteraction', data)
718
+ break
719
+
700
720
  case 'generation_error':
701
721
  this._log('Erro na geracao', data)
702
722
  this._triggerCallback('onError', data)
Binary file
Binary file
Binary file