agentmail 0.2.19 → 0.2.21

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.
@@ -9,113 +9,63 @@ import { partition } from "../../utils/partition.mjs";
9
9
  import { getObjectLikeUtils } from "../object-like/index.mjs";
10
10
  import { getSchemaUtils } from "../schema-utils/index.mjs";
11
11
  import { isProperty } from "./property.mjs";
12
- // eslint-disable-next-line @typescript-eslint/unbound-method
13
- const _hasOwn = Object.prototype.hasOwnProperty;
14
12
  export function object(schemas) {
15
- // All property metadata is lazily computed on first use.
16
- // This keeps schema construction free of iteration, which matters when
17
- // many schemas are defined but only some are exercised at runtime.
18
- // Required-key computation is also deferred because lazy() schemas may
19
- // not be resolved at construction time.
20
- let _rawKeyToProperty;
21
- function getRawKeyToProperty() {
22
- if (_rawKeyToProperty == null) {
23
- _rawKeyToProperty = {};
13
+ const baseSchema = {
14
+ _getRawProperties: () => Object.entries(schemas).map(([parsedKey, propertySchema]) => isProperty(propertySchema) ? propertySchema.rawKey : parsedKey),
15
+ _getParsedProperties: () => keys(schemas),
16
+ parse: (raw, opts) => {
17
+ const rawKeyToProperty = {};
18
+ const requiredKeys = [];
24
19
  for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
25
- const rawKey = isProperty(schemaOrObjectProperty)
26
- ? schemaOrObjectProperty.rawKey
27
- : parsedKey;
20
+ const rawKey = isProperty(schemaOrObjectProperty) ? schemaOrObjectProperty.rawKey : parsedKey;
28
21
  const valueSchema = isProperty(schemaOrObjectProperty)
29
22
  ? schemaOrObjectProperty.valueSchema
30
23
  : schemaOrObjectProperty;
31
- _rawKeyToProperty[rawKey] = {
24
+ const property = {
32
25
  rawKey,
33
26
  parsedKey: parsedKey,
34
27
  valueSchema,
35
28
  };
36
- }
37
- }
38
- return _rawKeyToProperty;
39
- }
40
- let _parseRequiredKeys;
41
- let _jsonRequiredKeys;
42
- let _parseRequiredKeysSet;
43
- let _jsonRequiredKeysSet;
44
- function getParseRequiredKeys() {
45
- if (_parseRequiredKeys == null) {
46
- _parseRequiredKeys = [];
47
- _jsonRequiredKeys = [];
48
- for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
49
- const rawKey = isProperty(schemaOrObjectProperty)
50
- ? schemaOrObjectProperty.rawKey
51
- : parsedKey;
52
- const valueSchema = isProperty(schemaOrObjectProperty)
53
- ? schemaOrObjectProperty.valueSchema
54
- : schemaOrObjectProperty;
29
+ rawKeyToProperty[rawKey] = property;
55
30
  if (isSchemaRequired(valueSchema)) {
56
- _parseRequiredKeys.push(rawKey);
57
- _jsonRequiredKeys.push(parsedKey);
31
+ requiredKeys.push(rawKey);
58
32
  }
59
33
  }
60
- _parseRequiredKeysSet = new Set(_parseRequiredKeys);
61
- _jsonRequiredKeysSet = new Set(_jsonRequiredKeys);
62
- }
63
- return _parseRequiredKeys;
64
- }
65
- function getJsonRequiredKeys() {
66
- if (_jsonRequiredKeys == null) {
67
- getParseRequiredKeys();
68
- }
69
- return _jsonRequiredKeys;
70
- }
71
- function getParseRequiredKeysSet() {
72
- if (_parseRequiredKeysSet == null) {
73
- getParseRequiredKeys();
74
- }
75
- return _parseRequiredKeysSet;
76
- }
77
- function getJsonRequiredKeysSet() {
78
- if (_jsonRequiredKeysSet == null) {
79
- getParseRequiredKeys();
80
- }
81
- return _jsonRequiredKeysSet;
82
- }
83
- const baseSchema = {
84
- _getRawProperties: () => Object.entries(schemas).map(([parsedKey, propertySchema]) => isProperty(propertySchema) ? propertySchema.rawKey : parsedKey),
85
- _getParsedProperties: () => keys(schemas),
86
- parse: (raw, opts) => {
87
- var _a;
88
- const breadcrumbsPrefix = (_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : [];
89
34
  return validateAndTransformObject({
90
35
  value: raw,
91
- requiredKeys: getParseRequiredKeys(),
92
- requiredKeysSet: getParseRequiredKeysSet(),
36
+ requiredKeys,
93
37
  getProperty: (rawKey) => {
94
- const property = getRawKeyToProperty()[rawKey];
38
+ const property = rawKeyToProperty[rawKey];
95
39
  if (property == null) {
96
40
  return undefined;
97
41
  }
98
42
  return {
99
43
  transformedKey: property.parsedKey,
100
44
  transform: (propertyValue) => {
101
- const childBreadcrumbs = [...breadcrumbsPrefix, rawKey];
102
- return property.valueSchema.parse(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
45
+ var _a;
46
+ return property.valueSchema.parse(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), rawKey] }));
103
47
  },
104
48
  };
105
49
  },
106
50
  unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
107
51
  skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
108
- breadcrumbsPrefix,
52
+ breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
109
53
  omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
110
54
  });
111
55
  },
112
56
  json: (parsed, opts) => {
113
- var _a;
114
- const breadcrumbsPrefix = (_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : [];
57
+ const requiredKeys = [];
58
+ for (const [parsedKey, schemaOrObjectProperty] of entries(schemas)) {
59
+ const valueSchema = isProperty(schemaOrObjectProperty)
60
+ ? schemaOrObjectProperty.valueSchema
61
+ : schemaOrObjectProperty;
62
+ if (isSchemaRequired(valueSchema)) {
63
+ requiredKeys.push(parsedKey);
64
+ }
65
+ }
115
66
  return validateAndTransformObject({
116
67
  value: parsed,
117
- requiredKeys: getJsonRequiredKeys(),
118
- requiredKeysSet: getJsonRequiredKeysSet(),
68
+ requiredKeys,
119
69
  getProperty: (parsedKey) => {
120
70
  const property = schemas[parsedKey];
121
71
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -126,8 +76,8 @@ export function object(schemas) {
126
76
  return {
127
77
  transformedKey: property.rawKey,
128
78
  transform: (propertyValue) => {
129
- const childBreadcrumbs = [...breadcrumbsPrefix, parsedKey];
130
- return property.valueSchema.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
79
+ var _a;
80
+ return property.valueSchema.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), parsedKey] }));
131
81
  },
132
82
  };
133
83
  }
@@ -135,15 +85,15 @@ export function object(schemas) {
135
85
  return {
136
86
  transformedKey: parsedKey,
137
87
  transform: (propertyValue) => {
138
- const childBreadcrumbs = [...breadcrumbsPrefix, parsedKey];
139
- return property.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: childBreadcrumbs }));
88
+ var _a;
89
+ return property.json(propertyValue, Object.assign(Object.assign({}, opts), { breadcrumbsPrefix: [...((_a = opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix) !== null && _a !== void 0 ? _a : []), parsedKey] }));
140
90
  },
