@lark-sh/client 0.1.17 → 0.1.19

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.
@@ -2828,6 +2828,9 @@ function generatePushId() {
2828
2828
 
2829
2829
  // src/utils/validation.ts
2830
2830
  var MAX_KEY_BYTES = 768;
2831
+ var MAX_STRING_VALUE_BYTES = 10 * 1024 * 1024;
2832
+ var MAX_WRITE_BYTES = 16 * 1024 * 1024;
2833
+ var MAX_VOLATILE_WRITE_BYTES = 2 * 1024;
2831
2834
  var INVALID_KEY_CHARS = /[.#$\[\]\/]/;
2832
2835
  var CONTROL_CHARS = /[\x00-\x1f\x7f]/;
2833
2836
  function hasControlChars(str) {
@@ -2898,10 +2901,11 @@ function validateValue(value, context, path = "") {
2898
2901
  return;
2899
2902
  }
2900
2903
  if (typeof value === "string") {
2901
- if (hasControlChars(value)) {
2904
+ const byteLength = getByteLength(value);
2905
+ if (byteLength > MAX_STRING_VALUE_BYTES) {
2902
2906
  throw new LarkError(
2903
2907
  ErrorCode.INVALID_DATA,
2904
- `${prefix}string value${location} contains control characters (ASCII 0-31, 127 are not allowed)`
2908
+ `${prefix}string value${location} exceeds maximum size of 10 MB (got ${Math.round(byteLength / 1024 / 1024 * 100) / 100} MB)`
2905
2909
  );
2906
2910
  }
2907
2911
  return;
@@ -2944,6 +2948,30 @@ function validateValue(value, context, path = "") {
2944
2948
  function validateWriteData(value, context) {
2945
2949
  validateValue(value, context);
2946
2950
  }
2951
+ function getJsonByteSize(value) {
2952
+ const json = JSON.stringify(value);
2953
+ return getByteLength(json);
2954
+ }
2955
+ function validateWriteSize(value, context) {
2956
+ const byteSize = getJsonByteSize(value);
2957
+ if (byteSize > MAX_WRITE_BYTES) {
2958
+ const sizeMB = Math.round(byteSize / 1024 / 1024 * 100) / 100;
2959
+ throw new LarkError(
2960
+ ErrorCode.INVALID_DATA,
2961
+ `${context ? `${context}: ` : ""}write exceeds 16 MB limit (got ${sizeMB} MB)`
2962
+ );
2963
+ }
2964
+ }
2965
+ function validateVolatileWriteSize(value, context) {
2966
+ const byteSize = getJsonByteSize(value);
2967
+ if (byteSize > MAX_VOLATILE_WRITE_BYTES) {
2968
+ const sizeKB = Math.round(byteSize / 1024 * 100) / 100;
2969
+ throw new LarkError(
2970
+ ErrorCode.INVALID_DATA,
2971
+ `${context ? `${context}: ` : ""}volatile write exceeds 2 KB limit (got ${sizeKB} KB)`
2972
+ );
2973
+ }
2974
+ }
2947
2975
 
2948
2976
  // src/DatabaseReference.ts
2949
2977
  function isInfoPath(path) {
@@ -5060,6 +5088,7 @@ var LarkDatabase = class {
5060
5088
  if (!this.isAuthenticatedOrThrow()) await this.waitForAuthenticated();
5061
5089
  const normalizedPath = normalizePath(path) || "/";
5062
5090
  validateWriteData(value, normalizedPath);
5091
+ validateWriteSize(value, normalizedPath);
5063
5092
  const requestId = this.messageQueue.nextRequestId();
5064
5093
  const pendingWriteIds = this.subscriptionManager.getPendingWriteIdsForPath(normalizedPath);
5065
5094
  this.pendingWrites.trackWrite(requestId, "set", normalizedPath, value);
@@ -5088,6 +5117,7 @@ var LarkDatabase = class {
5088
5117
  const fullPath = key.startsWith("/") ? key : `${normalizedPath}/${key}`;
5089
5118
  validateWriteData(value, fullPath);
5090
5119
  }
5120
+ validateWriteSize(values, normalizedPath);
5091
5121
  const requestId = this.messageQueue.nextRequestId();
5092
5122
  const pendingWriteIds = this.subscriptionManager.getPendingWriteIdsForPath(normalizedPath);
5093
5123
  this.pendingWrites.trackWrite(requestId, "update", normalizedPath, values);
@@ -5149,6 +5179,7 @@ var LarkDatabase = class {
5149
5179
  */
5150
5180
  _sendVolatileSet(path, value) {
5151
5181
  const normalizedPath = normalizePath(path) || "/";
5182
+ validateVolatileWriteSize(value, normalizedPath);
5152
5183
  this.subscriptionManager.applyOptimisticWrite(normalizedPath, value, "", "set");
5153
5184
  if (this._state !== "authenticated" || !this.transport || !this.transport.connected) {
5154
5185
  return;
@@ -5165,6 +5196,7 @@ var LarkDatabase = class {
5165
5196
  */
5166
5197
  _sendVolatileUpdate(path, values) {
5167
5198
  const normalizedPath = normalizePath(path) || "/";
5199
+ validateVolatileWriteSize(values, normalizedPath);
5168
5200
  this.subscriptionManager.applyOptimisticWrite(normalizedPath, values, "", "update");
5169
5201
  if (this._state !== "authenticated" || !this.transport || !this.transport.connected) {
5170
5202
  return;
@@ -5348,4 +5380,4 @@ export {
5348
5380
  ServerValue,
5349
5381
  LarkDatabase
5350
5382
  };
5351
- //# sourceMappingURL=chunk-VLAAYUVX.mjs.map
5383
+ //# sourceMappingURL=chunk-UF3SZ62Y.mjs.map