@nubitio/hydra 0.10.0 → 0.11.1

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
@@ -33,9 +33,7 @@ import { SchemaProvider, useResourceSchema, HydraRemoteDataSource } from '@nubit
33
33
  export function App() {
34
34
  return (
35
35
  <CoreConfigProvider apiBaseUrl="https://api.example.com" locale="es" timezone="America/Lima">
36
- <SchemaProvider>
37
- {/* CRUD pages that call useResourceSchema('products') */}
38
- </SchemaProvider>
36
+ <SchemaProvider>{/* CRUD pages that call useResourceSchema('products') */}</SchemaProvider>
39
37
  </CoreConfigProvider>
40
38
  );
41
39
  }
package/dist/index.cjs CHANGED
@@ -28,6 +28,25 @@ let _nubitio_crud = require("@nubitio/crud");
28
28
  let react_jsx_runtime = require("react/jsx-runtime");
29
29
  let _tanstack_react_query = require("@tanstack/react-query");
30
30
  //#region packages/hydra/HydraRemoteDataSource.ts
31
+ const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
32
+ const CONTENT_DISPOSITION_FILENAME_EXT = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i;
33
+ const CONTENT_DISPOSITION_FILENAME = /filename\s*=\s*"([^"]+)"|filename\s*=\s*([^;]+)/i;
34
+ function parseContentDispositionFilename(headers, fallback) {
35
+ const raw = headers.get("content-disposition");
36
+ if (!raw) return fallback;
37
+ const extended = CONTENT_DISPOSITION_FILENAME_EXT.exec(raw)?.[1];
38
+ if (extended) try {
39
+ return sanitizeFilename(decodeURIComponent(extended.trim())) ?? fallback;
40
+ } catch {}
41
+ const match = CONTENT_DISPOSITION_FILENAME.exec(raw);
42
+ const plain = match?.[1] ?? match?.[2];
43
+ return plain && sanitizeFilename(plain.trim()) || fallback;
44
+ }
45
+ /** The server names the file; never let that name escape the download directory. */
46
+ function sanitizeFilename(value) {
47
+ const name = value.replace(/[/\\]/g, "_").trim();
48
+ return name === "" || name === "." || name === ".." ? null : name;
49
+ }
31
50
  const defaultHttpClient = (0, _nubitio_core.createCoreHttpClient)({ baseUrl: "" });
32
51
  function findPreloadedItem(loadOptions, idField, id) {
33
52
  const prependData = Array.isArray(loadOptions.prependData) ? loadOptions.prependData : [];
@@ -208,6 +227,24 @@ var HydraRemoteDataSource = class {
208
227
  }
209
228
  return this.fetchAll(preparedOptions);
210
229
  }
230
+ async export(loadOptions) {
231
+ const preparedOptions = this.prepareLoadOptions({
232
+ ...loadOptions,
233
+ skip: void 0,
234
+ take: void 0
235
+ });
236
+ delete preparedOptions.itemsPerPage;
237
+ delete preparedOptions.page;
238
+ const response = await this.httpClient.get(this.config.url, {
239
+ params: stripMergeOnlyParams(preparedOptions),
240
+ headers: { Accept: XLSX_MIME_TYPE },
241
+ responseType: "blob"
242
+ });
243
+ return {
244
+ blob: response.data,
245
+ filename: parseContentDispositionFilename(response.headers, "export.xlsx")
246
+ };
247
+ }
211
248
  async byKey(key) {
212
249
  const id = typeof key === "object" && key !== null ? key[this.config.idField] : key;
213
250
  if (id === void 0) return null;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DataRecord, GridData } from "@nubitio/core";
2
- import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
2
+ import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceExportResult, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
3
3
  import React, { ReactNode } from "react";
4
4
 
5
5
  //#region packages/hydra/HydraRemoteDataSource.d.ts
@@ -14,6 +14,7 @@ declare class HydraRemoteDataSource implements ResourceStore {
14
14
  makeFilterRules(filterRules: ResourceFilterRule[]): string;
15
15
  prepareLoadOptions(loadOptions: ResourceLoadOptions): ResourceLoadOptions;
16
16
  load(loadOptions: ResourceLoadOptions): Promise<GridData<DataRecord>>;
17
+ export(loadOptions: ResourceLoadOptions): Promise<ResourceExportResult>;
17
18
  byKey(key: unknown): Promise<DataRecord | null>;
18
19
  private fetchAll;
19
20
  private fetchById;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DataRecord, GridData } from "@nubitio/core";
2
2
  import React, { ReactNode } from "react";
