@onkernel/sdk 0.80.0 → 0.81.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/CHANGELOG.md +8 -0
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/lib/audit-log-download.d.mts +28 -0
- package/lib/audit-log-download.d.mts.map +1 -0
- package/lib/audit-log-download.d.ts +28 -0
- package/lib/audit-log-download.d.ts.map +1 -0
- package/lib/audit-log-download.js +176 -0
- package/lib/audit-log-download.js.map +1 -0
- package/lib/audit-log-download.mjs +171 -0
- package/lib/audit-log-download.mjs.map +1 -0
- package/package.json +1 -1
- package/resources/audit-logs.d.mts +11 -1
- package/resources/audit-logs.d.mts.map +1 -1
- package/resources/audit-logs.d.ts +11 -1
- package/resources/audit-logs.d.ts.map +1 -1
- package/resources/audit-logs.js +11 -0
- package/resources/audit-logs.js.map +1 -1
- package/resources/audit-logs.mjs +11 -0
- package/resources/audit-logs.mjs.map +1 -1
- package/src/index.ts +9 -0
- package/src/lib/audit-log-download.ts +234 -0
- package/src/resources/audit-logs.ts +42 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.81.0 (2026-07-21)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.80.0...v0.81.0](https://github.com/kernel/kernel-node-sdk/compare/v0.80.0...v0.81.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* add complete audit log downloads ([6cb8e9e](https://github.com/kernel/kernel-node-sdk/commit/6cb8e9e38540b5e2954a6304b61b848fca70909e))
|
|
10
|
+
|
|
3
11
|
## 0.80.0 (2026-07-19)
|
|
4
12
|
|
|
5
13
|
Full Changelog: [v0.79.0...v0.80.0](https://github.com/kernel/kernel-node-sdk/compare/v0.79.0...v0.80.0)
|
package/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ export { type Uploadable, toFile } from "./core/uploads.mjs";
|
|
|
3
3
|
export { APIPromise } from "./core/api-promise.mjs";
|
|
4
4
|
export { Kernel, type ClientOptions } from "./client.mjs";
|
|
5
5
|
export { type BrowserFetchInit } from "./lib/browser-fetch.mjs";
|
|
6
|
+
export { AuditLogDownloadError, type AuditLogDownloadDestination, type AuditLogDownloadOptions, type AuditLogDownloadParams, type AuditLogDownloadProgress, type AuditLogDownloadResult, type AuditLogDownloadWriteResult, } from "./lib/audit-log-download.mjs";
|
|
6
7
|
export { BrowserRouteCache, type BrowserRoute } from "./lib/browser-routing.mjs";
|
|
7
8
|
export { PagePromise } from "./core/pagination.mjs";
|
|
8
9
|
export { KernelError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./core/error.mjs";
|
package/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,qBAAiB;AAE7C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,2BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,+BAA2B;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,qBAAiB;AACtD,OAAO,EAAE,KAAK,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,kCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,8BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,yBAAqB;AAEtB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,iCAA6B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,qBAAiB;AAE7C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,2BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,+BAA2B;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,qBAAiB;AACtD,OAAO,EAAE,KAAK,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACjC,qCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,kCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,8BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,yBAAqB;AAEtB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,iCAA6B"}
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { type Uploadable, toFile } from "./core/uploads.js";
|
|
|
3
3
|
export { APIPromise } from "./core/api-promise.js";
|
|
4
4
|
export { Kernel, type ClientOptions } from "./client.js";
|
|
5
5
|
export { type BrowserFetchInit } from "./lib/browser-fetch.js";
|
|
6
|
+
export { AuditLogDownloadError, type AuditLogDownloadDestination, type AuditLogDownloadOptions, type AuditLogDownloadParams, type AuditLogDownloadProgress, type AuditLogDownloadResult, type AuditLogDownloadWriteResult, } from "./lib/audit-log-download.js";
|
|
6
7
|
export { BrowserRouteCache, type BrowserRoute } from "./lib/browser-routing.js";
|
|
7
8
|
export { PagePromise } from "./core/pagination.js";
|
|
8
9
|
export { KernelError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./core/error.js";
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,oBAAiB;AAE7C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,0BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,8BAA2B;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,oBAAiB;AACtD,OAAO,EAAE,KAAK,gBAAgB,EAAE,+BAA4B;AAC5D,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,iCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,6BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,wBAAqB;AAEtB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,gCAA6B"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,oBAAiB;AAE7C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,0BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,8BAA2B;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,oBAAiB;AACtD,OAAO,EAAE,KAAK,gBAAgB,EAAE,+BAA4B;AAC5D,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACjC,oCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,iCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,6BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,wBAAqB;AAEtB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,gCAA6B"}
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports = module.exports = function (...args) {
|
|
|
4
4
|
return new exports.default(...args)
|
|
5
5
|
}
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.appRegistry = exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.KernelError = exports.PagePromise = exports.BrowserRouteCache = exports.Kernel = exports.APIPromise = exports.toFile = exports.default = void 0;
|
|
7
|
+
exports.appRegistry = exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.KernelError = exports.PagePromise = exports.BrowserRouteCache = exports.AuditLogDownloadError = exports.Kernel = exports.APIPromise = exports.toFile = exports.default = void 0;
|
|
8
8
|
var client_1 = require("./client.js");
|
|
9
9
|
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return client_1.Kernel; } });
|
|
10
10
|
var uploads_1 = require("./core/uploads.js");
|
|
@@ -13,6 +13,8 @@ var api_promise_1 = require("./core/api-promise.js");
|
|
|
13
13
|
Object.defineProperty(exports, "APIPromise", { enumerable: true, get: function () { return api_promise_1.APIPromise; } });
|
|
14
14
|
var client_2 = require("./client.js");
|
|
15
15
|
Object.defineProperty(exports, "Kernel", { enumerable: true, get: function () { return client_2.Kernel; } });
|
|
16
|
+
var audit_log_download_1 = require("./lib/audit-log-download.js");
|
|
17
|
+
Object.defineProperty(exports, "AuditLogDownloadError", { enumerable: true, get: function () { return audit_log_download_1.AuditLogDownloadError; } });
|
|
16
18
|
var browser_routing_1 = require("./lib/browser-routing.js");
|
|
17
19
|
Object.defineProperty(exports, "BrowserRouteCache", { enumerable: true, get: function () { return browser_routing_1.BrowserRouteCache; } });
|
|
18
20
|
var pagination_1 = require("./core/pagination.js");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,sCAA6C;AAApC,iGAAA,MAAM,OAAW;AAE1B,6CAAyD;AAA/B,iGAAA,MAAM,OAAA;AAChC,qDAAgD;AAAvC,yGAAA,UAAU,OAAA;AACnB,sCAAsD;AAA7C,gGAAA,MAAM,OAAA;AAEf,4DAA6E;AAApE,oHAAA,iBAAiB,OAAA;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HANGED
|
@@ -3,6 +3,7 @@ export { Kernel as default } from "./client.mjs";
|
|
|
3
3
|
export { toFile } from "./core/uploads.mjs";
|
|
4
4
|
export { APIPromise } from "./core/api-promise.mjs";
|
|
5
5
|
export { Kernel } from "./client.mjs";
|
|
6
|
+
export { AuditLogDownloadError, } from "./lib/audit-log-download.mjs";
|
|
6
7
|
export { BrowserRouteCache } from "./lib/browser-routing.mjs";
|
|
7
8
|
export { PagePromise } from "./core/pagination.mjs";
|
|
8
9
|
export { KernelError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./core/error.mjs";
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,qBAAiB;AAE7C,OAAO,EAAmB,MAAM,EAAE,2BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,+BAA2B;AAChD,OAAO,EAAE,MAAM,EAAsB,qBAAiB;AAEtD,OAAO,EAAE,iBAAiB,EAAqB,kCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,8BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,yBAAqB;AAEtB,OAAO,EAA2C,WAAW,EAAE,iCAA6B"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,qBAAiB;AAE7C,OAAO,EAAmB,MAAM,EAAE,2BAAuB;AACzD,OAAO,EAAE,UAAU,EAAE,+BAA2B;AAChD,OAAO,EAAE,MAAM,EAAsB,qBAAiB;AAEtD,OAAO,EACL,qBAAqB,GAOtB,qCAAiC;AAClC,OAAO,EAAE,iBAAiB,EAAqB,kCAA8B;AAC7E,OAAO,EAAE,WAAW,EAAE,8BAA0B;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,yBAAqB;AAEtB,OAAO,EAA2C,WAAW,EAAE,iCAA6B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KernelError } from "../core/error.mjs";
|
|
2
|
+
import type { RequestOptions } from "../internal/request-options.mjs";
|
|
3
|
+
import type { AuditLogExportChunkParams } from "../resources/audit-logs.mjs";
|
|
4
|
+
export declare class AuditLogDownloadError extends KernelError {
|
|
5
|
+
}
|
|
6
|
+
export type AuditLogDownloadParams = Omit<AuditLogExportChunkParams, 'cursor' | 'format'>;
|
|
7
|
+
export interface AuditLogDownloadResult {
|
|
8
|
+
bytesWritten: number;
|
|
9
|
+
chunks: number;
|
|
10
|
+
rows: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AuditLogDownloadProgress extends AuditLogDownloadResult {
|
|
13
|
+
chunkRows: number;
|
|
14
|
+
}
|
|
15
|
+
export type AuditLogDownloadWriteResult = void | number | {
|
|
16
|
+
bytesWritten: number;
|
|
17
|
+
};
|
|
18
|
+
export interface AuditLogDownloadDestination {
|
|
19
|
+
write(chunk: Uint8Array): AuditLogDownloadWriteResult | Promise<AuditLogDownloadWriteResult>;
|
|
20
|
+
}
|
|
21
|
+
export interface AuditLogDownloadOptions extends Omit<RequestOptions, 'method' | 'path' | 'query' | 'body' | 'stream' | '__binaryResponse' | '__streamClass'> {
|
|
22
|
+
onProgress?(progress: AuditLogDownloadProgress): void | Promise<void>;
|
|
23
|
+
maxTransferRetries?: number;
|
|
24
|
+
}
|
|
25
|
+
type FetchChunk = (query: AuditLogExportChunkParams, options?: RequestOptions) => Promise<Response>;
|
|
26
|
+
export declare function downloadAuditLogs(fetchChunk: FetchChunk, query: AuditLogDownloadParams, destination: AuditLogDownloadDestination, defaultTimeout: number, options?: AuditLogDownloadOptions): Promise<AuditLogDownloadResult>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=audit-log-download.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-download.d.mts","sourceRoot":"","sources":["../src/lib/audit-log-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,WAAW,EAAE,0BAAsB;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,wCAAoC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,oCAAgC;AAMzE,qBAAa,qBAAsB,SAAQ,WAAW;CAAG;AAEzD,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,yBAAyB,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAE1F,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,wBAAyB,SAAQ,sBAAsB;IACtE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,2BAA2B,GAAG,IAAI,GAAG,MAAM,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC9F;AAED,MAAM,WAAW,uBACf,SAAQ,IAAI,CACV,cAAc,EACd,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,kBAAkB,GAAG,eAAe,CACvF;IACD,UAAU,CAAC,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,yBAAyB,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEpG,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,sBAAsB,EAC7B,WAAW,EAAE,2BAA2B,EACxC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CA0CjC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { KernelError } from "../core/error.js";
|
|
2
|
+
import type { RequestOptions } from "../internal/request-options.js";
|
|
3
|
+
import type { AuditLogExportChunkParams } from "../resources/audit-logs.js";
|
|
4
|
+
export declare class AuditLogDownloadError extends KernelError {
|
|
5
|
+
}
|
|
6
|
+
export type AuditLogDownloadParams = Omit<AuditLogExportChunkParams, 'cursor' | 'format'>;
|
|
7
|
+
export interface AuditLogDownloadResult {
|
|
8
|
+
bytesWritten: number;
|
|
9
|
+
chunks: number;
|
|
10
|
+
rows: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AuditLogDownloadProgress extends AuditLogDownloadResult {
|
|
13
|
+
chunkRows: number;
|
|
14
|
+
}
|
|
15
|
+
export type AuditLogDownloadWriteResult = void | number | {
|
|
16
|
+
bytesWritten: number;
|
|
17
|
+
};
|
|
18
|
+
export interface AuditLogDownloadDestination {
|
|
19
|
+
write(chunk: Uint8Array): AuditLogDownloadWriteResult | Promise<AuditLogDownloadWriteResult>;
|
|
20
|
+
}
|
|
21
|
+
export interface AuditLogDownloadOptions extends Omit<RequestOptions, 'method' | 'path' | 'query' | 'body' | 'stream' | '__binaryResponse' | '__streamClass'> {
|
|
22
|
+
onProgress?(progress: AuditLogDownloadProgress): void | Promise<void>;
|
|
23
|
+
maxTransferRetries?: number;
|
|
24
|
+
}
|
|
25
|
+
type FetchChunk = (query: AuditLogExportChunkParams, options?: RequestOptions) => Promise<Response>;
|
|
26
|
+
export declare function downloadAuditLogs(fetchChunk: FetchChunk, query: AuditLogDownloadParams, destination: AuditLogDownloadDestination, defaultTimeout: number, options?: AuditLogDownloadOptions): Promise<AuditLogDownloadResult>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=audit-log-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-download.d.ts","sourceRoot":"","sources":["../src/lib/audit-log-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,WAAW,EAAE,yBAAsB;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,uCAAoC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,mCAAgC;AAMzE,qBAAa,qBAAsB,SAAQ,WAAW;CAAG;AAEzD,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,yBAAyB,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAE1F,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,wBAAyB,SAAQ,sBAAsB;IACtE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,2BAA2B,GAAG,IAAI,GAAG,MAAM,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,2BAA2B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;CAC9F;AAED,MAAM,WAAW,uBACf,SAAQ,IAAI,CACV,cAAc,EACd,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,kBAAkB,GAAG,eAAe,CACvF;IACD,UAAU,CAAC,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,KAAK,UAAU,GAAG,CAAC,KAAK,EAAE,yBAAyB,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEpG,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,sBAAsB,EAC7B,WAAW,EAAE,2BAA2B,EACxC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,sBAAsB,CAAC,CA0CjC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuditLogDownloadError = void 0;
|
|
4
|
+
exports.downloadAuditLogs = downloadAuditLogs;
|
|
5
|
+
const error_1 = require("../core/error.js");
|
|
6
|
+
const DEFAULT_MAX_TRANSFER_RETRIES = 6;
|
|
7
|
+
const MAX_CHUNK_ROWS = 50000;
|
|
8
|
+
const MAX_RETRY_DELAY_MS = 8000;
|
|
9
|
+
class AuditLogDownloadError extends error_1.KernelError {
|
|
10
|
+
}
|
|
11
|
+
exports.AuditLogDownloadError = AuditLogDownloadError;
|
|
12
|
+
async function downloadAuditLogs(fetchChunk, query, destination, defaultTimeout, options = {}) {
|
|
13
|
+
if (!destination || typeof destination.write !== 'function') {
|
|
14
|
+
throw new TypeError('audit log download destination must provide write()');
|
|
15
|
+
}
|
|
16
|
+
const { onProgress, maxTransferRetries = DEFAULT_MAX_TRANSFER_RETRIES, ...requestOptions } = options;
|
|
17
|
+
if (!Number.isInteger(maxTransferRetries) || maxTransferRetries < 0) {
|
|
18
|
+
throw new TypeError('maxTransferRetries must be a non-negative integer');
|
|
19
|
+
}
|
|
20
|
+
const timeout = requestOptions.timeout ?? defaultTimeout;
|
|
21
|
+
let cursor;
|
|
22
|
+
const result = { bytesWritten: 0, chunks: 0, rows: 0 };
|
|
23
|
+
const seenCursors = new Set();
|
|
24
|
+
while (true) {
|
|
25
|
+
const chunk = await fetchVerifiedChunk(fetchChunk, cursor ? { ...query, cursor } : query, requestOptions, maxTransferRetries, timeout);
|
|
26
|
+
const { nextCursor, hasMore, rows } = parseChunkHeaders(chunk.headers, cursor);
|
|
27
|
+
if (hasMore && nextCursor) {
|
|
28
|
+
if (seenCursors.has(nextCursor)) {
|
|
29
|
+
throw new AuditLogDownloadError('response repeated X-Next-Cursor header');
|
|
30
|
+
}
|
|
31
|
+
seenCursors.add(nextCursor);
|
|
32
|
+
}
|
|
33
|
+
await writeChunk(destination, chunk.body);
|
|
34
|
+
cursor = nextCursor;
|
|
35
|
+
result.bytesWritten += chunk.body.byteLength;
|
|
36
|
+
result.chunks += 1;
|
|
37
|
+
result.rows += rows;
|
|
38
|
+
if (onProgress) {
|
|
39
|
+
await onProgress({ ...result, chunkRows: rows });
|
|
40
|
+
}
|
|
41
|
+
if (!hasMore) {
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function fetchVerifiedChunk(fetchChunk, query, options, maxTransferRetries, timeout) {
|
|
47
|
+
for (let retries = 0;; retries += 1) {
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const onAbort = () => controller.abort();
|
|
50
|
+
if (options.signal?.aborted) {
|
|
51
|
+
controller.abort();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
55
|
+
}
|
|
56
|
+
let response;
|
|
57
|
+
try {
|
|
58
|
+
response = await fetchChunk(query, { ...options, signal: controller.signal });
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
let bodyTimedOut = false;
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
bodyTimedOut = true;
|
|
67
|
+
controller.abort();
|
|
68
|
+
}, timeout);
|
|
69
|
+
try {
|
|
70
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
if (options.signal?.aborted) {
|
|
73
|
+
throw new error_1.APIUserAbortError();
|
|
74
|
+
}
|
|
75
|
+
if (bodyTimedOut) {
|
|
76
|
+
throw new error_1.APIConnectionTimeoutError();
|
|
77
|
+
}
|
|
78
|
+
const expected = response.headers.get('x-content-sha256');
|
|
79
|
+
if (!expected) {
|
|
80
|
+
throw new AuditLogDownloadError('response missing X-Content-Sha256 header');
|
|
81
|
+
}
|
|
82
|
+
const actual = await sha256Hex(body);
|
|
83
|
+
if (options.signal?.aborted) {
|
|
84
|
+
throw new error_1.APIUserAbortError();
|
|
85
|
+
}
|
|
86
|
+
if (actual !== expected) {
|
|
87
|
+
throw new AuditLogDownloadError(`audit log chunk checksum mismatch (got ${actual}, want ${expected})`);
|
|
88
|
+
}
|
|
89
|
+
return { body, headers: response.headers };
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (options.signal?.aborted && !(error instanceof error_1.APIUserAbortError)) {
|
|
93
|
+
error = new error_1.APIUserAbortError();
|
|
94
|
+
}
|
|
95
|
+
else if (bodyTimedOut) {
|
|
96
|
+
error = new error_1.APIConnectionTimeoutError();
|
|
97
|
+
}
|
|
98
|
+
if (retries === maxTransferRetries || error instanceof error_1.APIUserAbortError) {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
await retryDelay(retries + 1, options.signal);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function parseChunkHeaders(headers, currentCursor) {
|
|
110
|
+
const hasMoreValue = headers.get('x-has-more');
|
|
111
|
+
if (hasMoreValue !== 'true' && hasMoreValue !== 'false') {
|
|
112
|
+
throw new AuditLogDownloadError('response missing or invalid X-Has-More header');
|
|
113
|
+
}
|
|
114
|
+
const hasMore = hasMoreValue === 'true';
|
|
115
|
+
const rowCount = headers.get('x-row-count');
|
|
116
|
+
if (rowCount === null || !/^[0-9]+$/.test(rowCount)) {
|
|
117
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
118
|
+
}
|
|
119
|
+
const rows = Number(rowCount);
|
|
120
|
+
if (!Number.isSafeInteger(rows) || rows > MAX_CHUNK_ROWS) {
|
|
121
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
122
|
+
}
|
|
123
|
+
const nextCursor = headers.get('x-next-cursor') || undefined;
|
|
124
|
+
if (hasMore && (!nextCursor || nextCursor === currentCursor)) {
|
|
125
|
+
throw new AuditLogDownloadError('response has invalid X-Next-Cursor header');
|
|
126
|
+
}
|
|
127
|
+
if (!hasMore && nextCursor) {
|
|
128
|
+
throw new AuditLogDownloadError('response returned a cursor after the final chunk');
|
|
129
|
+
}
|
|
130
|
+
return { rows, nextCursor, hasMore };
|
|
131
|
+
}
|
|
132
|
+
async function sha256Hex(body) {
|
|
133
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', body);
|
|
134
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
135
|
+
}
|
|
136
|
+
async function retryDelay(attempt, signal) {
|
|
137
|
+
const delay = Math.min(1000 * 2 ** (attempt - 1), MAX_RETRY_DELAY_MS);
|
|
138
|
+
await new Promise((resolve, reject) => {
|
|
139
|
+
if (signal?.aborted) {
|
|
140
|
+
reject(new error_1.APIUserAbortError());
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const onAbort = () => {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
reject(new error_1.APIUserAbortError());
|
|
146
|
+
};
|
|
147
|
+
const timer = setTimeout(() => {
|
|
148
|
+
signal?.removeEventListener('abort', onAbort);
|
|
149
|
+
resolve();
|
|
150
|
+
}, delay);
|
|
151
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async function writeChunk(destination, body) {
|
|
155
|
+
let offset = 0;
|
|
156
|
+
while (offset < body.byteLength) {
|
|
157
|
+
const result = await destination.write(offset === 0 ? body : body.subarray(offset));
|
|
158
|
+
if (typeof result === 'number') {
|
|
159
|
+
offset += validateWriteCount(result, body.byteLength - offset);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (result && typeof result === 'object' && 'bytesWritten' in result) {
|
|
163
|
+
const bytesWritten = result.bytesWritten;
|
|
164
|
+
offset += validateWriteCount(bytesWritten, body.byteLength - offset);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function validateWriteCount(value, remaining) {
|
|
171
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > remaining) {
|
|
172
|
+
throw new AuditLogDownloadError('audit log download destination performed a short write');
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=audit-log-download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-download.js","sourceRoot":"","sources":["../src/lib/audit-log-download.ts"],"names":[],"mappings":";;;AAuCA,8CAgDC;AAvFD,4CAA0F;AAI1F,MAAM,4BAA4B,GAAG,CAAC,CAAC;AACvC,MAAM,cAAc,GAAG,KAAM,CAAC;AAC9B,MAAM,kBAAkB,GAAG,IAAK,CAAC;AAEjC,MAAa,qBAAsB,SAAQ,mBAAW;CAAG;AAAzD,sDAAyD;AA+BlD,KAAK,UAAU,iBAAi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AAa,EAAE,SAAiB;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QACpE,MAAM,IAAI,qBAAqB,CAAC,wDAAwD,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { APIConnectionTimeoutError, APIUserAbortError, KernelError } from "../core/error.mjs";
|
|
2
|
+
const DEFAULT_MAX_TRANSFER_RETRIES = 6;
|
|
3
|
+
const MAX_CHUNK_ROWS = 50000;
|
|
4
|
+
const MAX_RETRY_DELAY_MS = 8000;
|
|
5
|
+
export class AuditLogDownloadError extends KernelError {
|
|
6
|
+
}
|
|
7
|
+
export async function downloadAuditLogs(fetchChunk, query, destination, defaultTimeout, options = {}) {
|
|
8
|
+
if (!destination || typeof destination.write !== 'function') {
|
|
9
|
+
throw new TypeError('audit log download destination must provide write()');
|
|
10
|
+
}
|
|
11
|
+
const { onProgress, maxTransferRetries = DEFAULT_MAX_TRANSFER_RETRIES, ...requestOptions } = options;
|
|
12
|
+
if (!Number.isInteger(maxTransferRetries) || maxTransferRetries < 0) {
|
|
13
|
+
throw new TypeError('maxTransferRetries must be a non-negative integer');
|
|
14
|
+
}
|
|
15
|
+
const timeout = requestOptions.timeout ?? defaultTimeout;
|
|
16
|
+
let cursor;
|
|
17
|
+
const result = { bytesWritten: 0, chunks: 0, rows: 0 };
|
|
18
|
+
const seenCursors = new Set();
|
|
19
|
+
while (true) {
|
|
20
|
+
const chunk = await fetchVerifiedChunk(fetchChunk, cursor ? { ...query, cursor } : query, requestOptions, maxTransferRetries, timeout);
|
|
21
|
+
const { nextCursor, hasMore, rows } = parseChunkHeaders(chunk.headers, cursor);
|
|
22
|
+
if (hasMore && nextCursor) {
|
|
23
|
+
if (seenCursors.has(nextCursor)) {
|
|
24
|
+
throw new AuditLogDownloadError('response repeated X-Next-Cursor header');
|
|
25
|
+
}
|
|
26
|
+
seenCursors.add(nextCursor);
|
|
27
|
+
}
|
|
28
|
+
await writeChunk(destination, chunk.body);
|
|
29
|
+
cursor = nextCursor;
|
|
30
|
+
result.bytesWritten += chunk.body.byteLength;
|
|
31
|
+
result.chunks += 1;
|
|
32
|
+
result.rows += rows;
|
|
33
|
+
if (onProgress) {
|
|
34
|
+
await onProgress({ ...result, chunkRows: rows });
|
|
35
|
+
}
|
|
36
|
+
if (!hasMore) {
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function fetchVerifiedChunk(fetchChunk, query, options, maxTransferRetries, timeout) {
|
|
42
|
+
for (let retries = 0;; retries += 1) {
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
const onAbort = () => controller.abort();
|
|
45
|
+
if (options.signal?.aborted) {
|
|
46
|
+
controller.abort();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
50
|
+
}
|
|
51
|
+
let response;
|
|
52
|
+
try {
|
|
53
|
+
response = await fetchChunk(query, { ...options, signal: controller.signal });
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
let bodyTimedOut = false;
|
|
60
|
+
const timer = setTimeout(() => {
|
|
61
|
+
bodyTimedOut = true;
|
|
62
|
+
controller.abort();
|
|
63
|
+
}, timeout);
|
|
64
|
+
try {
|
|
65
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
if (options.signal?.aborted) {
|
|
68
|
+
throw new APIUserAbortError();
|
|
69
|
+
}
|
|
70
|
+
if (bodyTimedOut) {
|
|
71
|
+
throw new APIConnectionTimeoutError();
|
|
72
|
+
}
|
|
73
|
+
const expected = response.headers.get('x-content-sha256');
|
|
74
|
+
if (!expected) {
|
|
75
|
+
throw new AuditLogDownloadError('response missing X-Content-Sha256 header');
|
|
76
|
+
}
|
|
77
|
+
const actual = await sha256Hex(body);
|
|
78
|
+
if (options.signal?.aborted) {
|
|
79
|
+
throw new APIUserAbortError();
|
|
80
|
+
}
|
|
81
|
+
if (actual !== expected) {
|
|
82
|
+
throw new AuditLogDownloadError(`audit log chunk checksum mismatch (got ${actual}, want ${expected})`);
|
|
83
|
+
}
|
|
84
|
+
return { body, headers: response.headers };
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (options.signal?.aborted && !(error instanceof APIUserAbortError)) {
|
|
88
|
+
error = new APIUserAbortError();
|
|
89
|
+
}
|
|
90
|
+
else if (bodyTimedOut) {
|
|
91
|
+
error = new APIConnectionTimeoutError();
|
|
92
|
+
}
|
|
93
|
+
if (retries === maxTransferRetries || error instanceof APIUserAbortError) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
await retryDelay(retries + 1, options.signal);
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function parseChunkHeaders(headers, currentCursor) {
|
|
105
|
+
const hasMoreValue = headers.get('x-has-more');
|
|
106
|
+
if (hasMoreValue !== 'true' && hasMoreValue !== 'false') {
|
|
107
|
+
throw new AuditLogDownloadError('response missing or invalid X-Has-More header');
|
|
108
|
+
}
|
|
109
|
+
const hasMore = hasMoreValue === 'true';
|
|
110
|
+
const rowCount = headers.get('x-row-count');
|
|
111
|
+
if (rowCount === null || !/^[0-9]+$/.test(rowCount)) {
|
|
112
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
113
|
+
}
|
|
114
|
+
const rows = Number(rowCount);
|
|
115
|
+
if (!Number.isSafeInteger(rows) || rows > MAX_CHUNK_ROWS) {
|
|
116
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
117
|
+
}
|
|
118
|
+
const nextCursor = headers.get('x-next-cursor') || undefined;
|
|
119
|
+
if (hasMore && (!nextCursor || nextCursor === currentCursor)) {
|
|
120
|
+
throw new AuditLogDownloadError('response has invalid X-Next-Cursor header');
|
|
121
|
+
}
|
|
122
|
+
if (!hasMore && nextCursor) {
|
|
123
|
+
throw new AuditLogDownloadError('response returned a cursor after the final chunk');
|
|
124
|
+
}
|
|
125
|
+
return { rows, nextCursor, hasMore };
|
|
126
|
+
}
|
|
127
|
+
async function sha256Hex(body) {
|
|
128
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', body);
|
|
129
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
130
|
+
}
|
|
131
|
+
async function retryDelay(attempt, signal) {
|
|
132
|
+
const delay = Math.min(1000 * 2 ** (attempt - 1), MAX_RETRY_DELAY_MS);
|
|
133
|
+
await new Promise((resolve, reject) => {
|
|
134
|
+
if (signal?.aborted) {
|
|
135
|
+
reject(new APIUserAbortError());
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const onAbort = () => {
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
reject(new APIUserAbortError());
|
|
141
|
+
};
|
|
142
|
+
const timer = setTimeout(() => {
|
|
143
|
+
signal?.removeEventListener('abort', onAbort);
|
|
144
|
+
resolve();
|
|
145
|
+
}, delay);
|
|
146
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async function writeChunk(destination, body) {
|
|
150
|
+
let offset = 0;
|
|
151
|
+
while (offset < body.byteLength) {
|
|
152
|
+
const result = await destination.write(offset === 0 ? body : body.subarray(offset));
|
|
153
|
+
if (typeof result === 'number') {
|
|
154
|
+
offset += validateWriteCount(result, body.byteLength - offset);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (result && typeof result === 'object' && 'bytesWritten' in result) {
|
|
158
|
+
const bytesWritten = result.bytesWritten;
|
|
159
|
+
offset += validateWriteCount(bytesWritten, body.byteLength - offset);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function validateWriteCount(value, remaining) {
|
|
166
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > remaining) {
|
|
167
|
+
throw new AuditLogDownloadError('audit log download destination performed a short write');
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=audit-log-download.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-download.mjs","sourceRoot":"","sources":["../src/lib/audit-log-download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,WAAW,EAAE,0BAAsB;AAI1F,MAAM,4BAA4B,GAAG,CAAC,CAAC;AACvC,MAAM,cAAc,GAAG,KAAM,CAAC;AAC9B,MAAM,kBAAkB,GAAG,IAAK,CAAC;AAEjC,MAAM,OAAO,qBAAsB,SAAQ,WAAW;CAAG;AA+BzD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAAsB,EACtB,KAA6B,EAC7B,WAAwC,EACxC,cAAsB,EACtB,UAAmC,EAAE;IAErC,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QAC5D,MAAM,IAAI,SAAS,CAAC,qDAAqD,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,4BAA4B,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAC;IACrG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,IAAI,kBAAkB,GAAG,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC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AAC;AACL,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,WAAwC,EAAE,IAAgB;IAClF,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QACpF,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;YAC/D,SAAS;QACX,CAAC;QACD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,cAAc,IAAI,MAAM,EAAE,CAAC;YACrE,MAAM,YAAY,GAAI,MAAmC,CAAC,YAAY,CAAC;YACvE,MAAM,IAAI,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC;YACrE,SAAS;QACX,CAAC;QACD,OAAO;IACT,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,SAAiB;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;QACpE,MAAM,IAAI,qBAAqB,CAAC,wDAAwD,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,6 +2,8 @@ import { APIResource } from "../core/resource.mjs";
|
|
|
2
2
|
import { APIPromise } from "../core/api-promise.mjs";
|
|
3
3
|
import { PagePromise, PageTokenPagination, type PageTokenPaginationParams } from "../core/pagination.mjs";
|
|
4
4
|
import { RequestOptions } from "../internal/request-options.mjs";
|
|
5
|
+
import { type AuditLogDownloadDestination, type AuditLogDownloadOptions, type AuditLogDownloadParams, type AuditLogDownloadProgress, type AuditLogDownloadResult } from "../lib/audit-log-download.mjs";
|
|
6
|
+
export type { AuditLogDownloadDestination, AuditLogDownloadOptions, AuditLogDownloadParams, AuditLogDownloadProgress, AuditLogDownloadResult, } from "../lib/audit-log-download.mjs";
|
|
5
7
|
/**
|
|
6
8
|
* Read audit log records for the authenticated organization.
|
|
7
9
|
*/
|
|
@@ -17,6 +19,14 @@ export declare class AuditLogs extends APIResource {
|
|
|
17
19
|
* /audit-logs.
|
|
18
20
|
*/
|
|
19
21
|
exportChunk(query: AuditLogExportChunkParams, options?: RequestOptions): APIPromise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* Download a complete gzip-compressed JSON Lines audit log export to a writable
|
|
24
|
+
* destination. The SDK verifies every chunk and retries transient transfer
|
|
25
|
+
* failures. It does not close the destination. If the download fails, the
|
|
26
|
+
* destination may contain a partial export; use a temporary file and atomic
|
|
27
|
+
* rename when the completed export must be published atomically.
|
|
28
|
+
*/
|
|
29
|
+
download(query: AuditLogDownloadParams, destination: AuditLogDownloadDestination, options?: AuditLogDownloadOptions): Promise<AuditLogDownloadResult>;
|
|
20
30
|
}
|
|
21
31
|
export type AuditLogEntriesPageTokenPagination = PageTokenPagination<AuditLogEntry>;
|
|
22
32
|
export interface AuditLogEntry {
|
|
@@ -150,6 +160,6 @@ export interface AuditLogExportChunkParams {
|
|
|
150
160
|
service?: string;
|
|
151
161
|
}
|
|
152
162
|
export declare namespace AuditLogs {
|
|
153
|
-
export { type AuditLogEntry as AuditLogEntry, type AuditLogEntriesPageTokenPagination as AuditLogEntriesPageTokenPagination, type AuditLogListParams as AuditLogListParams, type AuditLogExportChunkParams as AuditLogExportChunkParams, };
|
|
163
|
+
export { type AuditLogEntry as AuditLogEntry, type AuditLogEntriesPageTokenPagination as AuditLogEntriesPageTokenPagination, type AuditLogListParams as AuditLogListParams, type AuditLogExportChunkParams as AuditLogExportChunkParams, type AuditLogDownloadDestination as AuditLogDownloadDestination, type AuditLogDownloadOptions as AuditLogDownloadOptions, type AuditLogDownloadParams as AuditLogDownloadParams, type AuditLogDownloadProgress as AuditLogDownloadProgress, type AuditLogDownloadResult as AuditLogDownloadResult, };
|
|
154
164
|
}
|
|
155
165
|
//# sourceMappingURL=audit-logs.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-logs.d.mts","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAC/C,OAAO,EAAE,UAAU,EAAE,gCAA4B;AACjD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,KAAK,yBAAyB,EAAE,+BAA2B;AAEtG,OAAO,EAAE,cAAc,EAAE,wCAAoC;
|
|
1
|
+
{"version":3,"file":"audit-logs.d.mts","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAC/C,OAAO,EAAE,UAAU,EAAE,gCAA4B;AACjD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,KAAK,yBAAyB,EAAE,+BAA2B;AAEtG,OAAO,EAAE,cAAc,EAAE,wCAAoC;AAC7D,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC5B,sCAAkC;AAEnC,YAAY,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACvB,sCAAkC;AAEnC;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;IACxC;;;OAGG;IACH,IAAI,CACF,KAAK,EAAE,kBAAkB,EACzB,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,kCAAkC,EAAE,aAAa,CAAC;IAIjE;;;;OAIG;IACH,W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AAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,OAAO,EACL,KAAK,aAAa,IAAI,aAAa,EACnC,KAAK,kCAAkC,IAAI,kCAAkC,EAC7E,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,2BAA2B,IAAI,2BAA2B,EAC/D,KAAK,uBAAuB,IAAI,uBAAuB,EACvD,KAAK,sBAAsB,IAAI,sBAAsB,EACrD,KAAK,wBAAwB,IAAI,wBAAwB,EACzD,KAAK,sBAAsB,IAAI,sBAAsB,GACtD,CAAC;CACH"}
|
|
@@ -2,6 +2,8 @@ import { APIResource } from "../core/resource.js";
|
|
|
2
2
|
import { APIPromise } from "../core/api-promise.js";
|
|
3
3
|
import { PagePromise, PageTokenPagination, type PageTokenPaginationParams } from "../core/pagination.js";
|
|
4
4
|
import { RequestOptions } from "../internal/request-options.js";
|
|
5
|
+
import { type AuditLogDownloadDestination, type AuditLogDownloadOptions, type AuditLogDownloadParams, type AuditLogDownloadProgress, type AuditLogDownloadResult } from "../lib/audit-log-download.js";
|
|
6
|
+
export type { AuditLogDownloadDestination, AuditLogDownloadOptions, AuditLogDownloadParams, AuditLogDownloadProgress, AuditLogDownloadResult, } from "../lib/audit-log-download.js";
|
|
5
7
|
/**
|
|
6
8
|
* Read audit log records for the authenticated organization.
|
|
7
9
|
*/
|
|
@@ -17,6 +19,14 @@ export declare class AuditLogs extends APIResource {
|
|
|
17
19
|
* /audit-logs.
|
|
18
20
|
*/
|
|
19
21
|
exportChunk(query: AuditLogExportChunkParams, options?: RequestOptions): APIPromise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* Download a complete gzip-compressed JSON Lines audit log export to a writable
|
|
24
|
+
* destination. The SDK verifies every chunk and retries transient transfer
|
|
25
|
+
* failures. It does not close the destination. If the download fails, the
|
|
26
|
+
* destination may contain a partial export; use a temporary file and atomic
|
|
27
|
+
* rename when the completed export must be published atomically.
|
|
28
|
+
*/
|
|
29
|
+
download(query: AuditLogDownloadParams, destination: AuditLogDownloadDestination, options?: AuditLogDownloadOptions): Promise<AuditLogDownloadResult>;
|
|
20
30
|
}
|
|
21
31
|
export type AuditLogEntriesPageTokenPagination = PageTokenPagination<AuditLogEntry>;
|
|
22
32
|
export interface AuditLogEntry {
|
|
@@ -150,6 +160,6 @@ export interface AuditLogExportChunkParams {
|
|
|
150
160
|
service?: string;
|
|
151
161
|
}
|
|
152
162
|
export declare namespace AuditLogs {
|
|
153
|
-
export { type AuditLogEntry as AuditLogEntry, type AuditLogEntriesPageTokenPagination as AuditLogEntriesPageTokenPagination, type AuditLogListParams as AuditLogListParams, type AuditLogExportChunkParams as AuditLogExportChunkParams, };
|
|
163
|
+
export { type AuditLogEntry as AuditLogEntry, type AuditLogEntriesPageTokenPagination as AuditLogEntriesPageTokenPagination, type AuditLogListParams as AuditLogListParams, type AuditLogExportChunkParams as AuditLogExportChunkParams, type AuditLogDownloadDestination as AuditLogDownloadDestination, type AuditLogDownloadOptions as AuditLogDownloadOptions, type AuditLogDownloadParams as AuditLogDownloadParams, type AuditLogDownloadProgress as AuditLogDownloadProgress, type AuditLogDownloadResult as AuditLogDownloadResult, };
|
|
154
164
|
}
|
|
155
165
|
//# sourceMappingURL=audit-logs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-logs.d.ts","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,4BAAyB;AAC/C,OAAO,EAAE,UAAU,EAAE,+BAA4B;AACjD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,KAAK,yBAAyB,EAAE,8BAA2B;AAEtG,OAAO,EAAE,cAAc,EAAE,uCAAoC;
|
|
1
|
+
{"version":3,"file":"audit-logs.d.ts","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,4BAAyB;AAC/C,OAAO,EAAE,UAAU,EAAE,+BAA4B;AACjD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,KAAK,yBAAyB,EAAE,8BAA2B;AAEtG,OAAO,EAAE,cAAc,EAAE,uCAAoC;AAC7D,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC5B,qCAAkC;AAEnC,YAAY,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACvB,qCAAkC;AAEnC;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;IACxC;;;OAGG;IACH,IAAI,CACF,KAAK,EAAE,kBAAkB,EACzB,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,kCAAkC,EAAE,aAAa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OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC,OAAO,EACL,KAAK,aAAa,IAAI,aAAa,EACnC,KAAK,kCAAkC,IAAI,kCAAkC,EAC7E,KAAK,kBAAkB,IAAI,kBAAkB,EAC7C,KAAK,yBAAyB,IAAI,yBAAyB,EAC3D,KAAK,2BAA2B,IAAI,2BAA2B,EAC/D,KAAK,uBAAuB,IAAI,uBAAuB,EACvD,KAAK,sBAAsB,IAAI,sBAAsB,EACrD,KAAK,wBAAwB,IAAI,wBAAwB,EACzD,KAAK,sBAAsB,IAAI,sBAAsB,GACtD,CAAC;CACH"}
|
package/resources/audit-logs.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.AuditLogs = void 0;
|
|
|
5
5
|
const resource_1 = require("../core/resource.js");
|
|
6
6
|
const pagination_1 = require("../core/pagination.js");
|
|
7
7
|
const headers_1 = require("../internal/headers.js");
|
|
8
|
+
const audit_log_download_1 = require("../lib/audit-log-download.js");
|
|
8
9
|
/**
|
|
9
10
|
* Read audit log records for the authenticated organization.
|
|
10
11
|
*/
|
|
@@ -29,6 +30,16 @@ class AuditLogs extends resource_1.APIResource {
|
|
|
29
30
|
__binaryResponse: true,
|
|
30
31
|
});
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Download a complete gzip-compressed JSON Lines audit log export to a writable
|
|
35
|
+
* destination. The SDK verifies every chunk and retries transient transfer
|
|
36
|
+
* failures. It does not close the destination. If the download fails, the
|
|
37
|
+
* destination may contain a partial export; use a temporary file and atomic
|
|
38
|
+
* rename when the completed export must be published atomically.
|
|
39
|
+
*/
|
|
40
|
+
download(query, destination, options) {
|
|
41
|
+
return (0, audit_log_download_1.downloadAuditLogs)((chunkQuery, chunkOptions) => this.exportChunk(chunkQuery, chunkOptions), query, destination, this._client.timeout, options);
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
44
|
exports.AuditLogs = AuditLogs;
|
|
34
45
|
//# sourceMappingURL=audit-logs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-logs.js","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAE/C,sDAAsG;AACtG,oDAAmD;
|
|
1
|
+
{"version":3,"file":"audit-logs.js","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAE/C,sDAAsG;AACtG,oDAAmD;AAEnD,qEAOmC;AAUnC;;GAEG;AACH,MAAa,SAAU,SAAQ,sBAAW;IACxC;;;OAGG;IACH,IAAI,CACF,KAAyB,EACzB,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAA,gCAAkC,CAAA,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC3G,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,KAAgC,EAAE,OAAwB;QACpE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE;YAClD,KAAK;YACL,GAAG,OAAO;YACV,OAAO,EAAE,IAAA,sBAAY,EAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACjF,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CACN,KAA6B,EAC7B,WAAwC,EACxC,OAAiC;QAEjC,OAAO,IAAA,sCAAiB,EACtB,CAAC,UAAU,EAAE,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,YAAY,CAAC,EACxE,KAAK,EACL,WAAW,EACX,IAAI,CAAC,OAAO,CAAC,OAAO,EACpB,OAAO,CACR,CAAC;IACJ,CAAC;CACF;AA9CD,8BA8CC"}
|
package/resources/audit-logs.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { APIResource } from "../core/resource.mjs";
|
|
3
3
|
import { PageTokenPagination } from "../core/pagination.mjs";
|
|
4
4
|
import { buildHeaders } from "../internal/headers.mjs";
|
|
5
|
+
import { downloadAuditLogs, } from "../lib/audit-log-download.mjs";
|
|
5
6
|
/**
|
|
6
7
|
* Read audit log records for the authenticated organization.
|
|
7
8
|
*/
|
|
@@ -26,5 +27,15 @@ export class AuditLogs extends APIResource {
|
|
|
26
27
|
__binaryResponse: true,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Download a complete gzip-compressed JSON Lines audit log export to a writable
|
|
32
|
+
* destination. The SDK verifies every chunk and retries transient transfer
|
|
33
|
+
* failures. It does not close the destination. If the download fails, the
|
|
34
|
+
* destination may contain a partial export; use a temporary file and atomic
|
|
35
|
+
* rename when the completed export must be published atomically.
|
|
36
|
+
*/
|
|
37
|
+
download(query, destination, options) {
|
|
38
|
+
return downloadAuditLogs((chunkQuery, chunkOptions) => this.exportChunk(chunkQuery, chunkOptions), query, destination, this._client.timeout, options);
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
//# sourceMappingURL=audit-logs.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-logs.mjs","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAE/C,OAAO,EAAe,mBAAmB,EAAkC,+BAA2B;AACtG,OAAO,EAAE,YAAY,EAAE,gCAA4B;
|
|
1
|
+
{"version":3,"file":"audit-logs.mjs","sourceRoot":"","sources":["../src/resources/audit-logs.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAEtF,OAAO,EAAE,WAAW,EAAE,6BAAyB;AAE/C,OAAO,EAAe,mBAAmB,EAAkC,+BAA2B;AACtG,OAAO,EAAE,YAAY,EAAE,gCAA4B;AAEnD,OAAO,EACL,iBAAiB,GAMlB,sCAAkC;AAUnC;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IACxC;;;OAGG;IACH,IAAI,CACF,KAAyB,EACzB,OAAwB;QAExB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAA,mBAAkC,CAAA,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC3G,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,KAAgC,EAAE,OAAwB;QACpE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE;YAClD,KAAK;YACL,GAAG,OAAO;YACV,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACjF,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CACN,KAA6B,EAC7B,WAAwC,EACxC,OAAiC;QAEjC,OAAO,iBAAiB,CACtB,CAAC,UAAU,EAAE,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,YAAY,CAAC,EACxE,KAAK,EACL,WAAW,EACX,IAAI,CAAC,OAAO,CAAC,OAAO,EACpB,OAAO,CACR,CAAC;IACJ,CAAC;CACF"}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,15 @@ export { type Uploadable, toFile } from './core/uploads';
|
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
7
|
export { Kernel, type ClientOptions } from './client';
|
|
8
8
|
export { type BrowserFetchInit } from './lib/browser-fetch';
|
|
9
|
+
export {
|
|
10
|
+
AuditLogDownloadError,
|
|
11
|
+
type AuditLogDownloadDestination,
|
|
12
|
+
type AuditLogDownloadOptions,
|
|
13
|
+
type AuditLogDownloadParams,
|
|
14
|
+
type AuditLogDownloadProgress,
|
|
15
|
+
type AuditLogDownloadResult,
|
|
16
|
+
type AuditLogDownloadWriteResult,
|
|
17
|
+
} from './lib/audit-log-download';
|
|
9
18
|
export { BrowserRouteCache, type BrowserRoute } from './lib/browser-routing';
|
|
10
19
|
export { PagePromise } from './core/pagination';
|
|
11
20
|
export {
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { APIConnectionTimeoutError, APIUserAbortError, KernelError } from '../core/error';
|
|
2
|
+
import type { RequestOptions } from '../internal/request-options';
|
|
3
|
+
import type { AuditLogExportChunkParams } from '../resources/audit-logs';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_MAX_TRANSFER_RETRIES = 6;
|
|
6
|
+
const MAX_CHUNK_ROWS = 50_000;
|
|
7
|
+
const MAX_RETRY_DELAY_MS = 8_000;
|
|
8
|
+
|
|
9
|
+
export class AuditLogDownloadError extends KernelError {}
|
|
10
|
+
|
|
11
|
+
export type AuditLogDownloadParams = Omit<AuditLogExportChunkParams, 'cursor' | 'format'>;
|
|
12
|
+
|
|
13
|
+
export interface AuditLogDownloadResult {
|
|
14
|
+
bytesWritten: number;
|
|
15
|
+
chunks: number;
|
|
16
|
+
rows: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AuditLogDownloadProgress extends AuditLogDownloadResult {
|
|
20
|
+
chunkRows: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type AuditLogDownloadWriteResult = void | number | { bytesWritten: number };
|
|
24
|
+
|
|
25
|
+
export interface AuditLogDownloadDestination {
|
|
26
|
+
write(chunk: Uint8Array): AuditLogDownloadWriteResult | Promise<AuditLogDownloadWriteResult>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AuditLogDownloadOptions
|
|
30
|
+
extends Omit<
|
|
31
|
+
RequestOptions,
|
|
32
|
+
'method' | 'path' | 'query' | 'body' | 'stream' | '__binaryResponse' | '__streamClass'
|
|
33
|
+
> {
|
|
34
|
+
onProgress?(progress: AuditLogDownloadProgress): void | Promise<void>;
|
|
35
|
+
maxTransferRetries?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type FetchChunk = (query: AuditLogExportChunkParams, options?: RequestOptions) => Promise<Response>;
|
|
39
|
+
|
|
40
|
+
export async function downloadAuditLogs(
|
|
41
|
+
fetchChunk: FetchChunk,
|
|
42
|
+
query: AuditLogDownloadParams,
|
|
43
|
+
destination: AuditLogDownloadDestination,
|
|
44
|
+
defaultTimeout: number,
|
|
45
|
+
options: AuditLogDownloadOptions = {},
|
|
46
|
+
): Promise<AuditLogDownloadResult> {
|
|
47
|
+
if (!destination || typeof destination.write !== 'function') {
|
|
48
|
+
throw new TypeError('audit log download destination must provide write()');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { onProgress, maxTransferRetries = DEFAULT_MAX_TRANSFER_RETRIES, ...requestOptions } = options;
|
|
52
|
+
if (!Number.isInteger(maxTransferRetries) || maxTransferRetries < 0) {
|
|
53
|
+
throw new TypeError('maxTransferRetries must be a non-negative integer');
|
|
54
|
+
}
|
|
55
|
+
const timeout = requestOptions.timeout ?? defaultTimeout;
|
|
56
|
+
let cursor: string | undefined;
|
|
57
|
+
const result: AuditLogDownloadResult = { bytesWritten: 0, chunks: 0, rows: 0 };
|
|
58
|
+
const seenCursors = new Set<string>();
|
|
59
|
+
|
|
60
|
+
while (true) {
|
|
61
|
+
const chunk = await fetchVerifiedChunk(
|
|
62
|
+
fetchChunk,
|
|
63
|
+
cursor ? { ...query, cursor } : query,
|
|
64
|
+
requestOptions,
|
|
65
|
+
maxTransferRetries,
|
|
66
|
+
timeout,
|
|
67
|
+
);
|
|
68
|
+
const { nextCursor, hasMore, rows } = parseChunkHeaders(chunk.headers, cursor);
|
|
69
|
+
if (hasMore && nextCursor) {
|
|
70
|
+
if (seenCursors.has(nextCursor)) {
|
|
71
|
+
throw new AuditLogDownloadError('response repeated X-Next-Cursor header');
|
|
72
|
+
}
|
|
73
|
+
seenCursors.add(nextCursor);
|
|
74
|
+
}
|
|
75
|
+
await writeChunk(destination, chunk.body);
|
|
76
|
+
|
|
77
|
+
cursor = nextCursor;
|
|
78
|
+
result.bytesWritten += chunk.body.byteLength;
|
|
79
|
+
result.chunks += 1;
|
|
80
|
+
result.rows += rows;
|
|
81
|
+
if (onProgress) {
|
|
82
|
+
await onProgress({ ...result, chunkRows: rows });
|
|
83
|
+
}
|
|
84
|
+
if (!hasMore) {
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function fetchVerifiedChunk(
|
|
91
|
+
fetchChunk: FetchChunk,
|
|
92
|
+
query: AuditLogExportChunkParams,
|
|
93
|
+
options: RequestOptions,
|
|
94
|
+
maxTransferRetries: number,
|
|
95
|
+
timeout: number,
|
|
96
|
+
): Promise<{ body: Uint8Array; headers: Headers }> {
|
|
97
|
+
for (let retries = 0; ; retries += 1) {
|
|
98
|
+
const controller = new AbortController();
|
|
99
|
+
const onAbort = () => controller.abort();
|
|
100
|
+
if (options.signal?.aborted) {
|
|
101
|
+
controller.abort();
|
|
102
|
+
} else {
|
|
103
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let response: Response;
|
|
107
|
+
try {
|
|
108
|
+
response = await fetchChunk(query, { ...options, signal: controller.signal });
|
|
109
|
+
} catch (error) {
|
|
110
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let bodyTimedOut = false;
|
|
115
|
+
const timer = setTimeout(() => {
|
|
116
|
+
bodyTimedOut = true;
|
|
117
|
+
controller.abort();
|
|
118
|
+
}, timeout);
|
|
119
|
+
try {
|
|
120
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
if (options.signal?.aborted) {
|
|
123
|
+
throw new APIUserAbortError();
|
|
124
|
+
}
|
|
125
|
+
if (bodyTimedOut) {
|
|
126
|
+
throw new APIConnectionTimeoutError();
|
|
127
|
+
}
|
|
128
|
+
const expected = response.headers.get('x-content-sha256');
|
|
129
|
+
if (!expected) {
|
|
130
|
+
throw new AuditLogDownloadError('response missing X-Content-Sha256 header');
|
|
131
|
+
}
|
|
132
|
+
const actual = await sha256Hex(body);
|
|
133
|
+
if (options.signal?.aborted) {
|
|
134
|
+
throw new APIUserAbortError();
|
|
135
|
+
}
|
|
136
|
+
if (actual !== expected) {
|
|
137
|
+
throw new AuditLogDownloadError(
|
|
138
|
+
`audit log chunk checksum mismatch (got ${actual}, want ${expected})`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return { body, headers: response.headers };
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (options.signal?.aborted && !(error instanceof APIUserAbortError)) {
|
|
144
|
+
error = new APIUserAbortError();
|
|
145
|
+
} else if (bodyTimedOut) {
|
|
146
|
+
error = new APIConnectionTimeoutError();
|
|
147
|
+
}
|
|
148
|
+
if (retries === maxTransferRetries || error instanceof APIUserAbortError) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
await retryDelay(retries + 1, options.signal);
|
|
152
|
+
} finally {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseChunkHeaders(
|
|
160
|
+
headers: Headers,
|
|
161
|
+
currentCursor: string | undefined,
|
|
162
|
+
): { rows: number; nextCursor: string | undefined; hasMore: boolean } {
|
|
163
|
+
const hasMoreValue = headers.get('x-has-more');
|
|
164
|
+
if (hasMoreValue !== 'true' && hasMoreValue !== 'false') {
|
|
165
|
+
throw new AuditLogDownloadError('response missing or invalid X-Has-More header');
|
|
166
|
+
}
|
|
167
|
+
const hasMore = hasMoreValue === 'true';
|
|
168
|
+
|
|
169
|
+
const rowCount = headers.get('x-row-count');
|
|
170
|
+
if (rowCount === null || !/^[0-9]+$/.test(rowCount)) {
|
|
171
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
172
|
+
}
|
|
173
|
+
const rows = Number(rowCount);
|
|
174
|
+
if (!Number.isSafeInteger(rows) || rows > MAX_CHUNK_ROWS) {
|
|
175
|
+
throw new AuditLogDownloadError('response missing or invalid X-Row-Count header');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const nextCursor = headers.get('x-next-cursor') || undefined;
|
|
179
|
+
if (hasMore && (!nextCursor || nextCursor === currentCursor)) {
|
|
180
|
+
throw new AuditLogDownloadError('response has invalid X-Next-Cursor header');
|
|
181
|
+
}
|
|
182
|
+
if (!hasMore && nextCursor) {
|
|
183
|
+
throw new AuditLogDownloadError('response returned a cursor after the final chunk');
|
|
184
|
+
}
|
|
185
|
+
return { rows, nextCursor, hasMore };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function sha256Hex(body: Uint8Array): Promise<string> {
|
|
189
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', body);
|
|
190
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function retryDelay(attempt: number, signal: AbortSignal | null | undefined): Promise<void> {
|
|
194
|
+
const delay = Math.min(1_000 * 2 ** (attempt - 1), MAX_RETRY_DELAY_MS);
|
|
195
|
+
await new Promise<void>((resolve, reject) => {
|
|
196
|
+
if (signal?.aborted) {
|
|
197
|
+
reject(new APIUserAbortError());
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const onAbort = () => {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
reject(new APIUserAbortError());
|
|
203
|
+
};
|
|
204
|
+
const timer = setTimeout(() => {
|
|
205
|
+
signal?.removeEventListener('abort', onAbort);
|
|
206
|
+
resolve();
|
|
207
|
+
}, delay);
|
|
208
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function writeChunk(destination: AuditLogDownloadDestination, body: Uint8Array): Promise<void> {
|
|
213
|
+
let offset = 0;
|
|
214
|
+
while (offset < body.byteLength) {
|
|
215
|
+
const result = await destination.write(offset === 0 ? body : body.subarray(offset));
|
|
216
|
+
if (typeof result === 'number') {
|
|
217
|
+
offset += validateWriteCount(result, body.byteLength - offset);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (result && typeof result === 'object' && 'bytesWritten' in result) {
|
|
221
|
+
const bytesWritten = (result as { bytesWritten: number }).bytesWritten;
|
|
222
|
+
offset += validateWriteCount(bytesWritten, body.byteLength - offset);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function validateWriteCount(value: number, remaining: number): number {
|
|
230
|
+
if (!Number.isSafeInteger(value) || value <= 0 || value > remaining) {
|
|
231
|
+
throw new AuditLogDownloadError('audit log download destination performed a short write');
|
|
232
|
+
}
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
@@ -5,6 +5,22 @@ import { APIPromise } from '../core/api-promise';
|
|
|
5
5
|
import { PagePromise, PageTokenPagination, type PageTokenPaginationParams } from '../core/pagination';
|
|
6
6
|
import { buildHeaders } from '../internal/headers';
|
|
7
7
|
import { RequestOptions } from '../internal/request-options';
|
|
8
|
+
import {
|
|
9
|
+
downloadAuditLogs,
|
|
10
|
+
type AuditLogDownloadDestination,
|
|
11
|
+
type AuditLogDownloadOptions,
|
|
12
|
+
type AuditLogDownloadParams,
|
|
13
|
+
type AuditLogDownloadProgress,
|
|
14
|
+
type AuditLogDownloadResult,
|
|
15
|
+
} from '../lib/audit-log-download';
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
AuditLogDownloadDestination,
|
|
19
|
+
AuditLogDownloadOptions,
|
|
20
|
+
AuditLogDownloadParams,
|
|
21
|
+
AuditLogDownloadProgress,
|
|
22
|
+
AuditLogDownloadResult,
|
|
23
|
+
} from '../lib/audit-log-download';
|
|
8
24
|
|
|
9
25
|
/**
|
|
10
26
|
* Read audit log records for the authenticated organization.
|
|
@@ -34,6 +50,27 @@ export class AuditLogs extends APIResource {
|
|
|
34
50
|
__binaryResponse: true,
|
|
35
51
|
});
|
|
36
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Download a complete gzip-compressed JSON Lines audit log export to a writable
|
|
56
|
+
* destination. The SDK verifies every chunk and retries transient transfer
|
|
57
|
+
* failures. It does not close the destination. If the download fails, the
|
|
58
|
+
* destination may contain a partial export; use a temporary file and atomic
|
|
59
|
+
* rename when the completed export must be published atomically.
|
|
60
|
+
*/
|
|
61
|
+
download(
|
|
62
|
+
query: AuditLogDownloadParams,
|
|
63
|
+
destination: AuditLogDownloadDestination,
|
|
64
|
+
options?: AuditLogDownloadOptions,
|
|
65
|
+
): Promise<AuditLogDownloadResult> {
|
|
66
|
+
return downloadAuditLogs(
|
|
67
|
+
(chunkQuery, chunkOptions) => this.exportChunk(chunkQuery, chunkOptions),
|
|
68
|
+
query,
|
|
69
|
+
destination,
|
|
70
|
+
this._client.timeout,
|
|
71
|
+
options,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
37
74
|
}
|
|
38
75
|
|
|
39
76
|
export type AuditLogEntriesPageTokenPagination = PageTokenPagination<AuditLogEntry>;
|
|
@@ -205,5 +242,10 @@ export declare namespace AuditLogs {
|
|
|
205
242
|
type AuditLogEntriesPageTokenPagination as AuditLogEntriesPageTokenPagination,
|
|
206
243
|
type AuditLogListParams as AuditLogListParams,
|
|
207
244
|
type AuditLogExportChunkParams as AuditLogExportChunkParams,
|
|
245
|
+
type AuditLogDownloadDestination as AuditLogDownloadDestination,
|
|
246
|
+
type AuditLogDownloadOptions as AuditLogDownloadOptions,
|
|
247
|
+
type AuditLogDownloadParams as AuditLogDownloadParams,
|
|
248
|
+
type AuditLogDownloadProgress as AuditLogDownloadProgress,
|
|
249
|
+
type AuditLogDownloadResult as AuditLogDownloadResult,
|
|
208
250
|
};
|
|
209
251
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.81.0'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.81.0";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.81.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.81.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|