@kadoa/node-sdk 0.12.0 → 0.13.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/README.md +225 -188
- package/dist/browser/index.global.js +13 -13
- package/dist/browser/index.global.js.map +1 -1
- package/dist/index.d.mts +280 -100
- package/dist/index.d.ts +280 -100
- package/dist/index.js +247 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +248 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -26,7 +26,9 @@ var KadoaErrorCode = {
|
|
|
26
26
|
AUTH_ERROR: "AUTH_ERROR",
|
|
27
27
|
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
28
28
|
BAD_REQUEST: "BAD_REQUEST",
|
|
29
|
-
NOT_FOUND: "NOT_FOUND"
|
|
29
|
+
NOT_FOUND: "NOT_FOUND",
|
|
30
|
+
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
31
|
+
};
|
|
30
32
|
var _KadoaSdkException = class _KadoaSdkException extends Error {
|
|
31
33
|
constructor(message, options) {
|
|
32
34
|
super(message);
|
|
@@ -108,7 +110,10 @@ _KadoaSdkException.ERROR_MESSAGES = {
|
|
|
108
110
|
// Schema specific errors
|
|
109
111
|
SCHEMA_NOT_FOUND: "Schema not found",
|
|
110
112
|
SCHEMA_FETCH_ERROR: "Failed to fetch schema",
|
|
111
|
-
SCHEMAS_FETCH_ERROR: "Failed to fetch schemas"
|
|
113
|
+
SCHEMAS_FETCH_ERROR: "Failed to fetch schemas",
|
|
114
|
+
SCHEMA_CREATE_FAILED: "Failed to create schema",
|
|
115
|
+
SCHEMA_UPDATE_FAILED: "Failed to update schema",
|
|
116
|
+
SCHEMA_DELETE_FAILED: "Failed to delete schema"
|
|
112
117
|
};
|
|
113
118
|
var KadoaSdkException = _KadoaSdkException;
|
|
114
119
|
var ERROR_MESSAGES = KadoaSdkException.ERROR_MESSAGES;
|
|
@@ -4054,7 +4059,7 @@ var Configuration = class {
|
|
|
4054
4059
|
};
|
|
4055
4060
|
|
|
4056
4061
|
// src/version.ts
|
|
4057
|
-
var SDK_VERSION = "0.
|
|
4062
|
+
var SDK_VERSION = "0.13.0";
|
|
4058
4063
|
var SDK_NAME = "kadoa-node-sdk";
|
|
4059
4064
|
var SDK_LANGUAGE = "node";
|
|
4060
4065
|
|
|
@@ -4490,12 +4495,197 @@ var NotificationsModule = class {
|
|
|
4490
4495
|
return this.settingsService;
|
|
4491
4496
|
}
|
|
4492
4497
|
};
|
|
4498
|
+
var _SchemaBuilder = class _SchemaBuilder {
|
|
4499
|
+
constructor() {
|
|
4500
|
+
this.fields = [];
|
|
4501
|
+
}
|
|
4502
|
+
entity(entityName) {
|
|
4503
|
+
this.entityName = entityName;
|
|
4504
|
+
return this;
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* Add a structured field to the schema
|
|
4508
|
+
* @param name - Field name (alphanumeric only)
|
|
4509
|
+
* @param description - Field description
|
|
4510
|
+
* @param dataType - Data type (STRING, NUMBER, BOOLEAN, etc.)
|
|
4511
|
+
* @param options - Optional field configuration
|
|
4512
|
+
*/
|
|
4513
|
+
field(name, description, dataType, options) {
|
|
4514
|
+
this.validateFieldName(name);
|
|
4515
|
+
const requiresExample = _SchemaBuilder.TYPES_REQUIRING_EXAMPLE.includes(dataType);
|
|
4516
|
+
if (requiresExample && !options?.example) {
|
|
4517
|
+
throw new KadoaSdkException(
|
|
4518
|
+
`Field "${name}" with type ${dataType} requires an example`,
|
|
4519
|
+
{ code: "VALIDATION_ERROR", details: { name, dataType } }
|
|
4520
|
+
);
|
|
4521
|
+
}
|
|
4522
|
+
this.fields.push({
|
|
4523
|
+
name,
|
|
4524
|
+
description,
|
|
4525
|
+
dataType,
|
|
4526
|
+
fieldType: "SCHEMA",
|
|
4527
|
+
example: options?.example,
|
|
4528
|
+
isKey: options?.isKey
|
|
4529
|
+
});
|
|
4530
|
+
return this;
|
|
4531
|
+
}
|
|
4532
|
+
/**
|
|
4533
|
+
* Add a classification field to categorize content
|
|
4534
|
+
* @param name - Field name (alphanumeric only)
|
|
4535
|
+
* @param description - Field description
|
|
4536
|
+
* @param categories - Array of category definitions
|
|
4537
|
+
*/
|
|
4538
|
+
classify(name, description, categories) {
|
|
4539
|
+
this.validateFieldName(name);
|
|
4540
|
+
this.fields.push({
|
|
4541
|
+
name,
|
|
4542
|
+
description,
|
|
4543
|
+
fieldType: "CLASSIFICATION",
|
|
4544
|
+
categories
|
|
4545
|
+
});
|
|
4546
|
+
return this;
|
|
4547
|
+
}
|
|
4548
|
+
/**
|
|
4549
|
+
* Add raw page content to extract
|
|
4550
|
+
* @param name - Raw content format(s): "html", "markdown", or "url"
|
|
4551
|
+
*/
|
|
4552
|
+
raw(name) {
|
|
4553
|
+
const names = Array.isArray(name) ? name : [name];
|
|
4554
|
+
for (const name2 of names) {
|
|
4555
|
+
const fieldName = `raw${esToolkit.upperFirst(esToolkit.camelCase(name2))}`;
|
|
4556
|
+
if (this.fields.some((field) => field.name === fieldName)) {
|
|
4557
|
+
continue;
|
|
4558
|
+
}
|
|
4559
|
+
this.fields.push({
|
|
4560
|
+
name: fieldName,
|
|
4561
|
+
description: `Raw page content in ${name2.toUpperCase()} format`,
|
|
4562
|
+
fieldType: "METADATA",
|
|
4563
|
+
metadataKey: name2
|
|
4564
|
+
});
|
|
4565
|
+
}
|
|
4566
|
+
return this;
|
|
4567
|
+
}
|
|
4568
|
+
build() {
|
|
4569
|
+
if (!this.entityName) {
|
|
4570
|
+
throw new KadoaSdkException("Entity name is required", {
|
|
4571
|
+
code: "VALIDATION_ERROR",
|
|
4572
|
+
details: { entityName: this.entityName }
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
return {
|
|
4576
|
+
entityName: this.entityName,
|
|
4577
|
+
fields: this.fields
|
|
4578
|
+
};
|
|
4579
|
+
}
|
|
4580
|
+
validateFieldName(name) {
|
|
4581
|
+
if (!_SchemaBuilder.FIELD_NAME_PATTERN.test(name)) {
|
|
4582
|
+
throw new KadoaSdkException(
|
|
4583
|
+
`Field name "${name}" must be alphanumeric only (no underscores or special characters)`,
|
|
4584
|
+
{
|
|
4585
|
+
code: "VALIDATION_ERROR",
|
|
4586
|
+
details: { name, pattern: "^[A-Za-z0-9]+$" }
|
|
4587
|
+
}
|
|
4588
|
+
);
|
|
4589
|
+
}
|
|
4590
|
+
const lowerName = name.toLowerCase();
|
|
4591
|
+
if (this.fields.some((f) => f.name.toLowerCase() === lowerName)) {
|
|
4592
|
+
throw new KadoaSdkException(`Duplicate field name: "${name}"`, {
|
|
4593
|
+
code: "VALIDATION_ERROR",
|
|
4594
|
+
details: { name }
|
|
4595
|
+
});
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
};
|
|
4599
|
+
_SchemaBuilder.FIELD_NAME_PATTERN = /^[A-Za-z0-9]+$/;
|
|
4600
|
+
_SchemaBuilder.TYPES_REQUIRING_EXAMPLE = [
|
|
4601
|
+
"STRING",
|
|
4602
|
+
"IMAGE",
|
|
4603
|
+
"LINK",
|
|
4604
|
+
"OBJECT",
|
|
4605
|
+
"ARRAY"
|
|
4606
|
+
];
|
|
4607
|
+
var SchemaBuilder = _SchemaBuilder;
|
|
4493
4608
|
|
|
4494
4609
|
// src/modules/schemas.module.ts
|
|
4610
|
+
var SchemaBuilderWithCreate = class extends SchemaBuilder {
|
|
4611
|
+
constructor(entityName, service) {
|
|
4612
|
+
super();
|
|
4613
|
+
this.service = service;
|
|
4614
|
+
this.entity(entityName);
|
|
4615
|
+
}
|
|
4616
|
+
/**
|
|
4617
|
+
* Create the schema directly in Kadoa
|
|
4618
|
+
* @param name - Optional schema name (defaults to entity name)
|
|
4619
|
+
* @returns Promise resolving to the created schema
|
|
4620
|
+
*/
|
|
4621
|
+
async create(name) {
|
|
4622
|
+
const built = this.build();
|
|
4623
|
+
return this.service.createSchema({
|
|
4624
|
+
name: name || built.entityName,
|
|
4625
|
+
entity: built.entityName,
|
|
4626
|
+
fields: built.fields
|
|
4627
|
+
});
|
|
4628
|
+
}
|
|
4629
|
+
};
|
|
4495
4630
|
var SchemasModule = class {
|
|
4496
4631
|
constructor(service) {
|
|
4497
4632
|
this.service = service;
|
|
4498
4633
|
}
|
|
4634
|
+
/**
|
|
4635
|
+
* Create a new schema builder for fluent schema definition
|
|
4636
|
+
* @param entityName - The name of the entity this schema represents
|
|
4637
|
+
* @returns A new SchemaBuilder instance with the entity name already set
|
|
4638
|
+
* @example Build then create
|
|
4639
|
+
* ```typescript
|
|
4640
|
+
* const schema = kadoa.schema.builder("Product")
|
|
4641
|
+
* .field("title", "Product name", "STRING", { example: "iPhone 15" })
|
|
4642
|
+
* .field("price", "Product price", "NUMBER")
|
|
4643
|
+
* .build();
|
|
4644
|
+
*
|
|
4645
|
+
* await kadoa.schema.create(schema);
|
|
4646
|
+
* ```
|
|
4647
|
+
*
|
|
4648
|
+
* @example Fluent chain with create
|
|
4649
|
+
* ```typescript
|
|
4650
|
+
* const schema = await kadoa.schema.builder("Product")
|
|
4651
|
+
* .field("title", "Product name", "STRING", { example: "iPhone 15" })
|
|
4652
|
+
* .field("price", "Product price", "NUMBER")
|
|
4653
|
+
* .create("Product Schema");
|
|
4654
|
+
* ```
|
|
4655
|
+
*/
|
|
4656
|
+
builder(entityName) {
|
|
4657
|
+
return new SchemaBuilderWithCreate(entityName, this.service);
|
|
4658
|
+
}
|
|
4659
|
+
/**
|
|
4660
|
+
* Get a schema by ID
|
|
4661
|
+
*/
|
|
4662
|
+
async get(schemaId) {
|
|
4663
|
+
return this.service.getSchema(schemaId);
|
|
4664
|
+
}
|
|
4665
|
+
/**
|
|
4666
|
+
* List all schemas
|
|
4667
|
+
*/
|
|
4668
|
+
async list() {
|
|
4669
|
+
return this.service.listSchemas();
|
|
4670
|
+
}
|
|
4671
|
+
/**
|
|
4672
|
+
* Create a new schema from a body
|
|
4673
|
+
*/
|
|
4674
|
+
async create(body) {
|
|
4675
|
+
return this.service.createSchema(body);
|
|
4676
|
+
}
|
|
4677
|
+
/**
|
|
4678
|
+
* Update an existing schema
|
|
4679
|
+
*/
|
|
4680
|
+
async update(schemaId, body) {
|
|
4681
|
+
return this.service.updateSchema(schemaId, body);
|
|
4682
|
+
}
|
|
4683
|
+
/**
|
|
4684
|
+
* Delete a schema
|
|
4685
|
+
*/
|
|
4686
|
+
async delete(schemaId) {
|
|
4687
|
+
return this.service.deleteSchema(schemaId);
|
|
4688
|
+
}
|
|
4499
4689
|
};
|
|
4500
4690
|
|
|
4501
4691
|
// src/modules/user.module.ts
|
|
@@ -5312,7 +5502,6 @@ var SchemasService = class {
|
|
|
5312
5502
|
}
|
|
5313
5503
|
/**
|
|
5314
5504
|
* Get a schema by ID
|
|
5315
|
-
* //todo: use proper schema type for response from generated client (when avaialble)
|
|
5316
5505
|
*/
|
|
5317
5506
|
async getSchema(schemaId) {
|
|
5318
5507
|
debug4("Fetching schema with ID: %s", schemaId);
|
|
@@ -5331,6 +5520,49 @@ var SchemasService = class {
|
|
|
5331
5520
|
}
|
|
5332
5521
|
return schemaData;
|
|
5333
5522
|
}
|
|
5523
|
+
/**
|
|
5524
|
+
* List all schemas
|
|
5525
|
+
*/
|
|
5526
|
+
async listSchemas() {
|
|
5527
|
+
const response = await this.schemasApi.v4SchemasGet();
|
|
5528
|
+
return response.data.data;
|
|
5529
|
+
}
|
|
5530
|
+
/**
|
|
5531
|
+
* Create a new schema
|
|
5532
|
+
*/
|
|
5533
|
+
async createSchema(body) {
|
|
5534
|
+
debug4("Creating schema with name: %s", body.name);
|
|
5535
|
+
const response = await this.schemasApi.v4SchemasPost({
|
|
5536
|
+
createSchemaBody: body
|
|
5537
|
+
});
|
|
5538
|
+
const schemaId = response.data.schemaId;
|
|
5539
|
+
if (!schemaId) {
|
|
5540
|
+
throw new KadoaSdkException(ERROR_MESSAGES.SCHEMA_CREATE_FAILED, {
|
|
5541
|
+
code: KadoaErrorCode.INTERNAL_ERROR
|
|
5542
|
+
});
|
|
5543
|
+
}
|
|
5544
|
+
return this.getSchema(schemaId);
|
|
5545
|
+
}
|
|
5546
|
+
/**
|
|
5547
|
+
* Update an existing schema
|
|
5548
|
+
*/
|
|
5549
|
+
async updateSchema(schemaId, body) {
|
|
5550
|
+
debug4("Updating schema with ID: %s", schemaId);
|
|
5551
|
+
await this.schemasApi.v4SchemasSchemaIdPut({
|
|
5552
|
+
schemaId,
|
|
5553
|
+
updateSchemaBody: body
|
|
5554
|
+
});
|
|
5555
|
+
return this.getSchema(schemaId);
|
|
5556
|
+
}
|
|
5557
|
+
/**
|
|
5558
|
+
* Delete a schema
|
|
5559
|
+
*/
|
|
5560
|
+
async deleteSchema(schemaId) {
|
|
5561
|
+
debug4("Deleting schema with ID: %s", schemaId);
|
|
5562
|
+
await this.schemasApi.v4SchemasSchemaIdDelete({
|
|
5563
|
+
schemaId
|
|
5564
|
+
});
|
|
5565
|
+
}
|
|
5334
5566
|
};
|
|
5335
5567
|
|
|
5336
5568
|
// src/internal/domains/notifications/notification-setup.service.ts
|
|
@@ -5801,12 +6033,12 @@ var EntityResolverService = class {
|
|
|
5801
6033
|
fields: entityPrediction.fields
|
|
5802
6034
|
};
|
|
5803
6035
|
} else if (entityConfig) {
|
|
5804
|
-
if ("
|
|
6036
|
+
if ("schemaId" in entityConfig) {
|
|
5805
6037
|
const schema = await this.schemasService.getSchema(
|
|
5806
|
-
entityConfig.
|
|
6038
|
+
entityConfig.schemaId
|
|
5807
6039
|
);
|
|
5808
6040
|
return {
|
|
5809
|
-
entity: schema.entity,
|
|
6041
|
+
entity: schema.entity ?? "",
|
|
5810
6042
|
fields: schema.schema
|
|
5811
6043
|
};
|
|
5812
6044
|
} else if ("name" in entityConfig && "fields" in entityConfig) {
|
|
@@ -5867,187 +6099,6 @@ var EntityResolverService = class {
|
|
|
5867
6099
|
}
|
|
5868
6100
|
}
|
|
5869
6101
|
};
|
|
5870
|
-
|
|
5871
|
-
// src/internal/domains/extraction/builders/extraction-builder.ts
|
|
5872
|
-
var ExtractionBuilder = class {
|
|
5873
|
-
constructor() {
|
|
5874
|
-
this.fields = [];
|
|
5875
|
-
}
|
|
5876
|
-
/**
|
|
5877
|
-
* Start defining a custom schema with fields
|
|
5878
|
-
* @param name - The entity name (e.g., "Product", "Article")
|
|
5879
|
-
*/
|
|
5880
|
-
schema(name) {
|
|
5881
|
-
if (this.schemaId) {
|
|
5882
|
-
throw new KadoaSdkException(
|
|
5883
|
-
"Cannot use schema() after useSchema() - they are mutually exclusive",
|
|
5884
|
-
{ code: "VALIDATION_ERROR" }
|
|
5885
|
-
);
|
|
5886
|
-
}
|
|
5887
|
-
this.schemaName = name;
|
|
5888
|
-
return new SchemaBuilder(this);
|
|
5889
|
-
}
|
|
5890
|
-
/**
|
|
5891
|
-
* Use an existing schema by ID
|
|
5892
|
-
* @param schemaId - The schema ID to reference
|
|
5893
|
-
*/
|
|
5894
|
-
useSchema(schemaId) {
|
|
5895
|
-
if (this.schemaName || this.fields.length > 0) {
|
|
5896
|
-
throw new KadoaSdkException(
|
|
5897
|
-
"Cannot use useSchema() after schema() or field definitions - they are mutually exclusive",
|
|
5898
|
-
{ code: "VALIDATION_ERROR" }
|
|
5899
|
-
);
|
|
5900
|
-
}
|
|
5901
|
-
this.schemaId = schemaId;
|
|
5902
|
-
return this;
|
|
5903
|
-
}
|
|
5904
|
-
/**
|
|
5905
|
-
* Extract raw page content without transformation
|
|
5906
|
-
* @param format - Raw content format(s): "html", "markdown", or "url"
|
|
5907
|
-
*/
|
|
5908
|
-
raw(format) {
|
|
5909
|
-
const formats = Array.isArray(format) ? format : [format];
|
|
5910
|
-
const nameMap = {
|
|
5911
|
-
html: "rawHtml",
|
|
5912
|
-
markdown: "rawMarkdown",
|
|
5913
|
-
url: "rawUrl"
|
|
5914
|
-
};
|
|
5915
|
-
const metadataKeyMap = {
|
|
5916
|
-
html: "HTML",
|
|
5917
|
-
markdown: "MARKDOWN",
|
|
5918
|
-
url: "PAGE_URL"
|
|
5919
|
-
};
|
|
5920
|
-
for (const f of formats) {
|
|
5921
|
-
const fieldName = nameMap[f];
|
|
5922
|
-
if (this.fields.some((field) => field.name === fieldName)) {
|
|
5923
|
-
continue;
|
|
5924
|
-
}
|
|
5925
|
-
this.fields.push({
|
|
5926
|
-
name: fieldName,
|
|
5927
|
-
description: `Raw page content in ${f.toUpperCase()} format`,
|
|
5928
|
-
fieldType: "METADATA",
|
|
5929
|
-
metadataKey: metadataKeyMap[f]
|
|
5930
|
-
});
|
|
5931
|
-
}
|
|
5932
|
-
return this;
|
|
5933
|
-
}
|
|
5934
|
-
/**
|
|
5935
|
-
* Get the fields array (internal use)
|
|
5936
|
-
*/
|
|
5937
|
-
getFields() {
|
|
5938
|
-
return this.fields;
|
|
5939
|
-
}
|
|
5940
|
-
/**
|
|
5941
|
-
* Get the schema name (internal use)
|
|
5942
|
-
*/
|
|
5943
|
-
getSchemaName() {
|
|
5944
|
-
return this.schemaName;
|
|
5945
|
-
}
|
|
5946
|
-
/**
|
|
5947
|
-
* Get the schema ID (internal use)
|
|
5948
|
-
*/
|
|
5949
|
-
getSchemaId() {
|
|
5950
|
-
return this.schemaId;
|
|
5951
|
-
}
|
|
5952
|
-
};
|
|
5953
|
-
var _SchemaBuilder = class _SchemaBuilder extends ExtractionBuilder {
|
|
5954
|
-
constructor(parentBuilder) {
|
|
5955
|
-
super();
|
|
5956
|
-
this.fields = parentBuilder.getFields();
|
|
5957
|
-
this.schemaName = parentBuilder.getSchemaName();
|
|
5958
|
-
this.schemaId = parentBuilder.getSchemaId();
|
|
5959
|
-
}
|
|
5960
|
-
/**
|
|
5961
|
-
* Add a structured field to the schema
|
|
5962
|
-
* @param name - Field name (alphanumeric only)
|
|
5963
|
-
* @param description - Field description
|
|
5964
|
-
* @param dataType - Data type (STRING, NUMBER, BOOLEAN, etc.)
|
|
5965
|
-
* @param options - Optional field configuration
|
|
5966
|
-
*/
|
|
5967
|
-
field(name, description, dataType, options) {
|
|
5968
|
-
if (!_SchemaBuilder.FIELD_NAME_PATTERN.test(name)) {
|
|
5969
|
-
throw new KadoaSdkException(
|
|
5970
|
-
`Field name "${name}" must be alphanumeric only (no underscores or special characters)`,
|
|
5971
|
-
{
|
|
5972
|
-
code: "VALIDATION_ERROR",
|
|
5973
|
-
details: { name, pattern: "^[A-Za-z0-9]+$" }
|
|
5974
|
-
}
|
|
5975
|
-
);
|
|
5976
|
-
}
|
|
5977
|
-
const lowerName = name.toLowerCase();
|
|
5978
|
-
if (this.fields.some((f) => f.name.toLowerCase() === lowerName)) {
|
|
5979
|
-
throw new KadoaSdkException(`Duplicate field name: "${name}"`, {
|
|
5980
|
-
code: "VALIDATION_ERROR",
|
|
5981
|
-
details: { name }
|
|
5982
|
-
});
|
|
5983
|
-
}
|
|
5984
|
-
const requiresExample = _SchemaBuilder.TYPES_REQUIRING_EXAMPLE.includes(dataType);
|
|
5985
|
-
if (requiresExample && !options?.example) {
|
|
5986
|
-
throw new KadoaSdkException(
|
|
5987
|
-
`Field "${name}" with type ${dataType} requires an example`,
|
|
5988
|
-
{ code: "VALIDATION_ERROR", details: { name, dataType } }
|
|
5989
|
-
);
|
|
5990
|
-
}
|
|
5991
|
-
this.fields.push({
|
|
5992
|
-
name,
|
|
5993
|
-
description,
|
|
5994
|
-
dataType,
|
|
5995
|
-
fieldType: "SCHEMA",
|
|
5996
|
-
example: options?.example,
|
|
5997
|
-
isKey: options?.isKey
|
|
5998
|
-
});
|
|
5999
|
-
return this;
|
|
6000
|
-
}
|
|
6001
|
-
/**
|
|
6002
|
-
* Add a classification field to categorize content
|
|
6003
|
-
* @param name - Field name (alphanumeric only)
|
|
6004
|
-
* @param description - Field description
|
|
6005
|
-
* @param categories - Array of category definitions
|
|
6006
|
-
*/
|
|
6007
|
-
classify(name, description, categories) {
|
|
6008
|
-
if (!_SchemaBuilder.FIELD_NAME_PATTERN.test(name)) {
|
|
6009
|
-
throw new KadoaSdkException(
|
|
6010
|
-
`Field name "${name}" must be alphanumeric only (no underscores or special characters)`,
|
|
6011
|
-
{
|
|
6012
|
-
code: "VALIDATION_ERROR",
|
|
6013
|
-
details: { name, pattern: "^[A-Za-z0-9]+$" }
|
|
6014
|
-
}
|
|
6015
|
-
);
|
|
6016
|
-
}
|
|
6017
|
-
const lowerName = name.toLowerCase();
|
|
6018
|
-
if (this.fields.some((f) => f.name.toLowerCase() === lowerName)) {
|
|
6019
|
-
throw new KadoaSdkException(`Duplicate field name: "${name}"`, {
|
|
6020
|
-
code: "VALIDATION_ERROR",
|
|
6021
|
-
details: { name }
|
|
6022
|
-
});
|
|
6023
|
-
}
|
|
6024
|
-
this.fields.push({
|
|
6025
|
-
name,
|
|
6026
|
-
description,
|
|
6027
|
-
fieldType: "CLASSIFICATION",
|
|
6028
|
-
categories
|
|
6029
|
-
});
|
|
6030
|
-
return this;
|
|
6031
|
-
}
|
|
6032
|
-
/**
|
|
6033
|
-
* Add raw page content alongside structured fields
|
|
6034
|
-
* @param format - Raw content format(s): "html", "markdown", or "url"
|
|
6035
|
-
*/
|
|
6036
|
-
raw(format) {
|
|
6037
|
-
return super.raw(format);
|
|
6038
|
-
}
|
|
6039
|
-
};
|
|
6040
|
-
_SchemaBuilder.FIELD_NAME_PATTERN = /^[A-Za-z0-9]+$/;
|
|
6041
|
-
_SchemaBuilder.TYPES_REQUIRING_EXAMPLE = [
|
|
6042
|
-
"STRING",
|
|
6043
|
-
"IMAGE",
|
|
6044
|
-
"LINK",
|
|
6045
|
-
"OBJECT",
|
|
6046
|
-
"ARRAY"
|
|
6047
|
-
];
|
|
6048
|
-
var SchemaBuilder = _SchemaBuilder;
|
|
6049
|
-
|
|
6050
|
-
// src/internal/domains/extraction/services/extraction-builder.service.ts
|
|
6051
6102
|
var debug7 = logger.extraction;
|
|
6052
6103
|
var ExtractionBuilderService = class {
|
|
6053
6104
|
constructor(workflowsCoreService, entityResolverService, dataFetcherService, notificationSetupService) {
|
|
@@ -6083,18 +6134,12 @@ var ExtractionBuilderService = class {
|
|
|
6083
6134
|
}) {
|
|
6084
6135
|
let entity = "ai-detection";
|
|
6085
6136
|
if (extraction) {
|
|
6086
|
-
const
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
const fields = builder.getFields();
|
|
6090
|
-
if (schemaId) {
|
|
6091
|
-
entity = { schemId: schemaId };
|
|
6092
|
-
} else if (schemaName && fields.length > 0) {
|
|
6093
|
-
entity = { name: schemaName, fields };
|
|
6094
|
-
} else if (fields.length > 0 && !schemaName) {
|
|
6095
|
-
entity = { name: "RawExtraction", fields };
|
|
6137
|
+
const result = extraction(new SchemaBuilder());
|
|
6138
|
+
if ("schemaId" in result) {
|
|
6139
|
+
entity = { schemaId: result.schemaId };
|
|
6096
6140
|
} else {
|
|
6097
|
-
|
|
6141
|
+
const builtSchema = result.build();
|
|
6142
|
+
entity = { name: builtSchema.entityName, fields: builtSchema.fields };
|
|
6098
6143
|
}
|
|
6099
6144
|
}
|
|
6100
6145
|
this._options = {
|
|
@@ -6138,7 +6183,7 @@ var ExtractionBuilderService = class {
|
|
|
6138
6183
|
async create() {
|
|
6139
6184
|
assert__default.default(this._options, "Options are not set");
|
|
6140
6185
|
const { urls, name, description, navigationMode, entity } = this.options;
|
|
6141
|
-
const resolvedEntity = typeof entity === "object" && "
|
|
6186
|
+
const resolvedEntity = typeof entity === "object" && "schemaId" in entity ? void 0 : await this.entityResolverService.resolveEntity(entity, {
|
|
6142
6187
|
link: urls[0],
|
|
6143
6188
|
location: this._options.location,
|
|
6144
6189
|
navigationMode
|
|
@@ -6155,7 +6200,7 @@ var ExtractionBuilderService = class {
|
|
|
6155
6200
|
description,
|
|
6156
6201
|
navigationMode,
|
|
6157
6202
|
monitoring: this._monitoringOptions,
|
|
6158
|
-
schemaId: typeof entity === "object" && "
|
|
6203
|
+
schemaId: typeof entity === "object" && "schemaId" in entity ? entity.schemaId : void 0,
|
|
6159
6204
|
entity: resolvedEntity.entity,
|
|
6160
6205
|
fields: resolvedEntity.fields,
|
|
6161
6206
|
autoStart: false,
|
|
@@ -6465,6 +6510,7 @@ exports.ERROR_MESSAGES = ERROR_MESSAGES;
|
|
|
6465
6510
|
exports.KadoaClient = KadoaClient;
|
|
6466
6511
|
exports.KadoaHttpException = KadoaHttpException;
|
|
6467
6512
|
exports.KadoaSdkException = KadoaSdkException;
|
|
6513
|
+
exports.SchemaBuilder = SchemaBuilder;
|
|
6468
6514
|
exports.SchemasModule = SchemasModule;
|
|
6469
6515
|
exports.ValidationModule = ValidationModule;
|
|
6470
6516
|
exports.pollUntil = pollUntil;
|