@neetru/sdk 3.7.0 → 3.8.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +66 -1
  3. package/dist/ai.cjs +221 -177
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +221 -177
  7. package/dist/auth.cjs +1227 -1064
  8. package/dist/auth.d.cts +1 -1
  9. package/dist/auth.d.ts +1 -1
  10. package/dist/auth.mjs +1224 -1061
  11. package/dist/catalog.cjs +164 -97
  12. package/dist/catalog.d.cts +1 -1
  13. package/dist/catalog.d.ts +1 -1
  14. package/dist/catalog.mjs +164 -97
  15. package/dist/checkout.cjs +182 -115
  16. package/dist/checkout.d.cts +1 -1
  17. package/dist/checkout.d.ts +1 -1
  18. package/dist/checkout.mjs +181 -114
  19. package/dist/db-react.d.cts +1 -1
  20. package/dist/db-react.d.ts +1 -1
  21. package/dist/db.cjs +370 -298
  22. package/dist/db.d.cts +1 -1
  23. package/dist/db.d.ts +1 -1
  24. package/dist/db.mjs +362 -290
  25. package/dist/entitlements.cjs +17 -10
  26. package/dist/entitlements.d.cts +1 -1
  27. package/dist/entitlements.d.ts +1 -1
  28. package/dist/entitlements.mjs +17 -10
  29. package/dist/errors.cjs +15 -8
  30. package/dist/errors.d.cts +24 -3
  31. package/dist/errors.d.ts +24 -3
  32. package/dist/errors.mjs +14 -7
  33. package/dist/firestore-compat.d.cts +1 -1
  34. package/dist/firestore-compat.d.ts +1 -1
  35. package/dist/index.cjs +1409 -1075
  36. package/dist/index.d.cts +177 -3
  37. package/dist/index.d.ts +177 -3
  38. package/dist/index.mjs +1544 -1217
  39. package/dist/mobile.cjs +400 -181
  40. package/dist/mobile.d.cts +59 -4
  41. package/dist/mobile.d.ts +59 -4
  42. package/dist/mobile.mjs +400 -181
  43. package/dist/mocks.cjs +9 -2
  44. package/dist/mocks.d.cts +1 -1
  45. package/dist/mocks.d.ts +1 -1
  46. package/dist/mocks.mjs +9 -2
  47. package/dist/notifications.cjs +197 -130
  48. package/dist/notifications.d.cts +1 -1
  49. package/dist/notifications.d.ts +1 -1
  50. package/dist/notifications.mjs +196 -129
  51. package/dist/react.cjs +303 -282
  52. package/dist/react.d.cts +1 -1
  53. package/dist/react.d.ts +1 -1
  54. package/dist/react.mjs +295 -274
  55. package/dist/support.cjs +299 -229
  56. package/dist/support.d.cts +8 -4
  57. package/dist/support.d.ts +8 -4
  58. package/dist/support.mjs +298 -228
  59. package/dist/telemetry.cjs +234 -167
  60. package/dist/telemetry.d.cts +1 -1
  61. package/dist/telemetry.d.ts +1 -1
  62. package/dist/telemetry.mjs +234 -167
  63. package/dist/{types-Bx4kTLmk.d.cts → types-D-9bjlM0.d.cts} +48 -1
  64. package/dist/{types-Dx0IrOSF.d.ts → types-bVztFQTI.d.ts} +48 -1
  65. package/dist/usage.cjs +183 -116
  66. package/dist/usage.d.cts +1 -1
  67. package/dist/usage.d.ts +1 -1
  68. package/dist/usage.mjs +183 -116
  69. package/dist/webhooks.cjs +215 -148
  70. package/dist/webhooks.d.cts +1 -1
  71. package/dist/webhooks.d.ts +1 -1
  72. package/dist/webhooks.mjs +212 -145
  73. package/package.json +2 -1
package/dist/mobile.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { X as NeetruClientConfig, v as CompleteSignInResult, a5 as NeetruUser, m as AuthStateListener } from './types-Bx4kTLmk.cjs';
1
+ import { Y as NeetruClientConfig, v as CompleteSignInResult, a6 as NeetruUser, m as AuthStateListener } from './types-D-9bjlM0.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
@@ -12,7 +12,23 @@ interface MobileAuthStorage {
12
12
  setItem(key: string, value: string): Promise<void>;
13
13
  removeItem(key: string): Promise<void>;
14
14
  }
