@whaly/connector-sdk 0.3.11 → 0.3.13
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.d.mts +25 -4
- package/dist/index.d.ts +25 -4
- package/dist/index.js +44 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1489,6 +1489,12 @@ interface WhalyDocument {
|
|
|
1489
1489
|
size_kb: number;
|
|
1490
1490
|
storage: string;
|
|
1491
1491
|
metadata: Record<string, string> | null;
|
|
1492
|
+
/**
|
|
1493
|
+
* The document source this document belongs to.
|
|
1494
|
+
* `null` means the org's default source. On create this field is optional —
|
|
1495
|
+
* when omitted the document is attached to the default source.
|
|
1496
|
+
*/
|
|
1497
|
+
document_source_id: string | null;
|
|
1492
1498
|
}
|
|
1493
1499
|
/** Paginated response from the Whaly Document API. */
|
|
1494
1500
|
interface WhalyPaginatedResponse<T> {
|
|
@@ -1566,6 +1572,16 @@ interface WhalyDocumentServiceConfig {
|
|
|
1566
1572
|
serviceAccountKey?: string;
|
|
1567
1573
|
/** Object storage ID for file uploads. */
|
|
1568
1574
|
objectStorageId: string;
|
|
1575
|
+
/**
|
|
1576
|
+
* The document source this connector manages. One connector maps to exactly
|
|
1577
|
+
* one source. All operations are scoped to it:
|
|
1578
|
+
* - `listAllDocuments()` only returns documents belonging to this source,
|
|
1579
|
+
* so the reconciliation (create / update / **delete**) never touches
|
|
1580
|
+
* documents from other sources — important because the DocumentTap
|
|
1581
|
+
* deletes any listed document not present in the source.
|
|
1582
|
+
* - Created and updated documents are always attached to this source.
|
|
1583
|
+
*/
|
|
1584
|
+
documentSourceId: string;
|
|
1569
1585
|
}
|
|
1570
1586
|
interface WhalyUploadResult {
|
|
1571
1587
|
storage: string;
|
|
@@ -1575,17 +1591,22 @@ interface WhalyUploadResult {
|
|
|
1575
1591
|
declare class WhalyDocumentService {
|
|
1576
1592
|
private axiosClient;
|
|
1577
1593
|
readonly objectStorageId: string;
|
|
1594
|
+
readonly documentSourceId: string;
|
|
1578
1595
|
private gcsBucket;
|
|
1579
1596
|
constructor(config: WhalyDocumentServiceConfig);
|
|
1580
|
-
/**
|
|
1597
|
+
/**
|
|
1598
|
+
* Fetch all documents belonging to the configured document source,
|
|
1599
|
+
* handling cursor-based pagination. The `document_source_id` server-side
|
|
1600
|
+
* filter scopes the result to this connector's source only.
|
|
1601
|
+
*/
|
|
1581
1602
|
listAllDocuments(): Promise<WhalyDocument[]>;
|
|
1582
1603
|
/** Upload a file to object storage. Returns storage path and size. */
|
|
1583
1604
|
uploadFile(destinationPath: string, localFilePath: string, fileName: string): Promise<WhalyUploadResult>;
|
|
1584
1605
|
private uploadFileViaGCS;
|
|
1585
1606
|
private uploadFileViaAPI;
|
|
1586
|
-
/** Create a new document record. */
|
|
1587
|
-
createDocument(payload: Omit<WhalyDocument, "id">): Promise<WhalyDocument>;
|
|
1588
|
-
/** Update an existing document record. */
|
|
1607
|
+
/** Create a new document record, attached to the configured document source. */
|
|
1608
|
+
createDocument(payload: Omit<WhalyDocument, "id" | "document_source_id">): Promise<WhalyDocument>;
|
|
1609
|
+
/** Update an existing document record, keeping it in the configured document source. */
|
|
1589
1610
|
updateDocument(id: string, payload: Partial<WhalyDocument>): Promise<WhalyDocument>;
|
|
1590
1611
|
/** Delete a document record. */
|
|
1591
1612
|
deleteDocument(id: string): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1489,6 +1489,12 @@ interface WhalyDocument {
|
|
|
1489
1489
|
size_kb: number;
|
|
1490
1490
|
storage: string;
|
|
1491
1491
|
metadata: Record<string, string> | null;
|
|
1492
|
+
/**
|
|
1493
|
+
* The document source this document belongs to.
|
|
1494
|
+
* `null` means the org's default source. On create this field is optional —
|
|
1495
|
+
* when omitted the document is attached to the default source.
|
|
1496
|
+
*/
|
|
1497
|
+
document_source_id: string | null;
|
|
1492
1498
|
}
|
|
1493
1499
|
/** Paginated response from the Whaly Document API. */
|
|
1494
1500
|
interface WhalyPaginatedResponse<T> {
|
|
@@ -1566,6 +1572,16 @@ interface WhalyDocumentServiceConfig {
|
|
|
1566
1572
|
serviceAccountKey?: string;
|
|
1567
1573
|
/** Object storage ID for file uploads. */
|
|
1568
1574
|
objectStorageId: string;
|
|
1575
|
+
/**
|
|
1576
|
+
* The document source this connector manages. One connector maps to exactly
|
|
1577
|
+
* one source. All operations are scoped to it:
|
|
1578
|
+
* - `listAllDocuments()` only returns documents belonging to this source,
|
|
1579
|
+
* so the reconciliation (create / update / **delete**) never touches
|
|
1580
|
+
* documents from other sources — important because the DocumentTap
|
|
1581
|
+
* deletes any listed document not present in the source.
|
|
1582
|
+
* - Created and updated documents are always attached to this source.
|
|
1583
|
+
*/
|
|
1584
|
+
documentSourceId: string;
|
|
1569
1585
|
}
|
|
1570
1586
|
interface WhalyUploadResult {
|
|
1571
1587
|
storage: string;
|
|
@@ -1575,17 +1591,22 @@ interface WhalyUploadResult {
|
|
|
1575
1591
|
declare class WhalyDocumentService {
|
|
1576
1592
|
private axiosClient;
|
|
1577
1593
|
readonly objectStorageId: string;
|
|
1594
|
+
readonly documentSourceId: string;
|
|
1578
1595
|
private gcsBucket;
|
|
1579
1596
|
constructor(config: WhalyDocumentServiceConfig);
|
|
1580
|
-
/**
|
|
1597
|
+
/**
|
|
1598
|
+
* Fetch all documents belonging to the configured document source,
|
|
1599
|
+
* handling cursor-based pagination. The `document_source_id` server-side
|
|
1600
|
+
* filter scopes the result to this connector's source only.
|
|
1601
|
+
*/
|
|
1581
1602
|
listAllDocuments(): Promise<WhalyDocument[]>;
|
|
1582
1603
|
/** Upload a file to object storage. Returns storage path and size. */
|
|
1583
1604
|
uploadFile(destinationPath: string, localFilePath: string, fileName: string): Promise<WhalyUploadResult>;
|
|
1584
1605
|
private uploadFileViaGCS;
|
|
1585
1606
|
private uploadFileViaAPI;
|
|
1586
|
-
/** Create a new document record. */
|
|
1587
|
-
createDocument(payload: Omit<WhalyDocument, "id">): Promise<WhalyDocument>;
|
|
1588
|
-
/** Update an existing document record. */
|
|
1607
|
+
/** Create a new document record, attached to the configured document source. */
|
|
1608
|
+
createDocument(payload: Omit<WhalyDocument, "id" | "document_source_id">): Promise<WhalyDocument>;
|
|
1609
|
+
/** Update an existing document record, keeping it in the configured document source. */
|
|
1589
1610
|
updateDocument(id: string, payload: Partial<WhalyDocument>): Promise<WhalyDocument>;
|
|
1590
1611
|
/** Delete a document record. */
|
|
1591
1612
|
deleteDocument(id: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -11317,6 +11317,20 @@ var Tap = class {
|
|
|
11317
11317
|
|
|
11318
11318
|
// src/sdk/models/tap/stream.ts
|
|
11319
11319
|
var import_util2 = require("util");
|
|
11320
|
+
var DEFAULT_PROGRESS_LOG_PERCENT_STEP = 10;
|
|
11321
|
+
var DEFAULT_PROGRESS_LOG_FALLBACK_INTERVAL = 1e5;
|
|
11322
|
+
function getProgressLogPercentStep() {
|
|
11323
|
+
const raw = optionalEnv("PROGRESS_LOG_PERCENT_STEP", String(DEFAULT_PROGRESS_LOG_PERCENT_STEP));
|
|
11324
|
+
const n = parseInt(raw, 10);
|
|
11325
|
+
if (isNaN(n) || n <= 0) return DEFAULT_PROGRESS_LOG_PERCENT_STEP;
|
|
11326
|
+
return Math.min(n, 100);
|
|
11327
|
+
}
|
|
11328
|
+
function getProgressLogFallbackInterval() {
|
|
11329
|
+
const raw = optionalEnv("PROGRESS_LOG_FALLBACK_INTERVAL", String(DEFAULT_PROGRESS_LOG_FALLBACK_INTERVAL));
|
|
11330
|
+
const n = parseInt(raw, 10);
|
|
11331
|
+
if (isNaN(n) || n <= 0) return DEFAULT_PROGRESS_LOG_FALLBACK_INTERVAL;
|
|
11332
|
+
return n;
|
|
11333
|
+
}
|
|
11320
11334
|
var Stream = class {
|
|
11321
11335
|
// Runtime values, can't be overriden
|
|
11322
11336
|
config;
|
|
@@ -11579,6 +11593,9 @@ var Stream = class {
|
|
|
11579
11593
|
// Private sync methods:
|
|
11580
11594
|
async _syncRecords(parent) {
|
|
11581
11595
|
let rowsSent = 0;
|
|
11596
|
+
let lastLoggedPercent = 0;
|
|
11597
|
+
const progressPercentStep = getProgressLogPercentStep();
|
|
11598
|
+
const progressFallbackInterval = getProgressLogFallbackInterval();
|
|
11582
11599
|
const dryRunLimit = isDryRun() ? getDryRunLimit() : void 0;
|
|
11583
11600
|
let recordSyncedMetrics = [];
|
|
11584
11601
|
if (this.rowsSyncedMetricsConf.isEnabled() === true) {
|
|
@@ -11625,9 +11642,14 @@ var Stream = class {
|
|
|
11625
11642
|
logger.info(`\u{1F6D1} Stream: ${this.streamId} - DRY_RUN_LIMIT reached (${dryRunLimit} records), stopping.`);
|
|
11626
11643
|
break;
|
|
11627
11644
|
}
|
|
11628
|
-
if (
|
|
11629
|
-
const
|
|
11630
|
-
|
|
11645
|
+
if (this.totalRows) {
|
|
11646
|
+
const percent = Math.floor(rowsSent / this.totalRows * 100);
|
|
11647
|
+
if (percent >= lastLoggedPercent + progressPercentStep) {
|
|
11648
|
+
lastLoggedPercent = percent - percent % progressPercentStep;
|
|
11649
|
+
logger.info(`\u23F3 Stream: ${this.streamId} - ${rowsSent} records synced so far... (${percent}%)`);
|
|
11650
|
+
}
|
|
11651
|
+
} else if (rowsSent % progressFallbackInterval === 0) {
|
|
11652
|
+
logger.info(`\u23F3 Stream: ${this.streamId} - ${rowsSent} records synced so far...`);
|
|
11631
11653
|
}
|
|
11632
11654
|
}
|
|
11633
11655
|
const stateServiceInst = StateService.getInstance();
|
|
@@ -14782,11 +14804,13 @@ var MAX_RETRIES2 = 10;
|
|
|
14782
14804
|
var WhalyDocumentService = class {
|
|
14783
14805
|
axiosClient;
|
|
14784
14806
|
objectStorageId;
|
|
14807
|
+
documentSourceId;
|
|
14785
14808
|
gcsBucket;
|
|
14786
14809
|
constructor(config) {
|
|
14787
14810
|
const resolvedKey = getServiceAccountKey(config.serviceAccountKey);
|
|
14788
14811
|
const resolvedEndpoint = getApiEndpoint(config.apiEndpoint);
|
|
14789
14812
|
this.objectStorageId = config.objectStorageId;
|
|
14813
|
+
this.documentSourceId = config.documentSourceId;
|
|
14790
14814
|
const gcsBucketName = process.env["WLY_GCS_BUCKET"];
|
|
14791
14815
|
if (gcsBucketName) {
|
|
14792
14816
|
this.gcsBucket = new import_storage2.Storage().bucket(gcsBucketName);
|
|
@@ -14821,12 +14845,16 @@ var WhalyDocumentService = class {
|
|
|
14821
14845
|
}
|
|
14822
14846
|
});
|
|
14823
14847
|
}
|
|
14824
|
-
/**
|
|
14848
|
+
/**
|
|
14849
|
+
* Fetch all documents belonging to the configured document source,
|
|
14850
|
+
* handling cursor-based pagination. The `document_source_id` server-side
|
|
14851
|
+
* filter scopes the result to this connector's source only.
|
|
14852
|
+
*/
|
|
14825
14853
|
async listAllDocuments() {
|
|
14826
14854
|
const documents = [];
|
|
14827
14855
|
let after;
|
|
14828
14856
|
while (true) {
|
|
14829
|
-
const params = {};
|
|
14857
|
+
const params = { document_source_id: this.documentSourceId };
|
|
14830
14858
|
if (after) params["after"] = after;
|
|
14831
14859
|
const response = await this.axiosClient.get(
|
|
14832
14860
|
"/v1/documents",
|
|
@@ -14886,19 +14914,26 @@ var WhalyDocumentService = class {
|
|
|
14886
14914
|
throw enrichAxiosError(err);
|
|
14887
14915
|
}
|
|
14888
14916
|
}
|
|
14889
|
-
/** Create a new document record. */
|
|
14917
|
+
/** Create a new document record, attached to the configured document source. */
|
|
14890
14918
|
async createDocument(payload) {
|
|
14891
14919
|
try {
|
|
14892
|
-
const response = await this.axiosClient.post("/v1/documents",
|
|
14920
|
+
const response = await this.axiosClient.post("/v1/documents", {
|
|
14921
|
+
...payload,
|
|
14922
|
+
document_source_id: this.documentSourceId
|
|
14923
|
+
});
|
|
14893
14924
|
return response.data.data ?? response.data;
|
|
14894
14925
|
} catch (err) {
|
|
14895
14926
|
throw enrichAxiosError(err);
|
|
14896
14927
|
}
|
|
14897
14928
|
}
|
|
14898
|
-
/** Update an existing document record. */
|
|
14929
|
+
/** Update an existing document record, keeping it in the configured document source. */
|
|
14899
14930
|
async updateDocument(id, payload) {
|
|
14900
14931
|
try {
|
|
14901
|
-
const response = await this.axiosClient.put(`/v1/documents/${id}`, {
|
|
14932
|
+
const response = await this.axiosClient.put(`/v1/documents/${id}`, {
|
|
14933
|
+
id,
|
|
14934
|
+
...payload,
|
|
14935
|
+
document_source_id: this.documentSourceId
|
|
14936
|
+
});
|
|
14902
14937
|
return response.data.data ?? response.data;
|
|
14903
14938
|
} catch (err) {
|
|
14904
14939
|
throw enrichAxiosError(err);
|