dymo-api 1.0.99 → 1.1.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.
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getRandom = exports.sendEmail = exports.isValidData = void 0;
39
+ exports.extractWithTextly = exports.getRandom = exports.sendEmail = exports.isValidData = void 0;
40
40
  const path_1 = __importDefault(require("path"));
41
41
  const react_1 = __importDefault(require("react"));
42
42
  const promises_1 = __importDefault(require("fs/promises"));
@@ -184,3 +184,32 @@ const getRandom = async (token, data) => {
184
184
  }
185
185
  };
186
186
  exports.getRandom = getRandom;
187
+ /**
188
+ * Extracts structured data from a given string using a secure endpoint.
189
+ *
190
+ * @param token - A string or null representing the authentication token. Must not be null.
191
+ * @param data - An object adhering to the ExtractWithTextly interface, containing 'data' and 'format' fields.
192
+ * The 'data' field is the string from which structured data should be extracted.
193
+ * The 'format' field is an object defining the structure of the data to be extracted.
194
+ *
195
+ * @returns A promise that resolves to the response data containing the extracted structured data.
196
+ *
197
+ * @throws Will throw an error if the token is null, if 'data' or 'format' are not defined,
198
+ * or if an error occurs during the request to the extraction endpoint.
199
+ */
200
+ const extractWithTextly = async (token, data) => {
201
+ if (token === null)
202
+ throw customError(3000, "Invalid private token.");
203
+ if (!data.data)
204
+ throw customError(1500, "No data provided.");
205
+ if (!data.format)
206
+ throw customError(1500, "No format provided.");
207
+ try {
208
+ const response = await config_1.axiosApiUrl.post("/private/textly/extract", data, { headers: { "Content-Type": "application/json", "Authorization": token } });
209
+ return response.data;
210
+ }
211
+ catch (error) {
212
+ throw customError(5000, error.response?.data?.message || error.message);
213
+ }
214
+ };
215
+ exports.extractWithTextly = extractWithTextly;
@@ -136,6 +136,21 @@ class DymoAPI {
136
136
  async getRandom(data) {
137
137
  return await PrivateAPI.getRandom(this.rootApiKey || this.apiKey, data);
138
138
  }
139
+ /**
140
+ * Extracts structured data from a given string using Textly.
141
+ *
142
+ * This method requires either the root API key or the API key to be set.
143
+ * If neither is set, it will throw an error.
144
+ *
145
+ * @param {Interfaces.ExtractWithTextly} data - The data to be sent, containing the string to be processed and the format schema.
146
+ * @returns {Promise<any>} A promise that resolves to the extracted structured data.
147
+ * @throws Will throw an error if there is an issue with the extraction process.
148
+ *
149
+ * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/textly/text-extraction)
150
+ */
151
+ async extractWithTextly(data) {
152
+ return await PrivateAPI.extractWithTextly(this.rootApiKey || this.apiKey, data);
153
+ }
139
154
  // FUNCTIONS / Public.
140
155
  /**
141
156
  * Retrieves the prayer times for the given location.
@@ -142,3 +142,31 @@ export const getRandom = async (token, data) => {
142
142
  throw customError(5000, error.response?.data?.message || error.message);
143
143
  }
144
144
  };
145
+ /**
146
+ * Extracts structured data from a given string using a secure endpoint.
147
+ *
148
+ * @param token - A string or null representing the authentication token. Must not be null.
149
+ * @param data - An object adhering to the ExtractWithTextly interface, containing 'data' and 'format' fields.
150
+ * The 'data' field is the string from which structured data should be extracted.
151
+ * The 'format' field is an object defining the structure of the data to be extracted.
152
+ *
153
+ * @returns A promise that resolves to the response data containing the extracted structured data.
154
+ *
155
+ * @throws Will throw an error if the token is null, if 'data' or 'format' are not defined,
156
+ * or if an error occurs during the request to the extraction endpoint.
157
+ */
158
+ export const extractWithTextly = async (token, data) => {
159
+ if (token === null)
160
+ throw customError(3000, "Invalid private token.");
161
+ if (!data.data)
162
+ throw customError(1500, "No data provided.");
163
+ if (!data.format)
164
+ throw customError(1500, "No format provided.");
165
+ try {
166
+ const response = await axiosApiUrl.post("/private/textly/extract", data, { headers: { "Content-Type": "application/json", "Authorization": token } });
167
+ return response.data;
168
+ }
169
+ catch (error) {
170
+ throw customError(5000, error.response?.data?.message || error.message);
171
+ }
172
+ };
@@ -101,6 +101,21 @@ class DymoAPI {
101
101
  async getRandom(data) {
102
102
  return await PrivateAPI.getRandom(this.rootApiKey || this.apiKey, data);
103
103
  }
104
+ /**
105
+ * Extracts structured data from a given string using Textly.
106
+ *
107
+ * This method requires either the root API key or the API key to be set.
108
+ * If neither is set, it will throw an error.
109
+ *
110
+ * @param {Interfaces.ExtractWithTextly} data - The data to be sent, containing the string to be processed and the format schema.
111
+ * @returns {Promise<any>} A promise that resolves to the extracted structured data.
112
+ * @throws Will throw an error if there is an issue with the extraction process.
113
+ *
114
+ * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/textly/text-extraction)
115
+ */
116
+ async extractWithTextly(data) {
117
+ return await PrivateAPI.extractWithTextly(this.rootApiKey || this.apiKey, data);
118
+ }
104
119
  // FUNCTIONS / Public.
105
120
  /**
106
121
  * Retrieves the prayer times for the given location.
@@ -42,3 +42,17 @@ export declare const sendEmail: (token: string | null, data: Interfaces.SendEmai
42
42
  * or if an error occurs during the request to the random number generator endpoint.
43
43
  */
44
44
  export declare const getRandom: (token: string | null, data: Interfaces.SRNG) => Promise<any>;
45
+ /**
46
+ * Extracts structured data from a given string using a secure endpoint.
47
+ *
48
+ * @param token - A string or null representing the authentication token. Must not be null.
49
+ * @param data - An object adhering to the ExtractWithTextly interface, containing 'data' and 'format' fields.
50
+ * The 'data' field is the string from which structured data should be extracted.
51
+ * The 'format' field is an object defining the structure of the data to be extracted.
52
+ *
53
+ * @returns A promise that resolves to the response data containing the extracted structured data.
54
+ *
55
+ * @throws Will throw an error if the token is null, if 'data' or 'format' are not defined,
56
+ * or if an error occurs during the request to the extraction endpoint.
57
+ */
58
+ export declare const extractWithTextly: (token: string | null, data: Interfaces.ExtractWithTextly) => Promise<any>;
@@ -90,6 +90,19 @@ declare class DymoAPI {
90
90
  * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/secure-random-number-generator)
91
91
  */
92
92
  getRandom(data: Interfaces.SRNG): Promise<Interfaces.SRNSummary>;
93
+ /**
94
+ * Extracts structured data from a given string using Textly.
95
+ *
96
+ * This method requires either the root API key or the API key to be set.
97
+ * If neither is set, it will throw an error.
98
+ *
99
+ * @param {Interfaces.ExtractWithTextly} data - The data to be sent, containing the string to be processed and the format schema.
100
+ * @returns {Promise<any>} A promise that resolves to the extracted structured data.
101
+ * @throws Will throw an error if there is an issue with the extraction process.
102
+ *
103
+ * [Documentation](https://docs.tpeoficial.com/docs/dymo-api/private/textly/text-extraction)
104
+ */
105
+ extractWithTextly(data: Interfaces.ExtractWithTextly): Promise<any>;
93
106
  /**
94
107
  * Retrieves the prayer times for the given location.
95
108
  *
@@ -274,3 +274,25 @@ export interface DataValidationAnalysis {
274
274
  };
275
275
  };
276
276
  }
277
+ export type SchemaType = "string" | "number" | "boolean" | "array" | "object";
278
+ export interface JsonSchemaProperty {
279
+ type: SchemaType;
280
+ items?: JsonSchemaProperty;
281
+ properties?: Record<string, JsonSchemaProperty>;
282
+ required?: string[];
283
+ description?: string;
284
+ format?: string;
285
+ enum?: unknown[];
286
+ minimum?: number;
287
+ maximum?: number;
288
+ minLength?: number;
289
+ maxLength?: number;
290
+ pattern?: string;
291
+ [key: string]: unknown;
292
+ }
293
+ export interface ExtractWithTextly {
294
+ data: string;
295
+ format: {
296
+ [key: string]: JsonSchemaProperty;
297
+ };
298
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dymo-api",
3
- "version": "1.0.99",
3
+ "version": "1.1.00",
4
4
  "description": "Flow system for Dymo API.",
5
5
  "main": "dist/cjs/dymo-api.js",
6
6
  "module": "dist/esm/dymo-api.js",