15
- interface MobileAuthConfig extends NeetruClientConfig {
15
+ interface MobileAuthConfig extends Omit<NeetruClientConfig, 'apiKey'> {
16
+ /**
17
+ * 3.8.0: PROIBIDO. A credencial `nrt_` é só de servidor — passar qualquer
18
+ * valor aqui faz `createMobileAuthNamespace` lançar `server_only_key`.
19
+ */
20
+ apiKey?: never;
21
+ /**
22
+ * `client_id` do client OIDC PÚBLICO do app (iOS/Android), registrado no Core.
23
+ * Obrigatório a partir da 3.8.0 (antes caía no keyId da apiKey).
24
+ */
25
+ oidcClientId?: string;
26
+ /**
27
+ * 3.8.0: URL base da API do SEU produto (ex.: `https://pdv.neetru.com/api/v1`).
28
+ * Usada por `auth.authFetch(...)` — o access_token SÓ é enviado para essa
29
+ * origem (nunca para outro host). Precisa ser `https://` (ou `http://localhost`).
30
+ */
31
+ productApiUrl?: string;
16
32
  /** Storage persistente (idealmente seguro) — ver requisito 4 no JSDoc do módulo. */
17
33
  storage: MobileAuthStorage;
18
34
  /**
@@ -62,6 +78,30 @@ interface MobileAuthNamespace {
62
78
  completeSignIn(callbackUrl: string): Promise<CompleteSignInResult>;
63
79
  /** `id_token` cru armazenado, ou `null` se ausente/expirado. */
64
80
  getIdToken(): Promise<string | null>;
81
+ /**
82
+ * 3.8.0: `access_token` válido para chamar a API do produto (Bearer). Se o
83
+ * armazenado venceu (ou vence em <30s) e há refresh_token, renova 1x antes.
84
+ * `null` se não há sessão.
85
+ */
86
+ getAccessToken(): Promise<string | null>;
87
+ /**
88
+ * 3.8.0: claims do usuário no `/api/v1/oauth/userinfo` do Core (fonte
89
+ * autoritativa — reflete conta suspensa/cancelada, diferente do id_token).
90
+ * Num 401 renova a sessão 1x e repete.
91
+ *
92
+ * @throws {NeetruAuthRequiredError} sem sessão ou sessão recusada pelo Core.
93
+ */
94
+ getUserInfo(): Promise<MobileUserInfo>;
95
+ /**
96
+ * 3.8.0: `fetch` autenticado para a API do PRODUTO (`config.productApiUrl`):
97
+ * injeta `Authorization: Bearer <access_token>` e `x-correlation-id`; num 401
98
+ * renova a sessão 1x e repete. Aceita path relativo (`/vendas`) ou URL
99
+ * absoluta DA MESMA origem — outra origem é recusada (o token nunca vaza).
100
+ *
101
+ * @throws {NeetruError} `invalid_config` (sem `productApiUrl` / outra origem),
102
+ * {@link NeetruAuthRequiredError} sem sessão.
103
+ */
104
+ authFetch(pathOrUrl: string, init?: RequestInit): Promise<Response>;
65
105
  /** Usuário atual (claims do `id_token` armazenado), ou `null`. */
66
106
  getUser(): Promise<NeetruUser | null>;
67
107
  /**
@@ -77,13 +117,28 @@ interface MobileAuthNamespace {
77
117
  * token, `invalid_grant`, rede) — não lança.
78
118
  */
79
119
  refreshTokens(): Promise<boolean>;
80
- /** Limpa a sessão local (storage) + melhor esforço de revoke no servidor. */
120
+ /**
121
+ * Limpa a sessão local (storage) e revoga no Core (RFC 7009, client público)
122
+ * o refresh_token e o access_token. A limpeza local acontece SEMPRE, mesmo
123
+ * se o servidor estiver fora; a revogação é melhor esforço (avisa no console).
124
+ */
81
125
  signOut(): Promise<void>;
82
126
  }
127
+ /** 3.8.0 — resposta do `/userinfo` (escopo decide quais campos vêm). */
128
+ interface MobileUserInfo {
129
+ sub: string;
130
+ email?: string;
131
+ email_verified?: boolean;
132
+ name?: string;
133
+ picture?: string;
134
+ tenant_id?: string;
135
+ entitlements?: string[];
136
+ [claim: string]: unknown;
137
+ }
83
138
  /**
84
139
  * Cria o namespace de auth mobile. Ver JSDoc do módulo pros requisitos do
85
140
  * app consumidor (polyfill WebCrypto, browser externo, storage seguro).
86
141
  */
87
142
  declare function createMobileAuthNamespace(config: MobileAuthConfig): MobileAuthNamespace;
88
143
 
89
- export { type MobileAuthConfig, type MobileAuthNamespace, type MobileAuthStorage, type MobileSignInOptions, createMobileAuthNamespace };
144
+ export { type MobileAuthConfig, type MobileAuthNamespace, type MobileAuthStorage, type MobileSignInOptions, type MobileUserInfo, createMobileAuthNamespace };
package/dist/mobile.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { X as NeetruClientConfig, v as CompleteSignInResult, a5 as NeetruUser, m as AuthStateListener } from './types-Dx0IrOSF.js';
1
+ import { Y as NeetruClientConfig, v as CompleteSignInResult, a6 as NeetruUser, m as AuthStateListener } from './types-bVztFQTI.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
@@ -12,7 +12,23 @@ interface MobileAuthStorage {
12
12
  setItem(key: string, value: string): Promise<void>;
13
13
  removeItem(key: string): Promise<void>;
14
14
  }
15
- interface MobileAuthConfig extends NeetruClientConfig {
15
+ interface MobileAuthConfig extends Omit<NeetruClientConfig, 'apiKey'> {
16
+ /**
17
+ * 3.8.0: PROIBIDO. A credencial `nrt_` é só de servidor — passar qualquer
18
+ * valor aqui faz `createMobileAuthNamespace` lançar `server_only_key`.
19
+ */
20
+ apiKey?: never;
21
+ /**
22
+ * `client_id` do client OIDC PÚBLICO do app (iOS/Android), registrado no Core.
23
+ * Obrigatório a partir da 3.8.0 (antes caía no keyId da apiKey).
24
+ */
25
+ oidcClientId?: string;
26
+ /**
27
+ * 3.8.0: URL base da API do SEU produto (ex.: `https://pdv.neetru.com/api/v1`).
28
+ * Usada por `auth.authFetch(...)` — o access_token SÓ é enviado para essa
29
+ * origem (nunca para outro host). Precisa ser `https://` (ou `http://localhost`).
30
+ */
31
+ productApiUrl?: string;
16
32
  /** Storage persistente (idealmente seguro) — ver requisito 4 no JSDoc do módulo. */
17
33
  storage: MobileAuthStorage;
18
34
  /**
@@ -62,6 +78,30 @@ interface MobileAuthNamespace {
62
78
  completeSignIn(callbackUrl: string): Promise<CompleteSignInResult>;
63
79
  /** `id_token` cru armazenado, ou `null` se ausente/expirado. */
64
80
  getIdToken(): Promise<string | null>;
81
+ /**
82
+ * 3.8.0: `access_token` válido para chamar a API do produto (Bearer). Se o
83
+ * armazenado venceu (ou vence em <30s) e há refresh_token, renova 1x antes.
84
+ * `null` se não há sessão.
85
+ */
86
+ getAccessToken(): Promise<string | null>;
87
+ /**
88
+ * 3.8.0: claims do usuário no `/api/v1/oauth/userinfo` do Core (fonte
89
+ * autoritativa — reflete conta suspensa/cancelada, diferente do id_token).
90
+ * Num 401 renova a sessão 1x e repete.
91
+ *
92
+ * @throws {NeetruAuthRequiredError} sem sessão ou sessão recusada pelo Core.
93
+ */
94
+ getUserInfo(): Promise<MobileUserInfo>;
95
+ /**
96
+ * 3.8.0: `fetch` autenticado para a API do PRODUTO (`config.productApiUrl`):
97
+ * injeta `Authorization: Bearer <access_token>` e `x-correlation-id`; num 401
98
+ * renova a sessão 1x e repete. Aceita path relativo (`/vendas`) ou URL
99
+ * absoluta DA MESMA origem — outra origem é recusada (o token nunca vaza).
100
+ *
101
+ * @throws {NeetruError} `invalid_config` (sem `productApiUrl` / outra origem),
102
+ * {@link NeetruAuthRequiredError} sem sessão.
103
+ */
104
+ authFetch(pathOrUrl: string, init?: RequestInit): Promise<Response>;
65
105
  /** Usuário atual (claims do `id_token` armazenado), ou `null`. */
66
106
  getUser(): Promise<NeetruUser | null>;
67
107
  /**
@@ -77,13 +117,28 @@ interface MobileAuthNamespace {
77
117
  * token, `invalid_grant`, rede) — não lança.
78
118
  */
79
119
  refreshTokens(): Promise<boolean>;
80
- /** Limpa a sessão local (storage) + melhor esforço de revoke no servidor. */
120
+ /**
121
+ * Limpa a sessão local (storage) e revoga no Core (RFC 7009, client público)
122
+ * o refresh_token e o access_token. A limpeza local acontece SEMPRE, mesmo
123
+ * se o servidor estiver fora; a revogação é melhor esforço (avisa no console).
124
+ */
81
125
  signOut(): Promise<void>;
82
126
  }
127
+ /** 3.8.0 — resposta do `/userinfo` (escopo decide quais campos vêm). */
128
+ interface MobileUserInfo {
129
+ sub: string;
130
+ email?: string;
131
+ email_verified?: boolean;
132
+ name?: string;
133
+ picture?: string;
134
+ tenant_id?: string;
135
+ entitlements?: string[];
136
+ [claim: string]: unknown;
137
+ }
83
138
  /**
84
139
  * Cria o namespace de auth mobile. Ver JSDoc do módulo pros requisitos do
85
140
  * app consumidor (polyfill WebCrypto, browser externo, storage seguro).
86
141
  */
87
142
  declare function createMobileAuthNamespace(config: MobileAuthConfig): MobileAuthNamespace;
88
143
 
89
- export { type MobileAuthConfig, type MobileAuthNamespace, type MobileAuthStorage, type MobileSignInOptions, createMobileAuthNamespace };
144
+ export { type MobileAuthConfig, type MobileAuthNamespace, type MobileAuthStorage, type MobileSignInOptions, type MobileUserInfo, createMobileAuthNamespace };