@settlemint/sdk-portal 1.2.5 → 2.0.0
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 +11 -21
- package/dist/portal.cjs +9 -31
- package/dist/portal.cjs.map +1 -1
- package/dist/portal.d.cts +3 -28
- package/dist/portal.d.ts +3 -28
- package/dist/portal.mjs +10 -32
- package/dist/portal.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ For detailed information about using the Smart Contract Portal Middleware, check
|
|
|
54
54
|
|
|
55
55
|
> **createPortalClient**\<`Setup`\>(`options`, `clientOptions`?): `object`
|
|
56
56
|
|
|
57
|
-
Defined in: [sdk/portal/src/portal.ts:
|
|
57
|
+
Defined in: [sdk/portal/src/portal.ts:61](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L61)
|
|
58
58
|
|
|
59
59
|
Creates a Portal GraphQL client with the provided configuration.
|
|
60
60
|
|
|
@@ -68,7 +68,10 @@ Creates a Portal GraphQL client with the provided configuration.
|
|
|
68
68
|
|
|
69
69
|
| Parameter | Type | Description |
|
|
70
70
|
| ------ | ------ | ------ |
|
|
71
|
-
| `options` |
|
|
71
|
+
| `options` | \{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instance`: `string`; \} | Configuration options for the Portal client |
|
|
72
|
+
| `options.accessToken` | `string` | - |
|
|
73
|
+
| `options.cache`? | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | - |
|
|
74
|
+
| `options.instance`? | `string` | - |
|
|
72
75
|
| `clientOptions`? | `RequestConfig` | Additional GraphQL client configuration options |
|
|
73
76
|
|
|
74
77
|
##### Returns
|
|
@@ -79,8 +82,8 @@ An object containing the configured GraphQL client and graphql helper function
|
|
|
79
82
|
|
|
80
83
|
| Name | Type | Defined in |
|
|
81
84
|
| ------ | ------ | ------ |
|
|
82
|
-
| `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:
|
|
83
|
-
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:
|
|
85
|
+
| `client` | `GraphQLClient` | [sdk/portal/src/portal.ts:65](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L65) |
|
|
86
|
+
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/portal/src/portal.ts:66](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L66) |
|
|
84
87
|
|
|
85
88
|
##### Throws
|
|
86
89
|
|
|
@@ -92,7 +95,6 @@ If the provided options fail validation
|
|
|
92
95
|
import { createPortalClient } from '@settlemint/sdk-portal';
|
|
93
96
|
import type { introspection } from "@schemas/portal-env";
|
|
94
97
|
|
|
95
|
-
// Server-side usage
|
|
96
98
|
export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{
|
|
97
99
|
introspection: introspection;
|
|
98
100
|
disableMasking: true;
|
|
@@ -102,20 +104,9 @@ export const { client: portalClient, graphql: portalGraphql } = createPortalClie
|
|
|
102
104
|
};
|
|
103
105
|
}>({
|
|
104
106
|
instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
|
|
105
|
-
runtime: "server",
|
|
106
107
|
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
// Browser-side usage
|
|
110
|
-
export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{
|
|
111
|
-
introspection: introspection;
|
|
112
|
-
disableMasking: true;
|
|
113
|
-
scalars: {
|
|
114
|
-
// Change unknown to the type you are using to store metadata
|
|
115
|
-
JSON: unknown;
|
|
116
|
-
};
|
|
117
|
-
}>({});
|
|
118
|
-
|
|
119
110
|
// Making GraphQL queries
|
|
120
111
|
const query = graphql(`
|
|
121
112
|
query GetPendingTransactions {
|
|
@@ -134,7 +125,7 @@ const result = await client.request(query);
|
|
|
134
125
|
|
|
135
126
|
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
|
|
136
127
|
|
|
137
|
-
Defined in: [sdk/portal/src/portal.ts:
|
|
128
|
+
Defined in: [sdk/portal/src/portal.ts:24](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L24)
|
|
138
129
|
|
|
139
130
|
Type representing the validated client options.
|
|
140
131
|
|
|
@@ -144,7 +135,7 @@ Type representing the validated client options.
|
|
|
144
135
|
|
|
145
136
|
> **RequestConfig** = `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
|
|
146
137
|
|
|
147
|
-
Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/
|
|
138
|
+
Defined in: [sdk/portal/src/portal.ts:10](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L10)
|
|
148
139
|
|
|
149
140
|
Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
|
|
150
141
|
|
|
@@ -152,12 +143,11 @@ Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.
|
|
|
152
143
|
|
|
153
144
|
#### ClientOptionsSchema
|
|
154
145
|
|
|
155
|
-
> `const` **ClientOptionsSchema**: `
|
|
146
|
+
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString`; `cache`: `ZodOptional`\<`ZodEnum`\<\[`"default"`, `"force-cache"`, `"no-cache"`, `"no-store"`, `"only-if-cached"`, `"reload"`\]\>\>; `instance`: `ZodUnion`\<\[`ZodString`, `ZodString`\]\>; \}, `"strip"`, `ZodTypeAny`, \{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instance`: `string`; \}, \{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instance`: `string`; \}\>
|
|
156
147
|
|
|
157
|
-
Defined in: [sdk/portal/src/portal.ts:
|
|
148
|
+
Defined in: [sdk/portal/src/portal.ts:15](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/portal/src/portal.ts#L15)
|
|
158
149
|
|
|
159
150
|
Schema for validating Portal client configuration options.
|
|
160
|
-
Discriminates between server and browser runtime environments.
|
|
161
151
|
|
|
162
152
|
## Contributing
|
|
163
153
|
|
package/dist/portal.cjs
CHANGED
|
@@ -31,42 +31,20 @@ var import_gql = require("gql.tada");
|
|
|
31
31
|
var import_graphql_request = require("graphql-request");
|
|
32
32
|
var import_zod = require("zod");
|
|
33
33
|
var import_gql2 = require("gql.tada");
|
|
34
|
-
var ClientOptionsSchema = import_zod.z.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
40
|
-
}),
|
|
41
|
-
import_zod.z.object({
|
|
42
|
-
runtime: import_zod.z.literal("browser"),
|
|
43
|
-
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
44
|
-
})
|
|
45
|
-
]);
|
|
46
|
-
function getFullUrl(options) {
|
|
47
|
-
return options.runtime === "server" ? new URL(options.instance).toString() : new URL("/proxy/portal/graphql", window?.location?.origin ?? "http://localhost:3000").toString();
|
|
48
|
-
}
|
|
49
|
-
function getHeaders(options) {
|
|
50
|
-
if (options.runtime === "server") {
|
|
51
|
-
return {
|
|
52
|
-
headers: {
|
|
53
|
-
"x-auth-token": options.accessToken
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
34
|
+
var ClientOptionsSchema = import_zod.z.object({
|
|
35
|
+
instance: import_validation.UrlOrPathSchema,
|
|
36
|
+
accessToken: import_validation.ApplicationAccessTokenSchema,
|
|
37
|
+
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
38
|
+
});
|
|
59
39
|
function createPortalClient(options, clientOptions) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
runtime: import_runtime.runsOnServer ? "server" : "browser"
|
|
63
|
-
});
|
|
40
|
+
(0, import_runtime.ensureServer)();
|
|
41
|
+
const validatedOptions = (0, import_validation.validate)(ClientOptionsSchema, options);
|
|
64
42
|
const graphql = (0, import_gql.initGraphQLTada)();
|
|
65
|
-
const fullUrl =
|
|
43
|
+
const fullUrl = new URL(validatedOptions.instance).toString();
|
|
66
44
|
return {
|
|
67
45
|
client: new import_graphql_request.GraphQLClient(fullUrl, {
|
|
68
46
|
...clientOptions,
|
|
69
|
-
...
|
|
47
|
+
headers: { ...clientOptions?.headers ?? {}, "x-auth-token": validatedOptions.accessToken }
|
|
70
48
|
}),
|
|
71
49
|
graphql
|
|
72
50
|
};
|
package/dist/portal.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/portal.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/portal.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod\";\n\n/**\n * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating Portal client configuration options.\n */\nexport const ClientOptionsSchema = z.object({\n instance: UrlOrPathSchema,\n accessToken: ApplicationAccessTokenSchema,\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Creates a Portal GraphQL client with the provided configuration.\n *\n * @param options - Configuration options for the Portal client\n * @param clientOptions - Additional GraphQL client configuration options\n * @returns An object containing the configured GraphQL client and graphql helper function\n * @throws If the provided options fail validation\n *\n * @example\n * import { createPortalClient } from '@settlemint/sdk-portal';\n * import type { introspection } from \"@schemas/portal-env\";\n *\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetPendingTransactions {\n * getPendingTransactions {\n * count\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createPortalClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = new URL(validatedOptions.instance).toString();\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: { ...(clientOptions?.headers ?? {}), \"x-auth-token\": validatedOptions.accessToken },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AA6ElB,IAAAA,cAA6B;AAnEtB,IAAM,sBAAsB,aAAE,OAAO;AAAA,EAC1C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AACzG,CAAC;AA0CM,SAAS,mBACd,SACA,eAIA;AACA,mCAAa;AACb,QAAM,uBAAmB,4BAAS,qBAAqB,OAAO;AAC9D,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,IAAI,IAAI,iBAAiB,QAAQ,EAAE,SAAS;AAE5D,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,EAAE,GAAI,eAAe,WAAW,CAAC,GAAI,gBAAgB,iBAAiB,YAAY;AAAA,IAC7F,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql"]}
|
package/dist/portal.d.cts
CHANGED
|
@@ -9,33 +9,20 @@ import { z } from 'zod';
|
|
|
9
9
|
type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
10
10
|
/**
|
|
11
11
|
* Schema for validating Portal client configuration options.
|
|
12
|
-
* Discriminates between server and browser runtime environments.
|
|
13
12
|
*/
|
|
14
|
-
declare const ClientOptionsSchema: z.
|
|
13
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
15
14
|
instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
|
|
16
|
-
runtime: z.ZodLiteral<"server">;
|
|
17
15
|
accessToken: z.ZodString;
|
|
18
16
|
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
19
17
|
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
runtime: "server";
|
|
21
18
|
instance: string;
|
|
22
19
|
accessToken: string;
|
|
23
20
|
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
24
21
|
}, {
|
|
25
|
-
runtime: "server";
|
|
26
22
|
instance: string;
|
|
27
23
|
accessToken: string;
|
|
28
24
|
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
29
|
-
}
|
|
30
|
-
runtime: z.ZodLiteral<"browser">;
|
|
31
|
-
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
runtime: "browser";
|
|
34
|
-
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
35
|
-
}, {
|
|
36
|
-
runtime: "browser";
|
|
37
|
-
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
38
|
-
}>]>;
|
|
25
|
+
}>;
|
|
39
26
|
/**
|
|
40
27
|
* Type representing the validated client options.
|
|
41
28
|
*/
|
|
@@ -52,7 +39,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
52
39
|
* import { createPortalClient } from '@settlemint/sdk-portal';
|
|
53
40
|
* import type { introspection } from "@schemas/portal-env";
|
|
54
41
|
*
|
|
55
|
-
* // Server-side usage
|
|
56
42
|
* export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{
|
|
57
43
|
* introspection: introspection;
|
|
58
44
|
* disableMasking: true;
|
|
@@ -62,20 +48,9 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
62
48
|
* };
|
|
63
49
|
* }>({
|
|
64
50
|
* instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
|
|
65
|
-
* runtime: "server",
|
|
66
51
|
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
67
52
|
* });
|
|
68
53
|
*
|
|
69
|
-
* // Browser-side usage
|
|
70
|
-
* export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{
|
|
71
|
-
* introspection: introspection;
|
|
72
|
-
* disableMasking: true;
|
|
73
|
-
* scalars: {
|
|
74
|
-
* // Change unknown to the type you are using to store metadata
|
|
75
|
-
* JSON: unknown;
|
|
76
|
-
* };
|
|
77
|
-
* }>({});
|
|
78
|
-
*
|
|
79
54
|
* // Making GraphQL queries
|
|
80
55
|
* const query = graphql(`
|
|
81
56
|
* query GetPendingTransactions {
|
|
@@ -87,7 +62,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
87
62
|
*
|
|
88
63
|
* const result = await client.request(query);
|
|
89
64
|
*/
|
|
90
|
-
declare function createPortalClient<const Setup extends AbstractSetupSchema>(options:
|
|
65
|
+
declare function createPortalClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
|
|
91
66
|
client: GraphQLClient;
|
|
92
67
|
graphql: initGraphQLTada<Setup>;
|
|
93
68
|
};
|
package/dist/portal.d.ts
CHANGED
|
@@ -9,33 +9,20 @@ import { z } from 'zod';
|
|
|
9
9
|
type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
10
10
|
/**
|
|
11
11
|
* Schema for validating Portal client configuration options.
|
|
12
|
-
* Discriminates between server and browser runtime environments.
|
|
13
12
|
*/
|
|
14
|
-
declare const ClientOptionsSchema: z.
|
|
13
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
15
14
|
instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
|
|
16
|
-
runtime: z.ZodLiteral<"server">;
|
|
17
15
|
accessToken: z.ZodString;
|
|
18
16
|
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
19
17
|
}, "strip", z.ZodTypeAny, {
|
|
20
|
-
runtime: "server";
|
|
21
18
|
instance: string;
|
|
22
19
|
accessToken: string;
|
|
23
20
|
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
24
21
|
}, {
|
|
25
|
-
runtime: "server";
|
|
26
22
|
instance: string;
|
|
27
23
|
accessToken: string;
|
|
28
24
|
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
29
|
-
}
|
|
30
|
-
runtime: z.ZodLiteral<"browser">;
|
|
31
|
-
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
runtime: "browser";
|
|
34
|
-
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
35
|
-
}, {
|
|
36
|
-
runtime: "browser";
|
|
37
|
-
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
38
|
-
}>]>;
|
|
25
|
+
}>;
|
|
39
26
|
/**
|
|
40
27
|
* Type representing the validated client options.
|
|
41
28
|
*/
|
|
@@ -52,7 +39,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
52
39
|
* import { createPortalClient } from '@settlemint/sdk-portal';
|
|
53
40
|
* import type { introspection } from "@schemas/portal-env";
|
|
54
41
|
*
|
|
55
|
-
* // Server-side usage
|
|
56
42
|
* export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{
|
|
57
43
|
* introspection: introspection;
|
|
58
44
|
* disableMasking: true;
|
|
@@ -62,20 +48,9 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
62
48
|
* };
|
|
63
49
|
* }>({
|
|
64
50
|
* instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,
|
|
65
|
-
* runtime: "server",
|
|
66
51
|
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
67
52
|
* });
|
|
68
53
|
*
|
|
69
|
-
* // Browser-side usage
|
|
70
|
-
* export const { client: portalBrowserClient, graphql: portalBrowserGraphql } = createPortalClient<{
|
|
71
|
-
* introspection: introspection;
|
|
72
|
-
* disableMasking: true;
|
|
73
|
-
* scalars: {
|
|
74
|
-
* // Change unknown to the type you are using to store metadata
|
|
75
|
-
* JSON: unknown;
|
|
76
|
-
* };
|
|
77
|
-
* }>({});
|
|
78
|
-
*
|
|
79
54
|
* // Making GraphQL queries
|
|
80
55
|
* const query = graphql(`
|
|
81
56
|
* query GetPendingTransactions {
|
|
@@ -87,7 +62,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
87
62
|
*
|
|
88
63
|
* const result = await client.request(query);
|
|
89
64
|
*/
|
|
90
|
-
declare function createPortalClient<const Setup extends AbstractSetupSchema>(options:
|
|
65
|
+
declare function createPortalClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
|
|
91
66
|
client: GraphQLClient;
|
|
92
67
|
graphql: initGraphQLTada<Setup>;
|
|
93
68
|
};
|
package/dist/portal.mjs
CHANGED
|
@@ -1,46 +1,24 @@
|
|
|
1
1
|
// src/portal.ts
|
|
2
|
-
import {
|
|
2
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
3
3
|
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
4
4
|
import { initGraphQLTada } from "gql.tada";
|
|
5
5
|
import { GraphQLClient } from "graphql-request";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { readFragment } from "gql.tada";
|
|
8
|
-
var ClientOptionsSchema = z.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
14
|
-
}),
|
|
15
|
-
z.object({
|
|
16
|
-
runtime: z.literal("browser"),
|
|
17
|
-
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
18
|
-
})
|
|
19
|
-
]);
|
|
20
|
-
function getFullUrl(options) {
|
|
21
|
-
return options.runtime === "server" ? new URL(options.instance).toString() : new URL("/proxy/portal/graphql", window?.location?.origin ?? "http://localhost:3000").toString();
|
|
22
|
-
}
|
|
23
|
-
function getHeaders(options) {
|
|
24
|
-
if (options.runtime === "server") {
|
|
25
|
-
return {
|
|
26
|
-
headers: {
|
|
27
|
-
"x-auth-token": options.accessToken
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
8
|
+
var ClientOptionsSchema = z.object({
|
|
9
|
+
instance: UrlOrPathSchema,
|
|
10
|
+
accessToken: ApplicationAccessTokenSchema,
|
|
11
|
+
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
12
|
+
});
|
|
33
13
|
function createPortalClient(options, clientOptions) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
runtime: runsOnServer ? "server" : "browser"
|
|
37
|
-
});
|
|
14
|
+
ensureServer();
|
|
15
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
38
16
|
const graphql = initGraphQLTada();
|
|
39
|
-
const fullUrl =
|
|
17
|
+
const fullUrl = new URL(validatedOptions.instance).toString();
|
|
40
18
|
return {
|
|
41
19
|
client: new GraphQLClient(fullUrl, {
|
|
42
20
|
...clientOptions,
|
|
43
|
-
...
|
|
21
|
+
headers: { ...clientOptions?.headers ?? {}, "x-auth-token": validatedOptions.accessToken }
|
|
44
22
|
}),
|
|
45
23
|
graphql
|
|
46
24
|
};
|
package/dist/portal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/portal.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/portal.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod\";\n\n/**\n * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating Portal client configuration options.\n */\nexport const ClientOptionsSchema = z.object({\n instance: UrlOrPathSchema,\n accessToken: ApplicationAccessTokenSchema,\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Creates a Portal GraphQL client with the provided configuration.\n *\n * @param options - Configuration options for the Portal client\n * @param clientOptions - Additional GraphQL client configuration options\n * @returns An object containing the configured GraphQL client and graphql helper function\n * @throws If the provided options fail validation\n *\n * @example\n * import { createPortalClient } from '@settlemint/sdk-portal';\n * import type { introspection } from \"@schemas/portal-env\";\n *\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * // Change unknown to the type you are using to store metadata\n * JSON: unknown;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetPendingTransactions {\n * getPendingTransactions {\n * count\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createPortalClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = new URL(validatedOptions.instance).toString();\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: { ...(clientOptions?.headers ?? {}), \"x-auth-token\": validatedOptions.accessToken },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B,iBAAiB,gBAAgB;AACxE,SAAmC,uBAAuB;AAC1D,SAAS,qBAAqB;AAC9B,SAAS,SAAS;AA6ElB,SAAS,oBAAoB;AAnEtB,IAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AACzG,CAAC;AA0CM,SAAS,mBACd,SACA,eAIA;AACA,eAAa;AACb,QAAM,mBAAmB,SAAS,qBAAqB,OAAO;AAC9D,QAAM,UAAU,gBAAuB;AACvC,QAAM,UAAU,IAAI,IAAI,iBAAiB,QAAQ,EAAE,SAAS;AAE5D,SAAO;AAAA,IACL,QAAQ,IAAI,cAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,EAAE,GAAI,eAAe,WAAW,CAAC,GAAI,gBAAgB,iBAAiB,YAAY;AAAA,IAC7F,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-portal",
|
|
3
3
|
"description": "Portal API client module for SettleMint SDK, providing access to smart contract portal services and APIs",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"gql.tada": "^1",
|
|
55
|
-
"@settlemint/sdk-utils": "
|
|
55
|
+
"@settlemint/sdk-utils": "2.0.0",
|
|
56
56
|
"graphql-request": "^7",
|
|
57
57
|
"zod": "^3"
|
|
58
58
|
},
|