141
91
  };
142
92
  }
143
93
  },
144
94
  unrecognizedObjectKeys: opts === null || opts === void 0 ? void 0 : opts.unrecognizedObjectKeys,
145
95
  skipValidation: opts === null || opts === void 0 ? void 0 : opts.skipValidation,
146
- breadcrumbsPrefix,
96
+ breadcrumbsPrefix: opts === null || opts === void 0 ? void 0 : opts.breadcrumbsPrefix,
147
97
  omitUndefined: opts === null || opts === void 0 ? void 0 : opts.omitUndefined,
148
98
  });
149
99
  },
@@ -151,7 +101,7 @@ export function object(schemas) {
151
101
  };
152
102
  return Object.assign(Object.assign(Object.assign(Object.assign({}, maybeSkipValidation(baseSchema)), getSchemaUtils(baseSchema)), getObjectLikeUtils(baseSchema)), getObjectUtils(baseSchema));
153
103
  }
154
- function validateAndTransformObject({ value, requiredKeys, requiredKeysSet, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
104
+ function validateAndTransformObject({ value, requiredKeys, getProperty, unrecognizedObjectKeys = "fail", skipValidation = false, breadcrumbsPrefix = [], }) {
155
105
  if (!isPlainObject(value)) {
156
106
  return {
157
107
  ok: false,
@@ -163,21 +113,13 @@ function validateAndTransformObject({ value, requiredKeys, requiredKeysSet, getP
163
113
  ],
164
114
  };
165
115
  }
166
- // Track which required keys have been seen.
167
- // Use a counter instead of copying the Set to avoid per-call allocation.
168
- let missingRequiredCount = requiredKeys.length;
116
+ const missingRequiredKeys = new Set(requiredKeys);
169
117
  const errors = [];
170
118
  const transformed = {};
171
- for (const preTransformedKey in value) {
172
- if (!_hasOwn.call(value, preTransformedKey)) {
173
- continue;
174
- }
175
- const preTransformedItemValue = value[preTransformedKey];
119
+ for (const [preTransformedKey, preTransformedItemValue] of Object.entries(value)) {
176
120
  const property = getProperty(preTransformedKey);
177
121
  if (property != null) {
178
- if (missingRequiredCount > 0 && requiredKeysSet.has(preTransformedKey)) {
179
- missingRequiredCount--;
180
- }
122
+ missingRequiredKeys.delete(preTransformedKey);
181
123
  const value = property.transform(preTransformedItemValue);
182
124
  if (value.ok) {
183
125
  transformed[property.transformedKey] = value.value;
@@ -203,16 +145,12 @@ function validateAndTransformObject({ value, requiredKeys, requiredKeysSet, getP
203
145
  }
204
146
  }
205
147
  }
206
- if (missingRequiredCount > 0) {
207
- for (const key of requiredKeys) {
208
- if (!(key in value)) {
209
- errors.push({
210
- path: breadcrumbsPrefix,
211
- message: `Missing required key "${key}"`,
212
- });
213
- }
214
- }
215
- }
148
+ errors.push(...requiredKeys
149
+ .filter((key) => missingRequiredKeys.has(key))
150
+ .map((key) => ({
151
+ path: breadcrumbsPrefix,
152
+ message: `Missing required key "${key}"`,
153
+ })));
216
154
  if (errors.length === 0 || skipValidation) {
217
155
  return {
218
156
  ok: true,
@@ -2,8 +2,6 @@ import { filterObject } from "../../utils/filterObject.mjs";
2
2
  import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.mjs";
3
3
  import { isPlainObject } from "../../utils/isPlainObject.mjs";
4
4
  import { getSchemaUtils } from "../schema-utils/index.mjs";
5
- // eslint-disable-next-line @typescript-eslint/unbound-method
6
- const _hasOwn = Object.prototype.hasOwnProperty;
7
5
  export function getObjectLikeUtils(schema) {
8
6
  return {
9
7
  withParsedProperties: (properties) => withParsedProperties(schema, properties),
@@ -19,14 +17,9 @@ export function withParsedProperties(objectLike, properties) {
19
17
  if (!parsedObject.ok) {
20
18
  return parsedObject;
21
19
  }
22
- const additionalProperties = {};
23
- for (const key in properties) {
24
- if (_hasOwn.call(properties, key)) {
25
- const value = properties[key];
26
- additionalProperties[key] =
27
- typeof value === "function" ? value(parsedObject.value) : value;
28
- }
29
- }
20
+ const additionalProperties = Object.entries(properties).reduce((processed, [key, value]) => {
21
+ return Object.assign(Object.assign({}, processed), { [key]: typeof value === "function" ? value(parsedObject.value) : value });
22
+ }, {});
30
23
  return {
31
24
  ok: true,
32
25
  value: Object.assign(Object.assign({}, parsedObject.value), additionalProperties),
@@ -1,10 +1,9 @@
1
1
  import { SchemaType } from "../../Schema.mjs";
2
+ import { entries } from "../../utils/entries.mjs";
2
3
  import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.mjs";
3
4
  import { isPlainObject } from "../../utils/isPlainObject.mjs";
4
5
  import { maybeSkipValidation } from "../../utils/maybeSkipValidation.mjs";
5
6
  import { getSchemaUtils } from "../schema-utils/index.mjs";
6
- // eslint-disable-next-line @typescript-eslint/unbound-method
7
- const _hasOwn = Object.prototype.hasOwnProperty;
8
7
  export function record(keySchema, valueSchema) {
9
8
  const baseSchema = {
10
9
  parse: (raw, opts) => {
@@ -53,16 +52,11 @@ function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transfo
53
52
  ],
54
53
  };
55
54
  }
56
- const result = {};
57
- const errors = [];
58
- for (const stringKey in value) {
59
- if (!_hasOwn.call(value, stringKey)) {
60
- continue;
61
- }
62
- const entryValue = value[stringKey];
63
- if (entryValue === undefined) {
64
- continue;
55
+ return entries(value).reduce((accPromise, [stringKey, value]) => {
56
+ if (value === undefined) {
57
+ return accPromise;
65
58
  }
59
+ const acc = accPromise;
66
60
  let key = stringKey;
67
61
  if (isKeyNumeric) {
68
62
  const numberKey = stringKey.length > 0 ? Number(stringKey) : NaN;
@@ -71,21 +65,26 @@ function validateAndTransformRecord({ value, isKeyNumeric, transformKey, transfo
71
65
  }
72
66
  }
73
67
  const transformedKey = transformKey(key);
74
- const transformedValue = transformValue(entryValue, key);
75
- if (transformedKey.ok && transformedValue.ok) {
76
- result[transformedKey.value] = transformedValue.value;
68
+ const transformedValue = transformValue(value, key);
69
+ if (acc.ok && transformedKey.ok && transformedValue.ok) {
70
+ return {
71
+ ok: true,
72
+ value: Object.assign(Object.assign({}, acc.value), { [transformedKey.value]: transformedValue.value }),
73
+ };
77
74
  }
78
- else {
79
- if (!transformedKey.ok) {
80
- errors.push(...transformedKey.errors);
81
- }
82
- if (!transformedValue.ok) {
83
- errors.push(...transformedValue.errors);
84
- }
75
+ const errors = [];
76
+ if (!acc.ok) {
77
+ errors.push(...acc.errors);
85
78
  }
86
- }
87
- if (errors.length === 0) {
88
- return { ok: true, value: result };
89
- }
90
- return { ok: false, errors };
79
+ if (!transformedKey.ok) {
80
+ errors.push(...transformedKey.errors);
81
+ }
82
+ if (!transformedValue.ok) {
83
+ errors.push(...transformedValue.errors);
84
+ }
85
+ return {
86
+ ok: false,
87
+ errors,
88
+ };
89
+ }, { ok: true, value: {} });
91
90
  }
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { SchemaType } from "../../Schema.mjs";
2
13
  import { getErrorMessageForIncorrectType } from "../../utils/getErrorMessageForIncorrectType.mjs";
3
14
  import { isPlainObject } from "../../utils/isPlainObject.mjs";
@@ -6,8 +17,6 @@ import { maybeSkipValidation } from "../../utils/maybeSkipValidation.mjs";
6
17
  import { enum_ } from "../enum/index.mjs";
7
18
  import { getObjectLikeUtils } from "../object-like/index.mjs";
8
19
  import { getSchemaUtils } from "../schema-utils/index.mjs";
9
- // eslint-disable-next-line @typescript-eslint/unbound-method
10
- const _hasOwn = Object.prototype.hasOwnProperty;
11
20
  export function union(discriminant, union) {
12
21
  const rawDiscriminant = typeof discriminant === "string" ? discriminant : discriminant.rawDiscriminant;
13
22
  const parsedDiscriminant = typeof discriminant === "string"
@@ -67,13 +76,7 @@ function transformAndValidateUnion({ value, discriminant, transformedDiscriminan
67
76
  ],
68
77
  };
69
78
  }
70
- const discriminantValue = value[discriminant];
71
- const additionalProperties = {};
72
- for (const key in value) {
73
- if (_hasOwn.call(value, key) && key !== discriminant) {
74
- additionalProperties[key] = value[key];
75
- }
76
- }
79
+ const _a = value, _b = discriminant, discriminantValue = _a[_b], additionalProperties = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
77
80
  if (discriminantValue == null) {
78
81
  return {
79
82
  ok: false,
@@ -3,10 +3,12 @@ export function isPlainObject(value) {
3
3
  if (typeof value !== "object" || value === null) {
4
4
  return false;
5
5
  }
6
- const proto = Object.getPrototypeOf(value);
7
- if (proto === null) {
6
+ if (Object.getPrototypeOf(value) === null) {
8
7
  return true;
9
8
  }
10
- // Check that the prototype chain has exactly one level (i.e., proto is Object.prototype)
11
- return Object.getPrototypeOf(proto) === null;
9
+ let proto = value;
10
+ while (Object.getPrototypeOf(proto) !== null) {
11
+ proto = Object.getPrototypeOf(proto);
12
+ }
13
+ return Object.getPrototypeOf(value) === proto;
12
14
  }
@@ -11,9 +11,13 @@ export declare const AgentMailEnvironment: {
11
11
  readonly http: "https://x402.api.agentmail.to";
12
12
  readonly websockets: "wss://x402.ws.agentmail.to";
13
13
  };
14
+ readonly ProdMpp: {
15
+ readonly http: "https://mpp.api.agentmail.to";
16
+ readonly websockets: "wss://mpp.ws.agentmail.to";
17
+ };
14
18
  readonly EuProd: {
15
19
  readonly http: "https://api.agentmail.eu";
16
20
  readonly websockets: "wss://ws.agentmail.eu";
17
21
  };
18
22
  };
19
- export type AgentMailEnvironment = typeof AgentMailEnvironment.Prod | typeof AgentMailEnvironment.ProdX402 | typeof AgentMailEnvironment.EuProd;
23
+ export type AgentMailEnvironment = typeof AgentMailEnvironment.Prod | typeof AgentMailEnvironment.ProdX402 | typeof AgentMailEnvironment.ProdMpp | typeof AgentMailEnvironment.EuProd;
@@ -8,6 +8,10 @@ export const AgentMailEnvironment = {
8
8
  http: "https://x402.api.agentmail.to",
9
9
  websockets: "wss://x402.ws.agentmail.to",
10
10
  },
11
+ ProdMpp: {
12
+ http: "https://mpp.api.agentmail.to",
13
+ websockets: "wss://mpp.ws.agentmail.to",
14
+ },
11
15
  EuProd: {
12
16
  http: "https://api.agentmail.eu",
13
17
  websockets: "wss://ws.agentmail.eu",
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.2.19";
1
+ export declare const SDK_VERSION = "0.2.21";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.2.19";
1
+ export const SDK_VERSION = "0.2.21";