@kadoa/node-sdk 0.19.4-beta.3 → 0.20.2

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.js CHANGED
@@ -3614,7 +3614,7 @@ var WorkflowsApiAxiosParamCreator = function(configuration) {
3614
3614
  };
3615
3615
  },
3616
3616
  /**
3617
- * Resumes a paused, preview, or error workflow. If the user\'s team/organization or any of the user\'s organizations has the COMPLIANCE_REVIEW rule enabled, the workflow will be sent for compliance review instead of being directly activated.
3617
+ * Resumes/Activates a paused, preview, or error workflow.
3618
3618
  * @summary Resume a workflow
3619
3619
  * @param {string} workflowId The ID of the workflow to resume
3620
3620
  * @param {*} [options] Override http request option.
@@ -4065,7 +4065,7 @@ var WorkflowsApiFp = function(configuration) {
4065
4065
  return (axios2, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios3__default.default, BASE_PATH, configuration)(axios2, localVarOperationServerBasePath || basePath);
4066
4066
  },
4067
4067
  /**
4068
- * Resumes a paused, preview, or error workflow. If the user\'s team/organization or any of the user\'s organizations has the COMPLIANCE_REVIEW rule enabled, the workflow will be sent for compliance review instead of being directly activated.
4068
+ * Resumes/Activates a paused, preview, or error workflow.
4069
4069
  * @summary Resume a workflow
4070
4070
  * @param {string} workflowId The ID of the workflow to resume
4071
4071
  * @param {*} [options] Override http request option.
@@ -4300,7 +4300,7 @@ var WorkflowsApi = class extends BaseAPI {
4300
4300
  return WorkflowsApiFp(this.configuration).v4WorkflowsWorkflowIdPausePut(requestParameters.workflowId, options).then((request) => request(this.axios, this.basePath));
4301
4301
  }
4302
4302
  /**
4303
- * Resumes a paused, preview, or error workflow. If the user\'s team/organization or any of the user\'s organizations has the COMPLIANCE_REVIEW rule enabled, the workflow will be sent for compliance review instead of being directly activated.
4303
+ * Resumes/Activates a paused, preview, or error workflow.
4304
4304
  * @summary Resume a workflow
4305
4305
  * @param {WorkflowsApiV4WorkflowsWorkflowIdResumePutRequest} requestParameters Request parameters.
4306
4306
  * @param {*} [options] Override http request option.
@@ -4409,6 +4409,122 @@ var DataFieldDataTypeEnum = {
4409
4409
  Array: "ARRAY"
4410
4410
  };
4411
4411
 
4412
+ // src/domains/crawler/crawler.acl.ts
4413
+ var PageStatus = {
4414
+ Done: "DONE",
4415
+ Crawling: "CRAWLING",
4416
+ Pending: "PENDING"
4417
+ };
4418
+
4419
+ // src/domains/crawler/crawler-config.service.ts
4420
+ var CrawlerConfigService = class {
4421
+ constructor(client) {
4422
+ this.client = client;
4423
+ }
4424
+ get api() {
4425
+ return this.client.apis.crawler;
4426
+ }
4427
+ async createConfig(body) {
4428
+ const response = await this.api.v4CrawlConfigPost({
4429
+ createCrawlerConfigRequest: body
4430
+ });
4431
+ return response.data;
4432
+ }
4433
+ async getConfig(configId) {
4434
+ const response = await this.api.v4CrawlConfigConfigIdGet({ configId });
4435
+ return response.data;
4436
+ }
4437
+ async deleteConfig(configId) {
4438
+ const response = await this.api.v4CrawlConfigDelete({
4439
+ deleteCrawlerConfigRequest: { configId }
4440
+ });
4441
+ return response.data;
4442
+ }
4443
+ };
4444
+
4445
+ // src/domains/crawler/crawler-session.service.ts
4446
+ var CrawlerSessionService = class {
4447
+ constructor(client) {
4448
+ this.client = client;
4449
+ }
4450
+ get api() {
4451
+ return this.client.apis.crawler;
4452
+ }
4453
+ async start(body) {
4454
+ const response = await this.api.v4CrawlPost({
4455
+ startCrawlerSessionRequest: body
4456
+ });
4457
+ return response.data;
4458
+ }
4459
+ async startWithConfig(body) {
4460
+ const response = await this.api.v4CrawlStartPost({
4461
+ startSessionWithConfigRequest: body
4462
+ });
4463
+ return response.data;
4464
+ }
4465
+ async pause(sessionId) {
4466
+ const response = await this.api.v4CrawlPausePost({
4467
+ pauseCrawlerSessionRequest: { sessionId }
4468
+ });
4469
+ return response.data;
4470
+ }
4471
+ async resume(sessionId) {
4472
+ const response = await this.api.v4CrawlResumePost({
4473
+ resumeCrawlerSessionRequest: { sessionId }
4474
+ });
4475
+ return response.data;
4476
+ }
4477
+ async listSessions(options) {
4478
+ const response = await this.api.v4CrawlSessionsGet({
4479
+ page: options?.page,
4480
+ pageSize: options?.pageSize,
4481
+ userId: options?.userId
4482
+ });
4483
+ return response.data.data ?? [];
4484
+ }
4485
+ async getSessionStatus(sessionId) {
4486
+ const response = await this.api.v4CrawlSessionIdStatusGet({ sessionId });
4487
+ return response.data;
4488
+ }
4489
+ async getPages(sessionId, options) {
4490
+ const response = await this.api.v4CrawlSessionIdPagesGet({
4491
+ sessionId,
4492
+ currentPage: options?.currentPage,
4493
+ pageSize: options?.pageSize
4494
+ });
4495
+ return response.data;
4496
+ }
4497
+ async getPage(sessionId, pageId, options) {
4498
+ const response = await this.api.v4CrawlSessionIdPagesPageIdGet({
4499
+ sessionId,
4500
+ pageId,
4501
+ format: options?.format
4502
+ });
4503
+ return response.data;
4504
+ }
4505
+ async getAllSessionData(sessionId, options) {
4506
+ const response = await this.api.v4CrawlSessionIdListGet({
4507
+ sessionId,
4508
+ includeAll: options?.includeAll
4509
+ });
4510
+ return response.data;
4511
+ }
4512
+ async getBucketFile(filenameb64) {
4513
+ const response = await this.api.v4CrawlBucketDataFilenameb64Get({
4514
+ filenameb64
4515
+ });
4516
+ return response.data;
4517
+ }
4518
+ };
4519
+
4520
+ // src/domains/crawler/crawler.facade.ts
4521
+ function createCrawlerDomain(client) {
4522
+ return {
4523
+ config: new CrawlerConfigService(client),
4524
+ session: new CrawlerSessionService(client)
4525
+ };
4526
+ }
4527
+
4412
4528
  // src/domains/extraction/extraction.acl.ts
4413
4529
  var FetchDataOptions = class {
4414
4530
  };
@@ -4529,7 +4645,6 @@ var DataFetcherService = class {
4529
4645
 
4530
4646
  // src/runtime/exceptions/base.exception.ts
4531
4647
  var KadoaErrorCode = {
4532
- AUTH_ERROR: "AUTH_ERROR",
4533
4648
  VALIDATION_ERROR: "VALIDATION_ERROR",
4534
4649
  BAD_REQUEST: "BAD_REQUEST",
4535
4650
  NOT_FOUND: "NOT_FOUND",
@@ -4649,8 +4764,7 @@ var KadoaHttpException = class _KadoaHttpException extends KadoaSdkException {
4649
4764
  endpoint: url,
4650
4765
  method,
4651
4766
  responseBody: error.response?.data,
4652
- details: extra?.details,
4653
- cause: error
4767
+ details: extra?.details
4654
4768
  });
4655
4769
  }
4656
4770
  toJSON() {
@@ -4836,7 +4950,10 @@ var SchemaBuilder = _SchemaBuilder;
4836
4950
  var debug = logger.schemas;
4837
4951
  var SchemasService = class {
4838
4952
  constructor(client) {
4839
- this.schemasApi = new SchemasApi(client.configuration);
4953
+ this.client = client;
4954
+ }
4955
+ get schemasApi() {
4956
+ return this.client.apis.schemas;
4840
4957
  }
4841
4958
  /**
4842
4959
  * Create a schema builder with fluent API and inline create support.
@@ -5406,15 +5523,18 @@ var ExtractionBuilderService = class {
5406
5523
  selectorMode: useSelectorMode
5407
5524
  });
5408
5525
  }
5526
+ const hasSchemaId = typeof entity === "object" && "schemaId" in entity && entity.schemaId;
5409
5527
  const workflow = await this.workflowsCoreService.create({
5410
5528
  urls,
5411
5529
  name,
5412
5530
  description,
5413
5531
  navigationMode,
5414
5532
  monitoring: this._monitoringOptions,
5415
- schemaId: typeof entity === "object" && "schemaId" in entity ? entity.schemaId : void 0,
5416
- entity: resolvedEntity.entity,
5417
- fields: resolvedEntity.fields,
5533
+ ...hasSchemaId ? {
5534
+ schemaId: entity.schemaId,
5535
+ entity: resolvedEntity.entity,
5536
+ fields: resolvedEntity.fields
5537
+ } : { entity: resolvedEntity.entity, fields: resolvedEntity.fields },
5418
5538
  autoStart: false,
5419
5539
  interval: this._options.interval,
5420
5540
  schedules: this._options.schedules,
@@ -5607,11 +5727,14 @@ var _NotificationChannelsService = class _NotificationChannelsService {
5607
5727
  }
5608
5728
  async createChannel(type, config) {
5609
5729
  const payload = await this.buildPayload(
5610
- esToolkit.merge(config || {}, {
5611
- name: _NotificationChannelsService.DEFAULT_CHANNEL_NAME,
5612
- channelType: type,
5613
- config: {}
5614
- })
5730
+ esToolkit.merge(
5731
+ {
5732
+ name: _NotificationChannelsService.DEFAULT_CHANNEL_NAME,
5733
+ channelType: type,
5734
+ config: {}
5735
+ },
5736
+ config || {}
5737
+ )
5615
5738
  );
5616
5739
  const response = await this.api.v5NotificationsChannelsPost({
5617
5740
  v5NotificationsChannelsPostRequest: payload
@@ -5717,6 +5840,19 @@ var NotificationSettingsService = class {
5717
5840
  async listAllEvents() {
5718
5841
  return Object.values(V5NotificationsSettingsGetEventTypeEnum);
5719
5842
  }
5843
+ async updateSettings(settingsId, data) {
5844
+ const response = await this.api.v5NotificationsSettingsSettingsIdPut({
5845
+ settingsId,
5846
+ v5NotificationsSettingsSettingsIdPutRequest: data
5847
+ });
5848
+ const settings = response.data.data?.settings;
5849
+ if (!settings) {
5850
+ throw KadoaHttpException.wrap(response, {
5851
+ message: "Failed to update notification settings"
5852
+ });
5853
+ }
5854
+ return settings;
5855
+ }
5720
5856
  async deleteSettings(settingsId) {
5721
5857
  const response = await this.api.v5NotificationsSettingsSettingsIdDelete({
5722
5858
  settingsId
@@ -5737,20 +5873,10 @@ var NotificationSetupService = class {
5737
5873
  this.settingsService = settingsService;
5738
5874
  }
5739
5875
  /**
5740
- * Setup notification settings for a specific workflow ensuring no duplicates exist.
5876
+ * Setup notification settings for a specific workflow.
5877
+ * Creates channels and settings for the specified events.
5741
5878
  */
