@settlemint/sdk-blockscout 1.2.5 → 2.0.0-pr831671fa

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 CHANGED
@@ -52,7 +52,7 @@ For detailed information about using Blockscout with the SettleMint platform, ch
52
52
 
53
53
  > **createBlockscoutClient**\<`Setup`\>(`options`, `clientOptions`?): `object`
54
54
 
55
- Defined in: [sdk/blockscout/src/blockscout.ts:108](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L108)
55
+ Defined in: [sdk/blockscout/src/blockscout.ts:70](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L70)
56
56
 
57
57
  Creates a Blockscout GraphQL client with proper type safety using gql.tada
58
58
 
@@ -66,7 +66,9 @@ Creates a Blockscout GraphQL client with proper type safety using gql.tada
66
66
 
67
67
  | Parameter | Type | Description |
68
68
  | ------ | ------ | ------ |
69
- | `options` | `Omit`\<\{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `runtime`: `"browser"`; \}, `"runtime"`\> & `Record`\<`string`, `unknown`\> | Configuration options for the client |
69
+ | `options` | \{ `accessToken`: `string`; `instance`: `string`; \} | Configuration options for the client |
70
+ | `options.accessToken` | `string` | - |
71
+ | `options.instance`? | `string` | - |
70
72
  | `clientOptions`? | `RequestConfig` | Optional GraphQL client configuration options |
71
73
 
72
74
  ##### Returns
@@ -77,8 +79,8 @@ An object containing the GraphQL client and initialized gql.tada function
77
79
 
78
80
  | Name | Type | Defined in |
79
81
  | ------ | ------ | ------ |
80
- | `client` | `GraphQLClient` | [sdk/blockscout/src/blockscout.ts:112](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L112) |
81
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/blockscout/src/blockscout.ts:113](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L113) |
82
+ | `client` | `GraphQLClient` | [sdk/blockscout/src/blockscout.ts:74](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L74) |
83
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/blockscout/src/blockscout.ts:75](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L75) |
82
84
 
83
85
  ##### Throws
84
86
 
@@ -90,7 +92,6 @@ Will throw an error if the options fail validation
90
92
  import { createBlockscoutClient } from '@settlemint/sdk-blockscout';
91
93
  import type { introspection } from "@schemas/blockscout-env";
92
94
 
93
- // Server-side usage
94
95
  const { client, graphql } = createBlockscoutClient<{
95
96
  introspection: introspection;
96
97
  disableMasking: true;
@@ -109,22 +110,6 @@ const { client, graphql } = createBlockscoutClient<{
109
110
  accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
110
111
  });
111
112
 
112
- // Browser-side usage
113
- const { client, graphql } = createBlockscoutClient<{
114
- introspection: introspection;
115
- disableMasking: true;
116
- scalars: {
117
- AddressHash: string;
118
- Data: string;
119
- DateTime: string;
120
- Decimal: string;
121
- FullHash: string;
122
- Json: string;
123
- NonceHash: string;
124
- Wei: string;
125
- };
126
- }>({});
127
-
128
113
  // Making GraphQL queries
129
114
  const query = graphql(`
130
115
  query GetTransaction($hash: String!) {
@@ -148,7 +133,7 @@ const result = await client.request(query, {
148
133
 
149
134
  > **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
150
135
 
151
- Defined in: [sdk/blockscout/src/blockscout.ts:32](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L32)
136
+ Defined in: [sdk/blockscout/src/blockscout.ts:23](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L23)
152
137
 
153
138
  Type definition for client options derived from the ClientOptionsSchema
154
139
 
@@ -158,7 +143,7 @@ Type definition for client options derived from the ClientOptionsSchema
158
143
 
159
144
  > **RequestConfig** = `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
160
145
 
161
- Defined in: [sdk/blockscout/src/blockscout.ts:10](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L10)
146
+ Defined in: [sdk/blockscout/src/blockscout.ts:10](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L10)
162
147
 
163
148
  Type definition for GraphQL client configuration options
164
149
 
@@ -166,14 +151,11 @@ Type definition for GraphQL client configuration options
166
151
 
167
152
  #### ClientOptionsSchema
168
153
 
169
- > `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<`"runtime"`, \[`ZodObject`\<\{ `accessToken`: `ZodString`; `instance`: `ZodUnion`\<\[`ZodString`, `ZodString`\]\>; `runtime`: `ZodLiteral`\<`"server"`\>; \}, `"strip"`, `ZodTypeAny`, \{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \}, \{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \}\>, `ZodObject`\<\{ `runtime`: `ZodLiteral`\<`"browser"`\>; \}, `"strip"`, `ZodTypeAny`, \{ `runtime`: `"browser"`; \}, \{ `runtime`: `"browser"`; \}\>\]\>
154
+ > `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString`; `instance`: `ZodUnion`\<\[`ZodString`, `ZodString`\]\>; \}, `"strip"`, `ZodTypeAny`, \{ `accessToken`: `string`; `instance`: `string`; \}, \{ `accessToken`: `string`; `instance`: `string`; \}\>
170
155
 
171
- Defined in: [sdk/blockscout/src/blockscout.ts:18](https://github.com/settlemint/sdk/blob/v1.2.5/sdk/blockscout/src/blockscout.ts#L18)
156
+ Defined in: [sdk/blockscout/src/blockscout.ts:15](https://github.com/settlemint/sdk/blob/v2.0.0/sdk/blockscout/src/blockscout.ts#L15)
172
157
 
173
158
  Schema for validating client options for the Blockscout client.
174
- Defines two possible runtime configurations:
175
- 1. Server-side with instance URL and access token
176
- 2. Browser-side with no additional configuration needed
177
159
 
178
160
  ## Contributing
179
161
 
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of f(e))!g.call(t,n)&&n!==r&&s(t,n,{get:()=>e[n],enumerable:!(a=h(e,n))||a.enumerable});return t};var C=t=>d(s({},"__esModule",{value:!0}),t);var b={};S(b,{ClientOptionsSchema:()=>m,createBlockscoutClient:()=>x,readFragment:()=>u.readFragment});module.exports=C(b);var p=require("@settlemint/sdk-utils/runtime"),i=require("@settlemint/sdk-utils/validation"),c=require("gql.tada"),l=require("graphql-request"),o=require("zod"),u=require("gql.tada"),m=o.z.discriminatedUnion("runtime",[o.z.object({instance:i.UrlOrPathSchema,runtime:o.z.literal("server"),accessToken:i.ApplicationAccessTokenSchema}),o.z.object({runtime:o.z.literal("browser")})]);function O(t){return t.runtime==="server"?new URL(t.instance).toString():new URL("/proxy/blockscout/graphql",window?.location?.origin??"http://localhost:3000").toString()}function x(t,e){let r=(0,i.validate)(m,{...t,runtime:p.runsOnServer?"server":"browser"}),a=(0,c.initGraphQLTada)(),n=O(r);return{client:new l.GraphQLClient(n,{...e,...r.runtime==="server"&&{headers:{"x-auth-token":r.accessToken}}}),graphql:a}}0&&(module.exports={ClientOptionsSchema,createBlockscoutClient,readFragment});
1
+ "use strict";var p=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},d=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!S.call(t,n)&&n!==r&&p(t,n,{get:()=>e[n],enumerable:!(a=h(e,n))||a.enumerable});return t};var g=t=>d(p({},"__esModule",{value:!0}),t);var O={};C(O,{ClientOptionsSchema:()=>m,createBlockscoutClient:()=>x,readFragment:()=>f.readFragment});module.exports=g(O);var i=require("@settlemint/sdk-utils/runtime"),o=require("@settlemint/sdk-utils/validation"),s=require("gql.tada"),c=require("graphql-request"),l=require("zod"),f=require("gql.tada"),m=l.z.object({instance:o.UrlOrPathSchema,accessToken:o.ApplicationAccessTokenSchema});function x(t,e){(0,i.ensureServer)();let r=(0,o.validate)(m,t),a=(0,s.initGraphQLTada)(),n=new URL(r.instance).toString();return{client:new c.GraphQLClient(n,{...e,headers:{...e?.headers??{},"x-auth-token":r.accessToken}}),graphql:a}}0&&(module.exports={ClientOptionsSchema,createBlockscoutClient,readFragment});
2
2
  //# sourceMappingURL=blockscout.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/blockscout.ts"],"sourcesContent":["import { runsOnServer } 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 * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the Blockscout client.\n * Defines two possible runtime configurations:\n * 1. Server-side with instance URL and access token\n * 2. Browser-side with no additional configuration needed\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instance: UrlOrPathSchema,\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n }),\n]);\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for the Blockscout GraphQL API based on the provided options\n *\n * @param options - The client options for configuring the Blockscout client\n * @returns The complete GraphQL API URL as a string\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/blockscout/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\n\n/**\n * Creates a Blockscout GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing the GraphQL client and initialized gql.tada function\n * @throws Will throw an error if the options fail validation\n * @example\n * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';\n * import type { introspection } from \"@schemas/blockscout-env\";\n *\n * // Server-side usage\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Browser-side usage\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({});\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetTransaction($hash: String!) {\n * transaction(hash: $hash) {\n * hash\n * blockNumber\n * value\n * gasUsed\n * }\n * }\n * `);\n *\n * const result = await client.request(query, {\n * hash: \"0x123abc...\"\n * });\n */\nexport function createBlockscoutClient<const Setup extends AbstractSetupSchema>(\n options: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,2BAAAC,EAAA,iDAAAC,EAAAJ,GAAA,IAAAK,EAA6B,yCAC7BC,EAAwE,4CACxEC,EAA0D,oBAC1DC,EAA8B,2BAC9BC,EAAkB,eAkIlBF,EAA6B,oBArHhBG,EAAsB,IAAE,mBAAmB,UAAW,CACjE,IAAE,OAAO,CACP,SAAU,kBACV,QAAS,IAAE,QAAQ,QAAQ,EAC3B,YAAa,8BACf,CAAC,EACD,IAAE,OAAO,CACP,QAAS,IAAE,QAAQ,SAAS,CAC9B,CAAC,CACH,CAAC,EAaD,SAASC,EAAWC,EAAgC,CAClD,OAAOA,EAAQ,UAAY,SACvB,IAAI,IAAIA,EAAQ,QAAQ,EAAE,SAAS,EACnC,IAAI,IAAI,4BAA6B,QAAQ,UAAU,QAAU,uBAAuB,EAAE,SAAS,CACzG,CAgEO,SAASC,EACdD,EACAE,EAIA,CACA,IAAMC,KAAmB,YAASL,EAAqB,CACrD,GAAGE,EACH,QAAS,eAAe,SAAW,SACrC,CAAC,EACKI,KAAU,mBAAuB,EACjCC,EAAUN,EAAWI,CAAgB,EAE3C,MAAO,CACL,OAAQ,IAAI,gBAAcE,EAAS,CACjC,GAAGH,EACH,GAAIC,EAAiB,UAAY,UAAY,CAC3C,QAAS,CACP,eAAgBA,EAAiB,WACnC,CACF,CACF,CAAC,EACD,QAAAC,CACF,CACF","names":["blockscout_exports","__export","ClientOptionsSchema","createBlockscoutClient","__toCommonJS","import_runtime","import_validation","import_gql","import_graphql_request","import_zod","ClientOptionsSchema","getFullUrl","options","createBlockscoutClient","clientOptions","validatedOptions","graphql","fullUrl"]}
1
+ {"version":3,"sources":["../src/blockscout.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 * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the Blockscout client.\n */\nexport const ClientOptionsSchema = z.object({\n instance: UrlOrPathSchema,\n accessToken: ApplicationAccessTokenSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Creates a Blockscout GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing the GraphQL client and initialized gql.tada function\n * @throws Will throw an error if the options fail validation\n * @example\n * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';\n * import type { introspection } from \"@schemas/blockscout-env\";\n *\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetTransaction($hash: String!) {\n * transaction(hash: $hash) {\n * hash\n * blockNumber\n * value\n * gasUsed\n * }\n * }\n * `);\n *\n * const result = await client.request(query, {\n * hash: \"0x123abc...\"\n * });\n */\nexport function createBlockscoutClient<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: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,2BAAAC,EAAA,iDAAAC,EAAAJ,GAAA,IAAAK,EAA6B,yCAC7BC,EAAwE,4CACxEC,EAA0D,oBAC1DC,EAA8B,2BAC9BC,EAAkB,eAyFlBF,EAA6B,oBA/EhBG,EAAsB,IAAE,OAAO,CAC1C,SAAU,kBACV,YAAa,8BACf,CAAC,EAoDM,SAASC,EACdC,EACAC,EAIA,IACA,gBAAa,EACb,IAAMC,KAAmB,YAASJ,EAAqBE,CAAO,EACxDG,KAAU,mBAAuB,EACjCC,EAAU,IAAI,IAAIF,EAAiB,QAAQ,EAAE,SAAS,EAE5D,MAAO,CACL,OAAQ,IAAI,gBAAcE,EAAS,CACjC,GAAGH,EACH,QAAS,CACP,GAAIA,GAAe,SAAW,CAAC,EAC/B,eAAgBC,EAAiB,WACnC,CACF,CAAC,EACD,QAAAC,CACF,CACF","names":["blockscout_exports","__export","ClientOptionsSchema","createBlockscoutClient","__toCommonJS","import_runtime","import_validation","import_gql","import_graphql_request","import_zod","ClientOptionsSchema","createBlockscoutClient","options","clientOptions","validatedOptions","graphql","fullUrl"]}
@@ -9,29 +9,17 @@ import { z } from 'zod';
9
9
  type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
10
10
  /**
11
11
  * Schema for validating client options for the Blockscout client.
12
- * Defines two possible runtime configurations:
13
- * 1. Server-side with instance URL and access token
14
- * 2. Browser-side with no additional configuration needed
15
12
  */
16
- declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObject<{
13
+ declare const ClientOptionsSchema: z.ZodObject<{
17
14
  instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
18
- runtime: z.ZodLiteral<"server">;
19
15
  accessToken: z.ZodString;
20
16
  }, "strip", z.ZodTypeAny, {
21
- runtime: "server";
22
17
  instance: string;
23
18
  accessToken: string;
24
19
  }, {
25
- runtime: "server";
26
20
  instance: string;
27
21
  accessToken: string;
28
- }>, z.ZodObject<{
29
- runtime: z.ZodLiteral<"browser">;
30
- }, "strip", z.ZodTypeAny, {
31
- runtime: "browser";
32
- }, {
33
- runtime: "browser";
34
- }>]>;
22
+ }>;
35
23
  /**
36
24
  * Type definition for client options derived from the ClientOptionsSchema
37
25
  */
@@ -47,7 +35,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
47
35
  * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';
48
36
  * import type { introspection } from "@schemas/blockscout-env";
49
37
  *
50
- * // Server-side usage
51
38
  * const { client, graphql } = createBlockscoutClient<{
52
39
  * introspection: introspection;
53
40
  * disableMasking: true;
@@ -66,22 +53,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
66
53
  * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
67
54
  * });