3
- import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
3
+ import { DataRecord as DataRecord$1, EmbeddedLinesSchema, EmbeddedLinesSchema as EmbeddedLinesSchema$1, Field, FormLayout, ResourceExportResult, ResourceFilterDescriptor, ResourceFilterRule, ResourceFormDetail, ResourceLoadOptions, ResourceSchemaResolution, ResourceSortDescriptor, ResourceStore, ResourceStoreFactory, ResourceStoreOptions, SummaryItem, WorkflowSchema, WorkflowSchema as WorkflowSchema$1, WorkflowTransitionSchema } from "@nubitio/crud";
4
4
 
5
5
  //#region packages/hydra/HydraRemoteDataSource.d.ts
6
6
  type RemoteFilterDescriptor = ResourceFilterDescriptor;
@@ -14,6 +14,7 @@ declare class HydraRemoteDataSource implements ResourceStore {
14
14
  makeFilterRules(filterRules: ResourceFilterRule[]): string;
15
15
  prepareLoadOptions(loadOptions: ResourceLoadOptions): ResourceLoadOptions;
16
16
  load(loadOptions: ResourceLoadOptions): Promise<GridData<DataRecord>>;
17
+ export(loadOptions: ResourceLoadOptions): Promise<ResourceExportResult>;
17
18
  byKey(key: unknown): Promise<DataRecord | null>;
18
19
  private fetchAll;
19
20
  private fetchById;
package/dist/index.mjs CHANGED
@@ -4,6 +4,25 @@ import { ResourceSchemaProvider, ResourceStoreProvider, currencyField, datetimeF
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { useQuery } from "@tanstack/react-query";
6
6
  //#region packages/hydra/HydraRemoteDataSource.ts
7
+ const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
8
+ const CONTENT_DISPOSITION_FILENAME_EXT = /filename\*\s*=\s*[^']*'[^']*'([^;]+)/i;
9
+ const CONTENT_DISPOSITION_FILENAME = /filename\s*=\s*"([^"]+)"|filename\s*=\s*([^;]+)/i;
10
+ function parseContentDispositionFilename(headers, fallback) {
11
+ const raw = headers.get("content-disposition");
12
+ if (!raw) return fallback;
13
+ const extended = CONTENT_DISPOSITION_FILENAME_EXT.exec(raw)?.[1];
14
+ if (extended) try {
15
+ return sanitizeFilename(decodeURIComponent(extended.trim())) ?? fallback;
16
+ } catch {}
17
+ const match = CONTENT_DISPOSITION_FILENAME.exec(raw);
18
+ const plain = match?.[1] ?? match?.[2];
19
+ return plain && sanitizeFilename(plain.trim()) || fallback;
20
+ }
21
+ /** The server names the file; never let that name escape the download directory. */
22
+ function sanitizeFilename(value) {
23
+ const name = value.replace(/[/\\]/g, "_").trim();
24
+ return name === "" || name === "." || name === ".." ? null : name;
25
+ }
7
26
  const defaultHttpClient = createCoreHttpClient({ baseUrl: "" });
8
27
  function findPreloadedItem(loadOptions, idField, id) {
9
28
  const prependData = Array.isArray(loadOptions.prependData) ? loadOptions.prependData : [];
@@ -184,6 +203,24 @@ var HydraRemoteDataSource = class {
184
203
  }
185
204
  return this.fetchAll(preparedOptions);
186
205
  }
206
+ async export(loadOptions) {
207
+ const preparedOptions = this.prepareLoadOptions({
208
+ ...loadOptions,
209
+ skip: void 0,
210
+ take: void 0
211
+ });
212
+ delete preparedOptions.itemsPerPage;
213
+ delete preparedOptions.page;
214
+ const response = await this.httpClient.get(this.config.url, {
215
+ params: stripMergeOnlyParams(preparedOptions),
216
+ headers: { Accept: XLSX_MIME_TYPE },
217
+ responseType: "blob"
218
+ });
219
+ return {
220
+ blob: response.data,
221
+ filename: parseContentDispositionFilename(response.headers, "export.xlsx")
222
+ };
223
+ }
187
224
  async byKey(key) {
188
225
  const id = typeof key === "object" && key !== null ? key[this.config.idField] : key;
189
226
  if (id === void 0) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nubitio/hydra",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "type": "module",
5
5
  "description": "Hydra / OpenAPI adapter for @nubitio/crud — automatic schema discovery and data source from API Platform docs.",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "react": "^18.2.0 || ^19.0.0",
52
52
  "react-dom": "^18.2.0 || ^19.0.0",
53
53
  "react-i18next": "^14.0.0",
54
- "@nubitio/core": "^0.10.0",
55
- "@nubitio/crud": "^0.10.0"
54
+ "@nubitio/crud": "^0.11.1",
55
+ "@nubitio/core": "^0.11.1"
56
56
  }
57
57
  }