@settlemint/sdk-blockscout 1.1.9 → 1.1.11-prf5ea01e7

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:106](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L106)
55
+ Defined in: [sdk/blockscout/src/blockscout.ts:108](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L108)
56
56
 
57
57
  Creates a Blockscout GraphQL client with proper type safety using gql.tada
58
58
 
@@ -77,8 +77,8 @@ An object containing the GraphQL client and initialized gql.tada function
77
77
 
78
78
  | Name | Type | Defined in |
79
79
  | ------ | ------ | ------ |
80
- | `client` | `GraphQLClient` | [sdk/blockscout/src/blockscout.ts:110](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L110) |
81
- | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/blockscout/src/blockscout.ts:111](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L111) |
80
+ | `client` | `GraphQLClient` | [sdk/blockscout/src/blockscout.ts:112](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L112) |
81
+ | `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/blockscout/src/blockscout.ts:113](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L113) |
82
82
 
83
83
  ##### Throws
84
84
 
@@ -95,13 +95,14 @@ const { client, graphql } = createBlockscoutClient<{
95
95
  introspection: introspection;
96
96
  disableMasking: true;
97
97
  scalars: {
98
- DateTime: Date;
99
- JSON: Record<string, unknown>;
100
- Bytes: string;
101
- Int8: string;
102
- BigInt: string;
103
- BigDecimal: string;
104
- Timestamp: string;
98
+ AddressHash: string;
99
+ Data: string;
100
+ DateTime: string;
101
+ Decimal: string;
102
+ FullHash: string;
103
+ Json: string;
104
+ NonceHash: string;
105
+ Wei: string;
105
106
  };
106
107
  }>({
107
108
  instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,
@@ -113,13 +114,14 @@ const { client, graphql } = createBlockscoutClient<{
113
114
  introspection: introspection;
114
115
  disableMasking: true;
115
116
  scalars: {
116
- DateTime: Date;
117
- JSON: Record<string, unknown>;
118
- Bytes: string;
119
- Int8: string;
120
- BigInt: string;
121
- BigDecimal: string;
122
- Timestamp: string;
117
+ AddressHash: string;
118
+ Data: string;
119
+ DateTime: string;
120
+ Decimal: string;
121
+ FullHash: string;
122
+ Json: string;
123
+ NonceHash: string;
124
+ Wei: string;
123
125
  };
124
126
  }>({});
125
127
 
@@ -146,7 +148,7 @@ const result = await client.request(query, {
146
148
 
147
149
  > **ClientOptions**: \{ `accessToken`: `string`; `instance`: `string`; `runtime`: `"server"`; \} \| \{ `runtime`: `"browser"`; \}
148
150
 
149
- Defined in: [sdk/blockscout/src/blockscout.ts:32](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L32)
151
+ Defined in: [sdk/blockscout/src/blockscout.ts:32](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L32)
150
152
 
151
153
  Type definition for client options derived from the ClientOptionsSchema
152
154
 
@@ -156,7 +158,7 @@ Type definition for client options derived from the ClientOptionsSchema
156
158
 
157
159
  > **RequestConfig**: `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
158
160
 
159
- Defined in: [sdk/blockscout/src/blockscout.ts:10](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L10)
161
+ Defined in: [sdk/blockscout/src/blockscout.ts:10](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L10)
160
162
 
161
163
  Type definition for GraphQL client configuration options
162
164
 
@@ -166,7 +168,7 @@ Type definition for GraphQL client configuration options
166
168
 
167
169
  > `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<[`ClientOptions`](README.md#clientoptions)\>
168
170
 
169
- Defined in: [sdk/blockscout/src/blockscout.ts:18](https://github.com/settlemint/sdk/blob/v1.1.9/sdk/blockscout/src/blockscout.ts#L18)
171
+ Defined in: [sdk/blockscout/src/blockscout.ts:18](https://github.com/settlemint/sdk/blob/v1.1.11/sdk/blockscout/src/blockscout.ts#L18)
170
172
 
171
173
  Schema for validating client options for the Blockscout client.
172
174
  Defines two possible runtime configurations:
@@ -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 * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: 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 * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: 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,eAgIlBF,EAA6B,oBAnHhBG,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,CA8DO,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 { 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"]}
@@ -52,13 +52,14 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
52
52
  * introspection: introspection;
53
53
  * disableMasking: true;
54
54
  * scalars: {
55
- * DateTime: Date;
56
- * JSON: Record<string, unknown>;
57
- * Bytes: string;
58
- * Int8: string;
59
- * BigInt: string;
60
- * BigDecimal: string;
61
- * Timestamp: string;
55
+ * AddressHash: string;
56
+ * Data: string;
57
+ * DateTime: string;
58
+ * Decimal: string;
59
+ * FullHash: string;
60
+ * Json: string;
61
+ * NonceHash: string;
62
+ * Wei: string;
62
63
  * };
63
64
  * }>({
64
65
  * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,
@@ -70,13 +71,14 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
70
71
  * introspection: introspection;
71
72
  * disableMasking: true;
72
73
  * scalars: {
73
- * DateTime: Date;
74
- * JSON: Record<string, unknown>;
75
- * Bytes: string;
76
- * Int8: string;
77
- * BigInt: string;
78
- * BigDecimal: string;
79
- * Timestamp: string;
74
+ * AddressHash: string;
75
+ * Data: string;
76
+ * DateTime: string;
77
+ * Decimal: string;
78
+ * FullHash: string;
79
+ * Json: string;
80
+ * NonceHash: string;
81
+ * Wei: string;
80
82
  * };
81
83
  * }>({});
82
84
  *
@@ -52,13 +52,14 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
52
52
  * introspection: introspection;
53
53
  * disableMasking: true;
54
54
  * scalars: {
55
- * DateTime: Date;
56
- * JSON: Record<string, unknown>;
57
- * Bytes: string;
58
- * Int8: string;
59
- * BigInt: string;
60
- * BigDecimal: string;
61
- * Timestamp: string;
55
+ * AddressHash: string;
56
+ * Data: string;
57
+ * DateTime: string;
58
+ * Decimal: string;
59
+ * FullHash: string;
60
+ * Json: string;
61
+ * NonceHash: string;
62
+ * Wei: string;
62
63
  * };
63
64
  * }>({
64
65
  * instance: process.env.SETTLEMINT_BLOCKSCOUT_ENDPOINT,
@@ -70,13 +71,14 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
70
71
  * introspection: introspection;
71
72
  * disableMasking: true;
72
73
  * scalars: {
73
- * DateTime: Date;
74
- * JSON: Record<string, unknown>;
75
- * Bytes: string;
76
- * Int8: string;
77
- * BigInt: string;
78
- * BigDecimal: string;
79
- * Timestamp: string;
74
+ * AddressHash: string;
75
+ * Data: string;
76
+ * DateTime: string;
77
+ * Decimal: string;
78
+ * FullHash: string;
79
+ * Json: string;
80
+ * NonceHash: string;
81
+ * Wei: string;
80
82
  * };
81
83
  * }>({});
82
84
  *
@@ -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 * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: 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 * DateTime: Date;\n * JSON: Record<string, unknown>;\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: 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,MAgIlB,OAAS,gBAAAC,MAAoB,WAnHtB,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,CA8DO,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 { 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"]}
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.1.9",
4
+ "version": "1.1.11-prf5ea01e7",
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.1.9",
55
+ "@settlemint/sdk-utils": "1.1.11-prf5ea01e7",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },