@settlemint/sdk-blockscout 1.2.5-prbe4cc6dc → 1.2.5-prbee6b57d

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.
@@ -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-prbe4cc6dc",
4
+ "version": "1.2.5-prbee6b57d",
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-prbe4cc6dc",
55
+ "@settlemint/sdk-utils": "1.2.5-prbee6b57d",
56
56
  "graphql-request": "^7",
57
57
  "zod": "^3"
58
58
  },