@ardrive/turbo-sdk 1.42.0 → 1.43.0-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.
Files changed (99) hide show
  1. package/lib/cjs/cli/cli.js +92 -0
  2. package/lib/cjs/cli/commands/arns.js +440 -0
  3. package/lib/cjs/cli/commands/freeStatus.js +47 -0
  4. package/lib/cjs/cli/commands/index.js +3 -0
  5. package/lib/cjs/cli/commands/paymentHistory.js +25 -0
  6. package/lib/cjs/cli/options.js +201 -1
  7. package/lib/cjs/common/arnsActions.js +125 -0
  8. package/lib/cjs/common/chunked.js +51 -1
  9. package/lib/cjs/common/folderIndex.js +394 -0
  10. package/lib/cjs/common/http.js +32 -6
  11. package/lib/cjs/common/index.js +7 -0
  12. package/lib/cjs/common/payment.js +546 -0
  13. package/lib/cjs/common/signer.js +27 -6
  14. package/lib/cjs/common/token/index.js +0 -11
  15. package/lib/cjs/common/turbo.js +162 -0
  16. package/lib/cjs/common/upload.js +314 -31
  17. package/lib/cjs/node/folderIndex.js +132 -0
  18. package/lib/cjs/node/index.js +1 -0
  19. package/lib/cjs/node/upload.js +7 -0
  20. package/lib/cjs/types.js +53 -3
  21. package/lib/cjs/utils/common.js +0 -4
  22. package/lib/cjs/utils/errors.js +38 -1
  23. package/lib/cjs/utils/folderIndex.js +88 -0
  24. package/lib/cjs/utils/uuid.js +31 -0
  25. package/lib/cjs/web/signer.js +4 -2
  26. package/lib/esm/cli/cli.js +94 -2
  27. package/lib/esm/cli/commands/arns.js +416 -0
  28. package/lib/esm/cli/commands/freeStatus.js +44 -0
  29. package/lib/esm/cli/commands/index.js +3 -0
  30. package/lib/esm/cli/commands/paymentHistory.js +22 -0
  31. package/lib/esm/cli/options.js +200 -0
  32. package/lib/esm/common/arnsActions.js +114 -0
  33. package/lib/esm/common/chunked.js +51 -1
  34. package/lib/esm/common/folderIndex.js +389 -0
  35. package/lib/esm/common/http.js +31 -5
  36. package/lib/esm/common/index.js +7 -0
  37. package/lib/esm/common/payment.js +546 -0
  38. package/lib/esm/common/signer.js +28 -7
  39. package/lib/esm/common/token/index.js +1 -12
  40. package/lib/esm/common/turbo.js +162 -0
  41. package/lib/esm/common/upload.js +316 -33
  42. package/lib/esm/node/folderIndex.js +129 -0
  43. package/lib/esm/node/index.js +1 -0
  44. package/lib/esm/node/upload.js +7 -0
  45. package/lib/esm/types.js +52 -2
  46. package/lib/esm/utils/common.js +0 -4
  47. package/lib/esm/utils/errors.js +35 -0
  48. package/lib/esm/utils/folderIndex.js +81 -0
  49. package/lib/esm/utils/uuid.js +28 -0
  50. package/lib/esm/web/signer.js +4 -2
  51. package/lib/types/cli/commands/arns.d.ts +133 -0
  52. package/lib/types/cli/commands/arns.d.ts.map +1 -0
  53. package/lib/types/cli/commands/freeStatus.d.ts +3 -0
  54. package/lib/types/cli/commands/freeStatus.d.ts.map +1 -0
  55. package/lib/types/cli/commands/index.d.ts +3 -0
  56. package/lib/types/cli/commands/index.d.ts.map +1 -1
  57. package/lib/types/cli/commands/paymentHistory.d.ts +18 -0
  58. package/lib/types/cli/commands/paymentHistory.d.ts.map +1 -0
  59. package/lib/types/cli/options.d.ts +410 -0
  60. package/lib/types/cli/options.d.ts.map +1 -1
  61. package/lib/types/cli/types.d.ts +71 -0
  62. package/lib/types/cli/types.d.ts.map +1 -1
  63. package/lib/types/common/arnsActions.d.ts +58 -0
  64. package/lib/types/common/arnsActions.d.ts.map +1 -0
  65. package/lib/types/common/chunked.d.ts +47 -2
  66. package/lib/types/common/chunked.d.ts.map +1 -1
  67. package/lib/types/common/folderIndex.d.ts +54 -0
  68. package/lib/types/common/folderIndex.d.ts.map +1 -0
  69. package/lib/types/common/http.d.ts +25 -2
  70. package/lib/types/common/http.d.ts.map +1 -1
  71. package/lib/types/common/index.d.ts +3 -0
  72. package/lib/types/common/index.d.ts.map +1 -1
  73. package/lib/types/common/payment.d.ts +291 -1
  74. package/lib/types/common/payment.d.ts.map +1 -1
  75. package/lib/types/common/signer.d.ts +12 -6
  76. package/lib/types/common/signer.d.ts.map +1 -1
  77. package/lib/types/common/token/index.d.ts.map +1 -1
  78. package/lib/types/common/turbo.d.ts +183 -1
  79. package/lib/types/common/turbo.d.ts.map +1 -1
  80. package/lib/types/common/upload.d.ts +41 -0
  81. package/lib/types/common/upload.d.ts.map +1 -1
  82. package/lib/types/node/folderIndex.d.ts +28 -0
  83. package/lib/types/node/folderIndex.d.ts.map +1 -0
  84. package/lib/types/node/index.d.ts +1 -0
  85. package/lib/types/node/index.d.ts.map +1 -1
  86. package/lib/types/node/upload.d.ts +1 -0
  87. package/lib/types/node/upload.d.ts.map +1 -1
  88. package/lib/types/types.d.ts +694 -3
  89. package/lib/types/types.d.ts.map +1 -1
  90. package/lib/types/utils/common.d.ts.map +1 -1
  91. package/lib/types/utils/errors.d.ts +29 -0
  92. package/lib/types/utils/errors.d.ts.map +1 -1
  93. package/lib/types/utils/folderIndex.d.ts +47 -0
  94. package/lib/types/utils/folderIndex.d.ts.map +1 -0
  95. package/lib/types/utils/uuid.d.ts +7 -0
  96. package/lib/types/utils/uuid.d.ts.map +1 -0
  97. package/lib/types/web/signer.d.ts +1 -1
  98. package/lib/types/web/signer.d.ts.map +1 -1
  99. package/package.json +1 -1
