cloudcommerce 0.30.0 → 0.31.0
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/.github/workflows/test-apps.yml +1 -1
- package/CHANGELOG.md +64 -0
- package/action.yml +13 -1
- package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
- package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
- package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/barra-doce/package.json +2 -2
- package/ecomplus-stores/monocard/functions/many/package.json +3 -3
- package/ecomplus-stores/monocard/functions/ssr/package.json +6 -6
- package/ecomplus-stores/monocard/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/monocard/package.json +2 -2
- package/package.json +3 -3
- package/packages/api/lib/api.d.ts +2 -2
- package/packages/api/package.json +1 -1
- package/packages/apps/affilate-program/lib/events-to-affilate-program.js +4 -5
- package/packages/apps/affilate-program/lib/events-to-affilate-program.js.map +1 -1
- package/packages/apps/affilate-program/package.json +1 -1
- package/packages/apps/affilate-program/src/events-to-affilate-program.ts +6 -7
- package/packages/apps/correios/lib/correios.d.ts +1 -0
- package/packages/apps/correios/lib/correios.js +2 -1
- package/packages/apps/correios/lib/correios.js.map +1 -1
- package/packages/apps/correios/lib-mjs/calculate-shipping.mjs +430 -0
- package/packages/apps/correios/lib-mjs/correios-db.mjs +189 -0
- package/packages/apps/correios/lib-mjs/correios-v2.mjs +84 -0
- package/packages/apps/correios/lib-mjs/utils/constants-parsers.mjs +135 -0
- package/packages/apps/correios/lib-mjs/utils/correios-axios.mjs +93 -0
- package/packages/apps/correios/package.json +13 -5
- package/packages/apps/correios/scripts/tests.sh +11 -0
- package/packages/apps/correios/src/correios.ts +2 -1
- package/packages/apps/correios/tests/calculate-shipping.test.mjs +1 -1
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +1 -1
- package/packages/apps/fb-conversions/package.json +1 -1
- package/packages/apps/flash-courier/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/galaxpay/package.json +1 -1
- package/packages/apps/google-analytics/package.json +1 -1
- package/packages/apps/jadlog/package.json +1 -1
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mandae/package.json +1 -1
- package/packages/apps/melhor-envio/package.json +1 -1
- package/packages/apps/mercadopago/package.json +1 -1
- package/packages/apps/pagarme/package.json +1 -1
- package/packages/apps/paghiper/package.json +1 -1
- package/packages/apps/pix/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/apps/webhooks/package.json +1 -1
- package/packages/cli/config/firebase.json +17 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +1 -1
- package/packages/eslint/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/feeds/package.json +1 -1
- package/packages/firebase/lib/config.js +1 -1
- package/packages/firebase/lib/config.js.map +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/firebase/src/config.ts +1 -1
- package/packages/i18n/lib/en_us/i19emailWasSentMsg.txt +1 -0
- package/packages/i18n/lib/en_us.d.ts +1 -0
- package/packages/i18n/lib/en_us.js +1 -0
- package/packages/i18n/lib/en_us.js.map +1 -1
- package/packages/i18n/lib/pt_br/i19emailWasSentMsg.txt +1 -0
- package/packages/i18n/lib/pt_br.d.ts +1 -0
- package/packages/i18n/lib/pt_br.js +1 -0
- package/packages/i18n/lib/pt_br.js.map +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/i18n/src/en_us.ts +1 -0
- package/packages/i18n/src/pt_br.ts +1 -0
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/package.json +1 -1
- package/packages/storefront/package.json +1 -1
- package/packages/storefront/src/lib/components/ViewTransitions.astro +4 -1
- package/packages/storefront/src/lib/composables/use-login-form.ts +13 -4
- package/packages/storefront/src/lib/scripts/vbeta-app.ts +44 -0
- package/packages/storefront/src/lib/state/customer-session.ts +10 -3
- package/packages/test-base/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/apps/correios/lib-mjs/calculate-correios.mjs +0 -470
- package/packages/apps/correios/lib-mjs/correios-ws.mjs +0 -155
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import * as xml2js from 'xml2js';
|
|
4
|
-
|
|
5
|
-
const roundDecimal = (num) => Math.round(num * 100) / 100;
|
|
6
|
-
|
|
7
|
-
// https://www.correios.com.br/precos-e-prazos/calculador-remoto-de-precos-e-prazos
|
|
8
|
-
const baseUrl = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?StrRetorno=xml';
|
|
9
|
-
|
|
10
|
-
const sendCalculateRequest = (params, timeout, isDebug = false) => {
|
|
11
|
-
let url = baseUrl;
|
|
12
|
-
Object.keys(params).forEach((param) => {
|
|
13
|
-
if (params[param] !== undefined) {
|
|
14
|
-
url += `&${param}=${params[param]}`;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
if (isDebug === true) {
|
|
18
|
-
// eslint-disable-next-line no-console
|
|
19
|
-
console.log(`[ws] ${url}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return axios({
|
|
23
|
-
method: 'get',
|
|
24
|
-
url,
|
|
25
|
-
timeout,
|
|
26
|
-
responseType: 'text',
|
|
27
|
-
})
|
|
28
|
-
.then(async (response) => {
|
|
29
|
-
// parse XML to object
|
|
30
|
-
// https://www.npmjs.com/package/xml2js#options/
|
|
31
|
-
const result = await xml2js.parseStringPromise(response.data, { explicitArray: false });
|
|
32
|
-
let services;
|
|
33
|
-
if (Array.isArray(result.Servicos)) {
|
|
34
|
-
services = result.Servicos;
|
|
35
|
-
} else {
|
|
36
|
-
services = Array.isArray(result.Servicos.cServico)
|
|
37
|
-
? result.Servicos.cServico
|
|
38
|
-
: [result.Servicos.cServico];
|
|
39
|
-
}
|
|
40
|
-
const availableService = services.find(({ Erro, MsgErro }) => {
|
|
41
|
-
return String(Erro) !== '-33' && !String(MsgErro).includes('Unavailable');
|
|
42
|
-
});
|
|
43
|
-
if (availableService) {
|
|
44
|
-
return {
|
|
45
|
-
...result,
|
|
46
|
-
services,
|
|
47
|
-
url,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const err = new Error('Correios WS unavailable');
|
|
51
|
-
err.code = 'E503';
|
|
52
|
-
err.config = response.config;
|
|
53
|
-
err.response = response;
|
|
54
|
-
throw err;
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
.catch((error) => {
|
|
58
|
-
switch (error.code) {
|
|
59
|
-
case 'ECONNRESET':
|
|
60
|
-
case 'ECONNABORTED':
|
|
61
|
-
case 'ETIMEDOUT':
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
// Debug unknown error
|
|
65
|
-
if (error.response) {
|
|
66
|
-
const err = new Error('Correios WS error');
|
|
67
|
-
err.code = error.code;
|
|
68
|
-
err.config = error.config;
|
|
69
|
-
err.response = {
|
|
70
|
-
status: error.response.status,
|
|
71
|
-
data: error.response.data,
|
|
72
|
-
};
|
|
73
|
-
console.error(err);
|
|
74
|
-
} else {
|
|
75
|
-
console.error(error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw error;
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default (params, timeout = 20000, isDebug = false) => {
|
|
83
|
-
params.nIndicaCalculo = 3;
|
|
84
|
-
params.nCdFormato = 1;
|
|
85
|
-
params.nVlDiametro = 0;
|
|
86
|
-
if (!params.nCdServico) {
|
|
87
|
-
// PAC, SEDEX
|
|
88
|
-
params.nCdServico = '04510,04014';
|
|
89
|
-
}
|
|
90
|
-
// Check minimum package dimensions
|
|
91
|
-
if (!(params.nVlPeso >= 0.1)) {
|
|
92
|
-
params.nVlPeso = 0.1;
|
|
93
|
-
} else {
|
|
94
|
-
params.nVlPeso = roundDecimal(params.nVlPeso);
|
|
95
|
-
}
|
|
96
|
-
if (!(params.nVlComprimento >= 16)) {
|
|
97
|
-
params.nVlComprimento = 16;
|
|
98
|
-
}
|
|
99
|
-
if (!(params.nVlAltura >= 2)) {
|
|
100
|
-
params.nVlAltura = 2;
|
|
101
|
-
}
|
|
102
|
-
if (!(params.nVlLargura >= 11)) {
|
|
103
|
-
params.nVlLargura = 11;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Optional additional services
|
|
107
|
-
['sCdMaoPropria', 'sCdAvisoRecebimento'].forEach((param) => {
|
|
108
|
-
if (!params[param]) {
|
|
109
|
-
params[param] = 'n';
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
if (params.nVlValorDeclarado === undefined) {
|
|
113
|
-
params.nVlValorDeclarado = 0;
|
|
114
|
-
} else if (params.nVlValorDeclarado < 24) {
|
|
115
|
-
params.nVlValorDeclarado = 24;
|
|
116
|
-
} else if (params.nVlValorDeclarado > 10000) {
|
|
117
|
-
params.nVlValorDeclarado = 10000;
|
|
118
|
-
} else {
|
|
119
|
-
params.nVlValorDeclarado = roundDecimal(params.nVlValorDeclarado);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const promises = [];
|
|
123
|
-
if (!params.nCdEmpresa || !params.sDsSenha) {
|
|
124
|
-
// Correios limit up to 1 service code per public request
|
|
125
|
-
params.nCdServico.split(',').forEach((nCdServico) => {
|
|
126
|
-
if (nCdServico) {
|
|
127
|
-
promises.push(sendCalculateRequest({ ...params, nCdServico }, timeout, isDebug));
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
} else {
|
|
131
|
-
// Can send multiple service codes
|
|
132
|
-
promises.push(sendCalculateRequest(params, timeout, isDebug));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return Promise.all(promises).then((results) => {
|
|
136
|
-
if (results.length === 1) {
|
|
137
|
-
// single request with multiple services
|
|
138
|
-
const { Servicos, url } = results[0];
|
|
139
|
-
const { cServico } = Servicos;
|
|
140
|
-
return {
|
|
141
|
-
Servicos: {
|
|
142
|
-
cServico: (Array.isArray(cServico) ? cServico : [cServico])
|
|
143
|
-
.map((_cServico) => ({ ..._cServico, url })),
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
Servicos: {
|
|
149
|
-
cServico: results.map(({ Servicos, url }) => {
|
|
150
|
-
return { ...Servicos.cServico, url };
|
|
151
|
-
}),
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
});
|
|
155
|
-
};
|