@namefi/api-client 0.0.0-pre.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.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Namefi Client
2
+
3
+ API client for Namefi.
4
+
5
+ > This package is still in alpha. APIs and behavior may change without notice.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [Authentication](#authentication)
12
+ - [Contract](#contract)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @namefi-astra/client
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { createNamefiClient } from '@namefi-astra/client';
24
+
25
+ const client = createNamefiClient({
26
+ authentication: {
27
+ apiKey: process.env.NAMEFI_API_KEY ?? '',
28
+ type: 'API_KEY',
29
+ },
30
+ logger: true,
31
+ });
32
+
33
+ const domain = 'example.com';
34
+ const result = await client.search.checkAvailability({ domain });
35
+
36
+ if (result.availability) {
37
+ const order = await client.orders.registerDomain({
38
+ normalizedDomainName: domain,
39
+ durationInYears: 1,
40
+ });
41
+
42
+ console.log('Registered', order.id);
43
+ }
44
+ ```
45
+
46
+ ## Authentication
47
+
48
+ Provide an API key through the `authentication` option when creating the client.
49
+
50
+ ## Contract
51
+
52
+ The client is generated against the bundled `contract.json` OpenAPI contract, which defines the available routes and shapes.
package/contract.json ADDED
@@ -0,0 +1,449 @@
1
+ {
2
+ "dnsRecords": {
3
+ "getRecords": {
4
+ "~orpc": {
5
+ "errorMap": {},
6
+ "meta": {
7
+ "route": {
8
+ "path": "/dns/records",
9
+ "method": "GET",
10
+ "tags": ["dns"],
11
+ "operationId": "getDnsRecords",
12
+ "summary": "Get DNS records",
13
+ "description": "Retrieve all DNS records for a specified domain zone. Returns an array of DNS records including A, AAAA, CNAME, MX, TXT, and other record types."
14
+ }
15
+ },
16
+ "route": {
17
+ "path": "/dns/records",
18
+ "method": "GET",
19
+ "tags": ["dns"],
20
+ "operationId": "getDnsRecords",
21
+ "summary": "Get DNS records",
22
+ "description": "Retrieve all DNS records for a specified domain zone. Returns an array of DNS records including A, AAAA, CNAME, MX, TXT, and other record types."
23
+ }
24
+ }
25
+ },
26
+ "createDnsRecord": {
27
+ "~orpc": {
28
+ "errorMap": {},
29
+ "meta": {
30
+ "route": {
31
+ "path": "/dns/records",
32
+ "method": "POST",
33
+ "tags": ["dns"],
34
+ "operationId": "createDnsRecord",
35
+ "summary": "Create DNS record",
36
+ "description": "Create a new DNS record for a domain. Requires domain ownership. The record will be validated against DNS zone rules before creation."
37
+ }
38
+ },
39
+ "route": {
40
+ "path": "/dns/records",
41
+ "method": "POST",
42
+ "tags": ["dns"],
43
+ "operationId": "createDnsRecord",
44
+ "summary": "Create DNS record",
45
+ "description": "Create a new DNS record for a domain. Requires domain ownership. The record will be validated against DNS zone rules before creation."
46
+ }
47
+ }
48
+ },
49
+ "updateRecord": {
50
+ "~orpc": {
51
+ "errorMap": {},
52
+ "meta": {
53
+ "route": {
54
+ "path": "/dns/records/{id}",
55
+ "method": "PUT",
56
+ "tags": ["dns"],
57
+ "operationId": "updateDnsRecord",
58
+ "summary": "Update DNS record",
59
+ "description": "Update an existing DNS record by its ID. Requires domain ownership. The updated record will be validated against DNS zone rules."
60
+ }
61
+ },
62
+ "route": {
63
+ "path": "/dns/records/{id}",
64
+ "method": "PUT",
65
+ "tags": ["dns"],
66
+ "operationId": "updateDnsRecord",
67
+ "summary": "Update DNS record",
68
+ "description": "Update an existing DNS record by its ID. Requires domain ownership. The updated record will be validated against DNS zone rules."
69
+ }
70
+ }
71
+ },
72
+ "deleteRecord": {
73
+ "~orpc": {
74
+ "errorMap": {},
75
+ "meta": {
76
+ "route": {
77
+ "path": "/dns/records/{id}",
78
+ "method": "DELETE",
79
+ "tags": ["dns"],
80
+ "operationId": "deleteDnsRecord",
81
+ "summary": "Delete DNS record",
82
+ "description": "Delete a DNS record by its ID. Requires domain ownership. The deletion will be validated to ensure zone integrity."
83
+ }
84
+ },
85
+ "route": {
86
+ "path": "/dns/records/{id}",
87
+ "method": "DELETE",
88
+ "tags": ["dns"],
89
+ "operationId": "deleteDnsRecord",
90
+ "summary": "Delete DNS record",
91
+ "description": "Delete a DNS record by its ID. Requires domain ownership. The deletion will be validated to ensure zone integrity."
92
+ }
93
+ }
94
+ },
95
+ "updateRecords": {
96
+ "~orpc": {
97
+ "errorMap": {},
98
+ "meta": {
99
+ "route": {
100
+ "path": "/dns/records/batch",
101
+ "method": "PUT",
102
+ "tags": ["dns"],
103
+ "operationId": "batchUpdateDnsRecords",
104
+ "summary": "Batch update DNS records",
105
+ "description": "Update multiple DNS records in a single transaction. Requires domain ownership. All records must belong to the same zone and will be validated together."
106
+ }
107
+ },
108
+ "route": {
109
+ "path": "/dns/records/batch",
110
+ "method": "PUT",
111
+ "tags": ["dns"],
112
+ "operationId": "batchUpdateDnsRecords",
113
+ "summary": "Batch update DNS records",
114
+ "description": "Update multiple DNS records in a single transaction. Requires domain ownership. All records must belong to the same zone and will be validated together."
115
+ }
116
+ }
117
+ },
118
+ "createRecords": {
119
+ "~orpc": {
120
+ "errorMap": {},
121
+ "meta": {
122
+ "route": {
123
+ "path": "/dns/records/batch",
124
+ "method": "POST",
125
+ "tags": ["dns"],
126
+ "operationId": "batchCreateDnsRecords",
127
+ "summary": "Batch create DNS records",
128
+ "description": "Create multiple DNS records in a single transaction. Requires domain ownership. All records will be validated together against DNS zone rules."
129
+ }
130
+ },
131
+ "route": {
132
+ "path": "/dns/records/batch",
133
+ "method": "POST",
134
+ "tags": ["dns"],
135
+ "operationId": "batchCreateDnsRecords",
136
+ "summary": "Batch create DNS records",
137
+ "description": "Create multiple DNS records in a single transaction. Requires domain ownership. All records will be validated together against DNS zone rules."
138
+ }
139
+ }
140
+ },
141
+ "deleteRecords": {
142
+ "~orpc": {
143
+ "errorMap": {},
144
+ "meta": {
145
+ "route": {
146
+ "path": "/dns/records/batch",
147
+ "method": "DELETE",
148
+ "tags": ["dns"],
149
+ "operationId": "batchDeleteDnsRecords",
150
+ "summary": "Batch delete DNS records",
151
+ "description": "Delete multiple DNS records by their IDs in a single transaction. Requires domain ownership. The zone will be validated after deletion."
152
+ }
153
+ },
154
+ "route": {
155
+ "path": "/dns/records/batch",
156
+ "method": "DELETE",
157
+ "tags": ["dns"],
158
+ "operationId": "batchDeleteDnsRecords",
159
+ "summary": "Batch delete DNS records",
160
+ "description": "Delete multiple DNS records by their IDs in a single transaction. Requires domain ownership. The zone will be validated after deletion."
161
+ }
162
+ }
163
+ },
164
+ "parkDomain": {
165
+ "~orpc": {
166
+ "errorMap": {},
167
+ "meta": {
168
+ "route": {
169
+ "path": "/dns/park",
170
+ "method": "POST",
171
+ "tags": ["dns"],
172
+ "operationId": "parkDomain",
173
+ "summary": "Park domain",
174
+ "description": "Park a domain by setting up default parking DNS records (A and AAAA records pointing to the parking server). Optionally override existing conflicting records."
175
+ }
176
+ },
177
+ "route": {
178
+ "path": "/dns/park",
179
+ "method": "POST",
180
+ "tags": ["dns"],
181
+ "operationId": "parkDomain",
182
+ "summary": "Park domain",
183
+ "description": "Park a domain by setting up default parking DNS records (A and AAAA records pointing to the parking server). Optionally override existing conflicting records."
184
+ }
185
+ }
186
+ },
187
+ "isDomainParked": {
188
+ "~orpc": {
189
+ "errorMap": {},
190
+ "meta": {
191
+ "route": {
192
+ "path": "/dns/parked",
193
+ "method": "GET",
194
+ "tags": ["dns"],
195
+ "operationId": "isDomainParked",
196
+ "summary": "Check if domain is parked",
197
+ "description": "Check whether a domain has the standard parking DNS records configured. Returns true if the domain is parked, false otherwise."
198
+ }
199
+ },
200
+ "route": {
201
+ "path": "/dns/parked",
202
+ "method": "GET",
203
+ "tags": ["dns"],
204
+ "operationId": "isDomainParked",
205
+ "summary": "Check if domain is parked",
206
+ "description": "Check whether a domain has the standard parking DNS records configured. Returns true if the domain is parked, false otherwise."
207
+ }
208
+ }
209
+ }
210
+ },
211
+ "user": {
212
+ "getDomains": {
213
+ "~orpc": {
214
+ "errorMap": {},
215
+ "meta": {
216
+ "route": {
217
+ "path": "/user/domains",
218
+ "method": "GET",
219
+ "tags": ["user"],
220
+ "operationId": "getUserDomains",
221
+ "summary": "Get user domains",
222
+ "description": "Retrieve all domains owned by the current user. Returns domain details including DNS status, nameservers, and expiration dates."
223
+ }
224
+ },
225
+ "route": {
226
+ "path": "/user/domains",
227
+ "method": "GET",
228
+ "tags": ["user"],
229
+ "operationId": "getUserDomains",
230
+ "summary": "Get user domains",
231
+ "description": "Retrieve all domains owned by the current user. Returns domain details including DNS status, nameservers, and expiration dates."
232
+ }
233
+ }
234
+ },
235
+ "getUserCart": {
236
+ "~orpc": {
237
+ "errorMap": {},
238
+ "meta": {
239
+ "route": {
240
+ "path": "/user/cart",
241
+ "method": "GET",
242
+ "tags": ["user", "cart"],
243
+ "operationId": "getUserCart",
244
+ "summary": "Get user cart",
245
+ "description": "Retrieve all items in the current user's shopping cart. Includes free claim eligibility information for each item."
246
+ }
247
+ },
248
+ "route": {
249
+ "path": "/user/cart",
250
+ "method": "GET",
251
+ "tags": ["user", "cart"],
252
+ "operationId": "getUserCart",
253
+ "summary": "Get user cart",
254
+ "description": "Retrieve all items in the current user's shopping cart. Includes free claim eligibility information for each item."
255
+ }
256
+ }
257
+ },
258
+ "getUserOrders": {
259
+ "~orpc": {
260
+ "errorMap": {},
261
+ "meta": {
262
+ "route": {
263
+ "path": "/user/orders",
264
+ "method": "GET",
265
+ "tags": ["user", "orders"],
266
+ "operationId": "getUserOrders",
267
+ "summary": "Get user orders",
268
+ "description": "Retrieve all order items for the current user. Returns order items sorted by creation date in descending order."
269
+ }
270
+ },
271
+ "route": {
272
+ "path": "/user/orders",
273
+ "method": "GET",
274
+ "tags": ["user", "orders"],
275
+ "operationId": "getUserOrders",
276
+ "summary": "Get user orders",
277
+ "description": "Retrieve all order items for the current user. Returns order items sorted by creation date in descending order."
278
+ }
279
+ }
280
+ }
281
+ },
282
+ "orders": {
283
+ "getOrder": {
284
+ "~orpc": {
285
+ "errorMap": {},
286
+ "meta": {
287
+ "route": {
288
+ "path": "/orders/{orderId}",
289
+ "method": "GET",
290
+ "tags": ["orders"],
291
+ "operationId": "getOrder",
292
+ "summary": "Get order details",
293
+ "description": "Retrieve detailed information about an order including items, payments, and user details. User must own the order."
294
+ }
295
+ },
296
+ "route": {
297
+ "path": "/orders/{orderId}",
298
+ "method": "GET",
299
+ "tags": ["orders"],
300
+ "operationId": "getOrder",
301
+ "summary": "Get order details",
302
+ "description": "Retrieve detailed information about an order including items, payments, and user details. User must own the order."
303
+ }
304
+ }
305
+ },
306
+ "getOrderItems": {
307
+ "~orpc": {
308
+ "errorMap": {},
309
+ "meta": {
310
+ "route": {
311
+ "path": "/orders/items",
312
+ "method": "GET",
313
+ "tags": ["orders"],
314
+ "operationId": "getOrderItems",
315
+ "summary": "Get user order items",
316
+ "description": "Retrieve all order items for the current user, sorted by creation date in descending order."
317
+ }
318
+ },
319
+ "route": {
320
+ "path": "/orders/items",
321
+ "method": "GET",
322
+ "tags": ["orders"],
323
+ "operationId": "getOrderItems",
324
+ "summary": "Get user order items",
325
+ "description": "Retrieve all order items for the current user, sorted by creation date in descending order."
326
+ }
327
+ }
328
+ },
329
+ "registerDomain": {
330
+ "~orpc": {
331
+ "errorMap": {},
332
+ "meta": {
333
+ "route": {
334
+ "path": "/orders/register-domain",
335
+ "method": "POST",
336
+ "tags": ["orders"],
337
+ "operationId": "registerDomain",
338
+ "summary": "Instant Register domain",
339
+ "description": "Purchase a single domain instantly without adding to cart. Validates domain availability, creates payments and order, then starts the order processing workflow."
340
+ }
341
+ },
342
+ "route": {
343
+ "path": "/orders/register-domain",
344
+ "method": "POST",
345
+ "tags": ["orders"],
346
+ "operationId": "registerDomain",
347
+ "summary": "Instant Register domain",
348
+ "description": "Purchase a single domain instantly without adding to cart. Validates domain availability, creates payments and order, then starts the order processing workflow."
349
+ }
350
+ }
351
+ },
352
+ "getOrderPaymentMethodsDetails": {
353
+ "~orpc": {
354
+ "errorMap": {},
355
+ "meta": {
356
+ "route": {
357
+ "path": "/orders/{orderId}/payment-methods",
358
+ "method": "GET",
359
+ "tags": ["orders"],
360
+ "operationId": "getOrderPaymentMethodsDetails",
361
+ "summary": "Get order payment methods",
362
+ "description": "Retrieve payment method details for an order, including card info for Stripe payments and wallet addresses for on-chain payments."
363
+ }
364
+ },
365
+ "route": {
366
+ "path": "/orders/{orderId}/payment-methods",
367
+ "method": "GET",
368
+ "tags": ["orders"],
369
+ "operationId": "getOrderPaymentMethodsDetails",
370
+ "summary": "Get order payment methods",
371
+ "description": "Retrieve payment method details for an order, including card info for Stripe payments and wallet addresses for on-chain payments."
372
+ }
373
+ }
374
+ }
375
+ },
376
+ "balance": {
377
+ "getBalance": {
378
+ "~orpc": {
379
+ "errorMap": {},
380
+ "meta": {
381
+ "route": {
382
+ "path": "/balance",
383
+ "method": "GET",
384
+ "tags": ["balance"],
385
+ "operationId": "getBalance",
386
+ "summary": "Get NFSC balance",
387
+ "description": "Retrieve NFSC (Namefi Stable Coin) balance across all supported blockchain chains for the authenticated user's linked wallet addresses. Returns both raw contract values and human-readable USD amounts."
388
+ }
389
+ },
390
+ "route": {
391
+ "path": "/balance",
392
+ "method": "GET",
393
+ "tags": ["balance"],
394
+ "operationId": "getBalance",
395
+ "summary": "Get NFSC balance",
396
+ "description": "Retrieve NFSC (Namefi Stable Coin) balance across all supported blockchain chains for the authenticated user's linked wallet addresses. Returns both raw contract values and human-readable USD amounts."
397
+ }
398
+ }
399
+ }
400
+ },
401
+ "search": {
402
+ "checkAvailability": {
403
+ "~orpc": {
404
+ "errorMap": {},
405
+ "meta": {
406
+ "route": {
407
+ "path": "/search/availability",
408
+ "method": "GET",
409
+ "tags": ["search"],
410
+ "operationId": "checkAvailability",
411
+ "summary": "Check domain availability",
412
+ "description": "Check if a domain is available for registration. Returns availability status, pricing details, current owner (if any), and registration constraints."
413
+ }
414
+ },
415
+ "route": {
416
+ "path": "/search/availability",
417
+ "method": "GET",
418
+ "tags": ["search"],
419
+ "operationId": "checkAvailability",
420
+ "summary": "Check domain availability",
421
+ "description": "Check if a domain is available for registration. Returns availability status, pricing details, current owner (if any), and registration constraints."
422
+ }
423
+ }
424
+ },
425
+ "getSuggestions": {
426
+ "~orpc": {
427
+ "errorMap": {},
428
+ "meta": {
429
+ "route": {
430
+ "path": "/search/suggestions",
431
+ "method": "GET",
432
+ "tags": ["search"],
433
+ "operationId": "getSuggestions",
434
+ "summary": "Get domain suggestions",
435
+ "description": "Generate domain suggestions based on a search query. Supports pagination and optional parent domain filtering for third-level domain suggestions."
436
+ }
437
+ },
438
+ "route": {
439
+ "path": "/search/suggestions",
440
+ "method": "GET",
441
+ "tags": ["search"],
442
+ "operationId": "getSuggestions",
443
+ "summary": "Get domain suggestions",
444
+ "description": "Generate domain suggestions based on a search query. Supports pagination and optional parent domain filtering for third-level domain suggestions."
445
+ }
446
+ }
447
+ }
448
+ }
449
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@namefi-astra/client",
3
+ "author": "Namefi <dev-team@namefi.io>",
4
+ "license": "MIT",
5
+ "description": "API client for Namefi",
6
+ "version": "0.0.0-pre.1",
7
+ "type": "module",
8
+ "scripts": {
9
+ "clean": "git clean -xdf .next .turbo node_modules out dist",
10
+ "typecheck": "tsc --noEmit",
11
+ "build": "tsup",
12
+ "generate:contract": "bun run tsx ./scripts/minify-contract.ts",
13
+ "check": "biome check .",
14
+ "check:error": "biome check . --diagnostic-level=error",
15
+ "check:fix": "biome check --write .",
16
+ "check:unsafe": "biome check --write --unsafe ."
17
+ },
18
+ "dependencies": {
19
+ "@namefi-astra/backend": "workspace:*",
20
+ "@orpc/client": "^1.13.2",
21
+ "@orpc/contract": "^1.13.2",
22
+ "@orpc/openapi-client": "^1.13.2"
23
+ },
24
+ "exports": {
25
+ ".": "./src/index.ts"
26
+ },
27
+ "peerDependencies": {
28
+ "vitest": "^3.1.2",
29
+ "zod": "^4.1.12"
30
+ },
31
+ "devDependencies": {
32
+ "@namefi-astra/typescript": "workspace:*",
33
+ "tsup": "^8.4.0",
34
+ "vite-tsconfig-paths": "^5.1.4"
35
+ }
36
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@namefi/api-client",
3
+ "author": "Namefi <dev-team@namefi.io>",
4
+ "license": "MIT",
5
+ "description": "API client for Namefi",
6
+ "version": "0.0.0-pre.1",
7
+ "type": "module",
8
+ "dependencies": {
9
+ "@orpc/client": "^1.13.2",
10
+ "@orpc/contract": "^1.13.2",
11
+ "@orpc/openapi-client": "^1.13.2"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "require": "./dist/index.cjs",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.cjs",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "zod": "^4.1.12"
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@namefi/api-client",
3
+ "author": "Namefi <dev-team@namefi.io>",
4
+ "license": "MIT",
5
+ "description": "API client for Namefi",
6
+ "version": "0.0.0-pre.1",
7
+ "type": "module",
8
+ "dependencies": {
9
+ "@orpc/client": "^1.13.2",
10
+ "@orpc/contract": "^1.13.2",
11
+ "@orpc/openapi-client": "^1.13.2"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "require": "./dist/index.cjs",
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.cjs",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "peerDependencies": {
22
+ "zod": "^4.1.12"
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ import fs from 'node:fs';
2
+ import { minifyContractRouter } from '@orpc/contract';
3
+ import { orpcRouter } from '@namefi-astra/backend/openapi';
4
+
5
+ const minifiedRouter = minifyContractRouter(orpcRouter);
6
+
7
+ fs.writeFileSync('./contract.json', JSON.stringify(minifiedRouter));
package/src/index.ts ADDED
@@ -0,0 +1,79 @@
1
+ import type { JsonifiedClient } from '@orpc/openapi-client';
2
+ import type { ContractRouterClient } from '@orpc/contract';
3
+ import {
4
+ createORPCClient,
5
+ onError,
6
+ onFinish,
7
+ onStart,
8
+ onSuccess,
9
+ } from '@orpc/client';
10
+ import { OpenAPILink } from '@orpc/openapi-client/fetch';
11
+ import contract from '../contract.json';
12
+ import type { orpcRouter as router } from '@namefi-astra/backend/openapi';
13
+
14
+ type CreateNamefiClientOptions = {
15
+ authentication: {
16
+ apiKey: string;
17
+ type: 'API_KEY';
18
+ };
19
+ logger:
20
+ | {
21
+ info: (...args: any[]) => void;
22
+ error: (...args: any[]) => void;
23
+ }
24
+ | boolean
25
+ | undefined;
26
+ baseUrl?: string;
27
+ };
28
+
29
+ export function createNamefiClient({
30
+ authentication,
31
+ logger,
32
+ baseUrl = 'https://backend.astra.namefi.io',
33
+ }: CreateNamefiClientOptions) {
34
+ const { apiKey } = authentication;
35
+ const _logger = logger
36
+ ? typeof logger === 'object'
37
+ ? logger
38
+ : {
39
+ info: (...args: any[]) => console.log(...args),
40
+ error: (...args: any[]) => console.error(...args),
41
+ }
42
+ : undefined;
43
+
44
+ const url = new URL(baseUrl);
45
+ url.pathname =
46
+ '/' + [...url.pathname.split('/').filter(Boolean), 'v-next'].join('/');
47
+
48
+ const link = new OpenAPILink(contract as unknown as typeof router, {
49
+ url: url.toString(),
50
+ headers: () => ({
51
+ 'x-api-key': apiKey,
52
+ }),
53
+ fetch: (request, init) => {
54
+ return globalThis.fetch(request, {
55
+ ...init,
56
+ credentials: 'include', // Include cookies for cross-origin requests
57
+ });
58
+ },
59
+ interceptors: [
60
+ onError((error) => {
61
+ _logger?.error(error);
62
+ }),
63
+ onFinish((response) => {
64
+ _logger?.info('Request finished');
65
+ }),
66
+ onStart((request) => {
67
+ _logger?.info('Request started');
68
+ }),
69
+ onSuccess((response) => {
70
+ _logger?.info('Request succeeded');
71
+ }),
72
+ ],
73
+ });
74
+
75
+ const client: JsonifiedClient<ContractRouterClient<typeof router>> =
76
+ createORPCClient(link);
77
+
78
+ return client;
79
+ }
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+
3
+ # Switches between package.build.json and package.publish.json -> package.json
4
+ # Uses copy to set package.json to the desired config
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ cd "$SCRIPT_DIR"
10
+
11
+ usage() {
12
+ echo "Usage: $0 [build|publish]"
13
+ echo " build - Switch to package.build.json"
14
+ echo " publish - Switch to package.publish.json"
15
+ echo " (no arg) - Toggle between configs"
16
+ exit 1
17
+ }
18
+
19
+ switch_to() {
20
+ local target="$1"
21
+ local target_file="package.${target}.json"
22
+
23
+ if [ ! -f "$target_file" ]; then
24
+ echo "Error: $target_file does not exist"
25
+ exit 1
26
+ fi
27
+
28
+ cp "$target_file" package.json
29
+ echo "Switched to $target config ($target_file -> package.json)"
30
+ }
31
+
32
+ get_current() {
33
+ if [ ! -f "package.json" ]; then
34
+ echo "none"
35
+ return
36
+ fi
37
+
38
+ if [ -f "package.build.json" ] && diff -q package.json package.build.json > /dev/null 2>&1; then
39
+ echo "build"
40
+ elif [ -f "package.publish.json" ] && diff -q package.json package.publish.json > /dev/null 2>&1; then
41
+ echo "publish"
42
+ else
43
+ echo "unknown"
44
+ fi
45
+ }
46
+
47
+ if [ $# -eq 0 ]; then
48
+ # Toggle mode
49
+ current=$(get_current)
50
+ if [ "$current" = "build" ]; then
51
+ switch_to "publish"
52
+ elif [ "$current" = "publish" ]; then
53
+ switch_to "build"
54
+ else
55
+ # Default to build if unknown or none
56
+ switch_to "build"
57
+ fi
58
+ elif [ "$1" = "build" ] || [ "$1" = "publish" ]; then
59
+ current=$(get_current)
60
+ if [ "$current" = "$1" ]; then
61
+ echo "Already using $1 config"
62
+ else
63
+ switch_to "$1"
64
+ fi
65
+ else
66
+ usage
67
+ fi
@@ -0,0 +1,71 @@
1
+ #!/bin/bash
2
+
3
+ # Switches between package.build.json and package.publish.json -> package.json
4
+ # Uses symbolic links to point package.json to the desired config
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ cd "$SCRIPT_DIR"
10
+
11
+ usage() {
12
+ echo "Usage: $0 [build|publish]"
13
+ echo " build - Switch to package.build.json"
14
+ echo " publish - Switch to package.publish.json"
15
+ echo " (no arg) - Toggle between configs"
16
+ exit 1
17
+ }
18
+
19
+ switch_to() {
20
+ local target="$1"
21
+ local target_file="package.${target}.json"
22
+
23
+ if [ ! -f "$target_file" ]; then
24
+ echo "Error: $target_file does not exist"
25
+ exit 1
26
+ fi
27
+
28
+ # Remove existing package.json (symlink or file)
29
+ rm -f package.json
30
+
31
+ # Create symlink
32
+ ln -s "$target_file" package.json
33
+ echo "Switched to $target config ($target_file -> package.json)"
34
+ }
35
+
36
+ get_current() {
37
+ if [ -L "package.json" ]; then
38
+ local target=$(readlink package.json)
39
+ if [ "$target" = "package.build.json" ]; then
40
+ echo "build"
41
+ elif [ "$target" = "package.publish.json" ]; then
42
+ echo "publish"
43
+ else
44
+ echo "unknown"
45
+ fi
46
+ else
47
+ echo "none"
48
+ fi
49
+ }
50
+
51
+ if [ $# -eq 0 ]; then
52
+ # Toggle mode
53
+ current=$(get_current)
54
+ if [ "$current" = "build" ]; then
55
+ switch_to "publish"
56
+ elif [ "$current" = "publish" ]; then
57
+ switch_to "build"
58
+ else
59
+ # Default to build if no symlink exists
60
+ switch_to "build"
61
+ fi
62
+ elif [ "$1" = "build" ] || [ "$1" = "publish" ]; then
63
+ current=$(get_current)
64
+ if [ "$current" = "$1" ]; then
65
+ echo "Already using $1 config"
66
+ else
67
+ switch_to "$1"
68
+ fi
69
+ else
70
+ usage
71
+ fi
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "@namefi-astra/typescript",
3
+ "compilerOptions": {
4
+ "target": "ESNext",
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "strict": true,
8
+ "verbatimModuleSyntax": true,
9
+ "types": ["node"],
10
+ "baseUrl": ".",
11
+ "outDir": "./dist",
12
+ "rootDir": "./src",
13
+ "skipLibCheck": true
14
+ },
15
+ "include": ["src/**/*.ts"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type Options, defineConfig } from 'tsup';
2
+
3
+ const config: Options = {
4
+ splitting: true,
5
+ sourcemap: true,
6
+ clean: true,
7
+ format: ['esm', 'cjs'],
8
+ dts: true,
9
+ target: 'node22',
10
+ minify: true,
11
+ shims: true,
12
+ skipNodeModulesBundle: true,
13
+ treeshake: true,
14
+ keepNames: true,
15
+ minifyIdentifiers: false,
16
+ esbuildOptions(options) {
17
+ options.conditions = ['node'];
18
+ },
19
+ noExternal: (() => {
20
+ const noExternal: (string | RegExp)[] = [/@namefi-astra\/.*/];
21
+ const pkg = require('./package.json');
22
+ const imports = pkg.imports || {};
23
+ // Convert import paths like "#services/*": "./src/services/*" to regex patterns like /#services\/.*/
24
+ return noExternal.concat(
25
+ Object.keys(imports)
26
+ .map((key) => key.replace('/*', '/.*'))
27
+ .filter((pattern) => pattern.startsWith('#'))
28
+ .map((pattern) => new RegExp(pattern)),
29
+ );
30
+ })(),
31
+ };
32
+
33
+ export default defineConfig([
34
+ {
35
+ entry: ['src/index.ts'],
36
+ outDir: 'dist',
37
+ ...config,
38
+ },
39
+ ]);