@@ -0,0 +1,416 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { BigNumber } from 'bignumber.js';
17
+ import { solanaOwnerSigner } from '../../common/arnsActions.js';
18
+ import { TurboFactory } from '../../node/factory.js';
19
+ import { arNSActions, } from '../../types.js';
20
+ import { FiatPaymentsDisabledError, InsufficientCreditsError, } from '../../utils/errors.js';
21
+ import { wincPerCredit } from '../constants.js';
22
+ import { configFromOptions, turboFromOptions } from '../utils.js';
23
+ /**
24
+ * The ANT owner's Solana key.
25
+ *
26
+ * Deliberately separate from the wallet that pays: the payer holds Turbo
27
+ * credits (and may be Arweave or Ethereum), while the owner holds the ANT and
28
+ * must be Solana. The owner needs a key to SIGN with, not a funded account —
29
+ * Turbo is the fee payer on every sponsored action.
30
+ */
31
+ function ownerFromOptions(options) {
32
+ if (options.ownerKey === undefined || options.ownerKey === '') {
33
+ throw new Error('Must provide --owner-key (a base58 Solana secret key) — it owns the ANT and signs for it. ' +
34
+ 'This is separate from the wallet paying in Turbo Credits.');
35
+ }
36
+ return solanaOwnerSigner(options.ownerKey);
37
+ }
38
+ /** The four ARIO-purchase actions are priced via `arnsPrice`, not this route. */
39
+ const ARNS_PURCHASE_ACTIONS = new Set([
40
+ 'buy-name',
41
+ 'extend-lease',
42
+ 'upgrade-name',
43
+ 'increase-undername-limit',
44
+ ]);
45
+ export function requiredNameFromOptions(options) {
46
+ if (options.name === undefined || options.name.length === 0) {
47
+ throw new Error('Must provide an ArNS --name');
48
+ }
49
+ return options.name;
50
+ }
51
+ export function positiveIntFromOption(value, flag) {
52
+ if (value === undefined) {
53
+ throw new Error(`Must provide ${flag}`);
54
+ }
55
+ const num = +value;
56
+ if (!Number.isFinite(num) || !Number.isInteger(num) || num <= 0) {
57
+ throw new Error(`${flag} must be a positive integer`);
58
+ }
59
+ return num;
60
+ }
61
+ export function typeFromOptions(value) {
62
+ if (value !== 'lease' && value !== 'permabuy') {
63
+ throw new Error("Must provide --type of 'lease' or 'permabuy'");
64
+ }
65
+ return value;
66
+ }
67
+ /** Parses `--action` for `arns-action-price`, rejecting the four purchase actions. */
68
+ export function actionFromOptions(options) {
69
+ const { action } = options;
70
+ if (action === undefined || action.length === 0) {
71
+ throw new Error(`Must provide --action. One of: ${arNSActions.join(', ')}`);
72
+ }
73
+ if (!arNSActions.includes(action)) {
74
+ throw new Error(`Invalid --action '${action}'. One of: ${arNSActions.join(', ')}`);
75
+ }
76
+ if (ARNS_PURCHASE_ACTIONS.has(action)) {
77
+ throw new Error(`'${action}' is priced via \`turbo arns-price\`, not \`arns-action-price\` — ` +
78
+ 'it spends ARIO, not just the flat credits margin this route quotes.');
79
+ }
80
+ return action;
81
+ }
82
+ /** `null` clears the field (Set-Record-Metadata's tri-state), `undefined` leaves it unchanged. */
83
+ function metadataFieldFromOptions(value, clear) {
84
+ return clear ? null : value;
85
+ }
86
+ export function paidByFromArNSOptions(paidBy) {
87
+ return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
88
+ }
89
+ // A price quote depends only on the name (length), type, and years — NOT on the
90
+ // ANT the name will resolve to. The service ignores `processId` for pricing, but
91
+ // the SDK's Buy-Name validation still requires a non-empty one, so we substitute
92
+ // this obvious placeholder when the user omits `--process-id` from `arns-price`.
93
+ // (`buy-arns-name` still requires a real `--process-id`.)
94
+ const PRICING_PLACEHOLDER_PROCESS_ID = 'pricing-only-no-process-id';
95
+ /**
96
+ * Infer the ArNS pricing intent from the provided flags:
97
+ * - `--type` present -> Buy-Name (lease needs --years; --process-id optional for pricing)
98
+ * - `--increase-qty` present -> Increase-Undername-Limit
99
+ * - `--years` present (no type) -> Extend-Lease
100
+ * - otherwise -> Upgrade-Name
101
+ */
102
+ export function arnsPriceParamsFromOptions(options) {
103
+ const name = requiredNameFromOptions(options);
104
+ if (options.type !== undefined) {
105
+ const type = typeFromOptions(options.type);
106
+ const processId = options.processId ?? PRICING_PLACEHOLDER_PROCESS_ID;
107
+ if (type === 'lease') {
108
+ return {
109
+ intent: 'Buy-Name',
110
+ name,
111
+ type: 'lease',
112
+ years: positiveIntFromOption(options.years, '--years'),
113
+ processId,
114
+ };
115
+ }
116
+ return {
117
+ intent: 'Buy-Name',
118
+ name,
119
+ type: 'permabuy',
120
+ processId,
121
+ };
122
+ }
123
+ if (options.increaseQty !== undefined) {
124
+ return {
125
+ intent: 'Increase-Undername-Limit',
126
+ name,
127
+ increaseQty: positiveIntFromOption(options.increaseQty, '--increase-qty'),
128
+ };
129
+ }
130
+ if (options.years !== undefined) {
131
+ return {
132
+ intent: 'Extend-Lease',
133
+ name,
134
+ years: positiveIntFromOption(options.years, '--years'),
135
+ };
136
+ }
137
+ return { intent: 'Upgrade-Name', name };
138
+ }
139
+ function creditsFromWinc(winc) {
140
+ return new BigNumber(winc).dividedBy(wincPerCredit).toFixed(12);
141
+ }
142
+ /** Rethrow a 402 as a clear, actionable "top up" message. */
143
+ async function withCreditErrorMapping(fn) {
144
+ try {
145
+ return await fn();
146
+ }
147
+ catch (error) {
148
+ if (error instanceof InsufficientCreditsError) {
149
+ throw new Error('Insufficient Turbo credits to complete this ArNS purchase. ' +
150
+ 'Top up your balance (e.g. `turbo top-up` or `turbo crypto-fund`) and retry.');
151
+ }
152
+ throw error;
153
+ }
154
+ }
155
+ function logPurchaseResult(action, result) {
156
+ console.log(JSON.stringify({
157
+ message: `${action} completed!`,
158
+ nonce: result.nonce,
159
+ antId: result.antId,
160
+ // Solana transaction id of the on-chain write.
161
+ messageId: result.messageId,
162
+ ...(result.alreadyCompleted === true ? { alreadyCompleted: true } : {}),
163
+ }, null, 2));
164
+ console.log(`\nTrack this purchase with:\n turbo arns-purchase-status --nonce ${result.nonce}`);
165
+ }
166
+ export async function arnsPrice(options, turbo) {
167
+ const params = arnsPriceParamsFromOptions(options);
168
+ const client = turbo ?? TurboFactory.unauthenticated(configFromOptions(options));
169
+ const { winc, wincTotal, antSpawnSurchargeWinc, mARIO } = await client.getArNSPriceForName(params);
170
+ // `wincTotal` is the figure to pay. `winc` is the name only and excludes the
171
+ // ANT spawn surcharge, which for a Buy-Name can exceed the name's own price,
172
+ // so printing it as the price under-quotes what `buy-arns-name` then debits.
173
+ console.log(JSON.stringify({
174
+ name: params.name,
175
+ intent: params.intent,
176
+ wincTotal,
177
+ credits: creditsFromWinc(wincTotal),
178
+ nameOnlyWinc: winc,
179
+ antSpawnSurchargeWinc,
180
+ mARIO,
181
+ }, null, 2));
182
+ }
183
+ export async function arnsFiatQuote(options, turbo) {
184
+ const params = arnsPriceParamsFromOptions(options);
185
+ // `arnsPriceParamsFromOptions` substitutes PRICING_PLACEHOLDER_PROCESS_ID for
186
+ // an omitted Buy-Name `processId`, which is fine for a price lookup but NOT
187
+ // here: a quote records a real purchase, and that placeholder is not a valid
188
+ // ANT. Send `processId` only when the caller actually supplied one — omitting
189
+ // it is what tells Turbo to custodially provision the ANT.
190
+ if (options.processId === undefined) {
191
+ delete params.processId;
192
+ }
193
+ const address = options.address;
194
+ if (address === undefined) {
195
+ throw new Error('A destination --address is required for a fiat ArNS quote.');
196
+ }
197
+ const client = turbo ?? TurboFactory.unauthenticated(configFromOptions(options));
198
+ try {
199
+ const { purchaseQuote, paymentSession, adjustments, fees } = await client.getArNSFiatPurchaseQuote({
200
+ ...params,
201
+ address,
202
+ currency: (options.currency ?? 'usd'),
203
+ method: options.method,
204
+ promoCodes: options.promoCode,
205
+ });
206
+ console.log(JSON.stringify({
207
+ name: purchaseQuote.name,
208
+ intent: purchaseQuote.intent,
209
+ nonce: purchaseQuote.nonce,
210
+ paymentAmount: purchaseQuote.paymentAmount,
211
+ currency: purchaseQuote.currencyType,
212
+ quoteExpirationDate: purchaseQuote.quoteExpirationDate,
213
+ paymentSessionId: paymentSession.id,
214
+ // Present for a payment intent / embedded checkout; a hosted
215
+ // checkout session returns `url` instead.
216
+ clientSecret: paymentSession.client_secret ?? undefined,
217
+ checkoutUrl: paymentSession.url ?? undefined,
218
+ adjustments,
219
+ fees,
220
+ }, null, 2));
221
+ }
222
+ catch (error) {
223
+ if (error instanceof FiatPaymentsDisabledError) {
224
+ console.error('Fiat (Stripe) payments are disabled on this payment service. Use the credit-paid commands (buy-arns-name, extend-arns-lease, ...) instead.');
225
+ throw error;
226
+ }
227
+ throw error;
228
+ }
229
+ }
230
+ export async function buyArNSName(options, turbo) {
231
+ const name = requiredNameFromOptions(options);
232
+ const type = typeFromOptions(options.type);
233
+ const paidBy = paidByFromArNSOptions(options.paidBy);
234
+ // Every buy mints a fresh ANT straight to `--owner-key`; Turbo never holds
235
+ // it, and there is no bring-your-own-ANT path any more.
236
+ const owner = ownerFromOptions(options);
237
+ const client = turbo ?? (await turboFromOptions(options));
238
+ const result = await withCreditErrorMapping(() => type === 'lease'
239
+ ? client.buyArNSName({
240
+ name,
241
+ owner,
242
+ type: 'lease',
243
+ years: positiveIntFromOption(options.years, '--years'),
244
+ paidBy,
245
+ })
246
+ : client.buyArNSName({ name, owner, type: 'permabuy', paidBy }));
247
+ logPurchaseResult('ArNS name purchase', result);
248
+ }
249
+ export async function extendArNSLease(options, turbo) {
250
+ const name = requiredNameFromOptions(options);
251
+ const years = positiveIntFromOption(options.years, '--years');
252
+ const paidBy = paidByFromArNSOptions(options.paidBy);
253
+ const client = turbo ?? (await turboFromOptions(options));
254
+ const result = await withCreditErrorMapping(() => client.extendArNSLease({ name, years, paidBy }));
255
+ logPurchaseResult('ArNS lease extension', result);
256
+ }
257
+ export async function increaseArNSUndernames(options, turbo) {
258
+ const name = requiredNameFromOptions(options);
259
+ const increaseQty = positiveIntFromOption(options.increaseQty, '--increase-qty');
260
+ const paidBy = paidByFromArNSOptions(options.paidBy);
261
+ const client = turbo ?? (await turboFromOptions(options));
262
+ const result = await withCreditErrorMapping(() => client.increaseArNSUndernameLimit({ name, increaseQty, paidBy }));
263
+ logPurchaseResult('ArNS undername limit increase', result);
264
+ }
265
+ export async function upgradeArNSName(options, turbo) {
266
+ const name = requiredNameFromOptions(options);
267
+ const paidBy = paidByFromArNSOptions(options.paidBy);
268
+ const client = turbo ?? (await turboFromOptions(options));
269
+ const result = await withCreditErrorMapping(() => client.upgradeArNSName({ name, paidBy }));
270
+ logPurchaseResult('ArNS name upgrade (to permabuy)', result);
271
+ }
272
+ export async function arnsPurchaseStatus(options, turbo) {
273
+ if (options.nonce === undefined || options.nonce.length === 0) {
274
+ throw new Error('Must provide a --nonce to look up purchase status');
275
+ }
276
+ const client = turbo ?? TurboFactory.unauthenticated(configFromOptions(options));
277
+ const status = await client.getArNSPurchaseStatus({ nonce: options.nonce });
278
+ const state = status.failedDate !== undefined
279
+ ? 'failed'
280
+ : status.messageId
281
+ ? 'success'
282
+ : 'pending';
283
+ console.log(JSON.stringify({ state, ...status }, null, 2));
284
+ }
285
+ export async function transferArNSAnt(options, turbo) {
286
+ if (options.antId === undefined) {
287
+ throw new Error('Must provide an --ant-id to transfer');
288
+ }
289
+ if (options.target === undefined) {
290
+ throw new Error('Must provide a --target address to transfer the ANT to');
291
+ }
292
+ const client = turbo ?? (await turboFromOptions(options));
293
+ const result = await client.transferArNSAnt({
294
+ antId: options.antId,
295
+ owner: ownerFromOptions(options),
296
+ target: options.target,
297
+ });
298
+ console.log(JSON.stringify({ message: 'ANT transfer submitted!', ...result }, null, 2));
299
+ }
300
+ export async function setArNSRecord(options, turbo) {
301
+ if (options.antId === undefined) {
302
+ throw new Error('Must provide an --ant-id to set a record on');
303
+ }
304
+ if (options.transactionId === undefined) {
305
+ throw new Error('Must provide a --transaction-id for the record');
306
+ }
307
+ const ttlSeconds = positiveIntFromOption(options.ttlSeconds, '--ttl-seconds');
308
+ const client = turbo ?? (await turboFromOptions(options));
309
+ const result = await client.setArNSRecord({
310
+ antId: options.antId,
311
+ owner: ownerFromOptions(options),
312
+ undername: options.undername ?? '@',
313
+ transactionId: options.transactionId,
314
+ ttlSeconds,
315
+ });
316
+ console.log(JSON.stringify({ message: 'ArNS record set!', ...result }, null, 2));
317
+ }
318
+ export async function removeArNSRecord(options, turbo) {
319
+ if (options.antId === undefined) {
320
+ throw new Error('Must provide an --ant-id to remove a record from');
321
+ }
322
+ if (options.undername === undefined || options.undername.length === 0) {
323
+ throw new Error('Must provide an --undername to remove');
324
+ }
325
+ const client = turbo ?? (await turboFromOptions(options));
326
+ const result = await client.removeArNSRecord({
327
+ antId: options.antId,
328
+ owner: ownerFromOptions(options),
329
+ undername: options.undername,
330
+ });
331
+ console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
332
+ }
333
+ export async function addArNSController(options, turbo) {
334
+ if (options.antId === undefined) {
335
+ throw new Error('Must provide an --ant-id to add a controller to');
336
+ }
337
+ const client = turbo ?? (await turboFromOptions(options));
338
+ const result = await client.addArNSController({
339
+ antId: options.antId,
340
+ owner: ownerFromOptions(options),
341
+ target: options.target,
342
+ });
343
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
344
+ }
345
+ export async function removeArNSController(options, turbo) {
346
+ if (options.antId === undefined) {
347
+ throw new Error('Must provide an --ant-id to remove a controller from');
348
+ }
349
+ const client = turbo ?? (await turboFromOptions(options));
350
+ const result = await client.removeArNSController({
351
+ antId: options.antId,
352
+ owner: ownerFromOptions(options),
353
+ target: options.target,
354
+ });
355
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
356
+ }
357
+ export async function transferArNSRecord(options, turbo) {
358
+ if (options.antId === undefined) {
359
+ throw new Error('Must provide an --ant-id whose record to transfer');
360
+ }
361
+ if (options.undername === undefined || options.undername.length === 0) {
362
+ throw new Error('Must provide an --undername to transfer');
363
+ }
364
+ if (options.target === undefined) {
365
+ throw new Error('Must provide a --target address to transfer the record to');
366
+ }
367
+ const client = turbo ?? (await turboFromOptions(options));
368
+ const result = await client.transferArNSRecord({
369
+ antId: options.antId,
370
+ owner: ownerFromOptions(options),
371
+ undername: options.undername,
372
+ target: options.target,
373
+ });
374
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
375
+ }
376
+ export async function setArNSRecordMetadata(options, turbo) {
377
+ if (options.antId === undefined) {
378
+ throw new Error('Must provide an --ant-id to set record metadata on');
379
+ }
380
+ const client = turbo ?? (await turboFromOptions(options));
381
+ const result = await client.setArNSRecordMetadata({
382
+ antId: options.antId,
383
+ owner: ownerFromOptions(options),
384
+ undername: options.undername ?? '@',
385
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName),
386
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo),
387
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription),
388
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords),
389
+ });
390
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
391
+ }
392
+ export async function removeArNSRecordMetadata(options, turbo) {
393
+ if (options.antId === undefined) {
394
+ throw new Error('Must provide an --ant-id to remove record metadata from');
395
+ }
396
+ if (options.undername === undefined || options.undername.length === 0) {
397
+ throw new Error('Must provide an --undername');
398
+ }
399
+ const client = turbo ?? (await turboFromOptions(options));
400
+ const result = await client.removeArNSRecordMetadata({
401
+ antId: options.antId,
402
+ owner: ownerFromOptions(options),
403
+ undername: options.undername,
404
+ });
405
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
406
+ }
407
+ /**
408
+ * Preview what one of the eight non-purchase actions will debit, without
409
+ * creating it.
410
+ */
411
+ export async function arnsActionPrice(options, turbo) {
412
+ const action = actionFromOptions(options);
413
+ const client = turbo ?? TurboFactory.unauthenticated(configFromOptions(options));
414
+ const { wincQty } = await client.getArNSActionPrice(action);
415
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
416
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { TurboFactory } from '../../node/factory.js';
17
+ import { addressOrPrivateKeyFromOptions, configFromOptions } from '../utils.js';
18
+ export async function freeStatus(options) {
19
+ const config = configFromOptions(options);
20
+ const { address, privateKey } = await addressOrPrivateKeyFromOptions(options);
21
+ const { bytesRemaining, nativeAddress } = await (async () => {
22
+ if (address !== undefined) {
23
+ return {
24
+ ...(await TurboFactory.unauthenticated(config).getFreeStatus(address)),
25
+ nativeAddress: address,
26
+ };
27
+ }
28
+ if (privateKey === undefined) {
29
+ throw new Error('Must provide an (--address) or use a valid wallet');
30
+ }
31
+ const turbo = TurboFactory.authenticated({
32
+ ...config,
33
+ privateKey,
34
+ });
35
+ return {
36
+ ...(await turbo.getFreeStatus()),
37
+ nativeAddress: await turbo.signer.getNativeAddress(),
38
+ };
39
+ })();
40
+ console.log(`Turbo free-tier allowance for Native Address "${nativeAddress}"\n` +
41
+ (bytesRemaining === null
42
+ ? 'Free bytes remaining: unlimited (exempt/partner wallet)'
43
+ : `Free bytes remaining: ${bytesRemaining}`));
44
+ }
@@ -13,8 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ export * from './arns.js';
16
17
  export * from './balance.js';
17
18
  export * from './cryptoFund.js';
19
+ export * from './freeStatus.js';
20
+ export * from './paymentHistory.js';
18
21
  export * from './price.js';
19
22
  export * from './topUp.js';
20
23
  export * from './uploadFile.js';
@@ -0,0 +1,22 @@
1
+ import { turboFromOptions } from '../utils.js';
2
+ export async function paymentHistory(options) {
3
+ // Signature-required and self-scoped: a wallet is mandatory (there is no
4
+ // --address form), and the service returns only this signer's own top-ups.
5
+ const turbo = await turboFromOptions(options);
6
+ const limit = options.limit !== undefined ? +options.limit : undefined;
7
+ if (limit !== undefined &&
8
+ (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
9
+ throw new Error('--limit must be an integer between 1 and 100');
10
+ }
11
+ const { payments, hasMore, cursor } = await turbo.getPaymentHistory({
12
+ limit,
13
+ cursor: options.cursor,
14
+ });
15
+ // stdout carries only the JSON page and the next-page hint goes to stderr, so
16
+ // `... | jq` works at the default log level. (--debug intentionally routes SDK
17
+ // logs to stdout and will interleave — expected when you ask for debug output.)
18
+ console.log(JSON.stringify({ payments, hasMore, cursor }, null, 2));
19
+ if (hasMore) {
20
+ console.error(`\nMore results available — fetch the next page with --cursor ${cursor}`);
21
+ }
22
+ }