@apify/input_schema 3.8.0 → 3.9.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.
package/cjs/index.d.ts CHANGED
@@ -191,61 +191,159 @@ var definitions = {
191
191
  }
192
192
  },
193
193
  then: {
194
- additionalProperties: false,
195
- properties: {
196
- type: {
197
- "enum": [
198
- "string"
199
- ]
200
- },
201
- title: {
202
- type: "string"
203
- },
204
- description: {
205
- type: "string"
206
- },
207
- "default": {
208
- type: "string"
209
- },
210
- prefill: {
211
- type: "string"
212
- },
213
- example: {
214
- type: "string"
215
- },
216
- pattern: {
217
- type: "string"
218
- },
219
- nullable: {
220
- type: "boolean"
221
- },
222
- minLength: {
223
- type: "integer"
194
+ "if": {
195
+ properties: {
196
+ editor: {
197
+ "const": "datepicker"
198
+ }
199
+ }
200
+ },
201
+ then: {
202
+ additionalProperties: false,
203
+ properties: {
204
+ type: {
205
+ "enum": [
206
+ "string"
207
+ ]
208
+ },
209
+ title: {
210
+ type: "string"
211
+ },
212
+ description: {
213
+ type: "string"
214
+ },
215
+ "default": {
216
+ type: "string"
217
+ },
218
+ prefill: {
219
+ type: "string"
220
+ },
221
+ example: {
222
+ type: "string"
223
+ },
224
+ pattern: {
225
+ type: "string"
226
+ },
227
+ nullable: {
228
+ type: "boolean"
229
+ },
230
+ minLength: {
231
+ type: "integer"
232
+ },
233
+ maxLength: {
234
+ type: "integer"
235
+ },
236
+ editor: {
237
+ "enum": [
238
+ "datepicker"
239
+ ]
240
+ },
241
+ sectionCaption: {
242
+ type: "string"
243
+ },
244
+ sectionDescription: {
245
+ type: "string"
246
+ },
247
+ allowAbsolute: {
248
+ type: "boolean"
249
+ },
250
+ allowRelative: {
251
+ type: "boolean"
252
+ }
224
253
  },
225
- maxLength: {
226
- type: "integer"
254
+ "if": {
255
+ required: [
256
+ "allowAbsolute"
257
+ ],
258
+ properties: {
259
+ allowAbsolute: {
260
+ "const": false
261
+ }
262
+ }
227
263
  },
228
- editor: {
229
- "enum": [
230
- "javascript",
231
- "python",
232
- "textfield",
233
- "textarea",
234
- "datepicker",
235
- "hidden",
236
- "dataset",
237
- "keyValueStore",
238
- "requestQueue"
264
+ then: {
265
+ required: [
266
+ "type",
267
+ "title",
268
+ "description",
269
+ "editor",
270
+ "allowRelative"
239
271
  ]
240
272
  },
241
- isSecret: {
242
- type: "boolean"
243
- },
244
- sectionCaption: {
245
- type: "string"
246
- },
247
- sectionDescription: {
248
- type: "string"
273
+ anyOf: [
274
+ {
275
+ properties: {
276
+ allowAbsolute: {
277
+ "const": true
278
+ }
279
+ }
280
+ },
281
+ {
282
+ properties: {
283
+ allowRelative: {
284
+ "const": true
285
+ }
286
+ }
287
+ }
288
+ ]
289
+ },
290
+ "else": {
291
+ additionalProperties: false,
292
+ properties: {
293
+ type: {
294
+ "enum": [
295
+ "string"
296
+ ]
297
+ },
298
+ title: {
299
+ type: "string"
300
+ },
301
+ description: {
302
+ type: "string"
303
+ },
304
+ "default": {
305
+ type: "string"
306
+ },
307
+ prefill: {
308
+ type: "string"
309
+ },
310
+ example: {
311
+ type: "string"
312
+ },
313
+ pattern: {
314
+ type: "string"
315
+ },
316
+ nullable: {
317
+ type: "boolean"
318
+ },
319
+ minLength: {
320
+ type: "integer"
321
+ },
322
+ maxLength: {
323
+ type: "integer"
324
+ },
325
+ editor: {
326
+ "enum": [
327
+ "javascript",
328
+ "python",
329
+ "textfield",
330
+ "textarea",
331
+ "datepicker",
332
+ "hidden",
333
+ "dataset",
334
+ "keyValueStore",
335
+ "requestQueue"
336
+ ]
337
+ },
338
+ isSecret: {
339
+ type: "boolean"
340
+ },
341
+ sectionCaption: {
342
+ type: "string"
343
+ },
344
+ sectionDescription: {
345
+ type: "string"
346
+ }
249
347
  }
250
348
  }
251
349
  },
@@ -687,6 +785,8 @@ type StringFieldDefinition = CommonFieldDefinition<string> & {
687
785
  enum?: readonly string[];
688
786
  enumTitles?: readonly string[];
689
787
  isSecret?: boolean;
788
+ allowAbsolute?: boolean;
789
+ allowRelative?: boolean;
690
790
  };
691
791
  type BooleanFieldDefinition = CommonFieldDefinition<boolean> & {
692
792
  type: 'boolean';
@@ -751,6 +851,7 @@ type InputSchema = {
751
851
  */
752
852
  declare function parseAjvError(error: ErrorObject, rootName: string, properties?: Record<string, {
753
853
  nullable?: boolean;
854
+ editor?: string;
754
855
  }>, input?: Record<string, unknown>): {
755
856
  fieldKey: string;
756
857
  message: string;
package/esm/index.d.mts CHANGED
@@ -191,61 +191,159 @@ var definitions = {
191
191
  }
192
192
  },
193
193
  then: {
194
- additionalProperties: false,
195
- properties: {
196
- type: {
197
- "enum": [
198
- "string"
199
- ]
200
- },
201
- title: {
202
- type: "string"
203
- },
204
- description: {
205
- type: "string"
206
- },
207
- "default": {
208
- type: "string"
209
- },
210
- prefill: {
211
- type: "string"
212
- },
213
- example: {
214
- type: "string"
215
- },
216
- pattern: {
217
- type: "string"
218
- },
219
- nullable: {
220
- type: "boolean"
221
- },
222
- minLength: {
223
- type: "integer"
194
+ "if": {
195
+ properties: {
196
+ editor: {
197
+ "const": "datepicker"
198
+ }
199
+ }
200
+ },
201
+ then: {
202
+ additionalProperties: false,
203
+ properties: {
204
+ type: {
205
+ "enum": [
206
+ "string"
207
+ ]
208
+ },
209
+ title: {
210
+ type: "string"
211
+ },
212
+ description: {
213
+ type: "string"
214
+ },
215
+ "default": {
216
+ type: "string"
217
+ },
218
+ prefill: {
219
+ type: "string"
220
+ },
221
+ example: {
222
+ type: "string"
223
+ },
224
+ pattern: {
225
+ type: "string"
226
+ },
227
+ nullable: {
228
+ type: "boolean"
229
+ },
230
+ minLength: {
231
+ type: "integer"
232
+ },
233
+ maxLength: {
234
+ type: "integer"
235
+ },
236
+ editor: {
237
+ "enum": [
238
+ "datepicker"
239
+ ]
240
+ },
241
+ sectionCaption: {
242
+ type: "string"
243
+ },
244
+ sectionDescription: {
245
+ type: "string"
246
+ },
247
+ allowAbsolute: {
248
+ type: "boolean"
249
+ },
250
+ allowRelative: {
251
+ type: "boolean"
252
+ }
224
253
  },
225
- maxLength: {
226
- type: "integer"
254
+ "if": {
255
+ required: [
256
+ "allowAbsolute"
257
+ ],
258
+ properties: {
259
+ allowAbsolute: {
260
+ "const": false
261
+ }
262
+ }
227
263
  },
228
- editor: {
229
- "enum": [
230
- "javascript",
231
- "python",
232
- "textfield",
233
- "textarea",
234
- "datepicker",
235
- "hidden",
236
- "dataset",
237
- "keyValueStore",
238
- "requestQueue"
264
+ then: {
265
+ required: [
266
+ "type",
267
+ "title",
268
+ "description",
269
+ "editor",
270
+ "allowRelative"
239
271
  ]
240
272
  },
241
- isSecret: {
242
- type: "boolean"
243
- },
244
- sectionCaption: {
245
- type: "string"
246
- },
247
- sectionDescription: {
248
- type: "string"
273
+ anyOf: [
274
+ {
275
+ properties: {
276
+ allowAbsolute: {
277
+ "const": true
278
+ }
279
+ }
280
+ },
281
+ {
282
+ properties: {
283
+ allowRelative: {
284
+ "const": true
285
+ }
286
+ }
287
+ }
288
+ ]
289
+ },
290
+ "else": {
291
+ additionalProperties: false,
292
+ properties: {
293
+ type: {
294
+ "enum": [
295
+ "string"
296
+ ]
297
+ },
298
+ title: {
299
+ type: "string"
300
+ },
301
+ description: {
302
+ type: "string"
303
+ },
304
+ "default": {
305
+ type: "string"
306
+ },
307
+ prefill: {
308
+ type: "string"
309
+ },
310
+ example: {
311
+ type: "string"
312
+ },
313
+ pattern: {
314
+ type: "string"
315
+ },
316
+ nullable: {
317
+ type: "boolean"
318
+ },
319
+ minLength: {
320
+ type: "integer"
321
+ },
322
+ maxLength: {
323
+ type: "integer"
324
+ },
325
+ editor: {
326
+ "enum": [
327
+ "javascript",
328
+ "python",
329
+ "textfield",
330
+ "textarea",
331
+ "datepicker",
332
+ "hidden",
333
+ "dataset",
334
+ "keyValueStore",
335
+ "requestQueue"
336
+ ]
337
+ },
338
+ isSecret: {
339
+ type: "boolean"
340
+ },
341
+ sectionCaption: {
342
+ type: "string"
343
+ },
344
+ sectionDescription: {
345
+ type: "string"
346
+ }
249
347
  }
250
348
  }
251
349
  },
@@ -687,6 +785,8 @@ type StringFieldDefinition = CommonFieldDefinition<string> & {
687
785
  enum?: readonly string[];
688
786
  enumTitles?: readonly string[];
689
787
  isSecret?: boolean;
788
+ allowAbsolute?: boolean;
789
+ allowRelative?: boolean;
690
790
  };
691
791
  type BooleanFieldDefinition = CommonFieldDefinition<boolean> & {
692
792
  type: 'boolean';
@@ -751,6 +851,7 @@ type InputSchema = {
751
851
  */
752
852
  declare function parseAjvError(error: ErrorObject, rootName: string, properties?: Record<string, {
753
853
  nullable?: boolean;
854
+ editor?: string;
754
855
  }>, input?: Record<string, unknown>): {
755
856
  fieldKey: string;
756
857
  message: string;
package/esm/index.mjs CHANGED
@@ -19,7 +19,12 @@ var intlStrings = {
19
19
  "inputSchema.validation.noAvailableAutoProxy": "Currently you do not have access to any proxy group usable in automatic mode.",
20
20
  "inputSchema.validation.noMatchingDefinition": "Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it's type is valid.",
21
21
  "inputSchema.validation.missingRequiredField": "Field schema.properties.{fieldKey} does not exist, but it is specified in schema.required. Either define the field or remove it from schema.required.",
22
- "inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings."
22
+ "inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings.",
23
+ "inputSchema.validation.datepickerInvalidFormatAbsolute": 'Field {rootName}.{fieldKey} must be a string in format "YYYY-MM-DD".',
24
+ "inputSchema.validation.datepickerInvalidFormatRelative": 'Field {rootName}.{fieldKey} must be a string in format "+/- number unit". Supported units are "day", "week", "month" and "year".',
25
+ "inputSchema.validation.datepickerInvalidFormatBoth": 'Field {rootName}.{fieldKey} must be a string in format "YYYY-MM-DD" or "+/- number unit". Supported units are "day", "week", "month" and "year".',
26
+ "inputSchema.validation.datepickerInvalidDate": "Field {rootName}.{fieldKey} must be a valid date.",
27
+ "inputSchema.validation.datepickerNoType": 'Field {rootName} must accept absolute, relative or both dates. Set "allowAbsolute", "allowRelative" or both properties.'
23
28
  };
24
29
  function m(stringId, variables) {
25
30
  let text = intlStrings[stringId];
@@ -136,22 +141,58 @@ var schema_default = {
136
141
  }
137
142
  },
138
143
  then: {
139
- additionalProperties: false,
140
- properties: {
141
- type: { enum: ["string"] },
142
- title: { type: "string" },
143
- description: { type: "string" },
144
- default: { type: "string" },
145
- prefill: { type: "string" },
146
- example: { type: "string" },
147
- pattern: { type: "string" },
148
- nullable: { type: "boolean" },
149
- minLength: { type: "integer" },
150
- maxLength: { type: "integer" },
151
- editor: { enum: ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "dataset", "keyValueStore", "requestQueue"] },
152
- isSecret: { type: "boolean" },
153
- sectionCaption: { type: "string" },
154
- sectionDescription: { type: "string" }
144
+ if: {
145
+ properties: {
146
+ editor: { const: "datepicker" }
147
+ }
148
+ },
149
+ then: {
150
+ additionalProperties: false,
151
+ properties: {
152
+ type: { enum: ["string"] },
153
+ title: { type: "string" },
154
+ description: { type: "string" },
155
+ default: { type: "string" },
156
+ prefill: { type: "string" },
157
+ example: { type: "string" },
158
+ pattern: { type: "string" },
159
+ nullable: { type: "boolean" },
160
+ minLength: { type: "integer" },
161
+ maxLength: { type: "integer" },
162
+ editor: { enum: ["datepicker"] },
163
+ sectionCaption: { type: "string" },
164
+ sectionDescription: { type: "string" },
165
+ allowAbsolute: { type: "boolean" },
166
+ allowRelative: { type: "boolean" }
167
+ },
168
+ if: {
169
+ required: ["allowAbsolute"],
170
+ properties: { allowAbsolute: { const: false } }
171
+ },
172
+ then: { required: ["type", "title", "description", "editor", "allowRelative"] },
173
+ anyOf: [
174
+ { properties: { allowAbsolute: { const: true } } },
175
+ { properties: { allowRelative: { const: true } } }
176
+ ]
177
+ },
178
+ else: {
179
+ additionalProperties: false,
180
+ properties: {
181
+ type: { enum: ["string"] },
182
+ title: { type: "string" },
183
+ description: { type: "string" },
184
+ default: { type: "string" },
185
+ prefill: { type: "string" },
186
+ example: { type: "string" },
187
+ pattern: { type: "string" },
188
+ nullable: { type: "boolean" },
189
+ minLength: { type: "integer" },
190
+ maxLength: { type: "integer" },
191
+ editor: { enum: ["javascript", "python", "textfield", "textarea", "datepicker", "hidden", "dataset", "keyValueStore", "requestQueue"] },
192
+ isSecret: { type: "boolean" },
193
+ sectionCaption: { type: "string" },
194
+ sectionDescription: { type: "string" }
195
+ }
155
196
  }
156
197
  },
157
198
  else: {
@@ -331,7 +372,11 @@ function parseAjvError(error, rootName, properties = {}, input = {}) {
331
372
  message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
332
373
  } else if (error.keyword === "required") {
333
374
  fieldKey = error.params.missingProperty;
334
- message = m("inputSchema.validation.required", { rootName, fieldKey });
375
+ if (fieldKey === "allowRelative") {
376
+ message = m("inputSchema.validation.datepickerNoType", { rootName });
377
+ } else {
378
+ message = m("inputSchema.validation.required", { rootName, fieldKey });
379
+ }
335
380
  } else if (error.keyword === "additionalProperties") {
336
381
  fieldKey = error.params.additionalProperty;
337
382
  message = m("inputSchema.validation.additionalProperty", { rootName, fieldKey });
@@ -339,6 +384,13 @@ function parseAjvError(error, rootName, properties = {}, input = {}) {
339
384
  fieldKey = error.instancePath.split("/").pop();
340
385
  const errorMessage = `${error.message}: "${error.params.allowedValues.join('", "')}"`;
341
386
  message = m("inputSchema.validation.generic", { rootName, fieldKey, message: errorMessage });
387
+ } else if (error.keyword === "const") {
388
+ fieldKey = error.instancePath.split("/").pop();
389
+ if (fieldKey === "allowRelative" || fieldKey === "allowAbsolute") {
390
+ message = m("inputSchema.validation.datepickerNoType", { rootName });
391
+ } else {
392
+ message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
393
+ }
342
394
  } else {
343
395
  fieldKey = error.instancePath.split("/").pop();
344
396
  message = m("inputSchema.validation.generic", { rootName, fieldKey, message: error.message });
@@ -481,7 +533,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
481
533
  }
482
534
  Object.keys(properties).forEach((property) => {
483
535
  const value = input[property];
484
- const { type, editor, patternKey, patternValue } = properties[property];
536
+ const { type, editor, patternKey, patternValue, allowAbsolute, allowRelative } = properties[property];
485
537
  const fieldErrors = [];
486
538
  if (type === "object" && editor === "proxy") {
487
539
  const proxyValidationErrors = validateProxyField(property, value, required.includes(property), options.proxy);
@@ -584,6 +636,39 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
584
636
  }
585
637
  }
586
638
  }
639
+ if (type === "string" && editor === "datepicker" && value && typeof value === "string") {
640
+ const acceptAbsolute = allowAbsolute !== false;
641
+ const acceptRelative = allowRelative === true;
642
+ const isValidAbsolute = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(value);
643
+ const isValidRelative = /^[+-] [0-9]+ (day|week|month|year)s?$/.test(value);
644
+ let isValidDate;
645
+ if (isValidAbsolute) {
646
+ const [year, month, day] = value.split("-").map(Number);
647
+ const date = /* @__PURE__ */ new Date(`${year}-${month}-${day}`);
648
+ isValidDate = date.getFullYear() === year && date.getMonth() + 1 === month && date.getDate() === day;
649
+ }
650
+ if (acceptAbsolute && !acceptRelative && !isValidAbsolute) {
651
+ fieldErrors.push(m("inputSchema.validation.datepickerInvalidFormatAbsolute", {
652
+ rootName: "input",
653
+ fieldKey: property
654
+ }));
655
+ } else if (acceptRelative && !acceptAbsolute && !isValidRelative) {
656
+ fieldErrors.push(m("inputSchema.validation.datepickerInvalidFormatRelative", {
657
+ rootName: "input",
658
+ fieldKey: property
659
+ }));
660
+ } else if (acceptAbsolute && !acceptRelative && !isValidAbsolute || acceptRelative && !acceptAbsolute && !isValidRelative || acceptRelative && acceptAbsolute && !isValidAbsolute && !isValidRelative) {
661
+ fieldErrors.push(m("inputSchema.validation.datepickerInvalidFormatBoth", {
662
+ rootName: "input",
663
+ fieldKey: property
664
+ }));
665
+ } else if (isValidDate === false && acceptAbsolute) {
666
+ fieldErrors.push(m("inputSchema.validation.datepickerInvalidDate", {
667
+ rootName: "input",
668
+ fieldKey: property
669
+ }));
670
+ }
671
+ }
587
672
  if (fieldErrors.length > 0) {
588
673
  const message = fieldErrors.join(", ");
589
674
  errors.push({ fieldKey: property, message });