@ar.io/sdk 3.9.0-alpha.4 → 3.9.0-alpha.5

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.
@@ -68,13 +68,14 @@ class AOProcess {
68
68
  processId: this.processId,
69
69
  });
70
70
  if (attempts >= retries) {
71
- this.logger.error(`Maximum read attempts exceeded`, {
71
+ this.logger.debug(`Maximum read attempts exceeded`, {
72
72
  error: error?.message,
73
73
  stack: error?.stack,
74
74
  tags,
75
75
  processId: this.processId,
76
+ ao: JSON.stringify(this.ao),
76
77
  });
77
- throw new Error(`Maximum read attempts exceeded for process ${this.processId}`);
78
+ throw new Error(`Failed to evaluate a dry-run on process ${this.processId}.`);
78
79
  }
79
80
  // exponential backoff
80
81
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
@@ -92,7 +93,7 @@ class AOProcess {
92
93
  throw new Error(error);
93
94
  }
94
95
  if (result.Messages === undefined || result.Messages.length === 0) {
95
- this.logger.debug(`Process ${this.processId} does not support provided action.`, {
96
+ this.logger.debug(`Empty result - process ${this.processId} does not support provided action.`, {
96
97
  result,
97
98
  tags,
98
99
  processId: this.processId,
@@ -108,32 +109,50 @@ class AOProcess {
108
109
  return response;
109
110
  }
110
111
  async send({ tags, data, signer, retries = 3, }) {
111
- // main purpose of retries is to handle network errors/new process delays
112
- let attempts = 0;
113
112
  let messageId;
113
+ const anchor = (0, base64_js_1.getRandomText)(32); // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
114
+ try {
115
+ this.logger.debug(`Evaluating send interaction on contract`, {
116
+ tags,
117
+ data,
118
+ processId: this.processId,
119
+ });
120
+ /**
121
+ * DO NOT retry messaging if a message was already sent.
122
+ * This could result in a double entry-like condition when sending tokens for example.
123
+ * If the message fails to send we will throw an error and the caller can retry.
124
+ */
125
+ messageId = await this.ao.message({
126
+ process: this.processId,
127
+ tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
128
+ data,
129
+ signer,
130
+ anchor,
131
+ });
132
+ this.logger.debug(`Sent message to process`, {
133
+ messageId,
134
+ processId: this.processId,
135
+ anchor,
136
+ });
137
+ }
138
+ catch (error) {
139
+ this.logger.debug('Error sending message to process', {
140
+ error: error?.message,
141
+ stack: error?.stack,
142
+ processId: this.processId,
143
+ tags,
144
+ });
145
+ // throw the error so it can be handled by the caller
146
+ throw error;
147
+ }
148
+ if (messageId === undefined) {
149
+ throw new Error('Failed to send message to process.');
150
+ }
151
+ // get the result of the message before returning, using retries to handle network errors/new process delays
114
152
  let result = undefined;
115
- // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
116
- const anchor = (0, base64_js_1.getRandomText)(32);
153
+ let attempts = 0;
117
154
  while (attempts < retries) {
118
155
  try {
119
- this.logger.debug(`Evaluating send interaction on contract`, {
120
- tags,
121
- data,
122
- processId: this.processId,
123
- });
124
- // MUST NOT retry messaging if a message was already sent. This could result in a double entry-like condition when sending tokens for example.
125
- messageId ??= await this.ao.message({
126
- process: this.processId,
127
- tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
128
- data,
129
- signer,
130
- anchor,
131
- });
132
- this.logger.debug(`Sent message to process`, {
133
- messageId,
134
- processId: this.processId,
135
- anchor,
136
- });
137
156
  result = await this.ao.result({
138
157
  message: messageId,
139
158
  process: this.processId,
@@ -146,12 +165,6 @@ class AOProcess {
146
165
  break;
147
166
  }
148
167
  catch (error) {
149
- this.logger.error('Error sending message to process', {
150
- error: error?.message,
151
- stack: error?.stack,
152
- processId: this.processId,
153
- tags,
154
- });
155
168
  attempts++;
156
169
  this.logger.debug('Retrying send interaction', {
157
170
  attempts,
@@ -160,20 +173,26 @@ class AOProcess {
160
173
  processId: this.processId,
161
174
  });
162
175
  if (attempts >= retries) {
163
- this.logger.error(`Maximum read result attempts exceeded`, {
176
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but result was not returned. Review transactions for more details.`, {
164
177
  error: error?.message,
165
178
  stack: error?.stack,
166
179
  tags,
167
180
  processId: this.processId,
181
+ messageId,
168
182
  });
169
- throw new Error(`Maximum read result attempts exceeded for process ${this.processId}.`);
183
+ return { id: messageId };
170
184
  }
171
185
  // exponential backoff
172
186
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
173
187
  }
174
188
  }
175
- if (result === undefined || messageId === undefined) {
176
- throw new Error('Unexpected error when evaluating write interaction');
189
+ if (result === undefined) {
190
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but the result was not returned. Review transactions for more details.`, {
191
+ tags,
192
+ processId: this.processId,
193
+ messageId,
194
+ });
195
+ return { id: messageId };
177
196
  }
178
197
  const error = (0, index_js_1.errorMessageFromOutput)(result);
179
198
  if (error !== undefined) {
@@ -183,9 +202,6 @@ class AOProcess {
183
202
  if (result.Messages?.length === 0 || result.Messages === undefined) {
184
203
  return { id: messageId };
185
204
  }
186
- if (result.Messages.length === 0) {
187
- throw new Error(`Process ${this.processId} does not support provided action.`);
188
- }
189
205
  if (this.isMessageDataEmpty(result.Messages[0].Data)) {
190
206
  return { id: messageId };
191
207
  }
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.9.0-alpha.4';
20
+ exports.version = '3.9.0-alpha.5';
@@ -65,13 +65,14 @@ export class AOProcess {
65
65
  processId: this.processId,
66
66
  });
67
67
  if (attempts >= retries) {
68
- this.logger.error(`Maximum read attempts exceeded`, {
68
+ this.logger.debug(`Maximum read attempts exceeded`, {
69
69
  error: error?.message,
70
70
  stack: error?.stack,
71
71
  tags,
72
72
  processId: this.processId,
73
+ ao: JSON.stringify(this.ao),
73
74
  });
74
- throw new Error(`Maximum read attempts exceeded for process ${this.processId}`);
75
+ throw new Error(`Failed to evaluate a dry-run on process ${this.processId}.`);
75
76
  }
76
77
  // exponential backoff
77
78
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
@@ -89,7 +90,7 @@ export class AOProcess {
89
90
  throw new Error(error);
90
91
  }
91
92
  if (result.Messages === undefined || result.Messages.length === 0) {
92
- this.logger.debug(`Process ${this.processId} does not support provided action.`, {
93
+ this.logger.debug(`Empty result - process ${this.processId} does not support provided action.`, {
93
94
  result,
94
95
  tags,
95
96
  processId: this.processId,
@@ -105,32 +106,50 @@ export class AOProcess {
105
106
  return response;
106
107
  }
107
108
  async send({ tags, data, signer, retries = 3, }) {
108
- // main purpose of retries is to handle network errors/new process delays
109
- let attempts = 0;
110
109
  let messageId;
110
+ const anchor = getRandomText(32); // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
111
+ try {
112
+ this.logger.debug(`Evaluating send interaction on contract`, {
113
+ tags,
114
+ data,
115
+ processId: this.processId,
116
+ });
117
+ /**
118
+ * DO NOT retry messaging if a message was already sent.
119
+ * This could result in a double entry-like condition when sending tokens for example.
120
+ * If the message fails to send we will throw an error and the caller can retry.
121
+ */
122
+ messageId = await this.ao.message({
123
+ process: this.processId,
124
+ tags: [...tags, { name: 'AR-IO-SDK', value: version }],
125
+ data,
126
+ signer,
127
+ anchor,
128
+ });
129
+ this.logger.debug(`Sent message to process`, {
130
+ messageId,
131
+ processId: this.processId,
132
+ anchor,
133
+ });
134
+ }
135
+ catch (error) {
136
+ this.logger.debug('Error sending message to process', {
137
+ error: error?.message,
138
+ stack: error?.stack,
139
+ processId: this.processId,
140
+ tags,
141
+ });
142
+ // throw the error so it can be handled by the caller
143
+ throw error;
144
+ }
145
+ if (messageId === undefined) {
146
+ throw new Error('Failed to send message to process.');
147
+ }
148
+ // get the result of the message before returning, using retries to handle network errors/new process delays
111
149
  let result = undefined;
112
- // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
113
- const anchor = getRandomText(32);
150
+ let attempts = 0;
114
151
  while (attempts < retries) {
115
152
  try {
116
- this.logger.debug(`Evaluating send interaction on contract`, {
117
- tags,
118
- data,
119
- processId: this.processId,
120
- });
121
- // MUST NOT retry messaging if a message was already sent. This could result in a double entry-like condition when sending tokens for example.
122
- messageId ??= await this.ao.message({
123
- process: this.processId,
124
- tags: [...tags, { name: 'AR-IO-SDK', value: version }],
125
- data,
126
- signer,
127
- anchor,
128
- });
129
- this.logger.debug(`Sent message to process`, {
130
- messageId,
131
- processId: this.processId,
132
- anchor,
133
- });
134
153
  result = await this.ao.result({
135
154
  message: messageId,
136
155
  process: this.processId,
@@ -143,12 +162,6 @@ export class AOProcess {
143
162
  break;
144
163
  }
145
164
  catch (error) {
146
- this.logger.error('Error sending message to process', {
147
- error: error?.message,
148
- stack: error?.stack,
149
- processId: this.processId,
150
- tags,
151
- });
152
165
  attempts++;
153
166
  this.logger.debug('Retrying send interaction', {
154
167
  attempts,
@@ -157,20 +170,26 @@ export class AOProcess {
157
170
  processId: this.processId,
158
171
  });
159
172
  if (attempts >= retries) {
160
- this.logger.error(`Maximum read result attempts exceeded`, {
173
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but result was not returned. Review transactions for more details.`, {
161
174
  error: error?.message,
162
175
  stack: error?.stack,
163
176
  tags,
164
177
  processId: this.processId,
178
+ messageId,
165
179
  });
166
- throw new Error(`Maximum read result attempts exceeded for process ${this.processId}.`);
180
+ return { id: messageId };
167
181
  }
168
182
  // exponential backoff
169
183
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
170
184
  }
171
185
  }
172
- if (result === undefined || messageId === undefined) {
173
- throw new Error('Unexpected error when evaluating write interaction');
186
+ if (result === undefined) {
187
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but the result was not returned. Review transactions for more details.`, {
188
+ tags,
189
+ processId: this.processId,
190
+ messageId,
191
+ });
192
+ return { id: messageId };
174
193
  }
175
194
  const error = errorMessageFromOutput(result);
176
195
  if (error !== undefined) {
@@ -180,9 +199,6 @@ export class AOProcess {
180
199
  if (result.Messages?.length === 0 || result.Messages === undefined) {
181
200
  return { id: messageId };
182
201
  }
183
- if (result.Messages.length === 0) {
184
- throw new Error(`Process ${this.processId} does not support provided action.`);
185
- }
186
202
  if (this.isMessageDataEmpty(result.Messages[0].Data)) {
187
203
  return { id: messageId };
188
204
  }
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.9.0-alpha.4';
17
+ export const version = '3.9.0-alpha.5';
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.9.0-alpha.3";
16
+ export declare const version = "3.9.0-alpha.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.9.0-alpha.4",
3
+ "version": "3.9.0-alpha.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"