68
55
  *
69
- * // Browser-side usage
70
- * const { client, graphql } = createBlockscoutClient<{
71
- * introspection: introspection;
72
- * disableMasking: true;
73
- * scalars: {
74
- * AddressHash: string;
75
- * Data: string;
76
- * DateTime: string;
77
- * Decimal: string;
78
- * FullHash: string;
79
- * Json: string;
80
- * NonceHash: string;
81
- * Wei: string;
82
- * };
83
- * }>({});
84
- *
85
56
  * // Making GraphQL queries
86
57
  * const query = graphql(`
87
58
  * query GetTransaction($hash: String!) {
@@ -98,7 +69,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
98
69
  * hash: "0x123abc..."
99
70
  * });
100
71
  */
101
- declare function createBlockscoutClient<const Setup extends AbstractSetupSchema>(options: Omit<ClientOptions, "runtime"> & Record<string, unknown>, clientOptions?: RequestConfig): {
72
+ declare function createBlockscoutClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
102
73
  client: GraphQLClient;
103
74
  graphql: initGraphQLTada<Setup>;
104
75
  };
@@ -9,29 +9,17 @@ import { z } from 'zod';
9
9
  type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
10
10
  /**
11
11
  * Schema for validating client options for the Blockscout client.
12
- * Defines two possible runtime configurations:
13
- * 1. Server-side with instance URL and access token
14
- * 2. Browser-side with no additional configuration needed
15
12
  */
16
- declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObject<{
13
+ declare const ClientOptionsSchema: z.ZodObject<{
17
14
  instance: z.ZodUnion<[z.ZodString, z.ZodString]>;
18
- runtime: z.ZodLiteral<"server">;
19
15
  accessToken: z.ZodString;
20
16
  }, "strip", z.ZodTypeAny, {
21
- runtime: "server";
22
17
  instance: string;
23
18
  accessToken: string;
24
19
  }, {
25
- runtime: "server";
26
20
  instance: string;
27
21
  accessToken: string;
28
- }>, z.ZodObject<{
29
- runtime: z.ZodLiteral<"browser">;
30
- }, "strip", z.ZodTypeAny, {
31
- runtime: "browser";
32
- }, {
33
- runtime: "browser";
34
- }>]>;
22
+ }>;
35
23
  /**
36
24
  * Type definition for client options derived from the ClientOptionsSchema
37
25
  */
@@ -47,7 +35,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
47
35
  * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';
48
36
  * import type { introspection } from "@schemas/blockscout-env";
49
37
  *
50
- * // Server-side usage
51
38
  * const { client, graphql } = createBlockscoutClient<{
52
39
  * introspection: introspection;
53
40
  * disableMasking: true;
@@ -66,22 +53,6 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
66
53
  * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
67
54
  * });
68
55
  *
69
- * // Browser-side usage
70
- * const { client, graphql } = createBlockscoutClient<{
71
- * introspection: introspection;
72
- * disableMasking: true;
73
- * scalars: {
74
- * AddressHash: string;
75
- * Data: string;
76
- * DateTime: string;
77
- * Decimal: string;
78
- * FullHash: string;
79
- * Json: string;
80
- * NonceHash: string;
81
- * Wei: string;
82
- * };
83
- * }>({});
84
- *
85
56
  * // Making GraphQL queries
86
57
  * const query = graphql(`
87
58
  * query GetTransaction($hash: String!) {
@@ -98,7 +69,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
98
69
  * hash: "0x123abc..."
99
70
  * });
