@ar.io/sdk 3.9.0-alpha.3 → 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,7 +68,14 @@ class AOProcess {
68
68
  processId: this.processId,
69
69
  });
70
70
  if (attempts >= retries) {
71
- throw error;
71
+ this.logger.debug(`Maximum read attempts exceeded`, {
72
+ error: error?.message,
73
+ stack: error?.stack,
74
+ tags,
75
+ processId: this.processId,
76
+ ao: JSON.stringify(this.ao),
77
+ });
78
+ throw new Error(`Failed to evaluate a dry-run on process ${this.processId}.`);
72
79
  }
73
80
  // exponential backoff
74
81
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
@@ -86,7 +93,7 @@ class AOProcess {
86
93
  throw new Error(error);
87
94
  }
88
95
  if (result.Messages === undefined || result.Messages.length === 0) {
89
- 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.`, {
90
97
  result,
91
98
  tags,
92
99
  processId: this.processId,
@@ -102,34 +109,50 @@ class AOProcess {
102
109
  return response;
103
110
  }
104
111
  async send({ tags, data, signer, retries = 3, }) {
105
- // main purpose of retries is to handle network errors/new process delays
106
- let attempts = 0;
107
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
108
152
  let result = undefined;
153
+ let attempts = 0;
109
154
  while (attempts < retries) {
110
155
  try {
111
- this.logger.debug(`Evaluating send interaction on contract`, {
112
- tags,
113
- data,
114
- processId: this.processId,
115
- });
116
- // TODO: do a read as a dry run to check if the process supports the action
117
- // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
118
- const anchor = (0, base64_js_1.getRandomText)(32);
119
- messageId = await this.ao.message({
120
- process: this.processId,
121
- // TODO: any other default tags we want to add?
122
- tags: [...tags, { name: 'AR-IO-SDK', value: version_js_1.version }],
123
- data,
124
- signer,
125
- anchor,
126
- });
127
- this.logger.debug(`Sent message to process`, {
128
- messageId,
129
- processId: this.processId,
130
- anchor,
131
- });
132
- // check the result of the send interaction
133
156
  result = await this.ao.result({
134
157
  message: messageId,
135
158
  process: this.processId,
@@ -142,12 +165,6 @@ class AOProcess {
142
165
  break;
143
166
  }
144
167
  catch (error) {
145
- this.logger.error('Error sending message to process', {
146
- error: error?.message,
147
- stack: error?.stack,
148
- processId: this.processId,
149
- tags,
150
- });
151
168
  attempts++;
152
169
  this.logger.debug('Retrying send interaction', {
153
170
  attempts,
@@ -156,14 +173,26 @@ class AOProcess {
156
173
  processId: this.processId,
157
174
  });
158
175
  if (attempts >= retries) {
159
- throw error;
176
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but result was not returned. Review transactions for more details.`, {
177
+ error: error?.message,
178
+ stack: error?.stack,
179
+ tags,
180
+ processId: this.processId,
181
+ messageId,
182
+ });
183
+ return { id: messageId };
160
184
  }
161
185
  // exponential backoff
162
186
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
163
187
  }
164
188
  }
165
- if (result === undefined || messageId === undefined) {
166
- 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 };
167
196
  }
168
197
  const error = (0, index_js_1.errorMessageFromOutput)(result);
169
198
  if (error !== undefined) {
@@ -173,9 +202,6 @@ class AOProcess {
173
202
  if (result.Messages?.length === 0 || result.Messages === undefined) {
174
203
  return { id: messageId };
175
204
  }
176
- if (result.Messages.length === 0) {
177
- throw new Error(`Process ${this.processId} does not support provided action.`);
178
- }
179
205
  if (this.isMessageDataEmpty(result.Messages[0].Data)) {
180
206
  return { id: messageId };
181
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.3';
20
+ exports.version = '3.9.0-alpha.5';
@@ -65,7 +65,14 @@ export class AOProcess {
65
65
  processId: this.processId,
66
66
  });
67
67
  if (attempts >= retries) {
68
- throw error;
68
+ this.logger.debug(`Maximum read attempts exceeded`, {
69
+ error: error?.message,
70
+ stack: error?.stack,
71
+ tags,
72
+ processId: this.processId,
73
+ ao: JSON.stringify(this.ao),
74
+ });
75
+ throw new Error(`Failed to evaluate a dry-run on process ${this.processId}.`);
69
76
  }
70
77
  // exponential backoff
71
78
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 1000));
@@ -83,7 +90,7 @@ export class AOProcess {
83
90
  throw new Error(error);
84
91
  }
85
92
  if (result.Messages === undefined || result.Messages.length === 0) {
86
- 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.`, {
87
94
  result,
88
95
  tags,
89
96
  processId: this.processId,
@@ -99,34 +106,50 @@ export class AOProcess {
99
106
  return response;
100
107
  }
101
108
  async send({ tags, data, signer, retries = 3, }) {
102
- // main purpose of retries is to handle network errors/new process delays
103
- let attempts = 0;
104
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
105
149
  let result = undefined;
150
+ let attempts = 0;
106
151
  while (attempts < retries) {
107
152
  try {
108
- this.logger.debug(`Evaluating send interaction on contract`, {
109
- tags,
110
- data,
111
- processId: this.processId,
112
- });
113
- // TODO: do a read as a dry run to check if the process supports the action
114
- // anchor is a random text produce non-deterministic messages IDs when deterministic signers are provided (ETH)
115
- const anchor = getRandomText(32);
116
- messageId = await this.ao.message({
117
- process: this.processId,
118
- // TODO: any other default tags we want to add?
119
- tags: [...tags, { name: 'AR-IO-SDK', value: version }],
120
- data,
121
- signer,
122
- anchor,
123
- });
124
- this.logger.debug(`Sent message to process`, {
125
- messageId,
126
- processId: this.processId,
127
- anchor,
128
- });
129
- // check the result of the send interaction
130
153
  result = await this.ao.result({
131
154
  message: messageId,
132
155
  process: this.processId,
@@ -139,12 +162,6 @@ export class AOProcess {
139
162
  break;
140
163
  }
141
164
  catch (error) {
142
- this.logger.error('Error sending message to process', {
143
- error: error?.message,
144
- stack: error?.stack,
145
- processId: this.processId,
146
- tags,
147
- });
148
165
  attempts++;
149
166
  this.logger.debug('Retrying send interaction', {
150
167
  attempts,
@@ -153,14 +170,26 @@ export class AOProcess {
153
170
  processId: this.processId,
154
171
  });
155
172
  if (attempts >= retries) {
156
- throw error;
173
+ this.logger.debug(`Message was sent to process ${this.processId} with id ${messageId} but result was not returned. Review transactions for more details.`, {
174
+ error: error?.message,
175
+ stack: error?.stack,
176
+ tags,
177
+ processId: this.processId,
178
+ messageId,
179
+ });
180
+ return { id: messageId };
157
181
  }
158
182
  // exponential backoff
159
183
  await new Promise((resolve) => setTimeout(resolve, 2 ** attempts * 2000));
160
184
  }
161
185
  }
162
- if (result === undefined || messageId === undefined) {
163
- 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 };
164
193
  }
165
194
  const error = errorMessageFromOutput(result);
166
195
  if (error !== undefined) {
@@ -170,9 +199,6 @@ export class AOProcess {
170
199
  if (result.Messages?.length === 0 || result.Messages === undefined) {
171
200
  return { id: messageId };
172
201
  }
173
- if (result.Messages.length === 0) {
174
- throw new Error(`Process ${this.processId} does not support provided action.`);
175
- }
176
202
  if (this.isMessageDataEmpty(result.Messages[0].Data)) {
177
203
  return { id: messageId };
178
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.3';
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.2";
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.3",
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"