@proef/common-ui 2.6.34 → 2.6.36

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 (24) hide show
  1. package/dist/esm/index.js +10 -1
  2. package/dist/esm/index.js.map +1 -1
  3. package/dist/esm/v1/capabilities/onepoint-rn/connectInbox.js +26 -4
  4. package/dist/esm/v1/capabilities/onepoint-rn/connectInbox.js.map +1 -1
  5. package/dist/esm/v1/capabilities/onepoint-rn/connectOutbox.js.map +1 -1
  6. package/dist/esm/v1/capabilities/onepoint-rn/useOfflineBoxes.js +103 -0
  7. package/dist/esm/v1/capabilities/onepoint-rn/useOfflineBoxes.js.map +1 -0
  8. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxes.js +78 -0
  9. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxes.js.map +1 -0
  10. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.js +86 -0
  11. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.js.map +1 -0
  12. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesView.js +243 -0
  13. package/dist/esm/v1/components/feedback/OfflineBoxes/OfflineBoxesView.js.map +1 -0
  14. package/dist/style.components.css +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/style.layered.css +1 -1
  17. package/dist/types/v1/capabilities/onepoint-rn/connectInbox.d.ts +6 -0
  18. package/dist/types/v1/capabilities/onepoint-rn/connectOutbox.d.ts +2 -0
  19. package/dist/types/v1/capabilities/onepoint-rn/useOfflineBoxes.d.ts +14 -0
  20. package/dist/types/v1/components/feedback/OfflineBoxes/OfflineBoxes.d.ts +30 -0
  21. package/dist/types/v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.d.ts +12 -0
  22. package/dist/types/v1/components/feedback/OfflineBoxes/OfflineBoxesView.d.ts +86 -0
  23. package/dist/types/v1/index.d.ts +5 -1
  24. package/package.json +6 -5
package/dist/esm/index.js CHANGED
@@ -52,6 +52,8 @@ import { default as default49 } from "./legacy/components/ui/MenuAcoes.js";
52
52
  import { default as default50 } from "./legacy/components/molecules/Modal/Modal.js";
53
53
  import { default as default51 } from "./legacy/components/molecules/MultiTagPicker/MultiTagPicker.js";
54
54
  import { default as default52 } from "./legacy/pages/NotFound/NotFound.js";
55
+ import { OfflineBoxes } from "./v1/components/feedback/OfflineBoxes/OfflineBoxes.js";
56
+ import { OfflineBoxesIcon } from "./v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.js";
55
57
  import { default as default53 } from "./v1/components/layout/Page/Page.js";
56
58
  import { default as default54 } from "./v1/components/layout/PageHeader/PageHeader.js";
57
59
  import { default as default55 } from "./v1/components/tables/PaginatedTable/PaginatedTable.js";
@@ -101,13 +103,14 @@ import { BoldIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon
101
103
  import { Card } from "./v1/primitives/display/Card/Card.js";
102
104
  import { DEFAULT_DAY_TIMELINE_LABELS, DayTimeline, DayTimelineScale, scheduleParts, toMinutes, uncoveredIntervals } from "./v1/components/data/DayTimeline/DayTimeline.js";
103
105
  import { DEFAULT_LIST_FINDER_LABELS } from "./v1/components/lists/ListFinder/labels.js";
106
+ import { DEFAULT_OFFLINE_BOXES_LABELS } from "./v1/components/feedback/OfflineBoxes/OfflineBoxesView.js";
104
107
  import { DEFAULT_TABLE_LABELS } from "./v1/components/tables/Table/labels.js";
105
108
  import { DescriptionList } from "./v1/primitives/display/DescriptionList/DescriptionList.js";
106
109
  import { ESTILO_AVATAR_PILHA, PessoaComFoto, PilhaAvatares } from "./legacy/components/molecules/PhotoAvatar/pessoas.js";
107
110
  import { ErroBridge, pedirAoNativo } from "./v1/capabilities/onepoint-rn/bridge.js";
108
111
  import { FilterChips } from "./v1/primitives/display/FilterChips/FilterChips.js";
109
112
  import { FontWeight } from "./legacy/constants/FontWeight.js";
110
- import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, syncInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
113
+ import { INBOX_SAVED_AT_HEADER, connectInbox, inboxSavedAt, inboxStatus, syncInbox, watchInbox } from "./v1/capabilities/onepoint-rn/connectInbox.js";
111
114
  import { InputData, InputHora } from "./legacy/components/atoms/InputData/InputData.js";
112
115
  import { Kpi } from "./v1/primitives/display/Kpi/Kpi.js";
113
116
  import { LazyLoader } from "./legacy/components/organisms/LazyLoader/LazyLoader.js";
@@ -137,6 +140,7 @@ import { useApi } from "./legacy/hooks/useApi.js";
137
140
  import { useBarraEstadoNaApp } from "./v1/capabilities/onepoint-rn/useBarraEstadoNaApp.js";
138
141
  import { useIsDark } from "./v1/capabilities/theme/useIsDark.js";
139
142
  import { useMenuLateralNaApp } from "./v1/capabilities/onepoint-rn/useMenuLateralNaApp.js";
143
+ import { useOfflineBoxes } from "./v1/capabilities/onepoint-rn/useOfflineBoxes.js";
140
144
  import { useOrientacaoNaApp } from "./v1/capabilities/onepoint-rn/useOrientacaoNaApp.js";
141
145
  export {
142
146
  default3 as Acronym,
@@ -190,6 +194,7 @@ export {
190
194
  DEFAULT_DAY_TIMELINE_LABELS,
191
195
  DEFAULT_DROPDOWN_MENU_LABELS,
192
196
  DEFAULT_LIST_FINDER_LABELS,
197
+ DEFAULT_OFFLINE_BOXES_LABELS,
193
198
  DEFAULT_STEPS_LABELS,
194
199
  DEFAULT_TABLE_LABELS,
195
200
  default19 as DataTable,
@@ -272,6 +277,8 @@ export {
272
277
  default52 as NotFoundPage,
273
278
  Notice,
274
279
  OUTBOX_SAVED_MESSAGE,
280
+ OfflineBoxes,
281
+ OfflineBoxesIcon,
275
282
  OutboxSavedError,
276
283
  PALETA,
277
284
  default53 as Page,
@@ -392,10 +399,12 @@ export {
392
399
  useDialogContainer,
393
400
  useIsDark,
394
401
  useMenuLateralNaApp,
402
+ useOfflineBoxes,
395
403
  useOrientacaoNaApp,
396
404
  useSocket,
397
405
  useTheme,
398
406
  useToast,
407
+ watchInbox,
399
408
  watchOutbox
400
409
  };
401
410
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -63,10 +63,31 @@ function countIn(event, field) {
63
63
  const count = Reflect.get(event, field);
64
64
  return typeof count === "number" ? count : 0;
65
65
  }
66
- function progressFor(event, storageId, inboxId) {
66
+ function eventFor(event, storageId) {
67
67
  if (typeof event !== "object" || event === null) return null;
68
- if (Reflect.get(event, "storageId") !== storageId || Reflect.get(event, "inboxId") !== inboxId) return null;
69
- return { total: countIn(event, "total"), ready: countIn(event, "ready"), failed: countIn(event, "failed") };
68
+ const inboxId = Reflect.get(event, "inboxId");
69
+ if (Reflect.get(event, "storageId") !== storageId || typeof inboxId !== "string") return null;
70
+ const finishedAt = Reflect.get(event, "finishedAt");
71
+ return {
72
+ inboxId,
73
+ total: countIn(event, "total"),
74
+ ready: countIn(event, "ready"),
75
+ failed: countIn(event, "failed"),
76
+ finishedAt: typeof finishedAt === "string" ? finishedAt : null
77
+ };
78
+ }
79
+ function progressFor(event, storageId, inboxId) {
80
+ const inboxEvent = eventFor(event, storageId);
81
+ if (!inboxEvent || inboxEvent.inboxId !== inboxId) return null;
82
+ return { total: inboxEvent.total, ready: inboxEvent.ready, failed: inboxEvent.failed };
83
+ }
84
+ function watchInbox(options, onEvent) {
85
+ const storageId = checkedStorageId(options.storageId, "watchInbox");
86
+ if (!dentroDaApp()) return () => void 0;
87
+ return onNativeEvent("inbox", (carga) => {
88
+ const inboxEvent = eventFor(carga, storageId);
89
+ if (inboxEvent) onEvent(inboxEvent);
90
+ });
70
91
  }
71
92
  async function syncInbox(api, options, onProgress) {
72
93
  const storageId = checkedStorageId(options.storageId, "syncInbox");
@@ -91,6 +112,7 @@ export {
91
112
  connectInbox,
92
113
  inboxSavedAt,
93
114
  inboxStatus,
94
- syncInbox
115
+ syncInbox,
116
+ watchInbox
95
117
  };
96
118
  //# sourceMappingURL=connectInbox.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectInbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectInbox.ts"],"sourcesContent":["import axios, { AxiosError } from 'axios'\r\nimport type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoInbox = 'inbox.read' | 'inbox.state' | 'inbox.sync'\r\n\r\nexport type InboxTier = 'account' | 'device'\r\n\r\nexport type InboxEach = {\r\n id: string\r\n stamp?: string\r\n list?: string\r\n paths: string[]\r\n}\r\n\r\nexport type InboxBundle = {\r\n ids: string\r\n list: string\r\n id: string\r\n parts: Record<string, string>\r\n since?: { param: string; from: string }\r\n missing?: { param: string }\r\n}\r\n\r\nexport type InboxGet = { path: string; tier?: InboxTier } & ({ each?: InboxEach; bundle?: never } | { bundle: InboxBundle; each?: never })\r\n\r\nexport type InboxOptions = { storageId: string | undefined }\r\n\r\nexport type InboxConnectOptions = InboxOptions & { paused?: () => boolean }\r\n\r\nexport type InboxSyncOptions = InboxOptions & { inboxId: string; tier: InboxTier; gets: InboxGet[] }\r\n\r\nexport type InboxProgress = { total: number; ready: number; failed: number }\r\n\r\nexport type InboxStatus = InboxProgress & { finishedAt: string | null }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n inbox?: false\r\n }\r\n}\r\n\r\nexport const INBOX_SAVED_AT_HEADER = 'x-inbox-saved-at'\r\n\r\nconst INBOX_ID_FORMAT = /^[a-z0-9]+(-[a-z0-9]+)*$/\r\nconst BRIDGE_WAIT_MS = 30_000\r\nconst SYNC_WAIT_MS = 30 * 60_000\r\n\r\ntype InboxRead = { found: false } | { found: true; status: number; body: unknown; savedAt: string }\r\n\r\nfunction checkedInboxId(inboxId: string, caller: string): string {\r\n if (INBOX_ID_FORMAT.test(inboxId)) return inboxId\r\n throw new Error(`${caller}: inboxId \"${inboxId}\" is not valid; use lowercase letters, digits and hyphens, such as ajustes`)\r\n}\r\n\r\nconst pausedChecks = new WeakMap<AxiosInstance, () => boolean>()\r\n\r\nfunction isPaused(api: AxiosInstance): boolean {\r\n const paused = pausedChecks.get(api)\r\n return paused ? paused() : false\r\n}\r\n\r\nfunction answersFromInbox(error: unknown): error is AxiosError & { config: InternalAxiosRequestConfig } {\r\n if (!(error instanceof AxiosError) || !error.config || error.response || axios.isCancel(error)) return false\r\n const method = (error.config.method ?? 'get').toLowerCase()\r\n return method === 'get' && error.config.inbox !== false && dentroDaApp()\r\n}\r\n\r\nasync function storedAnswer(api: AxiosInstance, storageId: string, config: InternalAxiosRequestConfig): Promise<AxiosResponse | null> {\r\n const { address, path } = addressAndPath(api, config)\r\n let stored: InboxRead\r\n try {\r\n stored = await pedirAoNativo<InboxRead>('inbox.read', { storageId, address, path }, BRIDGE_WAIT_MS)\r\n } catch {\r\n return null\r\n }\r\n if (!stored.found) return null\r\n return {\r\n data: stored.body,\r\n status: stored.status,\r\n statusText: '',\r\n headers: { [INBOX_SAVED_AT_HEADER]: stored.savedAt },\r\n config,\r\n request: {},\r\n }\r\n}\r\n\r\nexport function connectInbox(api: AxiosInstance, options: InboxConnectOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectInbox')\r\n if (options.paused) pausedChecks.set(api, options.paused)\r\n api.interceptors.response.use(undefined, async (error: unknown) => {\r\n if (!answersFromInbox(error) || isPaused(api)) throw error\r\n const answer = await storedAnswer(api, storageId, error.config)\r\n if (!answer) throw error\r\n return answer\r\n })\r\n}\r\n\r\nexport function inboxSavedAt(response: AxiosResponse): string | null {\r\n const savedAt: unknown = response.headers[INBOX_SAVED_AT_HEADER]\r\n return typeof savedAt === 'string' ? savedAt : null\r\n}\r\n\r\nexport async function inboxStatus(options: InboxOptions & { inboxId: string }): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'inboxStatus')\r\n const inboxId = checkedInboxId(options.inboxId, 'inboxStatus')\r\n if (!dentroDaApp()) return null\r\n return pedirAoNativo<InboxStatus>('inbox.state', { storageId, inboxId }, BRIDGE_WAIT_MS)\r\n}\r\n\r\nfunction countIn(event: object, field: keyof InboxProgress): number {\r\n const count: unknown = Reflect.get(event, field)\r\n return typeof count === 'number' ? count : 0\r\n}\r\n\r\nfunction progressFor(event: unknown, storageId: string, inboxId: string): InboxProgress | null {\r\n if (typeof event !== 'object' || event === null) return null\r\n if (Reflect.get(event, 'storageId') !== storageId || Reflect.get(event, 'inboxId') !== inboxId) return null\r\n return { total: countIn(event, 'total'), ready: countIn(event, 'ready'), failed: countIn(event, 'failed') }\r\n}\r\n\r\nexport async function syncInbox(\r\n api: AxiosInstance,\r\n options: InboxSyncOptions,\r\n onProgress?: (progress: InboxProgress) => void,\r\n): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'syncInbox')\r\n const inboxId = checkedInboxId(options.inboxId, 'syncInbox')\r\n if (!dentroDaApp() || isPaused(api)) return null\r\n\r\n const gets = options.gets.map((get) => {\r\n const { address, path } = addressAndPath(api, { baseURL: api.defaults.baseURL, url: get.path })\r\n return { address, path, tier: get.tier ?? options.tier, each: get.each, bundle: get.bundle }\r\n })\r\n const stop = onNativeEvent('inbox', (carga) => {\r\n const progress = progressFor(carga, storageId, inboxId)\r\n if (progress && onProgress) onProgress(progress)\r\n })\r\n try {\r\n return await pedirAoNativo<InboxStatus>('inbox.sync', { storageId, inboxId, gets }, SYNC_WAIT_MS)\r\n } finally {\r\n stop()\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AA6CO,MAAM,wBAAwB;AAErC,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,eAAe,KAAK;AAI1B,SAAS,eAAe,SAAiB,QAAwB;AAC/D,MAAI,gBAAgB,KAAK,OAAO,EAAG,QAAO;AAC1C,QAAM,IAAI,MAAM,GAAG,MAAM,cAAc,OAAO,4EAA4E;AAC5H;AAEA,MAAM,mCAAmB,QAAA;AAEzB,SAAS,SAAS,KAA6B;AAC7C,QAAM,SAAS,aAAa,IAAI,GAAG;AACnC,SAAO,SAAS,WAAW;AAC7B;AAEA,SAAS,iBAAiB,OAA8E;AACtG,MAAI,EAAE,iBAAiB,eAAe,CAAC,MAAM,UAAU,MAAM,YAAY,MAAM,SAAS,KAAK,EAAG,QAAO;AACvG,QAAM,UAAU,MAAM,OAAO,UAAU,OAAO,YAAA;AAC9C,SAAO,WAAW,SAAS,MAAM,OAAO,UAAU,SAAS,YAAA;AAC7D;AAEA,eAAe,aAAa,KAAoB,WAAmB,QAAmE;AACpI,QAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,MAAM;AACpD,MAAI;AACJ,MAAI;AACF,aAAS,MAAM,cAAyB,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,cAAc;AAAA,EACpG,QAAQ;AACN,WAAO;AAAA,EACT;AACA,MAAI,CAAC,OAAO,MAAO,QAAO;AAC1B,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,QAAQ,OAAO;AAAA,IACf,YAAY;AAAA,IACZ,SAAS,EAAE,CAAC,qBAAqB,GAAG,OAAO,QAAA;AAAA,IAC3C;AAAA,IACA,SAAS,CAAA;AAAA,EAAC;AAEd;AAEO,SAAS,aAAa,KAAoB,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I,CAAC,YAAA,KAAiB,SAAS,GAAG,EAAG,QAAO;AAE5C,QAAM,OAAO,QAAQ,KAAK,IAAI,CAAC,QAAQ;AACrC,UAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,EAAE,SAAS,IAAI,SAAS,SAAS,KAAK,IAAI,MAAM;AAC9F,WAAO,EAAE,SAAS,MAAM,MAAM,IAAI,QAAQ,QAAQ,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,OAAA;AAAA,EACtF,CAAC;AACD,QAAM,OAAO,cAAc,SAAS,CAAC,UAAU;AAC7C,UAAM,WAAW,YAAY,OAAO,WAAW,OAAO;AACtD,QAAI,YAAY,WAAY,YAAW,QAAQ;AAAA,EACjD,CAAC;AACD,MAAI;AACF,WAAO,MAAM,cAA2B,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,YAAY;AAAA,EAClG,UAAA;AACE,SAAA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"connectInbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectInbox.ts"],"sourcesContent":["import axios, { AxiosError } from 'axios'\r\nimport type { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoInbox = 'inbox.read' | 'inbox.state' | 'inbox.sync'\r\n\r\nexport type InboxTier = 'account' | 'device'\r\n\r\nexport type InboxEach = {\r\n id: string\r\n stamp?: string\r\n list?: string\r\n paths: string[]\r\n}\r\n\r\nexport type InboxBundle = {\r\n ids: string\r\n list: string\r\n id: string\r\n parts: Record<string, string>\r\n since?: { param: string; from: string }\r\n missing?: { param: string }\r\n}\r\n\r\nexport type InboxGet = { path: string; tier?: InboxTier } & ({ each?: InboxEach; bundle?: never } | { bundle: InboxBundle; each?: never })\r\n\r\nexport type InboxOptions = { storageId: string | undefined }\r\n\r\nexport type InboxConnectOptions = InboxOptions & { paused?: () => boolean }\r\n\r\nexport type InboxSyncOptions = InboxOptions & { inboxId: string; tier: InboxTier; gets: InboxGet[] }\r\n\r\nexport type InboxProgress = { total: number; ready: number; failed: number }\r\n\r\nexport type InboxStatus = InboxProgress & { finishedAt: string | null; saved?: string[] }\r\n\r\nexport type InboxEvent = InboxProgress & { inboxId: string; finishedAt: string | null }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n inbox?: false\r\n }\r\n}\r\n\r\nexport const INBOX_SAVED_AT_HEADER = 'x-inbox-saved-at'\r\n\r\nconst INBOX_ID_FORMAT = /^[a-z0-9]+(-[a-z0-9]+)*$/\r\nconst BRIDGE_WAIT_MS = 30_000\r\nconst SYNC_WAIT_MS = 30 * 60_000\r\n\r\ntype InboxRead = { found: false } | { found: true; status: number; body: unknown; savedAt: string }\r\n\r\nfunction checkedInboxId(inboxId: string, caller: string): string {\r\n if (INBOX_ID_FORMAT.test(inboxId)) return inboxId\r\n throw new Error(`${caller}: inboxId \"${inboxId}\" is not valid; use lowercase letters, digits and hyphens, such as ajustes`)\r\n}\r\n\r\nconst pausedChecks = new WeakMap<AxiosInstance, () => boolean>()\r\n\r\nfunction isPaused(api: AxiosInstance): boolean {\r\n const paused = pausedChecks.get(api)\r\n return paused ? paused() : false\r\n}\r\n\r\nfunction answersFromInbox(error: unknown): error is AxiosError & { config: InternalAxiosRequestConfig } {\r\n if (!(error instanceof AxiosError) || !error.config || error.response || axios.isCancel(error)) return false\r\n const method = (error.config.method ?? 'get').toLowerCase()\r\n return method === 'get' && error.config.inbox !== false && dentroDaApp()\r\n}\r\n\r\nasync function storedAnswer(api: AxiosInstance, storageId: string, config: InternalAxiosRequestConfig): Promise<AxiosResponse | null> {\r\n const { address, path } = addressAndPath(api, config)\r\n let stored: InboxRead\r\n try {\r\n stored = await pedirAoNativo<InboxRead>('inbox.read', { storageId, address, path }, BRIDGE_WAIT_MS)\r\n } catch {\r\n return null\r\n }\r\n if (!stored.found) return null\r\n return {\r\n data: stored.body,\r\n status: stored.status,\r\n statusText: '',\r\n headers: { [INBOX_SAVED_AT_HEADER]: stored.savedAt },\r\n config,\r\n request: {},\r\n }\r\n}\r\n\r\nexport function connectInbox(api: AxiosInstance, options: InboxConnectOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectInbox')\r\n if (options.paused) pausedChecks.set(api, options.paused)\r\n api.interceptors.response.use(undefined, async (error: unknown) => {\r\n if (!answersFromInbox(error) || isPaused(api)) throw error\r\n const answer = await storedAnswer(api, storageId, error.config)\r\n if (!answer) throw error\r\n return answer\r\n })\r\n}\r\n\r\nexport function inboxSavedAt(response: AxiosResponse): string | null {\r\n const savedAt: unknown = response.headers[INBOX_SAVED_AT_HEADER]\r\n return typeof savedAt === 'string' ? savedAt : null\r\n}\r\n\r\nexport async function inboxStatus(options: InboxOptions & { inboxId: string }): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'inboxStatus')\r\n const inboxId = checkedInboxId(options.inboxId, 'inboxStatus')\r\n if (!dentroDaApp()) return null\r\n return pedirAoNativo<InboxStatus>('inbox.state', { storageId, inboxId }, BRIDGE_WAIT_MS)\r\n}\r\n\r\nfunction countIn(event: object, field: keyof InboxProgress): number {\r\n const count: unknown = Reflect.get(event, field)\r\n return typeof count === 'number' ? count : 0\r\n}\r\n\r\nfunction eventFor(event: unknown, storageId: string): InboxEvent | null {\r\n if (typeof event !== 'object' || event === null) return null\r\n const inboxId: unknown = Reflect.get(event, 'inboxId')\r\n if (Reflect.get(event, 'storageId') !== storageId || typeof inboxId !== 'string') return null\r\n const finishedAt: unknown = Reflect.get(event, 'finishedAt')\r\n return {\r\n inboxId,\r\n total: countIn(event, 'total'),\r\n ready: countIn(event, 'ready'),\r\n failed: countIn(event, 'failed'),\r\n finishedAt: typeof finishedAt === 'string' ? finishedAt : null,\r\n }\r\n}\r\n\r\nfunction progressFor(event: unknown, storageId: string, inboxId: string): InboxProgress | null {\r\n const inboxEvent = eventFor(event, storageId)\r\n if (!inboxEvent || inboxEvent.inboxId !== inboxId) return null\r\n return { total: inboxEvent.total, ready: inboxEvent.ready, failed: inboxEvent.failed }\r\n}\r\n\r\nexport function watchInbox(options: InboxOptions, onEvent: (event: InboxEvent) => void): () => void {\r\n const storageId = checkedStorageId(options.storageId, 'watchInbox')\r\n if (!dentroDaApp()) return () => undefined\r\n return onNativeEvent('inbox', (carga) => {\r\n const inboxEvent = eventFor(carga, storageId)\r\n if (inboxEvent) onEvent(inboxEvent)\r\n })\r\n}\r\n\r\nexport async function syncInbox(\r\n api: AxiosInstance,\r\n options: InboxSyncOptions,\r\n onProgress?: (progress: InboxProgress) => void,\r\n): Promise<InboxStatus | null> {\r\n const storageId = checkedStorageId(options.storageId, 'syncInbox')\r\n const inboxId = checkedInboxId(options.inboxId, 'syncInbox')\r\n if (!dentroDaApp() || isPaused(api)) return null\r\n\r\n const gets = options.gets.map((get) => {\r\n const { address, path } = addressAndPath(api, { baseURL: api.defaults.baseURL, url: get.path })\r\n return { address, path, tier: get.tier ?? options.tier, each: get.each, bundle: get.bundle }\r\n })\r\n const stop = onNativeEvent('inbox', (carga) => {\r\n const progress = progressFor(carga, storageId, inboxId)\r\n if (progress && onProgress) onProgress(progress)\r\n })\r\n try {\r\n return await pedirAoNativo<InboxStatus>('inbox.sync', { storageId, inboxId, gets }, SYNC_WAIT_MS)\r\n } finally {\r\n stop()\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;AA+CO,MAAM,wBAAwB;AAErC,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AACvB,MAAM,eAAe,KAAK;AAI1B,SAAS,eAAe,SAAiB,QAAwB;AAC/D,MAAI,gBAAgB,KAAK,OAAO,EAAG,QAAO;AAC1C,QAAM,IAAI,MAAM,GAAG,MAAM,cAAc,OAAO,4EAA4E;AAC5H;AAEA,MAAM,mCAAmB,QAAA;AAEzB,SAAS,SAAS,KAA6B;AAC7C,QAAM,SA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ACA,YAC6B;AAC7B,QAAM,YAAY,iBAAiB,QAAQ,WAAW,WAAW;AACjE,QAAM,UAAU,eAAe,QAAQ,SAAS,WAAW;AAC3D,MAAI,CAAC,YAAA,KAAiB,SAAS,GAAG,EAAG,QAAO;AAE5C,QAAM,OAAO,QAAQ,KAAK,IAAI,CAAC,QAAQ;AACrC,UAAM,EAAE,SAAS,KAAA,IAAS,eAAe,KAAK,EAAE,SAAS,IAAI,SAAS,SAAS,KAAK,IAAI,MAAM;AAC9F,WAAO,EAAE,SAAS,MAAM,MAAM,IAAI,QAAQ,QAAQ,MAAM,MAAM,IAAI,MAAM,QAAQ,IAAI,OAAA;AAAA,EACtF,CAAC;AACD,QAAM,OAAO,cAAc,SAAS,CAAC,UAAU;AAC7C,UAAM,WAAW,YAAY,OAAO,WAAW,OAAO;AACtD,QAAI,YAAY,WAAY,YAAW,QAAQ;AAAA,EACjD,CAAC;AACD,MAAI;AACF,WAAO,MAAM,cAA2B,cAAc,EAAE,WAAW,SAAS,KAAA,GAAQ,YAAY;AAAA,EAClG,UAAA;AACE,SAAA;AAAA,EACF;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"connectOutbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectOutbox.ts"],"sourcesContent":["import { AxiosError, AxiosHeaders } from 'axios'\r\nimport type { AxiosAdapter, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { ErroBridge, onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoOutbox = 'outbox.send' | 'outbox.watch'\r\n\r\nconst WRITE_METHODS = ['post', 'put', 'patch', 'delete']\r\nconst BRIDGE_WAIT_MS = 30_000\r\n\r\nexport const OUTBOX_SAVED_MESSAGE = 'Guardado no telemóvel. Será enviado quando a ligação voltar.'\r\n\r\nexport type OutboxOptions = { storageId: string | undefined }\r\n\r\nexport type OutboxRequestOptions = { expiresAt?: string | Date }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n outbox?: true | OutboxRequestOptions\r\n }\r\n}\r\n\r\ntype OutboxReply =\r\n | { outcome: 'delivered' | 'rejected'; status: number; body: unknown }\r\n | { outcome: 'saved'; id: string }\r\n\r\nexport class OutboxSavedError extends Error {\r\n readonly outboxActionId: string | null\r\n\r\n constructor(outboxActionId: string | null) {\r\n super(OUTBOX_SAVED_MESSAGE)\r\n this.name = 'OutboxSavedError'\r\n this.outboxActionId = outboxActionId\r\n }\r\n}\r\n\r\nexport function isOutboxSaved(error: unknown): error is OutboxSavedError {\r\n return error instanceof OutboxSavedError\r\n}\r\n\r\nfunction stringHeaders(config: InternalAxiosRequestConfig): Record<string, string> {\r\n const headers: Record<string, string> = {}\r\n for (const [name, value] of Object.entries(AxiosHeaders.from(config.headers).toJSON())) {\r\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') headers[name] = String(value)\r\n }\r\n return headers\r\n}\r\n\r\nasync function replyOf(carga: unknown): Promise<OutboxReply> {\r\n try {\r\n return await pedirAoNativo<OutboxReply>('outbox.send', carga, BRIDGE_WAIT_MS)\r\n } catch (error) {\r\n if (error instanceof ErroBridge && error.codigo === 'expirou') throw new OutboxSavedError(null)\r\n throw error\r\n }\r\n}\r\n\r\nfunction expiryOf(config: InternalAxiosRequestConfig): string | undefined {\r\n const expiresAt = config.outbox === true ? undefined : config.outbox?.expiresAt\r\n return expiresAt instanceof Date ? expiresAt.toISOString() : expiresAt\r\n}\r\n\r\nfunction outboxAdapter(api: AxiosInstance, storageId: string): AxiosAdapter {\r\n return async (config) => {\r\n const { address, path } = addressAndPath(api, config)\r\n const reply = await replyOf({\r\n storageId,\r\n address,\r\n method: config.method,\r\n path,\r\n headers: stringHeaders(config),\r\n body: config.data,\r\n expiresAt: expiryOf(config),\r\n })\r\n if (reply.outcome === 'saved') throw new OutboxSavedError(reply.id)\r\n\r\n const response: AxiosResponse = {\r\n data: reply.body,\r\n status: reply.status,\r\n statusText: '',\r\n headers: {},\r\n config,\r\n request: {},\r\n }\r\n const accepted = config.validateStatus ? config.validateStatus(reply.status) : reply.outcome === 'delivered'\r\n if (accepted) return response\r\n throw new AxiosError(\r\n `Request failed with status code ${reply.status}`,\r\n reply.status >= 500 ? AxiosError.ERR_BAD_RESPONSE : AxiosError.ERR_BAD_REQUEST,\r\n config,\r\n response.request,\r\n response,\r\n )\r\n }\r\n}\r\n\r\nfunction goesThroughOutbox(config: InternalAxiosRequestConfig): boolean {\r\n if (!config.outbox) return false\r\n const method = (config.method ?? 'get').toLowerCase()\r\n if (!WRITE_METHODS.includes(method)) {\r\n throw new Error(`connectOutbox: only writes go through the Outbox, and this ${method.toUpperCase()} is marked with outbox`)\r\n }\r\n const data: unknown = config.data\r\n if (data instanceof FormData || data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {\r\n throw new Error('connectOutbox: files do not go through the Outbox yet; send this write without outbox')\r\n }\r\n return dentroDaApp()\r\n}\r\n\r\nexport type OutboxState = 'pending' | 'sending' | 'delivered' | 'rejected' | 'expired' | 'deleted'\r\n\r\nexport type OutboxActionStatus = { id: string; state: OutboxState; createdAt?: string; reason?: string }\r\n\r\nexport type OutboxWatch = { actions: OutboxActionStatus[]; stop: () => void }\r\n\r\nconst WATCH_WAIT_MS = 10_000\r\n\r\nfunction statusFor(carga: unknown, storageId: string): OutboxActionStatus | null {\r\n if (typeof carga !== 'object' || carga === null) return null\r\n const { storageId: of, ...status } = carga as OutboxActionStatus & { storageId?: string }\r\n return of === storageId ? status : null\r\n}\r\n\r\nexport async function watchOutbox(options: OutboxOptions, onChange: (status: OutboxActionStatus) => void): Promise<OutboxWatch> {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n if (!dentroDaApp()) return { actions: [], stop: () => undefined }\r\n const stop = onNativeEvent('outbox', (carga) => {\r\n const status = statusFor(carga, storageId)\r\n if (status) onChange(status)\r\n })\r\n try {\r\n const actions = await pedirAoNativo<OutboxActionStatus[]>('outbox.watch', { storageId }, WATCH_WAIT_MS)\r\n return { actions, stop }\r\n } catch (error) {\r\n stop()\r\n throw error\r\n }\r\n}\r\n\r\nexport function connectOutbox(api: AxiosInstance, options: OutboxOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n const adapter = outboxAdapter(api, storageId)\r\n api.interceptors.request.use((config) => {\r\n if (goesThroughOutbox(config)) config.adapter = adapter\r\n return config\r\n })\r\n}\r\n"],"names":[],"mappings":";;;;;AASA,MAAM,gBAAgB,CAAC,QAAQ,OAAO,SAAS,QAAQ;AACvD,MAAM,iBAAiB;AAEhB,MAAM,uBAAuB;AAgB7B,MAAM,yBAAyB,MAAM;AAAA,EAG1C,YAAY,gBAA+B;AACzC,UAAM,oBAAoB;AAC1B,SAAK,OAAO;AACZ,SAAK,iBAAiB;AAAA,EACxB;AACF;AAEO,SAAS,cAAc,OAA2C;AACvE,SAAO,iBAAiB;AAC1B;AAEA,SAAS,cAAc,QAA4D;AACjF,QAAM,UAAkC,CAAA;AACxC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,aAAa,KAAK,OAAO,OAAO,EAAE,OAAA,CAAQ,GAAG;AACtF,QAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,SAAQ,IAAI,IAAI,OAAO,KAAK;AAAA,EACxH;AACA,SAAO;AACT;AAEA,eAAe,QAAQ,OAAsC;AAC3D,MAAI;AACF,WAAO,MAAM,cAA2B,eAAe,OAAO,cAAc;AAAA,EAC9E,SAAS,OAAO;AACd,QAAI,iBAAiB,cAAc,MAAM,WAAW,UAAW,OAAM,IAAI,iBAAiB,IAAI;AAC9F,UAAM;AAAA,EACR;AACF;AAEA,SAAS,SAAS,QAAwD;AACxE,QAAM,YAAY,OAAO,WAAW,OAAO,SAAY,OAAO,QAAQ;AACtE,SAAO,qBAAqB,OAAO,UAAU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B,SAAS,UAAU,OAAgB,WAA8C;AAC/E,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,EAAE,WAAW,IAAI,GAAG,WAAW;AACrC,SAAO,OAAO,YAAY,SAAS;AACrC;AAEA,eAAsB,YAAY,SAAwB,UAAsE;AAC9H,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,MAAI,CAAC,YAAA,EAAe,QAAO,EAAE,SAAS,IAAI,MAAM,MAAM,OAAA;AACtD,QAAM,OAAO,cAAc,UAAU,CAAC,UAAU;AAC9C,UAAM,SAAS,UAAU,OAAO,SAAS;AACzC,QAAI,iBAAiB,MAAM;AAAA,EAC7B,CAAC;AACD,MAAI;AACF,UAAM,UAAU,MAAM,cAAoC,gBAAgB,EAAE,UAAA,GAAa,aAAa;AACtG,WAAO,EAAE,SAAS,KAAA;AAAA,EACpB,SAAS,OAAO;AACd,SAAA;AACA,UAAM;AAAA,EACR;AACF;AAEO,SAAS,cAAc,KAAoB,SAA8B;AAC9E,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,QAAM,UAAU,cAAc,KAAK,SAAS;AAC5C,MAAI,aAAa,QAAQ,IAAI,CAAC,WAAW;AACvC,QAAI,kBAAkB,MAAM,EAAG,QAAO,UAAU;AAChD,WAAO;AAAA,EACT,CAAC;AACH;"}
1
+ {"version":3,"file":"connectOutbox.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/connectOutbox.ts"],"sourcesContent":["import { AxiosError, AxiosHeaders } from 'axios'\r\nimport type { AxiosAdapter, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'\r\nimport { ErroBridge, onNativeEvent, pedirAoNativo } from './bridge'\r\nimport { dentroDaApp } from './dentroDaApp'\r\nimport { addressAndPath } from './requestAddress'\r\nimport { checkedStorageId } from './storageId'\r\n\r\nexport type PedidoOutbox = 'outbox.send' | 'outbox.watch'\r\n\r\nconst WRITE_METHODS = ['post', 'put', 'patch', 'delete']\r\nconst BRIDGE_WAIT_MS = 30_000\r\n\r\nexport const OUTBOX_SAVED_MESSAGE = 'Guardado no telemóvel. Será enviado quando a ligação voltar.'\r\n\r\nexport type OutboxOptions = { storageId: string | undefined }\r\n\r\nexport type OutboxRequestOptions = { expiresAt?: string | Date }\r\n\r\ndeclare module 'axios' {\r\n interface AxiosRequestConfig {\r\n outbox?: true | OutboxRequestOptions\r\n }\r\n}\r\n\r\ntype OutboxReply =\r\n | { outcome: 'delivered' | 'rejected'; status: number; body: unknown }\r\n | { outcome: 'saved'; id: string }\r\n\r\nexport class OutboxSavedError extends Error {\r\n readonly outboxActionId: string | null\r\n\r\n constructor(outboxActionId: string | null) {\r\n super(OUTBOX_SAVED_MESSAGE)\r\n this.name = 'OutboxSavedError'\r\n this.outboxActionId = outboxActionId\r\n }\r\n}\r\n\r\nexport function isOutboxSaved(error: unknown): error is OutboxSavedError {\r\n return error instanceof OutboxSavedError\r\n}\r\n\r\nfunction stringHeaders(config: InternalAxiosRequestConfig): Record<string, string> {\r\n const headers: Record<string, string> = {}\r\n for (const [name, value] of Object.entries(AxiosHeaders.from(config.headers).toJSON())) {\r\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') headers[name] = String(value)\r\n }\r\n return headers\r\n}\r\n\r\nasync function replyOf(carga: unknown): Promise<OutboxReply> {\r\n try {\r\n return await pedirAoNativo<OutboxReply>('outbox.send', carga, BRIDGE_WAIT_MS)\r\n } catch (error) {\r\n if (error instanceof ErroBridge && error.codigo === 'expirou') throw new OutboxSavedError(null)\r\n throw error\r\n }\r\n}\r\n\r\nfunction expiryOf(config: InternalAxiosRequestConfig): string | undefined {\r\n const expiresAt = config.outbox === true ? undefined : config.outbox?.expiresAt\r\n return expiresAt instanceof Date ? expiresAt.toISOString() : expiresAt\r\n}\r\n\r\nfunction outboxAdapter(api: AxiosInstance, storageId: string): AxiosAdapter {\r\n return async (config) => {\r\n const { address, path } = addressAndPath(api, config)\r\n const reply = await replyOf({\r\n storageId,\r\n address,\r\n method: config.method,\r\n path,\r\n headers: stringHeaders(config),\r\n body: config.data,\r\n expiresAt: expiryOf(config),\r\n })\r\n if (reply.outcome === 'saved') throw new OutboxSavedError(reply.id)\r\n\r\n const response: AxiosResponse = {\r\n data: reply.body,\r\n status: reply.status,\r\n statusText: '',\r\n headers: {},\r\n config,\r\n request: {},\r\n }\r\n const accepted = config.validateStatus ? config.validateStatus(reply.status) : reply.outcome === 'delivered'\r\n if (accepted) return response\r\n throw new AxiosError(\r\n `Request failed with status code ${reply.status}`,\r\n reply.status >= 500 ? AxiosError.ERR_BAD_RESPONSE : AxiosError.ERR_BAD_REQUEST,\r\n config,\r\n response.request,\r\n response,\r\n )\r\n }\r\n}\r\n\r\nfunction goesThroughOutbox(config: InternalAxiosRequestConfig): boolean {\r\n if (!config.outbox) return false\r\n const method = (config.method ?? 'get').toLowerCase()\r\n if (!WRITE_METHODS.includes(method)) {\r\n throw new Error(`connectOutbox: only writes go through the Outbox, and this ${method.toUpperCase()} is marked with outbox`)\r\n }\r\n const data: unknown = config.data\r\n if (data instanceof FormData || data instanceof Blob || data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {\r\n throw new Error('connectOutbox: files do not go through the Outbox yet; send this write without outbox')\r\n }\r\n return dentroDaApp()\r\n}\r\n\r\nexport type OutboxState = 'pending' | 'sending' | 'delivered' | 'rejected' | 'expired' | 'deleted'\r\n\r\nexport type OutboxActionStatus = {\r\n id: string\r\n state: OutboxState\r\n createdAt?: string\r\n reason?: string\r\n method?: string\r\n path?: string\r\n}\r\n\r\nexport type OutboxWatch = { actions: OutboxActionStatus[]; stop: () => void }\r\n\r\nconst WATCH_WAIT_MS = 10_000\r\n\r\nfunction statusFor(carga: unknown, storageId: string): OutboxActionStatus | null {\r\n if (typeof carga !== 'object' || carga === null) return null\r\n const { storageId: of, ...status } = carga as OutboxActionStatus & { storageId?: string }\r\n return of === storageId ? status : null\r\n}\r\n\r\nexport async function watchOutbox(options: OutboxOptions, onChange: (status: OutboxActionStatus) => void): Promise<OutboxWatch> {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n if (!dentroDaApp()) return { actions: [], stop: () => undefined }\r\n const stop = onNativeEvent('outbox', (carga) => {\r\n const status = statusFor(carga, storageId)\r\n if (status) onChange(status)\r\n })\r\n try {\r\n const actions = await pedirAoNativo<OutboxActionStatus[]>('outbox.watch', { storageId }, WATCH_WAIT_MS)\r\n return { actions, stop }\r\n } catch (error) {\r\n stop()\r\n throw error\r\n }\r\n}\r\n\r\nexport function connectOutbox(api: AxiosInstance, options: OutboxOptions): void {\r\n const storageId = checkedStorageId(options.storageId, 'connectOutbox')\r\n const adapter = outboxAdapter(api, storageId)\r\n api.interceptors.request.use((config) => {\r\n if (goesThroughOutbox(config)) config.adapter = adapter\r\n return config\r\n })\r\n}\r\n"],"names":[],"mappings":";;;;;AASA,MAAM,gBAAgB,CAAC,QAAQ,OAAO,SAAS,QAAQ;AACvD,MAAM,iBAAiB;AAEhB,MAAM,uBAAuB;AAgB7B,MAAM,yBAAyB,MAAM;AAAA,EAG1C,YAAY,gBAA+B;AACzC,UAAM,oBAAoB;AAC1B,SAAK,OAAO;AACZ,SAAK,iBAAiB;AAAA,EACxB;AACF;AAEO,SAAS,cAAc,OAA2C;AACvE,SAAO,iBAAiB;AAC1B;AAEA,SAAS,cAAc,QAA4D;AACjF,QAAM,UAAkC,CAAA;AACxC,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,aAAa,KAAK,OAAO,OAAO,EAAE,OAAA,CAAQ,GAAG;AACtF,QAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,SAAQ,IAAI,IAAI,OAAO,KAAK;AAAA,EACxH;AACA,SAAO;AACT;AAEA,eAAe,QAAQ,OAAsC;AAC3D,MAAI;AACF,WAAO,MAAM,cAA2B,eAAe,OAAO,cAAc;AAAA,EAC9E,SAAS,OAAO;AACd,QAAI,iBAAiB,cAAc,MAAM,WA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O;AAC7B,MAAI,gBAAgB,YAAY,gBAAgB,QAAQ,gBAAgB,eAAe,YAAY,OAAO,IAAI,GAAG;AAC/G,UAAM,IAAI,MAAM,uFAAuF;AAAA,EACzG;AACA,SAAO,YAAA;AACT;AAeA,MAAM,gBAAgB;AAEtB,SAAS,UAAU,OAAgB,WAA8C;AAC/E,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,QAAM,EAAE,WAAW,IAAI,GAAG,WAAW;AACrC,SAAO,OAAO,YAAY,SAAS;AACrC;AAEA,eAAsB,YAAY,SAAwB,UAAsE;AAC9H,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,MAAI,CAAC,YAAA,EAAe,QAAO,EAAE,SAAS,IAAI,MAAM,MAAM,OAAA;AACtD,QAAM,OAAO,cAAc,UAAU,CAAC,UAAU;AAC9C,UAAM,SAAS,UAAU,OAAO,SAAS;AACzC,QAAI,iBAAiB,MAAM;AAAA,EAC7B,CAAC;AACD,MAAI;AACF,UAAM,UAAU,MAAM,cAAoC,gBAAgB,EAAE,UAAA,GAAa,aAAa;AACtG,WAAO,EAAE,SAAS,KAAA;AAAA,EACpB,SAAS,OAAO;AACd,SAAA;AACA,UAAM;AAAA,EACR;AACF;AAEO,SAAS,cAAc,KAAoB,SAA8B;AAC9E,QAAM,YAAY,iBAAiB,QAAQ,WAAW,eAAe;AACrE,QAAM,UAAU,cAAc,KAAK,SAAS;AAC5C,MAAI,aAAa,QAAQ,IAAI,CAAC,WAAW;AACvC,QAAI,kBAAkB,MAAM,EAAG,QAAO,UAAU;AAChD,WAAO;AAAA,EACT,CAAC;AACH;"}
@@ -0,0 +1,103 @@
1
+ import { useState, useEffect, useMemo } from "react";
2
+ import { watchInbox, inboxStatus } from "./connectInbox.js";
3
+ import { watchOutbox } from "./connectOutbox.js";
4
+ import { dentroDaApp } from "./dentroDaApp.js";
5
+ const STILL_WAITING = ["pending", "sending", "rejected"];
6
+ async function statusOrNothing(storageId, inboxId) {
7
+ try {
8
+ return await inboxStatus({ storageId, inboxId });
9
+ } catch {
10
+ return null;
11
+ }
12
+ }
13
+ function latest(dates) {
14
+ const known = dates.filter((date) => date !== null);
15
+ if (!known.length) return null;
16
+ return known.reduce((a, b) => a > b ? a : b);
17
+ }
18
+ function mergedAction(actions, change) {
19
+ const known = actions.find((action) => action.id === change.id);
20
+ const others = actions.filter((action) => action.id !== change.id);
21
+ if (!STILL_WAITING.includes(change.state)) return others;
22
+ return [...others, { ...known, ...change, method: change.method ?? known?.method, path: change.path ?? known?.path }];
23
+ }
24
+ function useOfflineBoxes({ storageId, inboxIds }) {
25
+ const inApp = dentroDaApp();
26
+ const inboxKey = inboxIds.join(",");
27
+ const [saved, setSaved] = useState({});
28
+ const [live, setLive] = useState({});
29
+ const [actions, setActions] = useState([]);
30
+ useEffect(() => {
31
+ if (!inApp) return;
32
+ let current = true;
33
+ const ids = inboxKey.split(",").filter(Boolean);
34
+ const load = async (inboxId) => {
35
+ const status = await statusOrNothing(storageId, inboxId);
36
+ if (current && status) setSaved((before) => ({ ...before, [inboxId]: status }));
37
+ };
38
+ for (const inboxId of ids) void load(inboxId);
39
+ const stop = watchInbox({ storageId }, (event) => {
40
+ if (!ids.includes(event.inboxId)) return;
41
+ if (event.finishedAt === null) {
42
+ setLive((before) => ({ ...before, [event.inboxId]: event }));
43
+ return;
44
+ }
45
+ setLive((before) => {
46
+ const rest = { ...before };
47
+ delete rest[event.inboxId];
48
+ return rest;
49
+ });
50
+ void load(event.inboxId);
51
+ });
52
+ return () => {
53
+ current = false;
54
+ stop();
55
+ };
56
+ }, [inApp, storageId, inboxKey]);
57
+ useEffect(() => {
58
+ if (!inApp) return;
59
+ let current = true;
60
+ let stop = () => void 0;
61
+ const start = async () => {
62
+ try {
63
+ const watch = await watchOutbox({ storageId }, (change) => {
64
+ if (current) setActions((before) => mergedAction(before, change));
65
+ });
66
+ stop = watch.stop;
67
+ if (!current) {
68
+ stop();
69
+ return;
70
+ }
71
+ setActions(watch.actions.filter((action) => STILL_WAITING.includes(action.state)));
72
+ } catch {
73
+ setActions([]);
74
+ }
75
+ };
76
+ void start();
77
+ return () => {
78
+ current = false;
79
+ stop();
80
+ };
81
+ }, [inApp, storageId]);
82
+ return useMemo(() => {
83
+ if (!inApp) return null;
84
+ const ids = inboxKey.split(",").filter(Boolean);
85
+ const parts = [];
86
+ for (const inboxId of ids) {
87
+ const part = live[inboxId] ?? saved[inboxId];
88
+ if (part) parts.push(part);
89
+ }
90
+ const inbox = {
91
+ total: parts.reduce((sum, part) => sum + part.total, 0),
92
+ ready: parts.reduce((sum, part) => sum + part.ready, 0),
93
+ failed: parts.reduce((sum, part) => sum + part.failed, 0),
94
+ finishedAt: latest(ids.map((inboxId) => saved[inboxId]?.finishedAt ?? null)),
95
+ saved: [...new Set(ids.flatMap((inboxId) => saved[inboxId]?.saved ?? []))]
96
+ };
97
+ return { inbox, downloading: ids.some((inboxId) => inboxId in live), waiting: actions };
98
+ }, [inApp, inboxKey, live, saved, actions]);
99
+ }
100
+ export {
101
+ useOfflineBoxes
102
+ };
103
+ //# sourceMappingURL=useOfflineBoxes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOfflineBoxes.js","sources":["../../../../../src/v1/capabilities/onepoint-rn/useOfflineBoxes.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\r\nimport { inboxStatus, watchInbox, type InboxEvent, type InboxProgress, type InboxStatus } from './connectInbox'\r\nimport { watchOutbox, type OutboxActionStatus } from './connectOutbox'\r\nimport { dentroDaApp } from './dentroDaApp'\r\n\r\nexport type OfflineBoxesOptions = { storageId: string | undefined; inboxIds: string[] }\r\n\r\nexport type OfflineBoxesState = {\r\n inbox: InboxStatus & { saved: string[] }\r\n downloading: boolean\r\n waiting: OutboxActionStatus[]\r\n}\r\n\r\nconst STILL_WAITING: OutboxActionStatus['state'][] = ['pending', 'sending', 'rejected']\r\n\r\nasync function statusOrNothing(storageId: string | undefined, inboxId: string): Promise<InboxStatus | null> {\r\n try {\r\n return await inboxStatus({ storageId, inboxId })\r\n } catch {\r\n return null\r\n }\r\n}\r\n\r\nfunction latest(dates: (string | null)[]): string | null {\r\n const known = dates.filter((date): date is string => date !== null)\r\n if (!known.length) return null\r\n return known.reduce((a, b) => (a > b ? a : b))\r\n}\r\n\r\nfunction mergedAction(actions: OutboxActionStatus[], change: OutboxActionStatus): OutboxActionStatus[] {\r\n const known = actions.find((action) => action.id === change.id)\r\n const others = actions.filter((action) => action.id !== change.id)\r\n if (!STILL_WAITING.includes(change.state)) return others\r\n return [...others, { ...known, ...change, method: change.method ?? known?.method, path: change.path ?? known?.path }]\r\n}\r\n\r\nexport function useOfflineBoxes({ storageId, inboxIds }: OfflineBoxesOptions): OfflineBoxesState | null {\r\n const inApp = dentroDaApp()\r\n const inboxKey = inboxIds.join(',')\r\n const [saved, setSaved] = useState<Record<string, InboxStatus>>({})\r\n const [live, setLive] = useState<Record<string, InboxEvent>>({})\r\n const [actions, setActions] = useState<OutboxActionStatus[]>([])\r\n\r\n useEffect(() => {\r\n if (!inApp) return\r\n let current = true\r\n const ids = inboxKey.split(',').filter(Boolean)\r\n const load = async (inboxId: string) => {\r\n const status = await statusOrNothing(storageId, inboxId)\r\n if (current && status) setSaved((before) => ({ ...before, [inboxId]: status }))\r\n }\r\n for (const inboxId of ids) void load(inboxId)\r\n const stop = watchInbox({ storageId }, (event) => {\r\n if (!ids.includes(event.inboxId)) return\r\n if (event.finishedAt === null) {\r\n setLive((before) => ({ ...before, [event.inboxId]: event }))\r\n return\r\n }\r\n setLive((before) => {\r\n const rest = { ...before }\r\n delete rest[event.inboxId]\r\n return rest\r\n })\r\n void load(event.inboxId)\r\n })\r\n return () => {\r\n current = false\r\n stop()\r\n }\r\n }, [inApp, storageId, inboxKey])\r\n\r\n useEffect(() => {\r\n if (!inApp) return\r\n let current = true\r\n let stop: () => void = () => undefined\r\n const start = async () => {\r\n try {\r\n const watch = await watchOutbox({ storageId }, (change) => {\r\n if (current) setActions((before) => mergedAction(before, change))\r\n })\r\n stop = watch.stop\r\n if (!current) {\r\n stop()\r\n return\r\n }\r\n setActions(watch.actions.filter((action) => STILL_WAITING.includes(action.state)))\r\n } catch {\r\n setActions([])\r\n }\r\n }\r\n void start()\r\n return () => {\r\n current = false\r\n stop()\r\n }\r\n }, [inApp, storageId])\r\n\r\n return useMemo(() => {\r\n if (!inApp) return null\r\n const ids = inboxKey.split(',').filter(Boolean)\r\n const parts: InboxProgress[] = []\r\n for (const inboxId of ids) {\r\n const part = live[inboxId] ?? saved[inboxId]\r\n if (part) parts.push(part)\r\n }\r\n const inbox = {\r\n total: parts.reduce((sum, part) => sum + part.total, 0),\r\n ready: parts.reduce((sum, part) => sum + part.ready, 0),\r\n failed: parts.reduce((sum, part) => sum + part.failed, 0),\r\n finishedAt: latest(ids.map((inboxId) => saved[inboxId]?.finishedAt ?? null)),\r\n saved: [...new Set(ids.flatMap((inboxId) => saved[inboxId]?.saved ?? []))],\r\n }\r\n return { inbox, downloading: ids.some((inboxId) => inboxId in live), waiting: actions }\r\n }, [inApp, inboxKey, live, saved, actions])\r\n}\r\n"],"names":[],"mappings":";;;;AAaA,MAAM,gBAA+C,CAAC,WAAW,WAAW,UAAU;AAEtF,eAAe,gBAAgB,WAA+B,SAA8C;AAC1G,MAAI;AACF,WAAO,MAAM,YAAY,EAAE,WAAW,SAAS;AAAA,EACjD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,OAAO,OAAyC;AACvD,QAAM,QAAQ,MAAM,OAAO,CAAC,SAAyB,SAAS,IAAI;AAClE,MAAI,CAAC,MAAM,OAAQ,QAAO;AAC1B,SAAO,MAAM,OAAO,CAAC,GAAG,MAAO,IAAI,IAAI,IAAI,CAAE;AAC/C;AAEA,SAAS,aAAa,SAA+B,QAAkD;AACrG,QAAM,QAAQ,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,OAAO,EAAE;AAC9D,QAAM,SAAS,QAAQ,OAAO,CAAC,WAAW,OA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IAAI,CAAC;AAAA,MAC3E,OAAO,CAAC,GAAG,IAAI,IAAI,IAAI,QAAQ,CAAC,YAAY,MAAM,OAAO,GAAG,SAAS,CAAA,CAAE,CAAC,CAAC;AAAA,IAAA;AAE3E,WAAO,EAAE,OAAO,aAAa,IAAI,KAAK,CAAC,YAAY,WAAW,IAAI,GAAG,SAAS,QAAA;AAAA,EAChF,GAAG,CAAC,OAAO,UAAU,MAAM,OAAO,OAAO,CAAC;AAC5C;"}
@@ -0,0 +1,78 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useState, useRef, useEffect } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { useOfflineBoxes } from "../../../capabilities/onepoint-rn/useOfflineBoxes.js";
5
+ import { useDialogContainer } from "../../overlays/Dialog/Dialog.js";
6
+ import { OfflineBoxesIcon } from "./OfflineBoxesIcon.js";
7
+ import OfflineBoxesView, { DEFAULT_OFFLINE_BOXES_LABELS, percentOf, toSendOf, filled } from "./OfflineBoxesView.js";
8
+ function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, describeSaved, describeWrite, labels, className = "" }) {
9
+ const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels };
10
+ const state = useOfflineBoxes({ storageId, inboxIds });
11
+ const [open, setOpen] = useState(false);
12
+ const triggerRef = useRef(null);
13
+ const dialogContainer = useDialogContainer();
14
+ const close = () => {
15
+ setOpen(false);
16
+ triggerRef.current?.focus();
17
+ };
18
+ useEffect(() => {
19
+ if (!open) return;
20
+ const escape = (e) => {
21
+ if (e.key !== "Escape") return;
22
+ setOpen(false);
23
+ triggerRef.current?.focus();
24
+ };
25
+ document.addEventListener("keydown", escape);
26
+ return () => document.removeEventListener("keydown", escape);
27
+ }, [open]);
28
+ if (!state) return null;
29
+ const pct = percentOf(state);
30
+ const pctLabel = pct === null ? "–" : `${pct}%`;
31
+ const toSend = toSendOf(state);
32
+ return /* @__PURE__ */ jsxs("div", { className: `relative inline-flex shrink-0 ${className}`, children: [
33
+ /* @__PURE__ */ jsxs(
34
+ "button",
35
+ {
36
+ ref: triggerRef,
37
+ type: "button",
38
+ "aria-haspopup": "dialog",
39
+ "aria-expanded": open,
40
+ "aria-label": `${L.title}: ${pctLabel} · ${filled(L.toSend, { n: toSend })}`,
41
+ onClick: (e) => {
42
+ e.stopPropagation();
43
+ setOpen(true);
44
+ },
45
+ className: "flex min-h-11 cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent px-1.5 text-left hover:bg-slate-100 dark:hover:bg-slate-800",
46
+ children: [
47
+ /* @__PURE__ */ jsx(OfflineBoxesIcon, { size: 28 }),
48
+ /* @__PURE__ */ jsxs("span", { className: "flex flex-col leading-tight whitespace-nowrap", children: [
49
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300", children: pctLabel }),
50
+ toSend > 0 && /* @__PURE__ */ jsx("span", { className: "text-[11px] font-bold text-orange-700 dark:text-orange-300", children: filled(L.toSend, { n: toSend }) })
51
+ ] })
52
+ ]
53
+ }
54
+ ),
55
+ open && createPortal(
56
+ /* @__PURE__ */ jsx(
57
+ OfflineBoxesView,
58
+ {
59
+ state,
60
+ labels: L,
61
+ subtitle,
62
+ address,
63
+ onRefresh,
64
+ onBack: close,
65
+ describeSaved,
66
+ describeWrite
67
+ }
68
+ ),
69
+ dialogContainer ?? document.body
70
+ )
71
+ ] });
72
+ }
73
+ export {
74
+ DEFAULT_OFFLINE_BOXES_LABELS,
75
+ OfflineBoxes,
76
+ OfflineBoxes as default
77
+ };
78
+ //# sourceMappingURL=OfflineBoxes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfflineBoxes.js","sources":["../../../../../../src/v1/components/feedback/OfflineBoxes/OfflineBoxes.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\r\nimport { createPortal } from 'react-dom'\r\nimport { useOfflineBoxes } from '../../../capabilities/onepoint-rn/useOfflineBoxes'\r\nimport { useDialogContainer } from '../../overlays/Dialog/Dialog'\r\nimport OfflineBoxesIcon from './OfflineBoxesIcon'\r\nimport OfflineBoxesView, {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n filled,\r\n percentOf,\r\n toSendOf,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedSummary,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\r\n\r\nexport {\r\n DEFAULT_OFFLINE_BOXES_LABELS,\r\n type OfflineBoxesLabels,\r\n type OfflineSavedItem,\r\n type OfflineSavedSummary,\r\n type OfflineSavedTag,\r\n type OfflineWrite,\r\n type OfflineWriteDescription,\r\n} from './OfflineBoxesView'\r\n\r\nexport interface OfflineBoxesProps {\r\n /** O mesmo `storageId` do `connectOutbox` e do `connectInbox`. */\r\n storageId: string | undefined\r\n /** As inboxes que este sítio mostra (ex: `['ajustes']`). Somam-se. */\r\n inboxIds: string[]\r\n /** O que o botão Atualizar faz (ex: chamar o `syncInbox`). Sem ele, não há botão. */\r\n onRefresh?: () => void\r\n /** Endereço da API (`api.defaults.baseURL`): os endereços chegam ao `describeSaved` e ao `describeWrite` sem ele à frente. */\r\n address?: string\r\n /** Linha ao lado do título na vista (ex: o nome do ecrã). */\r\n subtitle?: string\r\n /** Transforma os endereços guardados nas linhas que se mostram (ex: uma por OT). Sem ele, mostra os endereços. */\r\n describeSaved?: (paths: string[]) => OfflineSavedSummary\r\n /** Diz o que é cada escrita por enviar (ex: \"Ajuste guardado\"). Sem ele, ou se devolver `null`, mostra método e endereço. */\r\n describeWrite?: (write: OfflineWrite) => OfflineWriteDescription | null\r\n labels?: Partial<OfflineBoxesLabels>\r\n className?: string\r\n}\r\n\r\n/**\r\n * O que a app tem guardado para usar sem rede (Inbox, verde) e o que tem por\r\n * enviar (Outbox, laranja), num ícone que se põe onde se quiser (ex: à\r\n * direita do título). Ao lado, a percentagem guardada, que sobe enquanto a\r\n * descarga corre, e quantas escritas faltam enviar. Tocar abre a vista inteira\r\n * com o detalhe. Fora da app OnePoint não aparece.\r\n */\r\nexport default function OfflineBoxes({ storageId, inboxIds, onRefresh, address, subtitle, describeSaved, describeWrite, labels, className = '' }: OfflineBoxesProps) {\r\n const L = { ...DEFAULT_OFFLINE_BOXES_LABELS, ...labels }\r\n const state = useOfflineBoxes({ storageId, inboxIds })\r\n const [open, setOpen] = useState(false)\r\n const triggerRef = useRef<HTMLButtonElement>(null)\r\n const dialogContainer = useDialogContainer()\r\n\r\n const close = () => {\r\n setOpen(false)\r\n triggerRef.current?.focus()\r\n }\r\n\r\n useEffect(() => {\r\n if (!open) return\r\n const escape = (e: KeyboardEvent) => {\r\n if (e.key !== 'Escape') return\r\n setOpen(false)\r\n triggerRef.current?.focus()\r\n }\r\n document.addEventListener('keydown', escape)\r\n return () => document.removeEventListener('keydown', escape)\r\n }, [open])\r\n\r\n if (!state) return null\r\n\r\n const pct = percentOf(state)\r\n const pctLabel = pct === null ? '–' : `${pct}%`\r\n const toSend = toSendOf(state)\r\n\r\n return (\r\n <div className={`relative inline-flex shrink-0 ${className}`}>\r\n <button\r\n ref={triggerRef}\r\n type=\"button\"\r\n aria-haspopup=\"dialog\"\r\n aria-expanded={open}\r\n aria-label={`${L.title}: ${pctLabel} · ${filled(L.toSend, { n: toSend })}`}\r\n onClick={(e) => {\r\n e.stopPropagation()\r\n setOpen(true)\r\n }}\r\n className=\"flex min-h-11 cursor-pointer items-center gap-1.5 rounded-xl border-0 bg-transparent px-1.5 text-left hover:bg-slate-100 dark:hover:bg-slate-800\"\r\n >\r\n <OfflineBoxesIcon size={28} />\r\n <span className=\"flex flex-col leading-tight whitespace-nowrap\">\r\n <span className=\"text-xs font-extrabold tabular-nums text-emerald-700 dark:text-emerald-300\">{pctLabel}</span>\r\n {toSend > 0 && <span className=\"text-[11px] font-bold text-orange-700 dark:text-orange-300\">{filled(L.toSend, { n: toSend })}</span>}\r\n </span>\r\n </button>\r\n {open &&\r\n createPortal(\r\n <OfflineBoxesView\r\n state={state}\r\n labels={L}\r\n subtitle={subtitle}\r\n address={address}\r\n onRefresh={onRefresh}\r\n onBack={close}\r\n describeSaved={describeSaved}\r\n describeWrite={describeWrite}\r\n />,\r\n dialogContainer ?? document.body,\r\n )}\r\n </div>\r\n )\r\n}\r\n\r\nexport { OfflineBoxes }\r\n"],"names":[],"mappings":";;;;;;;AAoDA,SAAwB,aAAa,EAAE,WAAW,UAAU,WAAW,SAAS,UAAU,eAAe,eAAe,QAAQ,YAAY,GAAA,GAAyB;AACnK,QAAM,IAAI,EAAE,GAAG,8BAA8B,GAAG,OAAA;AAChD,QAAM,QAAQ,gBAAgB,EAAE,WAAW,UAAU;AACrD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,aAAa,OAA0B,IAAI;AACjD,QAAM,kBAAkB,mBAAA;AAExB,QAAM,QAAQ,MAAM;AAClB,YAAQ,KAAK;AACb,eAAW,SAAS,MAAA;AAAA,EACtB;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,KAAM;AACX,UAAM,SAAS,CAAC,MAAqB;AACnC,UAAI,EAAE,QAAQ,SAAU;AACxB,cAAQ,KAAK;AACb,iBAAW,SAAS,MAAA;AAAA,IACtB;AACA,aAAS,iBAAiB,WAAW,MAAM;AAC3C,WAAO,MAAM,SAAS,oBAAoB,WAAW,MAAM;AAAA,EAC7D,GAAG,CAAC,IAAI,CAAC;AAET,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,MAAM,UAAU,KAAK;AAC3B,QAAM,WAAW,QAAQ,OAAO,MAAM,GAAG,GAAG;AAC5C,QAAM,SAAS,SAAS,KAAK;AAE7B,SACE,qBAAC,OAAA,EAAI,WAAW,iCAAiC,SAAS,IACxD,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,MAAK;AAAA,QACL,iBAAc;AAAA,QACd,iBAAe;AAAA,QACf,cAAY,GAAG,EAAE,KAAK,KAAK,QAAQ,MAAM,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAA,CAAQ,CAAC;AAAA,QACxE,SAAS,CAAC,MAAM;AACd,YAAE,gBAAA;AACF,kBAAQ,IAAI;AAAA,QACd;AAAA,QACA,WAAU;AAAA,QAEV,UAAA;AAAA,UAAA,oBAAC,kBAAA,EAAiB,MAAM,GAAA,CAAI;AAAA,UAC5B,qBAAC,QAAA,EAAK,WAAU,iDACd,UAAA;AAAA,YAAA,oBAAC,QAAA,EAAK,WAAU,8EAA8E,UAAA,UAAS;AAAA,YACtG,SAAS,KAAK,oBAAC,QAAA,EAAK,WAAU,8DAA8D,UAAA,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAA,CAAQ,EAAA,CAAE;AAAA,UAAA,EAAA,CAC/H;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,IAED,QACC;AAAA,MACE;AAAA,QAAC;AAAA,QAAA;AAAA,UACC;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,UACA;AAAA,QAAA;AAAA,MAAA;AAAA,MAEF,mBAAmB,SAAS;AAAA,IAAA;AAAA,EAC9B,GACJ;AAEJ;"}
@@ -0,0 +1,86 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ const GREEN = "#19C99B";
4
+ const ORANGE = "#EA6A12";
5
+ const FRONT = "M4 33H20L23.5 40H40.5L44 33H60V48C60 52 57.6 55 53.5 55H10.5C6.4 55 4 52 4 48Z";
6
+ const LIP = "M4 33H20L23.5 40H40.5L44 33H60L56.8 30.4H43.4L40 37.4H24L20.6 30.4H7.2Z";
7
+ const RIM = "M13 11H51L60 33H4Z";
8
+ function OfflineBoxesIcon({ size = 28, className = "" }) {
9
+ const id = useId().replace(/[^a-zA-Z0-9]/g, "");
10
+ const ref = (name) => `${name}${id}`;
11
+ const url = (name) => `url(#${ref(name)})`;
12
+ return /* @__PURE__ */ jsxs("svg", { width: size, height: size, viewBox: "0 0 64 64", "aria-hidden": "true", className, children: [
13
+ /* @__PURE__ */ jsxs("defs", { children: [
14
+ /* @__PURE__ */ jsx("clipPath", { id: ref("green"), children: /* @__PURE__ */ jsx("path", { d: "M-2 -2H66L-2 66Z" }) }),
15
+ /* @__PURE__ */ jsx("clipPath", { id: ref("orange"), children: /* @__PURE__ */ jsx("path", { d: "M66 -2V66H-2Z" }) }),
16
+ /* @__PURE__ */ jsx("clipPath", { id: ref("front"), children: /* @__PURE__ */ jsx("path", { d: FRONT }) }),
17
+ /* @__PURE__ */ jsx("filter", { id: ref("blur"), x: "-20%", y: "-20%", width: "140%", height: "140%", children: /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "1.1" }) }),
18
+ /* @__PURE__ */ jsx("filter", { id: ref("blurSoft"), x: "-20%", y: "-20%", width: "140%", height: "140%", children: /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "0.6" }) }),
19
+ /* @__PURE__ */ jsxs("linearGradient", { id: ref("frontLight"), x1: "0", y1: "0", x2: "0", y2: "1", children: [
20
+ /* @__PURE__ */ jsx("stop", { offset: "0", stopColor: "#FFFFFF", stopOpacity: "0.22" }),
21
+ /* @__PURE__ */ jsx("stop", { offset: "0.35", stopColor: "#FFFFFF", stopOpacity: "0.04" }),
22
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#000000", stopOpacity: "0.26" })
23
+ ] }),
24
+ /* @__PURE__ */ jsxs("linearGradient", { id: ref("frontSide"), x1: "0", y1: "0", x2: "1", y2: "0", children: [
25
+ /* @__PURE__ */ jsx("stop", { offset: "0", stopColor: "#FFFFFF", stopOpacity: "0.12" }),
26
+ /* @__PURE__ */ jsx("stop", { offset: "0.25", stopColor: "#FFFFFF", stopOpacity: "0" }),
27
+ /* @__PURE__ */ jsx("stop", { offset: "0.8", stopColor: "#000000", stopOpacity: "0" }),
28
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#000000", stopOpacity: "0.12" })
29
+ ] }),
30
+ /* @__PURE__ */ jsxs("linearGradient", { id: ref("floorShade"), x1: "0", y1: "0", x2: "0", y2: "1", children: [
31
+ /* @__PURE__ */ jsx("stop", { offset: "0", stopColor: "#000000", stopOpacity: "0.28" }),
32
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#000000", stopOpacity: "0" })
33
+ ] }),
34
+ /* @__PURE__ */ jsxs("linearGradient", { id: ref("paper"), x1: "0", y1: "0", x2: "0", y2: "1", children: [
35
+ /* @__PURE__ */ jsx("stop", { offset: "0", stopColor: "#F3F6FA" }),
36
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#FFFFFF" })
37
+ ] }),
38
+ /* @__PURE__ */ jsxs("radialGradient", { id: ref("shadow"), cx: "0.5", cy: "0.5", r: "0.5", children: [
39
+ /* @__PURE__ */ jsx("stop", { offset: "0", stopColor: "#10195E", stopOpacity: "0.32" }),
40
+ /* @__PURE__ */ jsx("stop", { offset: "0.6", stopColor: "#10195E", stopOpacity: "0.12" }),
41
+ /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#10195E", stopOpacity: "0" })
42
+ ] }),
43
+ /* @__PURE__ */ jsxs("g", { id: ref("back"), children: [
44
+ /* @__PURE__ */ jsx("path", { d: RIM, fill: "currentColor" }),
45
+ /* @__PURE__ */ jsx("path", { d: RIM, fill: "#FFFFFF", opacity: "0.34" }),
46
+ /* @__PURE__ */ jsx("path", { d: "M15.2 13.2H48.8L56.8 30.4L54.5 37H9.5L7.2 30.4Z", fill: "currentColor" }),
47
+ /* @__PURE__ */ jsx("path", { d: "M17 20.5H47L54.5 37H9.5Z", fill: "#000000", opacity: "0.3" }),
48
+ /* @__PURE__ */ jsx("path", { d: "M17 20.5H47L49.6 26.2H14.4Z", fill: url("floorShade") }),
49
+ /* @__PURE__ */ jsx("path", { d: "M15.2 13.2H48.8L47 20.5H17Z", fill: "#000000", opacity: "0.46" }),
50
+ /* @__PURE__ */ jsx("path", { d: "M15.2 13.2L17 20.5L9.5 37L7.2 30.4Z", fill: "#000000", opacity: "0.56" }),
51
+ /* @__PURE__ */ jsx("path", { d: "M48.8 13.2L47 20.5L54.5 37L56.8 30.4Z", fill: "#000000", opacity: "0.2" }),
52
+ /* @__PURE__ */ jsx("path", { d: "M17 20.5H47", stroke: "#000000", strokeWidth: "0.5", opacity: "0.25" }),
53
+ /* @__PURE__ */ jsx("path", { d: "M13 11H51", stroke: "#FFFFFF", strokeWidth: "0.8", strokeLinecap: "round", opacity: "0.75" }),
54
+ /* @__PURE__ */ jsx("path", { d: "M7.2 30.4L15.2 13.2H48.8L56.8 30.4", fill: "none", stroke: "#000000", strokeWidth: "0.5", strokeLinejoin: "round", opacity: "0.22" })
55
+ ] }),
56
+ /* @__PURE__ */ jsxs("g", { id: ref("face"), children: [
57
+ /* @__PURE__ */ jsx("path", { d: FRONT, fill: "currentColor" }),
58
+ /* @__PURE__ */ jsx("path", { d: FRONT, fill: url("frontLight") }),
59
+ /* @__PURE__ */ jsx("path", { d: FRONT, fill: url("frontSide") }),
60
+ /* @__PURE__ */ jsxs("g", { clipPath: url("front"), children: [
61
+ /* @__PURE__ */ jsx("ellipse", { cx: "17", cy: "42", rx: "15", ry: "5.5", fill: "#FFFFFF", opacity: "0.13", filter: url("blur") }),
62
+ /* @__PURE__ */ jsx("path", { d: "M9 53.4H55", stroke: "#FFFFFF", strokeWidth: "0.9", strokeLinecap: "round", opacity: "0.2" })
63
+ ] }),
64
+ /* @__PURE__ */ jsx("path", { d: LIP, fill: "currentColor" }),
65
+ /* @__PURE__ */ jsx("path", { d: LIP, fill: "#FFFFFF", opacity: "0.42" }),
66
+ /* @__PURE__ */ jsx("path", { d: "M7.2 30.4H20.6L24 37.4H40L43.4 30.4H56.8", fill: "none", stroke: "#000000", strokeWidth: "0.55", strokeLinejoin: "round", opacity: "0.28" }),
67
+ /* @__PURE__ */ jsx("path", { d: "M4 33H20L23.5 40H40.5L44 33H60", fill: "none", stroke: "#FFFFFF", strokeWidth: "0.8", strokeLinejoin: "round", opacity: "0.9" }),
68
+ /* @__PURE__ */ jsx("path", { d: "M5 50.5C5.8 53.3 7.8 55 10.5 55H53.5C56.2 55 58.2 53.3 59 50.5", fill: "none", stroke: "#000000", strokeWidth: "0.7", opacity: "0.2" })
69
+ ] })
70
+ ] }),
71
+ /* @__PURE__ */ jsx("ellipse", { cx: "32", cy: "57", rx: "29", ry: "4.2", fill: url("shadow") }),
72
+ /* @__PURE__ */ jsx("use", { href: `#${ref("back")}`, color: GREEN, clipPath: url("green") }),
73
+ /* @__PURE__ */ jsx("use", { href: `#${ref("back")}`, color: ORANGE, clipPath: url("orange") }),
74
+ /* @__PURE__ */ jsx("path", { d: "M19.4 24.2L42.8 22.6L49.4 37.4L14.6 39Z", fill: "#000000", opacity: "0.28", filter: url("blurSoft") }),
75
+ /* @__PURE__ */ jsx("path", { d: "M19.8 23.4L42.6 22.4L48.6 36.8L14.8 38Z", fill: "#DCE3EC" }),
76
+ /* @__PURE__ */ jsx("path", { d: "M21.4 22H43.2L49.2 36.6H15Z", fill: url("paper") }),
77
+ /* @__PURE__ */ jsx("path", { d: "M24.2 26H40.4M23.4 29H41.4M22.6 32H35.6", stroke: "#B9C3D6", strokeWidth: "1.1", strokeLinecap: "round" }),
78
+ /* @__PURE__ */ jsx("use", { href: `#${ref("face")}`, color: GREEN, clipPath: url("green") }),
79
+ /* @__PURE__ */ jsx("use", { href: `#${ref("face")}`, color: ORANGE, clipPath: url("orange") })
80
+ ] });
81
+ }
82
+ export {
83
+ OfflineBoxesIcon,
84
+ OfflineBoxesIcon as default
85
+ };
86
+ //# sourceMappingURL=OfflineBoxesIcon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfflineBoxesIcon.js","sources":["../../../../../../src/v1/components/feedback/OfflineBoxes/OfflineBoxesIcon.tsx"],"sourcesContent":["import React, { useId } from 'react'\r\n\r\nconst GREEN = '#19C99B'\r\nconst ORANGE = '#EA6A12'\r\nconst FRONT = 'M4 33H20L23.5 40H40.5L44 33H60V48C60 52 57.6 55 53.5 55H10.5C6.4 55 4 52 4 48Z'\r\nconst LIP = 'M4 33H20L23.5 40H40.5L44 33H60L56.8 30.4H43.4L40 37.4H24L20.6 30.4H7.2Z'\r\nconst RIM = 'M13 11H51L60 33H4Z'\r\n\r\nexport interface OfflineBoxesIconProps {\r\n size?: number\r\n className?: string\r\n}\r\n\r\n/**\r\n * O tabuleiro de inbox em 3D, dividido na diagonal: verde (Inbox) em cima à\r\n * esquerda, laranja (Outbox) em baixo à direita. Só desenho; os números vão\r\n * ao lado, no OfflineBoxes.\r\n */\r\nexport default function OfflineBoxesIcon({ size = 28, className = '' }: OfflineBoxesIconProps) {\r\n const id = useId().replace(/[^a-zA-Z0-9]/g, '')\r\n const ref = (name: string) => `${name}${id}`\r\n const url = (name: string) => `url(#${ref(name)})`\r\n\r\n return (\r\n <svg width={size} height={size} viewBox=\"0 0 64 64\" aria-hidden=\"true\" className={className}>\r\n <defs>\r\n <clipPath id={ref('green')}><path d=\"M-2 -2H66L-2 66Z\" /></clipPath>\r\n <clipPath id={ref('orange')}><path d=\"M66 -2V66H-2Z\" /></clipPath>\r\n <clipPath id={ref('front')}><path d={FRONT} /></clipPath>\r\n <filter id={ref('blur')} x=\"-20%\" y=\"-20%\" width=\"140%\" height=\"140%\"><feGaussianBlur stdDeviation=\"1.1\" /></filter>\r\n <filter id={ref('blurSoft')} x=\"-20%\" y=\"-20%\" width=\"140%\" height=\"140%\"><feGaussianBlur stdDeviation=\"0.6\" /></filter>\r\n <linearGradient id={ref('frontLight')} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\r\n <stop offset=\"0\" stopColor=\"#FFFFFF\" stopOpacity=\"0.22\" />\r\n <stop offset=\"0.35\" stopColor=\"#FFFFFF\" stopOpacity=\"0.04\" />\r\n <stop offset=\"1\" stopColor=\"#000000\" stopOpacity=\"0.26\" />\r\n </linearGradient>\r\n <linearGradient id={ref('frontSide')} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\r\n <stop offset=\"0\" stopColor=\"#FFFFFF\" stopOpacity=\"0.12\" />\r\n <stop offset=\"0.25\" stopColor=\"#FFFFFF\" stopOpacity=\"0\" />\r\n <stop offset=\"0.8\" stopColor=\"#000000\" stopOpacity=\"0\" />\r\n <stop offset=\"1\" stopColor=\"#000000\" stopOpacity=\"0.12\" />\r\n </linearGradient>\r\n <linearGradient id={ref('floorShade')} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\r\n <stop offset=\"0\" stopColor=\"#000000\" stopOpacity=\"0.28\" />\r\n <stop offset=\"1\" stopColor=\"#000000\" stopOpacity=\"0\" />\r\n </linearGradient>\r\n <linearGradient id={ref('paper')} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\r\n <stop offset=\"0\" stopColor=\"#F3F6FA\" />\r\n <stop offset=\"1\" stopColor=\"#FFFFFF\" />\r\n </linearGradient>\r\n <radialGradient id={ref('shadow')} cx=\"0.5\" cy=\"0.5\" r=\"0.5\">\r\n <stop offset=\"0\" stopColor=\"#10195E\" stopOpacity=\"0.32\" />\r\n <stop offset=\"0.6\" stopColor=\"#10195E\" stopOpacity=\"0.12\" />\r\n <stop offset=\"1\" stopColor=\"#10195E\" stopOpacity=\"0\" />\r\n </radialGradient>\r\n <g id={ref('back')}>\r\n <path d={RIM} fill=\"currentColor\" />\r\n <path d={RIM} fill=\"#FFFFFF\" opacity=\"0.34\" />\r\n <path d=\"M15.2 13.2H48.8L56.8 30.4L54.5 37H9.5L7.2 30.4Z\" fill=\"currentColor\" />\r\n <path d=\"M17 20.5H47L54.5 37H9.5Z\" fill=\"#000000\" opacity=\"0.3\" />\r\n <path d=\"M17 20.5H47L49.6 26.2H14.4Z\" fill={url('floorShade')} />\r\n <path d=\"M15.2 13.2H48.8L47 20.5H17Z\" fill=\"#000000\" opacity=\"0.46\" />\r\n <path d=\"M15.2 13.2L17 20.5L9.5 37L7.2 30.4Z\" fill=\"#000000\" opacity=\"0.56\" />\r\n <path d=\"M48.8 13.2L47 20.5L54.5 37L56.8 30.4Z\" fill=\"#000000\" opacity=\"0.2\" />\r\n <path d=\"M17 20.5H47\" stroke=\"#000000\" strokeWidth=\"0.5\" opacity=\"0.25\" />\r\n <path d=\"M13 11H51\" stroke=\"#FFFFFF\" strokeWidth=\"0.8\" strokeLinecap=\"round\" opacity=\"0.75\" />\r\n <path d=\"M7.2 30.4L15.2 13.2H48.8L56.8 30.4\" fill=\"none\" stroke=\"#000000\" strokeWidth=\"0.5\" strokeLinejoin=\"round\" opacity=\"0.22\" />\r\n </g>\r\n <g id={ref('face')}>\r\n <path d={FRONT} fill=\"currentColor\" />\r\n <path d={FRONT} fill={url('frontLight')} />\r\n <path d={FRONT} fill={url('frontSide')} />\r\n <g clipPath={url('front')}>\r\n <ellipse cx=\"17\" cy=\"42\" rx=\"15\" ry=\"5.5\" fill=\"#FFFFFF\" opacity=\"0.13\" filter={url('blur')} />\r\n <path d=\"M9 53.4H55\" stroke=\"#FFFFFF\" strokeWidth=\"0.9\" strokeLinecap=\"round\" opacity=\"0.2\" />\r\n </g>\r\n <path d={LIP} fill=\"currentColor\" />\r\n <path d={LIP} fill=\"#FFFFFF\" opacity=\"0.42\" />\r\n <path d=\"M7.2 30.4H20.6L24 37.4H40L43.4 30.4H56.8\" fill=\"none\" stroke=\"#000000\" strokeWidth=\"0.55\" strokeLinejoin=\"round\" opacity=\"0.28\" />\r\n <path d=\"M4 33H20L23.5 40H40.5L44 33H60\" fill=\"none\" stroke=\"#FFFFFF\" strokeWidth=\"0.8\" strokeLinejoin=\"round\" opacity=\"0.9\" />\r\n <path d=\"M5 50.5C5.8 53.3 7.8 55 10.5 55H53.5C56.2 55 58.2 53.3 59 50.5\" fill=\"none\" stroke=\"#000000\" strokeWidth=\"0.7\" opacity=\"0.2\" />\r\n </g>\r\n </defs>\r\n\r\n <ellipse cx=\"32\" cy=\"57\" rx=\"29\" ry=\"4.2\" fill={url('shadow')} />\r\n <use href={`#${ref('back')}`} color={GREEN} clipPath={url('green')} />\r\n <use href={`#${ref('back')}`} color={ORANGE} clipPath={url('orange')} />\r\n <path d=\"M19.4 24.2L42.8 22.6L49.4 37.4L14.6 39Z\" fill=\"#000000\" opacity=\"0.28\" filter={url('blurSoft')} />\r\n <path d=\"M19.8 23.4L42.6 22.4L48.6 36.8L14.8 38Z\" fill=\"#DCE3EC\" />\r\n <path d=\"M21.4 22H43.2L49.2 36.6H15Z\" fill={url('paper')} />\r\n <path d=\"M24.2 26H40.4M23.4 29H41.4M22.6 32H35.6\" stroke=\"#B9C3D6\" strokeWidth=\"1.1\" strokeLinecap=\"round\" />\r\n <use href={`#${ref('face')}`} color={GREEN} clipPath={url('green')} />\r\n <use href={`#${ref('face')}`} color={ORANGE} clipPath={url('orange')} />\r\n </svg>\r\n )\r\n}\r\n\r\nexport { OfflineBoxesIcon }\r\n"],"names":[],"mappings":";;AAEA,MAAM,QAAQ;AACd,MAAM,SAAS;AACf,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,MAAM;AAYZ,SAAwB,iBAAiB,EAAE,OAAO,IAAI,YAAY,MAA6B;AAC7F,QAAM,KAAK,MAAA,EAAQ,QAAQ,iBAAiB,EAAE;AAC9C,QAAM,MAAM,CAAC,SAAiB,GAAG,IAAI,GAAG,EAAE;AAC1C,QAAM,MAAM,CAAC,SAAiB,QAAQ,IAAI,IAAI,CAAC;AAE/C,SACE,qBAAC,OAAA,EAAI,OAAO,MAAM,QAAQ,MAAM,SAAQ,aAAY,eAAY,QAAO,WACrE,UAAA;AAAA,IAAA,qBAAC,QAAA,EACC,UAAA;AAAA,MAAA,oBAAC,YAAA,EAAS,IAAI,IAAI,OAAO,GAAG,UAAA,oBAAC,QAAA,EAAK,GAAE,mBAAA,CAAmB,EAAA,CAAE;AAAA,MACzD,oBAAC,YAAA,EAAS,IAAI,IAAI,QAAQ,GAAG,UAAA,oBAAC,QAAA,EAAK,GAAE,gBAAA,CAAgB,EAAA,CAAE;AAAA,MACvD,oBAAC,YAAA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