100
71
  */
101
- declare function createBlockscoutClient<const Setup extends AbstractSetupSchema>(options: Omit<ClientOptions, "runtime"> & Record<string, unknown>, clientOptions?: RequestConfig): {
72
+ declare function createBlockscoutClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
102
73
  client: GraphQLClient;
103
74
  graphql: initGraphQLTada<Setup>;
104
75
  };
@@ -1,2 +1,2 @@
1
- import{runsOnServer as a}from"@settlemint/sdk-utils/runtime";import{ApplicationAccessTokenSchema as s,UrlOrPathSchema as p,validate as c}from"@settlemint/sdk-utils/validation";import{initGraphQLTada as l}from"gql.tada";import{GraphQLClient as m}from"graphql-request";import{z as t}from"zod";import{readFragment as y}from"gql.tada";var u=t.discriminatedUnion("runtime",[t.object({instance:p,runtime:t.literal("server"),accessToken:s}),t.object({runtime:t.literal("browser")})]);function h(e){return e.runtime==="server"?new URL(e.instance).toString():new URL("/proxy/blockscout/graphql",window?.location?.origin??"http://localhost:3000").toString()}function b(e,n){let r=c(u,{...e,runtime:a?"server":"browser"}),o=l(),i=h(r);return{client:new m(i,{...n,...r.runtime==="server"&&{headers:{"x-auth-token":r.accessToken}}}),graphql:o}}export{u as ClientOptionsSchema,b as createBlockscoutClient,y as readFragment};
1
+ import{ensureServer as a}from"@settlemint/sdk-utils/runtime";import{ApplicationAccessTokenSchema as p,UrlOrPathSchema as i,validate as s}from"@settlemint/sdk-utils/validation";import{initGraphQLTada as c}from"gql.tada";import{GraphQLClient as l}from"graphql-request";import{z as m}from"zod";import{readFragment as q}from"gql.tada";var f=m.object({instance:i,accessToken:p});function O(r,e){a();let t=s(f,r),n=c(),o=new URL(t.instance).toString();return{client:new l(o,{...e,headers:{...e?.headers??{},"x-auth-token":t.accessToken}}),graphql:n}}export{f as ClientOptionsSchema,O as createBlockscoutClient,q as readFragment};
2
2
  //# sourceMappingURL=blockscout.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/blockscout.ts"],"sourcesContent":["import { runsOnServer } 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 * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the Blockscout client.\n * Defines two possible runtime configurations:\n * 1. Server-side with instance URL and access token\n * 2. Browser-side with no additional configuration needed\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instance: UrlOrPathSchema,\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n }),\n]);\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for the Blockscout GraphQL API based on the provided options\n *\n * @param options - The client options for configuring the Blockscout client\n * @returns The complete GraphQL API URL as a string\n */\nfunction getFullUrl(options: ClientOptions): string {\n return options.runtime === \"server\"\n ? new URL(options.instance).toString()\n : new URL(\"/proxy/blockscout/graphql\", window?.location?.origin ?? \"http://localhost:3000\").toString();\n}\n\n/**\n * Creates a Blockscout GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing the GraphQL client and initialized gql.tada function\n * @throws Will throw an error if the options fail validation\n * @example\n * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';\n * import type { introspection } from \"@schemas/blockscout-env\";\n *\n * // Server-side usage\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Browser-side usage\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({});\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetTransaction($hash: String!) {\n * transaction(hash: $hash) {\n * hash\n * blockNumber\n * value\n * gasUsed\n * }\n * }\n * `);\n *\n * const result = await client.request(query, {\n * hash: \"0x123abc...\"\n * });\n */\nexport function createBlockscoutClient<const Setup extends AbstractSetupSchema>(\n options: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":"AAAA,OAAS,gBAAAA,MAAoB,gCAC7B,OAAS,gCAAAC,EAA8B,mBAAAC,EAAiB,YAAAC,MAAgB,mCACxE,OAAmC,mBAAAC,MAAuB,WAC1D,OAAS,iBAAAC,MAAqB,kBAC9B,OAAS,KAAAC,MAAS,MAkIlB,OAAS,gBAAAC,MAAoB,WArHtB,IAAMC,EAAsBF,EAAE,mBAAmB,UAAW,CACjEA,EAAE,OAAO,CACP,SAAUJ,EACV,QAASI,EAAE,QAAQ,QAAQ,EAC3B,YAAaL,CACf,CAAC,EACDK,EAAE,OAAO,CACP,QAASA,EAAE,QAAQ,SAAS,CAC9B,CAAC,CACH,CAAC,EAaD,SAASG,EAAWC,EAAgC,CAClD,OAAOA,EAAQ,UAAY,SACvB,IAAI,IAAIA,EAAQ,QAAQ,EAAE,SAAS,EACnC,IAAI,IAAI,4BAA6B,QAAQ,UAAU,QAAU,uBAAuB,EAAE,SAAS,CACzG,CAgEO,SAASC,EACdD,EACAE,EAIA,CACA,IAAMC,EAAmBV,EAASK,EAAqB,CACrD,GAAGE,EACH,QAASV,EAAe,SAAW,SACrC,CAAC,EACKc,EAAUV,EAAuB,EACjCW,EAAUN,EAAWI,CAAgB,EAE3C,MAAO,CACL,OAAQ,IAAIR,EAAcU,EAAS,CACjC,GAAGH,EACH,GAAIC,EAAiB,UAAY,UAAY,CAC3C,QAAS,CACP,eAAgBA,EAAiB,WACnC,CACF,CACF,CAAC,EACD,QAAAC,CACF,CACF","names":["runsOnServer","ApplicationAccessTokenSchema","UrlOrPathSchema","validate","initGraphQLTada","GraphQLClient","z","readFragment","ClientOptionsSchema","getFullUrl","options","createBlockscoutClient","clientOptions","validatedOptions","graphql","fullUrl"]}
