@ardrive/turbo-sdk 1.42.0 → 1.43.0-alpha.2

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 +97 -0
  2. package/lib/cjs/cli/commands/arns.js +475 -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 +202 -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 +401 -0
  10. package/lib/cjs/common/http.js +40 -6
  11. package/lib/cjs/common/index.js +7 -0
  12. package/lib/cjs/common/payment.js +548 -2
  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 +99 -2
  27. package/lib/esm/cli/commands/arns.js +450 -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 +201 -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 +396 -0
  35. package/lib/esm/common/http.js +39 -5
  36. package/lib/esm/common/index.js +7 -0
  37. package/lib/esm/common/payment.js +548 -2
  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 +147 -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 +423 -0
  60. package/lib/types/cli/options.d.ts.map +1 -1
  61. package/lib/types/cli/types.d.ts +78 -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
@@ -22,6 +22,7 @@ const arbundles_1 = require("@dha-team/arbundles");
22
22
  const commander_1 = require("commander");
23
23
  const fs_1 = require("fs");
24
24
  const version_js_1 = require("../version.js");
25
+ const arns_js_1 = require("./commands/arns.js");
25
26
  const fiatEstimate_js_1 = require("./commands/fiatEstimate.js");
26
27
  const index_js_1 = require("./commands/index.js");
27
28
  const listShares_js_1 = require("./commands/listShares.js");
@@ -39,6 +40,16 @@ const utils_js_1 = require("./utils.js");
39
40
  (0, utils_js_1.applyOptions)(commander_1.program.command('balance').description('Get balance of a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
40
41
  await (0, utils_js_1.runCommand)(command, index_js_1.balance);
41
42
  });
43
+ (0, utils_js_1.applyOptions)(commander_1.program
44
+ .command('free-status')
45
+ .description('Get the free-tier upload allowance remaining for a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
46
+ await (0, utils_js_1.runCommand)(command, index_js_1.freeStatus);
47
+ });
48
+ (0, utils_js_1.applyOptions)(commander_1.program
49
+ .command('payment-history')
50
+ .description("Get the signing wallet's own top-up (payment) history"), [...options_js_1.walletOptions, options_js_1.optionMap.limit, options_js_1.optionMap.cursor]).action(async (_commandOptions, command) => {
51
+ await (0, utils_js_1.runCommand)(command, index_js_1.paymentHistory);
52
+ });
42
53
  (0, utils_js_1.applyOptions)(commander_1.program.command('top-up').description('Top up a Turbo address with Fiat'), [...options_js_1.walletOptions, options_js_1.optionMap.address, options_js_1.optionMap.value, options_js_1.optionMap.currency]).action(async (_commandOptions, command) => {
43
54
  await (0, utils_js_1.runCommand)(command, index_js_1.topUp);
44
55
  });
@@ -86,6 +97,92 @@ const utils_js_1 = require("./utils.js");
86
97
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), options_js_1.listSharesOptions).action(async (_commandOptions, command) => {
87
98
  await (0, utils_js_1.runCommand)(command, listShares_js_1.listShares);
88
99
  });
100
+ (0, utils_js_1.applyOptions)(commander_1.program
101
+ .command('arns-price')
102
+ .description('Get the Turbo Credit (winc + mARIO) price to buy, extend, increase undernames, or upgrade an ArNS name'), options_js_1.arnsPriceOptions).action(async (_commandOptions, command) => {
103
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsPrice);
104
+ });
105
+ (0, utils_js_1.applyOptions)(commander_1.program
106
+ .command('arns-fiat-quote')
107
+ .description('Quote an ArNS purchase paid by credit card (Stripe) - no credits needed'), options_js_1.arnsFiatQuoteOptions).action(async (_commandOptions, command) => {
108
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsFiatQuote);
109
+ });
110
+ (0, utils_js_1.applyOptions)(commander_1.program
111
+ .command('buy-arns-name')
112
+ .description('Buy an ArNS name (lease or permabuy) with Turbo Credits'), options_js_1.buyArNSNameOptions).action(async (_commandOptions, command) => {
113
+ await (0, utils_js_1.runCommand)(command, arns_js_1.buyArNSName);
114
+ });
115
+ (0, utils_js_1.applyOptions)(commander_1.program
116
+ .command('extend-arns-lease')
117
+ .description('Extend an ArNS name lease with Turbo Credits'), options_js_1.extendArNSLeaseOptions).action(async (_commandOptions, command) => {
118
+ await (0, utils_js_1.runCommand)(command, arns_js_1.extendArNSLease);
119
+ });
120
+ (0, utils_js_1.applyOptions)(commander_1.program
121
+ .command('increase-arns-undernames')
122
+ .description('Increase the undername limit of an ArNS name with Turbo Credits'), options_js_1.increaseArNSUndernamesOptions).action(async (_commandOptions, command) => {
123
+ await (0, utils_js_1.runCommand)(command, arns_js_1.increaseArNSUndernames);
124
+ });
125
+ (0, utils_js_1.applyOptions)(commander_1.program
126
+ .command('upgrade-arns-name')
127
+ .description('Upgrade an ArNS leased name to a permabuy with Turbo Credits'), options_js_1.upgradeArNSNameOptions).action(async (_commandOptions, command) => {
128
+ await (0, utils_js_1.runCommand)(command, arns_js_1.upgradeArNSName);
129
+ });
130
+ (0, utils_js_1.applyOptions)(commander_1.program
131
+ .command('arns-purchase-status')
132
+ .description('Get the status of an ArNS purchase by its nonce'), options_js_1.arnsPurchaseStatusOptions).action(async (_commandOptions, command) => {
133
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsPurchaseStatus);
134
+ });
135
+ (0, utils_js_1.applyOptions)(commander_1.program
136
+ .command('arns-action-status')
137
+ .description('Get the status of a credit-paid ArNS action by its nonce (buy, extend, upgrade, and the non-purchase actions)'), options_js_1.arnsActionStatusOptions).action(async (_commandOptions, command) => {
138
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsActionStatus);
139
+ });
140
+ (0, utils_js_1.applyOptions)(commander_1.program
141
+ .command('transfer-arns-ant')
142
+ .description('Transfer a Turbo-custodied ANT to a Solana pubkey you control'), options_js_1.transferArNSAntOptions).action(async (_commandOptions, command) => {
143
+ await (0, utils_js_1.runCommand)(command, arns_js_1.transferArNSAnt);
144
+ });
145
+ (0, utils_js_1.applyOptions)(commander_1.program
146
+ .command('set-arns-record')
147
+ .description('Set a resolution record on a Turbo-custodied ANT'), options_js_1.setArNSRecordOptions).action(async (_commandOptions, command) => {
148
+ await (0, utils_js_1.runCommand)(command, arns_js_1.setArNSRecord);
149
+ });
150
+ (0, utils_js_1.applyOptions)(commander_1.program
151
+ .command('remove-arns-record')
152
+ .description('Remove a resolution record (undername) from a Turbo-custodied ANT'), options_js_1.removeArNSRecordOptions).action(async (_commandOptions, command) => {
153
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecord);
154
+ });
155
+ (0, utils_js_1.applyOptions)(commander_1.program
156
+ .command('add-arns-controller')
157
+ .description('Grant controller rights on a Turbo-custodied ANT'), options_js_1.addArNSControllerOptions).action(async (_commandOptions, command) => {
158
+ await (0, utils_js_1.runCommand)(command, arns_js_1.addArNSController);
159
+ });
160
+ (0, utils_js_1.applyOptions)(commander_1.program
161
+ .command('remove-arns-controller')
162
+ .description('Revoke controller rights on a Turbo-custodied ANT'), options_js_1.removeArNSControllerOptions).action(async (_commandOptions, command) => {
163
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSController);
164
+ });
165
+ (0, utils_js_1.applyOptions)(commander_1.program
166
+ .command('transfer-arns-record')
167
+ .description('Transfer one record (undername) on a Turbo-custodied ANT to another address'), options_js_1.transferArNSRecordOptions).action(async (_commandOptions, command) => {
168
+ await (0, utils_js_1.runCommand)(command, arns_js_1.transferArNSRecord);
169
+ });
170
+ (0, utils_js_1.applyOptions)(commander_1.program
171
+ .command('set-arns-record-metadata')
172
+ .description("Set a record's display name, logo, description, or keywords on a Turbo-custodied ANT"), options_js_1.setArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
173
+ await (0, utils_js_1.runCommand)(command, arns_js_1.setArNSRecordMetadata);
174
+ });
175
+ (0, utils_js_1.applyOptions)(commander_1.program
176
+ .command('remove-arns-record-metadata')
177
+ .description("Clear a record's metadata on a Turbo-custodied ANT"), options_js_1.removeArNSRecordMetadataOptions).action(async (_commandOptions, command) => {
178
+ await (0, utils_js_1.runCommand)(command, arns_js_1.removeArNSRecordMetadata);
179
+ });
180
+ (0, utils_js_1.applyOptions)(commander_1.program
181
+ .command('arns-action-price')
182
+ .description('Preview the Turbo Credit price of a non-purchase ArNS action (set-record, remove-record, ' +
183
+ 'set-record-metadata, remove-record-metadata, transfer-record, add-controller, remove-controller, transfer)'), options_js_1.arnsActionPriceOptions).action(async (_commandOptions, command) => {
184
+ await (0, utils_js_1.runCommand)(command, arns_js_1.arnsActionPrice);
185
+ });
89
186
  (0, utils_js_1.applyOptions)(commander_1.program
90
187
  .command('inspect-data-items')
91
188
  .description('Lists all given or received Turbo credit share approvals for specified address or connected wallet'), [options_js_1.optionMap.folderPath]).action(async (_commandOptions, command) => {
@@ -0,0 +1,475 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiredNameFromOptions = requiredNameFromOptions;
4
+ exports.positiveIntFromOption = positiveIntFromOption;
5
+ exports.typeFromOptions = typeFromOptions;
6
+ exports.actionFromOptions = actionFromOptions;
7
+ exports.paidByFromArNSOptions = paidByFromArNSOptions;
8
+ exports.arnsPriceParamsFromOptions = arnsPriceParamsFromOptions;
9
+ exports.arnsPrice = arnsPrice;
10
+ exports.arnsFiatQuote = arnsFiatQuote;
11
+ exports.buyArNSName = buyArNSName;
12
+ exports.extendArNSLease = extendArNSLease;
13
+ exports.increaseArNSUndernames = increaseArNSUndernames;
14
+ exports.upgradeArNSName = upgradeArNSName;
15
+ exports.arnsPurchaseStatus = arnsPurchaseStatus;
16
+ exports.arnsActionStatus = arnsActionStatus;
17
+ exports.transferArNSAnt = transferArNSAnt;
18
+ exports.setArNSRecord = setArNSRecord;
19
+ exports.removeArNSRecord = removeArNSRecord;
20
+ exports.addArNSController = addArNSController;
21
+ exports.removeArNSController = removeArNSController;
22
+ exports.transferArNSRecord = transferArNSRecord;
23
+ exports.setArNSRecordMetadata = setArNSRecordMetadata;
24
+ exports.removeArNSRecordMetadata = removeArNSRecordMetadata;
25
+ exports.arnsActionPrice = arnsActionPrice;
26
+ /**
27
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
28
+ *
29
+ * Licensed under the Apache License, Version 2.0 (the "License");
30
+ * you may not use this file except in compliance with the License.
31
+ * You may obtain a copy of the License at
32
+ *
33
+ * http://www.apache.org/licenses/LICENSE-2.0
34
+ *
35
+ * Unless required by applicable law or agreed to in writing, software
36
+ * distributed under the License is distributed on an "AS IS" BASIS,
37
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ * See the License for the specific language governing permissions and
39
+ * limitations under the License.
40
+ */
41
+ const bignumber_js_1 = require("bignumber.js");
42
+ const arnsActions_js_1 = require("../../common/arnsActions.js");
43
+ const factory_js_1 = require("../../node/factory.js");
44
+ const types_js_1 = require("../../types.js");
45
+ const errors_js_1 = require("../../utils/errors.js");
46
+ const constants_js_1 = require("../constants.js");
47
+ const utils_js_1 = require("../utils.js");
48
+ /**
49
+ * The ANT owner's Solana key.
50
+ *
51
+ * Deliberately separate from the wallet that pays: the payer holds Turbo
52
+ * credits (and may be Arweave or Ethereum), while the owner holds the ANT and
53
+ * must be Solana. The owner needs a key to SIGN with, not a funded account —
54
+ * Turbo is the fee payer on every sponsored action.
55
+ */
56
+ function ownerFromOptions(options) {
57
+ if (options.ownerKey === undefined || options.ownerKey === '') {
58
+ throw new Error('Must provide --owner-key (a base58 Solana secret key) — it owns the ANT and signs for it. ' +
59
+ 'This is separate from the wallet paying in Turbo Credits.');
60
+ }
61
+ return (0, arnsActions_js_1.solanaOwnerSigner)(options.ownerKey);
62
+ }
63
+ /** The four ARIO-purchase actions are priced via `arnsPrice`, not this route. */
64
+ const ARNS_PURCHASE_ACTIONS = new Set([
65
+ 'buy-name',
66
+ 'extend-lease',
67
+ 'upgrade-name',
68
+ 'increase-undername-limit',
69
+ ]);
70
+ function requiredNameFromOptions(options) {
71
+ if (options.name === undefined || options.name.length === 0) {
72
+ throw new Error('Must provide an ArNS --name');
73
+ }
74
+ return options.name;
75
+ }
76
+ function positiveIntFromOption(value, flag) {
77
+ if (value === undefined) {
78
+ throw new Error(`Must provide ${flag}`);
79
+ }
80
+ const num = +value;
81
+ if (!Number.isFinite(num) || !Number.isInteger(num) || num <= 0) {
82
+ throw new Error(`${flag} must be a positive integer`);
83
+ }
84
+ return num;
85
+ }
86
+ function typeFromOptions(value) {
87
+ if (value !== 'lease' && value !== 'permabuy') {
88
+ throw new Error("Must provide --type of 'lease' or 'permabuy'");
89
+ }
90
+ return value;
91
+ }
92
+ /** Parses `--action` for `arns-action-price`, rejecting the four purchase actions. */
93
+ function actionFromOptions(options) {
94
+ const { action } = options;
95
+ if (action === undefined || action.length === 0) {
96
+ throw new Error(`Must provide --action. One of: ${types_js_1.arNSActions.join(', ')}`);
97
+ }
98
+ if (!types_js_1.arNSActions.includes(action)) {
99
+ throw new Error(`Invalid --action '${action}'. One of: ${types_js_1.arNSActions.join(', ')}`);
100
+ }
101
+ if (ARNS_PURCHASE_ACTIONS.has(action)) {
102
+ throw new Error(`'${action}' is priced via \`turbo arns-price\`, not \`arns-action-price\` — ` +
103
+ 'it spends ARIO, not just the flat credits margin this route quotes.');
104
+ }
105
+ return action;
106
+ }
107
+ /** `null` clears the field (Set-Record-Metadata's tri-state), `undefined` leaves it unchanged. */
108
+ function metadataFieldFromOptions(value, clear, flag) {
109
+ // Commander registers each value flag and its --clear-* partner separately, so
110
+ // it accepts both. Silently letting the clear win would discard a value the
111
+ // caller explicitly passed.
112
+ if (clear && value !== undefined) {
113
+ throw new Error(`Cannot pass both --${flag} and --clear-${flag}. Pass one: the value to set it, or the clear flag to unset it.`);
114
+ }
115
+ return clear ? null : value;
116
+ }
117
+ function paidByFromArNSOptions(paidBy) {
118
+ return paidBy !== undefined && paidBy.length > 0 ? paidBy : undefined;
119
+ }
120
+ // A price quote depends only on the name (length), type, and years — NOT on the
121
+ // ANT the name will resolve to. The service ignores `processId` for pricing, but
122
+ // the SDK's Buy-Name validation still requires a non-empty one, so we substitute
123
+ // this obvious placeholder when the user omits `--process-id` from `arns-price`.
124
+ // (`buy-arns-name` still requires a real `--process-id`.)
125
+ const PRICING_PLACEHOLDER_PROCESS_ID = 'pricing-only-no-process-id';
126
+ /**
127
+ * Infer the ArNS pricing intent from the provided flags:
128
+ * - `--type` present -> Buy-Name (lease needs --years; --process-id optional for pricing)
129
+ * - `--increase-qty` present -> Increase-Undername-Limit
130
+ * - `--years` present (no type) -> Extend-Lease
131
+ * - otherwise -> Upgrade-Name
132
+ */
133
+ function arnsPriceParamsFromOptions(options) {
134
+ const name = requiredNameFromOptions(options);
135
+ if (options.type !== undefined) {
136
+ const type = typeFromOptions(options.type);
137
+ const processId = options.processId ?? PRICING_PLACEHOLDER_PROCESS_ID;
138
+ if (type === 'lease') {
139
+ return {
140
+ intent: 'Buy-Name',
141
+ name,
142
+ type: 'lease',
143
+ years: positiveIntFromOption(options.years, '--years'),
144
+ processId,
145
+ };
146
+ }
147
+ return {
148
+ intent: 'Buy-Name',
149
+ name,
150
+ type: 'permabuy',
151
+ processId,
152
+ };
153
+ }
154
+ if (options.increaseQty !== undefined) {
155
+ return {
156
+ intent: 'Increase-Undername-Limit',
157
+ name,
158
+ increaseQty: positiveIntFromOption(options.increaseQty, '--increase-qty'),
159
+ };
160
+ }
161
+ if (options.years !== undefined) {
162
+ return {
163
+ intent: 'Extend-Lease',
164
+ name,
165
+ years: positiveIntFromOption(options.years, '--years'),
166
+ };
167
+ }
168
+ return { intent: 'Upgrade-Name', name };
169
+ }
170
+ function creditsFromWinc(winc) {
171
+ return new bignumber_js_1.BigNumber(winc).dividedBy(constants_js_1.wincPerCredit).toFixed(12);
172
+ }
173
+ /** Rethrow a 402 as a clear, actionable "top up" message. */
174
+ /**
175
+ * Takes the promise rather than a thunk: wrapping the call in a closure would
176
+ * discard the `undefined` narrowing each handler's guard clauses establish.
177
+ */
178
+ async function withCreditErrorMapping(promise) {
179
+ try {
180
+ return await promise;
181
+ }
182
+ catch (error) {
183
+ if (error instanceof errors_js_1.InsufficientCreditsError) {
184
+ throw new Error('Insufficient Turbo credits to complete this ArNS action. ' +
185
+ 'Top up your balance (e.g. `turbo top-up` or `turbo crypto-fund`) and retry.');
186
+ }
187
+ throw error;
188
+ }
189
+ }
190
+ function logPurchaseResult(action, result) {
191
+ console.log(JSON.stringify({
192
+ message: `${action} completed!`,
193
+ nonce: result.nonce,
194
+ antId: result.antId,
195
+ // Solana transaction id of the on-chain write.
196
+ messageId: result.messageId,
197
+ ...(result.alreadyCompleted === true ? { alreadyCompleted: true } : {}),
198
+ }, null, 2));
199
+ // Credit-paid buys go through the actions API, so the nonce lives in the
200
+ // action namespace. `arns-purchase-status` reads `/arns/purchase/`, a
201
+ // separate namespace that answers "Purchase status not found" for this nonce.
202
+ console.log(`\nTrack this with:\n turbo arns-action-status --nonce ${result.nonce}`);
203
+ }
204
+ async function arnsPrice(options, turbo) {
205
+ const params = arnsPriceParamsFromOptions(options);
206
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
207
+ const { winc, wincTotal, antSpawnSurchargeWinc, mARIO } = await client.getArNSPriceForName(params);
208
+ // `wincTotal` is the figure to pay. `winc` is the name only and excludes the
209
+ // ANT spawn surcharge, which for a Buy-Name can exceed the name's own price,
210
+ // so printing it as the price under-quotes what `buy-arns-name` then debits.
211
+ console.log(JSON.stringify({
212
+ name: params.name,
213
+ intent: params.intent,
214
+ wincTotal,
215
+ credits: creditsFromWinc(wincTotal),
216
+ nameOnlyWinc: winc,
217
+ antSpawnSurchargeWinc,
218
+ mARIO,
219
+ }, null, 2));
220
+ }
221
+ async function arnsFiatQuote(options, turbo) {
222
+ const params = arnsPriceParamsFromOptions(options);
223
+ // `arnsPriceParamsFromOptions` substitutes PRICING_PLACEHOLDER_PROCESS_ID for
224
+ // an omitted Buy-Name `processId`, which is fine for a price lookup but NOT
225
+ // here: a quote records a real purchase, and that placeholder is not a valid
226
+ // ANT. Send `processId` only when the caller actually supplied one — omitting
227
+ // it is what tells Turbo to custodially provision the ANT.
228
+ if (options.processId === undefined) {
229
+ delete params.processId;
230
+ }
231
+ const address = options.address;
232
+ if (address === undefined) {
233
+ throw new Error('A destination --address is required for a fiat ArNS quote.');
234
+ }
235
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
236
+ try {
237
+ const { purchaseQuote, paymentSession, adjustments, fees } = await client.getArNSFiatPurchaseQuote({
238
+ ...params,
239
+ address,
240
+ currency: (options.currency ?? 'usd'),
241
+ method: options.method,
242
+ promoCodes: options.promoCode,
243
+ });
244
+ console.log(JSON.stringify({
245
+ name: purchaseQuote.name,
246
+ intent: purchaseQuote.intent,
247
+ nonce: purchaseQuote.nonce,
248
+ paymentAmount: purchaseQuote.paymentAmount,
249
+ currency: purchaseQuote.currencyType,
250
+ quoteExpirationDate: purchaseQuote.quoteExpirationDate,
251
+ paymentSessionId: paymentSession.id,
252
+ // Present for a payment intent / embedded checkout; a hosted
253
+ // checkout session returns `url` instead.
254
+ clientSecret: paymentSession.client_secret ?? undefined,
255
+ checkoutUrl: paymentSession.url ?? undefined,
256
+ adjustments,
257
+ fees,
258
+ }, null, 2));
259
+ }
260
+ catch (error) {
261
+ if (error instanceof errors_js_1.FiatPaymentsDisabledError) {
262
+ console.error('Fiat (Stripe) payments are disabled on this payment service. Use the credit-paid commands (buy-arns-name, extend-arns-lease, ...) instead.');
263
+ throw error;
264
+ }
265
+ throw error;
266
+ }
267
+ }
268
+ async function buyArNSName(options, turbo) {
269
+ const name = requiredNameFromOptions(options);
270
+ const type = typeFromOptions(options.type);
271
+ const paidBy = paidByFromArNSOptions(options.paidBy);
272
+ // Every buy mints a fresh ANT straight to `--owner-key`; Turbo never holds
273
+ // it, and there is no bring-your-own-ANT path any more.
274
+ const owner = ownerFromOptions(options);
275
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
276
+ const result = await withCreditErrorMapping(type === 'lease'
277
+ ? client.buyArNSName({
278
+ name,
279
+ owner,
280
+ type: 'lease',
281
+ years: positiveIntFromOption(options.years, '--years'),
282
+ paidBy,
283
+ })
284
+ : client.buyArNSName({ name, owner, type: 'permabuy', paidBy }));
285
+ logPurchaseResult('ArNS name purchase', result);
286
+ }
287
+ async function extendArNSLease(options, turbo) {
288
+ const name = requiredNameFromOptions(options);
289
+ const years = positiveIntFromOption(options.years, '--years');
290
+ const paidBy = paidByFromArNSOptions(options.paidBy);
291
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
292
+ const result = await withCreditErrorMapping(client.extendArNSLease({ name, years, paidBy }));
293
+ logPurchaseResult('ArNS lease extension', result);
294
+ }
295
+ async function increaseArNSUndernames(options, turbo) {
296
+ const name = requiredNameFromOptions(options);
297
+ const increaseQty = positiveIntFromOption(options.increaseQty, '--increase-qty');
298
+ const paidBy = paidByFromArNSOptions(options.paidBy);
299
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
300
+ const result = await withCreditErrorMapping(client.increaseArNSUndernameLimit({ name, increaseQty, paidBy }));
301
+ logPurchaseResult('ArNS undername limit increase', result);
302
+ }
303
+ async function upgradeArNSName(options, turbo) {
304
+ const name = requiredNameFromOptions(options);
305
+ const paidBy = paidByFromArNSOptions(options.paidBy);
306
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
307
+ const result = await withCreditErrorMapping(client.upgradeArNSName({ name, paidBy }));
308
+ logPurchaseResult('ArNS name upgrade (to permabuy)', result);
309
+ }
310
+ async function arnsPurchaseStatus(options, turbo) {
311
+ if (options.nonce === undefined || options.nonce.length === 0) {
312
+ throw new Error('Must provide a --nonce to look up purchase status');
313
+ }
314
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
315
+ const status = await client.getArNSPurchaseStatus({ nonce: options.nonce });
316
+ const state = status.failedDate !== undefined
317
+ ? 'failed'
318
+ : status.messageId
319
+ ? 'success'
320
+ : 'pending';
321
+ console.log(JSON.stringify({ state, ...status }, null, 2));
322
+ }
323
+ /**
324
+ * Status of a credit-paid ArNS action (buy, extend, upgrade, increase, and the
325
+ * eight non-purchase actions). Distinct from `arns-purchase-status`, which
326
+ * reads the `/arns/purchase/` namespace that fiat quotes land in.
327
+ *
328
+ * Authenticated because `getArNSActionStatus` lives on the authenticated
329
+ * client, though the route itself needs no signature.
330
+ */
331
+ async function arnsActionStatus(options, turbo) {
332
+ if (options.nonce === undefined || options.nonce.length === 0) {
333
+ throw new Error('Must provide a --nonce to look up action status');
334
+ }
335
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
336
+ const status = await client.getArNSActionStatus(options.nonce);
337
+ const state = status.failedDate !== undefined
338
+ ? 'failed'
339
+ : status.messageId
340
+ ? 'success'
341
+ : 'pending';
342
+ console.log(JSON.stringify({ state, ...status }, null, 2));
343
+ }
344
+ async function transferArNSAnt(options, turbo) {
345
+ if (options.antId === undefined) {
346
+ throw new Error('Must provide an --ant-id to transfer');
347
+ }
348
+ if (options.target === undefined) {
349
+ throw new Error('Must provide a --target address to transfer the ANT to');
350
+ }
351
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
352
+ const result = await withCreditErrorMapping(client.transferArNSAnt({
353
+ antId: options.antId,
354
+ owner: ownerFromOptions(options),
355
+ target: options.target,
356
+ }));
357
+ console.log(JSON.stringify({ message: 'ANT transfer submitted!', ...result }, null, 2));
358
+ }
359
+ async function setArNSRecord(options, turbo) {
360
+ if (options.antId === undefined) {
361
+ throw new Error('Must provide an --ant-id to set a record on');
362
+ }
363
+ if (options.transactionId === undefined) {
364
+ throw new Error('Must provide a --transaction-id for the record');
365
+ }
366
+ const ttlSeconds = positiveIntFromOption(options.ttlSeconds, '--ttl-seconds');
367
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
368
+ const result = await withCreditErrorMapping(client.setArNSRecord({
369
+ antId: options.antId,
370
+ owner: ownerFromOptions(options),
371
+ undername: options.undername ?? '@',
372
+ transactionId: options.transactionId,
373
+ ttlSeconds,
374
+ }));
375
+ console.log(JSON.stringify({ message: 'ArNS record set!', ...result }, null, 2));
376
+ }
377
+ async function removeArNSRecord(options, turbo) {
378
+ if (options.antId === undefined) {
379
+ throw new Error('Must provide an --ant-id to remove a record from');
380
+ }
381
+ if (options.undername === undefined || options.undername.length === 0) {
382
+ throw new Error('Must provide an --undername to remove');
383
+ }
384
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
385
+ const result = await withCreditErrorMapping(client.removeArNSRecord({
386
+ antId: options.antId,
387
+ owner: ownerFromOptions(options),
388
+ undername: options.undername,
389
+ }));
390
+ console.log(JSON.stringify({ message: 'ArNS record removed!', ...result }, null, 2));
391
+ }
392
+ async function addArNSController(options, turbo) {
393
+ if (options.antId === undefined) {
394
+ throw new Error('Must provide an --ant-id to add a controller to');
395
+ }
396
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
397
+ const result = await withCreditErrorMapping(client.addArNSController({
398
+ antId: options.antId,
399
+ owner: ownerFromOptions(options),
400
+ target: options.target,
401
+ }));
402
+ console.log(JSON.stringify({ message: 'ArNS controller added!', ...result }, null, 2));
403
+ }
404
+ async function removeArNSController(options, turbo) {
405
+ if (options.antId === undefined) {
406
+ throw new Error('Must provide an --ant-id to remove a controller from');
407
+ }
408
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
409
+ const result = await withCreditErrorMapping(client.removeArNSController({
410
+ antId: options.antId,
411
+ owner: ownerFromOptions(options),
412
+ target: options.target,
413
+ }));
414
+ console.log(JSON.stringify({ message: 'ArNS controller removed!', ...result }, null, 2));
415
+ }
416
+ async function transferArNSRecord(options, turbo) {
417
+ if (options.antId === undefined) {
418
+ throw new Error('Must provide an --ant-id whose record to transfer');
419
+ }
420
+ if (options.undername === undefined || options.undername.length === 0) {
421
+ throw new Error('Must provide an --undername to transfer');
422
+ }
423
+ if (options.target === undefined) {
424
+ throw new Error('Must provide a --target address to transfer the record to');
425
+ }
426
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
427
+ const result = await withCreditErrorMapping(client.transferArNSRecord({
428
+ antId: options.antId,
429
+ owner: ownerFromOptions(options),
430
+ undername: options.undername,
431
+ target: options.target,
432
+ }));
433
+ console.log(JSON.stringify({ message: 'ArNS record transferred!', ...result }, null, 2));
434
+ }
435
+ async function setArNSRecordMetadata(options, turbo) {
436
+ if (options.antId === undefined) {
437
+ throw new Error('Must provide an --ant-id to set record metadata on');
438
+ }
439
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
440
+ const result = await withCreditErrorMapping(client.setArNSRecordMetadata({
441
+ antId: options.antId,
442
+ owner: ownerFromOptions(options),
443
+ undername: options.undername ?? '@',
444
+ displayName: metadataFieldFromOptions(options.displayName, options.clearDisplayName, 'display-name'),
445
+ recordLogo: metadataFieldFromOptions(options.recordLogo, options.clearRecordLogo, 'record-logo'),
446
+ recordDescription: metadataFieldFromOptions(options.recordDescription, options.clearRecordDescription, 'record-description'),
447
+ recordKeywords: metadataFieldFromOptions(options.recordKeywords, options.clearRecordKeywords, 'record-keywords'),
448
+ }));
449
+ console.log(JSON.stringify({ message: 'ArNS record metadata set!', ...result }, null, 2));
450
+ }
451
+ async function removeArNSRecordMetadata(options, turbo) {
452
+ if (options.antId === undefined) {
453
+ throw new Error('Must provide an --ant-id to remove record metadata from');
454
+ }
455
+ if (options.undername === undefined || options.undername.length === 0) {
456
+ throw new Error('Must provide an --undername');
457
+ }
458
+ const client = turbo ?? (await (0, utils_js_1.turboFromOptions)(options));
459
+ const result = await withCreditErrorMapping(client.removeArNSRecordMetadata({
460
+ antId: options.antId,
461
+ owner: ownerFromOptions(options),
462
+ undername: options.undername,
463
+ }));
464
+ console.log(JSON.stringify({ message: 'ArNS record metadata removed!', ...result }, null, 2));
465
+ }
466
+ /**
467
+ * Preview what one of the eight non-purchase actions will debit, without
468
+ * creating it.
469
+ */
470
+ async function arnsActionPrice(options, turbo) {
471
+ const action = actionFromOptions(options);
472
+ const client = turbo ?? factory_js_1.TurboFactory.unauthenticated((0, utils_js_1.configFromOptions)(options));
473
+ const { wincQty } = await client.getArNSActionPrice(action);
474
+ console.log(JSON.stringify({ action, wincQty, credits: creditsFromWinc(wincQty) }, null, 2));
475
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.freeStatus = freeStatus;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const factory_js_1 = require("../../node/factory.js");
20
+ const utils_js_1 = require("../utils.js");
21
+ async function freeStatus(options) {
22
+ const config = (0, utils_js_1.configFromOptions)(options);
23
+ const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
24
+ const { bytesRemaining, nativeAddress } = await (async () => {
25
+ if (address !== undefined) {
26
+ return {
27
+ ...(await factory_js_1.TurboFactory.unauthenticated(config).getFreeStatus(address)),
28
+ nativeAddress: address,
29
+ };
30
+ }
31
+ if (privateKey === undefined) {
32
+ throw new Error('Must provide an (--address) or use a valid wallet');
33
+ }
34
+ const turbo = factory_js_1.TurboFactory.authenticated({
35
+ ...config,
36
+ privateKey,
37
+ });
38
+ return {
39
+ ...(await turbo.getFreeStatus()),
40
+ nativeAddress: await turbo.signer.getNativeAddress(),
41
+ };
42
+ })();
43
+ console.log(`Turbo free-tier allowance for Native Address "${nativeAddress}"\n` +
44
+ (bytesRemaining === null
45
+ ? 'Free bytes remaining: unlimited (exempt/partner wallet)'
46
+ : `Free bytes remaining: ${bytesRemaining}`));
47
+ }
@@ -29,8 +29,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./arns.js"), exports);
32
33
  __exportStar(require("./balance.js"), exports);
33
34
  __exportStar(require("./cryptoFund.js"), exports);
35
+ __exportStar(require("./freeStatus.js"), exports);
36
+ __exportStar(require("./paymentHistory.js"), exports);
34
37
  __exportStar(require("./price.js"), exports);
35
38
  __exportStar(require("./topUp.js"), exports);
36
39
  __exportStar(require("./uploadFile.js"), exports);