@kadoa/node-sdk 0.14.1 → 0.15.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/dist/index.mjs CHANGED
@@ -325,6 +325,9 @@ var _SchemaBuilder = class _SchemaBuilder {
325
325
  constructor() {
326
326
  this.fields = [];
327
327
  }
328
+ hasSchemaFields() {
329
+ return this.fields.some((field) => field.fieldType === "SCHEMA");
330
+ }
328
331
  entity(entityName) {
329
332
  this.entityName = entityName;
330
333
  return this;
@@ -392,11 +395,14 @@ var _SchemaBuilder = class _SchemaBuilder {
392
395
  return this;
393
396
  }
394
397
  build() {
395
- if (!this.entityName) {
396
- throw new KadoaSdkException("Entity name is required", {
397
- code: "VALIDATION_ERROR",
398
- details: { entityName: this.entityName }
399
- });
398
+ if (this.hasSchemaFields() && !this.entityName) {
399
+ throw new KadoaSdkException(
400
+ "Entity name is required when schema fields are present",
401
+ {
402
+ code: "VALIDATION_ERROR",
403
+ details: { entityName: this.entityName }
404
+ }
405
+ );
400
406
  }
401
407
  return {
402
408
  entityName: this.entityName,
@@ -4299,15 +4305,30 @@ var SchemasService = class {
4299
4305
  return new class extends SchemaBuilder {
4300
4306
  constructor() {
4301
4307
  super();
4302
- this.entity(entityName);
4308
+ if (entityName) {
4309
+ this.entity(entityName);
4310
+ }
4303
4311
  }
4304
4312
  async create(name) {
4305
4313
  const built = this.build();
4306
- return service.createSchema({
4307
- name: name || built.entityName,
4308
- entity: built.entityName,
4309
- fields: built.fields
4310
- });
4314
+ const schemaName = name ?? built.entityName;
4315
+ if (!schemaName) {
4316
+ throw new KadoaSdkException(
4317
+ "Schema name is required when entity name is not provided",
4318
+ {
4319
+ code: "VALIDATION_ERROR",
4320
+ details: { name }
4321
+ }
4322
+ );
4323
+ }
4324
+ const createSchemaBody = {
4325
+ name: schemaName,
4326
+ fields: built.fields,
4327
+ ...built.entityName ? { entity: built.entityName } : {}
4328
+ };
4329
+ return service.createSchema(
4330
+ createSchemaBody
4331
+ );
4311
4332
  }
4312
4333
  }();
4313
4334
  }
@@ -4403,8 +4424,9 @@ var EntityResolverService = class {
4403
4424
  location: options.location,
4404
4425
  navigationMode: options.navigationMode
4405
4426
  });
4427
+ const entity = entityPrediction.entity;
4406
4428
  return {
4407
- entity: entityPrediction.entity,
4429
+ entity,
4408
4430
  fields: entityPrediction.fields
4409
4431
  };
4410
4432
  } else if (entityConfig) {
@@ -4413,10 +4435,10 @@ var EntityResolverService = class {
4413
4435
  entityConfig.schemaId
4414
4436
  );
4415
4437
  return {
4416
- entity: schema.entity ?? "",
4438
+ entity: schema.entity ?? void 0,
4417
4439
  fields: schema.schema
4418
4440
  };
4419
- } else if ("name" in entityConfig && "fields" in entityConfig) {
4441
+ } else if ("fields" in entityConfig) {
4420
4442
  return {
4421
4443
  entity: entityConfig.name,
4422
4444
  fields: entityConfig.fields
@@ -4572,11 +4594,12 @@ var ExtractionService = class {
4572
4594
  }
4573
4595
  );
4574
4596
  const hasNotifications = !!config.notifications;
4575
- const result = await this.workflowsCoreService.create({
4597
+ const workflowRequest = {
4576
4598
  ...config,
4577
- entity: resolvedEntity.entity,
4578
- fields: resolvedEntity.fields
4579
- });
4599
+ fields: resolvedEntity.fields,
4600
+ ...resolvedEntity.entity !== void 0 ? { entity: resolvedEntity.entity } : {}
4601
+ };
4602
+ const result = await this.workflowsCoreService.create(workflowRequest);
4580
4603
  workflowId = result.id;
4581
4604
  if (hasNotifications) {
4582
4605
  const result2 = await this.notificationSetupService.setup({
@@ -4718,7 +4741,7 @@ var ExtractionBuilderService = class {
4718
4741
  entity = { schemaId: result.schemaId };
4719
4742
  } else {
4720
4743
  const builtSchema = result.build();
4721
- entity = { name: builtSchema.entityName, fields: builtSchema.fields };
4744
+ entity = builtSchema.entityName ? { name: builtSchema.entityName, fields: builtSchema.fields } : { fields: builtSchema.fields };
4722
4745
  }
4723
4746
  }
4724
4747
  this._options = {
@@ -4762,17 +4785,14 @@ var ExtractionBuilderService = class {
4762
4785
  async create() {
4763
4786
  assert(this._options, "Options are not set");
4764
4787
  const { urls, name, description, navigationMode, entity } = this.options;
4765
- const resolvedEntity = typeof entity === "object" && "schemaId" in entity ? void 0 : await this.entityResolverService.resolveEntity(entity, {
4766
- link: urls[0],
4767
- location: this._options.location,
4768
- navigationMode
4769
- });
4770
- if (!resolvedEntity) {
4771
- throw new KadoaSdkException(ERROR_MESSAGES.ENTITY_FETCH_FAILED, {
4772
- code: "VALIDATION_ERROR",
4773
- details: { entity }
4774
- });
4775
- }
4788
+ const resolvedEntity = await this.entityResolverService.resolveEntity(
4789
+ entity,
4790
+ {
4791
+ link: urls[0],
4792
+ location: this._options.location,
4793
+ navigationMode
4794
+ }
4795
+ );
4776
4796
  const workflow = await this.workflowsCoreService.create({
4777
4797
  urls,
4778
4798
  name,
@@ -5270,7 +5290,7 @@ var WSS_API_URI = process.env.KADOA_WSS_API_URI ?? "wss://realtime.kadoa.com";
5270
5290
  var REALTIME_API_URI = process.env.KADOA_REALTIME_API_URI ?? "https://realtime.kadoa.com";
5271
5291
 
5272
5292
  // src/version.ts
5273
- var SDK_VERSION = "0.14.1";
5293
+ var SDK_VERSION = "0.15.0";
5274
5294
  var SDK_NAME = "kadoa-node-sdk";
5275
5295
  var SDK_LANGUAGE = "node";
5276
5296