1
+ {"version":3,"sources":["../src/blockscout.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 * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the Blockscout client.\n */\nexport const ClientOptionsSchema = z.object({\n instance: UrlOrPathSchema,\n accessToken: ApplicationAccessTokenSchema,\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Creates a Blockscout GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing the GraphQL client and initialized gql.tada function\n * @throws Will throw an error if the options fail validation\n * @example\n * import { createBlockscoutClient } from '@settlemint/sdk-blockscout';\n * import type { introspection } from \"@schemas/blockscout-env\";\n *\n * const { client, graphql } = createBlockscoutClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * AddressHash: string;\n * Data: string;\n * DateTime: string;\n * Decimal: string;\n * FullHash: string;\n * Json: string;\n * NonceHash: string;\n * Wei: string;\n * };\n * }>({\n * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query GetTransaction($hash: String!) {\n * transaction(hash: $hash) {\n * hash\n * blockNumber\n * value\n * gasUsed\n * }\n * }\n * `);\n *\n * const result = await client.request(query, {\n * hash: \"0x123abc...\"\n * });\n */\nexport function createBlockscoutClient<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: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":"AAAA,OAAS,gBAAAA,MAAoB,gCAC7B,OAAS,gCAAAC,EAA8B,mBAAAC,EAAiB,YAAAC,MAAgB,mCACxE,OAAmC,mBAAAC,MAAuB,WAC1D,OAAS,iBAAAC,MAAqB,kBAC9B,OAAS,KAAAC,MAAS,MAyFlB,OAAS,gBAAAC,MAAoB,WA/EtB,IAAMC,EAAsBF,EAAE,OAAO,CAC1C,SAAUJ,EACV,YAAaD,CACf,CAAC,EAoDM,SAASQ,EACdC,EACAC,EAIA,CACAX,EAAa,EACb,IAAMY,EAAmBT,EAASK,EAAqBE,CAAO,EACxDG,EAAUT,EAAuB,EACjCU,EAAU,IAAI,IAAIF,EAAiB,QAAQ,EAAE,SAAS,EAE5D,MAAO,CACL,OAAQ,IAAIP,EAAcS,EAAS,CACjC,GAAGH,EACH,QAAS,CACP,GAAIA,GAAe,SAAW,CAAC,EAC/B,eAAgBC,EAAiB,WACnC,CACF,CAAC,EACD,QAAAC,CACF,CACF","names":["ensureServer","ApplicationAccessTokenSchema","UrlOrPathSchema","validate","initGraphQLTada","GraphQLClient","z","readFragment","ClientOptionsSchema","createBlockscoutClient","options","clientOptions","validatedOptions","graphql","fullUrl"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@settlemint/sdk-blockscout",
3
3
  "description": "Blockscout integration module for SettleMint SDK, enabling blockchain explorer and analytics functionality",
4
- "version": "1.2.5",
4
+ "version": "2.0.0-pr831671fa",
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": "1.2.5",
55
+ "@settlemint/sdk-utils": "2.0.0-pr831671fa",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },