• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-node-sdk / 19948713113

04 Dec 2025 02:32PM UTC coverage: 40.741% (+0.005%) from 40.736%
19948713113

push

github

web-flow
feat: update error message on exception (box/box-codegen#896) (#1233)

4578 of 19701 branches covered (23.24%)

Branch coverage included in aggregate %.

4 of 4 new or added lines in 2 files covered. (100.0%)

65 existing lines in 2 files now uncovered.

16742 of 32629 relevant lines covered (51.31%)

142.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.83
/src/schemas/aiExtractStructured.ts
1
import { serializeAiAgentReference } from './aiAgentReference';
2
import { deserializeAiAgentReference } from './aiAgentReference';
3
import { serializeAiAgentExtractStructured } from './aiAgentExtractStructured';
4
import { deserializeAiAgentExtractStructured } from './aiAgentExtractStructured';
5
import { serializeAiItemBase } from './aiItemBase';
237✔
6
import { deserializeAiItemBase } from './aiItemBase';
237✔
7
import { serializeAiExtractStructuredAgent } from './aiExtractStructuredAgent';
237✔
8
import { deserializeAiExtractStructuredAgent } from './aiExtractStructuredAgent';
237✔
9
import { AiAgentReference } from './aiAgentReference';
10
import { AiAgentExtractStructured } from './aiAgentExtractStructured';
11
import { AiItemBase } from './aiItemBase';
12
import { AiExtractStructuredAgent } from './aiExtractStructuredAgent';
13
import { BoxSdkError } from '../box/errors';
237✔
14
import { SerializedData } from '../serialization/json';
15
import { sdIsEmpty } from '../serialization/json';
16
import { sdIsBoolean } from '../serialization/json';
237✔
17
import { sdIsNumber } from '../serialization/json';
18
import { sdIsString } from '../serialization/json';
237✔
19
import { sdIsList } from '../serialization/json';
237✔
20
import { sdIsMap } from '../serialization/json';
237✔
21
export type AiExtractStructuredMetadataTemplateTypeField = 'metadata_template';
22
export interface AiExtractStructuredMetadataTemplateField {
23
  /**
24
   * The name of the metadata template. */
25
  readonly templateKey?: string;
26
  /**
27
   * Value is always `metadata_template`. */
28
  readonly type?: AiExtractStructuredMetadataTemplateTypeField;
29
  /**
30
   * The scope of the metadata template that can either be global or
31
   * enterprise.
32
   * * The **global** scope is used for templates that are
33
   * available to any Box enterprise.
34
   * * The **enterprise** scope represents templates created within a specific enterprise,
35
   *   containing the ID of that enterprise. */
36
  readonly scope?: string;
37
  readonly rawData?: SerializedData;
38
}
39
export interface AiExtractStructuredFieldsOptionsField {
40
  /**
41
   * A unique identifier for the field. */
42
  readonly key: string;
43
  readonly rawData?: SerializedData;
44
}
45
export interface AiExtractStructuredFieldsField {
46
  /**
47
   * A unique identifier for the field. */
48
  readonly key: string;
49
  /**
50
   * A description of the field. */
51
  readonly description?: string;
52
  /**
53
   * The display name of the field. */
54
  readonly displayName?: string;
55
  /**
56
   * The context about the key that may include how to find and format it. */
57
  readonly prompt?: string;
58
  /**
59
   * The type of the field. It include but is not limited to string, float, date, enum, and multiSelect. */
60
  readonly type?: string;
61
  /**
62
   * A list of options for this field. This is most often used in combination with the enum and multiSelect field types. */
63
  readonly options?: readonly AiExtractStructuredFieldsOptionsField[];
64
  readonly rawData?: SerializedData;
65
}
66
export interface AiExtractStructured {
67
  /**
68
   * The items to be processed by the LLM. Currently you can use files only. */
69
  readonly items: readonly AiItemBase[];
70
  /**
71
   * The metadata template containing the fields to extract.
72
   * For your request to work, you must provide either `metadata_template` or `fields`, but not both. */
73
  readonly metadataTemplate?: AiExtractStructuredMetadataTemplateField;
74
  /**
75
   * The fields to be extracted from the provided items.
76
   * For your request to work, you must provide either `metadata_template` or `fields`, but not both. */
77
  readonly fields?: readonly AiExtractStructuredFieldsField[];
78
  /**
79
   * A flag to indicate whether confidence scores for every extracted field should be returned. */
80
  readonly includeConfidenceScore?: boolean;
81
  readonly aiAgent?: AiExtractStructuredAgent;
82
  readonly rawData?: SerializedData;
83
}
84
export function serializeAiExtractStructuredMetadataTemplateTypeField(
237✔
85
  val: AiExtractStructuredMetadataTemplateTypeField,
86
): SerializedData {
UNCOV
87
  return val;
×
88
}
89
export function deserializeAiExtractStructuredMetadataTemplateTypeField(
237✔
90
  val: SerializedData,
91
): AiExtractStructuredMetadataTemplateTypeField {
92
  if (val == 'metadata_template') {
×
UNCOV
93
    return val;
×
94
  }
UNCOV
95
  throw new BoxSdkError({
×
96
    message: "Can't deserialize AiExtractStructuredMetadataTemplateTypeField",
97
  });
98
}
99
export function serializeAiExtractStructuredMetadataTemplateField(
237✔
100
  val: AiExtractStructuredMetadataTemplateField,
101
): SerializedData {
102
  return {
3✔
103
    ['template_key']: val.templateKey,
104
    ['type']:
105
      val.type == void 0
3!
106
        ? val.type
107
        : serializeAiExtractStructuredMetadataTemplateTypeField(val.type),
108
    ['scope']: val.scope,
109
  };
110
}
111
export function deserializeAiExtractStructuredMetadataTemplateField(
237✔
112
  val: SerializedData,
113
): AiExtractStructuredMetadataTemplateField {
UNCOV
114
  if (!sdIsMap(val)) {
×
UNCOV
115
    throw new BoxSdkError({
×
116
      message: 'Expecting a map for "AiExtractStructuredMetadataTemplateField"',
117
    });
118
  }
UNCOV
119
  if (!(val.template_key == void 0) && !sdIsString(val.template_key)) {
×
UNCOV
120
    throw new BoxSdkError({
×
121
      message:
122
        'Expecting string for "template_key" of type "AiExtractStructuredMetadataTemplateField"',
123
    });
124
  }
125
  const templateKey: undefined | string =
UNCOV
126
    val.template_key == void 0 ? void 0 : val.template_key;
×
127
  const type: undefined | AiExtractStructuredMetadataTemplateTypeField =
128
    val.type == void 0
×
129
      ? void 0
130
      : deserializeAiExtractStructuredMetadataTemplateTypeField(val.type);
UNCOV
131
  if (!(val.scope == void 0) && !sdIsString(val.scope)) {
×
UNCOV
132
    throw new BoxSdkError({
×
133
      message:
134
        'Expecting string for "scope" of type "AiExtractStructuredMetadataTemplateField"',
135
    });
136
  }
UNCOV
137
  const scope: undefined | string = val.scope == void 0 ? void 0 : val.scope;
×
UNCOV
138
  return {
×
139
    templateKey: templateKey,
140
    type: type,
141
    scope: scope,
142
  } satisfies AiExtractStructuredMetadataTemplateField;
143
}
144
export function serializeAiExtractStructuredFieldsOptionsField(
237✔
145
  val: AiExtractStructuredFieldsOptionsField,
146
): SerializedData {
147
  return { ['key']: val.key };
6✔
148
}
149
export function deserializeAiExtractStructuredFieldsOptionsField(
237✔
150
  val: SerializedData,
151
): AiExtractStructuredFieldsOptionsField {
UNCOV
152
  if (!sdIsMap(val)) {
×
UNCOV
153
    throw new BoxSdkError({
×
154
      message: 'Expecting a map for "AiExtractStructuredFieldsOptionsField"',
155
    });
156
  }
UNCOV
157
  if (val.key == void 0) {
×
UNCOV
158
    throw new BoxSdkError({
×
159
      message:
160
        'Expecting "key" of type "AiExtractStructuredFieldsOptionsField" to be defined',
161
    });
162
  }
UNCOV
163
  if (!sdIsString(val.key)) {
×
UNCOV
164
    throw new BoxSdkError({
×
165
      message:
166
        'Expecting string for "key" of type "AiExtractStructuredFieldsOptionsField"',
167
    });
168
  }
UNCOV
169
  const key: string = val.key;
×
UNCOV
170
  return { key: key } satisfies AiExtractStructuredFieldsOptionsField;
×
171
}
172
export function serializeAiExtractStructuredFieldsField(
237✔
173
  val: AiExtractStructuredFieldsField,
174
): SerializedData {
175
  return {
15✔
176
    ['key']: val.key,
177
    ['description']: val.description,
178
    ['displayName']: val.displayName,
179
    ['prompt']: val.prompt,
180
    ['type']: val.type,
181
    ['options']:
182
      val.options == void 0
15✔
183
        ? val.options
184
        : (val.options.map(function (
185
            item: AiExtractStructuredFieldsOptionsField,
186
          ): SerializedData {
187
            return serializeAiExtractStructuredFieldsOptionsField(item);
6✔
188
          }) as readonly any[]),
189
  };
190
}
191
export function deserializeAiExtractStructuredFieldsField(
237✔
192
  val: SerializedData,
193
): AiExtractStructuredFieldsField {
UNCOV
194
  if (!sdIsMap(val)) {
×
UNCOV
195
    throw new BoxSdkError({
×
196
      message: 'Expecting a map for "AiExtractStructuredFieldsField"',
197
    });
198
  }
UNCOV
199
  if (val.key == void 0) {
×
UNCOV
200
    throw new BoxSdkError({
×
201
      message:
202
        'Expecting "key" of type "AiExtractStructuredFieldsField" to be defined',
203
    });
204
  }
UNCOV
205
  if (!sdIsString(val.key)) {
×
UNCOV
206
    throw new BoxSdkError({
×
207
      message:
208
        'Expecting string for "key" of type "AiExtractStructuredFieldsField"',
209
    });
210
  }
UNCOV
211
  const key: string = val.key;
×
UNCOV
212
  if (!(val.description == void 0) && !sdIsString(val.description)) {
×
UNCOV
213
    throw new BoxSdkError({
×
214
      message:
215
        'Expecting string for "description" of type "AiExtractStructuredFieldsField"',
216
    });
217
  }
218
  const description: undefined | string =
UNCOV
219
    val.description == void 0 ? void 0 : val.description;
×
UNCOV
220
  if (!(val.displayName == void 0) && !sdIsString(val.displayName)) {
×
UNCOV
221
    throw new BoxSdkError({
×
222
      message:
223
        'Expecting string for "displayName" of type "AiExtractStructuredFieldsField"',
224
    });
225
  }
226
  const displayName: undefined | string =
UNCOV
227
    val.displayName == void 0 ? void 0 : val.displayName;
×
UNCOV
228
  if (!(val.prompt == void 0) && !sdIsString(val.prompt)) {
×
UNCOV
229
    throw new BoxSdkError({
×
230
      message:
231
        'Expecting string for "prompt" of type "AiExtractStructuredFieldsField"',
232
    });
233
  }
UNCOV
234
  const prompt: undefined | string = val.prompt == void 0 ? void 0 : val.prompt;
×
UNCOV
235
  if (!(val.type == void 0) && !sdIsString(val.type)) {
×
UNCOV
236
    throw new BoxSdkError({
×
237
      message:
238
        'Expecting string for "type" of type "AiExtractStructuredFieldsField"',
239
    });
240
  }
UNCOV
241
  const type: undefined | string = val.type == void 0 ? void 0 : val.type;
×
UNCOV
242
  if (!(val.options == void 0) && !sdIsList(val.options)) {
×
UNCOV
243
    throw new BoxSdkError({
×
244
      message:
245
        'Expecting array for "options" of type "AiExtractStructuredFieldsField"',
246
    });
247
  }
248
  const options: undefined | readonly AiExtractStructuredFieldsOptionsField[] =
UNCOV
249
    val.options == void 0
×
250
      ? void 0
251
      : sdIsList(val.options)
×
252
        ? (val.options.map(function (
253
            itm: SerializedData,
254
          ): AiExtractStructuredFieldsOptionsField {
255
            return deserializeAiExtractStructuredFieldsOptionsField(itm);
×
256
          }) as readonly any[])
257
        : [];
UNCOV
258
  return {
×
259
    key: key,
260
    description: description,
261
    displayName: displayName,
262
    prompt: prompt,
263
    type: type,
264
    options: options,
265
  } satisfies AiExtractStructuredFieldsField;
266
}
267
export function serializeAiExtractStructured(
237✔
268
  val: AiExtractStructured,
269
): SerializedData {
270
  return {
6✔
271
    ['items']: val.items.map(function (item: AiItemBase): SerializedData {
272
      return serializeAiItemBase(item);
6✔
273
    }) as readonly any[],
274
    ['metadata_template']:
275
      val.metadataTemplate == void 0
6✔
276
        ? val.metadataTemplate
277
        : serializeAiExtractStructuredMetadataTemplateField(
278
            val.metadataTemplate,
279
          ),
280
    ['fields']:
281
      val.fields == void 0
6✔
282
        ? val.fields
283
        : (val.fields.map(function (
284
            item: AiExtractStructuredFieldsField,
285
          ): SerializedData {
286
            return serializeAiExtractStructuredFieldsField(item);
15✔
287
          }) as readonly any[]),
288
    ['include_confidence_score']: val.includeConfidenceScore,
289
    ['ai_agent']:
290
      val.aiAgent == void 0
6✔
291
        ? val.aiAgent
292
        : serializeAiExtractStructuredAgent(val.aiAgent),
293
  };
294
}
295
export function deserializeAiExtractStructured(
237✔
296
  val: SerializedData,
297
): AiExtractStructured {
UNCOV
298
  if (!sdIsMap(val)) {
×
299
    throw new BoxSdkError({
×
300
      message: 'Expecting a map for "AiExtractStructured"',
301
    });
302
  }
UNCOV
303
  if (val.items == void 0) {
×
304
    throw new BoxSdkError({
×
305
      message: 'Expecting "items" of type "AiExtractStructured" to be defined',
306
    });
307
  }
UNCOV
308
  if (!sdIsList(val.items)) {
×
309
    throw new BoxSdkError({
×
310
      message: 'Expecting array for "items" of type "AiExtractStructured"',
311
    });
312
  }
UNCOV
313
  const items: readonly AiItemBase[] = sdIsList(val.items)
×
314
    ? (val.items.map(function (itm: SerializedData): AiItemBase {
315
        return deserializeAiItemBase(itm);
×
316
      }) as readonly any[])
317
    : [];
318
  const metadataTemplate: undefined | AiExtractStructuredMetadataTemplateField =
UNCOV
319
    val.metadata_template == void 0
×
320
      ? void 0
321
      : deserializeAiExtractStructuredMetadataTemplateField(
322
          val.metadata_template,
323
        );
UNCOV
324
  if (!(val.fields == void 0) && !sdIsList(val.fields)) {
×
UNCOV
325
    throw new BoxSdkError({
×
326
      message: 'Expecting array for "fields" of type "AiExtractStructured"',
327
    });
328
  }
329
  const fields: undefined | readonly AiExtractStructuredFieldsField[] =
UNCOV
330
    val.fields == void 0
×
331
      ? void 0
332
      : sdIsList(val.fields)
×
333
        ? (val.fields.map(function (
334
            itm: SerializedData,
335
          ): AiExtractStructuredFieldsField {
336
            return deserializeAiExtractStructuredFieldsField(itm);
×
337
          }) as readonly any[])
338
        : [];
339
  if (
×
340
    !(val.include_confidence_score == void 0) &&
×
341
    !sdIsBoolean(val.include_confidence_score)
342
  ) {
UNCOV
343
    throw new BoxSdkError({
×
344
      message:
345
        'Expecting boolean for "include_confidence_score" of type "AiExtractStructured"',
346
    });
347
  }
348
  const includeConfidenceScore: undefined | boolean =
UNCOV
349
    val.include_confidence_score == void 0
×
350
      ? void 0
351
      : val.include_confidence_score;
352
  const aiAgent: undefined | AiExtractStructuredAgent =
UNCOV
353
    val.ai_agent == void 0
×
354
      ? void 0
355
      : deserializeAiExtractStructuredAgent(val.ai_agent);
UNCOV
356
  return {
×
357
    items: items,
358
    metadataTemplate: metadataTemplate,
359
    fields: fields,
360
    includeConfidenceScore: includeConfidenceScore,
361
    aiAgent: aiAgent,
362
  } satisfies AiExtractStructured;
363
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc