@settlemint/sdk-ipfs 2.3.2-prfd3a56ad → 2.3.3
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 +4 -4
- package/dist/browser/ipfs.d.ts +81 -0
- package/dist/browser/ipfs.js +73 -0
- package/dist/browser/ipfs.js.map +1 -0
- package/dist/ipfs.cjs +83 -55
- package/dist/ipfs.cjs.map +1 -1
- package/dist/ipfs.d.cts +15 -7
- package/dist/ipfs.d.ts +15 -7
- package/dist/ipfs.js +73 -0
- package/dist/ipfs.js.map +1 -0
- package/package.json +6 -6
- package/dist/ipfs.mjs +0 -43
- package/dist/ipfs.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The SettleMint IPFS SDK provides a simple way to interact with IPFS (InterPlanet
|
|
|
46
46
|
|
|
47
47
|
> **createIpfsClient**(`options`): `object`
|
|
48
48
|
|
|
49
|
-
Defined in: [sdk/ipfs/src/ipfs.ts:31](https://github.com/settlemint/sdk/blob/v2.3.
|
|
49
|
+
Defined in: [sdk/ipfs/src/ipfs.ts:31](https://github.com/settlemint/sdk/blob/v2.3.3/sdk/ipfs/src/ipfs.ts#L31)
|
|
50
50
|
|
|
51
51
|
Creates an IPFS client for client-side use
|
|
52
52
|
|
|
@@ -65,7 +65,7 @@ An object containing the configured IPFS client instance
|
|
|
65
65
|
|
|
66
66
|
| Name | Type | Defined in |
|
|
67
67
|
| ------ | ------ | ------ |
|
|
68
|
-
| `client` | `KuboRPCClient` | [sdk/ipfs/src/ipfs.ts:31](https://github.com/settlemint/sdk/blob/v2.3.
|
|
68
|
+
| `client` | `KuboRPCClient` | [sdk/ipfs/src/ipfs.ts:31](https://github.com/settlemint/sdk/blob/v2.3.3/sdk/ipfs/src/ipfs.ts#L31) |
|
|
69
69
|
|
|
70
70
|
##### Throws
|
|
71
71
|
|
|
@@ -92,7 +92,7 @@ console.log(result.cid.toString());
|
|
|
92
92
|
|
|
93
93
|
> **createServerIpfsClient**(`options`): `object`
|
|
94
94
|
|
|
95
|
-
Defined in: [sdk/ipfs/src/ipfs.ts:60](https://github.com/settlemint/sdk/blob/v2.3.
|
|
95
|
+
Defined in: [sdk/ipfs/src/ipfs.ts:60](https://github.com/settlemint/sdk/blob/v2.3.3/sdk/ipfs/src/ipfs.ts#L60)
|
|
96
96
|
|
|
97
97
|
Creates an IPFS client for server-side use with authentication
|
|
98
98
|
|
|
@@ -112,7 +112,7 @@ An object containing the authenticated IPFS client instance
|
|
|
112
112
|
|
|
113
113
|
| Name | Type | Defined in |
|
|
114
114
|
| ------ | ------ | ------ |
|
|
115
|
-
| `client` | `KuboRPCClient` | [sdk/ipfs/src/ipfs.ts:60](https://github.com/settlemint/sdk/blob/v2.3.
|
|
115
|
+
| `client` | `KuboRPCClient` | [sdk/ipfs/src/ipfs.ts:60](https://github.com/settlemint/sdk/blob/v2.3.3/sdk/ipfs/src/ipfs.ts#L60) |
|
|
116
116
|
|
|
117
117
|
##### Throws
|
|
118
118
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { KuboRPCClient } from "kubo-rpc-client";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/client-options.schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Schema for validating client options for the IPFS client.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Schema for validating client options for the IPFS client.
|
|
10
|
+
*/
|
|
11
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
12
|
+
instance: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for client options derived from the ClientOptionsSchema.
|
|
16
|
+
*/
|
|
17
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Schema for validating server client options for the IPFS client.
|
|
20
|
+
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
21
|
+
*/
|
|
22
|
+
declare const ServerClientOptionsSchema: z.ZodObject<{
|
|
23
|
+
instance: z.ZodString;
|
|
24
|
+
accessToken: z.ZodString;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Type definition for server client options derived from the ServerClientOptionsSchema.
|
|
28
|
+
*/
|
|
29
|
+
type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/ipfs.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* Creates an IPFS client for client-side use
|
|
35
|
+
*
|
|
36
|
+
* @param options - Configuration options for the client
|
|
37
|
+
* @returns An object containing the configured IPFS client instance
|
|
38
|
+
* @throws Will throw an error if the options fail validation
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { createIpfsClient } from '@settlemint/sdk-ipfs';
|
|
42
|
+
*
|
|
43
|
+
* const { client } = createIpfsClient({
|
|
44
|
+
* instance: 'https://ipfs.settlemint.com'
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Upload a file using Blob
|
|
48
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
49
|
+
* const result = await client.add(blob);
|
|
50
|
+
* console.log(result.cid.toString());
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function createIpfsClient(options: ClientOptions): {
|
|
54
|
+
client: KuboRPCClient;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Creates an IPFS client for server-side use with authentication
|
|
58
|
+
*
|
|
59
|
+
* @param options - Configuration options for the client including authentication
|
|
60
|
+
* @returns An object containing the authenticated IPFS client instance
|
|
61
|
+
* @throws Will throw an error if called on the client side or if options validation fails
|
|
62
|
+
* @example
|
|
63
|
+
* import { createServerIpfsClient } from '@settlemint/sdk-ipfs';
|
|
64
|
+
*
|
|
65
|
+
* const { client } = createServerIpfsClient({
|
|
66
|
+
* instance: process.env.SETTLEMINT_IPFS_ENDPOINT,
|
|
67
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Upload a file using Blob
|
|
71
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
72
|
+
* const result = await client.add(blob);
|
|
73
|
+
* console.log(result.cid.toString());
|
|
74
|
+
*/
|
|
75
|
+
declare function createServerIpfsClient(options: ServerClientOptions): {
|
|
76
|
+
client: KuboRPCClient;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createIpfsClient, createServerIpfsClient };
|
|
81
|
+
//# sourceMappingURL=ipfs.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
|
+
import { AccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
|
+
import { create } from "kubo-rpc-client";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/client-options.schema.ts
|
|
7
|
+
/**
|
|
8
|
+
* Schema for validating client options for the IPFS client.
|
|
9
|
+
*/
|
|
10
|
+
const ClientOptionsSchema = z.object({ instance: UrlSchema });
|
|
11
|
+
/**
|
|
12
|
+
* Schema for validating server client options for the IPFS client.
|
|
13
|
+
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
14
|
+
*/
|
|
15
|
+
const ServerClientOptionsSchema = ClientOptionsSchema.extend({ accessToken: AccessTokenSchema });
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/ipfs.ts
|
|
19
|
+
/**
|
|
20
|
+
* Creates an IPFS client for client-side use
|
|
21
|
+
*
|
|
22
|
+
* @param options - Configuration options for the client
|
|
23
|
+
* @returns An object containing the configured IPFS client instance
|
|
24
|
+
* @throws Will throw an error if the options fail validation
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { createIpfsClient } from '@settlemint/sdk-ipfs';
|
|
28
|
+
*
|
|
29
|
+
* const { client } = createIpfsClient({
|
|
30
|
+
* instance: 'https://ipfs.settlemint.com'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Upload a file using Blob
|
|
34
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
35
|
+
* const result = await client.add(blob);
|
|
36
|
+
* console.log(result.cid.toString());
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function createIpfsClient(options) {
|
|
40
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
41
|
+
return { client: create({ url: validatedOptions.instance }) };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates an IPFS client for server-side use with authentication
|
|
45
|
+
*
|
|
46
|
+
* @param options - Configuration options for the client including authentication
|
|
47
|
+
* @returns An object containing the authenticated IPFS client instance
|
|
48
|
+
* @throws Will throw an error if called on the client side or if options validation fails
|
|
49
|
+
* @example
|
|
50
|
+
* import { createServerIpfsClient } from '@settlemint/sdk-ipfs';
|
|
51
|
+
*
|
|
52
|
+
* const { client } = createServerIpfsClient({
|
|
53
|
+
* instance: process.env.SETTLEMINT_IPFS_ENDPOINT,
|
|
54
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Upload a file using Blob
|
|
58
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
59
|
+
* const result = await client.add(blob);
|
|
60
|
+
* console.log(result.cid.toString());
|
|
61
|
+
*/
|
|
62
|
+
function createServerIpfsClient(options) {
|
|
63
|
+
ensureServer();
|
|
64
|
+
const validatedOptions = validate(ServerClientOptionsSchema, options);
|
|
65
|
+
return { client: create({
|
|
66
|
+
url: validatedOptions.instance,
|
|
67
|
+
headers: { "x-auth-token": validatedOptions.accessToken }
|
|
68
|
+
}) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { createIpfsClient, createServerIpfsClient };
|
|
73
|
+
//# sourceMappingURL=ipfs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs.js","names":["options: ClientOptions","options: ServerClientOptions"],"sources":["../../src/helpers/client-options.schema.ts","../../src/ipfs.ts"],"sourcesContent":["import { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating client options for the IPFS client.\n */\nexport const ClientOptionsSchema = z.object({\n /** The URL of the IPFS instance to connect to */\n instance: UrlSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Schema for validating server client options for the IPFS client.\n * Extends the ClientOptionsSchema with additional server-specific fields.\n */\nexport const ServerClientOptionsSchema = ClientOptionsSchema.extend({\n /** The access token used to authenticate with the SettleMint platform */\n accessToken: AccessTokenSchema,\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { type KuboRPCClient, create } from \"kubo-rpc-client\";\nimport {\n type ClientOptions,\n ClientOptionsSchema,\n type ServerClientOptions,\n ServerClientOptionsSchema,\n} from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates an IPFS client for client-side use\n *\n * @param options - Configuration options for the client\n * @returns An object containing the configured IPFS client instance\n * @throws Will throw an error if the options fail validation\n * @example\n * ```ts\n * import { createIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createIpfsClient({\n * instance: 'https://ipfs.settlemint.com'\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n * ```\n */\nexport function createIpfsClient(options: ClientOptions): { client: KuboRPCClient } {\n const validatedOptions = validate(ClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n }),\n };\n}\n\n/**\n * Creates an IPFS client for server-side use with authentication\n *\n * @param options - Configuration options for the client including authentication\n * @returns An object containing the authenticated IPFS client instance\n * @throws Will throw an error if called on the client side or if options validation fails\n * @example\n * import { createServerIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createServerIpfsClient({\n * instance: process.env.SETTLEMINT_IPFS_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n */\nexport function createServerIpfsClient(options: ServerClientOptions): { client: KuboRPCClient } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;AAMA,MAAa,sBAAsB,EAAE,OAAO,EAE1C,UAAU,UACX,EAAC;;;;;AAWF,MAAa,4BAA4B,oBAAoB,OAAO,EAElE,aAAa,kBACd,EAAC;;;;;;;;;;;;;;;;;;;;;;;;ACOF,SAAgB,iBAAiBA,SAAmD;CAClF,MAAM,mBAAmB,SAAS,qBAAqB,QAAQ;AAE/D,QAAO,EACL,QAAQ,OAAO,EACb,KAAK,iBAAiB,SACvB,EAAC,CACH;AACF;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,uBAAuBC,SAAyD;AAC9F,eAAc;CACd,MAAM,mBAAmB,SAAS,2BAA2B,QAAQ;AAErE,QAAO,EACL,QAAQ,OAAO;EACb,KAAK,iBAAiB;EACtB,SAAS,EACP,gBAAgB,iBAAiB,YAClC;CACF,EAAC,CACH;AACF"}
|
package/dist/ipfs.cjs
CHANGED
|
@@ -1,69 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
8
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(ipfs_exports);
|
|
27
|
-
var import_runtime = require("@settlemint/sdk-utils/runtime");
|
|
28
|
-
var import_validation2 = require("@settlemint/sdk-utils/validation");
|
|
29
|
-
var import_kubo_rpc_client = require("kubo-rpc-client");
|
|
23
|
+
//#endregion
|
|
24
|
+
const __settlemint_sdk_utils_runtime = __toESM(require("@settlemint/sdk-utils/runtime"));
|
|
25
|
+
const __settlemint_sdk_utils_validation = __toESM(require("@settlemint/sdk-utils/validation"));
|
|
26
|
+
const kubo_rpc_client = __toESM(require("kubo-rpc-client"));
|
|
27
|
+
const zod_v4 = __toESM(require("zod/v4"));
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
29
|
+
//#region src/helpers/client-options.schema.ts
|
|
30
|
+
/**
|
|
31
|
+
* Schema for validating client options for the IPFS client.
|
|
32
|
+
*/
|
|
33
|
+
const ClientOptionsSchema = zod_v4.z.object({ instance: __settlemint_sdk_utils_validation.UrlSchema });
|
|
34
|
+
/**
|
|
35
|
+
* Schema for validating server client options for the IPFS client.
|
|
36
|
+
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
37
|
+
*/
|
|
38
|
+
const ServerClientOptionsSchema = ClientOptionsSchema.extend({ accessToken: __settlemint_sdk_utils_validation.AccessTokenSchema });
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/ipfs.ts
|
|
42
|
+
/**
|
|
43
|
+
* Creates an IPFS client for client-side use
|
|
44
|
+
*
|
|
45
|
+
* @param options - Configuration options for the client
|
|
46
|
+
* @returns An object containing the configured IPFS client instance
|
|
47
|
+
* @throws Will throw an error if the options fail validation
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { createIpfsClient } from '@settlemint/sdk-ipfs';
|
|
51
|
+
*
|
|
52
|
+
* const { client } = createIpfsClient({
|
|
53
|
+
* instance: 'https://ipfs.settlemint.com'
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Upload a file using Blob
|
|
57
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
58
|
+
* const result = await client.add(blob);
|
|
59
|
+
* console.log(result.cid.toString());
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
44
62
|
function createIpfsClient(options) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
client: (0, import_kubo_rpc_client.create)({
|
|
48
|
-
url: validatedOptions.instance
|
|
49
|
-
})
|
|
50
|
-
};
|
|
63
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
64
|
+
return { client: (0, kubo_rpc_client.create)({ url: validatedOptions.instance }) };
|
|
51
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates an IPFS client for server-side use with authentication
|
|
68
|
+
*
|
|
69
|
+
* @param options - Configuration options for the client including authentication
|
|
70
|
+
* @returns An object containing the authenticated IPFS client instance
|
|
71
|
+
* @throws Will throw an error if called on the client side or if options validation fails
|
|
72
|
+
* @example
|
|
73
|
+
* import { createServerIpfsClient } from '@settlemint/sdk-ipfs';
|
|
74
|
+
*
|
|
75
|
+
* const { client } = createServerIpfsClient({
|
|
76
|
+
* instance: process.env.SETTLEMINT_IPFS_ENDPOINT,
|
|
77
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Upload a file using Blob
|
|
81
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
82
|
+
* const result = await client.add(blob);
|
|
83
|
+
* console.log(result.cid.toString());
|
|
84
|
+
*/
|
|
52
85
|
function createServerIpfsClient(options) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"x-auth-token": validatedOptions.accessToken
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
};
|
|
86
|
+
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
87
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ServerClientOptionsSchema, options);
|
|
88
|
+
return { client: (0, kubo_rpc_client.create)({
|
|
89
|
+
url: validatedOptions.instance,
|
|
90
|
+
headers: { "x-auth-token": validatedOptions.accessToken }
|
|
91
|
+
}) };
|
|
63
92
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.createIpfsClient = createIpfsClient;
|
|
96
|
+
exports.createServerIpfsClient = createServerIpfsClient;
|
|
69
97
|
//# sourceMappingURL=ipfs.cjs.map
|
package/dist/ipfs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ipfs.cjs","names":["UrlSchema","AccessTokenSchema","options: ClientOptions","options: ServerClientOptions"],"sources":["../src/helpers/client-options.schema.ts","../src/ipfs.ts"],"sourcesContent":["import { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating client options for the IPFS client.\n */\nexport const ClientOptionsSchema = z.object({\n /** The URL of the IPFS instance to connect to */\n instance: UrlSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Schema for validating server client options for the IPFS client.\n * Extends the ClientOptionsSchema with additional server-specific fields.\n */\nexport const ServerClientOptionsSchema = ClientOptionsSchema.extend({\n /** The access token used to authenticate with the SettleMint platform */\n accessToken: AccessTokenSchema,\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { type KuboRPCClient, create } from \"kubo-rpc-client\";\nimport {\n type ClientOptions,\n ClientOptionsSchema,\n type ServerClientOptions,\n ServerClientOptionsSchema,\n} from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates an IPFS client for client-side use\n *\n * @param options - Configuration options for the client\n * @returns An object containing the configured IPFS client instance\n * @throws Will throw an error if the options fail validation\n * @example\n * ```ts\n * import { createIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createIpfsClient({\n * instance: 'https://ipfs.settlemint.com'\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n * ```\n */\nexport function createIpfsClient(options: ClientOptions): { client: KuboRPCClient } {\n const validatedOptions = validate(ClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n }),\n };\n}\n\n/**\n * Creates an IPFS client for server-side use with authentication\n *\n * @param options - Configuration options for the client including authentication\n * @returns An object containing the authenticated IPFS client instance\n * @throws Will throw an error if called on the client side or if options validation fails\n * @example\n * import { createServerIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createServerIpfsClient({\n * instance: process.env.SETTLEMINT_IPFS_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n */\nexport function createServerIpfsClient(options: ServerClientOptions): { client: KuboRPCClient } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,sBAAsB,SAAE,OAAO,EAE1C,UAAUA,4CACX,EAAC;;;;;AAWF,MAAa,4BAA4B,oBAAoB,OAAO,EAElE,aAAaC,oDACd,EAAC;;;;;;;;;;;;;;;;;;;;;;;;ACOF,SAAgB,iBAAiBC,SAAmD;CAClF,MAAM,mBAAmB,gDAAS,qBAAqB,QAAQ;AAE/D,QAAO,EACL,QAAQ,4BAAO,EACb,KAAK,iBAAiB,SACvB,EAAC,CACH;AACF;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,uBAAuBC,SAAyD;AAC9F,mDAAc;CACd,MAAM,mBAAmB,gDAAS,2BAA2B,QAAQ;AAErE,QAAO,EACL,QAAQ,4BAAO;EACb,KAAK,iBAAiB;EACtB,SAAS,EACP,gBAAgB,iBAAiB,YAClC;CACF,EAAC,CACH;AACF"}
|
package/dist/ipfs.d.cts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { KuboRPCClient } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import { KuboRPCClient } from "kubo-rpc-client";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
3
|
|
|
4
|
+
//#region src/helpers/client-options.schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Schema for validating client options for the IPFS client.
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* Schema for validating client options for the IPFS client.
|
|
6
10
|
*/
|
|
7
11
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
8
|
-
|
|
12
|
+
instance: z.ZodString;
|
|
9
13
|
}, z.core.$strip>;
|
|
10
14
|
/**
|
|
11
15
|
* Type definition for client options derived from the ClientOptionsSchema.
|
|
@@ -16,14 +20,16 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
16
20
|
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
17
21
|
*/
|
|
18
22
|
declare const ServerClientOptionsSchema: z.ZodObject<{
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
instance: z.ZodString;
|
|
24
|
+
accessToken: z.ZodString;
|
|
21
25
|
}, z.core.$strip>;
|
|
22
26
|
/**
|
|
23
27
|
* Type definition for server client options derived from the ServerClientOptionsSchema.
|
|
24
28
|
*/
|
|
25
29
|
type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
26
30
|
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/ipfs.d.ts
|
|
27
33
|
/**
|
|
28
34
|
* Creates an IPFS client for client-side use
|
|
29
35
|
*
|
|
@@ -45,7 +51,7 @@ type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
|
45
51
|
* ```
|
|
46
52
|
*/
|
|
47
53
|
declare function createIpfsClient(options: ClientOptions): {
|
|
48
|
-
|
|
54
|
+
client: KuboRPCClient;
|
|
49
55
|
};
|
|
50
56
|
/**
|
|
51
57
|
* Creates an IPFS client for server-side use with authentication
|
|
@@ -67,7 +73,9 @@ declare function createIpfsClient(options: ClientOptions): {
|
|
|
67
73
|
* console.log(result.cid.toString());
|
|
68
74
|
*/
|
|
69
75
|
declare function createServerIpfsClient(options: ServerClientOptions): {
|
|
70
|
-
|
|
76
|
+
client: KuboRPCClient;
|
|
71
77
|
};
|
|
72
78
|
|
|
79
|
+
//#endregion
|
|
73
80
|
export { createIpfsClient, createServerIpfsClient };
|
|
81
|
+
//# sourceMappingURL=ipfs.d.cts.map
|
package/dist/ipfs.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { KuboRPCClient } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import { KuboRPCClient } from "kubo-rpc-client";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
3
|
|
|
4
|
+
//#region src/helpers/client-options.schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Schema for validating client options for the IPFS client.
|
|
7
|
+
*/
|
|
4
8
|
/**
|
|
5
9
|
* Schema for validating client options for the IPFS client.
|
|
6
10
|
*/
|
|
7
11
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
8
|
-
|
|
12
|
+
instance: z.ZodString;
|
|
9
13
|
}, z.core.$strip>;
|
|
10
14
|
/**
|
|
11
15
|
* Type definition for client options derived from the ClientOptionsSchema.
|
|
@@ -16,14 +20,16 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
16
20
|
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
17
21
|
*/
|
|
18
22
|
declare const ServerClientOptionsSchema: z.ZodObject<{
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
instance: z.ZodString;
|
|
24
|
+
accessToken: z.ZodString;
|
|
21
25
|
}, z.core.$strip>;
|
|
22
26
|
/**
|
|
23
27
|
* Type definition for server client options derived from the ServerClientOptionsSchema.
|
|
24
28
|
*/
|
|
25
29
|
type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
26
30
|
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/ipfs.d.ts
|
|
27
33
|
/**
|
|
28
34
|
* Creates an IPFS client for client-side use
|
|
29
35
|
*
|
|
@@ -45,7 +51,7 @@ type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;
|
|
|
45
51
|
* ```
|
|
46
52
|
*/
|
|
47
53
|
declare function createIpfsClient(options: ClientOptions): {
|
|
48
|
-
|
|
54
|
+
client: KuboRPCClient;
|
|
49
55
|
};
|
|
50
56
|
/**
|
|
51
57
|
* Creates an IPFS client for server-side use with authentication
|
|
@@ -67,7 +73,9 @@ declare function createIpfsClient(options: ClientOptions): {
|
|
|
67
73
|
* console.log(result.cid.toString());
|
|
68
74
|
*/
|
|
69
75
|
declare function createServerIpfsClient(options: ServerClientOptions): {
|
|
70
|
-
|
|
76
|
+
client: KuboRPCClient;
|
|
71
77
|
};
|
|
72
78
|
|
|
79
|
+
//#endregion
|
|
73
80
|
export { createIpfsClient, createServerIpfsClient };
|
|
81
|
+
//# sourceMappingURL=ipfs.d.ts.map
|
package/dist/ipfs.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
|
+
import { AccessTokenSchema, UrlSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
|
+
import { create } from "kubo-rpc-client";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
|
|
6
|
+
//#region src/helpers/client-options.schema.ts
|
|
7
|
+
/**
|
|
8
|
+
* Schema for validating client options for the IPFS client.
|
|
9
|
+
*/
|
|
10
|
+
const ClientOptionsSchema = z.object({ instance: UrlSchema });
|
|
11
|
+
/**
|
|
12
|
+
* Schema for validating server client options for the IPFS client.
|
|
13
|
+
* Extends the ClientOptionsSchema with additional server-specific fields.
|
|
14
|
+
*/
|
|
15
|
+
const ServerClientOptionsSchema = ClientOptionsSchema.extend({ accessToken: AccessTokenSchema });
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/ipfs.ts
|
|
19
|
+
/**
|
|
20
|
+
* Creates an IPFS client for client-side use
|
|
21
|
+
*
|
|
22
|
+
* @param options - Configuration options for the client
|
|
23
|
+
* @returns An object containing the configured IPFS client instance
|
|
24
|
+
* @throws Will throw an error if the options fail validation
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { createIpfsClient } from '@settlemint/sdk-ipfs';
|
|
28
|
+
*
|
|
29
|
+
* const { client } = createIpfsClient({
|
|
30
|
+
* instance: 'https://ipfs.settlemint.com'
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Upload a file using Blob
|
|
34
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
35
|
+
* const result = await client.add(blob);
|
|
36
|
+
* console.log(result.cid.toString());
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function createIpfsClient(options) {
|
|
40
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
41
|
+
return { client: create({ url: validatedOptions.instance }) };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates an IPFS client for server-side use with authentication
|
|
45
|
+
*
|
|
46
|
+
* @param options - Configuration options for the client including authentication
|
|
47
|
+
* @returns An object containing the authenticated IPFS client instance
|
|
48
|
+
* @throws Will throw an error if called on the client side or if options validation fails
|
|
49
|
+
* @example
|
|
50
|
+
* import { createServerIpfsClient } from '@settlemint/sdk-ipfs';
|
|
51
|
+
*
|
|
52
|
+
* const { client } = createServerIpfsClient({
|
|
53
|
+
* instance: process.env.SETTLEMINT_IPFS_ENDPOINT,
|
|
54
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Upload a file using Blob
|
|
58
|
+
* const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
|
|
59
|
+
* const result = await client.add(blob);
|
|
60
|
+
* console.log(result.cid.toString());
|
|
61
|
+
*/
|
|
62
|
+
function createServerIpfsClient(options) {
|
|
63
|
+
ensureServer();
|
|
64
|
+
const validatedOptions = validate(ServerClientOptionsSchema, options);
|
|
65
|
+
return { client: create({
|
|
66
|
+
url: validatedOptions.instance,
|
|
67
|
+
headers: { "x-auth-token": validatedOptions.accessToken }
|
|
68
|
+
}) };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { createIpfsClient, createServerIpfsClient };
|
|
73
|
+
//# sourceMappingURL=ipfs.js.map
|
package/dist/ipfs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipfs.js","names":["options: ClientOptions","options: ServerClientOptions"],"sources":["../src/helpers/client-options.schema.ts","../src/ipfs.ts"],"sourcesContent":["import { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating client options for the IPFS client.\n */\nexport const ClientOptionsSchema = z.object({\n /** The URL of the IPFS instance to connect to */\n instance: UrlSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Schema for validating server client options for the IPFS client.\n * Extends the ClientOptionsSchema with additional server-specific fields.\n */\nexport const ServerClientOptionsSchema = ClientOptionsSchema.extend({\n /** The access token used to authenticate with the SettleMint platform */\n accessToken: AccessTokenSchema,\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n","import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { type KuboRPCClient, create } from \"kubo-rpc-client\";\nimport {\n type ClientOptions,\n ClientOptionsSchema,\n type ServerClientOptions,\n ServerClientOptionsSchema,\n} from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates an IPFS client for client-side use\n *\n * @param options - Configuration options for the client\n * @returns An object containing the configured IPFS client instance\n * @throws Will throw an error if the options fail validation\n * @example\n * ```ts\n * import { createIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createIpfsClient({\n * instance: 'https://ipfs.settlemint.com'\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n * ```\n */\nexport function createIpfsClient(options: ClientOptions): { client: KuboRPCClient } {\n const validatedOptions = validate(ClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n }),\n };\n}\n\n/**\n * Creates an IPFS client for server-side use with authentication\n *\n * @param options - Configuration options for the client including authentication\n * @returns An object containing the authenticated IPFS client instance\n * @throws Will throw an error if called on the client side or if options validation fails\n * @example\n * import { createServerIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createServerIpfsClient({\n * instance: process.env.SETTLEMINT_IPFS_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n */\nexport function createServerIpfsClient(options: ServerClientOptions): { client: KuboRPCClient } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;AAMA,MAAa,sBAAsB,EAAE,OAAO,EAE1C,UAAU,UACX,EAAC;;;;;AAWF,MAAa,4BAA4B,oBAAoB,OAAO,EAElE,aAAa,kBACd,EAAC;;;;;;;;;;;;;;;;;;;;;;;;ACOF,SAAgB,iBAAiBA,SAAmD;CAClF,MAAM,mBAAmB,SAAS,qBAAqB,QAAQ;AAE/D,QAAO,EACL,QAAQ,OAAO,EACb,KAAK,iBAAiB,SACvB,EAAC,CACH;AACF;;;;;;;;;;;;;;;;;;;;AAqBD,SAAgB,uBAAuBC,SAAyD;AAC9F,eAAc;CACd,MAAM,mBAAmB,SAAS,2BAA2B,QAAQ;AAErE,QAAO,EACL,QAAQ,OAAO;EACb,KAAK,iBAAiB;EACtB,SAAS,EACP,gBAAgB,iBAAiB,YAClC;CACF,EAAC,CACH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-ipfs",
|
|
3
3
|
"description": "IPFS integration module for SettleMint SDK, enabling decentralized storage and content addressing",
|
|
4
|
-
"version": "2.3.
|
|
4
|
+
"version": "2.3.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": ["dist"],
|
|
24
24
|
"main": "./dist/ipfs.cjs",
|
|
25
|
-
"module": "./dist/ipfs.
|
|
25
|
+
"module": "./dist/ipfs.js",
|
|
26
26
|
"types": "./dist/ipfs.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|
|
29
29
|
".": {
|
|
30
30
|
"import": {
|
|
31
31
|
"types": "./dist/ipfs.d.ts",
|
|
32
|
-
"default": "./dist/ipfs.
|
|
32
|
+
"default": "./dist/ipfs.js"
|
|
33
33
|
},
|
|
34
34
|
"require": {
|
|
35
35
|
"types": "./dist/ipfs.d.cts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev": "
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
43
|
"publint": "publint run --strict",
|
|
44
44
|
"attw": "attw --pack .",
|
|
45
45
|
"test": "bun test",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@settlemint/sdk-utils": "2.3.
|
|
54
|
+
"@settlemint/sdk-utils": "2.3.3",
|
|
55
55
|
"kubo-rpc-client": "^5",
|
|
56
56
|
"zod": "^3.25.0"
|
|
57
57
|
},
|
package/dist/ipfs.mjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// src/ipfs.ts
|
|
2
|
-
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
3
|
-
import { validate } from "@settlemint/sdk-utils/validation";
|
|
4
|
-
import { create } from "kubo-rpc-client";
|
|
5
|
-
|
|
6
|
-
// src/helpers/client-options.schema.ts
|
|
7
|
-
import { ApplicationAccessTokenSchema, UrlSchema } from "@settlemint/sdk-utils/validation";
|
|
8
|
-
import { z } from "zod/v4";
|
|
9
|
-
var ClientOptionsSchema = z.object({
|
|
10
|
-
/** The URL of the IPFS instance to connect to */
|
|
11
|
-
instance: UrlSchema
|
|
12
|
-
});
|
|
13
|
-
var ServerClientOptionsSchema = ClientOptionsSchema.extend({
|
|
14
|
-
/** The access token used to authenticate with the SettleMint platform */
|
|
15
|
-
accessToken: ApplicationAccessTokenSchema
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// src/ipfs.ts
|
|
19
|
-
function createIpfsClient(options) {
|
|
20
|
-
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
21
|
-
return {
|
|
22
|
-
client: create({
|
|
23
|
-
url: validatedOptions.instance
|
|
24
|
-
})
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function createServerIpfsClient(options) {
|
|
28
|
-
ensureServer();
|
|
29
|
-
const validatedOptions = validate(ServerClientOptionsSchema, options);
|
|
30
|
-
return {
|
|
31
|
-
client: create({
|
|
32
|
-
url: validatedOptions.instance,
|
|
33
|
-
headers: {
|
|
34
|
-
"x-auth-token": validatedOptions.accessToken
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
createIpfsClient,
|
|
41
|
-
createServerIpfsClient
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=ipfs.mjs.map
|
package/dist/ipfs.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ipfs.ts","../src/helpers/client-options.schema.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { type KuboRPCClient, create } from \"kubo-rpc-client\";\nimport {\n type ClientOptions,\n ClientOptionsSchema,\n type ServerClientOptions,\n ServerClientOptionsSchema,\n} from \"./helpers/client-options.schema.js\";\n\n/**\n * Creates an IPFS client for client-side use\n *\n * @param options - Configuration options for the client\n * @returns An object containing the configured IPFS client instance\n * @throws Will throw an error if the options fail validation\n * @example\n * ```ts\n * import { createIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createIpfsClient({\n * instance: 'https://ipfs.settlemint.com'\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n * ```\n */\nexport function createIpfsClient(options: ClientOptions): { client: KuboRPCClient } {\n const validatedOptions = validate(ClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n }),\n };\n}\n\n/**\n * Creates an IPFS client for server-side use with authentication\n *\n * @param options - Configuration options for the client including authentication\n * @returns An object containing the authenticated IPFS client instance\n * @throws Will throw an error if called on the client side or if options validation fails\n * @example\n * import { createServerIpfsClient } from '@settlemint/sdk-ipfs';\n *\n * const { client } = createServerIpfsClient({\n * instance: process.env.SETTLEMINT_IPFS_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Upload a file using Blob\n * const blob = new Blob(['Hello, world!'], { type: 'text/plain' });\n * const result = await client.add(blob);\n * console.log(result.cid.toString());\n */\nexport function createServerIpfsClient(options: ServerClientOptions): { client: KuboRPCClient } {\n ensureServer();\n const validatedOptions = validate(ServerClientOptionsSchema, options);\n\n return {\n client: create({\n url: validatedOptions.instance,\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n };\n}\n","import { ApplicationAccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating client options for the IPFS client.\n */\nexport const ClientOptionsSchema = z.object({\n /** The URL of the IPFS instance to connect to */\n instance: UrlSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Schema for validating server client options for the IPFS client.\n * Extends the ClientOptionsSchema with additional server-specific fields.\n */\nexport const ServerClientOptionsSchema = ClientOptionsSchema.extend({\n /** The access token used to authenticate with the SettleMint platform */\n accessToken: ApplicationAccessTokenSchema,\n});\n\n/**\n * Type definition for server client options derived from the ServerClientOptionsSchema.\n */\nexport type ServerClientOptions = z.infer<typeof ServerClientOptionsSchema>;\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAA6B,cAAc;;;ACF3C,SAAS,8BAA8B,iBAAiB;AACxD,SAAS,SAAS;AAKX,IAAM,sBAAsB,EAAE,OAAO;AAAA;AAAA,EAE1C,UAAU;AACZ,CAAC;AAWM,IAAM,4BAA4B,oBAAoB,OAAO;AAAA;AAAA,EAElE,aAAa;AACf,CAAC;;;ADOM,SAAS,iBAAiB,SAAmD;AAClF,QAAM,mBAAmB,SAAS,qBAAqB,OAAO;AAE9D,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,MACb,KAAK,iBAAiB;AAAA,IACxB,CAAC;AAAA,EACH;AACF;AAqBO,SAAS,uBAAuB,SAAyD;AAC9F,eAAa;AACb,QAAM,mBAAmB,SAAS,2BAA2B,OAAO;AAEpE,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,MACb,KAAK,iBAAiB;AAAA,MACtB,SAAS;AAAA,QACP,gBAAgB,iBAAiB;AAAA,MACnC;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|