extractia-sdk 1.0.6 → 1.2.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.
@@ -84,19 +84,49 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
84
84
  // src/index.js
85
85
  var index_exports = {};
86
86
  __export(index_exports, {
87
+ AuthError: () => AuthError,
88
+ ExtractiaError: () => ExtractiaError,
89
+ ForbiddenError: () => ForbiddenError,
90
+ NotFoundError: () => NotFoundError,
91
+ RateLimitError: () => RateLimitError,
92
+ TierError: () => TierError,
93
+ bulkPreconform: () => bulkPreconform,
94
+ configure: () => configure,
95
+ createOcrTool: () => createOcrTool,
96
+ createSubUser: () => createSubUser,
87
97
  createTemplate: () => createTemplate,
88
98
  default: () => index_default,
89
99
  deleteAllTemplateDocuments: () => deleteAllTemplateDocuments,
90
100
  deleteDocument: () => deleteDocument,
101
+ deleteOcrTool: () => deleteOcrTool,
102
+ deleteSubUser: () => deleteSubUser,
91
103
  deleteTemplate: () => deleteTemplate,
104
+ exportDocumentsCsv: () => exportDocumentsCsv,
105
+ exportDocumentsJson: () => exportDocumentsJson,
106
+ generateDocumentSummary: () => generateDocumentSummary,
107
+ getCreditsBalance: () => getCreditsBalance,
108
+ getCreditsHistory: () => getCreditsHistory,
109
+ getDocumentById: () => getDocumentById,
110
+ getDocumentHistory: () => getDocumentHistory,
92
111
  getDocumentsByTemplateId: () => getDocumentsByTemplateId,
93
112
  getMyProfile: () => getMyProfile,
113
+ getOcrTools: () => getOcrTools,
114
+ getRecentDocuments: () => getRecentDocuments,
115
+ getSubUsers: () => getSubUsers,
94
116
  getTemplateById: () => getTemplateById,
95
117
  getTemplateByName: () => getTemplateByName,
96
118
  getTemplates: () => getTemplates,
97
119
  processImage: () => processImage,
98
120
  processImagesMultipage: () => processImagesMultipage,
121
+ runOcrTool: () => runOcrTool,
99
122
  setToken: () => setToken,
123
+ suggestFields: () => suggestFields,
124
+ toggleSuspendSubUser: () => toggleSuspendSubUser,
125
+ updateDocumentData: () => updateDocumentData,
126
+ updateDocumentNotes: () => updateDocumentNotes,
127
+ updateDocumentStatus: () => updateDocumentStatus,
128
+ updateOcrTool: () => updateOcrTool,
129
+ updateSubUser: () => updateSubUser,
100
130
  updateTemplate: () => updateTemplate,
101
131
  updateWebhook: () => updateWebhook
102
132
  });
@@ -105,6 +135,7 @@ module.exports = __toCommonJS(index_exports);
105
135
  // src/auth.js
106
136
  var auth_exports = {};
107
137
  __export(auth_exports, {
138
+ configure: () => configure,
108
139
  getMyProfile: () => getMyProfile,
109
140
  setToken: () => setToken,
110
141
  updateWebhook: () => updateWebhook
@@ -2622,22 +2653,93 @@ var {
2622
2653
  mergeConfig: mergeConfig2
2623
2654
  } = axios_default;
2624
2655
 
2656
+ // src/errors.js
2657
+ var ExtractiaError = class extends Error {
2658
+ /** @param {string} message @param {number} status */
2659
+ constructor(message, status) {
2660
+ super(message);
2661
+ this.name = "ExtractiaError";
2662
+ this.status = status;
2663
+ }
2664
+ };
2665
+ var AuthError = class extends ExtractiaError {
2666
+ constructor(message = "Unauthorized. Check your API token.") {
2667
+ super(message, 401);
2668
+ this.name = "AuthError";
2669
+ }
2670
+ };
2671
+ var ForbiddenError = class extends ExtractiaError {
2672
+ constructor(message = "Forbidden. Insufficient permissions.") {
2673
+ super(message, 403);
2674
+ this.name = "ForbiddenError";
2675
+ }
2676
+ };
2677
+ var TierError = class extends ExtractiaError {
2678
+ constructor(message = "Tier limit reached. Upgrade your plan.", status = 402) {
2679
+ super(message, status);
2680
+ this.name = "TierError";
2681
+ }
2682
+ };
2683
+ var RateLimitError = class extends ExtractiaError {
2684
+ constructor(message = "Too many requests. Please slow down.") {
2685
+ super(message, 429);
2686
+ this.name = "RateLimitError";
2687
+ }
2688
+ };
2689
+ var NotFoundError = class extends ExtractiaError {
2690
+ constructor(message = "Resource not found.") {
2691
+ super(message, 404);
2692
+ this.name = "NotFoundError";
2693
+ }
2694
+ };
2695
+ function mapAxiosError(err) {
2696
+ var _a, _b;
2697
+ const status = (_a = err.response) == null ? void 0 : _a.status;
2698
+ const serverMessage = (_b = err.response) == null ? void 0 : _b.data;
2699
+ const detail = typeof serverMessage === "string" ? serverMessage : void 0;
2700
+ switch (status) {
2701
+ case 401:
2702
+ return new AuthError(detail);
2703
+ case 402:
2704
+ return new TierError(detail);
2705
+ case 403:
2706
+ return new ForbiddenError(detail);
2707
+ case 404:
2708
+ return new NotFoundError(detail);
2709
+ case 429:
2710
+ return new RateLimitError(detail);
2711
+ default:
2712
+ return new ExtractiaError(detail != null ? detail : err.message, status != null ? status : 0);
2713
+ }
2714
+ }
2715
+
2625
2716
  // src/apiClient.js
2626
2717
  var token = null;
2718
+ var DEFAULT_BASE_URL = "https://api.extractia.info/api/public";
2627
2719
  var api = axios_default.create({
2628
- baseURL: "https://www.extractia-api.cat/api/public",
2629
- timeout: 1e4
2720
+ baseURL: DEFAULT_BASE_URL,
2721
+ timeout: 6e4
2722
+ // 60s — AI processing can take 10–30s
2630
2723
  });
2631
2724
  api.interceptors.request.use((config) => {
2632
2725
  if (!token) {
2633
- throw new Error("API token is required");
2726
+ throw new Error(
2727
+ "API token is required. Call setToken(yourApiToken) before making requests."
2728
+ );
2634
2729
  }
2635
2730
  config.headers.Authorization = `Bearer ${token}`;
2636
2731
  return config;
2637
2732
  });
2733
+ api.interceptors.response.use(
2734
+ (response) => response,
2735
+ (err) => Promise.reject(mapAxiosError(err))
2736
+ );
2638
2737
  function setToken(newToken) {
2639
2738
  token = newToken;
2640
2739
  }
2740
+ function configure({ baseURL } = {}) {
2741
+ if (baseURL) api.defaults.baseURL = baseURL;
2742
+ }
2641
2743
  var apiClient_default = api;
2642
2744
 
2643
2745
  // src/auth.js
@@ -2661,6 +2763,7 @@ __export(templates_exports, {
2661
2763
  getTemplateById: () => getTemplateById,
2662
2764
  getTemplateByName: () => getTemplateByName,
2663
2765
  getTemplates: () => getTemplates,
2766
+ suggestFields: () => suggestFields,
2664
2767
  updateTemplate: () => updateTemplate
2665
2768
  });
2666
2769
  async function getTemplates() {
@@ -2693,44 +2796,197 @@ async function deleteAllTemplateDocuments(id) {
2693
2796
  const res = await apiClient_default.delete(`/templates/${id}/documents`);
2694
2797
  return res.data;
2695
2798
  }
2799
+ async function suggestFields(templateName, extractionContext = "") {
2800
+ const res = await apiClient_default.post("/templates/suggest-fields", {
2801
+ templateName,
2802
+ extractionContext
2803
+ });
2804
+ return res.data;
2805
+ }
2696
2806
 
2697
2807
  // src/documents.js
2698
2808
  var documents_exports = {};
2699
2809
  __export(documents_exports, {
2810
+ bulkPreconform: () => bulkPreconform,
2700
2811
  deleteDocument: () => deleteDocument,
2812
+ exportDocumentsCsv: () => exportDocumentsCsv,
2813
+ exportDocumentsJson: () => exportDocumentsJson,
2814
+ generateDocumentSummary: () => generateDocumentSummary,
2815
+ getDocumentById: () => getDocumentById,
2701
2816
  getDocumentsByTemplateId: () => getDocumentsByTemplateId,
2817
+ getRecentDocuments: () => getRecentDocuments,
2702
2818
  processImage: () => processImage,
2703
- processImagesMultipage: () => processImagesMultipage
2819
+ processImagesMultipage: () => processImagesMultipage,
2820
+ updateDocumentData: () => updateDocumentData,
2821
+ updateDocumentNotes: () => updateDocumentNotes,
2822
+ updateDocumentStatus: () => updateDocumentStatus
2704
2823
  });
2705
2824
  async function getDocumentsByTemplateId(templateId, options = {}) {
2706
- var _a, _b, _c;
2707
- const params = {
2708
- preconformed: (_a = options.preconformed) != null ? _a : null,
2709
- index: (_b = options.index) != null ? _b : 0,
2710
- sort: (_c = options.sort) != null ? _c : -1,
2711
- includeImage: options.includeImage ? 1 : 0
2712
- };
2825
+ const params = {};
2826
+ if (options.preconformed != null) params.preconformed = options.preconformed;
2827
+ if (options.index != null) params.index = options.index;
2828
+ if (options.sort != null) params.sort = options.sort;
2829
+ params.includeImage = options.includeImage ? 1 : 0;
2713
2830
  const res = await apiClient_default.get(`/templates/${templateId}/documents`, { params });
2714
2831
  return res.data;
2715
2832
  }
2833
+ async function getDocumentById(templateId, docId, options = {}) {
2834
+ const params = { includeImage: options.includeImage ? 1 : 0 };
2835
+ const res = await apiClient_default.get(`/templates/${templateId}/documents/${docId}`, {
2836
+ params
2837
+ });
2838
+ return res.data;
2839
+ }
2840
+ async function getRecentDocuments(size = 10) {
2841
+ const res = await apiClient_default.get("/documents/recent", {
2842
+ params: { size: Math.min(size, 50) }
2843
+ });
2844
+ return res.data;
2845
+ }
2716
2846
  async function deleteDocument(documentId) {
2717
2847
  const res = await apiClient_default.delete(`/documents/${documentId}`);
2718
2848
  return res.data;
2719
2849
  }
2720
2850
  async function processImage(templateId, base64Image) {
2721
- const res = await apiClient_default.post(`/public/templates/${templateId}/process`, {
2851
+ const res = await apiClient_default.post(`/templates/${templateId}/process`, {
2722
2852
  image: base64Image
2723
2853
  });
2724
2854
  return res.data;
2725
2855
  }
2726
2856
  async function processImagesMultipage(templateId, base64ImagesArray) {
2727
- const res = await apiClient_default.post(`/public/templates/${templateId}/process-multipage`, {
2857
+ const res = await apiClient_default.post(`/templates/${templateId}/process-multipage`, {
2728
2858
  images: base64ImagesArray
2729
2859
  });
2730
2860
  return res.data;
2731
2861
  }
2862
+ async function generateDocumentSummary(docId) {
2863
+ const res = await apiClient_default.post(`/documents/${docId}/summary`);
2864
+ return res.data;
2865
+ }
2866
+ async function updateDocumentStatus(docId, status) {
2867
+ const res = await apiClient_default.put(`/documents/${docId}/status`, { status });
2868
+ return res.data;
2869
+ }
2870
+ async function updateDocumentNotes(docId, notes) {
2871
+ const res = await apiClient_default.put(`/documents/${docId}/notes`, { notes });
2872
+ return res.data;
2873
+ }
2874
+ async function updateDocumentData(docId, data, options = {}) {
2875
+ var _a;
2876
+ const res = await apiClient_default.put(`/documents/${docId}/data`, {
2877
+ data,
2878
+ preconformed: (_a = options.preconformed) != null ? _a : false
2879
+ });
2880
+ return res.data;
2881
+ }
2882
+ async function bulkPreconform(ids) {
2883
+ const res = await apiClient_default.post("/documents/bulk-preconform", { ids });
2884
+ return res.data;
2885
+ }
2886
+ async function exportDocumentsCsv(templateId, options = {}) {
2887
+ const params = {};
2888
+ if (options.fields && options.fields.length > 0)
2889
+ params.fields = options.fields.join(",");
2890
+ const res = await apiClient_default.get(`/templates/${templateId}/documents/export/csv`, {
2891
+ params,
2892
+ responseType: "text"
2893
+ });
2894
+ return res.data;
2895
+ }
2896
+ async function exportDocumentsJson(templateId) {
2897
+ const res = await apiClient_default.get(`/templates/${templateId}/documents/export/json`);
2898
+ return res.data;
2899
+ }
2900
+
2901
+ // src/analytics.js
2902
+ var analytics_exports = {};
2903
+ __export(analytics_exports, {
2904
+ getCreditsBalance: () => getCreditsBalance,
2905
+ getCreditsHistory: () => getCreditsHistory,
2906
+ getDocumentHistory: () => getDocumentHistory
2907
+ });
2908
+ async function getCreditsBalance() {
2909
+ const res = await apiClient_default.get("/me/credits");
2910
+ return res.data;
2911
+ }
2912
+ async function getCreditsHistory({ page = 0, size = 20 } = {}) {
2913
+ const res = await apiClient_default.get("/me/credits/history", {
2914
+ params: { page, size: Math.min(size, 100) }
2915
+ });
2916
+ return res.data;
2917
+ }
2918
+ async function getDocumentHistory({ page = 0, size = 20 } = {}) {
2919
+ const res = await apiClient_default.get("/me/documents/history", {
2920
+ params: { page, size: Math.min(size, 100) }
2921
+ });
2922
+ return res.data;
2923
+ }
2924
+
2925
+ // src/ocrTools.js
2926
+ var ocrTools_exports = {};
2927
+ __export(ocrTools_exports, {
2928
+ createOcrTool: () => createOcrTool,
2929
+ deleteOcrTool: () => deleteOcrTool,
2930
+ getOcrTools: () => getOcrTools,
2931
+ runOcrTool: () => runOcrTool,
2932
+ updateOcrTool: () => updateOcrTool
2933
+ });
2934
+ async function getOcrTools() {
2935
+ const res = await apiClient_default.get("/ocr-tools");
2936
+ return res.data;
2937
+ }
2938
+ async function createOcrTool(config) {
2939
+ const res = await apiClient_default.post("/ocr-tools", config);
2940
+ return res.data;
2941
+ }
2942
+ async function updateOcrTool(id, config) {
2943
+ const res = await apiClient_default.put(`/ocr-tools/${id}`, config);
2944
+ return res.data;
2945
+ }
2946
+ async function deleteOcrTool(id) {
2947
+ const res = await apiClient_default.delete(`/ocr-tools/${id}`);
2948
+ return res.data;
2949
+ }
2950
+ async function runOcrTool(id, base64Image, options = {}) {
2951
+ const body = { image: base64Image };
2952
+ if (options.params && Object.keys(options.params).length > 0) {
2953
+ body.params = options.params;
2954
+ }
2955
+ const res = await apiClient_default.post(`/ocr-tools/${id}/run`, body);
2956
+ return res.data;
2957
+ }
2958
+
2959
+ // src/subusers.js
2960
+ var subusers_exports = {};
2961
+ __export(subusers_exports, {
2962
+ createSubUser: () => createSubUser,
2963
+ deleteSubUser: () => deleteSubUser,
2964
+ getSubUsers: () => getSubUsers,
2965
+ toggleSuspendSubUser: () => toggleSuspendSubUser,
2966
+ updateSubUser: () => updateSubUser
2967
+ });
2968
+ async function getSubUsers() {
2969
+ const res = await apiClient_default.get("/me/subusers");
2970
+ return res.data;
2971
+ }
2972
+ async function createSubUser({ username, password, permissions }) {
2973
+ const res = await apiClient_default.post("/me/subusers", { username, password, permissions });
2974
+ return res.data;
2975
+ }
2976
+ async function deleteSubUser(username) {
2977
+ const res = await apiClient_default.delete(`/me/subusers/${encodeURIComponent(username)}`);
2978
+ return res.data;
2979
+ }
2980
+ async function updateSubUser(username, updates = {}) {
2981
+ const res = await apiClient_default.put(`/me/subusers/${encodeURIComponent(username)}`, updates);
2982
+ return res.data;
2983
+ }
2984
+ async function toggleSuspendSubUser(username) {
2985
+ const res = await apiClient_default.put(`/me/subusers/${encodeURIComponent(username)}/suspend`);
2986
+ return res.data;
2987
+ }
2732
2988
 
2733
2989
  // src/index.js
2734
- var extractia = __spreadValues(__spreadValues(__spreadValues({}, auth_exports), templates_exports), documents_exports);
2990
+ var extractia = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, auth_exports), templates_exports), documents_exports), analytics_exports), ocrTools_exports), subusers_exports);
2735
2991
  var index_default = extractia;
2736
2992
  //# sourceMappingURL=extractia-sdk.cjs.js.map