@uappi/public-sdk 1.21.0 → 1.23.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/README.md
CHANGED
|
@@ -65,3 +65,15 @@ git push origin v1.2.9
|
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
Não repita esse passo — é só histórico de como o processo começou.
|
|
68
|
+
|
|
69
|
+
## Nome do cookie de autenticação
|
|
70
|
+
|
|
71
|
+
O SDK envia o header `Uappi-Cookie-Name` em toda requisição, com o valor `token` por padrão.
|
|
72
|
+
|
|
73
|
+
Para usar outro cookie, acesse a loja com `?setCookieName=<nome>`. O SDK captura o valor, grava em `sessionStorage` sob a chave `uappi-cookie-name` e passa a enviá-lo no header a partir dali. Como `sessionStorage` é por aba, cada aba do navegador mantém sua própria sessão na mesma URL de projeto.
|
|
74
|
+
|
|
75
|
+
Nomes aceitos: `^[A-Za-z0-9_-]{1,64}$`. Valor fora desse formato é ignorado e o SDK segue com o anterior (ou com `token`).
|
|
76
|
+
|
|
77
|
+
Temas que compartilham a aba (iframe same-origin, ou navegação na mesma aba) leem o nome em uso por `Api.getCookieName()`, sem reimplementar a chave do storage.
|
|
78
|
+
|
|
79
|
+
A captura da URL acontece sozinha na primeira requisição. Se o tema limpa a query string no boot — router SPA com `replace`, por exemplo — chame `Api.captureCookieName()` antes disso.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const STORAGE_KEY = 'uappi-cookie-name';
|
|
2
|
+
const DEFAULT_COOKIE_NAME = 'token';
|
|
3
|
+
const VALID_COOKIE_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
4
|
+
|
|
5
|
+
export function captureCookieName() {
|
|
6
|
+
const param = new URLSearchParams(window.location.search).get(
|
|
7
|
+
'setCookieName',
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
if (!param || !VALID_COOKIE_NAME.test(param)) return;
|
|
11
|
+
|
|
12
|
+
sessionStorage.setItem(STORAGE_KEY, param);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getCookieName() {
|
|
16
|
+
captureCookieName();
|
|
17
|
+
|
|
18
|
+
const stored = sessionStorage.getItem(STORAGE_KEY);
|
|
19
|
+
|
|
20
|
+
return stored && VALID_COOKIE_NAME.test(stored)
|
|
21
|
+
? stored
|
|
22
|
+
: DEFAULT_COOKIE_NAME;
|
|
23
|
+
}
|
package/modules/Api/index.ts
CHANGED
|
@@ -103,6 +103,7 @@ import { sendMfa, confirmMfa, loginMfa, deleteMFA, mfaSetup } from './endpoints/
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
import { usePublicApi } from './usePublicApi';
|
|
106
|
+
import { captureCookieName, getCookieName } from './cookieName';
|
|
106
107
|
|
|
107
108
|
const thirdParty = {
|
|
108
109
|
oauthRedirect,
|
|
@@ -227,6 +228,8 @@ const notify = {
|
|
|
227
228
|
|
|
228
229
|
export {
|
|
229
230
|
usePublicApi,
|
|
231
|
+
captureCookieName,
|
|
232
|
+
getCookieName,
|
|
230
233
|
common,
|
|
231
234
|
customer,
|
|
232
235
|
customization,
|
|
@@ -239,6 +242,8 @@ export {
|
|
|
239
242
|
};
|
|
240
243
|
export default {
|
|
241
244
|
usePublicApi,
|
|
245
|
+
captureCookieName,
|
|
246
|
+
getCookieName,
|
|
242
247
|
|
|
243
248
|
common,
|
|
244
249
|
customer,
|
|
@@ -354,6 +354,16 @@ export interface CustomerOrderItem {
|
|
|
354
354
|
simpleProduct: SimpleProduct;
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
export interface InternalDepositBank {
|
|
358
|
+
name: string;
|
|
359
|
+
bankName: string;
|
|
360
|
+
bank: string;
|
|
361
|
+
agency: string;
|
|
362
|
+
account: string;
|
|
363
|
+
operation: string;
|
|
364
|
+
document: string;
|
|
365
|
+
}
|
|
366
|
+
|
|
357
367
|
export interface CustomerOrderPayment {
|
|
358
368
|
id: 154;
|
|
359
369
|
orderGroupId: number;
|
|
@@ -377,6 +387,7 @@ export interface CustomerOrderPayment {
|
|
|
377
387
|
billetBarCode: null | string;
|
|
378
388
|
billetDigitableLine: null | string;
|
|
379
389
|
billetUrl: null | string;
|
|
390
|
+
internalDepositBank: InternalDepositBank | null;
|
|
380
391
|
cardAutomaticCapture: boolean;
|
|
381
392
|
cardMasked: string | null;
|
|
382
393
|
cardFlag:
|
|
@@ -3,6 +3,7 @@ import axios, { type AxiosError, AxiosHeaders } from 'axios';
|
|
|
3
3
|
import type { ApiContext, ApiError, ApiErrorData } from './types';
|
|
4
4
|
|
|
5
5
|
import { encodeWafNormalizer } from './paramsSerializer/encodeWafNormalizer';
|
|
6
|
+
import { getCookieName } from './cookieName';
|
|
6
7
|
|
|
7
8
|
export async function usePublicApi<
|
|
8
9
|
ResponseType,
|
|
@@ -26,7 +27,7 @@ export async function usePublicApi<
|
|
|
26
27
|
params,
|
|
27
28
|
}: ApiContext<RequestType, FieldOptions, OrderOptions, ConditionOptions>) {
|
|
28
29
|
const headers = new AxiosHeaders({
|
|
29
|
-
'Uappi-Cookie-Name':
|
|
30
|
+
'Uappi-Cookie-Name': getCookieName(),
|
|
30
31
|
Accept: 'application/json',
|
|
31
32
|
});
|
|
32
33
|
|