@elizaos/plugin-twitter 0.1.9 → 0.25.6-alpha.1

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
@@ -189,6 +189,9 @@ var quotelessJson = (obj) => {
189
189
  return json.replace(/"([^"]+)":/g, "$1:");
190
190
  };
191
191
  var ZodError = class _ZodError extends Error {
192
+ get errors() {
193
+ return this.issues;
194
+ }
192
195
  constructor(issues) {
193
196
  super();
194
197
  this.issues = [];
@@ -207,9 +210,6 @@ var ZodError = class _ZodError extends Error {
207
210
  this.name = "ZodError";
208
211
  this.issues = issues;
209
212
  }
210
- get errors() {
211
- return this.issues;
212
- }
213
213
  format(_mapper) {
214
214
  const mapper = _mapper || function(issue) {
215
215
  return issue.message;
@@ -420,8 +420,11 @@ function addIssueToContext(ctx, issueData) {
420
420
  path: ctx.path,
421
421
  errorMaps: [
422
422
  ctx.common.contextualErrorMap,
423
+ // contextual error map is first priority
423
424
  ctx.schemaErrorMap,
425
+ // then schema-bound map if available
424
426
  overrideMap,
427
+ // then global override map
425
428
  overrideMap === errorMap ? void 0 : errorMap
426
429
  // then global default map
427
430
  ].filter((x) => !!x)
@@ -572,34 +575,6 @@ function processCreateParams(params) {
572
575
  return { errorMap: customMap, description };
573
576
  }
574
577
  var ZodType = class {
575
- constructor(def) {
576
- this.spa = this.safeParseAsync;
577
- this._def = def;
578
- this.parse = this.parse.bind(this);
579
- this.safeParse = this.safeParse.bind(this);
580
- this.parseAsync = this.parseAsync.bind(this);
581
- this.safeParseAsync = this.safeParseAsync.bind(this);
582
- this.spa = this.spa.bind(this);
583
- this.refine = this.refine.bind(this);
584
- this.refinement = this.refinement.bind(this);
585
- this.superRefine = this.superRefine.bind(this);
586
- this.optional = this.optional.bind(this);
587
- this.nullable = this.nullable.bind(this);
588
- this.nullish = this.nullish.bind(this);
589
- this.array = this.array.bind(this);
590
- this.promise = this.promise.bind(this);
591
- this.or = this.or.bind(this);
592
- this.and = this.and.bind(this);
593
- this.transform = this.transform.bind(this);
594
- this.brand = this.brand.bind(this);
595
- this.default = this.default.bind(this);
596
- this.catch = this.catch.bind(this);
597
- this.describe = this.describe.bind(this);
598
- this.pipe = this.pipe.bind(this);
599
- this.readonly = this.readonly.bind(this);
600
- this.isNullable = this.isNullable.bind(this);
601
- this.isOptional = this.isOptional.bind(this);
602
- }
603
578
  get description() {
604
579
  return this._def.description;
605
580
  }
@@ -663,6 +638,43 @@ var ZodType = class {
663
638
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
664
639
  return handleResult(ctx, result);
665
640
  }
641
+ "~validate"(data) {
642
+ var _a, _b;
643
+ const ctx = {
644
+ common: {
645
+ issues: [],
646
+ async: !!this["~standard"].async
647
+ },
648
+ path: [],
649
+ schemaErrorMap: this._def.errorMap,
650
+ parent: null,
651
+ data,
652
+ parsedType: getParsedType(data)
653
+ };
654
+ if (!this["~standard"].async) {
655
+ try {
656
+ const result = this._parseSync({ data, path: [], parent: ctx });
657
+ return isValid(result) ? {
658
+ value: result.value
659
+ } : {
660
+ issues: ctx.common.issues
661
+ };
662
+ } catch (err) {
663
+ if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
664
+ this["~standard"].async = true;
665
+ }
666
+ ctx.common = {
667
+ issues: [],
668
+ async: true
669
+ };
670
+ }
671
+ }
672
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
673
+ value: result.value
674
+ } : {
675
+ issues: ctx.common.issues
676
+ });
677
+ }
666
678
  async parseAsync(data, params) {
667
679
  const result = await this.safeParseAsync(data, params);
668
680
  if (result.success)
@@ -740,6 +752,39 @@ var ZodType = class {
740
752
  superRefine(refinement) {
741
753
  return this._refinement(refinement);
742
754
  }
755
+ constructor(def) {
756
+ this.spa = this.safeParseAsync;
757
+ this._def = def;
758
+ this.parse = this.parse.bind(this);
759
+ this.safeParse = this.safeParse.bind(this);
760
+ this.parseAsync = this.parseAsync.bind(this);
761
+ this.safeParseAsync = this.safeParseAsync.bind(this);
762
+ this.spa = this.spa.bind(this);
763
+ this.refine = this.refine.bind(this);
764
+ this.refinement = this.refinement.bind(this);
765
+ this.superRefine = this.superRefine.bind(this);
766
+ this.optional = this.optional.bind(this);
767
+ this.nullable = this.nullable.bind(this);
768
+ this.nullish = this.nullish.bind(this);
769
+ this.array = this.array.bind(this);
770
+ this.promise = this.promise.bind(this);
771
+ this.or = this.or.bind(this);
772
+ this.and = this.and.bind(this);
773
+ this.transform = this.transform.bind(this);
774
+ this.brand = this.brand.bind(this);
775
+ this.default = this.default.bind(this);
776
+ this.catch = this.catch.bind(this);
777
+ this.describe = this.describe.bind(this);
778
+ this.pipe = this.pipe.bind(this);
779
+ this.readonly = this.readonly.bind(this);
780
+ this.isNullable = this.isNullable.bind(this);
781
+ this.isOptional = this.isOptional.bind(this);
782
+ this["~standard"] = {
783
+ version: 1,
784
+ vendor: "zod",
785
+ validate: (data) => this["~validate"](data)
786
+ };
787
+ }
743
788
  optional() {
744
789
  return ZodOptional.create(this, this._def);
745
790
  }
@@ -750,7 +795,7 @@ var ZodType = class {
750
795
  return this.nullable().optional();
751
796
  }
752
797
  array() {
753
- return ZodArray.create(this, this._def);
798
+ return ZodArray.create(this);
754
799
  }
755
800
  promise() {
756
801
  return ZodPromise.create(this, this._def);
@@ -816,16 +861,20 @@ var ZodType = class {
816
861
  };
817
862
  var cuidRegex = /^c[^\s-]{8,}$/i;
818
863
  var cuid2Regex = /^[0-9a-z]+$/;
819
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
864
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
820
865
  var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
821
866
  var nanoidRegex = /^[a-z0-9_-]{21}$/i;
867
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
822
868
  var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
823
869
  var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
824
870
  var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
825
871
  var emojiRegex;
826
872
  var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
827
- var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
873
+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4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
828
876
  var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
877
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
829
878
  var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
830
879
  var dateRegex = new RegExp(`^${dateRegexSource}$`);
831
880
  function timeRegexSource(args) {
@@ -858,6 +907,33 @@ function isValidIP(ip, version) {
858
907
  }
859
908
  return false;
860
909
  }
910
+ function isValidJWT(jwt, alg) {
911
+ if (!jwtRegex.test(jwt))
912
+ return false;
913
+ try {
914
+ const [header] = jwt.split(".");
915
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
916
+ const decoded = JSON.parse(atob(base64));
917
+ if (typeof decoded !== "object" || decoded === null)
918
+ return false;
919
+ if (!decoded.typ || !decoded.alg)
920
+ return false;
921
+ if (alg && decoded.alg !== alg)
922
+ return false;
923
+ return true;
924
+ } catch (_a) {
925
+ return false;
926
+ }
927
+ }
928
+ function isValidCidr(ip, version) {
929
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
930
+ return true;
931
+ }
932
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
933
+ return true;
934
+ }
935
+ return false;
936
+ }
861
937
  var ZodString = class _ZodString extends ZodType {
862
938
  _parse(input) {
863
939
  if (this._def.coerce) {
@@ -1114,6 +1190,26 @@ var ZodString = class _ZodString extends ZodType {
1114
1190
  });
1115
1191
  status.dirty();
1116
1192
  }
1193
+ } else if (check.kind === "jwt") {
1194
+ if (!isValidJWT(input.data, check.alg)) {
1195
+ ctx = this._getOrReturnCtx(input, ctx);
1196
+ addIssueToContext(ctx, {
1197
+ validation: "jwt",
1198
+ code: ZodIssueCode.invalid_string,
1199
+ message: check.message
1200
+ });
1201
+ status.dirty();
1202
+ }
1203
+ } else if (check.kind === "cidr") {
1204
+ if (!isValidCidr(input.data, check.version)) {
1205
+ ctx = this._getOrReturnCtx(input, ctx);
1206
+ addIssueToContext(ctx, {
1207
+ validation: "cidr",
1208
+ code: ZodIssueCode.invalid_string,
1209
+ message: check.message
1210
+ });
1211
+ status.dirty();
1212
+ }
1117
1213
  } else if (check.kind === "base64") {
1118
1214
  if (!base64Regex.test(input.data)) {
1119
1215
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1124,6 +1220,16 @@ var ZodString = class _ZodString extends ZodType {
1124
1220
  });
1125
1221
  status.dirty();
1126
1222
  }
1223
+ } else if (check.kind === "base64url") {
1224
+ if (!base64urlRegex.test(input.data)) {
1225
+ ctx = this._getOrReturnCtx(input, ctx);
1226
+ addIssueToContext(ctx, {
1227
+ validation: "base64url",
1228
+ code: ZodIssueCode.invalid_string,
1229
+ message: check.message
1230
+ });
1231
+ status.dirty();
1232
+ }
1127
1233
  } else {
1128
1234
  util.assertNever(check);
1129
1235
  }
@@ -1170,9 +1276,21 @@ var ZodString = class _ZodString extends ZodType {
1170
1276
  base64(message) {
1171
1277
  return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1172
1278
  }
1279
+ base64url(message) {
1280
+ return this._addCheck({
1281
+ kind: "base64url",
1282
+ ...errorUtil.errToObj(message)
1283
+ });
1284
+ }
1285
+ jwt(options) {
1286
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1287
+ }
1173
1288
  ip(options) {
1174
1289
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1175
1290
  }
1291
+ cidr(options) {
1292
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1293
+ }
1176
1294
  datetime(options) {
1177
1295
  var _a, _b;
1178
1296
  if (typeof options === "string") {
@@ -1263,8 +1381,7 @@ var ZodString = class _ZodString extends ZodType {
1263
1381
  });
1264
1382
  }
1265
1383
  /**
1266
- * @deprecated Use z.string().min(1) instead.
1267
- * @see {@link ZodString.min}
1384
+ * Equivalent to `.min(1)`
1268
1385
  */
1269
1386
  nonempty(message) {
1270
1387
  return this.min(1, errorUtil.errToObj(message));
@@ -1326,9 +1443,15 @@ var ZodString = class _ZodString extends ZodType {
1326
1443
  get isIP() {
1327
1444
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1328
1445
  }
1446
+ get isCIDR() {
1447
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1448
+ }
1329
1449
  get isBase64() {
1330
1450
  return !!this._def.checks.find((ch) => ch.kind === "base64");
1331
1451
  }
1452
+ get isBase64url() {
1453
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1454
+ }
1332
1455
  get minLength() {
1333
1456
  let min = null;
1334
1457
  for (const ch of this._def.checks) {
@@ -1606,17 +1729,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1606
1729
  }
1607
1730
  _parse(input) {
1608
1731
  if (this._def.coerce) {
1609
- input.data = BigInt(input.data);
1732
+ try {
1733
+ input.data = BigInt(input.data);
1734
+ } catch (_a) {
1735
+ return this._getInvalidInput(input);
1736
+ }
1610
1737
  }
1611
1738
  const parsedType = this._getType(input);
1612
1739
  if (parsedType !== ZodParsedType.bigint) {
1613
- const ctx2 = this._getOrReturnCtx(input);
1614
- addIssueToContext(ctx2, {
1615
- code: ZodIssueCode.invalid_type,
1616
- expected: ZodParsedType.bigint,
1617
- received: ctx2.parsedType
1618
- });
1619
- return INVALID;
1740
+ return this._getInvalidInput(input);
1620
1741
  }
1621
1742
  let ctx = void 0;
1622
1743
  const status = new ParseStatus();
@@ -1663,6 +1784,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1663
1784
  }
1664
1785
  return { status: status.value, value: input.data };
1665
1786
  }
1787
+ _getInvalidInput(input) {
1788
+ const ctx = this._getOrReturnCtx(input);
1789
+ addIssueToContext(ctx, {
1790
+ code: ZodIssueCode.invalid_type,
1791
+ expected: ZodParsedType.bigint,
1792
+ received: ctx.parsedType
1793
+ });
1794
+ return INVALID;
1795
+ }
1666
1796
  gte(value, message) {
1667
1797
  return this.setLimit("min", value, true, errorUtil.toString(message));
1668
1798
  }