5742
5879
  async setupForWorkflow(requestData) {
5743
- const existingSettings = await this.settingsService.listSettings({
5744
- workflowId: requestData.workflowId
5745
- });
5746
- if (existingSettings.length > 0) {
5747
- throw new KadoaSdkException("Settings already exist", {
5748
- code: KadoaErrorCode.BAD_REQUEST,
5749
- details: {
5750
- workflowId: requestData.workflowId
5751
- }
5752
- });
5753
- }
5754
5880
  return this.setup({
5755
5881
  workflowId: requestData.workflowId,
5756
5882
  events: requestData.events,
@@ -5798,8 +5924,24 @@ var NotificationSetupService = class {
5798
5924
  channels: channelIds
5799
5925
  }
5800
5926
  );
5927
+ const existingSettings = await this.settingsService.listSettings({
5928
+ workflowId: requestData.workflowId
5929
+ });
5801
5930
  const newSettings = await Promise.all(
5802
5931
  eventTypes.map(async (eventType) => {
5932
+ const existing = existingSettings.find(
5933
+ (s) => s.eventType === eventType
5934
+ );
5935
+ if (existing?.id) {
5936
+ const existingChannelIds = (existing.channels || []).map((c) => c.id).filter(Boolean);
5937
+ const mergedChannelIds = [
5938
+ .../* @__PURE__ */ new Set([...existingChannelIds, ...channelIds])
5939
+ ];
5940
+ return await this.settingsService.updateSettings(existing.id, {
5941
+ channelIds: mergedChannelIds,
5942
+ enabled: existing.enabled ?? true
5943
+ });
5944
+ }
5803
5945
  return await this.settingsService.createSettings({
5804
5946
  workflowId: requestData.workflowId,
5805
5947
  channelIds,
@@ -5932,9 +6074,10 @@ var NotificationSetupService = class {
5932
6074
  });
5933
6075
  return existingChannel;
5934
6076
  }
6077
+ const { name: _, ...channelConfig } = config;
5935
6078
  const channel = await this.channelsService.createChannel(channelType, {
5936
6079
  name: channelName,
5937
- config
6080
+ config: channelConfig
5938
6081
  });
5939
6082
  debug4("Created channel with custom config %O", {
5940
6083
  workflowId,
@@ -5952,10 +6095,11 @@ var NotificationSetupService = class {
5952
6095
  // src/runtime/config/constants.ts
5953
6096
  var PUBLIC_API_URI = process.env.KADOA_PUBLIC_API_URI ?? "https://api.kadoa.com";
5954
6097
  var WSS_API_URI = process.env.KADOA_WSS_API_URI ?? "wss://realtime.kadoa.com";
6098
+ process.env.KADOA_WSS_NEO_API_URI ?? "wss://events.kadoa.com/events/ws";
5955
6099
  var REALTIME_API_URI = process.env.KADOA_REALTIME_API_URI ?? "https://realtime.kadoa.com";
5956
6100
 
5957
6101
  // src/version.ts
5958
- var SDK_VERSION = "0.19.3";
6102
+ var SDK_VERSION = "0.20.2";
5959
6103
  var SDK_NAME = "kadoa-node-sdk";
5960
6104
  var SDK_LANGUAGE = "node";
5961
6105
 
@@ -5975,7 +6119,6 @@ var Realtime = class {
5975
6119
  this.heartbeatInterval = config.heartbeatInterval || 1e4;
5976
6120
  this.reconnectDelay = config.reconnectDelay || 5e3;
5977
6121
  this.missedHeartbeatsLimit = config.missedHeartbeatsLimit || 3e4;
5978
- this.source = config.source;
5979
6122
  }
5980
6123
  async connect() {
5981
6124
  if (this.isConnecting) return;
@@ -5990,56 +6133,59 @@ var Realtime = class {
5990
6133
  }
5991
6134
  });
5992
6135
  const { access_token, team_id } = await response.json();
5993
- this.socket = new WebSocket(
5994
- `${WSS_API_URI}?access_token=${access_token}`
5995
- );
5996
- this.socket.onopen = () => {
5997
- this.isConnecting = false;
5998
- this.lastHeartbeat = Date.now();
5999
- if (this.socket?.readyState === WebSocket.OPEN) {
6000
- this.socket.send(
6001
- JSON.stringify({
6002
- action: "subscribe",
6003
- channel: team_id,
6004
- ...this.source && { source: this.source }
6005
- })
6006
- );
6007
- debug5("Connected to WebSocket");
6008
- this.notifyConnectionListeners(true);
6009
- }
6010
- this.startHeartbeatCheck();
6011
- };
6012
- this.socket.onmessage = (event) => {
6013
- try {
6014
- const data = JSON.parse(event.data);
6015
- if (data.type === "heartbeat") {
6016
- this.handleHeartbeat();
6017
- } else {
6018
- if (data?.id) {
6019
- fetch(`${REALTIME_API_URI}/api/v1/events/ack`, {
6020
- method: "POST",
6021
- headers: { "Content-Type": "application/json" },
6022
- body: JSON.stringify({ id: data.id })
6023
- });
6136
+ await new Promise((resolve, reject) => {
6137
+ this.socket = new WebSocket(
6138
+ `${WSS_API_URI}?access_token=${access_token}`
6139
+ );
6140
+ this.socket.onopen = () => {
6141
+ this.isConnecting = false;
6142
+ this.lastHeartbeat = Date.now();
6143
+ if (this.socket?.readyState === WebSocket.OPEN) {
6144
+ this.socket.send(
6145
+ JSON.stringify({
6146
+ action: "subscribe",
6147
+ channel: team_id
6148
+ })
6149
+ );
6150
+ debug5("Connected to WebSocket");
6151
+ this.notifyConnectionListeners(true);
6152
+ }
6153
+ this.startHeartbeatCheck();
6154
+ resolve();
6155
+ };
6156
+ this.socket.onmessage = (event) => {
6157
+ try {
6158
+ const data = JSON.parse(event.data);
6159
+ if (data.type === "heartbeat") {
6160
+ this.handleHeartbeat();
6161
+ } else {
6162
+ if (data?.id) {
6163
+ fetch(`${REALTIME_API_URI}/api/v1/events/ack`, {
6164
+ method: "POST",
6165
+ headers: { "Content-Type": "application/json" },
6166
+ body: JSON.stringify({ id: data.id })
6167
+ });
6168
+ }
6169
+ this.notifyEventListeners(data);
6024
6170
  }
6025
- this.notifyEventListeners(data);
6171
+ } catch (err) {
6172
+ debug5("Failed to parse incoming message: %O", err);
6026
6173
  }
6027
- } catch (err) {
6028
- debug5("Failed to parse incoming message: %O", err);
6029
- }
6030
- };
6031
- this.socket.onclose = () => {
6032
- debug5("WebSocket disconnected. Attempting to reconnect...");
6033
- this.isConnecting = false;
6034
- this.stopHeartbeatCheck();
6035
- this.notifyConnectionListeners(false, "Connection closed");
6036
- setTimeout(() => this.connect(), this.reconnectDelay);
6037
- };
6038
- this.socket.onerror = (error) => {
6039
- debug5("WebSocket error: %O", error);
6040
- this.isConnecting = false;
6041
- this.notifyErrorListeners(error);
6042
- };
6174
+ };
6175
+ this.socket.onclose = () => {
6176
+ debug5("WebSocket disconnected. Attempting to reconnect...");
6177
+ this.isConnecting = false;
6178
+ this.stopHeartbeatCheck();
6179
+ this.notifyConnectionListeners(false, "Connection closed");
6180
+ setTimeout(() => this.connect(), this.reconnectDelay);
6181
+ };
6182
+ this.socket.onerror = (error) => {
6183
+ debug5("WebSocket error: %O", error);
6184
+ this.isConnecting = false;
6185
+ this.notifyErrorListeners(error);
6186
+ reject(error);
6187
+ };
6188
+ });
6043
6189
  } catch (err) {
6044
6190
  debug5("Failed to connect: %O", err);
6045
6191
  this.isConnecting = false;
@@ -6282,11 +6428,10 @@ function isNewerVersion(version1, version2) {
6282
6428
  // src/domains/validation/validation-core.service.ts
6283
6429
  var ValidationCoreService = class {
6284
6430
  constructor(client) {
6285
- this.validationApi = new DataValidationApi(
6286
- client.configuration,
6287
- client.baseUrl,
6288
- client.axiosInstance
6289
- );
6431
+ this.client = client;
6432
+ }
6433
+ get validationApi() {
6434
+ return this.client.apis.validation;
6290
6435
  }
6291
6436
  async listWorkflowValidations(filters) {
6292
6437
  const response = await this.validationApi.v4DataValidationWorkflowsWorkflowIdJobsJobIdValidationsGet(
@@ -6388,6 +6533,7 @@ var ValidationCoreService = class {
6388
6533
  return response.data;
6389
6534
  }
6390
6535
  async waitUntilCompleted(validationId, options) {
6536
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
6391
6537
  const result = await pollUntil(
6392
6538
  async () => {
6393
6539
  const current = await this.getValidationDetails(validationId);
@@ -6407,11 +6553,10 @@ var ValidationCoreService = class {
6407
6553
  };
6408
6554
  var ValidationRulesService = class {
6409
6555
  constructor(client) {
6410
- this.validationApi = new DataValidationApi(
6411
- client.configuration,
6412
- client.baseUrl,
6413
- client.axiosInstance
6414
- );
6556
+ this.client = client;
6557
+ }
6558
+ get validationApi() {
6559
+ return this.client.apis.validation;
6415
6560
  }
6416
6561
  async listRules(options) {
6417
6562
  const response = await this.validationApi.v4DataValidationRulesGet(options);
@@ -6465,6 +6610,25 @@ var ValidationRulesService = class {
6465
6610
  }
6466
6611
  return response.data.data;
6467
6612
  }
6613
+ async deleteRule(data) {
6614
+ const response = await this.validationApi.v4DataValidationRulesRuleIdDelete(
6615
+ {
6616
+ ruleId: data.ruleId,
6617
+ ...data.workflowId != null && {
6618
+ deleteRuleWithReason: {
6619
+ workflowId: data.workflowId,
6620
+ ...data.reason != null && { reason: data.reason }
6621
+ }
6622
+ }
6623
+ }
6624
+ );
6625
+ if (response.status !== 200 || response.data.error) {
6626
+ throw KadoaHttpException.wrap(response.data, {
6627
+ message: response.data.message || "Failed to delete validation rule"
6628
+ });
6629
+ }
6630
+ return response.data;
6631
+ }
6468
6632
  async disableRule(data) {
6469
6633
  const response = await this.validationApi.v4DataValidationRulesRuleIdDisablePost(data);
6470
6634
  if (response.status !== 200 || response.data.error) {
@@ -6588,7 +6752,8 @@ var WorkflowsCoreService = class {
6588
6752
  location: input.location,
6589
6753
  autoStart: input.autoStart,
6590
6754
  schedules: input.schedules,
6591
- additionalData: input.additionalData
6755
+ additionalData: input.additionalData,
6756
+ limit: input.limit
6592
6757
  };
6593
6758
  const response2 = await this.workflowsApi.v4WorkflowsPost({
6594
6759
  createWorkflowBody: agenticRequest
@@ -6610,7 +6775,7 @@ var WorkflowsCoreService = class {
6610
6775
  schemaId: input.schemaId,
6611
6776
  description: input.description,
6612
6777
  navigationMode: input.navigationMode,
6613
- entity: input.entity ?? "",
6778
+ ...input.entity != null && { entity: input.entity },
6614
6779
  fields: input.fields,
6615
6780
  bypassPreview: input.bypassPreview ?? true,
6616
6781
  tags: input.tags,
@@ -6619,7 +6784,8 @@ var WorkflowsCoreService = class {
6619
6784
  location: input.location,
6620
6785
  autoStart: input.autoStart,
6621
6786
  schedules: input.schedules,
6622
- additionalData: input.additionalData
6787
+ additionalData: input.additionalData,
6788
+ limit: input.limit
6623
6789
  };
6624
6790
  const response = await this.workflowsApi.v4WorkflowsPost({
6625
6791
  createWorkflowBody: request
@@ -6753,131 +6919,44 @@ var WorkflowsCoreService = class {
6753
6919
  }
6754
6920
  };
6755
6921
 
6756
- // src/domains/crawler/crawler-config.service.ts
6757
- var CrawlerConfigService = class {
6758
- constructor(client) {
6759
- this.client = client;
6760
- this._api = null;
6761
- }
6762
- get api() {
6763
- if (!this._api) {
6764
- this._api = new CrawlerApi(
6765
- this.client.configuration,
6766
- this.client.baseUrl,
6767
- this.client.axiosInstance
6768
- );
6769
- }
6770
- return this._api;
6771
- }
6772
- async createConfig(body) {
6773
- const response = await this.api.v4CrawlConfigPost({
6774
- createCrawlerConfigRequest: body
6775
- });
6776
- return response.data;
6777
- }
6778
- async getConfig(configId) {
6779
- const response = await this.api.v4CrawlConfigConfigIdGet({ configId });
6780
- return response.data;
6781
- }
6782
- async deleteConfig(configId) {
6783
- const response = await this.api.v4CrawlConfigDelete({
6784
- deleteCrawlerConfigRequest: { configId }
6922
+ // src/client/api-registry.ts
6923
+ var ApiRegistry = class {
6924
+ constructor(apiKey, baseUrl, axios2, headers) {
6925
+ this.baseUrl = baseUrl;
6926
+ this.axios = axios2;
6927
+ this.cache = /* @__PURE__ */ new Map();
6928
+ this.configuration = new Configuration({
6929
+ apiKey,
6930
+ basePath: baseUrl,
6931
+ baseOptions: { headers }
6785
6932
  });
6786
- return response.data;
6787
- }
6788
- };
6789
-
6790
- // src/domains/crawler/crawler-session.service.ts
6791
- var CrawlerSessionService = class {
6792
- constructor(client) {
6793
- this.client = client;
6794
- this._api = null;
6795
6933
  }
6796
- get api() {
6797
- if (!this._api) {
6798
- this._api = new CrawlerApi(
6799
- this.client.configuration,
6800
- this.client.baseUrl,
6801
- this.client.axiosInstance
6934
+ get(ApiClass) {
6935
+ if (!this.cache.has(ApiClass)) {
6936
+ this.cache.set(
6937
+ ApiClass,
6938
+ new ApiClass(this.configuration, this.baseUrl, this.axios)
6802
6939
  );
6803
6940
  }
6804
- return this._api;
6805
- }
6806
- async start(body) {
6807
- const response = await this.api.v4CrawlPost({
6808
- startCrawlerSessionRequest: body
6809
- });
6810
- return response.data;
6811
- }
6812
- async startWithConfig(body) {
6813
- const response = await this.api.v4CrawlStartPost({
6814
- startSessionWithConfigRequest: body
6815
- });
6816
- return response.data;
6817
- }
6818
- async pause(sessionId) {
6819
- const response = await this.api.v4CrawlPausePost({
6820
- pauseCrawlerSessionRequest: { sessionId }
6821
- });
6822
- return response.data;
6823
- }
6824
- async resume(sessionId) {
6825
- const response = await this.api.v4CrawlResumePost({
6826
- resumeCrawlerSessionRequest: { sessionId }
6827
- });
6828
- return response.data;
6829
- }
6830
- async listSessions(options) {
6831
- const response = await this.api.v4CrawlSessionsGet({
6832
- page: options?.page,
6833
- pageSize: options?.pageSize,
6834
- userId: options?.userId
6835
- });
6836
- return response.data.data ?? [];
6941
+ return this.cache.get(ApiClass);
6837
6942
  }
6838
- async getSessionStatus(sessionId) {
6839
- const response = await this.api.v4CrawlSessionIdStatusGet({ sessionId });
6840
- return response.data;
6943
+ get schemas() {
6944
+ return this.get(SchemasApi);
6841
6945
  }
6842
- async getPages(sessionId, options) {
6843
- const response = await this.api.v4CrawlSessionIdPagesGet({
6844
- sessionId,
6845
- currentPage: options?.currentPage,
6846
- pageSize: options?.pageSize
6847
- });
6848
- return response.data;
6946
+ get validation() {
6947
+ return this.get(DataValidationApi);
6849
6948
  }
6850
- async getPage(sessionId, pageId, options) {
6851
- const response = await this.api.v4CrawlSessionIdPagesPageIdGet({
6852
- sessionId,
6853
- pageId,
6854
- format: options?.format
6855
- });
6856
- return response.data;
6949
+ get crawler() {
6950
+ return this.get(CrawlerApi);
6857
6951
  }
6858
- async getAllSessionData(sessionId, options) {
6859
- const response = await this.api.v4CrawlSessionIdListGet({
6860
- sessionId,
6861
- includeAll: options?.includeAll
6862
- });
6863
- return response.data;
6952
+ get workflows() {
6953
+ return this.get(WorkflowsApi);
6864
6954
  }
6865
- async getBucketFile(filenameb64) {
6866
- const response = await this.api.v4CrawlBucketDataFilenameb64Get({
6867
- filenameb64
6868
- });
6869
- return response.data;
6955
+ get notifications() {
6956
+ return this.get(NotificationsApi);
6870
6957
  }
6871
6958
  };
6872
6959
 
6873
- // src/domains/crawler/crawler.facade.ts
6874
- function createCrawlerDomain(client) {
6875
- return {
6876
- config: new CrawlerConfigService(client),
6877
- session: new CrawlerSessionService(client)
6878
- };
6879
- }
6880
-
6881
6960
  // src/domains/validation/validation.facade.ts
6882
6961
  function createValidationDomain(core, rules) {
6883
6962
  return {
@@ -6893,121 +6972,154 @@ function createValidationDomain(core, rules) {
6893
6972
  };
6894
6973
  }
6895
6974
 
6896
- // src/kadoa-client.ts
6897
- var KadoaClient = class {
6898
- constructor(config) {
6899
- this._baseUrl = PUBLIC_API_URI;
6900
- this._timeout = config.timeout || 3e4;
6901
- this._apiKey = config.apiKey;
6902
- const headers = {
6903
- "User-Agent": `${SDK_NAME}/${SDK_VERSION}`,
6904
- "X-SDK-Version": SDK_VERSION,
6905
- "X-SDK-Language": SDK_LANGUAGE
6906
- };
6907
- this._configuration = new Configuration({
6908
- apiKey: this._apiKey,
6909
- basePath: this._baseUrl,
6910
- baseOptions: {
6911
- headers
6912
- }
6913
- });
6914
- this._axiosInstance = globalAxios3__default.default.create({
6915
- timeout: this._timeout,
6916
- headers
6917
- });
6918
- this._axiosInstance.interceptors.request.use((config2) => {
6919
- config2.headers["x-request-id"] = uuid.v4();
6920
- return config2;
6921
- });
6922
- this._axiosInstance.interceptors.response.use(
6923
- (response) => {
6924
- if (response.status === 401) {
6925
- throw new KadoaHttpException("Unauthorized", {
6926
- code: KadoaErrorCode.AUTH_ERROR,
6927
- httpStatus: 401
6928
- });
6975
+ // src/client/wiring.ts
6976
+ function createSdkHeaders() {
6977
+ return {
6978
+ "User-Agent": `${SDK_NAME}/${SDK_VERSION}`,
6979
+ "X-SDK-Version": SDK_VERSION,
6980
+ "X-SDK-Language": SDK_LANGUAGE
6981
+ };
6982
+ }
6983
+ function createAxiosInstance(params) {
6984
+ const axiosInstance = globalAxios3__default.default.create({
6985
+ timeout: params.timeout,
6986
+ headers: params.headers
6987
+ });
6988
+ axiosInstance.interceptors.request.use((config) => {
6989
+ config.headers["x-request-id"] = uuid.v4();
6990
+ return config;
6991
+ });
6992
+ axiosInstance.interceptors.response.use(
6993
+ (response) => response,
6994
+ (error) => {
6995
+ if (error instanceof globalAxios3.AxiosError) {
6996
+ const status = error.response?.status;
6997
+ if (status === 401 || status === 403) {
6998
+ throw KadoaHttpException.wrap(error, { message: "Unauthorized" });
6929
6999
  }
6930
- return response;
6931
- },
6932
- (error) => {
6933
- if (error instanceof globalAxios3.AxiosError) {
6934
- const status = error.response?.status;
6935
- if (status === 400) {
6936
- throw KadoaHttpException.wrap(error);
7000
+ }
7001
+ throw KadoaHttpException.wrap(error);
7002
+ }
7003
+ );
7004
+ return axiosInstance;
7005
+ }
7006
+ function createClientDomains(params) {
7007
+ const { client } = params;
7008
+ const userService = new UserService(client);
7009
+ const dataFetcherService = new DataFetcherService(client.apis.workflows);
7010
+ const channelsService = new NotificationChannelsService(
7011
+ client.apis.notifications,
7012
+ userService
7013
+ );
7014
+ const settingsService = new NotificationSettingsService(
7015
+ client.apis.notifications
7016
+ );
7017
+ const entityResolverService = new EntityResolverService(client);
7018
+ const workflowsCoreService = new WorkflowsCoreService(client.apis.workflows);
7019
+ const schemasService = new SchemasService(client);
7020
+ const channelSetupService = new NotificationSetupService(
7021
+ channelsService,
7022
+ settingsService
7023
+ );
7024
+ const coreService = new ValidationCoreService(client);
7025
+ const rulesService = new ValidationRulesService(client);
7026
+ const extractionService = new ExtractionService(
7027
+ workflowsCoreService,
7028
+ dataFetcherService,
7029
+ entityResolverService,
7030
+ channelSetupService,
7031
+ channelsService,
7032
+ settingsService
7033
+ );
7034
+ const extractionBuilderService = new ExtractionBuilderService(
7035
+ workflowsCoreService,
7036
+ entityResolverService,
7037
+ dataFetcherService,
7038
+ channelSetupService
7039
+ );
7040
+ const notification = createNotificationDomain({
7041
+ notificationsApi: client.apis.notifications,
7042
+ channelsService,
7043
+ settingsService,
7044
+ channelSetupService
7045
+ });
7046
+ const validation = createValidationDomain(coreService, rulesService);
7047
+ const crawler = createCrawlerDomain(client);
7048
+ return {
7049
+ extractionBuilderService,
7050
+ extraction: extractionService,
7051
+ workflow: workflowsCoreService,
7052
+ notification,
7053
+ schema: schemasService,
7054
+ user: userService,
7055
+ validation,
7056
+ crawler
7057
+ };
7058
+ }
7059
+ function createNotificationDomain(params) {
7060
+ const {
7061
+ notificationsApi,
7062
+ channelsService,
7063
+ settingsService,
7064
+ channelSetupService
7065
+ } = params;
7066
+ return {
7067
+ channels: channelsService,
7068
+ settings: settingsService,
7069
+ setup: channelSetupService,
7070
+ configure: (options) => channelSetupService.setup(options),
7071
+ setupForWorkflow: (request) => channelSetupService.setupForWorkflow(request),
7072
+ setupForWorkspace: (request) => channelSetupService.setupForWorkspace(request),
7073
+ testNotification: async (request) => {
7074
+ const response = await notificationsApi.v5NotificationsTestPost({
7075
+ v5NotificationsTestPostRequest: {
7076
+ eventType: request.eventType,
7077
+ ...request.workflowId != null && {
7078
+ workflowId: request.workflowId
6937
7079
  }
6938
7080
  }
6939
- throw KadoaHttpException.wrap(error);
7081
+ });
7082
+ const data = response.data.data;
7083
+ if (!data?.eventId || !data?.eventType) {
7084
+ throw KadoaHttpException.wrap(response, {
7085
+ message: "Failed to test notification"
7086
+ });
6940
7087
  }
6941
- );
6942
- const workflowsApi = new WorkflowsApi(
6943
- this.configuration,
6944
- this.baseUrl,
6945
- this.axiosInstance
6946
- );
6947
- const notificationsApi = new NotificationsApi(
6948
- this.configuration,
6949
- this.baseUrl,
6950
- this.axiosInstance
6951
- );
6952
- const userService = new UserService(this);
6953
- const dataFetcherService = new DataFetcherService(workflowsApi);
6954
- const channelsService = new NotificationChannelsService(
6955
- notificationsApi,
6956
- userService
6957
- );
6958
- const settingsService = new NotificationSettingsService(notificationsApi);
6959
- const entityResolverService = new EntityResolverService(this);
6960
- const workflowsCoreService = new WorkflowsCoreService(workflowsApi);
6961
- const schemasService = new SchemasService(this);
6962
- const channelSetupService = new NotificationSetupService(
6963
- channelsService,
6964
- settingsService
6965
- );
6966
- const coreService = new ValidationCoreService(this);
6967
- const rulesService = new ValidationRulesService(this);
6968
- const extractionService = new ExtractionService(
6969
- workflowsCoreService,
6970
- dataFetcherService,
6971
- entityResolverService,
6972
- channelSetupService,
6973
- channelsService,
6974
- settingsService
6975
- );
6976
- this._extractionBuilderService = new ExtractionBuilderService(
6977
- workflowsCoreService,
6978
- entityResolverService,
6979
- dataFetcherService,
6980
- channelSetupService
6981
- );
6982
- this.user = userService;
6983
- this.extraction = extractionService;
6984
- this.workflow = workflowsCoreService;
6985
- this.schema = schemasService;
6986
- this.notification = {
6987
- channels: channelsService,
6988
- settings: settingsService,
6989
- setup: channelSetupService,
6990
- configure: (options) => channelSetupService.setup(options),
6991
- setupForWorkflow: (request) => channelSetupService.setupForWorkflow(request),
6992
- setupForWorkspace: (request) => channelSetupService.setupForWorkspace(request)
6993
- };
6994
- this.validation = createValidationDomain(coreService, rulesService);
6995
- this.crawler = createCrawlerDomain(this);
6996
- this._realtimeConfig = config.realtimeConfig;
6997
- if (config.enableRealtime && config.realtimeConfig?.autoConnect !== false) {
6998
- this.connectRealtime();
7088
+ return {
7089
+ eventId: data.eventId,
7090
+ eventType: data.eventType,
7091
+ ...data.workflowId != null && { workflowId: data.workflowId }
7092
+ };
6999
7093
  }
7094
+ };
7095
+ }
7096
+
7097
+ // src/client/kadoa-client.ts
7098
+ var KadoaClient = class {
7099
+ constructor(config) {
7100
+ this._baseUrl = config.baseUrl ?? PUBLIC_API_URI;
7101
+ this._apiKey = config.apiKey;
7102
+ const timeout = config.timeout ?? 3e4;
7103
+ const headers = createSdkHeaders();
7104
+ this._axiosInstance = createAxiosInstance({ timeout, headers });
7105
+ this.apis = new ApiRegistry(
7106
+ this._apiKey,
7107
+ this._baseUrl,
7108
+ this._axiosInstance,
7109
+ headers
7110
+ );
7111
+ const domains = createClientDomains({ client: this });
7112
+ this.user = domains.user;
7113
+ this.extraction = domains.extraction;
7114
+ this.workflow = domains.workflow;
7115
+ this.schema = domains.schema;
7116
+ this.notification = domains.notification;
7117
+ this.validation = domains.validation;
7118
+ this.crawler = domains.crawler;
7119
+ this._extractionBuilderService = domains.extractionBuilderService;
7000
7120
  checkForUpdates().catch(() => {
7001
7121
  });
7002
7122
  }
7003
- /**
7004
- * Get the underlying configuration
7005
- *
7006
- * @returns The configuration object
7007
- */
7008
- get configuration() {
7009
- return this._configuration;
7010
- }
7011
7123
  /**
7012
7124
  * Get the axios instance
7013
7125
  *
@@ -7032,14 +7144,6 @@ var KadoaClient = class {
7032
7144
  get apiKey() {
7033
7145
  return this._apiKey;
7034
7146
  }
7035
- /**
7036
- * Get the timeout value
7037
- *
7038
- * @returns The timeout in milliseconds
7039
- */
7040
- get timeout() {
7041
- return this._timeout;
7042
- }
7043
7147
  /**
7044
7148
  * Get the realtime connection (if enabled)
7045
7149
  */
@@ -7051,35 +7155,6 @@ var KadoaClient = class {
7051
7155
  *
7052
7156
  * @param options - Extraction options including URLs and optional extraction builder
7053
7157
  * @returns PreparedExtraction that can be configured with notifications, monitoring, etc.
7054
- *
7055
- * @example Auto-detection
7056
- * ```typescript
7057
- * const extraction = await client.extract({
7058
- * urls: ["https://example.com"],
7059
- * name: "My Extraction"
7060
- * }).create();
7061
- * ```
7062
- *
7063
- * @example Raw extraction
7064
- * ```typescript
7065
- * const extraction = await client.extract({
7066
- * urls: ["https://example.com"],
7067
- * name: "My Extraction",
7068
- * extraction: builder => builder.raw("markdown")
7069
- * }).create();
7070
- * ```
7071
- *
7072
- * @example Custom schema
7073
- * ```typescript
7074
- * const extraction = await client.extract({
7075
- * urls: ["https://example.com"],
7076
- * name: "My Extraction",
7077
- * extraction: builder => builder
7078
- * .schema("Product")
7079
- * .field("title", "Product name", "STRING", { example: "Example" })
7080
- * .field("price", "Product price", "CURRENCY")
7081
- * }).create();
7082
- * ```
7083
7158
  */
7084
7159
  extract(options) {
7085
7160
  return this._extractionBuilderService.extract(options);
@@ -7088,23 +7163,13 @@ var KadoaClient = class {
7088
7163
  * Connect to realtime WebSocket server
7089
7164
  * Creates a new connection if not already connected
7090
7165
  *
7166
+ * @param options - Optional realtime tuning options (heartbeat/reconnect settings)
7091
7167
  * @returns The Realtime instance
7092
7168
  */
7093
- connectRealtime() {
7169
+ async connectRealtime(options) {
7094
7170
  if (!this._realtime) {
7095
- this._realtime = new Realtime({
7096
- apiKey: this._apiKey,
7097
- ...this._realtimeConfig?.reconnectDelay != null && {
7098
- reconnectDelay: this._realtimeConfig.reconnectDelay
7099
- },
7100
- ...this._realtimeConfig?.heartbeatInterval != null && {
7101
- heartbeatInterval: this._realtimeConfig.heartbeatInterval
7102
- },
7103
- ...this._realtimeConfig?.source && {
7104
- source: this._realtimeConfig.source
7105
- }
7106
- });
7107
- this._realtime.connect();
7171
+ this._realtime = new Realtime({ apiKey: this._apiKey, ...options });
7172
+ await this._realtime.connect();
7108
7173
  }
7109
7174
  return this._realtime;
7110
7175
  }
@@ -7143,8 +7208,16 @@ var KadoaClient = class {
7143
7208
  dispose() {
7144
7209
  this.disconnectRealtime();
7145
7210
  }
7211
+ /**
7212
+ * Alias for {@link dispose}. Included for common Node.js client ergonomics.
7213
+ */
7214
+ close() {
7215
+ this.dispose();
7216
+ }
7146
7217
  };
7147
7218
 
7219
+ exports.CrawlerConfigService = CrawlerConfigService;
7220
+ exports.CrawlerSessionService = CrawlerSessionService;
7148
7221
  exports.DataFetcherService = DataFetcherService;
7149
7222
  exports.ERROR_MESSAGES = ERROR_MESSAGES;
7150
7223
  exports.EntityResolverService = EntityResolverService;
@@ -7159,6 +7232,7 @@ exports.NotificationChannelsService = NotificationChannelsService;
7159
7232
  exports.NotificationSettingsEventTypeEnum = V5NotificationsSettingsGetEventTypeEnum;
7160
7233
  exports.NotificationSettingsService = NotificationSettingsService;
7161
7234
  exports.NotificationSetupService = NotificationSetupService;
7235
+ exports.PageStatus = PageStatus;
7162
7236
  exports.Realtime = Realtime;
7163
7237
  exports.SchemaBuilder = SchemaBuilder;
7164
7238
  exports.SchemaFieldDataType = SchemaFieldDataType;
@@ -7169,6 +7243,7 @@ exports.UserService = UserService;
7169
7243
  exports.ValidationCoreService = ValidationCoreService;
7170
7244
  exports.ValidationRulesService = ValidationRulesService;
7171
7245
  exports.WorkflowsCoreService = WorkflowsCoreService;
7246
+ exports.createCrawlerDomain = createCrawlerDomain;
7172
7247
  exports.pollUntil = pollUntil;
7173
7248
  exports.validateAdditionalData = validateAdditionalData;
7174
7249
  //# sourceMappingURL=index.js.map